Loads tips_en.txt in fraction lang folder if present.
game.cpp modification
// ==================== init and load ====================
void GameState::load() {
GameSettings &gameSettings = g_simInterface.getGameSettings();
const string &mapName = gameSettings.getMapPath();
const string &tilesetName = gameSettings.getTilesetPath();
const string &techName = gameSettings.getTechPath();
const string &scenarioPath = gameSettings.getScenarioPath();
string scenarioName = basename(scenarioPath);
const string &thisFactionName = gameSettings.getFactionTypeName(gameSettings.getThisFactionIndex());
// determine loading screen settings:
// 1. check sceneraio if applicable
// 2. check faction
// 3. check tech
// 4. use defaults
ProgramLog &log = g_logger.getProgramLog();
if (!scenarioName.empty()
&& log.setupLoadingScreen(scenarioPath)) {
} else if (log.setupLoadingScreen(techName + "/factions/" + thisFactionName)) {
} else if (log.setupLoadingScreen(techName)) {
} else {
log.useLoadingScreenDefaults();
}
// maybe use config option instead - hailstone 01May2011
if (g_program.getMouseCursor().descType() == "ImageSetMouseCursor") {
ImageSetMouseCursor &mouse = static_cast<ImageSetMouseCursor&>(g_program.getMouseCursor());
// check for custom mouse (faction then tech)
if (mouse.loadMouse(techName + "/factions/" + thisFactionName)) {
} else if (mouse.loadMouse(techName)) {
} else {
// already using default
}
}
g_logger.getProgramLog().setProgressBar(true);
g_logger.getProgramLog().setState(Lang::getInstance().get("Loading"));
// overwrite subtitles
//if (scenarioName.empty()) {
//log.setSubtitle(formatString(mapName) + " - " +
// formatString(tilesetName) + " - " + formatString(techName));
//} else {
// log.setSubtitle(formatString(scenarioName));
//}
simInterface->loadWorld();
// finished loading
g_logger.getProgramLog().setProgressBar(false);
}
logger.cpp modification
/** Load the loading screen settings from xml
* @return true if loaded successfully
*/
bool ProgramLog::setupLoadingScreen(const string &dir) {
string path = dir + "/" + basename(dir) + ".xml";
//open xml file
XmlTree xmlTree;
try {
xmlTree.load(path);
} catch (runtime_error e) {
g_logger.logXmlError(path, "File missing or wrongly named.");
return false; // bail
}
const XmlNode *rootNode;
try {
rootNode = xmlTree.getRootNode();
} catch (runtime_error e) {
g_logger.logXmlError(path, "File appears to lack contents.");
return false; // bail
}
const XmlNode *loadingScreenNode = rootNode->getChild("loading-screen", 0, false);
if (loadingScreenNode) {
// could randomly choose from multiple or choose
// based on resolution - hailstone 21Jan2011
// background texture
int x = loadingScreenNode->getChildCount();
int k = 0;
if (x!=1) {
int seed = int(Chrono::getCurMicros());
Random random(seed);
k = random.randRange(0, x - 1);
}
const XmlNode *backgroundImageNode = loadingScreenNode->getChild("background-image", k, true);
if (backgroundImageNode) {
// load background image from faction.xml
m_backgroundTexture = g_renderer.newTexture2D(ResourceScope::GLOBAL);
m_backgroundTexture->setMipmap(false);
m_backgroundTexture->getPixmap()->load(dir + "/" +
backgroundImageNode->getAttribute("path")->getValue());
try {
m_backgroundTexture->init(Texture::fBilinear);
} catch (...) {
m_backgroundTexture = Texture2D::defaultTexture;
}
}
// faction tips
string path = dir + "/lang/tips_" + g_lang.getLocale() + ".txt";
vector<string> Strings;
FileOps *f = g_fileFactory.getFileOps();
char *buf = 0;
try {
f->openRead(path.c_str());
int size = f->fileSize();
buf = new char[size + 1];
f->read(buf, size, 1);
buf[size] = '\0';
stringstream ss(buf);
delete [] buf;
buf = 0;
char buffer[1024];
while (!ss.eof()) {
ss.getline(buffer, 1023);
if (buffer[0] == ';' || buffer[0] == '\0' || buffer[0] == 10 || buffer[0] == 13) {
continue;
}
string str(buffer);
if (*(str.end() - 1) == 13) {
str = str.substr(0, str.size() - 1);
}
if (!str.empty()) {
Strings.push_back(str);
}
}
} catch (runtime_error &e) {
delete [] buf;
Strings.clear();
}
delete f;
// random tips selection
if(Strings.size()!=0){
int seed = int(Chrono::getCurMicros());
Random random(seed);
int k = random.randRange(0, Strings.size() - 1);
setSubtitle(Strings.at(k));
Strings.clear();
}
return true; // successfully using settings
}
return false;
}
void ProgramLog::renderLoadingScreen(){
g_renderer.reset2d();
g_renderer.clearBuffers();
const Font *normFont = g_widgetConfig.getMenuFont();
const Font *bigFont = g_widgetConfig.getTitleFont();
if (m_backgroundTexture) {
g_renderer.renderBackground(m_backgroundTexture);
}
Vec2i headerPos(g_metrics.getScreenW() / 4, 25 * g_metrics.getScreenH() / 100);
Vec4f colour(1.f);
g_renderer.renderText(state, bigFont, colour, headerPos.x, headerPos.y);
int yStart = headerPos.y + int(bigFont->getMetrics()->getHeight()) + 6;
if (loadingGame) {
int offset = 0;
int step = int(normFont->getMetrics()->getHeight()) + 4;
//for (Strings::reverse_iterator it = logLines.rbegin(); it != logLines.rend(); ++it) {
// colour.a = 1.f - float(offset) / float(logLineCount + 1);
// g_renderer.renderText(*it, normFont, colour, g_metrics.getScreenW() / 4,
// 30 * g_metrics.getScreenH() / 100 + offset * step);
// ++offset;
//}
colour.a = 1.f - float(offset);
string k = logLines.back();
g_renderer.renderText(k, normFont, colour, g_metrics.getScreenW() / 4,
30 * g_metrics.getScreenH() / 100 + offset * step);
g_renderer.renderText(subtitle, normFont, colour, g_metrics.getScreenW() / 4,
38 * g_metrics.getScreenH() / 100);
if (m_progressBar) {
Vec2i progBarPos = headerPos;
progBarPos.x += int(bigFont->getMetrics()->getTextDiminsions(state).w) + 20;
int w = g_metrics.getScreenW() / 4 * 3 - progBarPos.x;
int h = int(normFont->getMetrics()->getHeight() + 2.f);
g_renderer.renderProgressBar(m_progress, progBarPos.x, progBarPos.y, w, h, normFont);
}
} else {
g_renderer.renderText(current, normFont, colour, g_metrics.getScreenW() / 4,
38 * g_metrics.getScreenH() / 100);
}
g_renderer.swapBuffers();
}