New tweak: kitchen-prefs-color

Disabled in default dfhack.init to avoid confusion
develop
lethosor 2015-06-26 23:18:08 -04:00
parent 8d21dd0a23
commit 4246dbd02a
4 changed files with 78 additions and 0 deletions

@ -16,6 +16,7 @@ DFHack Future
item-descriptions: holds a default description for every item type and subtype 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 warn-starving: check for starving, thirsty, or very drowsy units and pause with warning if any are found
New tweaks New tweaks
kitchen-prefs-color: Changes color of enabled items to green in kitchen preferences
kitchen-prefs-empty: Fixes a layout issue with empty kitchen tabs kitchen-prefs-empty: Fixes a layout issue with empty kitchen tabs
Fixes Fixes
Plugins with vmethod hooks can now be reloaded on OS X Plugins with vmethod hooks can now be reloaded on OS X

@ -1313,6 +1313,7 @@ Subcommands that persist until disabled or DF quits:
:fps-min: Fixes the in-game minimum FPS setting :fps-min: Fixes the in-game minimum FPS setting
:import-priority-category: Allows changing the priority of all goods in a :import-priority-category: Allows changing the priority of all goods in a
category when discussing an import agreement with the liaison category when discussing an import agreement with the liaison
: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) :kitchen-prefs-empty: Fixes a layout issue with empty kitchen tabs (bug 9000)
:manager-quantity: Removes the limit of 30 jobs per manager order :manager-quantity: Removes the limit of 30 jobs per manager order
:max-wheelbarrow: Allows assigning more than 3 wheelbarrows to a stockpile :max-wheelbarrow: Allows assigning more than 3 wheelbarrows to a stockpile

@ -84,6 +84,7 @@
#include "tweaks/fast-trade.h" #include "tweaks/fast-trade.h"
#include "tweaks/fps-min.h" #include "tweaks/fps-min.h"
#include "tweaks/import-priority-category.h" #include "tweaks/import-priority-category.h"
#include "tweaks/kitchen-prefs-color.h"
#include "tweaks/kitchen-prefs-empty.h" #include "tweaks/kitchen-prefs-empty.h"
#include "tweaks/manager-quantity.h" #include "tweaks/manager-quantity.h"
#include "tweaks/max-wheelbarrow.h" #include "tweaks/max-wheelbarrow.h"
@ -103,6 +104,7 @@ using namespace df::enums;
DFHACK_PLUGIN("tweak"); DFHACK_PLUGIN("tweak");
DFHACK_PLUGIN_IS_ENABLED(is_enabled); DFHACK_PLUGIN_IS_ENABLED(is_enabled);
REQUIRE_GLOBAL(enabler);
REQUIRE_GLOBAL(ui); REQUIRE_GLOBAL(ui);
REQUIRE_GLOBAL(ui_build_selector); REQUIRE_GLOBAL(ui_build_selector);
REQUIRE_GLOBAL(ui_building_item_cursor); REQUIRE_GLOBAL(ui_building_item_cursor);
@ -186,6 +188,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
" tweak import-priority-category [disable]\n" " tweak import-priority-category [disable]\n"
" When meeting with a liaison, makes Shift+Left/Right arrow adjust\n" " When meeting with a liaison, makes Shift+Left/Right arrow adjust\n"
" the priority of an entire category of imports.\n" " the priority of an entire category of imports.\n"
" tweak kitchen-prefs-color [disable]\n"
" Changes color of enabled items to green in kitchen preferences\n"
" tweak kitchen-prefs-empty [disable]\n" " tweak kitchen-prefs-empty [disable]\n"
" Fixes a layout issue with empty kitchen tabs (bug 9000)\n" " Fixes a layout issue with empty kitchen tabs (bug 9000)\n"
" tweak manager-quantity [disable]\n" " tweak manager-quantity [disable]\n"
@ -239,6 +243,8 @@ 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, feed);
TWEAK_HOOK("import-priority-category", takerequest_hook, render); TWEAK_HOOK("import-priority-category", takerequest_hook, render);
TWEAK_HOOK("kitchen-prefs-color", kitchen_prefs_color_hook, render);
TWEAK_HOOK("kitchen-prefs-empty", kitchen_prefs_empty_hook, render); TWEAK_HOOK("kitchen-prefs-empty", kitchen_prefs_empty_hook, render);
TWEAK_HOOK("manager-quantity", manager_quantity_hook, feed); TWEAK_HOOK("manager-quantity", manager_quantity_hook, feed);

@ -0,0 +1,70 @@
using namespace DFHack;
using df::global::gps;
struct kitchen_prefs_color_hook : df::viewscreen_kitchenprefst {
typedef df::viewscreen_kitchenprefst interpose_base;
static std::string read_string(unsigned x, unsigned y, size_t length)
{
std::string s;
for ( ; length; x++, length--)
{
auto tile = Screen::readTile(x, y);
if (!tile.valid())
break;
s += tile.ch;
}
return s;
}
static void recolor(unsigned x, unsigned y, std::string str, UIColor color)
{
static Screen::Pen tile;
for (unsigned i = 0; i < str.size(); i++)
{
tile = Screen::readTile(x + i, y);
if (!tile.valid() || tile.ch != str[i])
return;
}
for (unsigned i = 0; i < str.size(); i++)
{
tile = Screen::readTile(x + i, y);
tile.fg = color;
Screen::paintTile(tile, x + i, y);
}
}
DEFINE_VMETHOD_INTERPOSE(void, render, ())
{
INTERPOSE_NEXT(render)();
/* DF uses a slightly complicated algorithm to position the Number and
Permissions columns (i.e. not a constant distance from either margin).
Detecting light blue "Cook" and "Brew" strings should be sufficient,
but reverse-engineering the algorithm could be slightly faster. */
if (!item_type[page].size())
return;
int start_x = 0,
start_y = 6;
for (int x = 0; x < gps->dimx; x++)
{
std::string word = read_string(x, start_y, 4);
if (word == "Cook" || word == "----")
{
start_x = x;
break;
}
}
if (!start_x)
return;
for (int y = start_y; y < gps->dimy; y++)
{
recolor(start_x, y, "Cook", COLOR_GREEN);
recolor(start_x + 5, y, "Brew", COLOR_GREEN);
}
}
};
IMPLEMENT_VMETHOD_INTERPOSE(kitchen_prefs_color_hook, render);