From d28b64a2f57b32adbd9be94546956fb634543848 Mon Sep 17 00:00:00 2001 From: Morgan Christiansson Date: Sun, 21 Jun 2026 19:05:32 +0200 Subject: [PATCH 1/4] Load map from main screen --- CGame.cpp | 7 +++++++ CGame.h | 2 ++ callbacks.cpp | 47 +++++++++++++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/CGame.cpp b/CGame.cpp index 2b28fd3..e42fc26 100644 --- a/CGame.cpp +++ b/CGame.cpp @@ -156,6 +156,13 @@ void CGame::delMapObj() MapObj.reset(); } +void CGame::enterEditor(const boost::filesystem::path& filepath) +{ + for(auto& menu : Menus) + menu->setWaste(); + setMapObj(std::make_unique(filepath)); +} + void CGame::GameLoop() { for(auto&& callback : Callbacks) diff --git a/CGame.h b/CGame.h index f1e74eb..89131f4 100644 --- a/CGame.h +++ b/CGame.h @@ -7,6 +7,7 @@ #include "CIO/CFont.h" #include "SdlSurface.h" +#include #include #include #include @@ -92,6 +93,7 @@ class CGame void setMapObj(std::unique_ptr MapObj); CMap* getMapObj(); void delMapObj(); + void enterEditor(const boost::filesystem::path& filepath); SDL_Surface* getDisplaySurface() const { return Surf_Display.get(); }; auto getRes() const { return GameResolution; } }; diff --git a/callbacks.cpp b/callbacks.cpp index 31ede4d..5c7f121 100644 --- a/callbacks.cpp +++ b/callbacks.cpp @@ -133,6 +133,7 @@ void callback::mainmenu(int Param) { ENDGAME = 1, STARTEDITOR, + LOADMAP, OPTIONS }; @@ -142,9 +143,10 @@ void callback::mainmenu(int Param) MainMenu = global::s2->RegisterMenu(std::make_unique(SPLASHSCREEN_MAINMENU)); MainMenu->addButton(mainmenu, ENDGAME, 50, 400, 200, 20, BUTTON_RED1, "Quit program"); #ifdef _ADMINMODE - MainMenu->addButton(submenu1, INITIALIZING_CALL, 50, 200, 200, 20, BUTTON_GREY, "Submenu_1"); + MainMenu->addButton(submenu1, INITIALIZING_CALL, 50, 240, 200, 20, BUTTON_GREY, "Submenu_1"); #endif MainMenu->addButton(mainmenu, STARTEDITOR, 50, 160, 200, 20, BUTTON_RED1, "Start editor"); + MainMenu->addButton(mainmenu, LOADMAP, 50, 200, 200, 20, BUTTON_GREEN2, "Load map"); MainMenu->addButton(mainmenu, OPTIONS, 50, 370, 200, 20, BUTTON_GREEN2, "Options"); break; @@ -157,13 +159,11 @@ void callback::mainmenu(int Param) global::s2->Running = false; break; - case STARTEDITOR: + case STARTEDITOR: global::s2->enterEditor(""); break; + + case LOADMAP: assert(MainMenu); - PleaseWait(INITIALIZING_CALL); - global::s2->setMapObj(std::make_unique("")); - MainMenu->setWaste(); - MainMenu = nullptr; - PleaseWait(WINDOW_QUIT_MESSAGE); + EditorLoadMenu(INITIALIZING_CALL); break; case OPTIONS: @@ -788,17 +788,21 @@ void callback::EditorLoadMenu(int Param) return; PleaseWait(INITIALIZING_CALL); - // we have to close the windows and initialize them again to prevent failures - EditorCursorMenu(MAP_QUIT); - EditorTextureMenu(MAP_QUIT); - EditorTreeMenu(MAP_QUIT); - EditorLandscapeMenu(MAP_QUIT); - MinimapMenu(MAP_QUIT); - EditorResourceMenu(MAP_QUIT); - EditorAnimalMenu(MAP_QUIT); - EditorPlayerMenu(MAP_QUIT); + if(MapObj) + { + // we have to close the windows and initialize them again to prevent failures + EditorCursorMenu(MAP_QUIT); + EditorTextureMenu(MAP_QUIT); + EditorTreeMenu(MAP_QUIT); + EditorLandscapeMenu(MAP_QUIT); + MinimapMenu(MAP_QUIT); + EditorResourceMenu(MAP_QUIT); + EditorAnimalMenu(MAP_QUIT); + EditorPlayerMenu(MAP_QUIT); + + MapObj->destructMap(); + } - MapObj->destructMap(); bfs::path filepath = global::userMapsPath / curFilename; if(!filepath.has_extension()) filepath.replace_extension("SWD"); @@ -806,7 +810,14 @@ void callback::EditorLoadMenu(int Param) filepath.replace_extension("WLD"); if(!bfs::exists(filepath)) filepath.replace_extension("SWD"); - MapObj->constructMap(filepath); + + if(MapObj) + { + MapObj->constructMap(filepath); + } else + { + global::s2->enterEditor(filepath); + } // we need to check which of these windows was active before /* From 2f71dad153575ef36ea9de408afb7343985c43f4 Mon Sep 17 00:00:00 2001 From: Morgan Christiansson Date: Mon, 22 Jun 2026 11:25:04 +0200 Subject: [PATCH 2/4] Call enterEditor() to load save when already inside editor --- callbacks.cpp | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/callbacks.cpp b/callbacks.cpp index 5c7f121..f811e78 100644 --- a/callbacks.cpp +++ b/callbacks.cpp @@ -740,7 +740,6 @@ void callback::EditorMainMenu(int Param) void callback::EditorLoadMenu(int Param) { static CWindow* WNDLoad = nullptr; - static CMap* MapObj = nullptr; static std::string curFilename; enum @@ -757,8 +756,6 @@ void callback::EditorLoadMenu(int Param) break; WNDLoad = global::s2->RegisterWindow(std::make_unique( EditorLoadMenu, WINDOWQUIT, WindowPos::Center, Extent(280, 320), "Load", WINDOW_GREEN1, WINDOW_CLOSE)); - MapObj = global::s2->getMapObj(); - auto* CB_Filename = WNDLoad->addSelectBox(Point16(10, 5), Extent16(160, 280), FontSize::Medium); curFilename.clear(); for(const auto& itFile : bfs::directory_iterator(global::userMapsPath)) @@ -788,20 +785,15 @@ void callback::EditorLoadMenu(int Param) return; PleaseWait(INITIALIZING_CALL); - if(MapObj) - { - // we have to close the windows and initialize them again to prevent failures - EditorCursorMenu(MAP_QUIT); - EditorTextureMenu(MAP_QUIT); - EditorTreeMenu(MAP_QUIT); - EditorLandscapeMenu(MAP_QUIT); - MinimapMenu(MAP_QUIT); - EditorResourceMenu(MAP_QUIT); - EditorAnimalMenu(MAP_QUIT); - EditorPlayerMenu(MAP_QUIT); - - MapObj->destructMap(); - } + // we have to close the windows and initialize them again to prevent failures + EditorCursorMenu(MAP_QUIT); + EditorTextureMenu(MAP_QUIT); + EditorTreeMenu(MAP_QUIT); + EditorLandscapeMenu(MAP_QUIT); + MinimapMenu(MAP_QUIT); + EditorResourceMenu(MAP_QUIT); + EditorAnimalMenu(MAP_QUIT); + EditorPlayerMenu(MAP_QUIT); bfs::path filepath = global::userMapsPath / curFilename; if(!filepath.has_extension()) @@ -811,13 +803,7 @@ void callback::EditorLoadMenu(int Param) if(!bfs::exists(filepath)) filepath.replace_extension("SWD"); - if(MapObj) - { - MapObj->constructMap(filepath); - } else - { - global::s2->enterEditor(filepath); - } + global::s2->enterEditor(filepath); // we need to check which of these windows was active before /* From 541eaab3f73deabc7a33ca4676c66a681294fb55 Mon Sep 17 00:00:00 2001 From: Morgan Christiansson Date: Tue, 23 Jun 2026 14:42:18 +0200 Subject: [PATCH 3/4] Remove assert for now unused var --- callbacks.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/callbacks.cpp b/callbacks.cpp index f811e78..d4a1519 100644 --- a/callbacks.cpp +++ b/callbacks.cpp @@ -161,10 +161,7 @@ void callback::mainmenu(int Param) case STARTEDITOR: global::s2->enterEditor(""); break; - case LOADMAP: - assert(MainMenu); - EditorLoadMenu(INITIALIZING_CALL); - break; + case LOADMAP: EditorLoadMenu(INITIALIZING_CALL); break; case OPTIONS: assert(MainMenu); From 3e0d7cf05f4bfbdb7417eaa974fedbc4c36f6d85 Mon Sep 17 00:00:00 2001 From: Morgan Christiansson Date: Tue, 23 Jun 2026 14:48:30 +0200 Subject: [PATCH 4/4] Match addButton() order with UI --- callbacks.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/callbacks.cpp b/callbacks.cpp index d4a1519..0981ac5 100644 --- a/callbacks.cpp +++ b/callbacks.cpp @@ -142,11 +142,11 @@ void callback::mainmenu(int Param) case INITIALIZING_CALL: MainMenu = global::s2->RegisterMenu(std::make_unique(SPLASHSCREEN_MAINMENU)); MainMenu->addButton(mainmenu, ENDGAME, 50, 400, 200, 20, BUTTON_RED1, "Quit program"); + MainMenu->addButton(mainmenu, STARTEDITOR, 50, 160, 200, 20, BUTTON_RED1, "Start editor"); + MainMenu->addButton(mainmenu, LOADMAP, 50, 200, 200, 20, BUTTON_GREEN2, "Load map"); #ifdef _ADMINMODE MainMenu->addButton(submenu1, INITIALIZING_CALL, 50, 240, 200, 20, BUTTON_GREY, "Submenu_1"); #endif - MainMenu->addButton(mainmenu, STARTEDITOR, 50, 160, 200, 20, BUTTON_RED1, "Start editor"); - MainMenu->addButton(mainmenu, LOADMAP, 50, 200, 200, 20, BUTTON_GREEN2, "Load map"); MainMenu->addButton(mainmenu, OPTIONS, 50, 370, 200, 20, BUTTON_GREEN2, "Options"); break;