implement hollow area placement for constructions

develop
Myk Taylor 2023-02-21 13:04:53 -08:00
parent 1957ad4cdf
commit 4f2d86f50a
No known key found for this signature in database
2 changed files with 36 additions and 7 deletions

@ -560,8 +560,8 @@ static int countAvailableItems(color_ostream &out, df::building_type type, int16
return scanAvailableItems(out, type, subtype, custom, index); return scanAvailableItems(out, type, subtype, custom, index);
} }
static bool hasMaterialFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) { static bool hasFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {
DEBUG(status,out).print("entering hasMaterialFilter\n"); DEBUG(status,out).print("entering hasFilter\n");
return false; return false;
} }
@ -708,7 +708,7 @@ DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(doCycle), DFHACK_LUA_FUNCTION(doCycle),
DFHACK_LUA_FUNCTION(scheduleCycle), DFHACK_LUA_FUNCTION(scheduleCycle),
DFHACK_LUA_FUNCTION(countAvailableItems), DFHACK_LUA_FUNCTION(countAvailableItems),
DFHACK_LUA_FUNCTION(hasMaterialFilter), DFHACK_LUA_FUNCTION(hasFilter),
DFHACK_LUA_FUNCTION(setMaterialFilter), DFHACK_LUA_FUNCTION(setMaterialFilter),
DFHACK_LUA_FUNCTION(setHeatSafetyFilter), DFHACK_LUA_FUNCTION(setHeatSafetyFilter),
DFHACK_LUA_FUNCTION(getDescString), DFHACK_LUA_FUNCTION(getDescString),

