Merge remote-tracking branch 'suokko/spotclean_ui_state_fix_1194' into develop

Moved/adjusted changelog entry
develop
lethosor 2018-07-07 18:08:53 -04:00
commit 037e7e4901
5 changed files with 63 additions and 2 deletions

@ -37,6 +37,12 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
================================================================================
# Future
## Fixes
- `command-prompt`: added support for commands that require a specific screen to be visible, e.g. `spotclean`
## API
- Added ``Screen::Hide`` to temporarily hide screens, like `command-prompt`
================================================================================
# 0.44.11-beta1

@ -73,6 +73,11 @@ namespace DFHack
class df_window;
}
namespace Screen
{
struct Hide;
}
enum state_change_event
{
SC_UNKNOWN = -1,
@ -274,6 +279,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!

@ -306,6 +306,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 {
@ -379,4 +388,5 @@ namespace DFHack
virtual df::building *getSelectedBuilding();
virtual df::plant *getSelectedPlant();
};
}

@ -376,6 +376,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;

@ -200,7 +200,10 @@ void viewscreen_commandpromptst::submit()
return;
submitted = true;
prompt_ostream out(this);
{
Screen::Hide hide_guard(this);
Core::getInstance().runCommand(out, get_entry());
}
if(out.empty() && responses.empty())
Screen::dismiss(this);
else
@ -312,7 +315,7 @@ void viewscreen_commandpromptst::feed(std::set<df::interface_key> *events)
command_result show_prompt(color_ostream &out, std::vector <std::string> & parameters)
{
if (Gui::getCurFocus() == "dfhack/commandprompt")
if (Gui::getCurFocus(true) == "dfhack/commandprompt")
{
Screen::dismiss(Gui::getCurViewscreen(true));
return CR_OK;