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
develop
lethosor 2015-06-27 11:02:26 -04:00
parent 3795edb673
commit 2c734233eb
5 changed files with 82 additions and 1 deletions

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

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

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

@ -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 <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-keys [disable]\n"
" Fixes DF kitchen meal keybindings (bug 614)\n"
" tweak kitchen-prefs-color [disable]\n"
" Changes color of enabled items to green in kitchen preferences\n"
" tweak kitchen-prefs-empty [disable]\n"
@ -243,6 +250,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-keys", kitchen_keys_hook, feed);
TWEAK_HOOK("kitchen-keys", kitchen_keys_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,68 @@
using namespace DFHack;
using namespace df::enums;
using df::global::ui_sidebar_menus;
using df::global::ui_workshop_in_add;
static df::interface_key kitchen_bindings[] = {
df::interface_key::HOTKEY_KITCHEN_COOK_2,
df::interface_key::HOTKEY_KITCHEN_COOK_3,
df::interface_key::HOTKEY_KITCHEN_COOK_4,
// DF uses CUSTOM_R for this reaction in the raws, so this key is recognized
// by this tweak but not displayed
df::interface_key::HOTKEY_KITCHEN_RENDER_FAT
};
struct kitchen_keys_hook : df::viewscreen_dwarfmodest {
typedef df::viewscreen_dwarfmodest interpose_base;
void draw_binding (int row, df::interface_key key)
{
std::string label = Screen::getKeyDisplay(key);
int x = Gui::getDwarfmodeViewDims().menu_x2 - 2 - label.size();
int y = row + 4;
OutputString(COLOR_GREY, x, y, "(");
OutputString(COLOR_LIGHTRED, x, y, label);
OutputString(COLOR_GREY, x, y, ")");
}
bool kitchen_in_add()
{
if (!*ui_workshop_in_add)
return false;
df::building_workshopst *ws = virtual_cast<df::building_workshopst>(world->selected_building);
if (!ws)
return false;
if (ws->type != workshop_type::Kitchen)
return false;
return true;
}
DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set<df::interface_key> *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);