#include "SDL2/SDL_keycode.h" #include "editor_scenes.hpp" #include "../../sdlpp/sdlpp.hpp" #include "../../sdlpp/sdlpp_mouse.hpp" #include "../global_vars.hpp" #include "../objectids.hpp" #include "../editor_visitor.hpp" #include "../filesystem.hpp" bool __update_scenes_load_dialog = false; bool __quit_scenes_load_dialog = false; bool __started_load_dialog = false; uint64_t __cur_button_index_load_dialog = -1; uint64_t __cur_button_index_load_dialog_down = -1; std::vector> __buttons_load_dialog{}; std::shared_ptr __mouse_load_dialog{}; std::function __load_dialog_finalizer; std::string __selected_level_load_dialog = ""; void __quitLoadDialog() { __quit_scenes_load_dialog = true; } void __updateSelectedButton_LoadDialog(uint64_t new_index) { if (new_index != __cur_button_index_load_dialog && new_index != (uint64_t)-1) { __buttons_load_dialog[new_index]->setHighlight(); if (__cur_button_index_load_dialog != (uint64_t)-1) { __buttons_load_dialog[__cur_button_index_load_dialog] ->unsetHighlight(); } __cur_button_index_load_dialog = new_index; } } void __quitCallback_LoadDialog(void * /*UNUSED*/, Button *btn) { __selected_level_load_dialog = btn->getText(); __quitLoadDialog(); } void __moveButtons(double movement) { for (auto &button : __buttons_load_dialog) { button->setPos(button->getPos() + SDLPP::Vec2D(0, movement)); } __update_scenes_load_dialog = true; } void __selectUpperButton() { if (__cur_button_index_load_dialog > 0) { __updateSelectedButton_LoadDialog(__cur_button_index_load_dialog - 1); if (__buttons_load_dialog[__cur_button_index_load_dialog] ->getPos() .getY() < 0.49) { __moveButtons(0.25); } } } void __selectLowerButton() { if (__cur_button_index_load_dialog < __buttons_load_dialog.size() - 1) { __updateSelectedButton_LoadDialog(__cur_button_index_load_dialog + 1); auto pos = __buttons_load_dialog[__cur_button_index_load_dialog]->getPos(); if (__buttons_load_dialog[__cur_button_index_load_dialog] ->getPos() .getY() > 0.99) { __moveButtons(-0.25); } } } void __handleKeyUp_LoadDialog(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) { switch (key) { case SDLK_ESCAPE: __selected_level_load_dialog = ""; __quitLoadDialog(); break; case SDLK_RETURN: __buttons_load_dialog[__cur_button_index_load_dialog] ->performFunction(); break; case SDLK_UP: case SDLK_w: __selectUpperButton(); break; case SDLK_DOWN: case SDLK_s: __selectLowerButton(); break; default: break; } } void addLevelButton(const std::string &path, const std::string &file, double &start_height, const int initial_path_len, std::shared_ptr &renderer, ButtonConfig &button_theme) { if (FSLib::isDirectory(path + FSLib::dir_divisor + file)) { for (const auto &file_rec : FSLib::Directory(path + FSLib::dir_divisor + file)) { addLevelButton(path + FSLib::dir_divisor + file, file_rec, start_height, initial_path_len, renderer, button_theme); } } else { __buttons_load_dialog.emplace_back(std::make_shared