Commit 49669fb4 authored by mercury233's avatar mercury233

Merge branch 'sound' of https://github.com/DailyShana/ygopro into master

parents de985735 a22e3b9e
...@@ -47,6 +47,7 @@ inline int _wtoi(const wchar_t * s) { ...@@ -47,6 +47,7 @@ inline int _wtoi(const wchar_t * s) {
#endif #endif
#include <irrlicht.h> #include <irrlicht.h>
#include <irrKlang.h>
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#include "CGUITTFont.h" #include "CGUITTFont.h"
......
...@@ -459,6 +459,13 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -459,6 +459,13 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
} }
} }
} }
case irr::gui::EGET_CHECKBOX_CHANGED: {
case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked())
mainGame->engineMusic->stopAllSounds();
break;
}
}
default: break; default: break;
} }
break; break;
......
...@@ -626,6 +626,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -626,6 +626,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
break; break;
} }
case STOC_HS_PLAYER_ENTER: { case STOC_HS_PLAYER_ENTER: {
mainGame->PlaySoundEffect("./sound/playerenter.wav");
STOC_HS_PlayerEnter* pkt = (STOC_HS_PlayerEnter*)pdata; STOC_HS_PlayerEnter* pkt = (STOC_HS_PlayerEnter*)pdata;
if(pkt->pos > 3) if(pkt->pos > 3)
break; break;
...@@ -660,6 +661,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -660,6 +661,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
break; break;
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
if(state < 8) { if(state < 8) {
mainGame->PlaySoundEffect("./sound/playerenter.wav");
wchar_t* prename = (wchar_t*)mainGame->stHostPrepDuelist[pos]->getText(); wchar_t* prename = (wchar_t*)mainGame->stHostPrepDuelist[pos]->getText();
mainGame->stHostPrepDuelist[state]->setText(prename); mainGame->stHostPrepDuelist[state]->setText(prename);
mainGame->stHostPrepDuelist[pos]->setText(L""); mainGame->stHostPrepDuelist[pos]->setText(L"");
...@@ -1710,6 +1712,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -1710,6 +1712,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_SHUFFLE_DECK: { case MSG_SHUFFLE_DECK: {
mainGame->PlaySoundEffect("./sound/shuffle.wav");
int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
if(mainGame->dField.deck[player].size() < 2) if(mainGame->dField.deck[player].size() < 2)
return true; return true;
...@@ -1904,6 +1907,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -1904,6 +1907,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_NEW_TURN: { case MSG_NEW_TURN: {
mainGame->PlaySoundEffect("./sound/nextturn.wav");
int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
mainGame->dInfo.turn++; mainGame->dInfo.turn++;
if(!mainGame->dInfo.isTag && !mainGame->dInfo.isReplay && mainGame->dInfo.player_type < 7) { if(!mainGame->dInfo.isTag && !mainGame->dInfo.isReplay && mainGame->dInfo.player_type < 7) {
...@@ -1940,6 +1944,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -1940,6 +1944,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_NEW_PHASE: { case MSG_NEW_PHASE: {
mainGame->PlaySoundEffect("./sound/phase.wav");
unsigned short phase = BufferIO::ReadInt16(pbuf); unsigned short phase = BufferIO::ReadInt16(pbuf);
mainGame->btnPhaseStatus->setVisible(false); mainGame->btnPhaseStatus->setVisible(false);
mainGame->btnBP->setVisible(false); mainGame->btnBP->setVisible(false);
...@@ -1993,7 +1998,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -1993,7 +1998,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
int cl = BufferIO::ReadUInt8(pbuf); int cl = BufferIO::ReadUInt8(pbuf);
int cs = BufferIO::ReadInt8(pbuf); int cs = BufferIO::ReadInt8(pbuf);
int cp = BufferIO::ReadInt8(pbuf); int cp = BufferIO::ReadInt8(pbuf);
/*int reason = */BufferIO::ReadInt32(pbuf); int reason = BufferIO::ReadInt32(pbuf);
if(reason & REASON_DESTROY && pl != cl)
mainGame->PlaySoundEffect("./sound/destroyed.wav");
if (pl == 0) { if (pl == 0) {
ClientCard* pcard = new ClientCard(); ClientCard* pcard = new ClientCard();
pcard->position = cp; pcard->position = cp;
...@@ -2209,6 +2216,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2209,6 +2216,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_SET: { case MSG_SET: {
mainGame->PlaySoundEffect("./sound/set.wav");
/*int code = */BufferIO::ReadInt32(pbuf); /*int code = */BufferIO::ReadInt32(pbuf);
/*int cc = mainGame->LocalPlayer*/(BufferIO::ReadInt8(pbuf)); /*int cc = mainGame->LocalPlayer*/(BufferIO::ReadInt8(pbuf));
/*int cl = */BufferIO::ReadInt8(pbuf); /*int cl = */BufferIO::ReadInt8(pbuf);
...@@ -2261,6 +2269,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2261,6 +2269,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_SUMMONING: { case MSG_SUMMONING: {
mainGame->PlaySoundEffect("./sound/summon.wav");
unsigned int code = (unsigned int)BufferIO::ReadInt32(pbuf); unsigned int code = (unsigned int)BufferIO::ReadInt32(pbuf);
/*int cc = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); /*int cc = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
/*int cl = */BufferIO::ReadInt8(pbuf); /*int cl = */BufferIO::ReadInt8(pbuf);
...@@ -2283,6 +2292,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2283,6 +2292,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_SPSUMMONING: { case MSG_SPSUMMONING: {
mainGame->PlaySoundEffect("./sound/specialsummon.wav");
unsigned int code = (unsigned int)BufferIO::ReadInt32(pbuf); unsigned int code = (unsigned int)BufferIO::ReadInt32(pbuf);
/*int cc = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); /*int cc = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
/*int cl = */BufferIO::ReadInt8(pbuf); /*int cl = */BufferIO::ReadInt8(pbuf);
...@@ -2304,6 +2314,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2304,6 +2314,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_FLIPSUMMONING: { case MSG_FLIPSUMMONING: {
mainGame->PlaySoundEffect("./sound/flip.wav");
unsigned int code = (unsigned int)BufferIO::ReadInt32(pbuf); unsigned int code = (unsigned int)BufferIO::ReadInt32(pbuf);
int cc = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int cc = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int cl = BufferIO::ReadInt8(pbuf); int cl = BufferIO::ReadInt8(pbuf);
...@@ -2331,6 +2342,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2331,6 +2342,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_CHAINING: { case MSG_CHAINING: {
mainGame->PlaySoundEffect("./sound/activate.wav");
unsigned int code = (unsigned int)BufferIO::ReadInt32(pbuf); unsigned int code = (unsigned int)BufferIO::ReadInt32(pbuf);
int pcc = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int pcc = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int pcl = BufferIO::ReadInt8(pbuf); int pcl = BufferIO::ReadInt8(pbuf);
...@@ -2504,6 +2516,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2504,6 +2516,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
} }
} else { } else {
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
mainGame->PlaySoundEffect("./sound/draw.wav");
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
pcard = mainGame->dField.GetCard(player, LOCATION_DECK, mainGame->dField.deck[player].size() - 1); pcard = mainGame->dField.GetCard(player, LOCATION_DECK, mainGame->dField.deck[player].size() - 1);
mainGame->dField.deck[player].erase(mainGame->dField.deck[player].end() - 1); mainGame->dField.deck[player].erase(mainGame->dField.deck[player].end() - 1);
...@@ -2520,6 +2533,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2520,6 +2533,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_DAMAGE: { case MSG_DAMAGE: {
mainGame->PlaySoundEffect("./sound/damage.wav");
int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int val = BufferIO::ReadInt32(pbuf); int val = BufferIO::ReadInt32(pbuf);
int final = mainGame->dInfo.lp[player] - val; int final = mainGame->dInfo.lp[player] - val;
...@@ -2550,6 +2564,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2550,6 +2564,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_RECOVER: { case MSG_RECOVER: {
mainGame->PlaySoundEffect("./sound/gainlp.wav");
int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int val = BufferIO::ReadInt32(pbuf); int val = BufferIO::ReadInt32(pbuf);
int final = mainGame->dInfo.lp[player] + val; int final = mainGame->dInfo.lp[player] + val;
...@@ -2578,6 +2593,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2578,6 +2593,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_EQUIP: { case MSG_EQUIP: {
mainGame->PlaySoundEffect("./sound/equip.wav");
int c1 = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int c1 = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int l1 = BufferIO::ReadInt8(pbuf); int l1 = BufferIO::ReadInt8(pbuf);
int s1 = BufferIO::ReadInt8(pbuf); int s1 = BufferIO::ReadInt8(pbuf);
...@@ -2702,6 +2718,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2702,6 +2718,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
break; break;
} }
case MSG_PAY_LPCOST: { case MSG_PAY_LPCOST: {
mainGame->PlaySoundEffect("./sound/damage.wav");
int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int cost = BufferIO::ReadInt32(pbuf); int cost = BufferIO::ReadInt32(pbuf);
int final = mainGame->dInfo.lp[player] - cost; int final = mainGame->dInfo.lp[player] - cost;
...@@ -2728,6 +2745,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2728,6 +2745,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_ADD_COUNTER: { case MSG_ADD_COUNTER: {
mainGame->PlaySoundEffect("./sound/addcounter.wav");
int type = BufferIO::ReadInt16(pbuf); int type = BufferIO::ReadInt16(pbuf);
int c = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int c = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int l = BufferIO::ReadInt8(pbuf); int l = BufferIO::ReadInt8(pbuf);
...@@ -2750,6 +2768,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2750,6 +2768,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_REMOVE_COUNTER: { case MSG_REMOVE_COUNTER: {
mainGame->PlaySoundEffect("./sound/removecounter.wav");
int type = BufferIO::ReadInt16(pbuf); int type = BufferIO::ReadInt16(pbuf);
int c = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int c = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int l = BufferIO::ReadInt8(pbuf); int l = BufferIO::ReadInt8(pbuf);
...@@ -2772,6 +2791,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2772,6 +2791,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_ATTACK: { case MSG_ATTACK: {
mainGame->PlaySoundEffect("./sound/attack.wav");
int ca = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); int ca = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int la = BufferIO::ReadInt8(pbuf); int la = BufferIO::ReadInt8(pbuf);
int sa = BufferIO::ReadInt8(pbuf); int sa = BufferIO::ReadInt8(pbuf);
...@@ -2880,6 +2900,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2880,6 +2900,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_TOSS_COIN: { case MSG_TOSS_COIN: {
mainGame->PlaySoundEffect("./sound/coinflip.wav");
/*int player = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); /*int player = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int count = BufferIO::ReadInt8(pbuf); int count = BufferIO::ReadInt8(pbuf);
wchar_t* pwbuf = textBuffer; wchar_t* pwbuf = textBuffer;
...@@ -2903,6 +2924,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2903,6 +2924,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
return true; return true;
} }
case MSG_TOSS_DICE: { case MSG_TOSS_DICE: {
mainGame->PlaySoundEffect("./sound/diceroll.wav");
/*int player = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf)); /*int player = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int count = BufferIO::ReadInt8(pbuf); int count = BufferIO::ReadInt8(pbuf);
wchar_t* pwbuf = textBuffer; wchar_t* pwbuf = textBuffer;
......
...@@ -888,6 +888,11 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -888,6 +888,11 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
} }
break; break;
} }
case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked())
mainGame->engineMusic->stopAllSounds();
break;
}
} }
break; break;
} }
...@@ -2005,6 +2010,13 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -2005,6 +2010,13 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true; return true;
break; break;
} }
case SCROLL_VOLUME: {
mainGame->gameConf.soundvolume = (double)mainGame->srcSoundVolume->getPos() / 100;
mainGame->gameConf.musicvolume = (double)mainGame->srcMusicVolume->getPos() / 100;
mainGame->engineSound->setSoundVolume(mainGame->gameConf.soundvolume);
mainGame->engineMusic->setSoundVolume(mainGame->gameConf.musicvolume);
break;
}
} }
break; break;
} }
......
...@@ -274,6 +274,24 @@ bool Game::Initialize() { ...@@ -274,6 +274,24 @@ bool Game::Initialize() {
posY += 30; posY += 30;
chkAutoSearch = env->addCheckBox(false, rect<s32>(posX, posY, posX + 225, posY + 25), tabSystem, CHECKBOX_AUTO_SEARCH, dataManager.GetSysString(1358)); chkAutoSearch = env->addCheckBox(false, rect<s32>(posX, posY, posX + 225, posY + 25), tabSystem, CHECKBOX_AUTO_SEARCH, dataManager.GetSysString(1358));
chkAutoSearch->setChecked(gameConf.auto_search_limit >= 0); chkAutoSearch->setChecked(gameConf.auto_search_limit >= 0);
posY += 30;
chkEnableSound = env->addCheckBox(gameConf.enablesound, rect<s32>(posX, posY, posX + 100, posY + 25), tabSystem, -1, dataManager.GetSysString(1380));
chkEnableSound->setChecked(gameConf.enablesound);
srcSoundVolume = env->addScrollBar(true, rect<s32>(posX+105, posY, posX + 260, posY + 25), tabSystem, SCROLL_VOLUME);
srcSoundVolume->setMax(100);
srcSoundVolume->setMin(0);
srcSoundVolume->setPos(gameConf.soundvolume * 100);
srcSoundVolume->setLargeStep(1);
srcSoundVolume->setSmallStep(1);
posY += 30;
chkEnableMusic = env->addCheckBox(gameConf.enablemusic, rect<s32>(posX, posY, posX + 100, posY + 25), tabSystem, CHECKBOX_ENABLE_MUSIC, dataManager.GetSysString(1381));
chkEnableMusic->setChecked(gameConf.enablemusic);
srcMusicVolume = env->addScrollBar(true, rect<s32>(posX+105, posY, posX + 260, posY + 25), tabSystem, SCROLL_VOLUME);
srcMusicVolume->setMax(100);
srcMusicVolume->setMin(0);
srcMusicVolume->setPos(gameConf.musicvolume * 100);
srcMusicVolume->setLargeStep(1);
srcMusicVolume->setSmallStep(1);
// //
wHand = env->addWindow(rect<s32>(500, 450, 825, 605), false, L""); wHand = env->addWindow(rect<s32>(500, 450, 825, 605), false, L"");
wHand->getCloseButton()->setVisible(false); wHand->getCloseButton()->setVisible(false);
...@@ -603,6 +621,7 @@ bool Game::Initialize() { ...@@ -603,6 +621,7 @@ bool Game::Initialize() {
stTip->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); stTip->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
stTip->setVisible(false); stTip->setVisible(false);
device->setEventReceiver(&menuHandler); device->setEventReceiver(&menuHandler);
RefreshBGMList();
LoadConfig(); LoadConfig();
env->getSkin()->setFont(guiFont); env->getSkin()->setFont(guiFont);
env->setFocus(wMainMenu); env->setFocus(wMainMenu);
...@@ -611,6 +630,8 @@ bool Game::Initialize() { ...@@ -611,6 +630,8 @@ bool Game::Initialize() {
col.setAlpha(224); col.setAlpha(224);
env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col); env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
} }
engineSound = irrklang::createIrrKlangDevice();
engineMusic = irrklang::createIrrKlangDevice();
hideChat = false; hideChat = false;
hideChatTimer = 0; hideChatTimer = 0;
return true; return true;
...@@ -642,6 +663,16 @@ void Game::MainLoop() { ...@@ -642,6 +663,16 @@ void Game::MainLoop() {
driver->draw2DImage(imageManager.tBackGround, recti(0, 0, 1024, 640), recti(0, 0, imageManager.tBackGround->getOriginalSize().Width, imageManager.tBackGround->getOriginalSize().Height)); driver->draw2DImage(imageManager.tBackGround, recti(0, 0, 1024, 640), recti(0, 0, imageManager.tBackGround->getOriginalSize().Width, imageManager.tBackGround->getOriginalSize().Height));
gMutex.Lock(); gMutex.Lock();
if(dInfo.isStarted) { if(dInfo.isStarted) {
if(mainGame->showcardcode == 1 || mainGame->showcardcode == 3)
PlayMusic("./sound/duelwin.mp3", true);
else if(mainGame->showcardcode == 2)
PlayMusic("./sound/duellose.mp3", true);
else if(mainGame->dInfo.lp[0] > 0 && mainGame->dInfo.lp[LocalPlayer(0)] <= mainGame->dInfo.lp[LocalPlayer(1)] / 2)
PlayMusic("./sound/song-disadvantage.mp3", true);
else if(mainGame->dInfo.lp[0] > 0 && mainGame->dInfo.lp[LocalPlayer(0)] >= mainGame->dInfo.lp[LocalPlayer(1)] * 2)
PlayMusic("./sound/song-advantage.mp3", true);
else
PlayBGM();
DrawBackGround(); DrawBackGround();
DrawCards(); DrawCards();
DrawMisc(); DrawMisc();
...@@ -652,9 +683,11 @@ void Game::MainLoop() { ...@@ -652,9 +683,11 @@ void Game::MainLoop() {
if(imageManager.tBackGround_deck) if(imageManager.tBackGround_deck)
driver->draw2DImage(imageManager.tBackGround_deck, recti(0, 0, 1024, 640), recti(0, 0, imageManager.tBackGround->getOriginalSize().Width, imageManager.tBackGround->getOriginalSize().Height)); driver->draw2DImage(imageManager.tBackGround_deck, recti(0, 0, 1024, 640), recti(0, 0, imageManager.tBackGround->getOriginalSize().Width, imageManager.tBackGround->getOriginalSize().Height));
DrawDeckBd(); DrawDeckBd();
PlayMusic("./sound/deck.mp3", true);
} else { } else {
if(imageManager.tBackGround_menu) if(imageManager.tBackGround_menu)
driver->draw2DImage(imageManager.tBackGround_menu, recti(0, 0, 1024, 640), recti(0, 0, imageManager.tBackGround->getOriginalSize().Width, imageManager.tBackGround->getOriginalSize().Height)); driver->draw2DImage(imageManager.tBackGround_menu, recti(0, 0, 1024, 640), recti(0, 0, imageManager.tBackGround->getOriginalSize().Width, imageManager.tBackGround->getOriginalSize().Height));
PlayMusic("./sound/menu.mp3", true);
} }
DrawGUI(); DrawGUI();
DrawSpec(); DrawSpec();
...@@ -705,6 +738,7 @@ void Game::MainLoop() { ...@@ -705,6 +738,7 @@ void Game::MainLoop() {
usleep(500000); usleep(500000);
#endif #endif
SaveConfig(); SaveConfig();
engineMusic->drop();
// device->drop(); // device->drop();
} }
void Game::BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar) { void Game::BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar) {
...@@ -897,6 +931,33 @@ void Game::RefreshSingleplay() { ...@@ -897,6 +931,33 @@ void Game::RefreshSingleplay() {
closedir(dir); closedir(dir);
#endif #endif
} }
void Game::RefreshBGMList() {
#ifdef _WIN32
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./sound/BGM/*.mp3", &fdataw);
if(fh == INVALID_HANDLE_VALUE)
return;
do {
if(!(fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
BGMList.push_back(fdataw.cFileName);
} 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.push_back(fdataw.cFileName);
}
closedir(dir);
#endif
}
void Game::LoadConfig() { void Game::LoadConfig() {
FILE* fp = fopen("system.conf", "r"); FILE* fp = fopen("system.conf", "r");
if(!fp) if(!fp)
...@@ -931,6 +992,11 @@ void Game::LoadConfig() { ...@@ -931,6 +992,11 @@ void Game::LoadConfig() {
gameConf.separate_clear_button = 1; gameConf.separate_clear_button = 1;
gameConf.auto_search_limit = -1; gameConf.auto_search_limit = -1;
gameConf.chkIgnoreDeckChanges = 0; gameConf.chkIgnoreDeckChanges = 0;
gameConf.enablesound = true;
gameConf.soundvolume = 1.0;
gameConf.enablemusic = true;
gameConf.musicvolume = 1.0;
gameConf.BGM_index = -1;
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
int fsize = ftell(fp); int fsize = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
...@@ -991,6 +1057,14 @@ void Game::LoadConfig() { ...@@ -991,6 +1057,14 @@ void Game::LoadConfig() {
gameConf.auto_search_limit = atoi(valbuf); gameConf.auto_search_limit = atoi(valbuf);
} else if(!strcmp(strbuf, "ignore_deck_changes")) { } else if(!strcmp(strbuf, "ignore_deck_changes")) {
gameConf.chkIgnoreDeckChanges = atoi(valbuf); gameConf.chkIgnoreDeckChanges = atoi(valbuf);
} else if(!strcmp(strbuf, "enable_sound")) {
gameConf.enablesound = atoi(valbuf) > 0;
} else if(!strcmp(strbuf, "soundvolume")) {
gameConf.soundvolume = atof(valbuf) / 100;
} else if(!strcmp(strbuf, "enable_music")) {
gameConf.enablemusic = atoi(valbuf) > 0;
} else if(!strcmp(strbuf, "musicvolume")) {
gameConf.musicvolume = atof(valbuf) / 100;
} else { } else {
// options allowing multiple words // options allowing multiple words
sscanf(linebuf, "%s = %240[^\n]", strbuf, valbuf); sscanf(linebuf, "%s = %240[^\n]", strbuf, valbuf);
...@@ -1048,8 +1122,56 @@ void Game::SaveConfig() { ...@@ -1048,8 +1122,56 @@ void Game::SaveConfig() {
fprintf(fp, "#auto_search_limit >= 0: Start search automatically when the user enters N chars\n"); fprintf(fp, "#auto_search_limit >= 0: Start search automatically when the user enters N chars\n");
fprintf(fp, "auto_search_limit = %d\n", gameConf.auto_search_limit); fprintf(fp, "auto_search_limit = %d\n", gameConf.auto_search_limit);
fprintf(fp, "ignore_deck_changes = %d\n", ((mainGame->chkIgnoreDeckChanges->isChecked()) ? 1 : 0)); fprintf(fp, "ignore_deck_changes = %d\n", ((mainGame->chkIgnoreDeckChanges->isChecked()) ? 1 : 0));
fprintf(fp, "enable_sound = %d\n", ((mainGame->chkEnableSound->isChecked()) ? 1 : 0));
fprintf(fp, "enable_music = %d\n", ((mainGame->chkEnableMusic->isChecked()) ? 1 : 0));
fprintf(fp, "#Volume of sound and music, between 0 and 100\n");
int vol = gameConf.soundvolume * 100;
if(vol < 0) vol = 0; else if(vol > 100) vol = 100;
fprintf(fp, "soundvolume = %d\n", vol);
vol = gameConf.musicvolume * 100;
if(vol < 0) vol = 0; else if(vol > 100) vol = 100;
fprintf(fp, "musicvolume = %d\n", vol);
fprintf(fp, "#playing the music corresponding to the sequence(start from 0) under folder /BGM\n#-1 means playing one of them randomly\n");
fprintf(fp, "BGM_index = %d\n", gameConf.BGM_index);
fclose(fp); fclose(fp);
} }
void Game::PlaySoundEffect(char* sound) {
if(mainGame->chkEnableSound->isChecked()) {
engineSound->play2D(sound);
engineSound->setSoundVolume(gameConf.soundvolume);
}
}
void Game::PlayMusic(char* song, bool loop) {
if(mainGame->chkEnableMusic->isChecked()) {
if(!engineMusic->isCurrentlyPlaying(song)) {
engineMusic->stopAllSounds();
engineMusic->play2D(song, loop);
engineMusic->setSoundVolume(gameConf.musicvolume);
}
}
}
void Game::PlayBGM() {
if(mainGame->chkEnableMusic->isChecked()) {
static bool is_playing = false;
static char strBuffer[1024];
if(is_playing && !engineMusic->isCurrentlyPlaying(strBuffer))
is_playing = false;
if(!is_playing) {
int count = BGMList.size();
int bgm = (gameConf.BGM_index >= 0) ? gameConf.BGM_index : rand() % count;
auto name = BGMList[bgm].c_str();
wchar_t fname[256];
myswprintf(fname, L"./sound/BGM/%ls", name);
BufferIO::EncodeUTF8(fname, strBuffer);
}
if(!engineMusic->isCurrentlyPlaying(strBuffer)) {
engineMusic->stopAllSounds();
engineMusic->play2D(strBuffer, true);
engineMusic->setSoundVolume(gameConf.musicvolume);
is_playing = true;
}
}
}
void Game::ShowCardInfo(int code) { void Game::ShowCardInfo(int code) {
CardData cd; CardData cd;
wchar_t formatBuffer[256]; wchar_t formatBuffer[256];
...@@ -1062,7 +1184,7 @@ void Game::ShowCardInfo(int code) { ...@@ -1062,7 +1184,7 @@ void Game::ShowCardInfo(int code) {
else myswprintf(formatBuffer, L"%ls[%08d]", dataManager.GetName(code), code); else myswprintf(formatBuffer, L"%ls[%08d]", dataManager.GetName(code), code);
stName->setText(formatBuffer); stName->setText(formatBuffer);
int offset = 0; int offset = 0;
if(!mainGame->chkHideSetname->isChecked()) { if(!gameConf.chkHideSetname) {
unsigned long long sc = cd.setcode; unsigned long long sc = cd.setcode;
if(cd.alias) { if(cd.alias) {
auto aptr = dataManager._datas.find(cd.alias); auto aptr = dataManager._datas.find(cd.alias);
...@@ -1141,14 +1263,17 @@ void Game::AddChatMsg(wchar_t* msg, int player) { ...@@ -1141,14 +1263,17 @@ void Game::AddChatMsg(wchar_t* msg, int player) {
chatMsg[0].append(L": "); chatMsg[0].append(L": ");
break; break;
case 1: //from client case 1: //from client
mainGame->PlaySoundEffect("./sound/chatmessage.wav");
chatMsg[0].append(dInfo.clientname); chatMsg[0].append(dInfo.clientname);
chatMsg[0].append(L": "); chatMsg[0].append(L": ");
break; break;
case 2: //host tag case 2: //host tag
mainGame->PlaySoundEffect("./sound/chatmessage.wav");
chatMsg[0].append(dInfo.hostname_tag); chatMsg[0].append(dInfo.hostname_tag);
chatMsg[0].append(L": "); chatMsg[0].append(L": ");
break; break;
case 3: //client tag case 3: //client tag
mainGame->PlaySoundEffect("./sound/chatmessage.wav");
chatMsg[0].append(dInfo.clientname_tag); chatMsg[0].append(dInfo.clientname_tag);
chatMsg[0].append(L": "); chatMsg[0].append(L": ");
break; break;
...@@ -1157,6 +1282,7 @@ void Game::AddChatMsg(wchar_t* msg, int player) { ...@@ -1157,6 +1282,7 @@ void Game::AddChatMsg(wchar_t* msg, int player) {
chatMsg[0].append(L": "); chatMsg[0].append(L": ");
break; break;
case 8: //system custom message, no prefix. case 8: //system custom message, no prefix.
mainGame->PlaySoundEffect("./sound/chatmessage.wav");
chatMsg[0].append(L"[System]: "); chatMsg[0].append(L"[System]: ");
break; break;
case 9: //error message case 9: //error message
......
...@@ -39,6 +39,11 @@ struct Config { ...@@ -39,6 +39,11 @@ struct Config {
int separate_clear_button; int separate_clear_button;
int auto_search_limit; int auto_search_limit;
int chkIgnoreDeckChanges; int chkIgnoreDeckChanges;
bool enablesound;
bool enablemusic;
double soundvolume;
double musicvolume;
int BGM_index;
}; };
struct DuelInfo { struct DuelInfo {
...@@ -90,6 +95,7 @@ public: ...@@ -90,6 +95,7 @@ public:
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck); void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay(); void RefreshReplay();
void RefreshSingleplay(); void RefreshSingleplay();
void RefreshBGMList();
void DrawSelectionLine(irr::video::S3DVertex* vec, bool strip, int width, float* cv); void DrawSelectionLine(irr::video::S3DVertex* vec, bool strip, int width, float* cv);
void DrawBackGround(); void DrawBackGround();
void DrawLinkedZones(ClientCard* pcard); void DrawLinkedZones(ClientCard* pcard);
...@@ -113,6 +119,9 @@ public: ...@@ -113,6 +119,9 @@ public:
void AddDebugMsg(char* msgbuf); void AddDebugMsg(char* msgbuf);
void ClearTextures(); void ClearTextures();
void CloseDuelWindow(); void CloseDuelWindow();
void PlaySoundEffect(char* sound);
void PlayMusic(char* song, bool loop);
void PlayBGM();
int LocalPlayer(int player); int LocalPlayer(int player);
const wchar_t* LocalName(int local_player); const wchar_t* LocalName(int local_player);
...@@ -139,6 +148,7 @@ public: ...@@ -139,6 +148,7 @@ public:
std::list<FadingUnit> fadingList; std::list<FadingUnit> fadingList;
std::vector<int> logParam; std::vector<int> logParam;
std::wstring chatMsg[8]; std::wstring chatMsg[8];
std::vector<std::wstring> BGMList;
int hideChatTimer; int hideChatTimer;
bool hideChat; bool hideChat;
...@@ -213,9 +223,13 @@ public: ...@@ -213,9 +223,13 @@ public:
irr::gui::IGUICheckBox* chkHideHintButton; irr::gui::IGUICheckBox* chkHideHintButton;
irr::gui::IGUICheckBox* chkIgnoreDeckChanges; irr::gui::IGUICheckBox* chkIgnoreDeckChanges;
irr::gui::IGUICheckBox* chkAutoSearch; irr::gui::IGUICheckBox* chkAutoSearch;
irr::gui::IGUICheckBox* chkEnableSound;
irr::gui::IGUICheckBox* chkEnableMusic;
irr::gui::IGUIListBox* lstLog; irr::gui::IGUIListBox* lstLog;
irr::gui::IGUIButton* btnClearLog; irr::gui::IGUIButton* btnClearLog;
irr::gui::IGUIButton* btnSaveLog; irr::gui::IGUIButton* btnSaveLog;
irr::gui::IGUIScrollBar* srcSoundVolume;
irr::gui::IGUIScrollBar* srcMusicVolume;
//main menu //main menu
irr::gui::IGUIWindow* wMainMenu; irr::gui::IGUIWindow* wMainMenu;
irr::gui::IGUIButton* btnLanMode; irr::gui::IGUIButton* btnLanMode;
...@@ -420,6 +434,10 @@ public: ...@@ -420,6 +434,10 @@ public:
irr::gui::IGUIButton* btnChainWhenAvail; irr::gui::IGUIButton* btnChainWhenAvail;
//cancel or finish //cancel or finish
irr::gui::IGUIButton* btnCancelOrFinish; irr::gui::IGUIButton* btnCancelOrFinish;
//soundEngine
irrklang::ISoundEngine* engineSound;
irrklang::ISoundEngine* engineMusic;
}; };
extern Game* mainGame; extern Game* mainGame;
...@@ -552,6 +570,10 @@ extern Game* mainGame; ...@@ -552,6 +570,10 @@ extern Game* mainGame;
#define BUTTON_LOAD_SINGLEPLAY 351 #define BUTTON_LOAD_SINGLEPLAY 351
#define BUTTON_CANCEL_SINGLEPLAY 352 #define BUTTON_CANCEL_SINGLEPLAY 352
#define CHECKBOX_AUTO_SEARCH 360 #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_SORTTYPE 370
#define BUTTON_MARKS_FILTER 380 #define BUTTON_MARKS_FILTER 380
......
...@@ -6,12 +6,13 @@ project "ygopro" ...@@ -6,12 +6,13 @@ project "ygopro"
files { "**.cpp", "**.cc", "**.c", "**.h" } files { "**.cpp", "**.cc", "**.c", "**.h" }
excludes "lzma/**" excludes "lzma/**"
includedirs { "../ocgcore" } includedirs { "../ocgcore" }
links { "ocgcore", "clzma", "Irrlicht", "freetype", "sqlite3", "lua" , "event"} links { "ocgcore", "clzma", "Irrlicht", "freetype", "sqlite3", "lua" , "event", "irrKlang"}
configuration "windows" configuration "windows"
files "ygopro.rc" files "ygopro.rc"
excludes "CGUIButton.cpp" excludes "CGUIButton.cpp"
includedirs { "../irrlicht/include", "../freetype/include", "../event/include", "../sqlite3" } includedirs { "../irrlicht/include", "../freetype/include", "../event/include", "../sqlite3", "../irrklang/include" }
libdirs { "../irrklang/lib/Win32-visualStudio" }
links { "opengl32", "ws2_32", "winmm", "gdi32", "kernel32", "user32", "imm32" } links { "opengl32", "ws2_32", "winmm", "gdi32", "kernel32", "user32", "imm32" }
configuration {"windows", "not vs*"} configuration {"windows", "not vs*"}
includedirs { "/mingw/include/irrlicht", "/mingw/include/freetype2" } includedirs { "/mingw/include/irrlicht", "/mingw/include/freetype2" }
......
...@@ -366,6 +366,8 @@ ...@@ -366,6 +366,8 @@
!system 1372 守备↑ !system 1372 守备↑
!system 1373 名称↓ !system 1373 名称↓
!system 1374 连接标记 !system 1374 连接标记
!system 1380 开启音效
!system 1381 开启音乐
!system 1390 等待行动中... !system 1390 等待行动中...
!system 1391 等待行动中.... !system 1391 等待行动中....
!system 1392 等待行动中..... !system 1392 等待行动中.....
......
...@@ -27,3 +27,11 @@ separate_clear_button = 1 ...@@ -27,3 +27,11 @@ separate_clear_button = 1
#auto_search_limit >= 0: Start search automatically when the user enters N chars. #auto_search_limit >= 0: Start search automatically when the user enters N chars.
auto_search_limit = -1 auto_search_limit = -1
prompt_to_discard_deck_changes = 1 prompt_to_discard_deck_changes = 1
enable_sound = 1
enable_music = 1
#Volume of sound and music, between 0 and 100
soundvolume = 50
musicvolume = 50
#playing the music corresponding to the sequence(start from 0) under folder /BGM
#-1 means playing one of them randomly
BGM_index = -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