From 9b6781f0f284a40b14cf5a6cd4173fa6dd021f68 Mon Sep 17 00:00:00 2001 From: Pauli Date: Wed, 20 Jun 2018 20:08:35 +0300 Subject: [PATCH 1/3] Temporary lower command-prompt when executing the command command-prompt viewscreen may affect command execution if they are looking for UI state. To make commands execute simillary to hotkeys or console commands the viewscreen needs to removed from the top position. Fixes #1194 --- library/include/Core.h | 6 ++++++ library/include/modules/Screen.h | 10 +++++++++ library/modules/Screen.cpp | 36 ++++++++++++++++++++++++++++++++ plugins/command-prompt.cpp | 5 ++++- 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/library/include/Core.h b/library/include/Core.h index fa65645a1..2c55f8b3a 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -70,6 +70,11 @@ namespace DFHack class df_window; } + namespace Screen + { + struct Hide; + } + enum state_change_event { SC_UNKNOWN = -1, @@ -273,6 +278,7 @@ namespace DFHack void *last_world_data_ptr; // for state change tracking void *last_local_map_ptr; + friend struct Screen::Hide; df::viewscreen *top_viewscreen; bool last_pause_state; // Very important! diff --git a/library/include/modules/Screen.h b/library/include/modules/Screen.h index 673533f3e..76a331eb6 100644 --- a/library/include/modules/Screen.h +++ b/library/include/modules/Screen.h @@ -301,6 +301,15 @@ namespace DFHack GUI_HOOK_DECLARE(set_tile, bool, (const Pen &pen, int x, int y, bool map)); } + //! Temporary hide a screen until destructor is called + struct DFHACK_EXPORT Hide { + Hide(df::viewscreen* screen); + ~Hide(); + private: + void extract(df::viewscreen*); + void merge(df::viewscreen*); + df::viewscreen* screen_; + }; } class DFHACK_EXPORT dfhack_viewscreen : public df::viewscreen { @@ -374,4 +383,5 @@ namespace DFHack virtual df::building *getSelectedBuilding(); virtual df::plant *getSelectedPlant(); }; + } diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index 6ac39aa05..ee68a0fe5 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -371,6 +371,42 @@ bool Screen::hasActiveScreens(Plugin *plugin) return false; } +namespace DFHack { namespace Screen { + +Hide::Hide(df::viewscreen* screen) : + screen_{screen} +{ + extract(screen_); +} + +Hide::~Hide() +{ + if (screen_) + merge(screen_); +} + +void Hide::extract(df::viewscreen* a) +{ + df::viewscreen* ap = a->parent; + df::viewscreen* ac = a->child; + + ap->child = ac; + if (ac) ac->parent = ap; + else Core::getInstance().top_viewscreen = ap; +} + +void Hide::merge(df::viewscreen* a) +{ + df::viewscreen* ap = a->parent; + df::viewscreen* ac = a->parent->child; + + ap->child = a; + a->child = ac; + if (ac) ac->parent = a; + else Core::getInstance().top_viewscreen = a; +} +} } + #ifdef _LINUX class DFHACK_EXPORT renderer { unsigned char *screen; diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp index 449da0e80..c53132486 100644 --- a/plugins/command-prompt.cpp +++ b/plugins/command-prompt.cpp @@ -200,7 +200,10 @@ void viewscreen_commandpromptst::submit() return; submitted = true; prompt_ostream out(this); - Core::getInstance().runCommand(out, get_entry()); + { + Screen::Hide hide_guard(this); + Core::getInstance().runCommand(out, get_entry()); + } if(out.empty() && responses.empty()) Screen::dismiss(this); else From 37e3a59b7ca7c3468229d0544cca715f4535c0bd Mon Sep 17 00:00:00 2001 From: Pauli Date: Wed, 20 Jun 2018 21:46:25 +0300 Subject: [PATCH 2/3] Changelog entry for command-prompt screen hiding --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index ccbce41c6..ee84b1bc5 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -49,6 +49,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `remove-stress`: fixed an error when running on soul-less units (e.g. with ``-all``) - `revflood`: stopped revealing tiles adjacent to tiles above open space inappropriately - `stockpiles`: ``loadstock`` sets usable and unusable weapon and armor settings +- `command-prompt`: Allow executing commands that require specific screen to be visible ## Misc Improvements - Added script name to messages produced by ``qerror()`` in Lua scripts From 72029e7de930445e11bc2415921ad5e1bef94eff Mon Sep 17 00:00:00 2001 From: Pauli Date: Wed, 20 Jun 2018 22:16:23 +0300 Subject: [PATCH 3/3] Avoid closing DF if launching command-prompt from prompt --- plugins/command-prompt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp index c53132486..d288f747c 100644 --- a/plugins/command-prompt.cpp +++ b/plugins/command-prompt.cpp @@ -315,7 +315,7 @@ void viewscreen_commandpromptst::feed(std::set *events) command_result show_prompt(color_ostream &out, std::vector & parameters) { - if (Gui::getCurFocus() == "dfhack/commandprompt") + if (Gui::getCurFocus(true) == "dfhack/commandprompt") { Screen::dismiss(Gui::getCurViewscreen(true)); return CR_OK;