From af36771b3cf8bf79868b9e8f4467943cee929ab8 Mon Sep 17 00:00:00 2001 From: titiger Date: Tue, 8 Oct 2019 01:08:24 +0200 Subject: [PATCH] save setups --- source/glest_game/global/core_data.cpp | 2 + .../menu/menu_state_custom_game.cpp | 49 ++++++++++++++----- .../glest_game/menu/menu_state_custom_game.h | 1 + 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 3dafb543..6e2781fe 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -1374,6 +1374,8 @@ void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSe else saveSetupDir = userData; + createDirectoryPaths(saveSetupDir); + if(saveSetupDir != "") { endPathWithSlash(saveSetupDir); } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 6566f061..dda13019 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -386,22 +386,38 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, listBoxTileset.setSelectedItemIndex(rand() % listBoxTileset.getItemCount()); - buttonSaveSetup.registerGraphicComponent(containerName,"buttonSaveSetup"); - buttonSaveSetup.init(xoffset+380, mapHeadPos-154, 125); - buttonSaveSetup.setText(lang.getString("Save")); - buttonLoadSetup.registerGraphicComponent(containerName,"buttonLoadSetup"); - buttonLoadSetup.init(xoffset+435, mapHeadPos-132, 110); - buttonLoadSetup.setText(lang.getString("Load")); - buttonDeleteSetup.registerGraphicComponent(containerName,"buttonDeleteSetup"); - buttonDeleteSetup.init(xoffset+325, mapHeadPos-132, 110); - buttonDeleteSetup.setText(lang.getString("Delete")); + // Save Setup + currY=mapHeadPos-100; + currX=xoffset+325; - //handle setup save/load - comboBoxLoadSetup.registerGraphicComponent(containerName,"comboBoxLoadSetup"); - comboBoxLoadSetup.init(xoffset+325, mapHeadPos-110, 220); + comboBoxLoadSetup.registerGraphicComponent(containerName,"comboBoxLoadSetup"); + comboBoxLoadSetup.init(currX, currY, 220); loadSavedSetupNames(); comboBoxLoadSetup.setItems(savedSetupFilenames); - //comboBoxLoadSetup.setSelectedItemIndex(initialMapSelection); + + currY = currY - labelOffset; + + buttonDeleteSetup.registerGraphicComponent(containerName,"buttonDeleteSetup"); + buttonDeleteSetup.init(currX, currY, 110); + buttonDeleteSetup.setText(lang.getString("Delete")); + buttonLoadSetup.registerGraphicComponent(containerName,"buttonLoadSetup"); + buttonLoadSetup.init(currX+110, currY, 110); + buttonLoadSetup.setText(lang.getString("Load")); + + currY = currY - labelOffset; + + labelSaveSetupName.registerGraphicComponent(containerName,"labelSaveSetupName"); + labelSaveSetupName.init(currX,currY, 110); + labelSaveSetupName.setText(""); + labelSaveSetupName.setEditable(true); + labelSaveSetupName.setMaxEditWidth(16); + labelSaveSetupName.setMaxEditRenderWidth(labelSaveSetupName.getW()); + labelSaveSetupName.setBackgroundColor(Vec4f(230,230,230,0.4)); + labelSaveSetupName.setRenderBackground(true); + + buttonSaveSetup.registerGraphicComponent(containerName,"buttonSaveSetup"); + buttonSaveSetup.init(currX+110, currY, 110); + buttonSaveSetup.setText(lang.getString("Save")); // Toy Block currY=mapHeadPos; @@ -1234,6 +1250,9 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { lastSetChangedGameSettings = time(NULL); } } + else if(labelSaveSetupName.mouseClick(x, y) ){ + setActiveInputLabel(&labelSaveSetupName); + } else if ( buttonSaveSetup.mouseClick(x, y)){ GameSettings gameSettings; loadGameSettings(&gameSettings); @@ -1251,6 +1270,9 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { } } string setupname=intToStr(humanSlots)+"_"+gameSettings.getMap(); + if(labelSaveSetupName.getText()!=""){ + setupname=labelSaveSetupName.getText(); + } string filename=setupname+".mgg"; saveGameSettingsToFile(filename,true); @@ -2234,6 +2256,7 @@ void MenuStateCustomGame::render() { renderer.renderButton(&buttonReturn); renderer.renderButton(&buttonPlayNow); renderer.renderButton(&buttonRestoreLastSettings); + renderer.renderLabel(&labelSaveSetupName); renderer.renderButton(&buttonSaveSetup); renderer.renderButton(&buttonLoadSetup); renderer.renderButton(&buttonDeleteSetup); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 2345ab7c..b1ae1e48 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -127,6 +127,7 @@ private: GraphicButton buttonShowLanInfo; GraphicButton buttonSaveSetup; + GraphicLabel labelSaveSetupName; GraphicButton buttonLoadSetup; GraphicButton buttonDeleteSetup; GraphicComboBox comboBoxLoadSetup;