From fe8be909924e9f876a8058961859ab94ed679148 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 25 Jun 2017 16:42:30 -0400 Subject: [PATCH] Add "tweak burrow-name-cancel" to fix bug 1518 http://www.bay12games.com/dwarves/mantisbt/view.php?id=1518 Closes #526 --- dfhack.init-example | 1 + docs/Plugins.rst | 2 ++ plugins/tweak/tweak.cpp | 5 +++ plugins/tweak/tweaks/burrow-name-cancel.h | 44 +++++++++++++++++++++++ plugins/tweak/tweaks/cursor-cross.h | 0 5 files changed, 52 insertions(+) create mode 100644 plugins/tweak/tweaks/burrow-name-cancel.h create mode 100644 plugins/tweak/tweaks/cursor-cross.h diff --git a/dfhack.init-example b/dfhack.init-example index 87462975c..525e823a3 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -198,6 +198,7 @@ tweak embark-profile-name # Misc. UI tweaks tweak block-labors # Prevents labors that can't be used from being toggled +tweak burrow-name-cancel tweak cage-butcher tweak civ-view-agreement tweak eggs-fertile diff --git a/docs/Plugins.rst b/docs/Plugins.rst index a1fd57e85..eec37960a 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -275,6 +275,8 @@ Subcommands that persist until disabled or DF quits: the contents separately from the container. This forcefully skips child reagents. :block-labors: Prevents labors that can't be used from being toggled +:burrow-name-cancel: Implements the "back" option when renaming a burrow, + which currently does nothing (:bug:`1518`) :cage-butcher: Adds an option to butcher units when viewing cages with :kbd:`q` :civ-view-agreement: Fixes overlapping text on the "view agreement" screen :condition-material: Fixes a crash in the work order contition material list (:bug:`9905`). diff --git a/plugins/tweak/tweak.cpp b/plugins/tweak/tweak.cpp index 1336e3b81..bf044dd58 100644 --- a/plugins/tweak/tweak.cpp +++ b/plugins/tweak/tweak.cpp @@ -80,6 +80,7 @@ #include "tweaks/adamantine-cloth-wear.h" #include "tweaks/advmode-contained.h" #include "tweaks/block-labors.h" +#include "tweaks/burrow-name-cancel.h" #include "tweaks/cage-butcher.h" #include "tweaks/civ-agreement-ui.h" #include "tweaks/condition-material.h" @@ -184,6 +185,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector *input)) + { + if (ui->main.mode == df::ui_sidebar_mode::Burrows) + { + bool was_naming = ui->burrows.in_edit_name_mode; + INTERPOSE_NEXT(feed)(input); + df::burrow *burrow = vector_get(ui->burrows.list, ui->burrows.sel_index); + if (!burrow) + return; + + if (ui->burrows.in_edit_name_mode) + { + if (!was_naming) + { + // Just started renaming - make a copy of the old name + old_name = burrow->name; + } + if (input->count(df::interface_key::LEAVESCREEN)) + { + // Cancel and restore the old name + ui->burrows.in_edit_name_mode = false; + burrow->name = old_name; + } + } + } + else + { + INTERPOSE_NEXT(feed)(input); + } + } +}; + +std::string burrow_name_cancel_hook::old_name; + +IMPLEMENT_VMETHOD_INTERPOSE(burrow_name_cancel_hook, feed); diff --git a/plugins/tweak/tweaks/cursor-cross.h b/plugins/tweak/tweaks/cursor-cross.h new file mode 100644 index 000000000..e69de29bb