- 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="<path to music>"
faction-battle-end-lose-music="<path to 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.*
This commit is contained in:
Mark Vejvoda 2012-09-25 01:52:09 +00:00
parent 3ede912b9a
commit 75011d84d5
4 changed files with 156 additions and 0 deletions

View File

@ -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<string> 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<string> 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<string> 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<string> 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;
}
}
}
}
}
}

View File

@ -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);

View File

@ -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<string,string> 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<string,string> 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) {

View File

@ -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<string,string> getBattleEndVideo(bool won);
string getBattleEndMusic(bool won);
void initBackgroundMusic();
};
}}//end namespace