- allow streaming faction preview videos and fallback to local faction preview

This commit is contained in:
Mark Vejvoda 2012-05-26 06:19:30 +00:00
parent ead7c316e5
commit e014ecbd94
2 changed files with 86 additions and 4 deletions

View File

@ -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<string,string> 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<ContextGl*>(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.*");

View File

@ -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<string,string> 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<ContextGl*>(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.*");