2010-03-18 22:26:40 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2010-07-08 10:29:51 +02:00
|
|
|
// Copyright (C) 2001-2005 Martio Figueroa
|
2010-03-18 22:26:40 +01:00
|
|
|
//
|
|
|
|
// 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 "menu_state_scenario.h"
|
|
|
|
|
|
|
|
#include "renderer.h"
|
|
|
|
#include "menu_state_new_game.h"
|
|
|
|
#include "sound_renderer.h"
|
|
|
|
#include "core_data.h"
|
|
|
|
#include "menu_state_options.h"
|
|
|
|
#include "network_manager.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "auto_test.h"
|
|
|
|
#include "game.h"
|
|
|
|
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
using namespace Shared::Xml;
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class MenuStateScenario
|
|
|
|
// =====================================================
|
|
|
|
|
2012-06-30 21:11:54 +02:00
|
|
|
MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu,
|
|
|
|
bool isTutorialMode, const vector<string> &dirList, string autoloadScenarioName) :
|
2010-03-18 22:26:40 +01:00
|
|
|
MenuState(program, mainMenu, "scenario")
|
|
|
|
{
|
2010-09-09 23:07:39 +02:00
|
|
|
containerName = "Scenario";
|
2012-06-30 21:11:54 +02:00
|
|
|
this->isTutorialMode = isTutorialMode;
|
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
enableScenarioTexturePreview = Config::getInstance().getBool("EnableScenarioTexturePreview","true");
|
2011-03-31 00:14:51 +02:00
|
|
|
scenarioLogoTexture=NULL;
|
2011-03-31 02:33:40 +02:00
|
|
|
previewLoadDelayTimer=time(NULL);
|
|
|
|
needToLoadTextures=true;
|
2011-03-31 00:14:51 +02:00
|
|
|
|
2010-03-18 22:26:40 +01:00
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
2012-03-15 21:48:27 +01:00
|
|
|
try {
|
|
|
|
networkManager.init(nrServer);
|
|
|
|
}
|
|
|
|
catch(const std::exception &ex) {
|
2012-10-19 03:31:20 +02:00
|
|
|
char szBuf[8096]="";
|
2013-05-28 17:42:54 +02:00
|
|
|
snprintf(szBuf,8096,"In [%s::%s %d] Error detected:\n%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
|
2012-03-15 21:48:27 +01:00
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
|
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
|
|
|
|
|
|
|
|
mainMessageBoxState=1;
|
|
|
|
showMessageBox( "Error: " + string(ex.what()), "Error detected", false);
|
|
|
|
}
|
2010-09-01 08:05:28 +02:00
|
|
|
|
2010-09-09 23:07:39 +02:00
|
|
|
mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox");
|
2013-10-29 07:13:38 +01:00
|
|
|
mainMessageBox.init(lang.getString("Ok"));
|
2010-09-01 08:05:28 +02:00
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
mainMessageBoxState=0;
|
|
|
|
|
|
|
|
this->autoloadScenarioName = autoloadScenarioName;
|
2010-03-18 22:26:40 +01:00
|
|
|
vector<string> results;
|
|
|
|
|
|
|
|
this->dirList = dirList;
|
|
|
|
|
2013-10-24 01:20:13 +02:00
|
|
|
int buttonStartY=50;
|
|
|
|
int buttonStartX=70;
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2010-09-09 23:07:39 +02:00
|
|
|
buttonReturn.registerGraphicComponent(containerName,"buttonReturn");
|
2013-10-24 01:20:13 +02:00
|
|
|
buttonReturn.init(buttonStartX, buttonStartY, 125);
|
2013-10-29 07:13:38 +01:00
|
|
|
buttonReturn.setText(lang.getString("Return"));
|
2010-09-09 23:07:39 +02:00
|
|
|
|
|
|
|
buttonPlayNow.registerGraphicComponent(containerName,"buttonPlayNow");
|
2013-10-24 01:20:13 +02:00
|
|
|
buttonPlayNow.init(buttonStartX+150, buttonStartY, 125);
|
2013-10-29 07:13:38 +01:00
|
|
|
buttonPlayNow.setText(lang.getString("PlayNow"));
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2013-10-24 01:20:13 +02:00
|
|
|
int startY=700;
|
|
|
|
int startX=50;
|
2010-09-09 23:07:39 +02:00
|
|
|
|
|
|
|
labelScenario.registerGraphicComponent(containerName,"labelScenario");
|
2013-10-24 01:20:13 +02:00
|
|
|
labelScenario.init(startX, startY);
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2013-10-24 01:20:13 +02:00
|
|
|
listBoxScenario.registerGraphicComponent(containerName,"listBoxScenario");
|
|
|
|
listBoxScenario.init(startX, startY-30, 290);
|
|
|
|
|
|
|
|
labelScenarioName.registerGraphicComponent(containerName,"labelScenarioName");
|
|
|
|
labelScenarioName.init(startX, startY-80);
|
|
|
|
labelScenarioName.setFont(CoreData::getInstance().getMenuFontBig());
|
|
|
|
labelScenarioName.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
|
|
|
|
|
|
|
labelInfo.registerGraphicComponent(containerName,"labelInfo");
|
|
|
|
labelInfo.init(startX, startY-110);
|
|
|
|
labelInfo.setFont(CoreData::getInstance().getMenuFontNormal());
|
|
|
|
labelInfo.setFont3D(CoreData::getInstance().getMenuFontNormal3D());
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2012-06-30 21:11:54 +02:00
|
|
|
if(this->isTutorialMode == true) {
|
2013-10-29 07:13:38 +01:00
|
|
|
labelScenario.setText(lang.getString("Tutorial"));
|
2012-06-30 21:11:54 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-10-29 07:13:38 +01:00
|
|
|
labelScenario.setText(lang.getString("Scenario"));
|
2012-06-30 21:11:54 +02:00
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
|
|
|
|
//scenario listbox
|
|
|
|
findDirs(dirList, results);
|
|
|
|
scenarioFiles = results;
|
2011-10-06 20:04:59 +02:00
|
|
|
//printf("scenarioFiles[0] [%s]\n",scenarioFiles[0].c_str());
|
|
|
|
|
2011-09-01 03:11:23 +02:00
|
|
|
if(results.empty() == true) {
|
2012-06-30 21:11:54 +02:00
|
|
|
//throw megaglest_runtime_error("There are no scenarios found to load");
|
|
|
|
mainMessageBoxState=1;
|
|
|
|
if(this->isTutorialMode == true) {
|
|
|
|
showMessageBox( "Error: There are no tutorials found to load", "Error detected", false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
showMessageBox( "Error: There are no scenarios found to load", "Error detected", false);
|
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
2013-05-03 08:03:54 +02:00
|
|
|
|
|
|
|
std::map<string,string> scenarioErrors;
|
2013-10-24 01:20:13 +02:00
|
|
|
for(int i= 0; i<results.size(); ++i){
|
|
|
|
results[i] = formatString(results[i]);
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
listBoxScenario.setItems(results);
|
|
|
|
|
2011-01-02 17:55:52 +01:00
|
|
|
try {
|
2012-07-18 03:01:24 +02:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] listBoxScenario.getSelectedItemIndex() = %d scenarioFiles.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,listBoxScenario.getSelectedItemIndex(),(int)scenarioFiles.size());
|
2013-05-03 08:03:54 +02:00
|
|
|
|
2012-07-18 02:54:47 +02:00
|
|
|
if(listBoxScenario.getItemCount() > 0 && listBoxScenario.getSelectedItemIndex() >= 0 && listBoxScenario.getSelectedItemIndex() < scenarioFiles.size()) {
|
2013-11-08 23:41:17 +01:00
|
|
|
string scenarioPath = Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]);
|
|
|
|
//printf("scenarioPath [%s]\n",scenarioPath.c_str());
|
|
|
|
|
|
|
|
loadScenarioInfo(scenarioPath, &scenarioInfo );
|
2012-06-30 21:11:54 +02:00
|
|
|
labelInfo.setText(scenarioInfo.desc);
|
2013-10-24 01:20:13 +02:00
|
|
|
if(scenarioInfo.namei18n != "") {
|
|
|
|
labelScenarioName.setText(scenarioInfo.namei18n);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
labelScenarioName.setText(listBoxScenario.getSelectedItem());
|
|
|
|
}
|
2012-06-30 21:11:54 +02:00
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2011-01-02 17:55:52 +01:00
|
|
|
GraphicComponent::applyAllCustomProperties(containerName);
|
|
|
|
}
|
|
|
|
catch(const std::exception &ex) {
|
2012-10-19 03:31:20 +02:00
|
|
|
char szBuf[8096]="";
|
2013-05-28 17:42:54 +02:00
|
|
|
snprintf(szBuf,8096,"In [%s::%s %d] Error detected:\n%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
|
2011-01-02 17:55:52 +01:00
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
|
2011-01-02 17:55:52 +01:00
|
|
|
|
|
|
|
mainMessageBoxState=1;
|
|
|
|
showMessageBox( "Error: " + string(ex.what()), "Error detected", false);
|
|
|
|
}
|
2013-05-03 08:03:54 +02:00
|
|
|
|
2013-05-17 07:01:23 +02:00
|
|
|
if(scenarioErrors.empty() == false) {
|
2013-05-03 08:03:54 +02:00
|
|
|
mainMessageBoxState=1;
|
|
|
|
|
|
|
|
string errorMsg = "";
|
|
|
|
for(std::map<string,string>::iterator iterMap = scenarioErrors.begin();
|
|
|
|
iterMap != scenarioErrors.end(); ++iterMap) {
|
|
|
|
errorMsg += "scenario: " + iterMap->first + " error text: " + iterMap->second.substr(0,400) + "\n";
|
|
|
|
}
|
|
|
|
showMessageBox( "Error loading scenario(s): " + errorMsg, "Error detected", false);
|
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
|
2011-10-25 20:39:11 +02:00
|
|
|
void MenuStateScenario::reloadUI() {
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
2011-11-04 00:38:43 +01:00
|
|
|
console.resetFonts();
|
2013-10-29 07:13:38 +01:00
|
|
|
mainMessageBox.init(lang.getString("Ok"));
|
2011-10-25 20:39:11 +02:00
|
|
|
labelInfo.setFont(CoreData::getInstance().getMenuFontNormal());
|
|
|
|
labelInfo.setFont3D(CoreData::getInstance().getMenuFontNormal3D());
|
|
|
|
|
2013-10-24 01:20:13 +02:00
|
|
|
labelScenarioName.setFont(CoreData::getInstance().getMenuFontNormal());
|
|
|
|
labelScenarioName.setFont3D(CoreData::getInstance().getMenuFontNormal3D());
|
|
|
|
|
2013-10-29 07:13:38 +01:00
|
|
|
buttonReturn.setText(lang.getString("Return"));
|
|
|
|
buttonPlayNow.setText(lang.getString("PlayNow"));
|
2011-10-25 20:39:11 +02:00
|
|
|
|
2013-10-29 07:13:38 +01:00
|
|
|
labelScenario.setText(lang.getString("Scenario"));
|
2011-10-25 20:39:11 +02:00
|
|
|
|
|
|
|
GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName);
|
|
|
|
}
|
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
MenuStateScenario::~MenuStateScenario() {
|
|
|
|
cleanupPreviewTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuStateScenario::cleanupPreviewTexture() {
|
2013-05-28 17:42:54 +02:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] scenarioLogoTexture [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,scenarioLogoTexture);
|
2011-03-31 03:34:01 +02:00
|
|
|
|
|
|
|
if(scenarioLogoTexture != NULL) {
|
|
|
|
Renderer::getInstance().endTexture(rsGlobal, scenarioLogoTexture, false);
|
|
|
|
}
|
|
|
|
scenarioLogoTexture = NULL;
|
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
void MenuStateScenario::mouseClick(int x, int y, MouseButton mouseButton) {
|
2010-03-18 22:26:40 +01:00
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
2013-11-05 22:25:51 +01:00
|
|
|
string advanceToItemStartingWith = "";
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2010-09-01 08:05:28 +02:00
|
|
|
if(mainMessageBox.getEnabled()){
|
2012-02-19 18:37:53 +01:00
|
|
|
int button= 0;
|
2012-07-03 02:26:27 +02:00
|
|
|
if(mainMessageBox.mouseClick(x, y, button)) {
|
2010-09-01 08:05:28 +02:00
|
|
|
soundRenderer.playFx(coreData.getClickSoundA());
|
2012-02-19 18:37:53 +01:00
|
|
|
if(button==0) {
|
2010-09-01 08:05:28 +02:00
|
|
|
mainMessageBox.setEnabled(false);
|
2012-07-03 02:26:27 +02:00
|
|
|
|
|
|
|
if(scenarioFiles.empty() == true && mainMessageBoxState ==1) {
|
|
|
|
mainMenu->setState(new MenuStateNewGame(program, mainMenu));
|
|
|
|
return;
|
|
|
|
}
|
2010-09-01 08:05:28 +02:00
|
|
|
}
|
|
|
|
}
|
2013-11-05 22:25:51 +01:00
|
|
|
return;
|
2010-09-01 08:05:28 +02:00
|
|
|
}
|
2013-11-05 22:25:51 +01:00
|
|
|
else {
|
|
|
|
if(Shared::Platform::Window::isKeyStateModPressed(KMOD_SHIFT) == true) {
|
|
|
|
const wchar_t lastKey = Shared::Platform::Window::extractLastKeyPressed();
|
|
|
|
// xxx:
|
|
|
|
// string hehe=lastKey;
|
|
|
|
// printf("lastKey = %d [%c] '%s'\n",lastKey,lastKey,hehe);
|
|
|
|
advanceToItemStartingWith = lastKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(buttonReturn.mouseClick(x,y)){
|
2010-03-18 22:26:40 +01:00
|
|
|
soundRenderer.playFx(coreData.getClickSoundA());
|
|
|
|
mainMenu->setState(new MenuStateNewGame(program, mainMenu));
|
2012-07-03 02:26:27 +02:00
|
|
|
return;
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
else if(buttonPlayNow.mouseClick(x,y)){
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundC());
|
|
|
|
launchGame();
|
2011-04-03 04:11:45 +02:00
|
|
|
return;
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
2013-11-05 22:25:51 +01:00
|
|
|
else if(listBoxScenario.mouseClick(x, y,advanceToItemStartingWith)){
|
2011-01-02 18:06:07 +01:00
|
|
|
try {
|
2012-07-18 03:01:24 +02:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] listBoxScenario.getSelectedItemIndex() = %d scenarioFiles.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,listBoxScenario.getSelectedItemIndex(),(int)scenarioFiles.size());
|
2012-07-18 02:43:46 +02:00
|
|
|
|
2012-07-18 02:54:47 +02:00
|
|
|
if(listBoxScenario.getItemCount() > 0 && listBoxScenario.getSelectedItemIndex() >= 0 && listBoxScenario.getSelectedItemIndex() < scenarioFiles.size()) {
|
2012-07-18 02:12:42 +02:00
|
|
|
loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo);
|
|
|
|
labelInfo.setText(scenarioInfo.desc);
|
2013-10-24 01:20:13 +02:00
|
|
|
if(scenarioInfo.namei18n != "") {
|
|
|
|
labelScenarioName.setText(scenarioInfo.namei18n);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
labelScenarioName.setText(listBoxScenario.getSelectedItem());
|
|
|
|
}
|
2012-07-18 02:12:42 +02:00
|
|
|
}
|
2011-01-02 18:06:07 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &ex) {
|
2012-10-19 03:31:20 +02:00
|
|
|
char szBuf[8096]="";
|
2013-05-28 17:42:54 +02:00
|
|
|
snprintf(szBuf,8096,"In [%s::%s %d] Error detected:\n%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
|
2011-01-02 18:06:07 +01:00
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
|
2011-01-02 18:06:07 +01:00
|
|
|
|
|
|
|
mainMessageBoxState=1;
|
|
|
|
showMessageBox( "Error: " + string(ex.what()), "Error detected", false);
|
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuStateScenario::mouseMove(int x, int y, const MouseState *ms){
|
|
|
|
|
2010-09-01 08:05:28 +02:00
|
|
|
if (mainMessageBox.getEnabled()) {
|
|
|
|
mainMessageBox.mouseMove(x, y);
|
|
|
|
}
|
|
|
|
|
2010-03-18 22:26:40 +01:00
|
|
|
listBoxScenario.mouseMove(x, y);
|
|
|
|
|
|
|
|
buttonReturn.mouseMove(x, y);
|
|
|
|
buttonPlayNow.mouseMove(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuStateScenario::render(){
|
|
|
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
2011-03-31 00:14:51 +02:00
|
|
|
if(scenarioLogoTexture != NULL) {
|
2013-10-24 01:20:13 +02:00
|
|
|
renderer.renderTextureQuad(450,200,533,400,scenarioLogoTexture,1.0f);
|
|
|
|
//renderer.renderBackground(scenarioLogoTexture);
|
2011-03-31 00:14:51 +02:00
|
|
|
}
|
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
if(mainMessageBox.getEnabled()) {
|
2010-09-01 08:05:28 +02:00
|
|
|
renderer.renderMessageBox(&mainMessageBox);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
renderer.renderLabel(&labelInfo);
|
2013-10-24 01:20:13 +02:00
|
|
|
renderer.renderLabel(&labelScenarioName);
|
|
|
|
|
2010-09-01 08:05:28 +02:00
|
|
|
renderer.renderLabel(&labelScenario);
|
|
|
|
renderer.renderListBox(&listBoxScenario);
|
2010-07-08 10:29:51 +02:00
|
|
|
|
2010-09-01 08:05:28 +02:00
|
|
|
renderer.renderButton(&buttonReturn);
|
|
|
|
renderer.renderButton(&buttonPlayNow);
|
|
|
|
}
|
2011-04-15 03:05:36 +02:00
|
|
|
renderer.renderConsole(&console,false,true);
|
2010-07-08 10:29:51 +02:00
|
|
|
if(program != NULL) program->renderProgramMsgBox();
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
void MenuStateScenario::update() {
|
2010-09-01 08:05:28 +02:00
|
|
|
if(Config::getInstance().getBool("AutoTest")) {
|
2010-03-18 22:26:40 +01:00
|
|
|
AutoTest::getInstance().updateScenario(this);
|
2012-03-17 09:20:17 +01:00
|
|
|
return;
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
2010-09-01 08:05:28 +02:00
|
|
|
if(this->autoloadScenarioName != "") {
|
2013-11-10 20:47:04 +01:00
|
|
|
string scenarioPath = Scenario::getScenarioPath(dirList, this->autoloadScenarioName);
|
|
|
|
|
|
|
|
//printf("[%s:%s] Line: %d this->autoloadScenarioName [%s] scenarioPath [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->autoloadScenarioName.c_str(),scenarioPath.c_str());
|
|
|
|
|
|
|
|
loadScenarioInfo(scenarioPath, &scenarioInfo );
|
2013-09-19 08:56:50 +02:00
|
|
|
if(scenarioInfo.namei18n != "") {
|
|
|
|
this->autoloadScenarioName = scenarioInfo.namei18n;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this->autoloadScenarioName = formatString(this->autoloadScenarioName);
|
|
|
|
}
|
|
|
|
|
|
|
|
listBoxScenario.setSelectedItem(this->autoloadScenarioName,false);
|
2010-09-01 08:05:28 +02:00
|
|
|
|
2013-09-19 08:56:50 +02:00
|
|
|
if(listBoxScenario.getSelectedItem() != this->autoloadScenarioName) {
|
2010-09-01 08:05:28 +02:00
|
|
|
mainMessageBoxState=1;
|
2013-09-19 08:56:50 +02:00
|
|
|
showMessageBox( "Could not find scenario name: " + this->autoloadScenarioName, "Scenario Missing", false);
|
2010-09-01 08:05:28 +02:00
|
|
|
this->autoloadScenarioName = "";
|
|
|
|
}
|
|
|
|
else {
|
2013-05-28 17:42:54 +02:00
|
|
|
try {
|
|
|
|
this->autoloadScenarioName = "";
|
|
|
|
if(listBoxScenario.getItemCount() > 0 && listBoxScenario.getSelectedItemIndex() >= 0 && listBoxScenario.getSelectedItemIndex() < scenarioFiles.size()) {
|
|
|
|
loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo);
|
|
|
|
labelInfo.setText(scenarioInfo.desc);
|
2013-10-24 01:20:13 +02:00
|
|
|
if(scenarioInfo.namei18n != "") {
|
|
|
|
labelScenarioName.setText(scenarioInfo.namei18n);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
labelScenarioName.setText(listBoxScenario.getSelectedItem());
|
|
|
|
}
|
2013-05-28 17:42:54 +02:00
|
|
|
|
|
|
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundC());
|
|
|
|
launchGame();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const std::exception &ex) {
|
|
|
|
char szBuf[8096]="";
|
|
|
|
snprintf(szBuf,8096,"In [%s::%s %d] Error detected:\n%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
|
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
|
|
|
|
|
|
|
|
mainMessageBoxState=1;
|
|
|
|
showMessageBox( "Error: " + string(ex.what()), "Error detected", false);
|
2012-07-18 02:12:42 +02:00
|
|
|
}
|
2010-09-01 08:05:28 +02:00
|
|
|
}
|
|
|
|
}
|
2011-03-31 02:33:40 +02:00
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
if(needToLoadTextures) {
|
2011-03-31 02:33:40 +02:00
|
|
|
// this delay is done to make it possible to switch faster
|
|
|
|
if(difftime(time(NULL), previewLoadDelayTimer) >= 2){
|
|
|
|
loadScenarioPreviewTexture();
|
|
|
|
needToLoadTextures= false;
|
|
|
|
}
|
|
|
|
}
|
2011-04-15 03:05:36 +02:00
|
|
|
console.update();
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
void MenuStateScenario::launchGame() {
|
2012-07-18 18:01:19 +02:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] scenarioInfo.file [%s] [%s][%s][%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,scenarioInfo.file.c_str(),scenarioInfo.tilesetName.c_str(),scenarioInfo.mapName.c_str(),scenarioInfo.techTreeName.c_str());
|
2012-07-18 02:35:39 +02:00
|
|
|
|
|
|
|
if(scenarioInfo.file != "" && scenarioInfo.tilesetName != "" && scenarioInfo.mapName != "" && scenarioInfo.techTreeName != "") {
|
|
|
|
GameSettings gameSettings;
|
|
|
|
loadGameSettings(&scenarioInfo, &gameSettings);
|
|
|
|
program->setState(new Game(program, &gameSettings, false));
|
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
void MenuStateScenario::setScenario(int i) {
|
2010-03-18 22:26:40 +01:00
|
|
|
listBoxScenario.setSelectedItemIndex(i);
|
|
|
|
loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo);
|
|
|
|
}
|
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
void MenuStateScenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) {
|
2013-05-21 22:28:42 +02:00
|
|
|
bool isTutorial = Scenario::isGameTutorial(file);
|
2013-11-10 20:47:04 +01:00
|
|
|
|
|
|
|
//printf("[%s:%s] Line: %d file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,file.c_str());
|
|
|
|
|
2013-05-21 22:28:42 +02:00
|
|
|
Scenario::loadScenarioInfo(file, scenarioInfo, isTutorial);
|
2010-04-24 05:57:38 +02:00
|
|
|
|
2011-03-31 03:34:01 +02:00
|
|
|
cleanupPreviewTexture();
|
2011-03-31 02:33:40 +02:00
|
|
|
previewLoadDelayTimer=time(NULL);
|
|
|
|
needToLoadTextures=true;
|
|
|
|
}
|
2011-03-31 00:14:51 +02:00
|
|
|
|
2011-03-31 02:33:40 +02:00
|
|
|
void MenuStateScenario::loadScenarioPreviewTexture(){
|
2011-03-31 03:34:01 +02:00
|
|
|
if(enableScenarioTexturePreview == true) {
|
2012-07-18 02:12:42 +02:00
|
|
|
//if(listBoxScenario.getSelectedItemIndex() >= 0) {
|
2012-07-18 02:54:47 +02:00
|
|
|
if(listBoxScenario.getItemCount() > 0 && listBoxScenario.getSelectedItemIndex() >= 0 && listBoxScenario.getSelectedItemIndex() < scenarioFiles.size()) {
|
2012-06-30 21:11:54 +02:00
|
|
|
GameSettings gameSettings;
|
|
|
|
loadGameSettings(&scenarioInfo, &gameSettings);
|
2011-03-31 00:14:51 +02:00
|
|
|
|
2012-06-30 21:11:54 +02:00
|
|
|
string scenarioLogo = "";
|
|
|
|
bool loadingImageUsed = false;
|
2011-03-31 00:14:51 +02:00
|
|
|
|
2012-06-30 21:11:54 +02:00
|
|
|
Game::extractScenarioLogoFile(&gameSettings, scenarioLogo, loadingImageUsed);
|
2011-03-31 03:34:01 +02:00
|
|
|
|
2013-05-28 17:42:54 +02:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] scenarioLogo [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,scenarioLogo.c_str());
|
2011-03-31 03:34:01 +02:00
|
|
|
|
2012-06-30 21:11:54 +02:00
|
|
|
if(scenarioLogo != "") {
|
|
|
|
cleanupPreviewTexture();
|
2012-09-25 09:05:52 +02:00
|
|
|
scenarioLogoTexture = Renderer::findTexture(scenarioLogo);
|
2012-06-30 21:11:54 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cleanupPreviewTexture();
|
|
|
|
scenarioLogoTexture = NULL;
|
|
|
|
}
|
2011-03-31 00:14:51 +02:00
|
|
|
}
|
2011-03-31 03:34:01 +02:00
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuStateScenario::loadGameSettings(const ScenarioInfo *scenarioInfo, GameSettings *gameSettings){
|
2011-04-03 04:11:45 +02:00
|
|
|
if(listBoxScenario.getSelectedItemIndex() < 0) {
|
2012-10-19 03:31:20 +02:00
|
|
|
char szBuf[8096]="";
|
|
|
|
snprintf(szBuf,8096,"listBoxScenario.getSelectedItemIndex() < 0, = %d",listBoxScenario.getSelectedItemIndex());
|
2012-04-14 23:21:09 +02:00
|
|
|
throw megaglest_runtime_error(szBuf);
|
2011-04-03 04:11:45 +02:00
|
|
|
}
|
|
|
|
else if(listBoxScenario.getSelectedItemIndex() >= scenarioFiles.size()) {
|
2012-10-19 03:31:20 +02:00
|
|
|
char szBuf[8096]="";
|
|
|
|
snprintf(szBuf,8096,"listBoxScenario.getSelectedItemIndex() >= scenarioFiles.size(), = [%d][%d]",listBoxScenario.getSelectedItemIndex(),(int)scenarioFiles.size());
|
2012-04-14 23:21:09 +02:00
|
|
|
throw megaglest_runtime_error(szBuf);
|
2011-04-03 04:11:45 +02:00
|
|
|
}
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2011-10-06 20:04:59 +02:00
|
|
|
Scenario::loadGameSettings(dirList,scenarioInfo, gameSettings, formatString(scenarioFiles[listBoxScenario.getSelectedItemIndex()]));
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
|
2010-09-01 08:05:28 +02:00
|
|
|
void MenuStateScenario::showMessageBox(const string &text, const string &header, bool toggle){
|
|
|
|
if(!toggle){
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!mainMessageBox.getEnabled()){
|
|
|
|
mainMessageBox.setText(text);
|
|
|
|
mainMessageBox.setHeader(header);
|
|
|
|
mainMessageBox.setEnabled(true);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-26 03:55:08 +02:00
|
|
|
void MenuStateScenario::keyDown(SDL_KeyboardEvent key) {
|
2010-09-09 23:07:39 +02:00
|
|
|
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
2011-06-26 03:55:08 +02:00
|
|
|
if(isKeyPressed(configKeys.getSDLKey("SaveGUILayout"),key) == true) {
|
2011-09-01 03:11:23 +02:00
|
|
|
GraphicComponent::saveAllCustomProperties(containerName);
|
2010-09-09 23:07:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 22:26:40 +01:00
|
|
|
}}//end namespace
|