more tokens, textures, and colors

develop
Myk Taylor 2023-02-16 23:02:34 -08:00
parent c0cdd58b50
commit c59ad78f40
No known key found for this signature in database
2 changed files with 64 additions and 41 deletions

@ -148,7 +148,30 @@ static void validate_config(color_ostream &out, bool verbose = false) {
set_config_bool(config, CONFIG_BARS, false); set_config_bool(config, CONFIG_BARS, false);
} }
static void clear_job_item_repo() { static bool call_buildingplan_lua(color_ostream *out, const char *fn_name,
int nargs = 0, int nres = 0,
Lua::LuaLambda && args_lambda = Lua::DEFAULT_LUA_LAMBDA,
Lua::LuaLambda && res_lambda = Lua::DEFAULT_LUA_LAMBDA) {
DEBUG(status).print("calling buildingplan lua function: '%s'\n", fn_name);
CoreSuspender guard;
auto L = Lua::Core::State;
Lua::StackUnwinder top(L);
if (!out)
out = &Core::getInstance().getConsole();
return Lua::CallLuaModuleFunction(*out, L, "plugins.buildingplan", fn_name,
nargs, nres,
std::forward<Lua::LuaLambda&&>(args_lambda),
std::forward<Lua::LuaLambda&&>(res_lambda));
}
static void clear_state(color_ostream &out) {
call_buildingplan_lua(&out, "signal_reset");
planned_buildings.clear();
tasks.clear();
for (auto &entry : job_item_repo) { for (auto &entry : job_item_repo) {
for (auto &jitem : entry.second) { for (auto &jitem : entry.second) {
delete jitem; delete jitem;
@ -168,9 +191,7 @@ DFhackCExport command_result plugin_load_data (color_ostream &out) {
validate_config(out); validate_config(out);
DEBUG(status,out).print("loading persisted state\n"); DEBUG(status,out).print("loading persisted state\n");
planned_buildings.clear(); clear_state(out);
tasks.clear();
clear_job_item_repo();
vector<PersistentDataItem> building_configs; vector<PersistentDataItem> building_configs;
World::GetPersistentData(&building_configs, BLD_CONFIG_KEY); World::GetPersistentData(&building_configs, BLD_CONFIG_KEY);
const size_t num_building_configs = building_configs.size(); const size_t num_building_configs = building_configs.size();
@ -185,33 +206,11 @@ DFhackCExport command_result plugin_load_data (color_ostream &out) {
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) { DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) {
if (event == SC_WORLD_UNLOADED) { if (event == SC_WORLD_UNLOADED) {
DEBUG(status,out).print("world unloaded; clearing state for %s\n", plugin_name); DEBUG(status,out).print("world unloaded; clearing state for %s\n", plugin_name);
planned_buildings.clear(); clear_state(out);
tasks.clear();
clear_job_item_repo();
} }
return CR_OK; return CR_OK;
} }
static bool call_buildingplan_lua(color_ostream *out, const char *fn_name,
int nargs = 0, int nres = 0,
Lua::LuaLambda && args_lambda = Lua::DEFAULT_LUA_LAMBDA,
Lua::LuaLambda && res_lambda = Lua::DEFAULT_LUA_LAMBDA) {
DEBUG(status).print("calling buildingplan lua function: '%s'\n", fn_name);
CoreSuspender guard;
auto L = Lua::Core::State;
Lua::StackUnwinder top(L);
if (!out)
out = &Core::getInstance().getConsole();
return Lua::CallLuaModuleFunction(*out, L, "plugins.buildingplan", fn_name,
nargs, nres,
std::forward<Lua::LuaLambda&&>(args_lambda),
std::forward<Lua::LuaLambda&&>(res_lambda));
}
static bool cycle_requested = false; static bool cycle_requested = false;
static void do_cycle(color_ostream &out) { static void do_cycle(color_ostream &out) {

@ -64,15 +64,34 @@ function get_job_item(btype, subtype, custom, index)
return obj return obj
end end
local texpos_base = -1 local BUTTON_START_PEN, BUTTON_END_PEN = nil, nil
local reset_counts_flag = false local reset_counts_flag = false
local reset_inspector_flag = false local reset_inspector_flag = false
function signal_reset() function signal_reset()
texpos_base = dfhack.textures.getControlPanelTexposStart() BUTTON_START_PEN = nil
BUTTON_END_PEN = nil
reset_counts_flag = true reset_counts_flag = true
reset_inspector_flag = true reset_inspector_flag = true
end end
local to_pen = dfhack.pen.parse
local function get_button_start_pen()
if not BUTTON_START_PEN then
local texpos_base = dfhack.textures.getControlPanelTexposStart()
BUTTON_START_PEN = to_pen{ch='[', fg=COLOR_YELLOW,
tile=texpos_base > 0 and texpos_base + 13 or nil}
end
return BUTTON_START_PEN
end
local function get_button_end_pen()
if not BUTTON_END_PEN then
local texpos_base = dfhack.textures.getControlPanelTexposStart()
BUTTON_END_PEN = to_pen{ch=']', fg=COLOR_YELLOW,
tile=texpos_base > 0 and texpos_base + 15 or nil}
end
return BUTTON_END_PEN
end
-------------------------------- --------------------------------
-- PlannerOverlay -- PlannerOverlay
-- --
@ -172,19 +191,20 @@ function ItemLine:init()
widgets.Label{ widgets.Label{
frame={t=0, l=23}, frame={t=0, l=23},
text={ text={
{tile=2600}, {tile=get_button_start_pen},
{gap=6, tile=2602}, {gap=6, tile=get_button_end_pen},
{tile=2600}, {tile=get_button_start_pen},
{gap=1, tile=2602}, {gap=1, tile=get_button_end_pen},
}, },
}, },
widgets.Label{ widgets.Label{
frame={t=0, l=0}, frame={t=0, l=0},
text={ text={
{width=21, text=function() return self:get_item_line_text() end}, {width=21, text=self:callback('get_item_line_text')},
{gap=3, text='filter'}, {gap=3, text='filter', pen=COLOR_GREEN},
{gap=2, text='x'}, {gap=2, text='x', pen=COLOR_GREEN},
{gap=3, text=function() return self.note end}, {gap=3, text=function() return self.note end,
pen=function() return self.note_pen end},
}, },
}, },
} }
@ -246,8 +266,13 @@ function ItemLine:get_item_line_text()
self.available = self.available or countAvailableItems(uibs.building_type, self.available = self.available or countAvailableItems(uibs.building_type,
uibs.building_subtype, uibs.custom_type, idx - 1) uibs.building_subtype, uibs.custom_type, idx - 1)
self.note = self.available >= quantity and if self.available >= quantity then
'Can build now' or 'Will build later' self.note_pen = COLOR_GREEN
self.note = 'Available now'
else
self.note_pen = COLOR_YELLOW
self.note = 'Will link later'
end
return ('%d %s%s'):format(quantity, self.desc, quantity == 1 and '' or 's') return ('%d %s%s'):format(quantity, self.desc, quantity == 1 and '' or 's')
end end
@ -298,7 +323,7 @@ function PlannerOverlay:init()
view_id='stairs_top_subtype', view_id='stairs_top_subtype',
frame={t=4, l=4}, frame={t=4, l=4},
key='CUSTOM_R', key='CUSTOM_R',
label='Top Stair Type: ', label='Top Stair Type: ',
visible=is_stairs, visible=is_stairs,
options={ options={
{label='Auto', value='auto'}, {label='Auto', value='auto'},
@ -444,7 +469,6 @@ function PlannerOverlay:render(dc)
PlannerOverlay.super.render(self, dc) PlannerOverlay.super.render(self, dc)
end end
local to_pen = dfhack.pen.parse
local GOOD_PEN = to_pen{ch='o', fg=COLOR_GREEN, local GOOD_PEN = to_pen{ch='o', fg=COLOR_GREEN,
tile=dfhack.screen.findGraphicsTile('CURSORS', 1, 2)} tile=dfhack.screen.findGraphicsTile('CURSORS', 1, 2)}
local BAD_PEN = to_pen{ch='X', fg=COLOR_RED, local BAD_PEN = to_pen{ch='X', fg=COLOR_RED,