From 75011d84d5f3c7613721e06facec29237b4a5c96 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 25 Sep 2012 01:52:09 +0000 Subject: [PATCH] - added support for custom music on battle end screen: look for music in the following order: 1. check faction xml file for the following attributes (depends on win/lose) on the faction tag: faction-battle-end-win-music="" faction-battle-end-lose-music="" if not defined 2. check the faction folder for the files: battle_end_win_music.* battle_end_lose_music.* if not found check the data/core/menu/music/ paths for: battle_end_win.* battle_end_lose.* --- source/glest_game/global/core_data.cpp | 69 +++++++++++++++++++++++ source/glest_game/global/core_data.h | 7 +++ source/glest_game/main/battle_end.cpp | 77 ++++++++++++++++++++++++++ source/glest_game/main/battle_end.h | 3 + 4 files changed, 156 insertions(+) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 275a4d11..aa2c29b0 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -83,8 +83,10 @@ CoreData::CoreData() { battleEndWinVideoFilename=""; battleEndWinVideoFilenameFallback=""; + battleEndWinMusicFilename=""; battleEndLoseVideoFilename=""; battleEndLoseVideoFilenameFallback=""; + battleEndLoseMusicFilename=""; } CoreData::~CoreData() { @@ -483,6 +485,7 @@ void CoreData::load() { battleEndWinVideoFilename = config.getString("BattleEndWinVideoURL",""); battleEndWinVideoFilenameFallback = config.getString("BattleEndWinVideoURLFallback",""); + if(battleEndWinVideoFilename == "") { string battleEndWinVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/battle_end_win.*"; vector battleEndWinVideos; @@ -515,8 +518,42 @@ void CoreData::load() { } } + battleEndWinMusicFilename = config.getString("BattleEndWinMusicFilename",""); + if(battleEndWinMusicFilename == "") { + string battleEndWinPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/music/battle_end_win.*"; + vector battleEndWinMusic; + findAll(battleEndWinPath, battleEndWinMusic, false, false); + for(int i = 0; i < battleEndWinMusic.size(); ++i) { + string music = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/music/" + battleEndWinMusic[i]; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if battle end win music [%s] exists\n",music.c_str()); + + if(fileExists(music)) { + battleEndWinMusicFilename = music; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND battle end win music [%s] will use this file\n",music.c_str()); + break; + } + } + + if(battleEndWinMusicFilename == "") { + battleEndWinPath = data_path + "data/core/menu/music/battle_end_win.*"; + battleEndWinMusic.clear(); + findAll(battleEndWinPath, battleEndWinMusic, false, false); + for(int i = 0; i < battleEndWinMusic.size(); ++i) { + string music = data_path + "data/core/menu/music/" + battleEndWinMusic[i]; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if battle end win music [%s] exists\n",music.c_str()); + + if(fileExists(music)) { + battleEndWinMusicFilename = music; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND battle end music win [%s] will use this file\n",music.c_str()); + break; + } + } + } + } + battleEndLoseVideoFilename = config.getString("BattleEndLoseVideoURL",""); battleEndLoseVideoFilenameFallback = config.getString("BattleEndLoseVideoURLFallback",""); + if(battleEndLoseVideoFilename == "") { string battleEndLoseVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/battle_end_lose.*"; vector battleEndLoseVideos; @@ -549,6 +586,38 @@ void CoreData::load() { } } + battleEndLoseMusicFilename = config.getString("BattleEndLoseMusicFilename",""); + if(battleEndLoseMusicFilename == "") { + string battleEndLosePath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/music/battle_end_lose.*"; + vector battleEndLoseMusic; + findAll(battleEndLosePath, battleEndLoseMusic, false, false); + for(int i = 0; i < battleEndLoseMusic.size(); ++i) { + string music = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/music/" + battleEndLoseMusic[i]; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if battle end lose music [%s] exists\n",music.c_str()); + + if(fileExists(music)) { + battleEndLoseMusicFilename = music; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND battle end lose music [%s] will use this file\n",music.c_str()); + break; + } + } + + if(battleEndLoseMusicFilename == "") { + battleEndLosePath = data_path + "data/core/menu/music/battle_end_lose.*"; + battleEndLoseMusic.clear(); + findAll(battleEndLosePath, battleEndLoseMusic, false, false); + for(int i = 0; i < battleEndLoseMusic.size(); ++i) { + string music = data_path + "data/core/menu/music/" + battleEndLoseMusic[i]; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if battle end lose music [%s] exists\n",music.c_str()); + + if(fileExists(music)) { + battleEndLoseMusicFilename = music; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND battle end music lose [%s] will use this file\n",music.c_str()); + break; + } + } + } + } } } diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index d683ddac..e099c197 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -91,12 +91,17 @@ private: string introVideoFilename; string introVideoFilenameFallback; + string mainMenuVideoFilename; string mainMenuVideoFilenameFallback; + string battleEndWinVideoFilename; string battleEndWinVideoFilenameFallback; + string battleEndWinMusicFilename; + string battleEndLoseVideoFilename; string battleEndLoseVideoFilenameFallback; + string battleEndLoseMusicFilename; public: @@ -200,6 +205,8 @@ public: string getBattleEndVideoFilenameFallback(bool won) const { return won == true ? battleEndWinVideoFilenameFallback : battleEndLoseVideoFilenameFallback; } bool hasBattleEndVideoFilenameFallback(bool won) const; + string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; } + void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0); bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings); diff --git a/source/glest_game/main/battle_end.cpp b/source/glest_game/main/battle_end.cpp index cd088610..0c86fed3 100644 --- a/source/glest_game/main/battle_end.cpp +++ b/source/glest_game/main/battle_end.cpp @@ -73,6 +73,7 @@ BattleEnd::BattleEnd(Program *program, const Stats *stats,ProgramState *originSt SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); initBackgroundVideo(); + initBackgroundMusic(); GraphicComponent::applyAllCustomProperties(containerName); } @@ -175,6 +176,82 @@ std::pair BattleEnd::getBattleEndVideo(bool won) { return result; } +string BattleEnd::getBattleEndMusic(bool won) { + string result=""; + string resultFallback=""; + + if(gameSettings != NULL) { + string currentTechName_factionPreview = gameSettings->getTech(); + string currentFactionName_factionPreview = gameSettings->getFactionTypeName(stats.getThisFactionIndex()); + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 tech [%s] faction [%s] won = %d\n",currentTechName_factionPreview.c_str(),currentFactionName_factionPreview.c_str(),won); + + string factionDefinitionXML = Game::findFactionLogoFile(gameSettings, NULL,currentFactionName_factionPreview + ".xml"); + if(factionDefinitionXML != "" && currentFactionName_factionPreview != GameConstants::RANDOMFACTION_SLOTNAME && + currentFactionName_factionPreview != GameConstants::OBSERVER_SLOTNAME && fileExists(factionDefinitionXML) == true) { + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 tech [%s] faction [%s]\n",currentTechName_factionPreview.c_str(),currentFactionName_factionPreview.c_str()); + + XmlTree xmlTree; + std::map mapExtraTagReplacementValues; + xmlTree.load(factionDefinitionXML, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); + const XmlNode *factionNode= xmlTree.getRootNode(); + if(won == true) { + if(factionNode->hasAttribute("faction-battle-end-win-music") == true) { + result = factionNode->getAttribute("faction-battle-end-win-music")->getValue(); + } + } + else { + if(factionNode->hasAttribute("faction-battle-end-lose-music") == true) { + result = factionNode->getAttribute("faction-battle-end-lose-music")->getValue(); + } + } + + if(won == true) { + resultFallback = Game::findFactionLogoFile(gameSettings, NULL,"battle_end_win_music.*"); + } + else { + resultFallback = Game::findFactionLogoFile(gameSettings, NULL,"battle_end_lose_music.*"); + } + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#3 result [%s] resultFallback [%s]\n",result.c_str(),resultFallback.c_str()); + + if(result == "") { + result = resultFallback; + } + } + //printf("currentFactionName_factionPreview [%s] random [%s] observer [%s] factionVideoUrl [%s]\n",currentFactionName_factionPreview.c_str(),GameConstants::RANDOMFACTION_SLOTNAME,GameConstants::OBSERVER_SLOTNAME,factionVideoUrl.c_str()); + } + + if(result == "") { + result = CoreData::getInstance().getBattleEndMusicFilename(won); + } + + return result; +} + +void BattleEnd::initBackgroundMusic() { + string music = ""; + + if(stats.getTeam(stats.getThisFactionIndex()) != GameConstants::maxPlayers -1 + fpt_Observer) { + if(stats.getVictory(stats.getThisFactionIndex())){ + //header += lang.get("Victory"); + music = getBattleEndMusic(true); + } + else{ + //header += lang.get("Defeat"); + music = getBattleEndMusic(false); + } + + if(music != "" && fileExists(music) == true) { + battleEndMusic.open(music); + + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + soundRenderer.playMusic(&battleEndMusic); + } + } +} + void BattleEnd::initBackgroundVideo() { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) { diff --git a/source/glest_game/main/battle_end.h b/source/glest_game/main/battle_end.h index c0a020d3..6b5583e7 100644 --- a/source/glest_game/main/battle_end.h +++ b/source/glest_game/main/battle_end.h @@ -49,6 +49,7 @@ private: Shared::Graphics::VideoPlayer *menuBackgroundVideo; GameSettings *gameSettings; + StrSound battleEndMusic; void showMessageBox(const string &text, const string &header, bool toggle); @@ -69,6 +70,8 @@ private: void initBackgroundVideo(); std::pair getBattleEndVideo(bool won); + string getBattleEndMusic(bool won); + void initBackgroundMusic(); }; }}//end namespace