From 759ba5c420f65ae9bd9be72abbe1a476a4b800a6 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 17 May 2018 19:47:56 -0400 Subject: [PATCH] New tweak: kitchen-prefs-all Options to toggle brew/cook for all listed items Also fixed kitchen lua docs and moved kitchen search option --- dfhack.init-example | 1 + docs/Lua API.rst | 8 +-- docs/Plugins.rst | 1 + docs/changelog.txt | 1 + plugins/search.cpp | 2 +- plugins/tweak/tweak.cpp | 7 +++ plugins/tweak/tweaks/kitchen-prefs-all.h | 69 ++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 plugins/tweak/tweaks/kitchen-prefs-all.h diff --git a/dfhack.init-example b/dfhack.init-example index 17a36fb0c..bdf035bd3 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -215,6 +215,7 @@ tweak civ-view-agreement tweak eggs-fertile tweak fps-min tweak hide-priority +tweak kitchen-prefs-all tweak kitchen-prefs-empty tweak max-wheelbarrow tweak shift-8-scroll diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 5c2484475..8190de4c1 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -1741,7 +1741,7 @@ Constructions module Kitchen module -------------- -* ``dfhack.kitchen.findExclusion(type, item_type, item_index, mat_type, mat_index)`` +* ``dfhack.kitchen.findExclusion(type, item_type, item_subtype, mat_type, mat_index)`` Finds a kitchen exclusion in the vectors in ``df.global.ui.kitchen``. Returns -1 if not found. @@ -1749,10 +1749,10 @@ Kitchen module * ``type`` is a ``df.kitchen_exc_type``, i.e. ``df.kitchen_exc_type.Cook`` or ``df.kitchen_exc_type.Brew``. * ``item_type`` is a ``df.item_type`` - * ``item_index``, ``mat_type``, and ``mat_index`` are all numeric + * ``item_subtype``, ``mat_type``, and ``mat_index`` are all numeric -* ``dfhack.kitchen.addExclusion(type, item_type, item_index, mat_type, mat_index)`` -* ``dfhack.kitchen.removeExclusion(type, item_type, item_index, mat_type, mat_index)`` +* ``dfhack.kitchen.addExclusion(type, item_type, item_subtype, mat_type, mat_index)`` +* ``dfhack.kitchen.removeExclusion(type, item_type, item_subtype, mat_type, mat_index)`` Adds or removes a kitchen exclusion, using the same parameters as ``findExclusion``. Both return ``true`` on success and ``false`` on failure, diff --git a/docs/Plugins.rst b/docs/Plugins.rst index 33a2c452a..082dff360 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -311,6 +311,7 @@ Subcommands that persist until disabled or DF quits: :import-priority-category: Allows changing the priority of all goods in a category when discussing an import agreement with the liaison +:kitchen-prefs-all: Adds an option to toggle cook/brew for all visible items in kitchen preferences :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`) :max-wheelbarrow: Allows assigning more than 3 wheelbarrows to a stockpile diff --git a/docs/changelog.txt b/docs/changelog.txt index 55086abfa..927500af8 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -39,6 +39,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## New Tweaks - `tweak` stone-status-all: adds an option to toggle the economic status of all stones +- `tweak` kitchen-prefs-all: adds an option to toggle cook/brew for all visible items in kitchen preferences ## Fixes - `tweak` max-wheelbarrow: fixed conflict with building renaming diff --git a/plugins/search.cpp b/plugins/search.cpp index 58fca7d44..b43daa942 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -2135,7 +2135,7 @@ public: void render() const override { - print_search_option(2, gps->dimy - 2); + print_search_option(40, gps->dimy - 2); } int32_t *get_viewscreen_cursor() override diff --git a/plugins/tweak/tweak.cpp b/plugins/tweak/tweak.cpp index 8d6d61db8..35f0f4705 100644 --- a/plugins/tweak/tweak.cpp +++ b/plugins/tweak/tweak.cpp @@ -94,6 +94,7 @@ #include "tweaks/hide-priority.h" #include "tweaks/hotkey-clear.h" #include "tweaks/import-priority-category.h" +#include "tweaks/kitchen-prefs-all.h" #include "tweaks/kitchen-prefs-color.h" #include "tweaks/kitchen-prefs-empty.h" #include "tweaks/max-wheelbarrow.h" @@ -219,6 +220,9 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector *input)) + { + df::kitchen_pref_flag flag; + df::kitchen_exc_type exc_type; + if (input->count(interface_key::CUSTOM_SHIFT_C)) + { + flag.bits.Cook = true; + exc_type = df::kitchen_exc_type::Cook; + } + else if (input->count(interface_key::CUSTOM_SHIFT_B)) + { + flag.bits.Brew = true; + exc_type = df::kitchen_exc_type::Brew; + } + + if (flag.whole && cursor < forbidden[page].size()) + { + bool was_forbidden = forbidden[page][cursor].whole & flag.whole; + for (size_t i = 0; i < forbidden[page].size(); i++) + { + if (possible[page][i].whole & flag.whole) + { + if (was_forbidden) + { + // unset flag + forbidden[page][i].whole &= ~flag.whole; + Kitchen::removeExclusion(exc_type, + item_type[page][i], item_subtype[page][i], + mat_type[page][i], mat_index[page][i]); + } + else + { + // set flag + forbidden[page][i].whole |= flag.whole; + Kitchen::addExclusion(exc_type, + item_type[page][i], item_subtype[page][i], + mat_type[page][i], mat_index[page][i]); + } + } + } + } + INTERPOSE_NEXT(feed)(input); + } + + DEFINE_VMETHOD_INTERPOSE(void, render, ()) + { + INTERPOSE_NEXT(render)(); + int x = 2, y = gps->dimy - 2; + OutputHotkeyString(x, y, "Cook all", interface_key::CUSTOM_SHIFT_C, + false, 0, COLOR_WHITE, COLOR_LIGHTRED); + x = 20; + OutputHotkeyString(x, y, "Brew all", interface_key::CUSTOM_SHIFT_B, + false, 0, COLOR_WHITE, COLOR_LIGHTRED); + } +}; + +IMPLEMENT_VMETHOD_INTERPOSE(kitchen_prefs_all_hook, render); +IMPLEMENT_VMETHOD_INTERPOSE(kitchen_prefs_all_hook, feed);