Compare commits
No commits in common. "ab6dcccbac33bf351ca467b2b8ccb3d6f0562858" and "fa60a0f163b77bc8dc04dfdb9a93927255ad3cf6" have entirely different histories.
ab6dcccbac
...
fa60a0f163
@ -91,7 +91,6 @@ target_sources(editor
|
|||||||
PRIVATE scenes/editor_main.cpp
|
PRIVATE scenes/editor_main.cpp
|
||||||
PRIVATE scenes/editor_main_menu.cpp
|
PRIVATE scenes/editor_main_menu.cpp
|
||||||
PRIVATE scenes/yes_no_scene.cpp
|
PRIVATE scenes/yes_no_scene.cpp
|
||||||
PRIVATE scenes/ok_scene.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(editor PUBLIC EDITOR)
|
target_compile_definitions(editor PUBLIC EDITOR)
|
||||||
|
@ -894,10 +894,8 @@ void pollEvents(std::shared_ptr<SDLPP::Scene> &scene) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_TEXTINPUT:
|
case SDL_TEXTINPUT:
|
||||||
if (getFlag(TEXT_INPUT_FLAG)) {
|
|
||||||
global_test_text_text += event.text.text;
|
global_test_text_text += event.text.text;
|
||||||
setFlag(TEXT_UPDATE_FLAG);
|
setFlag(TEXT_UPDATE_FLAG);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -1032,18 +1030,10 @@ void dialogFinishedTest(bool result) {
|
|||||||
setFlag(TEXT_UPDATE_FLAG);
|
setFlag(TEXT_UPDATE_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
void okDialogFinalizer() {
|
|
||||||
global_test_text_text = "You OK'd";
|
|
||||||
setFlag(TEXT_UPDATE_FLAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testButtonFunc(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
void testButtonFunc(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
||||||
/* game_scenes.push_back(
|
game_scenes.push_back(
|
||||||
createYesNoScene(game_scenes.back().scene->getRendererShared(),
|
createYesNoScene(game_scenes.back().scene->getRendererShared(), "Yeah?",
|
||||||
"Yeah?", dialogFinishedTest));*/
|
dialogFinishedTest));
|
||||||
game_scenes.push_back(createOkScene(
|
|
||||||
game_scenes.back().scene->getRendererShared(),
|
|
||||||
"You cannot choose anything other than OK", okDialogFinalizer));
|
|
||||||
/* setFlag(TEXT_INPUT_FLAG);
|
/* setFlag(TEXT_INPUT_FLAG);
|
||||||
SDL_StartTextInput();*/
|
SDL_StartTextInput();*/
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,5 @@ createEditorFileChoiceScene(std::shared_ptr<SDLPP::Renderer> &renderer);
|
|||||||
SceneStruct createYesNoScene(std::shared_ptr<SDLPP::Renderer> renderer,
|
SceneStruct createYesNoScene(std::shared_ptr<SDLPP::Renderer> renderer,
|
||||||
const std::string &text,
|
const std::string &text,
|
||||||
std::function<void(bool)> finalizer);
|
std::function<void(bool)> finalizer);
|
||||||
SceneStruct createOkScene(std::shared_ptr<SDLPP::Renderer> renderer,
|
|
||||||
const std::string &text,
|
|
||||||
std::function<void()> finalizer);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,175 +0,0 @@
|
|||||||
#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"
|
|
||||||
|
|
||||||
bool __update_scenes_ok_dialog = false;
|
|
||||||
bool __quit_scenes_ok_dialog = false;
|
|
||||||
bool __started_ok_dialog = false;
|
|
||||||
uint64_t __cur_button_index_ok_dialog = -1;
|
|
||||||
uint64_t __cur_button_index_ok_dialog_down = -1;
|
|
||||||
std::vector<std::shared_ptr<Button>> __buttons_ok_dialog{};
|
|
||||||
std::shared_ptr<SDLPP::RectangleRender> __mouse_ok_dialog{};
|
|
||||||
|
|
||||||
std::function<void()> __ok_dialog_finalizer;
|
|
||||||
|
|
||||||
void __quitOkDialog() {
|
|
||||||
__quit_scenes_ok_dialog = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void __quitCallback_OkDialog(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
|
||||||
__quitOkDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
void __handleKeyUp_OkDialog(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) {
|
|
||||||
switch (key) {
|
|
||||||
case SDLK_ESCAPE:
|
|
||||||
case SDLK_RETURN:
|
|
||||||
__quitOkDialog();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<SDLPP::Scene>
|
|
||||||
createSceneOkDialog(std::shared_ptr<SDLPP::Renderer> &renderer,
|
|
||||||
const std::string &text) {
|
|
||||||
auto scene = std::make_shared<SDLPP::Scene>(renderer);
|
|
||||||
auto bg = std::make_shared<SDLPP::RectangleRender>(0, 0, 10, 10, renderer,
|
|
||||||
"#00000088", true);
|
|
||||||
bg->setPermanent();
|
|
||||||
bg->setId(1);
|
|
||||||
scene->addObject(bg);
|
|
||||||
__mouse_ok_dialog =
|
|
||||||
std::make_shared<SDLPP::RectangleRender>(0.01, 0.01, 0, 0, renderer);
|
|
||||||
__mouse_ok_dialog->setMinWidth(1);
|
|
||||||
__mouse_ok_dialog->setMinHeight(1);
|
|
||||||
__mouse_ok_dialog->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
|
||||||
__mouse_ok_dialog->setId(EDITOR_MOUSE_ID);
|
|
||||||
__mouse_ok_dialog->setColiderColor("#00FF00");
|
|
||||||
__mouse_ok_dialog->addCollision(SDLPP::RectColider({ 0, 0 }, { 1, 1 }));
|
|
||||||
scene->addObject(__mouse_ok_dialog);
|
|
||||||
|
|
||||||
ButtonConfig default_button_theme{};
|
|
||||||
default_button_theme.bg_color = "#FFFFFF88";
|
|
||||||
default_button_theme.bg_color_highlight = "#FFFFFFBB";
|
|
||||||
default_button_theme.bg_color_disabled = "#AAAAAA88";
|
|
||||||
default_button_theme.font_color = "#000000";
|
|
||||||
default_button_theme.font_color_highlight = "#000000";
|
|
||||||
default_button_theme.font_color_disabled = "#555555";
|
|
||||||
default_button_theme.font_outline_color = "#FFFFFF88";
|
|
||||||
default_button_theme.font_outline_color_highlight = "#FFFFFFAA";
|
|
||||||
default_button_theme.font_outline_color_disabled = "#787878";
|
|
||||||
default_button_theme.outline = 0.1;
|
|
||||||
// buttons
|
|
||||||
__buttons_ok_dialog.emplace_back(std::make_shared<Button>(
|
|
||||||
0.3, 0.5, 0.4, 0.2, renderer, "OK", default_button_theme,
|
|
||||||
__quitCallback_OkDialog, nullptr));
|
|
||||||
__buttons_ok_dialog.back()->setAlignment(SDLPP::OBJ_CENTER,
|
|
||||||
SDLPP::OBJ_CENTER);
|
|
||||||
__buttons_ok_dialog.back()->setPermanent();
|
|
||||||
__buttons_ok_dialog.back()->setButtonIndex(__buttons_ok_dialog.size() - 1);
|
|
||||||
__buttons_ok_dialog.back()->setHighlight();
|
|
||||||
for (auto &button : __buttons_ok_dialog) {
|
|
||||||
scene->addObject(button);
|
|
||||||
}
|
|
||||||
auto font_config = std::make_shared<SDLPP::FontConfiguration>(
|
|
||||||
g_text_config->getFont(), "#000000", "#282828", 0.05);
|
|
||||||
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);
|
|
||||||
dialog_text->setPermanent();
|
|
||||||
scene->addObject(dialog_text);
|
|
||||||
return scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
void __resetGlobals_OkDialog() {
|
|
||||||
__update_scenes_ok_dialog = false;
|
|
||||||
__quit_scenes_ok_dialog = false;
|
|
||||||
__started_ok_dialog = false;
|
|
||||||
__cur_button_index_ok_dialog = -1;
|
|
||||||
__cur_button_index_ok_dialog_down = -1;
|
|
||||||
__buttons_ok_dialog.clear();
|
|
||||||
__mouse_ok_dialog.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void __additionalRender_OkDialog(std::shared_ptr<SDLPP::Scene> & /*UNUSED*/) {
|
|
||||||
if (__update_scenes_ok_dialog) {
|
|
||||||
for (auto &_scene : game_scenes) {
|
|
||||||
_scene.scene->updateSizeAndPosition();
|
|
||||||
}
|
|
||||||
if (__started_ok_dialog) {
|
|
||||||
__update_scenes_ok_dialog = false;
|
|
||||||
} else {
|
|
||||||
__started_ok_dialog = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (__quit_scenes_ok_dialog) {
|
|
||||||
__ok_dialog_finalizer();
|
|
||||||
game_scenes.pop_back();
|
|
||||||
__resetGlobals_OkDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void __getMousePositionFlags_OkDialog(SDLPP::Scene &scene) {
|
|
||||||
auto mouse = scene.getObjects({ EDITOR_MOUSE_ID })[0];
|
|
||||||
// move mouse colider to mouse position
|
|
||||||
mouse->setPos(SDLPP::Mouse::getMousePositionDouble(
|
|
||||||
scene.getRenderer(), SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER));
|
|
||||||
|
|
||||||
MouseVisitor visitor;
|
|
||||||
scene.visitCollisions(*mouse, visitor);
|
|
||||||
__cur_button_index_ok_dialog = visitor.getCurButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
void __pollEvents_OkDialog(std::shared_ptr<SDLPP::Scene> &scene) {
|
|
||||||
SDL_Event event;
|
|
||||||
while (SDLPP::getSDLEvent(event)) {
|
|
||||||
switch (event.type) {
|
|
||||||
case SDL_QUIT:
|
|
||||||
__quitOkDialog();
|
|
||||||
break;
|
|
||||||
case SDL_KEYUP:
|
|
||||||
__handleKeyUp_OkDialog(event.key.keysym.sym, *scene);
|
|
||||||
break;
|
|
||||||
case SDL_WINDOWEVENT:
|
|
||||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
|
||||||
__update_scenes_ok_dialog = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
__getMousePositionFlags_OkDialog(*scene);
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
if (__cur_button_index_ok_dialog_down ==
|
|
||||||
__cur_button_index_ok_dialog &&
|
|
||||||
__cur_button_index_ok_dialog != (uint64_t)-1) {
|
|
||||||
__buttons_ok_dialog[__cur_button_index_ok_dialog]
|
|
||||||
->performFunction();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
// store current mouse flags in previous mouse flags
|
|
||||||
__cur_button_index_ok_dialog_down = __cur_button_index_ok_dialog;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneStruct createOkScene(std::shared_ptr<SDLPP::Renderer> renderer,
|
|
||||||
const std::string &text,
|
|
||||||
std::function<void()> finalizer) {
|
|
||||||
__ok_dialog_finalizer = finalizer;
|
|
||||||
SceneStruct ret{};
|
|
||||||
ret.scene = createSceneOkDialog(renderer, text);
|
|
||||||
ret.additionalRender = __additionalRender_OkDialog;
|
|
||||||
ret.doInput = __pollEvents_OkDialog;
|
|
||||||
__update_scenes_ok_dialog = true;
|
|
||||||
return ret;
|
|
||||||
}
|
|
@ -50,6 +50,7 @@ void __handleKeyUp_YesNoDialog(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) {
|
|||||||
case SDLK_RETURN:
|
case SDLK_RETURN:
|
||||||
__quitYesNoDialog(__cur_button_index_yesno_dialog == 0);
|
__quitYesNoDialog(__cur_button_index_yesno_dialog == 0);
|
||||||
break;
|
break;
|
||||||
|
// TODO return chooses selected button
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user