Commit ffc16757 authored by mercury233's avatar mercury233

Merge branch 'sound' into test

parents cc2fedfc 65f949f8
......@@ -1018,7 +1018,6 @@ bool ClientField::ShowSelectSum(bool panelmode) {
BufferIO::CopyWStrRef(dataManager.GetSysString(210), pwbuf, 256);
mainGame->stQMessage->setText(wbuf);
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
}
} else {
select_ready = false;
......@@ -1040,7 +1039,6 @@ bool ClientField::ShowSelectSum(bool panelmode) {
BufferIO::CopyWStrRef(dataManager.GetSysString(210), pwbuf, 256);
mainGame->stQMessage->setText(wbuf);
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
}
} else
select_ready = false;
......
......@@ -48,10 +48,6 @@ inline int _wtoi(const wchar_t * s) {
#endif
#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,12 @@ 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);
mainGame->gMutex.Unlock();
prev_operation = id;
break;
......@@ -184,7 +184,6 @@ 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);
mainGame->gMutex.Unlock();
prev_operation = id;
break;
......@@ -194,7 +193,6 @@ 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);
mainGame->gMutex.Unlock();
prev_operation = id;
break;
......@@ -358,7 +356,6 @@ 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);
mainGame->gMutex.Unlock();
prev_operation = id;
break;
......@@ -516,7 +513,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 +543,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 +561,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 +578,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 +605,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 +624,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 "materials.h"
#include "image_manager.h"
#include "deck_manager.h"
#include "sound_manager.h"
#include "duelclient.h"
#include "../ocgcore/field.h"
......@@ -1008,6 +1009,7 @@ void Game::HideElement(irr::gui::IGUIElement * win, bool set_action) {
fadingList.push_back(fu);
}
void Game::PopupElement(irr::gui::IGUIElement * element, int hideframe) {
soundManager.PlayDialogSound(element);
element->getParent()->bringToFront(element);
if(!mainGame->is_building)
dField.panel = element;
......
This diff is collapsed.
......@@ -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);
......@@ -148,7 +149,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;
......@@ -156,7 +157,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;
......@@ -164,7 +165,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;
......@@ -172,7 +173,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()) {
......@@ -282,7 +283,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
else {
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
ShowCancelOrFinishButton(0);
}
if (mainGame->wOptions->isVisible()) {
......@@ -304,13 +304,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: {
......@@ -344,7 +344,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: {
......@@ -397,7 +397,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)
......@@ -406,7 +406,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)
......@@ -415,7 +415,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 {
......@@ -433,13 +433,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;
......@@ -1456,7 +1456,6 @@ 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);
}
}
} else {
......@@ -1632,7 +1631,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
mainGame->HideElement(mainGame->wQuery, true);
} else {
mainGame->PopupElement(mainGame->wQuery);
mainGame->PlaySoundEffect(SOUND_QUESTION);
ShowCancelOrFinishButton(0);
}
if(mainGame->wOptions->isVisible()) {
......@@ -1985,7 +1983,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;
......@@ -2003,7 +2001,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
}
case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked())
mainGame->engineMusic->stopAllSounds();
soundManager.StopBGM();
return true;
break;
}
......@@ -2047,8 +2045,9 @@ 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);
return true;
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();
......@@ -670,30 +670,26 @@ 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);
chkEnableSound->setVisible(false);
chkEnableMusic->setChecked(false);
chkEnableMusic->setEnabled(false);
chkEnableMusic->setVisible(false);
scrSoundVolume->setVisible(false);
scrMusicVolume->setVisible(false);
chkMusicMode->setEnabled(false);
chkMusicMode->setVisible(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;
......@@ -724,15 +720,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();
......@@ -741,11 +737,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();
......@@ -797,8 +793,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) {
......@@ -986,47 +980,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::RefreshBot() {
if(!gameConf.enable_bot_mode)
return;
......@@ -1256,163 +1209,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];
......@@ -1504,17 +1300,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;
......@@ -1523,7 +1319,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
......
......@@ -107,8 +107,6 @@ public:
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay();
void RefreshSingleplay();
void RefreshBGMList();
void RefershBGMDir(std::wstring path, int scene);
void RefreshBot();
void DrawSelectionLine(irr::video::S3DVertex* vec, bool strip, int width, float* cv);
void DrawBackGround();
......@@ -134,9 +132,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);
......@@ -163,7 +158,6 @@ public:
std::list<FadingUnit> fadingList;
std::vector<int> logParam;
std::wstring chatMsg[8];
std::vector<std::wstring> BGMList[8];
std::vector<BotInfo> botInfo;
int hideChatTimer;
......@@ -196,8 +190,6 @@ public:
bool is_building;
bool is_siding;
int bgm_scene;
ClientField dField;
DeckBuilder deckBuilder;
MenuHandler menuHandler;
......@@ -466,11 +458,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();
......
......@@ -313,7 +313,6 @@ 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);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......
......@@ -179,7 +179,6 @@ 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);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......@@ -786,7 +785,6 @@ 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);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
......
#include "sound_manager.h"
namespace ygo {
SoundManager soundManager;
bool SoundManager::Init() {
#ifdef YGOPRO_USE_IRRKLANG
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;
}
#endif // YGOPRO_USE_IRRKLANG
// TODO: Implement other sound engines
return false;
}
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) {
#ifdef YGOPRO_USE_IRRKLANG
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);
#endif
}
void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
if(element == mainGame->wMessage) {
PlaySoundEffect(SOUND_INFO);
} else if(element == mainGame->wQuery) {
PlaySoundEffect(SOUND_QUESTION);
} else if(element == mainGame->wOptions) {
PlaySoundEffect(SOUND_QUESTION);
} else if(element == mainGame->wANAttribute) {
PlaySoundEffect(SOUND_QUESTION);
} else if(element == mainGame->wANCard) {
PlaySoundEffect(SOUND_QUESTION);
} else if(element == mainGame->wANNumber) {
PlaySoundEffect(SOUND_QUESTION);
} else if(element == mainGame->wANRace) {
PlaySoundEffect(SOUND_QUESTION);
} else if(element == mainGame->wReplaySave) {
PlaySoundEffect(SOUND_QUESTION);
}
}
void SoundManager::PlayMusic(char* song, bool loop) {
#ifdef YGOPRO_USE_IRRKLANG
if(!mainGame->chkEnableMusic->isChecked())
return;
if(!engineMusic->isCurrentlyPlaying(song)) {
engineMusic->stopAllSounds();
soundBGM = engineMusic->play2D(song, loop, false, true);
engineMusic->setSoundVolume(mainGame->gameConf.music_volume);
}
#endif
}
void SoundManager::PlayBGM(int scene) {
#ifdef YGOPRO_USE_IRRKLANG
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);
}
#endif
}
void SoundManager::StopBGM() {
#ifdef YGOPRO_USE_IRRKLANG
engineMusic->stopAllSounds();
#endif
}
void SoundManager::SetSoundVolume(double volume) {
#ifdef YGOPRO_USE_IRRKLANG
engineSound->setSoundVolume(volume);
#endif
}
void SoundManager::SetMusicVolume(double volume) {
#ifdef YGOPRO_USE_IRRKLANG
engineMusic->setSoundVolume(volume);
#endif
}
}
#ifndef SOUNDMANAGER_H
#define SOUNDMANAGER_H
#include "config.h"
#include "game.h"
#ifdef YGOPRO_USE_IRRKLANG
#include <irrKlang.h>
#ifdef IRRKLANG_STATIC
#include "../ikpmp3/ikpMP3.h"
#endif
#endif
namespace ygo {
class SoundManager {
private:
std::vector<std::wstring> BGMList[8];
int bgm_scene;
#ifdef YGOPRO_USE_IRRKLANG
irrklang::ISoundEngine* engineSound;
irrklang::ISoundEngine* engineMusic;
irrklang::ISound* soundBGM;
#endif
void RefershBGMDir(std::wstring path, int scene);
public:
bool Init();
void RefreshBGMList();
void PlaySoundEffect(int sound);
void PlayDialogSound(irr::gui::IGUIElement * element);
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