Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ void CGame::delMapObj()
MapObj.reset();
}

void CGame::enterEditor(const boost::filesystem::path& filepath)
{
for(auto& menu : Menus)
menu->setWaste();
setMapObj(std::make_unique<CMap>(filepath));
}

void CGame::LoadSettings()
{
const bfs::path settingsPath = RTTRCONFIG.ExpandPath("<RTTR_USERDATA>/s25edit.ini");
Expand Down
2 changes: 2 additions & 0 deletions CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "CIO/CFont.h"
#include "SdlSurface.h"
#include <boost/filesystem/path.hpp>
#include <Point.h>
#include <memory>
#include <vector>
Expand Down Expand Up @@ -98,6 +99,7 @@ class CGame
void setMapObj(std::unique_ptr<CMap> 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; }
};
24 changes: 9 additions & 15 deletions callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void callback::mainmenu(int Param)
{
ENDGAME = 1,
STARTEDITOR,
LOADMAP,
OPTIONS
};

Expand All @@ -141,10 +142,11 @@ void callback::mainmenu(int Param)
case INITIALIZING_CALL:
MainMenu = global::s2->RegisterMenu(std::make_unique<CMenu>(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, 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, OPTIONS, 50, 370, 200, 20, BUTTON_GREEN2, "Options");
break;

Expand All @@ -157,14 +159,9 @@ void callback::mainmenu(int Param)
global::s2->Running = false;
break;

case STARTEDITOR:
assert(MainMenu);
PleaseWait(INITIALIZING_CALL);
global::s2->setMapObj(std::make_unique<CMap>(""));
MainMenu->setWaste();
MainMenu = nullptr;
PleaseWait(WINDOW_QUIT_MESSAGE);
break;
case STARTEDITOR: global::s2->enterEditor(""); break;

case LOADMAP: EditorLoadMenu(INITIALIZING_CALL); break;

case OPTIONS:
assert(MainMenu);
Expand Down Expand Up @@ -749,7 +746,6 @@ void callback::EditorMainMenu(int Param)
void callback::EditorLoadMenu(int Param)
{
static CWindow* WNDLoad = nullptr;
static CMap* MapObj = nullptr;
static std::string curFilename;

enum
Expand All @@ -766,8 +762,6 @@ void callback::EditorLoadMenu(int Param)
break;
WNDLoad = global::s2->RegisterWindow(std::make_unique<CWindow>(
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))
Expand Down Expand Up @@ -807,15 +801,15 @@ void callback::EditorLoadMenu(int Param)
EditorAnimalMenu(MAP_QUIT);
EditorPlayerMenu(MAP_QUIT);

MapObj->destructMap();
bfs::path filepath = global::userMapsPath / curFilename;
if(!filepath.has_extension())
filepath.replace_extension("SWD");
if(!bfs::exists(filepath))
filepath.replace_extension("WLD");
if(!bfs::exists(filepath))
filepath.replace_extension("SWD");
MapObj->constructMap(filepath);

global::s2->enterEditor(filepath);

// we need to check which of these windows was active before
/*
Expand Down