Commit 5a55adf1 authored by mercury233's avatar mercury233 Committed by GitHub

Sound (#2071)

parent 96442947
......@@ -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>
......@@ -122,6 +123,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
switch(event.GUIEvent.EventType) {
case irr::gui::EGET_BUTTON_CLICKED: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(id) {
case BUTTON_CLEAR_DECK: {
mainGame->gMutex.Lock();
......@@ -228,6 +230,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case BUTTON_SIDE_OK: {
if(deckManager.current_deck.main.size() != pre_mainc || deckManager.current_deck.extra.size() != pre_extrac
|| deckManager.current_deck.side.size() != pre_sidec) {
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1410));
break;
}
......@@ -516,6 +519,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
is_starting_dragging = false;
if(!is_draging)
break;
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
bool pushed = false;
if(hovered_pos == 1)
pushed = push_main(draging_pointer, hovered_seq);
......@@ -545,6 +549,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager._datas.end())
break;
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
if(hovered_pos == 1) {
if(push_side(pointer))
pop_main(hovered_seq);
......@@ -562,6 +567,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(!is_draging) {
if(hovered_pos == 0 || hovered_seq == -1)
break;
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
if(hovered_pos == 1) {
pop_main(hovered_seq);
} else if(hovered_pos == 2) {
......@@ -578,6 +584,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
push_side(pointer);
}
} else {
soundManager.PlaySoundEffect(SOUND_CARD_PICK);
if(click_pos == 1) {
push_side(draging_pointer);
} else if(click_pos == 2) {
......@@ -604,6 +611,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
auto pointer = dataManager.GetCodePointer(hovered_code);
if(!check_limit(pointer))
break;
soundManager.PlaySoundEffect(SOUND_CARD_PICK);
if (hovered_pos == 1) {
if(!push_main(pointer))
push_side(pointer);
......@@ -622,6 +630,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case irr::EMIE_MOUSE_MOVED: {
if(is_starting_dragging) {
is_draging = true;
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,6 +41,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
case BUTTON_FIRST:
case BUTTON_SECOND: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->HideElement(mainGame->wFTSelect);
CTOS_TPResult cstr;
cstr.res = BUTTON_SECOND - id;
......@@ -49,6 +51,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_REPLAY_START: {
if(!mainGame->dInfo.isReplay)
break;
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->btnReplayStart->setVisible(false);
mainGame->btnReplayPause->setVisible(true);
mainGame->btnReplayStep->setVisible(false);
......@@ -59,6 +62,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_REPLAY_PAUSE: {
if(!mainGame->dInfo.isReplay)
break;
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->btnReplayStart->setVisible(true);
mainGame->btnReplayPause->setVisible(false);
mainGame->btnReplayStep->setVisible(true);
......@@ -69,16 +73,19 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_REPLAY_STEP: {
if(!mainGame->dInfo.isReplay)
break;
soundManager.PlaySoundEffect(SOUND_BUTTON);
ReplayMode::Pause(false, true);
break;
}
case BUTTON_REPLAY_EXIT: {
if(!mainGame->dInfo.isReplay)
break;
soundManager.PlaySoundEffect(SOUND_BUTTON);
ReplayMode::StopReplay();
break;
}
case BUTTON_REPLAY_SWAP: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
if(mainGame->dInfo.isReplay)
ReplayMode::SwapField();
else if (mainGame->dInfo.player_type == 7)
......@@ -88,24 +95,28 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_REPLAY_UNDO: {
if(!mainGame->dInfo.isReplay)
break;
soundManager.PlaySoundEffect(SOUND_BUTTON);
ReplayMode::Undo();
break;
}
case BUTTON_REPLAY_SAVE: {
if(mainGame->ebRSName->getText()[0] == 0)
break;
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->actionParam = 1;
mainGame->HideElement(mainGame->wReplaySave);
mainGame->replaySignal.Set();
break;
}
case BUTTON_REPLAY_CANCEL: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->actionParam = 0;
mainGame->HideElement(mainGame->wReplaySave);
mainGame->replaySignal.Set();
break;
}
case BUTTON_LEAVE_GAME: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
if(mainGame->dInfo.isSingleMode) {
mainGame->singleSignal.SetNoWait(true);
SingleMode::StopPlay(false);
......@@ -114,6 +125,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(mainGame->dInfo.player_type == 7) {
DuelClient::StopClient();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isFinished = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->stTip->setVisible(false);
mainGame->wCardImg->setVisible(false);
......@@ -137,6 +149,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_CHAIN_IGNORE: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->ignore_chain = mainGame->btnChainIgnore->isPressed();
mainGame->always_chain = false;
mainGame->chain_when_avail = false;
......@@ -144,6 +157,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_CHAIN_ALWAYS: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->always_chain = mainGame->btnChainAlways->isPressed();
mainGame->ignore_chain = false;
mainGame->chain_when_avail = false;
......@@ -151,6 +165,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_CHAIN_WHENAVAIL: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->chain_when_avail = mainGame->btnChainWhenAvail->isPressed();
mainGame->always_chain = false;
mainGame->ignore_chain = false;
......@@ -158,15 +173,18 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_CANCEL_OR_FINISH: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
CancelOrFinish();
break;
}
case BUTTON_MSG_OK: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->HideElement(mainGame->wMessage);
mainGame->actionSignal.Set();
break;
}
case BUTTON_YES: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(mainGame->dInfo.curMsg) {
case MSG_SELECT_YESNO:
case MSG_SELECT_EFFECTYN: {
......@@ -200,6 +218,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_NO: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(mainGame->dInfo.curMsg) {
case MSG_SELECT_YESNO:
case MSG_SELECT_EFFECTYN: {
......@@ -252,6 +271,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_OPTION_PREV: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
selected_option--;
mainGame->btnOptionn->setVisible(true);
if(selected_option == 0)
......@@ -260,6 +280,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_OPTION_NEXT: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
selected_option++;
mainGame->btnOptionp->setVisible(true);
if(selected_option == select_options.size() - 1)
......@@ -268,6 +289,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_OPTION_OK: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
if (mainGame->dInfo.curMsg == MSG_SELECT_OPTION) {
DuelClient::SetResponseI(selected_option);
} else {
......@@ -285,11 +307,13 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_ANNUMBER_OK: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
DuelClient::SetResponseI(mainGame->cbANNumber->getSelected());
mainGame->HideElement(mainGame->wANNumber, true);
break;
}
case BUTTON_ANCARD_OK: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
int sel = mainGame->lstANCard->getSelected();
if(sel == -1)
break;
......@@ -1708,6 +1732,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
case irr::gui::EGET_BUTTON_CLICKED: {
switch(id) {
case BUTTON_CLEAR_LOG: {
soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->lstLog->clear();
mainGame->logParam.clear();
return true;
......@@ -1723,6 +1748,12 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true;
break;
}
case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked())
soundManager.StopBGM();
return true;
break;
}
}
break;
}
......@@ -1764,6 +1795,14 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true;
break;
}
case SCROLL_VOLUME: {
mainGame->gameConf.sound_volume = (double)mainGame->scrSoundVolume->getPos() / 100;
mainGame->gameConf.music_volume = (double)mainGame->scrMusicVolume->getPos() / 100;
soundManager.SetSoundVolume(mainGame->gameConf.sound_volume);
soundManager.SetMusicVolume(mainGame->gameConf.music_volume);
return true;
break;
}
}
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"
......@@ -281,6 +282,27 @@ bool Game::Initialize() {
posY += 30;
chkAutoSearch = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_AUTO_SEARCH, dataManager.GetSysString(1358));
chkAutoSearch->setChecked(gameConf.auto_search_limit >= 0);
posY += 30;
chkEnableSound = env->addCheckBox(gameConf.enable_sound, rect<s32>(posX, posY, posX + 120, posY + 25), tabSystem, -1, dataManager.GetSysString(1279));
chkEnableSound->setChecked(gameConf.enable_sound);
scrSoundVolume = env->addScrollBar(true, rect<s32>(posX + 126, posY + 4, posX + 260, posY + 21), tabSystem, SCROLL_VOLUME);
scrSoundVolume->setMax(100);
scrSoundVolume->setMin(0);
scrSoundVolume->setPos(gameConf.sound_volume * 100);
scrSoundVolume->setLargeStep(1);
scrSoundVolume->setSmallStep(1);
posY += 30;
chkEnableMusic = env->addCheckBox(gameConf.enable_music, rect<s32>(posX, posY, posX + 120, posY + 25), tabSystem, CHECKBOX_ENABLE_MUSIC, dataManager.GetSysString(1280));
chkEnableMusic->setChecked(gameConf.enable_music);
scrMusicVolume = env->addScrollBar(true, rect<s32>(posX + 126, posY + 4, posX + 260, posY + 21), tabSystem, SCROLL_VOLUME);
scrMusicVolume->setMax(100);
scrMusicVolume->setMin(0);
scrMusicVolume->setPos(gameConf.music_volume * 100);
scrMusicVolume->setLargeStep(1);
scrMusicVolume->setSmallStep(1);
posY += 30;
chkMusicMode = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, -1, dataManager.GetSysString(1281));
chkMusicMode->setChecked(gameConf.music_mode != 0);
//
wHand = env->addWindow(rect<s32>(500, 450, 825, 605), false, L"");
wHand->getCloseButton()->setVisible(false);
......@@ -639,6 +661,18 @@ bool Game::Initialize() {
stTip->setVisible(false);
device->setEventReceiver(&menuHandler);
LoadConfig();
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);
}
env->getSkin()->setFont(guiFont);
env->setFocus(wMainMenu);
for (u32 i = 0; i < EGDC_COUNT; ++i) {
......@@ -675,6 +709,16 @@ void Game::MainLoop() {
driver->beginScene(true, true, SColor(0, 0, 0, 0));
gMutex.Lock();
if(dInfo.isStarted || dInfo.isReplaySkiping) {
if(dInfo.isFinished && showcardcode == 1)
soundManager.PlayBGM(BGM_WIN);
else if(dInfo.isFinished && (showcardcode == 2 || showcardcode == 3))
soundManager.PlayBGM(BGM_LOSE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] <= dInfo.lp[1] / 2)
soundManager.PlayBGM(BGM_DISADVANTAGE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] >= dInfo.lp[1] * 2)
soundManager.PlayBGM(BGM_ADVANTAGE);
else
soundManager.PlayBGM(BGM_DUEL);
DrawBackImage(imageManager.tBackGround);
DrawBackGround();
DrawCards();
......@@ -683,9 +727,11 @@ void Game::MainLoop() {
driver->setMaterial(irr::video::IdentityMaterial);
driver->clearZBuffer();
} else if(is_building) {
soundManager.PlayBGM(BGM_DECK);
DrawBackImage(imageManager.tBackGround_deck);
DrawDeckBd();
} else {
soundManager.PlayBGM(BGM_MENU);
DrawBackImage(imageManager.tBackGround_menu);
}
DrawGUI();
......@@ -1004,6 +1050,11 @@ void Game::LoadConfig() {
gameConf.chkIgnoreDeckChanges = 0;
gameConf.defaultOT = 1;
gameConf.enable_bot_mode = 0;
gameConf.enable_sound = true;
gameConf.sound_volume = 0.5;
gameConf.enable_music = true;
gameConf.music_volume = 0.5;
gameConf.music_mode = 1;
while(fgets(linebuf, 256, fp)) {
sscanf(linebuf, "%s = %s", strbuf, valbuf);
if(!strcmp(strbuf, "antialias")) {
......@@ -1066,6 +1117,16 @@ void Game::LoadConfig() {
gameConf.defaultOT = atoi(valbuf);
} else if(!strcmp(strbuf, "enable_bot_mode")) {
gameConf.enable_bot_mode = atoi(valbuf);
} else if(!strcmp(strbuf, "enable_sound")) {
gameConf.enable_sound = atoi(valbuf) > 0;
} else if(!strcmp(strbuf, "sound_volume")) {
gameConf.sound_volume = atof(valbuf) / 100;
} else if(!strcmp(strbuf, "enable_music")) {
gameConf.enable_music = atoi(valbuf) > 0;
} else if(!strcmp(strbuf, "music_volume")) {
gameConf.music_volume = atof(valbuf) / 100;
} else if(!strcmp(strbuf, "music_mode")) {
gameConf.music_mode = atoi(valbuf);
} else {
// options allowing multiple words
sscanf(linebuf, "%s = %240[^\n]", strbuf, valbuf);
......@@ -1126,6 +1187,16 @@ void Game::SaveConfig() {
fprintf(fp, "ignore_deck_changes = %d\n", (chkIgnoreDeckChanges->isChecked() ? 1 : 0));
fprintf(fp, "default_ot = %d\n", gameConf.defaultOT);
fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode);
fprintf(fp, "enable_sound = %d\n", (chkEnableSound->isChecked() ? 1 : 0));
fprintf(fp, "enable_music = %d\n", (chkEnableMusic->isChecked() ? 1 : 0));
fprintf(fp, "#Volume of sound and music, between 0 and 100\n");
int vol = gameConf.sound_volume * 100;
if(vol < 0) vol = 0; else if(vol > 100) vol = 100;
fprintf(fp, "sound_volume = %d\n", vol);
vol = gameConf.music_volume * 100;
if(vol < 0) vol = 0; else if(vol > 100) vol = 100;
fprintf(fp, "music_volume = %d\n", vol);
fprintf(fp, "music_mode = %d\n", (chkMusicMode->isChecked() ? 1 : 0));
fclose(fp);
}
void Game::ShowCardInfo(int code) {
......@@ -1219,14 +1290,17 @@ void Game::AddChatMsg(wchar_t* msg, int player) {
chatMsg[0].append(L": ");
break;
case 1: //from client
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.clientname);
chatMsg[0].append(L": ");
break;
case 2: //host tag
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.hostname_tag);
chatMsg[0].append(L": ");
break;
case 3: //client tag
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.clientname_tag);
chatMsg[0].append(L": ");
break;
......@@ -1235,6 +1309,7 @@ void Game::AddChatMsg(wchar_t* msg, int player) {
chatMsg[0].append(L": ");
break;
case 8: //system custom message, no prefix.
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(L"[System]: ");
break;
case 9: //error message
......
......@@ -42,10 +42,16 @@ struct Config {
int chkIgnoreDeckChanges;
int defaultOT;
int enable_bot_mode;
bool enable_sound;
bool enable_music;
double sound_volume;
double music_volume;
int music_mode;
};
struct DuelInfo {
bool isStarted;
bool isFinished;
bool isReplay;
bool isReplaySkiping;
bool isFirst;
......@@ -220,6 +226,9 @@ public:
irr::gui::IGUIStaticText* stSetName;
irr::gui::IGUIStaticText* stText;
irr::gui::IGUIScrollBar* scrCardText;
irr::gui::IGUIListBox* lstLog;
irr::gui::IGUIButton* btnClearLog;
irr::gui::IGUIButton* btnSaveLog;
irr::gui::IGUICheckBox* chkMAutoPos;
irr::gui::IGUICheckBox* chkSTAutoPos;
irr::gui::IGUICheckBox* chkRandomPos;
......@@ -229,9 +238,11 @@ public:
irr::gui::IGUICheckBox* chkHideHintButton;
irr::gui::IGUICheckBox* chkIgnoreDeckChanges;
irr::gui::IGUICheckBox* chkAutoSearch;
irr::gui::IGUIListBox* lstLog;
irr::gui::IGUIButton* btnClearLog;
irr::gui::IGUIButton* btnSaveLog;
irr::gui::IGUICheckBox* chkEnableSound;
irr::gui::IGUICheckBox* chkEnableMusic;
irr::gui::IGUIScrollBar* scrSoundVolume;
irr::gui::IGUIScrollBar* scrMusicVolume;
irr::gui::IGUICheckBox* chkMusicMode;
//main menu
irr::gui::IGUIWindow* wMainMenu;
irr::gui::IGUIButton* btnLanMode;
......@@ -597,6 +608,10 @@ extern Game* mainGame;
#define BUTTON_LOAD_SINGLEPLAY 351
#define BUTTON_CANCEL_SINGLEPLAY 352
#define CHECKBOX_AUTO_SEARCH 360
#define CHECKBOX_ENABLE_SOUND 361
#define CHECKBOX_ENABLE_MUSIC 362
#define SCROLL_VOLUME 363
#define COMBOBOX_SORTTYPE 370
#define COMBOBOX_LIMIT 371
......
......@@ -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 {
......@@ -50,6 +51,10 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case irr::gui::EGET_BUTTON_CLICKED: {
if(id < 110)
soundManager.PlaySoundEffect(SOUND_MENU);
else
soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(id) {
case BUTTON_MODE_EXIT: {
mainGame->device->closeDevice();
......@@ -84,6 +89,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int status = evutil_getaddrinfo(hostname, port, &hints, &answer);
if(status != 0) {
mainGame->gMutex.Lock();
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1412));
mainGame->gMutex.Unlock();
break;
......
......@@ -6,12 +6,22 @@ project "ygopro"
files { "**.cpp", "**.cc", "**.c", "**.h" }
excludes "lzma/**"
includedirs { "../ocgcore" }
links { "ocgcore", "clzma", "Irrlicht", "freetype", "sqlite3", "lua" , "event"}
links { "ocgcore", "clzma", "Irrlicht", "freetype", "sqlite3", "lua" , "event" }
configuration "windows"
files "ygopro.rc"
excludes "CGUIButton.cpp"
includedirs { "../irrlicht/include", "../freetype/include", "../event/include", "../sqlite3" }
if USE_IRRKLANG then
defines { "YGOPRO_USE_IRRKLANG" }
links { "irrKlang" }
includedirs { "../irrklang/include" }
libdirs { "../irrklang/lib/Win32-visualStudio" }
if IRRKLANG_PRO then
defines { "IRRKLANG_STATIC" }
links { "ikpmp3" }
end
end
links { "opengl32", "ws2_32", "winmm", "gdi32", "kernel32", "user32", "imm32" }
configuration {"windows", "not vs*"}
includedirs { "/mingw/include/irrlicht", "/mingw/include/freetype2" }
......@@ -21,3 +31,11 @@ project "ygopro"
includedirs { "/usr/include/lua", "/usr/include/lua5.3", "/usr/include/lua/5.3", "/usr/include/irrlicht", "/usr/include/freetype2" }
excludes { "COSOperator.*" }
links { "event_pthreads", "GL", "dl", "pthread" }
configuration "linux"
if USE_IRRKLANG then
defines { "YGOPRO_USE_IRRKLANG" }
links { "IrrKlang" }
linkoptions{ "-Wl,-rpath=./irrklang/bin/linux-gcc-64/" }
libdirs { "../irrklang/bin/linux-gcc-64" }
includedirs { "../irrklang/include" }
end
......@@ -78,6 +78,7 @@ int ReplayMode::ReplayThread(void* param) {
return 0;
}
mainGame->dInfo.isStarted = true;
mainGame->dInfo.isFinished = false;
mainGame->dInfo.isReplay = true;
mainGame->dInfo.isReplaySkiping = (skip_turn > 0);
char engineBuffer[0x1000];
......@@ -122,6 +123,7 @@ int ReplayMode::ReplayThread(void* param) {
if(step == 0) {
Pause(true, false);
mainGame->dInfo.isStarted = true;
mainGame->dInfo.isFinished = false;
mainGame->dInfo.isReplaySkiping = false;
mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock();
......@@ -236,6 +238,7 @@ void ReplayMode::EndDuel() {
mainGame->actionSignal.Wait();
mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isFinished = true;
mainGame->dInfo.isReplay = false;
mainGame->gMutex.Unlock();
mainGame->closeDoneSignal.Reset();
......@@ -253,6 +256,7 @@ void ReplayMode::EndDuel() {
void ReplayMode::Restart(bool refresh) {
end_duel(pduel);
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isFinished = true;
mainGame->dField.Clear();
//mainGame->device->setEventReceiver(&mainGame->dField);
cur_replay.Rewind();
......@@ -265,6 +269,7 @@ void ReplayMode::Restart(bool refresh) {
if(refresh) {
mainGame->dField.RefreshAllCards();
mainGame->dInfo.isStarted = true;
mainGame->dInfo.isFinished = false;
//mainGame->dInfo.isReplay = true;
}
skip_turn = 0;
......@@ -833,6 +838,7 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
if(skip_step == 0) {
Pause(true, false);
mainGame->dInfo.isStarted = true;
mainGame->dInfo.isFinished = false;
mainGame->dInfo.isReplaySkiping = false;
mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock();
......
......@@ -97,6 +97,7 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->dField.Clear();
mainGame->dInfo.isFirst = true;
mainGame->dInfo.isStarted = true;
mainGame->dInfo.isFinished = false;
mainGame->dInfo.isSingleMode = true;
mainGame->device->setEventReceiver(&mainGame->dField);
mainGame->gMutex.Unlock();
......@@ -150,6 +151,7 @@ int SingleMode::SinglePlayThread(void* param) {
if(!is_closing) {
mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isFinished = true;
mainGame->dInfo.isSingleMode = false;
mainGame->gMutex.Unlock();
mainGame->closeDoneSignal.Reset();
......
#include "sound_manager.h"
#ifndef _WIN32
#include <dirent.h>
#endif
#ifdef IRRKLANG_STATIC
#include "../ikpmp3/ikpMP3.h"
#endif
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(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"*.*";
HANDLE fh = FindFirstFileW(search.c_str(), &fdataw);
if(fh == INVALID_HANDLE_VALUE)
return;
do {
size_t len = wcslen(fdataw.cFileName);
if((fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || len < 5
|| !(_wcsicmp(fdataw.cFileName + len - 4, L".mp3") == 0 || _wcsicmp(fdataw.cFileName + len - 4, L".ogg") == 0))
continue;
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;
std::wstring wsearchpath = L"./sound/BGM/" + path;
char searchpath[256];
BufferIO::EncodeUTF8(wsearchpath.c_str(), searchpath);
if((dir = opendir(searchpath)) == 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 || strcasecmp(dirp->d_name + len - 4, ".ogg")))
continue;
wchar_t wname[256];
BufferIO::DecodeUTF8(dirp->d_name, wname);
std::wstring filename = path + (std::wstring)wname;
BGMList[BGM_ALL].push_back(filename);
BGMList[scene].push_back(filename);
}
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 "game.h"
#ifdef YGOPRO_USE_IRRKLANG
#include <irrKlang.h>
#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;
#define SOUND_SUMMON 101
#define SOUND_SPECIAL_SUMMON 102
#define SOUND_ACTIVATE 103
#define SOUND_SET 104
#define SOUND_FILP 105
#define SOUND_REVEAL 106
#define SOUND_EQUIP 107
#define SOUND_DESTROYED 108
#define SOUND_BANISHED 109
#define SOUND_TOKEN 110
#define SOUND_ATTACK 201
#define SOUND_DIRECT_ATTACK 202
#define SOUND_DRAW 203
#define SOUND_SHUFFLE 204
#define SOUND_DAMAGE 205
#define SOUND_RECOVER 206
#define SOUND_COUNTER_ADD 207
#define SOUND_COUNTER_REMOVE 208
#define SOUND_COIN 209
#define SOUND_DICE 210
#define SOUND_NEXT_TURN 211
#define SOUND_PHASE 212
#define SOUND_MENU 301
#define SOUND_BUTTON 302
#define SOUND_INFO 303
#define SOUND_QUESTION 304
#define SOUND_CARD_PICK 305
#define SOUND_CARD_DROP 306
#define SOUND_PLAYER_ENTER 307
#define SOUND_CHAT 308
#define BGM_ALL 0
#define BGM_DUEL 1
#define BGM_MENU 2
#define BGM_DECK 3
#define BGM_ADVANTAGE 4
#define BGM_DISADVANTAGE 5
#define BGM_WIN 6
#define BGM_LOSE 7
}
#endif //SOUNDMANAGER_H
summon.wav
specialsummon.wav
activate.wav
set.wav
flip.wav
reveal.wav
equip.wav
destroyed.wav
banished.wav
token.wav
attack.wav
directattack.wav
draw.wav
shuffle.wav
damage.wav
gainlp.wav
addcounter.wav
removecounter.wav
coinflip.wav
diceroll.wav
nextturn.wav
phase.wav
menu.wav
button.wav
info.wav
question.wav
cardpick.wav
carddrop.wav
playerenter.wav
chatmessage.wav
BGM/*.mp3
BGM/duel/*.mp3
BGM/menu/*.mp3
BGM/deck/*.mp3
BGM/advantage/*.mp3
BGM/disadvantage/*.mp3
BGM/win/*.mp3
BGM/lose/*.mp3
......@@ -302,6 +302,9 @@
!system 1276 自动排列连锁顺序
!system 1277 没有可连锁的卡时延迟回应
!system 1278 自动选择魔陷卡片位置
!system 1279 开启音效
!system 1280 开启音乐
!system 1281 按场景切换音乐
!system 1290 忽略对方发言
!system 1291 忽略观战者发言
!system 1292 忽略时点
......
......@@ -30,3 +30,9 @@ auto_search_limit = -1
ignore_deck_changes = 0
default_ot = 1
enable_bot_mode = 0
enable_sound = 1
enable_music = 1
#Volume of sound and music, between 0 and 100
sound_volume = 50
music_volume = 50
music_mode = 1
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