@ -146,6 +146,8 @@ BuildingplanScreen.ATTRS {
local BUILD_TEXT_PEN = to_pen{fg=COLOR_BLACK, bg=COLOR_GREEN, keep_lower=true} local BUILD_TEXT_PEN = to_pen{fg=COLOR_BLACK, bg=COLOR_GREEN, keep_lower=true}
local BUILD_TEXT_HPEN = to_pen{fg=COLOR_WHITE, bg=COLOR_GREEN, keep_lower=true} local BUILD_TEXT_HPEN = to_pen{fg=COLOR_WHITE, bg=COLOR_GREEN, keep_lower=true}
local recently_selected = {}
ItemSelection = defclass(ItemSelection, widgets.Window) ItemSelection = defclass(ItemSelection, widgets.Window)
ItemSelection.ATTRS{ ItemSelection.ATTRS{
frame_title='Choose items', frame_title='Choose items',
@ -442,8 +444,12 @@ local function is_plannable()
and uibs.building_subtype == df.construction_type.TrackNSEW) and uibs.building_subtype == df.construction_type.TrackNSEW)
end end
local function is_stairs() local function is_construction()
return uibs.building_type == df.building_type.Construction return uibs.building_type == df.building_type.Construction
end
local function is_stairs()
return is_construction
and uibs.building_subtype == df.construction_type.UpDownStair and uibs.building_subtype == df.construction_type.UpDownStair
end end
@ -555,7 +561,7 @@ function ItemLine:onInput(keys)
end end
function ItemLine:get_x_pen() function ItemLine:get_x_pen()
return hasMaterialFilter(uibs.building_type, uibs.building_subtype, uibs.custom_type, self.idx - 1) and return hasFilter(uibs.building_type, uibs.building_subtype, uibs.custom_type, self.idx - 1) and
COLOR_GREEN or COLOR_GREY COLOR_GREEN or COLOR_GREY
end end
@ -678,6 +684,17 @@ function PlannerOverlay:init()
is_selected_fn=make_is_selected_fn(4), on_select=on_select_fn, is_selected_fn=make_is_selected_fn(4), on_select=on_select_fn,
on_filter=self:callback('set_filter'), on_filter=self:callback('set_filter'),
on_clear_filter=self:callback('clear_filter')}, on_clear_filter=self:callback('clear_filter')},
widgets.CycleHotkeyLabel{
view_id='hollow',
frame={t=3, l=4},
key='CUSTOM_H',
label='Hollow area:',
visible=is_construction,
options={
{label='No', value=false},
{label='Yes', value=true},
},
},
widgets.CycleHotkeyLabel{ widgets.CycleHotkeyLabel{
view_id='stairs_top_subtype', view_id='stairs_top_subtype',
frame={t=4, l=4}, frame={t=4, l=4},
@ -747,7 +764,7 @@ function PlannerOverlay:init()
auto_width=true, auto_width=true,
on_activate=function() self:clear_filter(self.selected) end, on_activate=function() self:clear_filter(self.selected) end,
enabled=function() enabled=function()
return hasMaterialFilter(uibs.building_type, uibs.building_subtype, uibs.custom_type, self.selected - 1) return hasFilter(uibs.building_type, uibs.building_subtype, uibs.custom_type, self.selected - 1)
end end
}, },
widgets.CycleHotkeyLabel{ widgets.CycleHotkeyLabel{
@ -904,6 +921,7 @@ function PlannerOverlay:onInput(keys)
return true return true
end end
self.selected = 1 self.selected = 1
self.subviews.hollow:setOption(false)
self.subviews.choose:setOption(false) self.subviews.choose:setOption(false)
self:reset() self:reset()
reset_counts_flag = true reset_counts_flag = true
@ -1005,10 +1023,16 @@ function PlannerOverlay:onRenderFrame(dc, rect)
y2 = math.max(selection_pos.y, pos.y), y2 = math.max(selection_pos.y, pos.y),
} }
local hollow = self.subviews.hollow:getOptionValue()
local pen = (self.saved_selection_pos or #uibs.errors == 0) and GOOD_PEN or BAD_PEN local pen = (self.saved_selection_pos or #uibs.errors == 0) and GOOD_PEN or BAD_PEN
local function get_overlay_pen(pos) local function get_overlay_pen(pos)
return pen if not hollow then return pen end
if pos.x == bounds.x1 or pos.x == bounds.x2 or
pos.y == bounds.y1 or pos.y == bounds.y2 then
return pen
end
return gui.TRANSPARENT_PEN
end end
guidm.renderMapOverlay(get_overlay_pen, bounds) guidm.renderMapOverlay(get_overlay_pen, bounds)
@ -1045,8 +1069,12 @@ end
function PlannerOverlay:place_building(placement_data, chosen_items) function PlannerOverlay:place_building(placement_data, chosen_items)
local p1, p2 = placement_data.p1, placement_data.p2 local p1, p2 = placement_data.p1, placement_data.p2
local blds = {} local blds = {}
local hollow = self.subviews.hollow:getOptionValue()
local subtype = uibs.building_subtype local subtype = uibs.building_subtype
for z=p1.z,p2.z do for y=p1.y,p2.y do for x=p1.x,p2.x do for z=p1.z,p2.z do for y=p1.y,p2.y do for x=p1.x,p2.x do
if hollow and x ~= p1.x and x ~= p2.x and y ~= p1.y and y ~= p2.y then
goto continue
end
local pos = xyz2pos(x, y, z) local pos = xyz2pos(x, y, z)
if is_stairs() then if is_stairs() then
subtype = self:get_stairs_subtype(pos, p1, p2) subtype = self:get_stairs_subtype(pos, p1, p2)
@ -1073,6 +1101,7 @@ function PlannerOverlay:place_building(placement_data, chosen_items)
if k == 'speed' then bld.speed = uibs.speed end if k == 'speed' then bld.speed = uibs.speed end
end end
table.insert(blds, bld) table.insert(blds, bld)
::continue::
end end end end end end
self.subviews.item1:reduce_quantity() self.subviews.item1:reduce_quantity()
self.subviews.item2:reduce_quantity() self.subviews.item2:reduce_quantity()