Skip to content

Commit

Permalink
Added receiving of alert packet + sound, fixed display of long chat m…
Browse files Browse the repository at this point in the history
…essages
  • Loading branch information
kroyee committed Aug 13, 2017
1 parent 1a119bb commit 71a22a4
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,12 @@ void UI::setCountdown() {
}
}

void UI::getAlert() {
sf::String msg;
net.packet >> msg;
alertsUI->addAlert(msg);
}

void UI::handlePacket() {
if (net.packetid <100)
cout << "Packet id: " << (int)net.packetid << endl;
Expand Down Expand Up @@ -916,6 +922,9 @@ void UI::handlePacket() {
}
}
break;
case 10: //Alert msg
getAlert();
break;
case 12: // Incoming chat msg
chatScreen->getMsg();
break;
Expand Down
1 change: 1 addition & 0 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class UI {
void receiveRecording();

void iGotKicked(sf::Uint16 reason);
void getAlert();

void disconnect();

Expand Down
3 changes: 3 additions & 0 deletions src/gui/AlertsUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void AlertsUI::addAlert(const sf::String& msg) {
panel->add(alerts.back().button);

update();

if (gui->options.sound)
gui->resources.sounds.alert();
}

void AlertsUI::removeAlert(sf::Uint16 _id) {
Expand Down
3 changes: 1 addition & 2 deletions src/gui/ChatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,11 @@ void ChatScreen::fade(const sf::Time& t) {
else break;
}

sf::Uint8 amount = fadingChatBox->getLineAmount();
sf::Uint8 amount = fadingChatBox->getScrollbar()->getMaximum();
if (!amount || isActive())
fadingChatBox->hide();
else {
fadingChatBox->show();
amount = amount* gui->tGui.getFont()->getLineSpacing(chatTextSize);
fadingChatBox->setPosition(5, 560-amount);
fadingChatBox->setSize(470, amount);
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/GameOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void GameOptions::create(sf::Rect<int> _pos, UI* _gui, tgui::Panel::Ptr parentPa
SndOpt->add(CvS);

tgui::Label::Ptr CvL = gui->themeTG->load("Label");
CvL->setText("Chat Volume");
CvL->setText("Alert Volume");
CvL->setPosition(240, 250);
SndOpt->add(CvL);

Expand Down Expand Up @@ -694,7 +694,7 @@ void GameOptions::volSlide(short i, short vol) {
}
else if (i == 3) {
gui->options.ChatVolume = vol;
gui->resources.sounds.setChatVolume(vol);
gui->resources.sounds.setAlertVolume(vol);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/OnlineplayUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MainMenu.h"
#include "gamePlay.h"
#include "AreYouSure.h"
#include "AlertsUI.h"
using std::to_string;
using std::cout;
using std::endl;
Expand Down Expand Up @@ -329,5 +330,5 @@ void OnlineplayUI::alertMsg(const sf::Uint16 id1) {
for (auto&& tournament : tournamentList.items)
if (tournament.id == id1)
msg += " in " + tournament.name;
gui->quickMsg(msg);
gui->alertsUI->addAlert(msg);
}
2 changes: 1 addition & 1 deletion src/resources/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool Resources::init() {

sounds.setEffectVolume(options.EffectVolume);
sounds.setMusicVolume(options.MusicVolume);
sounds.setChatVolume(options.ChatVolume);
sounds.setAlertVolume(options.ChatVolume);

gfx.setGhostPieceAlpha(options.ghostPieceAlpha);

Expand Down
7 changes: 5 additions & 2 deletions src/resources/sounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ sf::String soundBank::loadSounds() {
return "sounds/171640__fins__scale-c7.wav";
if (!startBeepBuff.loadFromFile(resourcePath() + "sounds/13119__looppool__bell-blip.wav"))
return "sounds/13119__looppool__bell-blip.wav";
if (!alertBuff.loadFromFile(resourcePath() + "sounds/274183__littlerobotsoundfactory__jingle-win-synth-04.wav"))
return "sounds/274183__littlerobotsoundfactory__jingle-win-synth-04.wav";

pieceDropSound.setBuffer(pieceDropBuff);
lineClearSound.setBuffer(lineClearBuff);
Expand All @@ -54,6 +56,7 @@ sf::String soundBank::loadSounds() {
combo21Sound.setBuffer(combo21Buff);
startBeep1Sound.setBuffer(startBeepBuff);
startBeep2Sound.setBuffer(startBeepBuff);
alertSound.setBuffer(alertBuff);

startBeep2Sound.setPitch(1.5);

Expand Down Expand Up @@ -83,6 +86,6 @@ void soundBank::setMusicVolume(short vol) {

}

void soundBank::setChatVolume(short vol) {

void soundBank::setAlertVolume(short vol) {
alertSound.setVolume(vol);
}
5 changes: 4 additions & 1 deletion src/resources/sounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class soundBank {
sf::SoundBuffer combo19Buff;
sf::SoundBuffer combo21Buff;
sf::SoundBuffer startBeepBuff;
sf::SoundBuffer alertBuff;

sf::Sound pieceDropSound;
sf::Sound lineClearSound;
Expand All @@ -37,6 +38,7 @@ class soundBank {
sf::Sound combo21Sound;
sf::Sound startBeep1Sound;
sf::Sound startBeep2Sound;
sf::Sound alertSound;

sf::String loadSounds();

Expand All @@ -56,10 +58,11 @@ class soundBank {
void combo21() { combo21Sound.play(); }
void startBeep1() { startBeep1Sound.play(); }
void startBeep2() { startBeep2Sound.play(); }
void alert() { alertSound.play(); }

void setMusicVolume(short vol);
void setEffectVolume(short vol);
void setChatVolume(short vol);
void setAlertVolume(short vol);
};

#endif

0 comments on commit 71a22a4

Please sign in to comment.