2015-06-26 21:18:08 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-06-27 07:54:31 -06:00
|
|
|
static void recolor(unsigned x, unsigned y, std::string str,
|
|
|
|
UIColor old_color, UIColor new_color)
|
2015-06-26 21:18:08 -06:00
|
|
|
{
|
|
|
|
static Screen::Pen tile;
|
|
|
|
for (unsigned i = 0; i < str.size(); i++)
|
|
|
|
{
|
|
|
|
tile = Screen::readTile(x + i, y);
|
2015-06-27 07:54:31 -06:00
|
|
|
if (!tile.valid() || tile.ch != str[i] || tile.fg != old_color)
|
2015-06-26 21:18:08 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < str.size(); i++)
|
|
|
|
{
|
|
|
|
tile = Screen::readTile(x + i, y);
|
2015-06-27 07:54:31 -06:00
|
|
|
tile.fg = new_color;
|
2015-06-26 21:18:08 -06:00
|
|
|
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++)
|
|
|
|
{
|
2015-06-27 07:54:31 -06:00
|
|
|
recolor(start_x, y, "Cook", COLOR_BLUE, COLOR_GREEN);
|
|
|
|
recolor(start_x + 5, y, "Brew", COLOR_BLUE, COLOR_GREEN);
|
2015-06-26 21:18:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(kitchen_prefs_color_hook, render);
|