From ef17e4619a0a5600dbc4acb2342c3bcc90f62ed2 Mon Sep 17 00:00:00 2001 From: Llennpie <44985633+Llennpie@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:13:12 -0400 Subject: [PATCH] Prevent Mario from getting stuck outside of menu --- src/saturn/imgui/saturn_imgui.cpp | 12 ++++++----- src/saturn/imgui/saturn_imgui.h | 3 ++- src/saturn/saturn.cpp | 34 +++++++++++++++++-------------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/saturn/imgui/saturn_imgui.cpp b/src/saturn/imgui/saturn_imgui.cpp index 1e095007..f1b60284 100644 --- a/src/saturn/imgui/saturn_imgui.cpp +++ b/src/saturn/imgui/saturn_imgui.cpp @@ -238,12 +238,13 @@ void saturn_imgui_update() { if (ImGui::BeginMenu("Menu")) { windowCcEditor = false; - if (ImGui::MenuItem(ICON_FK_WINDOW_MAXIMIZE " Show UI", translate_bind_to_name(configKeyShowMenu[0]), showMenu)) showMenu = !showMenu; + if (ImGui::MenuItem(ICON_FK_WINDOW_MAXIMIZE " Show UI", translate_bind_to_name(configKeyShowMenu[0]), showMenu)) { + showMenu = !showMenu; + if (!showMenu) accept_text_input = true; + } if (ImGui::MenuItem(ICON_FK_WINDOW_MINIMIZE " Show Status Bars", NULL, showStatusBars)) showStatusBars = !showStatusBars; ImGui::Separator(); - if (ImGui::MenuItem("Stats", NULL, windowStats == true)) { - windowStats = !windowStats; - } + if (ImGui::MenuItem("Stats", NULL, windowStats == true)) windowStats = !windowStats; if (ImGui::MenuItem(ICON_FK_COG " Settings", NULL, windowSettings == true)) { windowSettings = !windowSettings; k_popout_open = false; @@ -431,7 +432,8 @@ uint32_t startFrame = 0; uint32_t endFrame = 60; int endFrameText = 60; -void saturn_keyframe_popout(float* edit_value, string value_name, string id) { +template +void saturn_keyframe_popout(const T &edit_value, string value_name, string id) { string buttonLabel = ICON_FK_LINK "###kb_" + id; string windowLabel = "Timeline###kw_" + id; diff --git a/src/saturn/imgui/saturn_imgui.h b/src/saturn/imgui/saturn_imgui.h index ce2cd0ce..a766a84f 100644 --- a/src/saturn/imgui/saturn_imgui.h +++ b/src/saturn/imgui/saturn_imgui.h @@ -11,7 +11,8 @@ extern void imgui_update_theme(); extern void imgui_bundled_tooltip(const char*); extern void imgui_bundled_help_marker(const char*); extern void imgui_bundled_space(float, const char*, const char*); -extern void saturn_keyframe_popout(float*, std::string, std::string); +template +extern void saturn_keyframe_popout(const T &edit_value, std::string, std::string); extern bool showMenu; extern int currentMenu; diff --git a/src/saturn/saturn.cpp b/src/saturn/saturn.cpp index ad0178f1..9c908983 100644 --- a/src/saturn/saturn.cpp +++ b/src/saturn/saturn.cpp @@ -143,31 +143,35 @@ void saturn_update() { // Keybinds - if (accept_text_input && mario_exists) { - if (gPlayer1Controller->buttonPressed & U_JPAD) camera_frozen = !camera_frozen; - if (gPlayer1Controller->buttonPressed & D_JPAD) showMenu = !showMenu; - if (gPlayer1Controller->buttonPressed & L_JPAD) { - if (!is_anim_playing) { - anim_play_button(); - } else { - is_anim_paused = !is_anim_paused; - } + if (mario_exists) { + if (gPlayer1Controller->buttonPressed & D_JPAD) { + showMenu = !showMenu; + if (!showMenu) accept_text_input = true; } - if (gPlayer1Controller->buttonPressed & R_JPAD) { - is_anim_looped = !is_anim_looped; - } - if (keyResetter == 6) { - if (SDL_GetKeyboardState(NULL)[SDL_SCANCODE_F2] & accept_text_input) { + if (SDL_GetKeyboardState(NULL)[SDL_SCANCODE_F2]) { if (gMarioState->action == ACT_IDLE) set_mario_action(gMarioState, ACT_DEBUG_FREE_MOVE, 0); else set_mario_action(gMarioState, ACT_IDLE, 0); keyResetter = 0; } - if (SDL_GetKeyboardState(NULL)[SDL_SCANCODE_F3] & accept_text_input) { + if (SDL_GetKeyboardState(NULL)[SDL_SCANCODE_F3]) { saturn_play_keyframe(active_key_value); keyResetter = 0; } } + if (accept_text_input) { + if (gPlayer1Controller->buttonPressed & U_JPAD) camera_frozen = !camera_frozen; + if (gPlayer1Controller->buttonPressed & L_JPAD) { + if (!is_anim_playing) { + anim_play_button(); + } else { + is_anim_paused = !is_anim_paused; + } + } + if (gPlayer1Controller->buttonPressed & R_JPAD) { + is_anim_looped = !is_anim_looped; + } + } } if (keyResetter < 6)