skeleton for quantity scanning

develop
Myk Taylor 2023-02-13 16:24:10 -08:00
parent c490be0271
commit a9d9e0e50c
No known key found for this signature in database
2 changed files with 34 additions and 10 deletions

@ -707,6 +707,11 @@ static void scheduleCycle(color_ostream &out) {
cycle_requested = true; cycle_requested = true;
} }
static int countAvailableItems(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {
DEBUG(status,out).print("entering countAvailableItems\n");
return 10;
}
DFHACK_PLUGIN_LUA_FUNCTIONS { DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(printStatus), DFHACK_LUA_FUNCTION(printStatus),
DFHACK_LUA_FUNCTION(setSetting), DFHACK_LUA_FUNCTION(setSetting),
@ -715,5 +720,6 @@ DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(addPlannedBuilding), DFHACK_LUA_FUNCTION(addPlannedBuilding),
DFHACK_LUA_FUNCTION(doCycle), DFHACK_LUA_FUNCTION(doCycle),
DFHACK_LUA_FUNCTION(scheduleCycle), DFHACK_LUA_FUNCTION(scheduleCycle),
DFHACK_LUA_FUNCTION(countAvailableItems),
DFHACK_LUA_END DFHACK_LUA_END
}; };

@ -143,8 +143,7 @@ local function to_title_case(str)
return str return str
end end
-- returns a reasonable label for the item based on the qualities of the filter function get_item_line_text(idx)
function get_item_label(idx)
local filter = get_cur_filters()[idx] local filter = get_cur_filters()[idx]
local desc = 'Unknown' local desc = 'Unknown'
if filter.has_tool_use then if filter.has_tool_use then
@ -154,17 +153,24 @@ function get_item_label(idx)
desc = to_title_case(df.item_type[filter.item_type]) desc = to_title_case(df.item_type[filter.item_type])
end end
if filter.flags2 and filter.flags2.building_material then if filter.flags2 and filter.flags2.building_material then
desc = "Generic building material"; desc = "Generic material";
if filter.flags2.fire_safe then if filter.flags2.fire_safe then
desc = "Fire-safe building material"; desc = "Fire-safe material";
end end
if filter.flags2.magma_safe then if filter.flags2.magma_safe then
desc = "Magma-safe building material"; desc = "Magma-safe material";
end end
elseif filter.vector_id then elseif filter.vector_id then
desc = to_title_case(df.job_item_vector_id[filter.vector_id]) desc = to_title_case(df.job_item_vector_id[filter.vector_id])
end end
if desc:endswith('s') then
desc = desc:sub(1,-2)
end
if desc == 'Trappart' then
desc = 'Mechanism'
end
local quantity = filter.quantity or 1 local quantity = filter.quantity or 1
local dimx, dimy, dimz = get_cur_area_dims() local dimx, dimy, dimz = get_cur_area_dims()
if quantity < 1 then if quantity < 1 then
@ -172,7 +178,14 @@ function get_item_label(idx)
else else
quantity = quantity * dimx * dimy * dimz quantity = quantity * dimx * dimy * dimz
end end
return ('%s (need: %d)'):format(desc, quantity) desc = ('%d %s%s'):format(quantity, desc, quantity == 1 and '' or 's')
local available = countAvailableItems(uibs.building_type,
uibs.building_subtype, uibs.custom_type, idx - 1)
local note = available >= quantity and
'Can build now' or 'Will wait for item'
return ('%-21s%s%s'):format(desc:sub(1,21), (' '):rep(13), note)
end end
ItemLine = defclass(ItemLine, widgets.Panel) ItemLine = defclass(ItemLine, widgets.Panel)
@ -186,7 +199,11 @@ function ItemLine:init()
self:addviews{ self:addviews{
widgets.Label{ widgets.Label{
frame={t=0, l=0}, frame={t=0, l=0},
text={{text=function() return get_item_label(self.idx) end}} text={{text=function() return get_item_line_text(self.idx) end}},
},
widgets.Label{
frame={t=0, l=22},
text='[filter][x]',
}, },
} }
end end
@ -215,7 +232,7 @@ function PlannerOverlay:init()
ItemLine{frame={t=6, l=0}, idx=4}, ItemLine{frame={t=6, l=0}, idx=4},
widgets.CycleHotkeyLabel{ widgets.CycleHotkeyLabel{
view_id="stairs_top_subtype", view_id="stairs_top_subtype",
frame={t=2, l=0}, frame={t=3, l=0},
key="CUSTOM_R", key="CUSTOM_R",
label="Top Stair Type: ", label="Top Stair Type: ",
visible=is_stairs, visible=is_stairs,
@ -227,7 +244,7 @@ function PlannerOverlay:init()
}, },
widgets.CycleHotkeyLabel { widgets.CycleHotkeyLabel {
view_id="stairs_bottom_subtype", view_id="stairs_bottom_subtype",
frame={t=3, l=0}, frame={t=4, l=0},
key="CUSTOM_B", key="CUSTOM_B",
label="Bottom Stair Type: ", label="Bottom Stair Type: ",
visible=is_stairs, visible=is_stairs,
@ -242,7 +259,7 @@ function PlannerOverlay:init()
text={ text={
'Selected area: ', 'Selected area: ',
{text=function() {text=function()
return ('%d x %d x %d'):format(get_cur_area_dims()) return ('%dx%dx%d'):format(get_cur_area_dims())
end end
}, },
}, },
@ -401,6 +418,7 @@ function PlannerOverlay:place_building()
for _,bld in ipairs(blds) do for _,bld in ipairs(blds) do
addPlannedBuilding(bld) addPlannedBuilding(bld)
end end
scheduleCycle()
end end
InspectorOverlay = defclass(InspectorOverlay, overlay.OverlayWidget) InspectorOverlay = defclass(InspectorOverlay, overlay.OverlayWidget)