mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- added new commandline option to auto-load a scenario:
--load-scenario=x - added support for a special faction preview texture when faction preview is enabled
This commit is contained in:
parent
21ded6679f
commit
ab42ca7ace
@ -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<string> 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<string> 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<string> 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];
|
||||
|
@ -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
|
||||
|
@ -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<string> 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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -31,11 +31,17 @@ using namespace Shared::Xml;
|
||||
// class MenuStateScenario
|
||||
// =====================================================
|
||||
|
||||
MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const vector<string> &dirList):
|
||||
MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const vector<string> &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<string> 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; i<results.size(); ++i){
|
||||
results[i]= formatString(results[i]);
|
||||
results[i] = formatString(results[i]);
|
||||
}
|
||||
listBoxScenario.setItems(results);
|
||||
|
||||
@ -76,7 +82,18 @@ void MenuStateScenario::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
CoreData &coreData= CoreData::getInstance();
|
||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||
|
||||
if(buttonReturn.mouseClick(x,y)){
|
||||
if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
if(mainMessageBox.mouseClick(x, y, button))
|
||||
{
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
if(button==1)
|
||||
{
|
||||
mainMessageBox.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(buttonReturn.mouseClick(x,y)){
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
mainMenu->setState(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
|
||||
|
@ -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<string> dirList;
|
||||
|
||||
GraphicMessageBox mainMessageBox;
|
||||
int mainMessageBoxState;
|
||||
|
||||
string autoloadScenarioName;
|
||||
|
||||
public:
|
||||
MenuStateScenario(Program *program, MainMenu *mainMenu, const vector<string> &dirList);
|
||||
MenuStateScenario(Program *program, MainMenu *mainMenu, const vector<string> &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);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user