tweak hide-priority: make toggle state persist across designation menu uses

To reproduce:
1. Enter the `d`esignation menu
2. Press `-+` to change priorities
3. Create a designation
4. Press `Alt-p` to hide priorities
5. Exit and re-enter the designation menu (`Esc`, `d`)

Previously, priorities would be visible again after step 5. With this change, they are not visible until you press `Alt-p` again.

Fixes #1068. Note that this is a relatively unobtrusive fix: selecting a priority with `+-` will still result in priorities being shown again. This is native DF behavior that I am reluctant to override because users of designation priorities likely want to see them.
develop
lethosor 2021-04-05 21:58:51 -04:00
parent 9d723dc256
commit 761cf19e99
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 20 additions and 0 deletions

@ -37,6 +37,9 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- `buildingplan`: fixed an issue where planned constructions designated with DF's sizing keys (``umkh``) would sometimes be larger than requested - `buildingplan`: fixed an issue where planned constructions designated with DF's sizing keys (``umkh``) would sometimes be larger than requested
- `command-prompt`: fixed issues where overlays created by running certain commands (e.g. `gui/liquids`, `gui/teleport`) would not update the parent screen correctly - `command-prompt`: fixed issues where overlays created by running certain commands (e.g. `gui/liquids`, `gui/teleport`) would not update the parent screen correctly
## Misc Improvements
- `tweak` hide-priority: changed so that priorities stay hidden (or visible) when exiting and re-entering the designations menu
## Lua ## Lua
- ``gui.Painter``: fixed error when calling ``viewport()`` method - ``gui.Painter``: fixed error when calling ``viewport()`` method
- `xlsxreader`: Added Lua class wrappers for the xlsxreader plugin API - `xlsxreader`: Added Lua class wrappers for the xlsxreader plugin API

@ -7,6 +7,11 @@ using df::global::ui_sidebar_menus;
struct hide_priority_hook : df::viewscreen_dwarfmodest { struct hide_priority_hook : df::viewscreen_dwarfmodest {
typedef df::viewscreen_dwarfmodest interpose_base; typedef df::viewscreen_dwarfmodest interpose_base;
static bool was_valid_mode;
static bool toggled_manually;
static bool last_show_priorities_setting;
inline bool valid_mode () inline bool valid_mode ()
{ {
switch (ui->main.mode) switch (ui->main.mode)
@ -35,6 +40,9 @@ struct hide_priority_hook : df::viewscreen_dwarfmodest {
} }
DEFINE_VMETHOD_INTERPOSE(void, render, ()) DEFINE_VMETHOD_INTERPOSE(void, render, ())
{ {
if (!was_valid_mode && valid_mode() && toggled_manually) {
ui_sidebar_menus->designation.priority_set = last_show_priorities_setting;
}
INTERPOSE_NEXT(render)(); INTERPOSE_NEXT(render)();
if (valid_mode()) if (valid_mode())
{ {
@ -47,15 +55,24 @@ struct hide_priority_hook : df::viewscreen_dwarfmodest {
COLOR_WHITE, COLOR_LIGHTRED); COLOR_WHITE, COLOR_LIGHTRED);
} }
} }
was_valid_mode = valid_mode();
} }
DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set<df::interface_key> *input)) DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set<df::interface_key> *input))
{ {
if (valid_mode() && input->count(df::interface_key::CUSTOM_ALT_P)) if (valid_mode() && input->count(df::interface_key::CUSTOM_ALT_P))
{
ui_sidebar_menus->designation.priority_set = !ui_sidebar_menus->designation.priority_set; ui_sidebar_menus->designation.priority_set = !ui_sidebar_menus->designation.priority_set;
toggled_manually = true;
last_show_priorities_setting = ui_sidebar_menus->designation.priority_set;
}
else else
INTERPOSE_NEXT(feed)(input); INTERPOSE_NEXT(feed)(input);
} }
}; };
bool hide_priority_hook::was_valid_mode = false;
bool hide_priority_hook::toggled_manually = false;
bool hide_priority_hook::last_show_priorities_setting = false;
IMPLEMENT_VMETHOD_INTERPOSE(hide_priority_hook, feed); IMPLEMENT_VMETHOD_INTERPOSE(hide_priority_hook, feed);
IMPLEMENT_VMETHOD_INTERPOSE(hide_priority_hook, render); IMPLEMENT_VMETHOD_INTERPOSE(hide_priority_hook, render);