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
develop
Pauli 2018-06-20 20:08:35 +03:00
parent 2c106fa7a5
commit 9b6781f0f2
4 changed files with 56 additions and 1 deletions

@ -70,6 +70,11 @@ namespace DFHack
class df_window; class df_window;
} }
namespace Screen
{
struct Hide;
}
enum state_change_event enum state_change_event
{ {
SC_UNKNOWN = -1, SC_UNKNOWN = -1,
@ -273,6 +278,7 @@ namespace DFHack
void *last_world_data_ptr; void *last_world_data_ptr;
// for state change tracking // for state change tracking
void *last_local_map_ptr; void *last_local_map_ptr;
friend struct Screen::Hide;
df::viewscreen *top_viewscreen; df::viewscreen *top_viewscreen;
bool last_pause_state; bool last_pause_state;
// Very important! // Very important!

@ -301,6 +301,15 @@ namespace DFHack
GUI_HOOK_DECLARE(set_tile, bool, (const Pen &pen, int x, int y, bool map)); 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 { class DFHACK_EXPORT dfhack_viewscreen : public df::viewscreen {
@ -374,4 +383,5 @@ namespace DFHack
virtual df::building *getSelectedBuilding(); virtual df::building *getSelectedBuilding();
virtual df::plant *getSelectedPlant(); virtual df::plant *getSelectedPlant();
}; };
} }

@ -371,6 +371,42 @@ bool Screen::hasActiveScreens(Plugin *plugin)
return false; 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 #ifdef _LINUX
class DFHACK_EXPORT renderer { class DFHACK_EXPORT renderer {
unsigned char *screen; unsigned char *screen;

@ -200,7 +200,10 @@ void viewscreen_commandpromptst::submit()
return; return;
submitted = true; submitted = true;
prompt_ostream out(this); prompt_ostream out(this);
{
Screen::Hide hide_guard(this);
Core::getInstance().runCommand(out, get_entry()); Core::getInstance().runCommand(out, get_entry());
}
if(out.empty() && responses.empty()) if(out.empty() && responses.empty())
Screen::dismiss(this); Screen::dismiss(this);
else else