detect extended tile properties and communicate them back to lua

develop
Myk Taylor 2023-08-12 15:53:22 -07:00
parent 9cb764b847
commit c37dce7c33
No known key found for this signature in database
3 changed files with 43 additions and 5 deletions

@ -79,6 +79,7 @@ Template for new versions:
- ``dfhack.items.getValue()``: remove ``caravan_buying`` param as per C++ API change - ``dfhack.items.getValue()``: remove ``caravan_buying`` param as per C++ API change
- ``widgets.BannerPanel``: panel with distinctive border for marking DFHack UI elements on otherwise vanilla screens - ``widgets.BannerPanel``: panel with distinctive border for marking DFHack UI elements on otherwise vanilla screens
- ``widgets.Panel``: new functions to override instead of setting corresponding properties (useful when subclassing instead of just setting attributes): ``onDragBegin``, ``onDragEnd``, ``onResizeBegin``, ``onResizeEnd`` - ``widgets.Panel``: new functions to override instead of setting corresponding properties (useful when subclassing instead of just setting attributes): ``onDragBegin``, ``onDragEnd``, ``onResizeBegin``, ``onResizeEnd``
- ``dfhack.screen.readTile()``: now populates extended tile property fields (like top_of_text) in the returned Pen object
## Removed ## Removed

@ -844,6 +844,23 @@ static void make_pen_table(lua_State *L, Pen &pen)
lua_pushboolean(L, false); lua_setfield(L, -2, "tile_color"); lua_pushboolean(L, false); lua_setfield(L, -2, "tile_color");
break; break;
} }
if (pen.keep_lower) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "keep_lower");
}
if (pen.write_to_lower) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "write_to_lower");
}
if (pen.top_of_text) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "top_of_text");
}
if (pen.bottom_of_text) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "bottom_of_text");
}
} }
} }

@ -294,6 +294,7 @@ static Pen doGetTile_default(int x, int y, bool map) {
return Pen(0, 0, 0, -1); return Pen(0, 0, 0, -1);
long *texpos = &gps->screentexpos[index]; long *texpos = &gps->screentexpos[index];
long *texpos_lower = &gps->screentexpos_lower[index];
uint32_t *flag = &gps->screentexpos_flag[index]; uint32_t *flag = &gps->screentexpos_flag[index];
if (gps->top_in_use && if (gps->top_in_use &&
@ -301,6 +302,7 @@ static Pen doGetTile_default(int x, int y, bool map) {
(use_graphics && gps->screentexpos_top[index]))) { (use_graphics && gps->screentexpos_top[index]))) {
screen = &gps->screen_top[index * 8]; screen = &gps->screen_top[index * 8];
texpos = &gps->screentexpos_top[index]; texpos = &gps->screentexpos_top[index];
texpos_lower = &gps->screentexpos_top_lower[index];
flag = &gps->screentexpos_top_flag[index]; flag = &gps->screentexpos_top_flag[index];
} }
@ -308,19 +310,37 @@ static Pen doGetTile_default(int x, int y, bool map) {
uint8_t fg = to_16_bit_color(&screen[1]); uint8_t fg = to_16_bit_color(&screen[1]);
uint8_t bg = to_16_bit_color(&screen[4]); uint8_t bg = to_16_bit_color(&screen[4]);
int tile = 0; int tile = 0;
if (use_graphics) bool write_to_lower = false;
bool top_of_text = false;
bool bottom_of_text = false;
if (use_graphics) {
tile = *texpos; tile = *texpos;
if (!tile && *texpos_lower) {
tile = *texpos_lower;
write_to_lower = true;
}
if (*flag & 0x8)
top_of_text = true;
else if (*flag &0x10)
bottom_of_text = true;
}
Pen ret;
if (*flag & 1) { if (*flag & 1) {
// TileColor // TileColor
return Pen(ch, fg&7, bg, !!(fg&8), tile, fg, bg); ret = Pen(ch, fg&7, bg, !!(fg&8), tile, fg, bg);
} else if (*flag & 2) { } else if (*flag & 2) {
// CharColor // CharColor
return Pen(ch, fg, bg, tile, true); ret = Pen(ch, fg, bg, tile, true);
} else {
// AsIs
ret = Pen(ch, fg, bg, tile, false);
} }
// AsIs ret.write_to_lower = write_to_lower;
return Pen(ch, fg, bg, tile, false); ret.top_of_text = top_of_text;
ret.bottom_of_text = bottom_of_text;
return ret;
} }
GUI_HOOK_DEFINE(Screen::Hooks::get_tile, doGetTile_default); GUI_HOOK_DEFINE(Screen::Hooks::get_tile, doGetTile_default);