load/save/delete setups

This commit is contained in:
titiger 2019-10-16 20:46:43 +02:00
parent 10f23fb3ad
commit 22d22e275b
5 changed files with 87 additions and 97 deletions

View File

@ -380,7 +380,12 @@ public:
int getItemCount() const {return (int)items.size();} int getItemCount() const {return (int)items.size();}
string getItem(int index) const {return items[index];} string getItem(int index) const {return items[index];}
int getSelectedItemIndex() const {return selectedItemIndex;} int getSelectedItemIndex() const {return selectedItemIndex;}
string getSelectedItem() const {return items[selectedItemIndex];} string getSelectedItem() const {
if (selectedItemIndex < 0)
return "";
else
return items[selectedItemIndex];
}
GraphicButton *getButton() {return &dropDownButton;} GraphicButton *getButton() {return &dropDownButton;}
GraphicScrollBar *getScrollbar() {return &scrollBar;} GraphicScrollBar *getScrollbar() {return &scrollBar;}
GraphicButtons *getPopupButtons() {return &popupButtons;} GraphicButtons *getPopupButtons() {return &popupButtons;}

View File

@ -1359,27 +1359,17 @@ int CoreData::computeFontSize(int size) {
return rs; return rs;
} }
void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings, int advancedIndex, bool inSetupDir) { void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings, int advancedIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
Config &config = Config::getInstance(); Config &config = Config::getInstance();
string userData = config.getString("UserData_Root",""); string saveSetupDir = config.getString("UserData_Root","");
if(userData != "") {
endPathWithSlash(userData);
}
string saveSetupDir ;
if( inSetupDir)
saveSetupDir = userData +"setups";
else
saveSetupDir = userData;
createDirectoryPaths(saveSetupDir);
if(saveSetupDir != "") { if(saveSetupDir != "") {
endPathWithSlash(saveSetupDir); endPathWithSlash(saveSetupDir);
} }
fileName = saveSetupDir + fileName; fileName = saveSetupDir + fileName;
// create path if non existant
createDirectoryPaths(extractDirectoryPathFromFile(fileName));
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str());
#if defined(WIN32) && !defined(__MINGW32__) #if defined(WIN32) && !defined(__MINGW32__)
@ -1434,25 +1424,15 @@ void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSe
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
} }
bool CoreData::loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings, bool inSetupDir) { bool CoreData::loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
bool fileWasFound = false; bool fileWasFound = false;
Config &config = Config::getInstance(); Config &config = Config::getInstance();
string userData = config.getString("UserData_Root",""); string saveSetupDir = config.getString("UserData_Root","");
if(userData != "") {
endPathWithSlash(userData);
}
string saveSetupDir ;
if( inSetupDir)
saveSetupDir = userData +"setups";
else
saveSetupDir = userData;
if(saveSetupDir != "") { if(saveSetupDir != "") {
endPathWithSlash(saveSetupDir); endPathWithSlash(saveSetupDir);
} }
if(fileExists(saveSetupDir + fileName) == true) { if(fileExists(saveSetupDir + fileName) == true) {
fileName = saveSetupDir + fileName; fileName = saveSetupDir + fileName;

View File

@ -233,8 +233,8 @@ public:
string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; } string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; }
void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0, bool inSetupDir=false); void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0);
bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings, bool inSetupDir=false); bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings);
void registerFontChangedCallback(std::string entityName, FontChangedCallbackInterface *cb); void registerFontChangedCallback(std::string entityName, FontChangedCallbackInterface *cb);
void unRegisterFontChangedCallback(std::string entityName); void unRegisterFontChangedCallback(std::string entityName);

View File

