- added support for custom video's on battle end screen:

look for videos 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-video="<path to video>"
faction-battle-end-lose-video="<path to video>"

if not defined 2. check the faction folder for the files:
battle_end_win_video.*
battle_end_lose_video.*

if not found check the data/core/menu/videos/ paths for:
battle_end_win.*
battle_end_lose.*
This commit is contained in:
Mark Vejvoda 2012-09-25 00:23:25 +00:00
parent 9e75b9144c
commit 3ede912b9a
7 changed files with 285 additions and 14 deletions

View File

@ -108,10 +108,11 @@ string PlayerStats::getStats() const {
// class Stats
// =====================================================
void Stats::init(int factionCount, int thisFactionIndex, const string& description){
void Stats::init(int factionCount, int thisFactionIndex, const string& description, const string techName) {
this->thisFactionIndex= thisFactionIndex;
this->factionCount= factionCount;
this->description= description;
this->techName = techName;
}
void Stats::setVictorious(int playerIndex){

View File

@ -73,6 +73,7 @@ private:
int maxConcurrentUnitCount;
int totalEndGameConcurrentUnitCount;
bool isMasterserverMode;
string techName;
public:
@ -88,9 +89,11 @@ public:
totalEndGameConcurrentUnitCount = 0;
isMasterserverMode = false;
timePlayed = 0;
techName = "";
}
void init(int factionCount, int thisFactionIndex, const string &description);
void init(int factionCount, int thisFactionIndex, const string &description,
const string techName);
string getDescription() const {return description;}
int getThisFactionIndex() const {return thisFactionIndex;}
@ -146,6 +149,9 @@ public:
void addFramesToCalculatePlaytime() {this->framesToCalculatePlaytime++; }
void setTechName(string name) { techName = name; }
string getTechName() const { return techName; }
string getStats() const;
void saveGame(XmlNode *rootNode);

View File

@ -80,6 +80,11 @@ CoreData::CoreData() {
introVideoFilename="";
mainMenuVideoFilename="";
battleEndWinVideoFilename="";
battleEndWinVideoFilenameFallback="";
battleEndLoseVideoFilename="";
battleEndLoseVideoFilenameFallback="";
}
CoreData::~CoreData() {
@ -450,11 +455,11 @@ void CoreData::load() {
findAll(mainVideoPath, mainVideos, false, false);
for(int i = 0; i < mainVideos.size(); ++i) {
string video = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/" + mainVideos[i];
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if intro video [%s] exists\n",video.c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if mainmenu video [%s] exists\n",video.c_str());
if(fileExists(video)) {
mainMenuVideoFilename = video;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND intro video [%s] will use this file\n",video.c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND mainmenu video [%s] will use this file\n",video.c_str());
break;
}
}
@ -465,16 +470,85 @@ void CoreData::load() {
findAll(mainVideoPath, mainVideos, false, false);
for(int i = 0; i < mainVideos.size(); ++i) {
string video = data_path + "data/core/menu/videos/" + mainVideos[i];
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if intro video [%s] exists\n",video.c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if mainmenu video [%s] exists\n",video.c_str());
if(fileExists(video)) {
mainMenuVideoFilename = video;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND intro video [%s] will use this file\n",video.c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND mainmenu video [%s] will use this file\n",video.c_str());
break;
}
}
}
}
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;
findAll(battleEndWinVideoPath, battleEndWinVideos, false, false);
for(int i = 0; i < battleEndWinVideos.size(); ++i) {
string video = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/" + battleEndWinVideos[i];
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if battle end win video [%s] exists\n",video.c_str());
if(fileExists(video)) {
battleEndWinVideoFilename = video;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND battle end win video [%s] will use this file\n",video.c_str());
break;
}
}
if(battleEndWinVideoFilename == "") {
battleEndWinVideoPath = data_path + "data/core/menu/videos/battle_end_win.*";
battleEndWinVideos.clear();
findAll(battleEndWinVideoPath, battleEndWinVideos, false, false);
for(int i = 0; i < battleEndWinVideos.size(); ++i) {
string video = data_path + "data/core/menu/videos/" + battleEndWinVideos[i];
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if battle end win video [%s] exists\n",video.c_str());
if(fileExists(video)) {
battleEndWinVideoFilename = video;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND battle end video win [%s] will use this file\n",video.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;
findAll(battleEndLoseVideoPath, battleEndLoseVideos, false, false);
for(int i = 0; i < battleEndLoseVideos.size(); ++i) {
string video = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/" + battleEndLoseVideos[i];
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if battle end lose video [%s] exists\n",video.c_str());
if(fileExists(video)) {
battleEndLoseVideoFilename = video;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND battle end lose video [%s] will use this file\n",video.c_str());
break;
}
}
if(battleEndLoseVideoFilename == "") {
battleEndLoseVideoPath = data_path + "data/core/menu/videos/battle_end_lose.*";
battleEndLoseVideos.clear();
findAll(battleEndLoseVideoPath, battleEndLoseVideos, false, false);
for(int i = 0; i < battleEndLoseVideos.size(); ++i) {
string video = data_path + "data/core/menu/videos/" + battleEndLoseVideos[i];
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if battle end lose video [%s] exists\n",video.c_str());
if(fileExists(video)) {
battleEndLoseVideoFilename = video;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND battle end video lose [%s] will use this file\n",video.c_str());
break;
}
}
}
}
}
}
@ -490,6 +564,18 @@ bool CoreData::hasMainMenuVideoFilename() const {
return result;
}
bool CoreData::hasBattleEndVideoFilename(bool won) const {
//bool result = (mainMenuVideoFilename != "" && fileExists(mainMenuVideoFilename) == true);
bool result = false;
if(won == true) {
result =(battleEndWinVideoFilename != "");
}
else {
result =(battleEndLoseVideoFilename != "");
}
return result;
}
void CoreData::loadFonts() {
Renderer &renderer= Renderer::getInstance();
Lang &lang= Lang::getInstance();

View File

@ -93,6 +93,10 @@ private:
string introVideoFilenameFallback;
string mainMenuVideoFilename;
string mainMenuVideoFilenameFallback;
string battleEndWinVideoFilename;
string battleEndWinVideoFilenameFallback;
string battleEndLoseVideoFilename;
string battleEndLoseVideoFilenameFallback;
public:
@ -191,6 +195,11 @@ public:
string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; }
bool hasIntroVideoFilenameFallback() const;
string getBattleEndVideoFilename(bool won) const { return won == true ? battleEndWinVideoFilename : battleEndLoseVideoFilename; }
bool hasBattleEndVideoFilename(bool won) const;
string getBattleEndVideoFilenameFallback(bool won) const { return won == true ? battleEndWinVideoFilenameFallback : battleEndLoseVideoFilenameFallback; }
bool hasBattleEndVideoFilenameFallback(bool won) const;
void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0);
bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings);

