support closure as tile arg to get texpos

develop
shevernitskiy 2023-08-14 12:07:27 +03:00
parent 900a2c65ba
commit 0e725be046
3 changed files with 61 additions and 22 deletions

@ -161,6 +161,26 @@ static bool get_int_field(lua_State *L, T *pf, int idx, const char *name, int de
return !nil;
}
template<class T>
static bool get_int_or_closure_field(lua_State *L, T *pf, int idx, const char *name, int defval)
{
lua_getfield(L, idx, name);
bool nil = lua_isnil(L, -1);
if (nil) {
*pf = T(defval);
} else if (lua_isnumber(L, -1)) {
*pf = T(lua_tointeger(L, -1));
} else if (lua_isfunction(L, -1)) {
lua_call(L, 0, 1);
*pf = T(lua_tointeger(L, -1));
lua_pop(L, 1);
} else {
luaL_error(L, "Field %s is not a number or closure function.", name);
}
lua_pop(L, 1);
return !nil;
}
static bool get_char_field(lua_State *L, char *pf, int idx, const char *name, char defval)
{
lua_getfield(L, idx, name);
@ -207,7 +227,7 @@ static void decode_pen(lua_State *L, Pen &pen, int idx)
else pen.bold = lua_toboolean(L, -1);
lua_pop(L, 1);
get_int_field(L, &pen.tile, idx, "tile", 0);
get_int_or_closure_field(L, &pen.tile, idx, "tile", 0);
bool tcolor = get_int_field(L, &pen.tile_fg, idx, "tile_fg", 7);
tcolor = get_int_field(L, &pen.tile_bg, idx, "tile_bg", 0) || tcolor;

@ -912,6 +912,11 @@ local BASE_FRAME = {
paused_pen = to_pen{fg=COLOR_RED, bg=COLOR_BLACK},
}
-- DFHack textures
--------------------------
-- Preloaded DFHack Asset
-- Use this handles if you need to get dfhack standard textures
local texpos_handles = {
green_pin = dfhack.textures.loadTileset('hack/data/art/green-pin.png', 8, 12),
red_pin = dfhack.textures.loadTileset('hack/data/art/red-pin.png', 8, 12),
@ -925,6 +930,22 @@ local texpos_handles = {
border_window = dfhack.textures.loadTileset('hack/data/art/border-window.png', 8, 12),
}
-- Mathods to obtain valid texposes by handles
function tp_green_pin(offset)
return dfhack.textures.getTexposByHandle(texpos_handles.green_pin[offset])
end
function tp_red_pin(offset)
return dfhack.textures.getTexposByHandle(texpos_handles.red_pin[offset])
end
function tp_icons(offset)
return dfhack.textures.getTexposByHandle(texpos_handles.icons[offset])
end
function tp_on_off(offset)
return dfhack.textures.getTexposByHandle(texpos_handles.on_off[offset])
end
function tp_control_panel(offset)
return dfhack.textures.getTexposByHandle(texpos_handles.control_panel[offset])
end
function tp_border_thin(offset)
return dfhack.textures.getTexposByHandle(texpos_handles.border_thin[offset])
end
@ -940,27 +961,25 @@ end
function tp_border_window(offset)
return dfhack.textures.getTexposByHandle(texpos_handles.border_window[offset])
end
function tp_control_panel(offset)
return dfhack.textures.getTexposByHandle(texpos_handles.control_panel[offset])
end
local function make_frame(tp, double_line)
local frame = copyall(BASE_FRAME)
frame.t_frame_pen = to_pen{ tile=tp(2), ch=double_line and 205 or 196, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.l_frame_pen = to_pen{ tile=tp(8), ch=double_line and 186 or 179, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.b_frame_pen = to_pen{ tile=tp(16), ch=double_line and 205 or 196, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.r_frame_pen = to_pen{ tile=tp(10), ch=double_line and 186 or 179, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.lt_frame_pen = to_pen{ tile=tp(1), ch=double_line and 201 or 218, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.lb_frame_pen = to_pen{ tile=tp(15), ch=double_line and 200 or 192, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.rt_frame_pen = to_pen{ tile=tp(3), ch=double_line and 187 or 191, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.rb_frame_pen = to_pen{ tile=tp(17), ch=double_line and 188 or 217, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.t_frame_pen = to_pen{ tile=curry(tp, 2), ch=double_line and 205 or 196, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.l_frame_pen = to_pen{ tile=curry(tp, 8), ch=double_line and 186 or 179, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.b_frame_pen = to_pen{ tile=curry(tp, 16), ch=double_line and 205 or 196, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.r_frame_pen = to_pen{ tile=curry(tp, 10), ch=double_line and 186 or 179, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.lt_frame_pen = to_pen{ tile=curry(tp, 1), ch=double_line and 201 or 218, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.lb_frame_pen = to_pen{ tile=curry(tp, 15), ch=double_line and 200 or 192, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.rt_frame_pen = to_pen{ tile=curry(tp, 3), ch=double_line and 187 or 191, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.rb_frame_pen = to_pen{ tile=curry(tp, 17), ch=double_line and 188 or 217, fg=COLOR_GREY, bg=COLOR_BLACK }
return frame
end
function FRAME_WINDOW(resizable)
local frame = make_frame(tp_border_window, true)
if not resizable then
frame.rb_frame_pen = to_pen{ tile=tp_border_panel(17), ch=double_line and 188 or 217, fg=COLOR_GREY, bg=COLOR_BLACK }
frame.rb_frame_pen = to_pen{ tile=curry(tp_border_panel, 17), ch=double_line and 188 or 217, fg=COLOR_GREY, bg=COLOR_BLACK }
end
return frame
end

@ -15,17 +15,17 @@ function reload_pens()
GOOD_TILE_PEN = to_pen{ch='o', fg=COLOR_GREEN, tile=dfhack.screen.findGraphicsTile('CURSORS', 1, 2)}
BAD_TILE_PEN = to_pen{ch='X', fg=COLOR_RED, tile=dfhack.screen.findGraphicsTile('CURSORS', 3, 0)}
VERT_TOP_PEN = to_pen { tile = gui.tp_border_thin(11), ch = 194, fg = COLOR_GREY, bg = COLOR_BLACK }
VERT_MID_PEN = to_pen { tile = gui.tp_border_thin(5), ch = 179, fg = COLOR_GREY, bg = COLOR_BLACK }
VERT_BOT_PEN = to_pen { tile = gui.tp_border_thin(12), ch = 193, fg = COLOR_GREY, bg = COLOR_BLACK }
VERT_TOP_PEN = to_pen { tile = curry(gui.tp_border_thin, 11), ch = 194, fg = COLOR_GREY, bg = COLOR_BLACK }
VERT_MID_PEN = to_pen { tile = curry(gui.tp_border_thin, 5), ch = 179, fg = COLOR_GREY, bg = COLOR_BLACK }
VERT_BOT_PEN = to_pen { tile = curry(gui.tp_border_thin, 12), ch = 193, fg = COLOR_GREY, bg = COLOR_BLACK }
HORI_LEFT_PEN = to_pen { tile = gui.tp_border_medium(13), ch = 195, fg = COLOR_GREY, bg = COLOR_BLACK }
HORI_MID_PEN = to_pen { tile = gui.tp_border_medium(6), ch = 196, fg = COLOR_GREY, bg = COLOR_BLACK }
HORI_RIGHT_PEN = to_pen { tile = gui.tp_border_medium(14), ch = 180, fg = COLOR_GREY, bg = COLOR_BLACK }
HORI_LEFT_PEN = to_pen { tile = curry(gui.tp_border_medium, 13), ch = 195, fg = COLOR_GREY, bg = COLOR_BLACK }
HORI_MID_PEN = to_pen { tile = curry(gui.tp_border_medium, 6), ch = 196, fg = COLOR_GREY, bg = COLOR_BLACK }
HORI_RIGHT_PEN = to_pen { tile = curry(gui.tp_border_medium, 14), ch = 180, fg = COLOR_GREY, bg = COLOR_BLACK }
BUTTON_START_PEN = to_pen { tile = gui.tp_control_panel(14), ch = '[', fg = COLOR_YELLOW }
BUTTON_END_PEN = to_pen { tile = gui.tp_control_panel(16), ch = ']', fg = COLOR_YELLOW }
SELECTED_ITEM_PEN = to_pen { tile = gui.tp_control_panel(10), ch = string.char(251), fg = COLOR_YELLOW }
BUTTON_START_PEN = to_pen { tile = curry(gui.tp_control_panel, 14), ch = '[', fg = COLOR_YELLOW }
BUTTON_END_PEN = to_pen { tile = curry(gui.tp_control_panel, 16), ch = ']', fg = COLOR_YELLOW }
SELECTED_ITEM_PEN = to_pen { tile = curry(gui.tp_control_panel, 10), ch = string.char(251), fg = COLOR_YELLOW }
MINI_TEXT_PEN = to_pen{fg=COLOR_BLACK, bg=COLOR_GREY}
MINI_TEXT_HPEN = to_pen{fg=COLOR_BLACK, bg=COLOR_WHITE}