@ -41,9 +41,11 @@ const int MASTERSERVER_BROADCAST_MAX_WAIT_RESPONSE_SECONDS = 15;
const int MASTERSERVER_BROADCAST_PUBLISH_SECONDS = 6; const int MASTERSERVER_BROADCAST_PUBLISH_SECONDS = 6;
const int BROADCAST_MAP_DELAY_SECONDS = 5; const int BROADCAST_MAP_DELAY_SECONDS = 5;
const int BROADCAST_SETTINGS_SECONDS = 4; const int BROADCAST_SETTINGS_SECONDS = 4;
static const char *SAVED_GAME_FILENAME = "lastCustomGameSettings.mgg"; static const char *SAVED_SETUP_FILENAME = "lastCustomGameSettings.mgg";
static const char *DEFAULT_GAME_FILENAME = "data/defaultGameSetup.mgg"; static const char *DEFAULT_SETUP_FILENAME = "data/defaultGameSetup.mgg";
static const char *DEFAULT_NETWORKGAME_FILENAME = "data/defaultNetworkGameSetup.mgg"; static const char *DEFAULT_NETWORK_SETUP_FILENAME = "data/defaultNetworkGameSetup.mgg";
static const char *LAST_SETUP_STRING="LastSetup";
static const char *SETUPS_DIR="setups/";
const int mapPreviewTexture_X = 5; const int mapPreviewTexture_X = 5;
const int mapPreviewTexture_Y = 260; const int mapPreviewTexture_Y = 260;
@ -152,7 +154,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
if(userData != "") { if(userData != "") {
endPathWithSlash(userData); endPathWithSlash(userData);
} }
savedSetupsDir = userData +"setups/"; savedSetupsDir = userData +SETUPS_DIR;
mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox"); mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox");
@ -213,7 +215,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
int currXLabel=currX+20; int currXLabel=currX+20;
int lineHeightSmall=18; int lineHeightSmall=18;
int buttonx=165; int buttonx=195;
int buttony=180; int buttony=180;
// player status // player status
@ -228,17 +230,12 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
listBoxPlayerStatus.setTextColor(Vec3f(0.0f,1.0f,0.0f)); listBoxPlayerStatus.setTextColor(Vec3f(0.0f,1.0f,0.0f));
listBoxPlayerStatus.setLighted(false); listBoxPlayerStatus.setLighted(false);
listBoxPlayerStatus.setVisible(true); listBoxPlayerStatus.setVisible(true);
buttonx+=180; buttonx+=175;
buttonReturn.registerGraphicComponent(containerName,"buttonReturn"); buttonReturn.registerGraphicComponent(containerName,"buttonReturn");
buttonReturn.init(buttonx, buttony, 125); buttonReturn.init(buttonx, buttony, 125);
buttonReturn.setText(lang.getString("Return")); buttonReturn.setText(lang.getString("Return"));
buttonx+=132; buttonx+=135;
buttonRestoreLastSettings.registerGraphicComponent(containerName,"buttonRestoreLastSettings");
buttonRestoreLastSettings.init(buttonx, buttony, 240);
buttonRestoreLastSettings.setText(lang.getString("ReloadLastGameSettings"));
buttonx+=247;
buttonPlayNow.registerGraphicComponent(containerName,"buttonPlayNow"); buttonPlayNow.registerGraphicComponent(containerName,"buttonPlayNow");
buttonPlayNow.init(buttonx, buttony, 125); buttonPlayNow.init(buttonx, buttony, 125);
@ -759,14 +756,14 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
if(openNetworkSlots == true) { if(openNetworkSlots == true) {
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
if(fileExists(data_path + DEFAULT_NETWORKGAME_FILENAME) == true) if(fileExists(data_path + DEFAULT_NETWORK_SETUP_FILENAME) == true)
loadGameSettings(data_path + DEFAULT_NETWORKGAME_FILENAME); loadGameSettings(data_path + DEFAULT_NETWORK_SETUP_FILENAME);
} }
else { else {
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
if(fileExists(data_path + DEFAULT_GAME_FILENAME) == true) if(fileExists(data_path + DEFAULT_SETUP_FILENAME) == true)
loadGameSettings(data_path + DEFAULT_GAME_FILENAME); loadGameSettings(data_path + DEFAULT_SETUP_FILENAME);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@ -885,7 +882,6 @@ void MenuStateCustomGame::reloadUI() {
buttonClearBlockedPlayers.setText(lang.getString("BlockPlayerClear")); buttonClearBlockedPlayers.setText(lang.getString("BlockPlayerClear"));
buttonReturn.setText(lang.getString("Return")); buttonReturn.setText(lang.getString("Return"));
buttonPlayNow.setText(lang.getString("PlayNow")); buttonPlayNow.setText(lang.getString("PlayNow"));
buttonRestoreLastSettings.setText(lang.getString("ReloadLastGameSettings"));
vector<string> controlItems; vector<string> controlItems;
controlItems.push_back(lang.getString("Closed")); controlItems.push_back(lang.getString("Closed"));
@ -1230,12 +1226,6 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
PlayNow(true); PlayNow(true);
return; return;
} }
else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) {
soundRenderer.playFx(coreData.getClickSoundB());
RestoreLastGameSettings();
}
else if (checkBoxAdvanced.getValue() == 1 && listBoxFogOfWar.mouseClick(x, y)) { else if (checkBoxAdvanced.getValue() == 1 && listBoxFogOfWar.mouseClick(x, y)) {
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@ -1269,31 +1259,41 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
break; break;
} }
} }
string setupname=intToStr(humanSlots)+"_"+gameSettings.getMap(); string setupName=intToStr(humanSlots)+"_"+gameSettings.getMap();
labelSaveSetupName.setText(trim(labelSaveSetupName.getText()));
if(labelSaveSetupName.getText()!=""){ if(labelSaveSetupName.getText()!=""){
setupname=labelSaveSetupName.getText(); setupName=labelSaveSetupName.getText();
setupName=replaceAll(setupName,"/","_");
setupName=replaceAll(setupName,"\\","_");
}
if( setupName!= lang.getString(LAST_SETUP_STRING)) {
string filename=setupName+".mgg";
saveGameSettingsToFile(SETUPS_DIR+filename);
console.addLine("--> " +filename);
loadSavedSetupNames();
comboBoxLoadSetup.setItems(savedSetupFilenames);
comboBoxLoadSetup.setSelectedItem(setupName);
} }
string filename=setupname+".mgg";
saveGameSettingsToFile(filename,true);
console.addLine("--> " +filename);
loadSavedSetupNames();
comboBoxLoadSetup.setItems(savedSetupFilenames);
comboBoxLoadSetup.setSelectedItem(setupname);
} }
else if ( buttonLoadSetup.mouseClick(x, y)){ else if ( buttonLoadSetup.mouseClick(x, y)){
string setupName=comboBoxLoadSetup.getSelectedItem(); string setupName=comboBoxLoadSetup.getSelectedItem();
loadGameSettings(setupName+".mgg",true); if( setupName!=""){
console.addLine("<-- " +setupName+".mgg"); string fileNameToLoad=SETUPS_DIR+setupName+".mgg";
if( setupName== lang.getString(LAST_SETUP_STRING)){
fileNameToLoad=SAVED_SETUP_FILENAME;
}
if(loadGameSettings(fileNameToLoad))
console.addLine("<-- " +setupName+".mgg");
}
} }
else if ( buttonDeleteSetup.mouseClick(x, y)){ else if ( buttonDeleteSetup.mouseClick(x, y)){
string setupName=comboBoxLoadSetup.getSelectedItem(); string setupName=comboBoxLoadSetup.getSelectedItem();
if( setupName!=""){ if( setupName!=""&& setupName!= lang.getString(LAST_SETUP_STRING)) {
removeFile(savedSetupsDir+setupName+".mgg"); removeFile(savedSetupsDir+setupName+".mgg");
loadSavedSetupNames(); loadSavedSetupNames();
comboBoxLoadSetup.setItems(savedSetupFilenames); comboBoxLoadSetup.setItems(savedSetupFilenames);
console.addLine("X " +setupName+".mgg"); console.addLine("X " +setupName+".mgg");
} }
} }
else if (checkBoxAdvanced.getValue() == 1 && buttonShowLanInfo.mouseClick(x, y)) { else if (checkBoxAdvanced.getValue() == 1 && buttonShowLanInfo.mouseClick(x, y)) {
// show to console // show to console
@ -1802,9 +1802,11 @@ void MenuStateCustomGame::updateResourceMultiplier(const int index) {
//printf("Line: %d multiplier index: %d index: %d\n",__LINE__,listBoxRMultiplier[index].getSelectedItemIndex(),index); //printf("Line: %d multiplier index: %d index: %d\n",__LINE__,listBoxRMultiplier[index].getSelectedItemIndex(),index);
} }
void MenuStateCustomGame::loadGameSettings(const std::string &fileName,bool inSetupDir) { bool MenuStateCustomGame::loadGameSettings(const std::string &fileName) {
// Ensure we have set the gamesettings at least once // Ensure we have set the gamesettings at least once
GameSettings gameSettings = loadGameSettingsFromFile(fileName,inSetupDir); GameSettings gameSettings;
bool result=loadGameSettingsFromFile(&gameSettings,fileName);
if(result==false) return false;
if(gameSettings.getMap() == "") { if(gameSettings.getMap() == "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@ -1825,10 +1827,11 @@ void MenuStateCustomGame::loadGameSettings(const std::string &fileName,bool inSe
needToSetChangedGameSettings = true; needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL); lastSetChangedGameSettings = time(NULL);
} }
return true;
} }
void MenuStateCustomGame::RestoreLastGameSettings() { void MenuStateCustomGame::RestoreLastGameSettings() {
loadGameSettings(SAVED_GAME_FILENAME); loadGameSettings(SAVED_SETUP_FILENAME);
} }
bool MenuStateCustomGame::checkNetworkPlayerDataSynch(bool checkMapCRC, bool MenuStateCustomGame::checkNetworkPlayerDataSynch(bool checkMapCRC,
@ -1883,7 +1886,7 @@ void MenuStateCustomGame::PlayNow(bool saveGame) {
MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
if(saveGame == true) { if(saveGame == true) {
saveGameSettingsToFile(SAVED_GAME_FILENAME); saveGameSettingsToFile(SAVED_SETUP_FILENAME);
} }
forceWaitForShutdown = false; forceWaitForShutdown = false;
@ -2136,7 +2139,6 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms) {
buttonReturn.mouseMove(x, y); buttonReturn.mouseMove(x, y);
buttonPlayNow.mouseMove(x, y); buttonPlayNow.mouseMove(x, y);
buttonRestoreLastSettings.mouseMove(x, y);
buttonClearBlockedPlayers.mouseMove(x, y); buttonClearBlockedPlayers.mouseMove(x, y);
buttonSaveSetup.mouseMove(x, y); buttonSaveSetup.mouseMove(x, y);
buttonLoadSetup.mouseMove(x, y); buttonLoadSetup.mouseMove(x, y);
@ -2255,7 +2257,6 @@ void MenuStateCustomGame::render() {
renderer.renderButton(&buttonReturn); renderer.renderButton(&buttonReturn);
renderer.renderButton(&buttonPlayNow); renderer.renderButton(&buttonPlayNow);
renderer.renderButton(&buttonRestoreLastSettings);
renderer.renderLabel(&labelSaveSetupName); renderer.renderLabel(&labelSaveSetupName);
renderer.renderButton(&buttonSaveSetup); renderer.renderButton(&buttonSaveSetup);
renderer.renderButton(&buttonLoadSetup); renderer.renderButton(&buttonLoadSetup);
@ -4104,37 +4105,40 @@ void MenuStateCustomGame::KeepCurrentHumanPlayerSlots(GameSettings &gameSettings
} }
} }
void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName, bool inSetupDir) { void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
GameSettings gameSettings; GameSettings gameSettings;
loadGameSettings(&gameSettings); loadGameSettings(&gameSettings);
CoreData::getInstance().saveGameSettingsToFile(fileName, &gameSettings,checkBoxAdvanced.getValue(),inSetupDir); CoreData::getInstance().saveGameSettingsToFile(fileName, &gameSettings,checkBoxAdvanced.getValue());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
} }
GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName, bool inSetupDir) { bool MenuStateCustomGame::loadGameSettingsFromFile(GameSettings *gameSettings,std::string fileName) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
GameSettings gameSettings;
GameSettings originalGameSettings; GameSettings originalGameSettings;
loadGameSettings(&originalGameSettings); loadGameSettings(&originalGameSettings);
try { try {
CoreData::getInstance().loadGameSettingsFromFile(fileName, &gameSettings, inSetupDir); bool loadSuccessful= CoreData::getInstance().loadGameSettingsFromFile(fileName, gameSettings);
KeepCurrentHumanPlayerSlots(gameSettings); if(!loadSuccessful){
console.addLine("Cannot load '"+fileName+"'");
// do nothing on failure
return false;
}
KeepCurrentHumanPlayerSlots(*gameSettings);
// correct game settings for headless: // correct game settings for headless:
if(this->headlessServerMode == true) { if(this->headlessServerMode == true) {
for(int i = 0; i < GameConstants::maxPlayers; ++i) { for(int i = 0; i < GameConstants::maxPlayers; ++i) {
if(gameSettings.getFactionControl(i)== ctHuman){ if(gameSettings->getFactionControl(i)== ctHuman){
gameSettings.setFactionControl(i,ctNetwork); gameSettings->setFactionControl(i,ctNetwork);
} }
} }
} }
setupUIFromGameSettings(gameSettings); setupUIFromGameSettings(*gameSettings);
} }
catch(const exception &ex) { catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
@ -4143,12 +4147,12 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName,
showMessageBox( ex.what(), "Error", false); showMessageBox( ex.what(), "Error", false);
setupUIFromGameSettings(originalGameSettings); setupUIFromGameSettings(originalGameSettings);
gameSettings = originalGameSettings; *gameSettings = originalGameSettings;
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
return gameSettings; return true;
} }
void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettings) { void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettings) {
@ -4377,8 +4381,8 @@ void MenuStateCustomGame::lastPlayerDisconnected() {
if(!foundConnectedPlayer && headlessHasConnectedPlayer==true ){ if(!foundConnectedPlayer && headlessHasConnectedPlayer==true ){
// load defaults // load defaults
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
if(fileExists(data_path + DEFAULT_NETWORKGAME_FILENAME) == true) if(fileExists(data_path + DEFAULT_NETWORK_SETUP_FILENAME) == true)
loadGameSettings(data_path + DEFAULT_NETWORKGAME_FILENAME); loadGameSettings(data_path + DEFAULT_NETWORK_SETUP_FILENAME);
} }
headlessHasConnectedPlayer=foundConnectedPlayer; headlessHasConnectedPlayer=foundConnectedPlayer;
} }
@ -5152,6 +5156,7 @@ void MenuStateCustomGame::SetupUIForScenarios() {
void MenuStateCustomGame::loadSavedSetupNames() { void MenuStateCustomGame::loadSavedSetupNames() {
Config &config = Config::getInstance(); Config &config = Config::getInstance();
Lang &lang= Lang::getInstance();
vector<string> paths; vector<string> paths;
string userData = config.getString("UserData_Root",""); string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
@ -5163,6 +5168,7 @@ void MenuStateCustomGame::loadSavedSetupNames() {
savedSetupFilenames.clear(); savedSetupFilenames.clear();
findAll(paths, "*.mgg", savedSetupFilenames, true, false, true); findAll(paths, "*.mgg", savedSetupFilenames, true, false, true);
sort(savedSetupFilenames.begin(),savedSetupFilenames.end()); sort(savedSetupFilenames.begin(),savedSetupFilenames.end());
savedSetupFilenames.insert(savedSetupFilenames.begin(),1,lang.getString(LAST_SETUP_STRING));
} }
int MenuStateCustomGame::setupMapList(string scenario) { int MenuStateCustomGame::setupMapList(string scenario) {

View File

@ -45,7 +45,6 @@ class MenuStateCustomGame : public MenuState, public SimpleTaskCallbackInterface
private: private:
GraphicButton buttonReturn; GraphicButton buttonReturn;
GraphicButton buttonPlayNow; GraphicButton buttonPlayNow;
GraphicButton buttonRestoreLastSettings;
GraphicLabel labelControl; GraphicLabel labelControl;
GraphicLabel labelRMultiplier; GraphicLabel labelRMultiplier;
GraphicLabel labelFaction; GraphicLabel labelFaction;
@ -280,7 +279,7 @@ private:
void returnToParentMenu(); void returnToParentMenu();
void showMessageBox(const string &text, const string &header, bool toggle); void showMessageBox(const string &text, const string &header, bool toggle);
void saveGameSettingsToFile(std::string fileName, bool saveInSetupDir=false); void saveGameSettingsToFile(std::string fileName);
void switchToNextMapGroup(const int direction); void switchToNextMapGroup(const int direction);
void updateAllResourceMultiplier(); void updateAllResourceMultiplier();
void updateResourceMultiplier(const int index); void updateResourceMultiplier(const int index);
@ -290,8 +289,8 @@ private:
void loadFactionTexture(string filepath); void loadFactionTexture(string filepath);
GameSettings loadGameSettingsFromFile(std::string fileName, bool inSetupDir=false); bool loadGameSettingsFromFile(GameSettings *gameSettings,std::string fileName);
void loadGameSettings(const std::string &fileName, bool inSetupDir=false); bool loadGameSettings(const std::string &fileName);
void RestoreLastGameSettings(); void RestoreLastGameSettings();
void PlayNow(bool saveGame); void PlayNow(bool saveGame);