Commit a22e3b9e authored by DailyShana's avatar DailyShana

sound

parent c0fe8f31
...@@ -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"
......
...@@ -221,6 +221,13 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -221,6 +221,13 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
mainGame->SetStaticText(mainGame->stText, mainGame->stText->getRelativePosition().getWidth()-25, mainGame->textFont, mainGame->showingtext, pos); mainGame->SetStaticText(mainGame->stText, mainGame->stText->getRelativePosition().getWidth()-25, mainGame->textFont, mainGame->showingtext, pos);
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;
} }
} }
...@@ -321,6 +328,13 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -321,6 +328,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;
......
...@@ -603,6 +603,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -603,6 +603,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;
...@@ -636,6 +637,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -636,6 +637,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"");
...@@ -1645,6 +1647,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -1645,6 +1647,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;
...@@ -1835,6 +1838,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -1835,6 +1838,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.turn == 5 && !mainGame->dInfo.isReplay && mainGame->dInfo.player_type < 7) { if(!mainGame->dInfo.isTag && mainGame->dInfo.turn == 5 && !mainGame->dInfo.isReplay && mainGame->dInfo.player_type < 7) {
...@@ -1859,6 +1863,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -1859,6 +1863,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->btnDP->setVisible(false); mainGame->btnDP->setVisible(false);
mainGame->btnSP->setVisible(false); mainGame->btnSP->setVisible(false);
...@@ -1918,7 +1923,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -1918,7 +1923,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;
...@@ -2133,6 +2140,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2133,6 +2140,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);
...@@ -2185,6 +2193,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2185,6 +2193,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);
...@@ -2207,6 +2216,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2207,6 +2216,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);
...@@ -2228,6 +2238,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2228,6 +2238,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);
...@@ -2255,6 +2266,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2255,6 +2266,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);
...@@ -2427,6 +2439,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2427,6 +2439,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);
...@@ -2443,6 +2456,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2443,6 +2456,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;
...@@ -2473,6 +2487,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2473,6 +2487,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;
...@@ -2501,6 +2516,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2501,6 +2516,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);
...@@ -2618,6 +2634,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2618,6 +2634,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;
...@@ -2644,6 +2661,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2644,6 +2661,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);
...@@ -2666,6 +2684,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2666,6 +2684,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);
...@@ -2688,6 +2707,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2688,6 +2707,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);
...@@ -2796,6 +2816,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2796,6 +2816,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;
...@@ -2819,6 +2840,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2819,6 +2840,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;
......
...@@ -688,6 +688,11 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -688,6 +688,11 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
} }
break; break;
} }
case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked())
mainGame->engineMusic->stopAllSounds();
break;
}
} }
break; break;
} }
...@@ -800,6 +805,13 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -800,6 +805,13 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
mainGame->SetStaticText(mainGame->stText, mainGame->stText->getRelativePosition().getWidth()-25, mainGame->textFont, mainGame->showingtext, pos); mainGame->SetStaticText(mainGame->stText, mainGame->stText->getRelativePosition().getWidth()-25, mainGame->textFont, mainGame->showingtext, pos);
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;
} }
} }
......
...@@ -236,8 +236,22 @@ bool Game::Initialize() { ...@@ -236,8 +236,22 @@ bool Game::Initialize() {
chkIgnore1->setChecked(gameConf.chkIgnore1 != 0); chkIgnore1->setChecked(gameConf.chkIgnore1 != 0);
chkIgnore2 = env->addCheckBox(false, rect<s32>(20, 200, 280, 225), tabSystem, -1, dataManager.GetSysString(1291)); chkIgnore2 = env->addCheckBox(false, rect<s32>(20, 200, 280, 225), tabSystem, -1, dataManager.GetSysString(1291));
chkIgnore2->setChecked(gameConf.chkIgnore2 != 0); chkIgnore2->setChecked(gameConf.chkIgnore2 != 0);
chkHideSetname = env->addCheckBox(false, rect<s32>(20, 260, 280, 285), tabSystem, -1, dataManager.GetSysString(1354)); chkEnableSound = env->addCheckBox(gameConf.enablesound, rect<s32>(20, 230, 280, 255), tabSystem, -1, dataManager.GetSysString(1292));
chkHideSetname->setChecked(gameConf.chkHideSetname != 0); chkEnableSound->setChecked(gameConf.enablesound);
srcSoundVolume = env->addScrollBar(true, rect<s32>(125, 235, 280, 250), tabSystem, SCROLL_VOLUME);
srcSoundVolume->setMax(100);
srcSoundVolume->setMin(0);
srcSoundVolume->setPos(gameConf.soundvolume * 100);
srcSoundVolume->setLargeStep(1);
srcSoundVolume->setSmallStep(1);
chkEnableMusic = env->addCheckBox(gameConf.enablemusic, rect<s32>(20, 260, 280, 285), tabSystem, CHECKBOX_ENABLE_MUSIC, dataManager.GetSysString(1293));
chkEnableMusic->setChecked(gameConf.enablemusic);
srcMusicVolume = env->addScrollBar(true, rect<s32>(125, 265, 280, 280), 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);
...@@ -504,6 +518,7 @@ bool Game::Initialize() { ...@@ -504,6 +518,7 @@ bool Game::Initialize() {
btnLeaveGame = env->addButton(rect<s32>(205, 5, 295, 80), 0, BUTTON_LEAVE_GAME, L""); btnLeaveGame = env->addButton(rect<s32>(205, 5, 295, 80), 0, BUTTON_LEAVE_GAME, L"");
btnLeaveGame->setVisible(false); btnLeaveGame->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);
...@@ -512,6 +527,8 @@ bool Game::Initialize() { ...@@ -512,6 +527,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;
...@@ -543,6 +560,16 @@ void Game::MainLoop() { ...@@ -543,6 +560,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();
...@@ -551,6 +578,9 @@ void Game::MainLoop() { ...@@ -551,6 +578,9 @@ void Game::MainLoop() {
driver->clearZBuffer(); driver->clearZBuffer();
} else if(is_building) { } else if(is_building) {
DrawDeckBd(); DrawDeckBd();
PlayMusic("./sound/deck.mp3", true);
} else {
PlayMusic("./sound/menu.mp3", true);
} }
DrawGUI(); DrawGUI();
DrawSpec(); DrawSpec();
...@@ -603,6 +633,7 @@ void Game::MainLoop() { ...@@ -603,6 +633,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) {
...@@ -788,6 +819,33 @@ void Game::RefreshSingleplay() { ...@@ -788,6 +819,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)
...@@ -816,6 +874,12 @@ void Game::LoadConfig() { ...@@ -816,6 +874,12 @@ void Game::LoadConfig() {
gameConf.chkIgnore2 = 0; gameConf.chkIgnore2 = 0;
gameConf.chkHideSetname = 0; gameConf.chkHideSetname = 0;
gameConf.control_mode = 0; gameConf.control_mode = 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);
...@@ -864,6 +928,14 @@ void Game::LoadConfig() { ...@@ -864,6 +928,14 @@ void Game::LoadConfig() {
gameConf.chkHideSetname = atoi(valbuf); gameConf.chkHideSetname = atoi(valbuf);
} else if(!strcmp(strbuf, "control_mode")) { } else if(!strcmp(strbuf, "control_mode")) {
gameConf.control_mode = atoi(valbuf); gameConf.control_mode = 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);
...@@ -913,11 +985,59 @@ void Game::SaveConfig() { ...@@ -913,11 +985,59 @@ void Game::SaveConfig() {
fprintf(fp, "waitchain = %d\n", ((mainGame->chkWaitChain->isChecked()) ? 1 : 0)); fprintf(fp, "waitchain = %d\n", ((mainGame->chkWaitChain->isChecked()) ? 1 : 0));
fprintf(fp, "mute_opponent = %d\n", ((mainGame->chkIgnore1->isChecked()) ? 1 : 0)); fprintf(fp, "mute_opponent = %d\n", ((mainGame->chkIgnore1->isChecked()) ? 1 : 0));
fprintf(fp, "mute_spectators = %d\n", ((mainGame->chkIgnore2->isChecked()) ? 1 : 0)); fprintf(fp, "mute_spectators = %d\n", ((mainGame->chkIgnore2->isChecked()) ? 1 : 0));
fprintf(fp, "hide_setname = %d\n", ((mainGame->chkHideSetname->isChecked()) ? 1 : 0)); fprintf(fp, "hide_setname = %d\n", gameConf.chkHideSetname);
fprintf(fp, "#control_mode = 0: Key A/S/R. control_mode = 1: MouseLeft/MouseRight/F9\n"); fprintf(fp, "#control_mode = 0: Key A/S/R. control_mode = 1: MouseLeft/MouseRight/F9\n");
fprintf(fp, "control_mode = %d\n", gameConf.control_mode); fprintf(fp, "control_mode = %d\n", gameConf.control_mode);
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];
...@@ -930,7 +1050,7 @@ void Game::ShowCardInfo(int code) { ...@@ -930,7 +1050,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);
...@@ -998,14 +1118,17 @@ void Game::AddChatMsg(wchar_t* msg, int player) { ...@@ -998,14 +1118,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;
...@@ -1014,6 +1137,7 @@ void Game::AddChatMsg(wchar_t* msg, int player) { ...@@ -1014,6 +1137,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
......
...@@ -33,6 +33,12 @@ struct Config { ...@@ -33,6 +33,12 @@ struct Config {
int chkIgnore2; int chkIgnore2;
int chkHideSetname; int chkHideSetname;
int control_mode; int control_mode;
bool enablesound;
double soundvolume;
bool enablemusic;
double musicvolume;
int BGM_index;
}; };
struct DuelInfo { struct DuelInfo {
...@@ -84,6 +90,7 @@ public: ...@@ -84,6 +90,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 DrawCards(); void DrawCards();
...@@ -103,6 +110,9 @@ public: ...@@ -103,6 +110,9 @@ public:
void AddChatMsg(wchar_t* msg, int player); void AddChatMsg(wchar_t* msg, int player);
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);
...@@ -126,6 +136,7 @@ public: ...@@ -126,6 +136,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;
...@@ -189,10 +200,13 @@ public: ...@@ -189,10 +200,13 @@ public:
irr::gui::IGUICheckBox* chkRandomPos; irr::gui::IGUICheckBox* chkRandomPos;
irr::gui::IGUICheckBox* chkAutoChain; irr::gui::IGUICheckBox* chkAutoChain;
irr::gui::IGUICheckBox* chkWaitChain; irr::gui::IGUICheckBox* chkWaitChain;
irr::gui::IGUICheckBox* chkHideSetname; 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;
...@@ -380,6 +394,9 @@ public: ...@@ -380,6 +394,9 @@ public:
//surrender/leave //surrender/leave
irr::gui::IGUIButton* btnLeaveGame; irr::gui::IGUIButton* btnLeaveGame;
//soundEngine
irrklang::ISoundEngine* engineSound;
irrklang::ISoundEngine* engineMusic;
}; };
extern Game* mainGame; extern Game* mainGame;
...@@ -497,4 +514,7 @@ extern Game* mainGame; ...@@ -497,4 +514,7 @@ extern Game* mainGame;
#define LISTBOX_SINGLEPLAY_LIST 350 #define LISTBOX_SINGLEPLAY_LIST 350
#define BUTTON_LOAD_SINGLEPLAY 351 #define BUTTON_LOAD_SINGLEPLAY 351
#define BUTTON_CANCEL_SINGLEPLAY 352 #define BUTTON_CANCEL_SINGLEPLAY 352
//#define CHECKBOX_ENABLE_SOUND 360
#define CHECKBOX_ENABLE_MUSIC 361
#define SCROLL_VOLUME 362
#endif // GAME_H #endif // GAME_H
...@@ -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-1.5.0/include" }
libdirs { "../irrKlang-1.5.0/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" }
......
...@@ -279,6 +279,8 @@ ...@@ -279,6 +279,8 @@
!system 1281 自定义 !system 1281 自定义
!system 1290 忽略对方发言 !system 1290 忽略对方发言
!system 1291 忽略观战者发言 !system 1291 忽略观战者发言
!system 1292 开启音效
!system 1293 开启音乐
!system 1300 禁限卡表: !system 1300 禁限卡表:
!system 1301 卡组列表: !system 1301 卡组列表:
!system 1302 保存 !system 1302 保存
...@@ -326,7 +328,6 @@ ...@@ -326,7 +328,6 @@
!system 1351 投降 !system 1351 投降
!system 1352 主要信息: !system 1352 主要信息:
!system 1353 播放起始于回合: !system 1353 播放起始于回合:
!system 1354 不显示卡片系列
!system 1390 等待行动中... !system 1390 等待行动中...
!system 1391 等待行动中.... !system 1391 等待行动中....
!system 1392 等待行动中..... !system 1392 等待行动中.....
......
...@@ -20,3 +20,11 @@ mute_spectators = 0 ...@@ -20,3 +20,11 @@ mute_spectators = 0
hide_setname = 0 hide_setname = 0
#control_mode = 0: Key A/S/R. control_mode = 1: MouseLeft/MouseRight/F9 #control_mode = 0: Key A/S/R. control_mode = 1: MouseLeft/MouseRight/F9
control_mode = 0 control_mode = 0
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