Commit cc086f3f authored by mercury233's avatar mercury233

update SoundManager

parent c0dd50c2
......@@ -4,6 +4,7 @@
#include "duelclient.h"
#include "data_manager.h"
#include "image_manager.h"
#include "sound_manager.h"
#include "game.h"
#include "materials.h"
#include "../ocgcore/field.h"
......@@ -1018,7 +1019,7 @@ bool ClientField::ShowSelectSum(bool panelmode) {
BufferIO::CopyWStrRef(dataManager.GetSysString(210), pwbuf, 256);
mainGame->stQMessage->setText(wbuf);
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
}
} else {
select_ready = false;
......@@ -1040,7 +1041,7 @@ bool ClientField::ShowSelectSum(bool panelmode) {
BufferIO::CopyWStrRef(dataManager.GetSysString(210), pwbuf, 256);
mainGame->stQMessage->setText(wbuf);
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
}
} else
select_ready = false;
......
......@@ -49,9 +49,6 @@ inline int _wtoi(const wchar_t * s) {
#include <irrlicht.h>
#include <irrKlang.h>
#ifdef IRRKLANG_STATIC
#include "../ikpmp3/ikpMP3.h"
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include "CGUITTFont.h"
......
......@@ -3,6 +3,7 @@
#include "data_manager.h"
#include "deck_manager.h"
#include "image_manager.h"
#include "sound_manager.h"
#include "game.h"
#include "duelclient.h"
#include <algorithm>
......@@ -121,13 +122,13 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
switch(event.GUIEvent.EventType) {
case irr::gui::EGET_BUTTON_CLICKED: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(id) {
case BUTTON_CLEAR_DECK: {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetSysString(1339));
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
prev_operation = id;
break;
......@@ -184,7 +185,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
myswprintf(textBuffer, L"%ls\n%ls", mainGame->cbDBDecks->getItem(sel), dataManager.GetSysString(1337));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)textBuffer);
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
prev_operation = id;
break;
......@@ -194,7 +195,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetSysString(1356));
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
prev_operation = id;
break;
......@@ -358,7 +359,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetSysString(1356));
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
prev_operation = id;
break;
......@@ -516,7 +517,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
is_starting_dragging = false;
if(!is_draging)
break;
mainGame->PlaySoundEffect(SOUND_CARD_DROP);
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
bool pushed = false;
if(hovered_pos == 1)
pushed = push_main(draging_pointer, hovered_seq);
......@@ -546,7 +547,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager._datas.end())
break;
mainGame->PlaySoundEffect(SOUND_CARD_DROP);
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
if(hovered_pos == 1) {
if(push_side(pointer))
pop_main(hovered_seq);
......@@ -564,7 +565,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(!is_draging) {
if(hovered_pos == 0 || hovered_seq == -1)
break;
mainGame->PlaySoundEffect(SOUND_CARD_DROP);
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
if(hovered_pos == 1) {
pop_main(hovered_seq);
} else if(hovered_pos == 2) {
......@@ -581,7 +582,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
push_side(pointer);
}
} else {
mainGame->PlaySoundEffect(SOUND_CARD_PICK);
soundManager.PlaySoundEffect(SOUND_CARD_PICK);
if(click_pos == 1) {
push_side(draging_pointer);
} else if(click_pos == 2) {
......@@ -608,7 +609,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
auto pointer = dataManager.GetCodePointer(hovered_code);
if(!check_limit(pointer))
break;
mainGame->PlaySoundEffect(SOUND_CARD_PICK);
soundManager.PlaySoundEffect(SOUND_CARD_PICK);
if (hovered_pos == 1) {
if(!push_main(pointer))
push_side(pointer);
......@@ -627,7 +628,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case irr::EMIE_MOUSE_MOVED: {
if(is_starting_dragging) {
is_draging = true;
mainGame->PlaySoundEffect(SOUND_CARD_PICK);
soundManager.PlaySoundEffect(SOUND_CARD_PICK);
if(hovered_pos == 1)
pop_main(hovered_seq);
else if(hovered_pos == 2)
......
......@@ -2,6 +2,7 @@
#include "client_card.h"
#include "materials.h"
#include "image_manager.h"
#include "sound_manager.h"
#include "single_mode.h"
#include "../ocgcore/field.h"
#include "../ocgcore/duel.h"
......@@ -589,7 +590,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->btnCancelOrFinish->setVisible(false);
mainGame->stMessage->setText(dataManager.GetSysString(1500));
mainGame->PopupElement(mainGame->wMessage);
mainGame->PlaySoundEffect(SOUND_INFO);
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......@@ -632,7 +633,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mbstowcs(timetext, timebuf, size);
mainGame->ebRSName->setText(timetext);
mainGame->PopupElement(mainGame->wReplaySave);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
mainGame->replaySignal.Reset();
mainGame->replaySignal.Wait();
......@@ -699,7 +700,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
break;
}
case STOC_HS_PLAYER_ENTER: {
mainGame->PlaySoundEffect(SOUND_PLAYER_ENTER);
soundManager.PlaySoundEffect(SOUND_PLAYER_ENTER);
STOC_HS_PlayerEnter* pkt = (STOC_HS_PlayerEnter*)pdata;
if(pkt->pos > 3)
break;
......@@ -734,7 +735,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
break;
mainGame->gMutex.Lock();
if(state < 8) {
mainGame->PlaySoundEffect(SOUND_PLAYER_ENTER);
soundManager.PlaySoundEffect(SOUND_PLAYER_ENTER);
wchar_t* prename = (wchar_t*)mainGame->stHostPrepDuelist[pos]->getText();
mainGame->stHostPrepDuelist[state]->setText(prename);
mainGame->stHostPrepDuelist[pos]->setText(L"");
......@@ -819,7 +820,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->stMessage->setText(L"Error occurs.");
mainGame->PopupElement(mainGame->wMessage);
mainGame->PlaySoundEffect(SOUND_INFO);
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......@@ -856,7 +857,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->stMessage->setText(dataManager.GetDesc(data));
mainGame->PopupElement(mainGame->wMessage);
mainGame->PlaySoundEffect(SOUND_INFO);
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......@@ -1240,7 +1241,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, textBuffer);
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
return false;
}
......@@ -1251,7 +1252,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetDesc(desc));
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
return false;
}
......@@ -1275,7 +1276,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
select_hint = 0;
mainGame->wOptions->setText(textBuffer);
mainGame->PopupElement(mainGame->wOptions);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
return false;
}
......@@ -1420,7 +1421,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
myswprintf(textBuffer, L"%ls\n%ls", event_string, dataManager.GetSysString(203));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)textBuffer);
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
}
}
mainGame->gMutex.Unlock();
......@@ -1716,7 +1717,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
}
if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping)
return true;
mainGame->PlaySoundEffect(SOUND_REVEAL);
soundManager.PlaySoundEffect(SOUND_REVEAL);
myswprintf(textBuffer, dataManager.GetSysString(207), count);
mainGame->lstLog->addItem(textBuffer);
mainGame->logParam.push_back(0);
......@@ -1752,7 +1753,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
pbuf += count * 7;
return true;
}
mainGame->PlaySoundEffect(SOUND_REVEAL);
soundManager.PlaySoundEffect(SOUND_REVEAL);
myswprintf(textBuffer, dataManager.GetSysString(208), count);
mainGame->lstLog->addItem(textBuffer);
mainGame->logParam.push_back(0);
......@@ -1861,7 +1862,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->dField.deck[player][i]->is_reversed = false;
}
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
mainGame->PlaySoundEffect(SOUND_SHUFFLE);
soundManager.PlaySoundEffect(SOUND_SHUFFLE);
for (int i = 0; i < 5; ++i) {
for (auto cit = mainGame->dField.deck[player].begin(); cit != mainGame->dField.deck[player].end(); ++cit) {
(*cit)->dPos = irr::core::vector3df(rand() * 0.4f / RAND_MAX - 0.2f, 0, 0);
......@@ -1887,7 +1888,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
int count = BufferIO::ReadInt8(pbuf);
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
if(count > 1)
mainGame->PlaySoundEffect(SOUND_SHUFFLE);
soundManager.PlaySoundEffect(SOUND_SHUFFLE);
mainGame->WaitFrameSignal(5);
if(player == 1 && !mainGame->dInfo.isReplay && !mainGame->dInfo.isSingleMode) {
bool flip = false;
......@@ -2031,7 +2032,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
}
}
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
mainGame->PlaySoundEffect(SOUND_SHUFFLE);
soundManager.PlaySoundEffect(SOUND_SHUFFLE);
for (int i = 0; i < count; ++i) {
mainGame->dField.MoveCard(mc[i], 10);
for (cit = mc[i]->overlayed.begin(); cit != mc[i]->overlayed.end(); ++cit)
......@@ -2068,7 +2069,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->dInfo.tag_player[1] = !mainGame->dInfo.tag_player[1];
}
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
mainGame->PlaySoundEffect(SOUND_NEXT_TURN);
soundManager.PlaySoundEffect(SOUND_NEXT_TURN);
mainGame->showcardcode = 10;
mainGame->showcarddif = 30;
mainGame->showcardp = 0;
......@@ -2116,7 +2117,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->btnPhaseStatus->setPressed(true);
mainGame->btnPhaseStatus->setVisible(true);
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
mainGame->PlaySoundEffect(SOUND_PHASE);
soundManager.PlaySoundEffect(SOUND_PHASE);
mainGame->showcard = 101;
mainGame->WaitFrameSignal(40);
mainGame->showcard = 0;
......@@ -2136,9 +2137,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
int reason = BufferIO::ReadInt32(pbuf);
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
if(cl & LOCATION_REMOVED && pl != cl)
mainGame->PlaySoundEffect(SOUND_BANISHED);
soundManager.PlaySoundEffect(SOUND_BANISHED);
else if(reason & REASON_DESTROY && pl != cl)
mainGame->PlaySoundEffect(SOUND_DESTROYED);
soundManager.PlaySoundEffect(SOUND_DESTROYED);
}
if (pl == 0) {
ClientCard* pcard = new ClientCard();
......@@ -2361,7 +2362,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
/*int cs = */BufferIO::ReadInt8(pbuf);
/*int cp = */BufferIO::ReadInt8(pbuf);
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping)
mainGame->PlaySoundEffect(SOUND_SET);
soundManager.PlaySoundEffect(SOUND_SET);
myswprintf(event_string, dataManager.GetSysString(1601));
return true;
}
......@@ -2415,7 +2416,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
/*int cs = */BufferIO::ReadInt8(pbuf);
/*int cp = */BufferIO::ReadInt8(pbuf);
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
mainGame->PlaySoundEffect(SOUND_SUMMON);
soundManager.PlaySoundEffect(SOUND_SUMMON);
myswprintf(event_string, dataManager.GetSysString(1603), dataManager.GetName(code));
mainGame->showcardcode = code;
mainGame->showcarddif = 0;
......@@ -2440,9 +2441,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
CardData cd;
if(dataManager.GetData(code, &cd) && (cd.type & TYPE_TOKEN))
mainGame->PlaySoundEffect(SOUND_TOKEN);
soundManager.PlaySoundEffect(SOUND_TOKEN);
else
mainGame->PlaySoundEffect(SOUND_SPECIAL_SUMMON);
soundManager.PlaySoundEffect(SOUND_SPECIAL_SUMMON);
myswprintf(event_string, dataManager.GetSysString(1605), dataManager.GetName(code));
mainGame->showcardcode = code;
mainGame->showcarddif = 1;
......@@ -2467,7 +2468,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
pcard->SetCode(code);
pcard->position = cp;
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
mainGame->PlaySoundEffect(SOUND_FILP);
soundManager.PlaySoundEffect(SOUND_FILP);
myswprintf(event_string, dataManager.GetSysString(1607), dataManager.GetName(code));
mainGame->dField.MoveCard(pcard, 10);
mainGame->WaitFrameSignal(11);
......@@ -2498,7 +2499,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
/*int ct = */BufferIO::ReadInt8(pbuf);
if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping)
return true;
mainGame->PlaySoundEffect(SOUND_ACTIVATE);
soundManager.PlaySoundEffect(SOUND_ACTIVATE);
ClientCard* pcard = mainGame->dField.GetCard(pcc, pcl, pcs, subs);
if(pcard->code != code) {
pcard->code = code;
......@@ -2600,7 +2601,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
pbuf += count * 4;
return true;
}
mainGame->PlaySoundEffect(SOUND_DICE);
soundManager.PlaySoundEffect(SOUND_DICE);
ClientCard* pcards[10];
for (int i = 0; i < count; ++i) {
int c = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
......@@ -2619,7 +2620,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true;
}
case MSG_BECOME_TARGET: {
//mainGame->PlaySoundEffect(SOUND_TARGET);
//soundManager.PlaySoundEffect(SOUND_TARGET);
int count = BufferIO::ReadInt8(pbuf);
if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping) {
pbuf += count * 4;
......@@ -2667,7 +2668,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
}
} else {
for (int i = 0; i < count; ++i) {
mainGame->PlaySoundEffect(SOUND_DRAW);
soundManager.PlaySoundEffect(SOUND_DRAW);
mainGame->gMutex.Lock();
pcard = mainGame->dField.GetCard(player, LOCATION_DECK, mainGame->dField.deck[player].size() - 1);
mainGame->dField.deck[player].erase(mainGame->dField.deck[player].end() - 1);
......@@ -2694,7 +2695,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
myswprintf(mainGame->dInfo.strLP[player], L"%d", mainGame->dInfo.lp[player]);
return true;
}
mainGame->PlaySoundEffect(SOUND_DAMAGE);
soundManager.PlaySoundEffect(SOUND_DAMAGE);
mainGame->lpd = (mainGame->dInfo.lp[player] - final) / 10;
if (player == 0)
myswprintf(event_string, dataManager.GetSysString(1613), val);
......@@ -2723,7 +2724,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
myswprintf(mainGame->dInfo.strLP[player], L"%d", mainGame->dInfo.lp[player]);
return true;
}
mainGame->PlaySoundEffect(SOUND_RECOVER);
soundManager.PlaySoundEffect(SOUND_RECOVER);
mainGame->lpd = (mainGame->dInfo.lp[player] - final) / 10;
if (player == 0)
myswprintf(event_string, dataManager.GetSysString(1615), val);
......@@ -2760,7 +2761,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
pc1->equipTarget = pc2;
pc2->equipped.insert(pc1);
} else {
mainGame->PlaySoundEffect(SOUND_EQUIP);
soundManager.PlaySoundEffect(SOUND_EQUIP);
mainGame->gMutex.Lock();
if(pc1->equipTarget) {
pc1->is_showequip = false;
......@@ -2879,7 +2880,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
myswprintf(mainGame->dInfo.strLP[player], L"%d", mainGame->dInfo.lp[player]);
return true;
}
mainGame->PlaySoundEffect(SOUND_DAMAGE);
soundManager.PlaySoundEffect(SOUND_DAMAGE);
mainGame->lpd = (mainGame->dInfo.lp[player] - final) / 10;
mainGame->lpccolor = 0xff0000ff;
mainGame->lpplayer = player;
......@@ -2907,7 +2908,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
else pc->counters[type] = count;
if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping)
return true;
mainGame->PlaySoundEffect(SOUND_COUNTER_ADD);
soundManager.PlaySoundEffect(SOUND_COUNTER_ADD);
myswprintf(textBuffer, dataManager.GetSysString(1617), dataManager.GetName(pc->code), count, dataManager.GetCounterName(type));
pc->is_highlighting = true;
mainGame->gMutex.Lock();
......@@ -2930,7 +2931,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
pc->counters.erase(type);
if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping)
return true;
mainGame->PlaySoundEffect(SOUND_COUNTER_REMOVE);
soundManager.PlaySoundEffect(SOUND_COUNTER_REMOVE);
myswprintf(textBuffer, dataManager.GetSysString(1618), dataManager.GetName(pc->code), count, dataManager.GetCounterName(type));
pc->is_highlighting = true;
mainGame->gMutex.Lock();
......@@ -2955,7 +2956,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true;
float sy;
if (ld != 0) {
mainGame->PlaySoundEffect(SOUND_ATTACK);
soundManager.PlaySoundEffect(SOUND_ATTACK);
mainGame->dField.attack_target = mainGame->dField.GetCard(cd, ld, sd);
myswprintf(event_string, dataManager.GetSysString(1619), dataManager.GetName(mainGame->dField.attacker->code),
dataManager.GetName(mainGame->dField.attack_target->code));
......@@ -2970,7 +2971,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
else
mainGame->atk_r = vector3df(0, 0, 3.1415926 - atan((xd - xa) / (yd - ya)));
} else {
mainGame->PlaySoundEffect(SOUND_DIRECT_ATTACK);
soundManager.PlaySoundEffect(SOUND_DIRECT_ATTACK);
myswprintf(event_string, dataManager.GetSysString(1620), dataManager.GetName(mainGame->dField.attacker->code));
float xa = mainGame->dField.attacker->curPos.X;
float ya = mainGame->dField.attacker->curPos.Y;
......@@ -3065,7 +3066,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
*pwbuf = 0;
if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping)
return true;
mainGame->PlaySoundEffect(SOUND_COIN);
soundManager.PlaySoundEffect(SOUND_COIN);
mainGame->gMutex.Lock();
mainGame->lstLog->addItem(textBuffer);
mainGame->logParam.push_back(0);
......@@ -3089,7 +3090,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
*pwbuf = 0;
if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping)
return true;
mainGame->PlaySoundEffect(SOUND_DICE);
soundManager.PlaySoundEffect(SOUND_DICE);
mainGame->gMutex.Lock();
mainGame->lstLog->addItem(textBuffer);
mainGame->logParam.push_back(0);
......@@ -3142,7 +3143,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->wANRace->setText(textBuffer);
mainGame->PopupElement(mainGame->wANRace);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
return false;
}
......@@ -3163,7 +3164,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->wANAttribute->setText(textBuffer);
mainGame->PopupElement(mainGame->wANAttribute);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
return false;
}
......@@ -3180,7 +3181,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->wANCard->setText(textBuffer);
mainGame->dField.UpdateDeclarableCode(true);
mainGame->PopupElement(mainGame->wANCard);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
return false;
}
......@@ -3201,7 +3202,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
select_hint = 0;
mainGame->wANNumber->setText(textBuffer);
mainGame->PopupElement(mainGame->wANNumber);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
return false;
}
......@@ -3221,7 +3222,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->wANCard->setText(textBuffer);
mainGame->dField.UpdateDeclarableCode(true);
mainGame->PopupElement(mainGame->wANCard);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
mainGame->gMutex.Unlock();
return false;
}
......
......@@ -6,6 +6,7 @@
#include "duelclient.h"
#include "data_manager.h"
#include "image_manager.h"
#include "sound_manager.h"
#include "replay_mode.h"
#include "single_mode.h"
#include "materials.h"
......@@ -40,7 +41,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
case BUTTON_FIRST:
case BUTTON_SECOND: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->HideElement(mainGame->wFTSelect);
CTOS_TPResult cstr;
cstr.res = BUTTON_SECOND - id;
......@@ -50,7 +51,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_REPLAY_START: {
if(!mainGame->dInfo.isReplay)
break;
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->btnReplayStart->setVisible(false);
mainGame->btnReplayPause->setVisible(true);
mainGame->btnReplayStep->setVisible(false);
......@@ -61,7 +62,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_REPLAY_PAUSE: {
if(!mainGame->dInfo.isReplay)
break;
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->btnReplayStart->setVisible(true);
mainGame->btnReplayPause->setVisible(false);
mainGame->btnReplayStep->setVisible(true);
......@@ -72,19 +73,19 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_REPLAY_STEP: {
if(!mainGame->dInfo.isReplay)
break;
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
ReplayMode::Pause(false, true);
break;
}
case BUTTON_REPLAY_EXIT: {
if(!mainGame->dInfo.isReplay)
break;
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
ReplayMode::StopReplay();
break;
}
case BUTTON_REPLAY_SWAP: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
if(mainGame->dInfo.isReplay)
ReplayMode::SwapField();
else if (mainGame->dInfo.player_type == 7)
......@@ -94,28 +95,28 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_REPLAY_UNDO: {
if(!mainGame->dInfo.isReplay)
break;
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
ReplayMode::Undo();
break;
}
case BUTTON_REPLAY_SAVE: {
if(mainGame->ebRSName->getText()[0] == 0)
break;
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->actionParam = 1;
mainGame->HideElement(mainGame->wReplaySave);
mainGame->replaySignal.Set();
break;
}
case BUTTON_REPLAY_CANCEL: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->actionParam = 0;
mainGame->HideElement(mainGame->wReplaySave);
mainGame->replaySignal.Set();
break;
}
case BUTTON_LEAVE_GAME: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
if(mainGame->dInfo.isSingleMode) {
mainGame->singleSignal.SetNoWait(true);
SingleMode::StopPlay(false);
......@@ -143,7 +144,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_CHAIN_IGNORE: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->ignore_chain = mainGame->btnChainIgnore->isPressed();
mainGame->always_chain = false;
mainGame->chain_when_avail = false;
......@@ -151,7 +152,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_CHAIN_ALWAYS: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->always_chain = mainGame->btnChainAlways->isPressed();
mainGame->ignore_chain = false;
mainGame->chain_when_avail = false;
......@@ -159,7 +160,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_CHAIN_WHENAVAIL: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->chain_when_avail = mainGame->btnChainWhenAvail->isPressed();
mainGame->always_chain = false;
mainGame->ignore_chain = false;
......@@ -167,7 +168,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_CANCEL_OR_FINISH: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch (mainGame->dInfo.curMsg) {
case MSG_WAITING: {
if (mainGame->wCardSelect->isVisible()) {
......@@ -277,7 +278,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
else {
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
ShowCancelOrFinishButton(0);
}
if (mainGame->wOptions->isVisible()) {
......@@ -299,13 +300,13 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_MSG_OK: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->HideElement(mainGame->wMessage);
mainGame->actionSignal.Set();
break;
}
case BUTTON_YES: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(mainGame->dInfo.curMsg) {
case MSG_SELECT_YESNO:
case MSG_SELECT_EFFECTYN: {
......@@ -339,7 +340,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_NO: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(mainGame->dInfo.curMsg) {
case MSG_SELECT_YESNO:
case MSG_SELECT_EFFECTYN: {
......@@ -392,7 +393,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_OPTION_PREV: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
selected_option--;
mainGame->btnOptionn->setVisible(true);
if(selected_option == 0)
......@@ -401,7 +402,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_OPTION_NEXT: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
selected_option++;
mainGame->btnOptionp->setVisible(true);
if(selected_option == select_options.size() - 1)
......@@ -410,7 +411,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_OPTION_OK: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
if (mainGame->dInfo.curMsg == MSG_SELECT_OPTION) {
DuelClient::SetResponseI(selected_option);
} else {
......@@ -428,13 +429,13 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_ANNUMBER_OK: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
DuelClient::SetResponseI(mainGame->cbANNumber->getSelected());
mainGame->HideElement(mainGame->wANNumber, true);
break;
}
case BUTTON_ANCARD_OK: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
int sel = mainGame->lstANCard->getSelected();
if(sel == -1)
break;
......@@ -1451,7 +1452,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
BufferIO::CopyWStrRef(dataManager.GetSysString(210), pwbuf, 256);
mainGame->stQMessage->setText(wbuf);
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
}
}
} else {
......@@ -1627,7 +1628,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
mainGame->HideElement(mainGame->wQuery, true);
} else {
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
soundManager.PlaySoundEffect(SOUND_QUESTION);
ShowCancelOrFinishButton(0);
}
if(mainGame->wOptions->isVisible()) {
......@@ -1980,7 +1981,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
case irr::gui::EGET_BUTTON_CLICKED: {
switch(id) {
case BUTTON_CLEAR_LOG: {
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->lstLog->clear();
mainGame->logParam.clear();
return true;
......@@ -1998,7 +1999,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
}
case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked())
mainGame->engineMusic->stopAllSounds();
soundManager.StopBGM();
return true;
break;
}
......@@ -2042,8 +2043,8 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
case SCROLL_VOLUME: {
mainGame->gameConf.sound_volume = (double)mainGame->scrSoundVolume->getPos() / 100;
mainGame->gameConf.music_volume = (double)mainGame->scrMusicVolume->getPos() / 100;
mainGame->engineSound->setSoundVolume(mainGame->gameConf.sound_volume);
mainGame->engineMusic->setSoundVolume(mainGame->gameConf.music_volume);
soundManager.SetSoundVolume(mainGame->gameConf.sound_volume);
soundManager.SetMusicVolume(mainGame->gameConf.music_volume);
break;
}
}
......
......@@ -3,6 +3,7 @@
#include "image_manager.h"
#include "data_manager.h"
#include "deck_manager.h"
#include "sound_manager.h"
#include "replay.h"
#include "materials.h"
#include "duelclient.h"
......@@ -44,7 +45,6 @@ bool Game::Initialize() {
ignore_chain = false;
chain_when_avail = false;
is_building = false;
bgm_scene = -1;
memset(&dInfo, 0, sizeof(DuelInfo));
memset(chatTiming, 0, sizeof(chatTiming));
deckManager.LoadLFList();
......@@ -636,30 +636,21 @@ bool Game::Initialize() {
stTip->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
stTip->setVisible(false);
device->setEventReceiver(&menuHandler);
RefreshBGMList();
LoadConfig();
env->getSkin()->setFont(guiFont);
env->setFocus(wMainMenu);
for (u32 i = 0; i < EGDC_COUNT; ++i) {
SColor col = env->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
col.setAlpha(224);
env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
}
engineSound = irrklang::createIrrKlangDevice();
engineMusic = irrklang::createIrrKlangDevice();
if(!engineSound || !engineMusic) {
if(!soundManager.Init()) {
chkEnableSound->setChecked(false);
chkEnableSound->setEnabled(false);
chkEnableMusic->setChecked(false);
chkEnableMusic->setEnabled(false);
chkMusicMode->setEnabled(false);
}
#ifdef IRRKLANG_STATIC
else {
irrklang::ikpMP3Init(engineSound);
irrklang::ikpMP3Init(engineMusic);
env->getSkin()->setFont(guiFont);
env->setFocus(wMainMenu);
for (u32 i = 0; i < EGDC_COUNT; ++i) {
SColor col = env->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
col.setAlpha(224);
env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
}
#endif
hideChat = false;
hideChatTimer = 0;
return true;
......@@ -690,15 +681,15 @@ void Game::MainLoop() {
gMutex.Lock();
if(dInfo.isStarted) {
if(mainGame->dInfo.isFinished && mainGame->showcardcode == 1)
PlayBGM(BGM_WIN);
soundManager.PlayBGM(BGM_WIN);
else if(mainGame->dInfo.isFinished && (mainGame->showcardcode == 2 || mainGame->showcardcode == 3))
PlayBGM(BGM_LOSE);
soundManager.PlayBGM(BGM_LOSE);
else if(mainGame->dInfo.lp[0] > 0 && mainGame->dInfo.lp[0] <= mainGame->dInfo.lp[1] / 2)
PlayBGM(BGM_DISADVANTAGE);
soundManager.PlayBGM(BGM_DISADVANTAGE);
else if(mainGame->dInfo.lp[0] > 0 && mainGame->dInfo.lp[0] >= mainGame->dInfo.lp[1] * 2)
PlayBGM(BGM_ADVANTAGE);
soundManager.PlayBGM(BGM_ADVANTAGE);
else
PlayBGM(BGM_DUEL);
soundManager.PlayBGM(BGM_DUEL);
DrawBackImage(imageManager.tBackGround);
DrawBackGround();
DrawCards();
......@@ -707,11 +698,11 @@ void Game::MainLoop() {
driver->setMaterial(irr::video::IdentityMaterial);
driver->clearZBuffer();
} else if(is_building) {
PlayBGM(BGM_DECK);
soundManager.PlayBGM(BGM_DECK);
DrawBackImage(imageManager.tBackGround_deck);
DrawDeckBd();
} else {
PlayBGM(BGM_MENU);
soundManager.PlayBGM(BGM_MENU);
DrawBackImage(imageManager.tBackGround_menu);
}
DrawGUI();
......@@ -763,8 +754,6 @@ void Game::MainLoop() {
usleep(500000);
#endif
SaveConfig();
if(engineMusic)
engineMusic->drop();
// device->drop();
}
void Game::BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar) {
......@@ -952,47 +941,6 @@ void Game::RefreshSingleplay() {
closedir(dir);
#endif
}
void Game::RefreshBGMList() {
RefershBGMDir(L"", BGM_DUEL);
RefershBGMDir(L"duel/", BGM_DUEL);
RefershBGMDir(L"menu/", BGM_MENU);
RefershBGMDir(L"deck/", BGM_DECK);
RefershBGMDir(L"advantage/", BGM_ADVANTAGE);
RefershBGMDir(L"disadvantage/", BGM_DISADVANTAGE);
RefershBGMDir(L"win/", BGM_WIN);
RefershBGMDir(L"lose/", BGM_LOSE);
}
void Game::RefershBGMDir(std::wstring path, int scene) {
#ifdef _WIN32
WIN32_FIND_DATAW fdataw;
std::wstring search = L"./sound/BGM/" + path + L"*.mp3";
HANDLE fh = FindFirstFileW(search.c_str(), &fdataw);
if(fh == INVALID_HANDLE_VALUE)
return;
do {
if(!(fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
std::wstring filename = path + (std::wstring)fdataw.cFileName;
BGMList[BGM_ALL].push_back(filename);
BGMList[scene].push_back(filename);
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./sound/BGM/*.mp3")) == NULL)
return;
while((dirp = readdir(dir)) != NULL) {
size_t len = strlen(dirp->d_name);
if(len < 5 || strcasecmp(dirp->d_name + len - 4, ".mp3") != 0)
continue;
wchar_t wname[256];
BufferIO::DecodeUTF8(dirp->d_name, wname);
BGMList[BGM_ALL].push_back(wname);
}
closedir(dir);
#endif
}
void Game::LoadConfig() {
FILE* fp = fopen("system.conf", "r");
if(!fp)
......@@ -1176,163 +1124,6 @@ void Game::SaveConfig() {
fprintf(fp, "music_mode = %d\n", ((mainGame->chkMusicMode->isChecked()) ? 1 : 0));
fclose(fp);
}
void Game::PlaySoundEffect(int sound) {
if(!mainGame->chkEnableSound->isChecked())
return;
switch(sound) {
case SOUND_SUMMON: {
engineSound->play2D("./sound/summon.wav");
break;
}
case SOUND_SPECIAL_SUMMON: {
engineSound->play2D("./sound/specialsummon.wav");
break;
}
case SOUND_ACTIVATE: {
engineSound->play2D("./sound/activate.wav");
break;
}
case SOUND_SET: {
engineSound->play2D("./sound/set.wav");
break;
}
case SOUND_FILP: {
engineSound->play2D("./sound/flip.wav");
break;
}
case SOUND_REVEAL: {
engineSound->play2D("./sound/reveal.wav");
break;
}
case SOUND_EQUIP: {
engineSound->play2D("./sound/equip.wav");
break;
}
case SOUND_DESTROYED: {
engineSound->play2D("./sound/destroyed.wav");
break;
}
case SOUND_BANISHED: {
engineSound->play2D("./sound/banished.wav");
break;
}
case SOUND_TOKEN: {
engineSound->play2D("./sound/token.wav");
break;
}
case SOUND_ATTACK: {
engineSound->play2D("./sound/attack.wav");
break;
}
case SOUND_DIRECT_ATTACK: {
engineSound->play2D("./sound/directattack.wav");
break;
}
case SOUND_DRAW: {
engineSound->play2D("./sound/draw.wav");
break;
}
case SOUND_SHUFFLE: {
engineSound->play2D("./sound/shuffle.wav");
break;
}
case SOUND_DAMAGE: {
engineSound->play2D("./sound/damage.wav");
break;
}
case SOUND_RECOVER: {
engineSound->play2D("./sound/gainlp.wav");
break;
}
case SOUND_COUNTER_ADD: {
engineSound->play2D("./sound/addcounter.wav");
break;
}
case SOUND_COUNTER_REMOVE: {
engineSound->play2D("./sound/removecounter.wav");
break;
}
case SOUND_COIN: {
engineSound->play2D("./sound/coinflip.wav");
break;
}
case SOUND_DICE: {
engineSound->play2D("./sound/diceroll.wav");
break;
}
case SOUND_NEXT_TURN: {
engineSound->play2D("./sound/nextturn.wav");
break;
}
case SOUND_PHASE: {
engineSound->play2D("./sound/phase.wav");
break;
}
case SOUND_MENU: {
engineSound->play2D("./sound/menu.wav");
break;
}
case SOUND_BUTTON: {
engineSound->play2D("./sound/button.wav");
break;
}
case SOUND_INFO: {
engineSound->play2D("./sound/info.wav");
break;
}
case SOUND_QUESTION: {
engineSound->play2D("./sound/question.wav");
break;
}
case SOUND_CARD_PICK: {
engineSound->play2D("./sound/cardpick.wav");
break;
}
case SOUND_CARD_DROP: {
engineSound->play2D("./sound/carddrop.wav");
break;
}
case SOUND_PLAYER_ENTER: {
engineSound->play2D("./sound/playerenter.wav");
break;
}
case SOUND_CHAT: {
engineSound->play2D("./sound/chatmessage.wav");
break;
}
default:
break;
}
engineSound->setSoundVolume(gameConf.sound_volume);
}
void Game::PlayMusic(char* song, bool loop) {
if(!mainGame->chkEnableMusic->isChecked())
return;
if(!engineMusic->isCurrentlyPlaying(song)) {
engineMusic->stopAllSounds();
soundBGM = engineMusic->play2D(song, loop, false, true);
engineMusic->setSoundVolume(gameConf.music_volume);
}
}
void Game::PlayBGM(int scene) {
if(!mainGame->chkEnableMusic->isChecked())
return;
if(!mainGame->chkMusicMode->isChecked())
scene = BGM_ALL;
char BGMName[1024];
if(scene != bgm_scene || (soundBGM && soundBGM->isFinished())) {
int count = BGMList[scene].size();
if(count <= 0)
return;
bgm_scene = scene;
int bgm = rand() % count;
auto name = BGMList[scene][bgm].c_str();
wchar_t fname[1024];
myswprintf(fname, L"./sound/BGM/%ls", name);
BufferIO::EncodeUTF8(fname, BGMName);
PlayMusic(BGMName, false);
}
}
void Game::ShowCardInfo(int code) {
CardData cd;
wchar_t formatBuffer[256];
......@@ -1424,17 +1215,17 @@ void Game::AddChatMsg(wchar_t* msg, int player) {
chatMsg[0].append(L": ");
break;
case 1: //from client
mainGame->PlaySoundEffect(SOUND_CHAT);
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.clientname);
chatMsg[0].append(L": ");
break;
case 2: //host tag
mainGame->PlaySoundEffect(SOUND_CHAT);
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.hostname_tag);
chatMsg[0].append(L": ");
break;
case 3: //client tag
mainGame->PlaySoundEffect(SOUND_CHAT);
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.clientname_tag);
chatMsg[0].append(L": ");
break;
......@@ -1443,7 +1234,7 @@ void Game::AddChatMsg(wchar_t* msg, int player) {
chatMsg[0].append(L": ");
break;
case 8: //system custom message, no prefix.
mainGame->PlaySoundEffect(SOUND_CHAT);
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(L"[System]: ");
break;
case 9: //error message
......
......@@ -98,8 +98,6 @@ public:
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay();
void RefreshSingleplay();
void RefreshBGMList();
void RefershBGMDir(std::wstring path, int scene);
void DrawSelectionLine(irr::video::S3DVertex* vec, bool strip, int width, float* cv);
void DrawBackGround();
void DrawLinkedZones(ClientCard* pcard);
......@@ -124,9 +122,6 @@ public:
void AddDebugMsg(char* msgbuf);
void ClearTextures();
void CloseDuelWindow();
void PlaySoundEffect(int sound);
void PlayMusic(char* song, bool loop);
void PlayBGM(int scene);
int LocalPlayer(int player);
const wchar_t* LocalName(int local_player);
......@@ -153,7 +148,6 @@ public:
std::list<FadingUnit> fadingList;
std::vector<int> logParam;
std::wstring chatMsg[8];
std::vector<std::wstring> BGMList[8];
int hideChatTimer;
bool hideChat;
......@@ -185,8 +179,6 @@ public:
bool is_building;
bool is_siding;
int bgm_scene;
ClientField dField;
DeckBuilder deckBuilder;
MenuHandler menuHandler;
......@@ -447,11 +439,6 @@ public:
irr::gui::IGUIButton* btnChainWhenAvail;
//cancel or finish
irr::gui::IGUIButton* btnCancelOrFinish;
//soundEngine
irrklang::ISoundEngine* engineSound;
irrklang::ISoundEngine* engineMusic;
irrklang::ISound* soundBGM;
};
extern Game* mainGame;
......
......@@ -6,6 +6,7 @@
#include "replay_mode.h"
#include "single_mode.h"
#include "image_manager.h"
#include "sound_manager.h"
#include "game.h"
namespace ygo {
......@@ -33,9 +34,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
switch(event.GUIEvent.EventType) {
case irr::gui::EGET_BUTTON_CLICKED: {
if(id < 110)
mainGame->PlaySoundEffect(SOUND_MENU);
soundManager.PlaySoundEffect(SOUND_MENU);
else
mainGame->PlaySoundEffect(SOUND_BUTTON);
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(id) {
case BUTTON_MODE_EXIT: {
mainGame->device->closeDevice();
......
......@@ -2,6 +2,7 @@
#include "duelclient.h"
#include "game.h"
#include "single_mode.h"
#include "sound_manager.h"
#include "../ocgcore/duel.h"
#include "../ocgcore/field.h"
#include "../ocgcore/mtrandom.h"
......@@ -313,7 +314,7 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->stMessage->setText(L"Error occurs.");
mainGame->PopupElement(mainGame->wMessage);
mainGame->PlaySoundEffect(SOUND_INFO);
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......
#include "single_mode.h"
#include "duelclient.h"
#include "game.h"
#include "sound_manager.h"
#include "../ocgcore/duel.h"
#include "../ocgcore/field.h"
#include "../ocgcore/mtrandom.h"
......@@ -179,7 +180,7 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->stMessage->setText(L"Error occurs.");
mainGame->PopupElement(mainGame->wMessage);
mainGame->PlaySoundEffect(SOUND_INFO);
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......@@ -786,7 +787,7 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stMessage, 310, mainGame->textFont, msg);
mainGame->PopupElement(mainGame->wMessage);
mainGame->PlaySoundEffect(SOUND_INFO);
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......
#include "sound_manager.h"
#ifdef IRRKLANG_STATIC
#include "../ikpmp3/ikpMP3.h"
#endif
namespace ygo {
SoundManager soundManager;
bool SoundManager::Init() {
bgm_scene = -1;
RefreshBGMList();
engineSound = irrklang::createIrrKlangDevice();
engineMusic = irrklang::createIrrKlangDevice();
if(!engineSound || !engineMusic) {
return false;
} else {
#ifdef IRRKLANG_STATIC
irrklang::ikpMP3Init(engineSound);
irrklang::ikpMP3Init(engineMusic);
#endif
return true;
}
}
void SoundManager::RefreshBGMList() {
RefershBGMDir(L"", BGM_DUEL);
RefershBGMDir(L"duel/", BGM_DUEL);
RefershBGMDir(L"menu/", BGM_MENU);
RefershBGMDir(L"deck/", BGM_DECK);
RefershBGMDir(L"advantage/", BGM_ADVANTAGE);
RefershBGMDir(L"disadvantage/", BGM_DISADVANTAGE);
RefershBGMDir(L"win/", BGM_WIN);
RefershBGMDir(L"lose/", BGM_LOSE);
}
void SoundManager::RefershBGMDir(std::wstring path, int scene) {
#ifdef _WIN32
WIN32_FIND_DATAW fdataw;
std::wstring search = L"./sound/BGM/" + path + L"*.mp3";
HANDLE fh = FindFirstFileW(search.c_str(), &fdataw);
if(fh == INVALID_HANDLE_VALUE)
return;
do {
if(!(fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
std::wstring filename = path + (std::wstring)fdataw.cFileName;
BGMList[BGM_ALL].push_back(filename);
BGMList[scene].push_back(filename);
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
#else
DIR * dir;
struct dirent * dirp;
if((dir = opendir("./sound/BGM/*.mp3")) == NULL)
return;
while((dirp = readdir(dir)) != NULL) {
size_t len = strlen(dirp->d_name);
if(len < 5 || strcasecmp(dirp->d_name + len - 4, ".mp3") != 0)
continue;
wchar_t wname[256];
BufferIO::DecodeUTF8(dirp->d_name, wname);
BGMList[BGM_ALL].push_back(wname);
}
closedir(dir);
#endif
}
void SoundManager::PlaySoundEffect(int sound) {
if(!mainGame->chkEnableSound->isChecked())
return;
switch(sound) {
case SOUND_SUMMON: {
engineSound->play2D("./sound/summon.wav");
break;
}
case SOUND_SPECIAL_SUMMON: {
engineSound->play2D("./sound/specialsummon.wav");
break;
}
case SOUND_ACTIVATE: {
engineSound->play2D("./sound/activate.wav");
break;
}
case SOUND_SET: {
engineSound->play2D("./sound/set.wav");
break;
}
case SOUND_FILP: {
engineSound->play2D("./sound/flip.wav");
break;
}
case SOUND_REVEAL: {
engineSound->play2D("./sound/reveal.wav");
break;
}
case SOUND_EQUIP: {
engineSound->play2D("./sound/equip.wav");
break;
}
case SOUND_DESTROYED: {
engineSound->play2D("./sound/destroyed.wav");
break;
}
case SOUND_BANISHED: {
engineSound->play2D("./sound/banished.wav");
break;
}
case SOUND_TOKEN: {
engineSound->play2D("./sound/token.wav");
break;
}
case SOUND_ATTACK: {
engineSound->play2D("./sound/attack.wav");
break;
}
case SOUND_DIRECT_ATTACK: {
engineSound->play2D("./sound/directattack.wav");
break;
}
case SOUND_DRAW: {
engineSound->play2D("./sound/draw.wav");
break;
}
case SOUND_SHUFFLE: {
engineSound->play2D("./sound/shuffle.wav");
break;
}
case SOUND_DAMAGE: {
engineSound->play2D("./sound/damage.wav");
break;
}
case SOUND_RECOVER: {
engineSound->play2D("./sound/gainlp.wav");
break;
}
case SOUND_COUNTER_ADD: {
engineSound->play2D("./sound/addcounter.wav");
break;
}
case SOUND_COUNTER_REMOVE: {
engineSound->play2D("./sound/removecounter.wav");
break;
}
case SOUND_COIN: {
engineSound->play2D("./sound/coinflip.wav");
break;
}
case SOUND_DICE: {
engineSound->play2D("./sound/diceroll.wav");
break;
}
case SOUND_NEXT_TURN: {
engineSound->play2D("./sound/nextturn.wav");
break;
}
case SOUND_PHASE: {
engineSound->play2D("./sound/phase.wav");
break;
}
case SOUND_MENU: {
engineSound->play2D("./sound/menu.wav");
break;
}
case SOUND_BUTTON: {
engineSound->play2D("./sound/button.wav");
break;
}
case SOUND_INFO: {
engineSound->play2D("./sound/info.wav");
break;
}
case SOUND_QUESTION: {
engineSound->play2D("./sound/question.wav");
break;
}
case SOUND_CARD_PICK: {
engineSound->play2D("./sound/cardpick.wav");
break;
}
case SOUND_CARD_DROP: {
engineSound->play2D("./sound/carddrop.wav");
break;
}
case SOUND_PLAYER_ENTER: {
engineSound->play2D("./sound/playerenter.wav");
break;
}
case SOUND_CHAT: {
engineSound->play2D("./sound/chatmessage.wav");
break;
}
default:
break;
}
engineSound->setSoundVolume(mainGame->gameConf.sound_volume);
}
void SoundManager::PlayMusic(char* song, bool loop) {
if(!mainGame->chkEnableMusic->isChecked())
return;
if(!engineMusic->isCurrentlyPlaying(song)) {
engineMusic->stopAllSounds();
soundBGM = engineMusic->play2D(song, loop, false, true);
engineMusic->setSoundVolume(mainGame->gameConf.music_volume);
}
}
void SoundManager::PlayBGM(int scene) {
if(!mainGame->chkEnableMusic->isChecked())
return;
if(!mainGame->chkMusicMode->isChecked())
scene = BGM_ALL;
char BGMName[1024];
if(scene != bgm_scene || (soundBGM && soundBGM->isFinished())) {
int count = BGMList[scene].size();
if(count <= 0)
return;
bgm_scene = scene;
int bgm = rand() % count;
auto name = BGMList[scene][bgm].c_str();
wchar_t fname[1024];
myswprintf(fname, L"./sound/BGM/%ls", name);
BufferIO::EncodeUTF8(fname, BGMName);
PlayMusic(BGMName, false);
}
}
void SoundManager::StopBGM() {
engineMusic->stopAllSounds();
}
void SoundManager::SetSoundVolume(double volume) {
engineSound->setSoundVolume(volume);
}
void SoundManager::SetMusicVolume(double volume) {
engineMusic->setSoundVolume(volume);
}
}
#ifndef SOUNDMANAGER_H
#define SOUNDMANAGER_H
#include "config.h"
#include "game.h"
#include <vector>
namespace ygo {
class SoundManager {
private:
std::vector<std::wstring> BGMList[8];
int bgm_scene;
irrklang::ISoundEngine* engineSound;
irrklang::ISoundEngine* engineMusic;
irrklang::ISound* soundBGM;
void RefershBGMDir(std::wstring path, int scene);
public:
bool Init();
void RefreshBGMList();
void PlaySoundEffect(int sound);
void PlayMusic(char* song, bool loop);
void PlayBGM(int scene);
void StopBGM();
void SetSoundVolume(double volume);
void SetMusicVolume(double volume);
};
extern SoundManager soundManager;
}
#endif //SOUNDMANAGER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment