From 2c734233eb8440d90dce53423601e381daf29d55 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 27 Jun 2015 11:02:26 -0400 Subject: [PATCH] New tweak: kitchen-keys Fixes an issue where HOTKEY_KITCHEN_* bindings aren't used by DF: http://www.bay12games.com/dwarves/mantisbt/view.php?id=614 See #526 --- NEWS | 1 + Readme.rst | 1 + dfhack.init-example | 1 + plugins/tweak/tweak.cpp | 12 ++++- plugins/tweak/tweaks/kitchen-keys.h | 68 +++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 plugins/tweak/tweaks/kitchen-keys.h diff --git a/NEWS b/NEWS index ec36df918..d44d456aa 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ DFHack Future item-descriptions: holds a default description for every item type and subtype warn-starving: check for starving, thirsty, or very drowsy units and pause with warning if any are found New tweaks + kitchen-keys: Fixes DF kitchen meal keybindings kitchen-prefs-color: Changes color of enabled items to green in kitchen preferences kitchen-prefs-empty: Fixes a layout issue with empty kitchen tabs Fixes diff --git a/Readme.rst b/Readme.rst index b32663d37..ca886907b 100644 --- a/Readme.rst +++ b/Readme.rst @@ -1313,6 +1313,7 @@ Subcommands that persist until disabled or DF quits: :fps-min: Fixes the in-game minimum FPS setting :import-priority-category: Allows changing the priority of all goods in a category when discussing an import agreement with the liaison +:kitchen-keys: Fixes DF kitchen meal keybindings (bug 614) :kitchen-prefs-color: Changes color of enabled items to green in kitchen preferences :kitchen-prefs-empty: Fixes a layout issue with empty kitchen tabs (bug 9000) :manager-quantity: Removes the limit of 30 jobs per manager order diff --git a/dfhack.init-example b/dfhack.init-example index c6e8ba309..daed81041 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -181,6 +181,7 @@ tweak import-priority-category # Misc. UI tweaks tweak civ-view-agreement tweak fps-min +tweak kitchen-keys tweak kitchen-prefs-empty tweak max-wheelbarrow tweak shift-8-scroll diff --git a/plugins/tweak/tweak.cpp b/plugins/tweak/tweak.cpp index 10b36b178..fa2810d5d 100644 --- a/plugins/tweak/tweak.cpp +++ b/plugins/tweak/tweak.cpp @@ -38,7 +38,9 @@ #include "df/viewscreen_layer_unit_actionst.h" #include "df/squad_order_trainst.h" #include "df/ui_build_selector.h" +#include "df/ui_sidebar_menus.h" #include "df/building_trapst.h" +#include "df/building_workshopst.h" #include "df/item_actual.h" #include "df/item_crafted.h" #include "df/item_armorst.h" @@ -84,6 +86,7 @@ #include "tweaks/fast-trade.h" #include "tweaks/fps-min.h" #include "tweaks/import-priority-category.h" +#include "tweaks/kitchen-keys.h" #include "tweaks/kitchen-prefs-color.h" #include "tweaks/kitchen-prefs-empty.h" #include "tweaks/manager-quantity.h" @@ -106,10 +109,12 @@ DFHACK_PLUGIN_IS_ENABLED(is_enabled); REQUIRE_GLOBAL(enabler); REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_area_map_width); REQUIRE_GLOBAL(ui_build_selector); REQUIRE_GLOBAL(ui_building_item_cursor); REQUIRE_GLOBAL(ui_menu_width); -REQUIRE_GLOBAL(ui_area_map_width); +REQUIRE_GLOBAL(ui_sidebar_menus); +REQUIRE_GLOBAL(ui_workshop_in_add); REQUIRE_GLOBAL(world); using namespace DFHack::Gui; @@ -188,6 +193,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector (world->selected_building); + if (!ws) + return false; + if (ws->type != workshop_type::Kitchen) + return false; + return true; + } + + DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set *input)) + { + if (kitchen_in_add()) + { + for (int i = 0; i < 4; i++) + { + if (input->count(kitchen_bindings[i])) + { + ui_sidebar_menus->workshop_job.cursor = i; + input->clear(); + input->insert(df::interface_key::SELECT); + } + } + } + INTERPOSE_NEXT(feed)(input); + } + + DEFINE_VMETHOD_INTERPOSE(void, render, ()) + { + INTERPOSE_NEXT(render)(); + if (kitchen_in_add()) + for (int i = 0; i < 3; i++) + draw_binding(i, kitchen_bindings[i]); + } +}; + +IMPLEMENT_VMETHOD_INTERPOSE(kitchen_keys_hook, feed); +IMPLEMENT_VMETHOD_INTERPOSE(kitchen_keys_hook, render);