View File

@ -23,7 +23,9 @@
#include "metrics.h"
#include "stats.h"
#include "auto_test.h"
#include "video_player.h"
#include "game.h"
#include "game_settings.h"
#include "leak_dumper.h"
using namespace Shared::Util;
@ -34,7 +36,8 @@ namespace Glest{ namespace Game{
// class BattleEnd
// =====================================================
BattleEnd::BattleEnd(Program *program, const Stats *stats,ProgramState *originState): ProgramState(program) {
BattleEnd::BattleEnd(Program *program, const Stats *stats,ProgramState *originState) :
ProgramState(program), menuBackgroundVideo(NULL), gameSettings(NULL) {
containerName= "BattleEnd";
@ -44,6 +47,13 @@ BattleEnd::BattleEnd(Program *program, const Stats *stats,ProgramState *originSt
if(stats != NULL) {
this->stats= *stats;
}
if(originState != NULL) {
Game *game = dynamic_cast<Game *>(originState);
if(game != NULL) {
gameSettings = new GameSettings();
*gameSettings = *(game->getGameSettings());
}
}
mouseX = 0;
mouseY = 0;
mouse2d = 0;
@ -62,6 +72,8 @@ BattleEnd::BattleEnd(Program *program, const Stats *stats,ProgramState *originSt
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
initBackgroundVideo();
GraphicComponent::applyAllCustomProperties(containerName);
}
@ -77,6 +89,15 @@ void BattleEnd::reloadUI() {
BattleEnd::~BattleEnd() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(menuBackgroundVideo != NULL) {
menuBackgroundVideo->closePlayer();
delete menuBackgroundVideo;
menuBackgroundVideo = NULL;
}
delete gameSettings;
gameSettings = NULL;
delete originState;
originState = NULL;
@ -92,6 +113,126 @@ BattleEnd::~BattleEnd() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
std::pair<string,string> BattleEnd::getBattleEndVideo(bool won) {
std::pair<string,string> result;
string factionVideoUrl = "";
string factionVideoUrlFallback = "";
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-video") == true) {
factionVideoUrl = factionNode->getAttribute("faction-battle-end-win-video")->getValue();
}
}
else {
if(factionNode->hasAttribute("faction-battle-end-lose-video") == true) {
factionVideoUrl = factionNode->getAttribute("faction-battle-end-lose-video")->getValue();
}
}
if(won == true) {
factionVideoUrlFallback = Game::findFactionLogoFile(gameSettings, NULL,"battle_end_win_video.*");
}
else {
factionVideoUrlFallback = Game::findFactionLogoFile(gameSettings, NULL,"battle_end_lose_video.*");
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#3 factionVideoUrl [%s] factionVideoUrlFallback [%s]\n",factionVideoUrl.c_str(),factionVideoUrlFallback.c_str());
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 != "") {
result.first = factionVideoUrl;
result.second = factionVideoUrlFallback;
}
else {
result.first = CoreData::getInstance().getBattleEndVideoFilename(won);
result.second = CoreData::getInstance().getBattleEndVideoFilenameFallback(won);
}
return result;
}
void BattleEnd::initBackgroundVideo() {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false &&
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) {
if(menuBackgroundVideo != NULL) {
menuBackgroundVideo->closePlayer();
delete menuBackgroundVideo;
menuBackgroundVideo = NULL;
}
string videoFile = "";
string videoFileFallback = "";
if(stats.getTeam(stats.getThisFactionIndex()) != GameConstants::maxPlayers -1 + fpt_Observer) {
if(stats.getVictory(stats.getThisFactionIndex())){
//header += lang.get("Victory");
//videoFile = CoreData::getInstance().getBattleEndVideoFilename(true);
//videoFileFallback = CoreData::getInstance().getBattleEndVideoFilenameFallback(true);
std::pair<string,string> wonVideos = getBattleEndVideo(true);
videoFile = wonVideos.first;
videoFileFallback = wonVideos.second;
}
else{
//header += lang.get("Defeat");
//videoFile = CoreData::getInstance().getBattleEndVideoFilename(false);
//videoFileFallback = CoreData::getInstance().getBattleEndVideoFilenameFallback(false);
std::pair<string,string> lostVideos = getBattleEndVideo(false);
videoFile = lostVideos.first;
videoFileFallback = lostVideos.second;
}
}
else {
//header += "Observer";
}
if(fileExists(videoFile) || fileExists(videoFileFallback)) {
Context *c= GraphicsInterface::getInstance().getCurrentContext();
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
menuBackgroundVideo = new VideoPlayer(
&Renderer::getInstance(),
videoFile,
videoFileFallback,
screen,
0,0,
screen->w,
screen->h,
screen->format->BitsPerPixel,
vlcPluginsPath,
SystemFlags::VERBOSE_MODE_ENABLED);
menuBackgroundVideo->initPlayer();
}
}
}
const string BattleEnd::getTimeString(int frames) {
int framesleft=frames;
int hours=(int) frames / (float)GameConstants::updateFps / 3600.0;
@ -143,7 +284,7 @@ void BattleEnd::render() {
incrementFps();
//printf("In [%s::%s Line: %d] renderToTexture [%p]\n",__FILE__,__FUNCTION__,__LINE__,renderToTexture);
if(renderToTexture != NULL) {
if(menuBackgroundVideo == NULL && renderToTexture != NULL) {
//printf("Rendering from texture!\n");
renderer.clearBuffers();
@ -166,7 +307,7 @@ void BattleEnd::render() {
else {
//printf("Rendering to texture!\n");
renderer.beginRenderToTexture(&renderToTexture);
if(menuBackgroundVideo == NULL) renderer.beginRenderToTexture(&renderToTexture);
TextRenderer2D *textRenderer2D = renderer.getTextRenderer();
TextRenderer3D *textRenderer3D = renderer.getTextRenderer3D();
@ -185,8 +326,25 @@ void BattleEnd::render() {
renderer.reset3dMenu();
renderer.clearZBuffer();
renderer.reset2d();
renderer.renderBackground(CoreData::getInstance().getBackgroundTexture());
if(menuBackgroundVideo != NULL) {
//printf("Rendering video not null!\n");
if(menuBackgroundVideo->isPlaying() == true) {
menuBackgroundVideo->playFrame(false);
//printf("Rendering video playing!\n");
}
else {
if(menuBackgroundVideo != NULL) {
initBackgroundVideo();
}
}
}
else {
renderer.renderBackground(CoreData::getInstance().getBackgroundTexture());
}
//int winnerIndex = -1;
int bestScore = -1;
//int mostKillsIndex = -1;
@ -462,11 +620,11 @@ void BattleEnd::render() {
renderer.renderMessageBox(&mainMessageBox);
}
if(renderToTexture == NULL) {
if(menuBackgroundVideo == NULL || renderToTexture == NULL) {
renderer.renderMouse2d(mouseX, mouseY, mouse2d, 0.f);
}
renderer.endRenderToTexture(&renderToTexture);
if(menuBackgroundVideo == NULL) renderer.endRenderToTexture(&renderToTexture);
}
renderer.renderFPSWhenEnabled(lastFps);

View File

@ -21,8 +21,13 @@
#include "stats.h"
#include "leak_dumper.h"
namespace Shared { namespace Graphics {
class VideoPlayer;
}}
namespace Glest{ namespace Game{
class GameSettings;
// =====================================================
// class BattleEnd
//
@ -42,6 +47,9 @@ private:
ProgramState *originState;
const char *containerName;
Shared::Graphics::VideoPlayer *menuBackgroundVideo;
GameSettings *gameSettings;
void showMessageBox(const string &text, const string &header, bool toggle);
public:
@ -58,6 +66,9 @@ public:
private:
const string getTimeString(int frames);
void initBackgroundVideo();
std::pair<string,string> getBattleEndVideo(bool won);
};
}}//end namespace

View File

@ -1445,7 +1445,7 @@ void World::initFactionTypes(GameSettings *gs) {
}
//create stats
stats.init(gs->getFactionCount(), gs->getThisFactionIndex(), gs->getDescription());
stats.init(gs->getFactionCount(), gs->getThisFactionIndex(), gs->getDescription(),gs->getTech());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);