New tweak: kitchen-prefs-all

Options to toggle brew/cook for all listed items

Also fixed kitchen lua docs and moved kitchen search option
develop
lethosor 2018-05-17 19:47:56 -04:00
parent d502dce2db
commit 759ba5c420
7 changed files with 84 additions and 5 deletions

@ -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

@ -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,

@ -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

@ -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

@ -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

@ -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 <Plugi
" tweak import-priority-category [disable]\n"
" When meeting with a liaison, makes Shift+Left/Right arrow adjust\n"
" the priority of an entire category of imports.\n"
" tweak kitchen-prefs-all [disable]\n"
" Adds an option to toggle cook/brew for all visible items in\n"
" kitchen preferences\n"
" tweak kitchen-prefs-color [disable]\n"
" Changes color of enabled items to green in kitchen preferences\n"
" tweak kitchen-prefs-empty [disable]\n"
@ -297,6 +301,9 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
TWEAK_HOOK("import-priority-category", takerequest_hook, feed);
TWEAK_HOOK("import-priority-category", takerequest_hook, render);
TWEAK_HOOK("kitchen-prefs-all", kitchen_prefs_all_hook, feed);
TWEAK_HOOK("kitchen-prefs-all", kitchen_prefs_all_hook, render);
TWEAK_HOOK("kitchen-prefs-color", kitchen_prefs_color_hook, render);
TWEAK_HOOK("kitchen-prefs-empty", kitchen_prefs_empty_hook, render);

@ -0,0 +1,69 @@
#include "modules/Kitchen.h"
#include "df/interface_key.h"
#include "df/layer_object_listst.h"
#include "df/viewscreen_kitchenprefst.h"
using namespace DFHack;
struct kitchen_prefs_all_hook : df::viewscreen_kitchenprefst {
typedef df::viewscreen_kitchenprefst interpose_base;
DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set<df::interface_key> *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);