loading screen for players faction ( doesn't work at the moment )
This commit is contained in:
parent
8681a551a1
commit
ab1c302107
|
@ -0,0 +1,122 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "renderer.h"
|
||||
#include "core_data.h"
|
||||
#include "metrics.h"
|
||||
#include "lang.h"
|
||||
#include "leak_dumper.h"
|
||||
#include "graphics_interface.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Shared::Graphics;
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
// =====================================================
|
||||
// class Logger
|
||||
// =====================================================
|
||||
|
||||
const int Logger::logLineCount= 15;
|
||||
|
||||
// ===================== PUBLIC ========================
|
||||
|
||||
Logger::Logger(){
|
||||
fileName= "log.txt";
|
||||
loadingTexture=NULL;
|
||||
}
|
||||
|
||||
Logger & Logger::getInstance(){
|
||||
static Logger logger;
|
||||
return logger;
|
||||
}
|
||||
|
||||
void Logger::add(const string &str, bool renderScreen){
|
||||
FILE *f=fopen(fileName.c_str(), "at+");
|
||||
if(f!=NULL){
|
||||
fprintf(f, "%s\n", str.c_str());
|
||||
fclose(f);
|
||||
}
|
||||
current= str;
|
||||
if(renderScreen){
|
||||
renderLoadingScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::clear(){
|
||||
string s="Log file\n";
|
||||
|
||||
FILE *f= fopen(fileName.c_str(), "wt+");
|
||||
if(f==NULL){
|
||||
throw runtime_error("Error opening log file"+ fileName);
|
||||
}
|
||||
|
||||
fprintf(f, "%s", s.c_str());
|
||||
fprintf(f, "\n");
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
void Logger::loadLoadingScreen(string filepath){
|
||||
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
|
||||
if(loadingTexture!=NULL)
|
||||
{
|
||||
delete loadingTexture;
|
||||
loadingTexture=NULL;
|
||||
}
|
||||
|
||||
if(filepath=="")
|
||||
{
|
||||
loadingTexture=NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
loadingTexture=GraphicsInterface::getInstance().getFactory()->newTexture2D();
|
||||
loadingTexture->setMipmap(false);
|
||||
loadingTexture->getPixmap()->load(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== PRIVATE ====================
|
||||
|
||||
void Logger::renderLoadingScreen(){
|
||||
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
CoreData &coreData= CoreData::getInstance();
|
||||
const Metrics &metrics= Metrics::getInstance();
|
||||
|
||||
renderer.reset2d();
|
||||
renderer.clearBuffers();
|
||||
if(loadingTexture==NULL){
|
||||
renderer.renderBackground(CoreData::getInstance().getBackgroundTexture());
|
||||
}
|
||||
else{
|
||||
renderer.renderBackground(loadingTexture);
|
||||
}
|
||||
renderer.renderText(
|
||||
state, coreData.getMenuFontBig(), Vec3f(1.f),
|
||||
metrics.getVirtualW()/4, 65*metrics.getVirtualH()/100, false);
|
||||
|
||||
renderer.renderText(
|
||||
current, coreData.getMenuFontNormal(), 1.0f,
|
||||
metrics.getVirtualW()/4,
|
||||
62*metrics.getVirtualH()/100, false);
|
||||
|
||||
renderer.swapBuffers();
|
||||
}
|
||||
|
||||
}}//end namespace
|
|
@ -0,0 +1,65 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_UTIL_LOGGER_H_
|
||||
#define _SHARED_UTIL_LOGGER_H_
|
||||
|
||||
#include <string>
|
||||
#include <deque>
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
using std::string;
|
||||
using std::deque;
|
||||
using Shared::Graphics::Texture2D;
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
// =====================================================
|
||||
// class Logger
|
||||
//
|
||||
/// Interface to write log files
|
||||
// =====================================================
|
||||
|
||||
class Logger{
|
||||
private:
|
||||
static const int logLineCount;
|
||||
|
||||
private:
|
||||
typedef deque<string> Strings;
|
||||
|
||||
private:
|
||||
string fileName;
|
||||
string state;
|
||||
string subtitle;
|
||||
string current;
|
||||
Texture2D *loadingTexture;
|
||||
|
||||
private:
|
||||
Logger();
|
||||
|
||||
public:
|
||||
static Logger & getInstance();
|
||||
|
||||
void setFile(const string &fileName) {this->fileName= fileName;}
|
||||
void setState(const string &state) {this->state= state;}
|
||||
void setSubtitle(const string &subtitle) {this->subtitle= subtitle;}
|
||||
|
||||
void add(const string &str, bool renderScreen= false);
|
||||
void loadLoadingScreen(string filepath);
|
||||
void renderLoadingScreen();
|
||||
|
||||
void clear();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
|
@ -62,7 +62,8 @@ Game::Game(Program *program, const GameSettings *gameSettings):
|
|||
Game::~Game(){
|
||||
Logger &logger= Logger::getInstance();
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
|
||||
|
||||
logger.loadLoadingScreen("");
|
||||
logger.setState(Lang::getInstance().get("Deleting"));
|
||||
logger.add("Game", true);
|
||||
|
||||
|
@ -84,7 +85,7 @@ void Game::load(){
|
|||
string tilesetName= gameSettings.getTileset();
|
||||
string techName= gameSettings.getTech();
|
||||
string scenarioName= gameSettings.getScenario();
|
||||
|
||||
|
||||
logger.setState(Lang::getInstance().get("Loading"));
|
||||
|
||||
if(scenarioName.empty()){
|
||||
|
@ -107,6 +108,25 @@ void Game::load(){
|
|||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getScenarioDir().c_str(),gameSettings.getScenario().c_str(),scenarioDir.c_str());
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Searching for loading screen\n",__FILE__,__FUNCTION__);
|
||||
for ( int i=0; i < gameSettings.getFactionCount(); ++i ) {
|
||||
if(gameSettings.getFactionControl(i)==ctHuman){
|
||||
vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir);
|
||||
for(int idx = 0; idx < pathList.size(); idx++) {
|
||||
const string path = pathList[idx]+ "/" +techName+ "/"+ "factions"+ "/"+ gameSettings.getFactionTypeName(i);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,path.c_str());
|
||||
if(isdir(path.c_str()) == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] found loading screen '%s'\n",__FILE__,__FUNCTION__,path.c_str());
|
||||
logger.loadLoadingScreen(path+"/"+"loading_screen.tga");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//tileset
|
||||
world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
|
|
Loading…
Reference in New Issue