Editor: warn if map isn't saved when quitting
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
31f00ed5d0
commit
45ab92c31f
@ -15,6 +15,7 @@
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
#include <array>
|
||||
#include "../filesystem.hpp"
|
||||
#include "shared_scenes.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../sdlpp/SDL2/SDL2_framerate.h"
|
||||
@ -28,7 +29,8 @@
|
||||
#define MAP_WIDTH 24
|
||||
#define MAP_HEIGHT 16
|
||||
|
||||
#define QUIT_FLAG 0x00000001
|
||||
bool quit_editor = false;
|
||||
|
||||
#define UPDATE_FLAG 0x00000002
|
||||
#define MAP_LEFT_ENABLED_FLAG 0x00000004
|
||||
#define MAP_RIGHT_ENABLED_FLAG 0x00000008
|
||||
@ -49,6 +51,7 @@
|
||||
#define OVERWORLD_WIDTH 2
|
||||
|
||||
const std::string levelsDir = "levels";
|
||||
bool map_changed = false;
|
||||
|
||||
struct ToolType {
|
||||
enum Value {
|
||||
@ -148,9 +151,12 @@ void saveMapCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
||||
std::cout << "SAVING" << std::endl;
|
||||
saveMap(levelsDir + FSLib::dir_divisor + level_name_text + ".marmap",
|
||||
global_vars.objects);
|
||||
map_changed = false;
|
||||
game_scenes.pop_back();
|
||||
}
|
||||
void loadMapDialogCallback(const std::string &level_name) {
|
||||
std::cout << "LOADING" << std::endl;
|
||||
map_changed = false;
|
||||
level_name_text = level_name.substr(0, level_name.length() - 7);
|
||||
setFlag(LOAD_MAP_FLAG);
|
||||
setFlag(TEXT_UPDATE_FLAG);
|
||||
@ -531,7 +537,6 @@ void handleKeyUp(SDL_Keycode key, SDLPP::Scene &scene) {
|
||||
switch (key) {
|
||||
case SDLK_ESCAPE:
|
||||
std::cout << "Eskape" << std::endl;
|
||||
// setFlag(QUIT_FLAG);
|
||||
game_scenes.push_back(mainMenuScene);
|
||||
break;
|
||||
case SDLK_a:
|
||||
@ -703,6 +708,7 @@ MapObject &getSelectedObject() {
|
||||
|
||||
void placeTool(SDLPP::Scene &scene) {
|
||||
std::lock_guard<std::mutex> lock(render_mutex);
|
||||
map_changed = true;
|
||||
|
||||
ToolVisitor visitor;
|
||||
visitor.setSourceType(global_vars.current_world_type);
|
||||
@ -806,7 +812,7 @@ void pollEvents(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
while (SDLPP::getSDLEvent(event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
setFlag(QUIT_FLAG);
|
||||
quit_editor = true;
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
if (!getFlag(TEXT_INPUT_FLAG) && !controlOrCommandPressed()) {
|
||||
@ -824,15 +830,18 @@ void pollEvents(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
!level_name_text.empty()) {
|
||||
level_name_text.pop_back();
|
||||
setFlag(TEXT_UPDATE_FLAG);
|
||||
} else if (event.key.keysym.sym == SDLK_c && controlOrCommandPressed()) {
|
||||
} else if (event.key.keysym.sym == SDLK_c &&
|
||||
controlOrCommandPressed()) {
|
||||
// handle copy
|
||||
SDL_SetClipboardText(level_name_text.c_str());
|
||||
} else if (event.key.keysym.sym == SDLK_v && controlOrCommandPressed()) {
|
||||
} else if (event.key.keysym.sym == SDLK_v &&
|
||||
controlOrCommandPressed()) {
|
||||
// handle paste
|
||||
level_name_text += SDL_GetClipboardText();
|
||||
setFlag(TEXT_UPDATE_FLAG);
|
||||
}
|
||||
} else if (event.key.keysym.sym == SDLK_s && controlOrCommandPressed()) {
|
||||
} else if (event.key.keysym.sym == SDLK_s &&
|
||||
controlOrCommandPressed()) {
|
||||
saveMapCallback(nullptr, nullptr);
|
||||
}
|
||||
break;
|
||||
@ -1059,7 +1068,8 @@ void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
MAP_WIDTH);
|
||||
for (int i = 0; i < global_vars.objects.size(); i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
if(global_vars.objects[i][j].hasCharacter() && global_vars.objects[i][j].getCharacterId() == MARIO_ID) {
|
||||
if (global_vars.objects[i][j].hasCharacter() &&
|
||||
global_vars.objects[i][j].getCharacterId() == MARIO_ID) {
|
||||
global_vars.mario_pos = { i, j };
|
||||
}
|
||||
}
|
||||
@ -1342,8 +1352,21 @@ createEditorMainScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
return scene;
|
||||
}
|
||||
|
||||
void quitEditor(bool actually_quit) {
|
||||
g_quit = actually_quit;
|
||||
}
|
||||
|
||||
void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
g_quit = getFlag(QUIT_FLAG);
|
||||
if (quit_editor) {
|
||||
if (map_changed) {
|
||||
game_scenes.push_back(createYesNoScene(
|
||||
scene->getRendererShared(),
|
||||
"Map hasn't been saved. Actually quit?", quitEditor));
|
||||
quit_editor = false;
|
||||
} else {
|
||||
quitEditor(true);
|
||||
}
|
||||
}
|
||||
for (auto &button : global_vars.buttons) {
|
||||
button->update();
|
||||
}
|
||||
@ -1377,7 +1400,7 @@ SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
ret.additionalRender = editorAdditionalRender;
|
||||
editorScene = ret.scene;
|
||||
|
||||
mainMenuScene = createEditorMainMenuScene(renderer);
|
||||
mainMenuScene = createEditorMainMenuScene(renderer, &quit_editor);
|
||||
// fileChoiceScene = createEditorFileChoiceScene(renderer);
|
||||
return ret;
|
||||
}
|
||||
|
@ -8,14 +8,20 @@
|
||||
bool __update_scenes_main_menu = false;
|
||||
bool __quit_scenes_main_menu = false;
|
||||
bool __started_main_menu = false;
|
||||
bool *__quit_flag = nullptr;
|
||||
uint64_t __cur_button_index_main_menu = -1;
|
||||
uint64_t __cur_button_index_main_menu_down = -1;
|
||||
std::vector<std::shared_ptr<Button>> __buttons_main_menu{};
|
||||
std::shared_ptr<SDLPP::RectangleRender> __mouse_main_menu{};
|
||||
|
||||
void quitMainMenu() {
|
||||
game_scenes.pop_back();
|
||||
if (__quit_flag != nullptr) {
|
||||
*__quit_flag = true;
|
||||
} else {
|
||||
g_quit = true;
|
||||
}
|
||||
}
|
||||
|
||||
void resumeMainMenu() {
|
||||
__quit_scenes_main_menu = true;
|
||||
@ -36,7 +42,8 @@ void loadFinished(const std::string level_name) {
|
||||
|
||||
void showLoadMenu(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
||||
// TODO levels
|
||||
auto loadMenu = createLoadScene(__buttons_main_menu.back()->getRenderer(), "levels", loadFinished);
|
||||
auto loadMenu = createLoadScene(__buttons_main_menu.back()->getRenderer(),
|
||||
"levels", loadFinished);
|
||||
game_scenes.push_back(loadMenu);
|
||||
}
|
||||
|
||||
@ -46,8 +53,7 @@ void __updateSelectedButton_MainMenu(uint64_t new_index) {
|
||||
__buttons_main_menu[new_index]->setHighlight();
|
||||
|
||||
if (__cur_button_index_main_menu != (uint64_t)-1) {
|
||||
__buttons_main_menu[__cur_button_index_main_menu]
|
||||
->unsetHighlight();
|
||||
__buttons_main_menu[__cur_button_index_main_menu]->unsetHighlight();
|
||||
}
|
||||
__cur_button_index_main_menu = new_index;
|
||||
}
|
||||
@ -82,7 +88,8 @@ void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) {
|
||||
}
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
if(__cur_button_index_main_menu >= 0 && __cur_button_index_main_menu < __buttons_main_menu.size()) {
|
||||
if (__cur_button_index_main_menu >= 0 &&
|
||||
__cur_button_index_main_menu < __buttons_main_menu.size()) {
|
||||
__buttons_main_menu[__cur_button_index_main_menu]
|
||||
->performFunction();
|
||||
}
|
||||
@ -129,9 +136,9 @@ createSceneMainMenu(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
SDLPP::OBJ_CENTER);
|
||||
__buttons_main_menu.back()->setPermanent();
|
||||
__buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1);
|
||||
__buttons_main_menu.emplace_back(std::make_shared<Button>(
|
||||
0.2, 0.4, 0.6, 0.1, renderer, "LOAD", default_button_theme,
|
||||
showLoadMenu, nullptr));
|
||||
__buttons_main_menu.emplace_back(
|
||||
std::make_shared<Button>(0.2, 0.4, 0.6, 0.1, renderer, "LOAD",
|
||||
default_button_theme, showLoadMenu, nullptr));
|
||||
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER,
|
||||
SDLPP::OBJ_CENTER);
|
||||
__buttons_main_menu.back()->setPermanent();
|
||||
@ -221,12 +228,14 @@ void pollEventsMainMenu(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
}
|
||||
|
||||
SceneStruct
|
||||
createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
bool *quit_flag) {
|
||||
SceneStruct ret{};
|
||||
ret.scene = createSceneMainMenu(renderer);
|
||||
ret.additionalRender = additionalRenderMainMenu;
|
||||
ret.doInput = pollEventsMainMenu;
|
||||
__update_scenes_main_menu = true;
|
||||
__updateSelectedButton_MainMenu(0);
|
||||
__quit_flag = quit_flag;
|
||||
return ret;
|
||||
}
|
@ -14,7 +14,8 @@ void loadMapDialogCallback(const std::string &level_name);
|
||||
|
||||
SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer);
|
||||
SceneStruct
|
||||
createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer);
|
||||
createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
bool *quit_flag);
|
||||
SceneStruct
|
||||
createEditorFileChoiceScene(std::shared_ptr<SDLPP::Renderer> &renderer);
|
||||
|
||||
|
@ -114,7 +114,7 @@ createSceneYesNoDialog(std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
scene->addObject(button);
|
||||
}
|
||||
auto font_config = std::make_shared<SDLPP::FontConfiguration>(
|
||||
g_text_config->getFont(), "#000000", "#282828", 0.05);
|
||||
g_text_config->getFont(), "#000000", "#FFFFFFAA", 0.10);
|
||||
auto dialog_text = std::make_shared<SDLPP::TextRenderer>(
|
||||
0.1, 0.15, 0.8, 0.3, renderer, text, font_config, SDLPP_TEXT_CENTER);
|
||||
dialog_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
|
Loading…
Reference in New Issue
Block a user