From 761cf19e99a2cb4145cccf54c08263b8424b47ae Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 5 Apr 2021 21:58:51 -0400 Subject: [PATCH] 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. --- docs/changelog.txt | 3 +++ plugins/tweak/tweaks/hide-priority.h | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 70264aff5..57814f17c 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -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 - `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 - ``gui.Painter``: fixed error when calling ``viewport()`` method - `xlsxreader`: Added Lua class wrappers for the xlsxreader plugin API diff --git a/plugins/tweak/tweaks/hide-priority.h b/plugins/tweak/tweaks/hide-priority.h index c9ac78eec..ef84a5831 100644 --- a/plugins/tweak/tweaks/hide-priority.h +++ b/plugins/tweak/tweaks/hide-priority.h @@ -7,6 +7,11 @@ using df::global::ui_sidebar_menus; struct hide_priority_hook : df::viewscreen_dwarfmodest { 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 () { switch (ui->main.mode) @@ -35,6 +40,9 @@ struct hide_priority_hook : df::viewscreen_dwarfmodest { } 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)(); if (valid_mode()) { @@ -47,15 +55,24 @@ struct hide_priority_hook : df::viewscreen_dwarfmodest { COLOR_WHITE, COLOR_LIGHTRED); } } + was_valid_mode = valid_mode(); } DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set *input)) { if (valid_mode() && input->count(df::interface_key::CUSTOM_ALT_P)) + { 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 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, render);