New tweak: kitchen-prefs-color
Disabled in default dfhack.init to avoid confusiondevelop
parent
8d21dd0a23
commit
4246dbd02a
@ -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);
|
Loading…
Reference in New Issue