diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index d9d15875b..95536a461 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -153,7 +153,7 @@ int Game::ErrorDisplayMessage(const char *msg, bool exitApp) { return 0; } -string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger) { +string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,string factionLogoFilter) { string result = ""; if(settings == NULL) { result = ""; @@ -191,7 +191,7 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger) { } // use a scenario based loading screen vector loadScreenList; - findAll(scenarioDir + "loading_screen.*", loadScreenList, false, false); + findAll(scenarioDir + factionLogoFilter, loadScreenList, false, false); if(loadScreenList.size() > 0) { //string senarioLogo = scenarioDir + "/" + "loading_screen.jpg"; string senarioLogo = scenarioDir + loadScreenList[0]; @@ -224,7 +224,7 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,path.c_str()); if(isdir(path.c_str()) == true) { vector loadScreenList; - findAll(path + "/" + "loading_screen.*", loadScreenList, false, false); + findAll(path + "/" + factionLogoFilter, loadScreenList, false, false); if(loadScreenList.size() > 0) { //string factionLogo = path + "/" + "loading_screen.jpg"; string factionLogo = path + "/" + loadScreenList[0]; @@ -262,7 +262,7 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,path.c_str()); if(isdir(path.c_str()) == true) { vector loadScreenList; - findAll(path + "/" + "loading_screen.*", loadScreenList, false, false); + findAll(path + "/" + factionLogoFilter, loadScreenList, false, false); if(loadScreenList.size() > 0) { //string factionLogo = path + "/" + "loading_screen.jpg"; string factionLogo = path + "/" + loadScreenList[0]; diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index b74f5535b..e93a5bd87 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -143,7 +143,7 @@ public: void endPerformanceTimer(); Vec2i getPerformanceTimerResults(); - static string findFactionLogoFile(const GameSettings *settings, Logger *logger); + static string findFactionLogoFile(const GameSettings *settings, Logger *logger, string factionLogoFilter="loading_screen.*"); private: //render diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 90cefe1ea..f924b1b13 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -52,6 +52,7 @@ const char *GAME_ARGS[] = { "--help", "--connecthost", "--starthost", + "--load-scenario", "--version", "--opengl-info", "--sdl-info", @@ -63,6 +64,7 @@ enum GAME_ARG_TYPE { GAME_ARG_HELP = 0, GAME_ARG_CLIENT, GAME_ARG_SERVER, + GAME_ARG_LOADSCENARIO, GAME_ARG_VERSION, GAME_ARG_OPENGL_INFO, GAME_ARG_SDL_INFO, @@ -462,6 +464,7 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n%s\t\t\t\tdisplays this help text.",GAME_ARGS[GAME_ARG_HELP]); printf("\n%s=x\t\t\tAuto connects to a network server at IP or hostname x",GAME_ARGS[GAME_ARG_CLIENT]); printf("\n%s\t\t\tAuto creates a network server.",GAME_ARGS[GAME_ARG_SERVER]); + printf("\n%s=x\t\t\tAuto loads the specified scenario by scenario name.",GAME_ARGS[GAME_ARG_LOADSCENARIO]); printf("\n%s\t\t\tdisplays the version string of this program.",GAME_ARGS[GAME_ARG_VERSION]); printf("\n%s\t\t\tdisplays your video driver's OpenGL information.",GAME_ARGS[GAME_ARG_OPENGL_INFO]); printf("\n%s\t\t\tdisplays your SDL version information.",GAME_ARGS[GAME_ARG_SDL_INFO]); @@ -695,7 +698,28 @@ int glestMain(int argc, char** argv){ return -1; } } - else{ + else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_LOADSCENARIO])) == true) { + + int foundParamIndIndex = -1; + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_LOADSCENARIO]) + string("="),&foundParamIndIndex); + if(foundParamIndIndex < 0) { + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_LOADSCENARIO]),&foundParamIndIndex); + } + string scenarioName = argv[foundParamIndIndex]; + vector paramPartTokens; + Tokenize(scenarioName,paramPartTokens,"="); + if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) { + string autoloadScenarioName = paramPartTokens[1]; + program->initScenario(mainWindow, autoloadScenarioName); + } + else { + printf("\nInvalid scenario name specified on commandline [%s] host [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); + printParameterHelp(argv[0],foundInvalidArgs); + delete mainWindow; + return -1; + } + } + else { program->initNormal(mainWindow); } diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index cafc6419c..afd96be27 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -26,6 +26,7 @@ #include "network_manager.h" #include "menu_state_custom_game.h" #include "menu_state_join_game.h" +#include "menu_state_scenario.h" #include "leak_dumper.h" using namespace Shared::Util; @@ -149,7 +150,7 @@ void Program::initServer(WindowGl *window){ mainMenu->setState(new MenuStateCustomGame(this, mainMenu, true)); } -void Program::initClient(WindowGl *window, const Ip &serverIp){ +void Program::initClient(WindowGl *window, const Ip &serverIp) { MainMenu* mainMenu= NULL; init(window); @@ -158,6 +159,15 @@ void Program::initClient(WindowGl *window, const Ip &serverIp){ mainMenu->setState(new MenuStateJoinGame(this, mainMenu, true, serverIp)); } +void Program::initScenario(WindowGl *window, string autoloadScenarioName) { + MainMenu* mainMenu= NULL; + + init(window); + mainMenu= new MainMenu(this); + setState(mainMenu); + mainMenu->setState(new MenuStateScenario(this, mainMenu, Config::getInstance().getPathListForType(ptScenarios),autoloadScenarioName)); +} + Program::~Program(){ delete programState; programState = NULL; diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 6a23d9aa9..7328d6808 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -133,6 +133,7 @@ public: void initNormal(WindowGl *window); void initServer(WindowGl *window); void initClient(WindowGl *window, const Ip &serverIp); + void initScenario(WindowGl *window, string autoloadScenarioName); //main void keyDown(char key); diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 09950e341..da88bf2e9 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -800,7 +800,10 @@ void MenuStateConnectedGame::update() { if( clientInterface != NULL && clientInterface->isConnected() && gameSettings != NULL) { - string factionLogo = Game::findFactionLogoFile(gameSettings, NULL); + string factionLogo = Game::findFactionLogoFile(gameSettings, NULL,"preview_screen.*"); + if(factionLogo == "") { + factionLogo = Game::findFactionLogoFile(gameSettings, NULL); + } if(currentFactionLogo != factionLogo) { currentFactionLogo = factionLogo; loadFactionTexture(currentFactionLogo); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 0b9bb55dd..59be4a7a4 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1296,7 +1296,10 @@ void MenuStateCustomGame::update() { } soundConnectionCount = currentConnectionCount; - string factionLogo = Game::findFactionLogoFile(&gameSettings, NULL); + string factionLogo = Game::findFactionLogoFile(&gameSettings, NULL,"preview_screen.*"); + if(factionLogo == "") { + factionLogo = Game::findFactionLogoFile(&gameSettings, NULL); + } if(currentFactionLogo != factionLogo) { currentFactionLogo = factionLogo; loadFactionTexture(currentFactionLogo); diff --git a/source/glest_game/menu/menu_state_scenario.cpp b/source/glest_game/menu/menu_state_scenario.cpp index 06b6e1a83..e3fb0f80b 100644 --- a/source/glest_game/menu/menu_state_scenario.cpp +++ b/source/glest_game/menu/menu_state_scenario.cpp @@ -31,11 +31,17 @@ using namespace Shared::Xml; // class MenuStateScenario // ===================================================== -MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const vector &dirList): +MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const vector &dirList, string autoloadScenarioName): MenuState(program, mainMenu, "scenario") { Lang &lang= Lang::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance(); + + mainMessageBox.init(lang.get("Ok")); + mainMessageBox.setEnabled(false); + mainMessageBoxState=0; + + this->autoloadScenarioName = autoloadScenarioName; vector results; this->dirList = dirList; @@ -61,7 +67,7 @@ MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const throw runtime_error("There are no scenarios"); } for(int i= 0; isetState(new MenuStateNewGame(program, mainMenu)); } @@ -92,6 +109,10 @@ void MenuStateScenario::mouseClick(int x, int y, MouseButton mouseButton){ void MenuStateScenario::mouseMove(int x, int y, const MouseState *ms){ + if (mainMessageBox.getEnabled()) { + mainMessageBox.mouseMove(x, y); + } + listBoxScenario.mouseMove(x, y); buttonReturn.mouseMove(x, y); @@ -102,20 +123,42 @@ void MenuStateScenario::render(){ Renderer &renderer= Renderer::getInstance(); - renderer.renderLabel(&labelInfo); - renderer.renderLabel(&labelScenario); - renderer.renderListBox(&listBoxScenario); - - renderer.renderButton(&buttonReturn); - renderer.renderButton(&buttonPlayNow); + if(mainMessageBox.getEnabled()){ + renderer.renderMessageBox(&mainMessageBox); + } + else { + renderer.renderLabel(&labelInfo); + renderer.renderLabel(&labelScenario); + renderer.renderListBox(&listBoxScenario); + renderer.renderButton(&buttonReturn); + renderer.renderButton(&buttonPlayNow); + } if(program != NULL) program->renderProgramMsgBox(); } void MenuStateScenario::update(){ - if(Config::getInstance().getBool("AutoTest")){ + if(Config::getInstance().getBool("AutoTest")) { AutoTest::getInstance().updateScenario(this); } + if(this->autoloadScenarioName != "") { + listBoxScenario.setSelectedItem(formatString(this->autoloadScenarioName),false); + + if(listBoxScenario.getSelectedItem() != formatString(this->autoloadScenarioName)) { + mainMessageBoxState=1; + showMessageBox( "Could not find scenario name: " + formatString(this->autoloadScenarioName), "Scenario Missing", false); + this->autoloadScenarioName = ""; + } + else { + loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo); + labelInfo.setText(scenarioInfo.desc); + + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + CoreData &coreData= CoreData::getInstance(); + soundRenderer.playFx(coreData.getClickSoundC()); + launchGame(); + } + } } void MenuStateScenario::launchGame(){ @@ -266,4 +309,19 @@ ControlType MenuStateScenario::strToControllerType(const string &str){ throw std::runtime_error("Unknown controller type: " + str); } +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); + } +} + }}//end namespace diff --git a/source/glest_game/menu/menu_state_scenario.h b/source/glest_game/menu/menu_state_scenario.h index 9eb3fcaa3..c95cce2d7 100644 --- a/source/glest_game/menu/menu_state_scenario.h +++ b/source/glest_game/menu/menu_state_scenario.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2005 Martiņo Figueroa +// Copyright (C) 2001-2005 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -20,9 +20,9 @@ namespace Glest{ namespace Game{ // class MenuStateScenario // =============================== -class MenuStateScenario: public MenuState{ +class MenuStateScenario: public MenuState { private: - enum Difficulty{ + enum Difficulty { dVeryEasy, dEasy, dMedium, @@ -43,8 +43,13 @@ private: ScenarioInfo scenarioInfo; vector dirList; + GraphicMessageBox mainMessageBox; + int mainMessageBoxState; + + string autoloadScenarioName; + public: - MenuStateScenario(Program *program, MainMenu *mainMenu, const vector &dirList); + MenuStateScenario(Program *program, MainMenu *mainMenu, const vector &dirList, string autoloadScenarioName=""); void mouseClick(int x, int y, MouseButton mouseButton); void mouseMove(int x, int y, const MouseState *mouseState); @@ -56,11 +61,12 @@ public: int getScenarioCount() const { return listBoxScenario.getItemCount(); } private: - void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo); + + void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo); void loadGameSettings(const ScenarioInfo *scenarioInfo, GameSettings *gameSettings); Difficulty computeDifficulty(const ScenarioInfo *scenarioInfo); ControlType strToControllerType(const string &str); - + void showMessageBox(const string &text, const string &header, bool toggle); };