From 6657fb59e55908ca9cf74f2670df5c3188939906 Mon Sep 17 00:00:00 2001 From: Robob27 Date: Fri, 3 Feb 2023 00:24:13 -0500 Subject: [PATCH] Fix pausing and warnings --- library/modules/Gui.cpp | 4 ++++ plugins/confirm.cpp | 23 ++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index d3615f17d..538331450 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -172,6 +172,8 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode) case df::enums::info_interface_mode_type::JUSTICE: newFocusString += "/" + enum_item_key(game->main_interface.info.justice.current_mode); break; + default: + break; } focusStrings.push_back(newFocusString); @@ -282,6 +284,8 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode) case df::enums::main_bottom_mode_type::BUILDING_PICK_MATERIALS: newFocusString += "/Building/PickMaterials"; break; + default: + break; } focusStrings.push_back(newFocusString); diff --git a/plugins/confirm.cpp b/plugins/confirm.cpp index 419df5443..a55d567b8 100644 --- a/plugins/confirm.cpp +++ b/plugins/confirm.cpp @@ -73,6 +73,7 @@ public: enum cstate { INACTIVE, ACTIVE, SELECTED }; virtual string get_id() = 0; virtual string get_focus_string() = 0; + virtual bool match_prefix() = 0; virtual bool set_state(cstate) = 0; static bool set_state(string id, cstate state) @@ -275,7 +276,6 @@ class confirmation : public confirmation_base { public: typedef T screen_type; screen_type *screen; - bool tryUnpauseOnRender; bool set_state (cstate s) override { @@ -308,12 +308,7 @@ public: conf_wrapper *wrapper = confirmations[this->get_id()]; if(wrapper->is_paused()) - { - if ((input->count(df::interface_key::LEAVESCREEN) || mouseExit)) - tryUnpauseOnRender = true; - return false; - } else if (state == INACTIVE) { if(mouseExit) { @@ -378,15 +373,10 @@ public: return state == ACTIVE; } void render() { - if(tryUnpauseOnRender) { - tryUnpauseOnRender = false; - conf_wrapper *wrapper = confirmations[this->get_id()]; - std::string concernedFocus = this->get_focus_string(); - bool prefixMatch = concernedFocus.find("*") != std::string::npos; - - if(!Gui::matchFocusString(this->get_focus_string(), prefixMatch)) - wrapper->set_paused(false); - } + conf_wrapper *wrapper = confirmations[this->get_id()]; + std::string concernedFocus = this->get_focus_string(); + if(!Gui::matchFocusString(this->get_focus_string(), this->match_prefix())) + wrapper->set_paused(false); static vector lines; static const std::string pause_message = "Pause confirmations until you exit this screen"; @@ -484,6 +474,7 @@ public: } string get_id() override = 0; string get_focus_string() override = 0; + bool match_prefix() override = 0; #define CONF_LUA_START using namespace conf_lua; Lua::StackUnwinder unwind(l_state); push(screen); push(get_id()); bool intercept_key (df::interface_key key) { @@ -574,6 +565,7 @@ static int conf_register_##cls = conf_register(&cls##_instance, {\ class confirmation_##cls : public confirmation { \ virtual string get_id() { static string id = char_replace(#cls, '_', '-'); return id; } \ virtual string get_focus_string() { return focusString; } \ + virtual bool match_prefix() { return focusString[strlen(focusString) - 1] == '*'; } \ }; \ IMPLEMENT_CONFIRMATION_HOOKS(confirmation_##cls, 0); @@ -583,6 +575,7 @@ static int conf_register_##cls = conf_register(&cls##_instance, {\ are obtained by replacing '_' with '-' in the first argument to DEFINE_CONFIRMATION TODO: document focus string stuff and how * does prefix matching + or just add a 4th param? that's probably the move */ DEFINE_CONFIRMATION(trade_cancel, viewscreen_dwarfmodest, "dwarfmode/Trade");