diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 3137f530..e31eaa74 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -3623,8 +3623,34 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, currentTechName_factionPreview=gameSettings->getTech(); currentFactionName_factionPreview=gameSettings->getFactionTypeName(gameSettings->getThisFactionIndex()); - string factionVideoUrl = Game::findFactionLogoFile(gameSettings, NULL,"preview_video.*"); + string factionVideoUrl = ""; + string factionVideoUrlFallback = ""; + + string factionDefinitionXML = Game::findFactionLogoFile(gameSettings, NULL,currentFactionName_factionPreview + ".xml"); + if(factionDefinitionXML != "" && currentFactionName_factionPreview != GameConstants::RANDOMFACTION_SLOTNAME && + currentFactionName_factionPreview != GameConstants::OBSERVER_SLOTNAME && fileExists(factionDefinitionXML) == true) { + XmlTree xmlTree; + std::map mapExtraTagReplacementValues; + xmlTree.load(factionDefinitionXML, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); + const XmlNode *factionNode= xmlTree.getRootNode(); + if(factionNode->hasAttribute("faction-preview-video") == true) { + factionVideoUrl = factionNode->getAttribute("faction-preview-video")->getValue(); + } + + factionVideoUrlFallback = Game::findFactionLogoFile(gameSettings, NULL,"preview_video.*"); + if(factionVideoUrl == "") { + factionVideoUrl = factionVideoUrlFallback; + factionVideoUrlFallback = ""; + } + } + //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(factionVideoUrl != "") { + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + if(CoreData::getInstance().getMenuMusic()->getVolume() != 0) { + CoreData::getInstance().getMenuMusic()->setVolume(0); + } + if(currentFactionLogo != factionVideoUrl) { currentFactionLogo = factionVideoUrl; if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && @@ -3636,7 +3662,7 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, factionVideo = NULL; } string introVideoFile = factionVideoUrl; - string introVideoFileFallback = ""; + string introVideoFileFallback = factionVideoUrlFallback; Context *c= GraphicsInterface::getInstance().getCurrentContext(); SDL_Surface *screen = static_cast(c)->getPlatformContextGlPtr()->getScreen(); @@ -3658,6 +3684,21 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, } } } + else { + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + //switch on music again!! + Config &config = Config::getInstance(); + float configVolume = (config.getInt("SoundVolumeMusic") / 100.f); + if(CoreData::getInstance().getMenuMusic()->getVolume() != configVolume) { + CoreData::getInstance().getMenuMusic()->setVolume(configVolume); + } + + if(factionVideo != NULL) { + factionVideo->closePlayer(); + delete factionVideo; + factionVideo = NULL; + } + } if(factionVideo == NULL) { string factionLogo = Game::findFactionLogoFile(gameSettings, NULL,"preview_screen.*"); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index f478e9eb..8d808733 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2519,8 +2519,34 @@ void MenuStateCustomGame::update() { currentTechName_factionPreview=gameSettings.getTech(); currentFactionName_factionPreview=gameSettings.getFactionTypeName(gameSettings.getThisFactionIndex()); - string factionVideoUrl = Game::findFactionLogoFile(&gameSettings, NULL,"preview_video.*"); + string factionVideoUrl = ""; + string factionVideoUrlFallback = ""; + + string factionDefinitionXML = Game::findFactionLogoFile(&gameSettings, NULL,currentFactionName_factionPreview + ".xml"); + if(factionDefinitionXML != "" && currentFactionName_factionPreview != GameConstants::RANDOMFACTION_SLOTNAME && + currentFactionName_factionPreview != GameConstants::OBSERVER_SLOTNAME && fileExists(factionDefinitionXML) == true) { + XmlTree xmlTree; + std::map mapExtraTagReplacementValues; + xmlTree.load(factionDefinitionXML, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); + const XmlNode *factionNode= xmlTree.getRootNode(); + if(factionNode->hasAttribute("faction-preview-video") == true) { + factionVideoUrl = factionNode->getAttribute("faction-preview-video")->getValue(); + } + + factionVideoUrlFallback = Game::findFactionLogoFile(&gameSettings, NULL,"preview_video.*"); + if(factionVideoUrl == "") { + factionVideoUrl = factionVideoUrlFallback; + factionVideoUrlFallback = ""; + } + } + //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(factionVideoUrl != "") { + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + if(CoreData::getInstance().getMenuMusic()->getVolume() != 0) { + CoreData::getInstance().getMenuMusic()->setVolume(0); + } + if(currentFactionLogo != factionVideoUrl) { currentFactionLogo = factionVideoUrl; if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && @@ -2532,7 +2558,7 @@ void MenuStateCustomGame::update() { factionVideo = NULL; } string introVideoFile = factionVideoUrl; - string introVideoFileFallback = ""; + string introVideoFileFallback = factionVideoUrlFallback; Context *c= GraphicsInterface::getInstance().getCurrentContext(); SDL_Surface *screen = static_cast(c)->getPlatformContextGlPtr()->getScreen(); @@ -2554,6 +2580,21 @@ void MenuStateCustomGame::update() { } } } + else { + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + //switch on music again!! + Config &config = Config::getInstance(); + float configVolume = (config.getInt("SoundVolumeMusic") / 100.f); + if(CoreData::getInstance().getMenuMusic()->getVolume() != configVolume) { + CoreData::getInstance().getMenuMusic()->setVolume(configVolume); + } + + if(factionVideo != NULL) { + factionVideo->closePlayer(); + delete factionVideo; + factionVideo = NULL; + } + } if(factionVideo == NULL) { string factionLogo = Game::findFactionLogoFile(&gameSettings, NULL,"preview_screen.*");