redesign stockpiles overlay

develop
Myk Taylor 2023-05-04 02:39:49 -07:00
parent b7d4b8fed6
commit aa1c0f2071
No known key found for this signature in database
1 changed files with 48 additions and 64 deletions

@ -75,7 +75,7 @@ end
local function get_sp_id(opts) local function get_sp_id(opts)
if opts.id then return opts.id end if opts.id then return opts.id end
local sp = dfhack.gui.getSelectedStockpile() local sp = dfhack.gui.getSelectedStockpile(true)
if sp then return sp.id end if sp then return sp.id end
return nil return nil
end end
@ -212,16 +212,16 @@ function get_stockpile_features(stockpile_number)
return config.melt, config.trade, config.dump return config.melt, config.trade, config.dump
end end
function set_stockpile_features(stockpile_number, melt, trade, dump)
logistics.logistics_setStockpileConfig(stockpile_number, melt, trade, dump)
end
-------------------- --------------------
-- dialogs -- dialogs
-------------------- --------------------
StockpilesExport = defclass(StockpilesExport, widgets.Window) StockpilesExport = defclass(StockpilesExport, widgets.Window)
StockpilesExport.ATTRS{ StockpilesExport.ATTRS{frame_title='Export stockpile settings', frame={w=33, h=15}, resizable=true}
frame_title='Export stockpile settings',
frame={w=33, h=15},
resizable=true,
}
function StockpilesExport:init() function StockpilesExport:init()
self:addviews{ self:addviews{
@ -365,22 +365,19 @@ end
StockpilesOverlay = defclass(StockpilesOverlay, overlay.OverlayWidget) StockpilesOverlay = defclass(StockpilesOverlay, overlay.OverlayWidget)
StockpilesOverlay.ATTRS{ StockpilesOverlay.ATTRS{
default_pos={x=53, y=-6}, default_pos={x=24, y=-6},
default_enabled=true, default_enabled=true,
viewscreens='dwarfmode/Some/Stockpile', viewscreens='dwarfmode/Some/Stockpile',
frame={w=27, h=11}, frame={w=73, h=4},
} }
function StockpilesOverlay:init() function StockpilesOverlay:init()
self.minimized = false self.minimized = false
self.hovered = false
local main_panel = widgets.ResizingPanel{ local main_panel = widgets.Panel{
view_id='main', view_id='main',
frame={b=0, l=0, r=0},
frame_style=gui.MEDIUM_FRAME, frame_style=gui.MEDIUM_FRAME,
frame_background=gui.CLEAR_PEN, frame_background=gui.CLEAR_PEN,
autoarrange_subviews=true,
visible=function() visible=function()
return not self.minimized return not self.minimized
end, end,
@ -388,64 +385,59 @@ function StockpilesOverlay:init()
widgets.HotkeyLabel{ widgets.HotkeyLabel{
frame={t=0, l=0}, frame={t=0, l=0},
label='import settings', label='import settings',
auto_width=true,
key='CUSTOM_CTRL_I', key='CUSTOM_CTRL_I',
on_activate=do_import, on_activate=do_import,
}, widgets.HotkeyLabel{ }, widgets.HotkeyLabel{
frame={t=1, l=0}, frame={t=1, l=0},
label='export settings', label='export settings',
auto_width=true,
key='CUSTOM_CTRL_E', key='CUSTOM_CTRL_E',
on_activate=do_export, on_activate=do_export,
}, widgets.Panel{ }, widgets.Panel{
frame={t=2, h=4}, frame={t=0, l=25},
subviews={ subviews={
widgets.Label{ widgets.Label{
frame={t=1, l=0, h=2}, frame={t=0, l=0, h=1},
auto_height=false, auto_height=false,
text={'Designate items brought', NEWLINE, 'to this stockpile for:'}, text={'Designate items brought to this stockpile for:'},
}, text_pen=COLOR_DARKGREY,
},
visible=function()
return self.hovered or self.subviews.melt:getOptionValue() or
self.subviews.trade:getOptionValue() or
self.subviews.dump:getOptionValue()
end,
}, widgets.ToggleHotkeyLabel{ }, widgets.ToggleHotkeyLabel{
view_id='melt', view_id='melt',
frame={t=6, l=2}, frame={t=1, l=0},
label='melting', auto_width=true,
key='CUSTOM_CTRL_M', key='CUSTOM_CTRL_M',
option_gap=-1,
options={{label='Melting', value=true, pen=COLOR_RED},
{label='Melting', value=false}},
on_change=self:callback('toggleLogisticsFeature', 'melt'), on_change=self:callback('toggleLogisticsFeature', 'melt'),
visible=function()
return self.hovered or self.subviews.melt:getOptionValue()
end,
}, widgets.ToggleHotkeyLabel{ }, widgets.ToggleHotkeyLabel{
view_id='trade', view_id='trade',
frame={t=7, l=2}, frame={t=1, l=16},
label='trading', auto_width=true,
key='CUSTOM_CTRL_T', key='CUSTOM_CTRL_T',
option_gap=-1,
options={{label='Trading', value=true, pen=COLOR_YELLOW},
{label='Trading', value=false}},
on_change=self:callback('toggleLogisticsFeature', 'trade'), on_change=self:callback('toggleLogisticsFeature', 'trade'),
visible=function()
return self.hovered or self.subviews.trade:getOptionValue()
end,
}, widgets.ToggleHotkeyLabel{ }, widgets.ToggleHotkeyLabel{
view_id='dump', view_id='dump',
frame={t=8, l=2}, frame={t=1, l=32},
label='dumping', auto_width=true,
key='CUSTOM_CTRL_D', key='CUSTOM_CTRL_U',
option_gap=-1,
options={{label='Dumping', value=true, pen=COLOR_LIGHTMAGENTA},
{label='Dumping', value=false}},
on_change=self:callback('toggleLogisticsFeature', 'dump'), on_change=self:callback('toggleLogisticsFeature', 'dump'),
visible=function() },
return self.hovered or self.subviews.dump:getOptionValue() },
end,
}, },
}, },
} }
self:addviews{ self:addviews{
main_panel, MinimizeButton{ main_panel, MinimizeButton{
frame={b=0, l=1}, frame={t=0, r=1},
label_pos='right',
symbol_minimize=string.char(30),
symbol_restore=string.char(31),
get_minimized_fn=function() get_minimized_fn=function()
return self.minimized return self.minimized
end, end,
@ -460,33 +452,25 @@ function StockpilesOverlay:overlay_onupdate()
end end
function StockpilesOverlay:onRenderFrame() function StockpilesOverlay:onRenderFrame()
local sp = dfhack.gui.getSelectedStockpile() local sp = dfhack.gui.getSelectedStockpile(true)
local sp_updated = false if sp and self.cur_stockpile ~= sp then
if self.cur_stockpile ~= sp then
local config = logistics.logistics_getStockpileConfigs(sp.stockpile_number)[1] local config = logistics.logistics_getStockpileConfigs(sp.stockpile_number)[1]
self.subviews.melt:setOption(config.melt == 1) self.subviews.melt:setOption(config.melt == 1)
self.subviews.trade:setOption(config.trade == 1) self.subviews.trade:setOption(config.trade == 1)
self.subviews.dump:setOption(config.dump == 1) self.subviews.dump:setOption(config.dump == 1)
self.cur_stockpile = sp self.cur_stockpile = sp
sp_updated = true
end
local prev_hovered = self.hovered
self.hovered = not not (self.hovered and self:getMouseFramePos() or
self.subviews.main:getMousePos())
if self.hovered ~= prev_hovered or sp_updated then
self:updateLayout()
df.global.gps.force_full_display_count = 1
end end
end end
function StockpilesOverlay:toggleLogisticsFeature(feature) function StockpilesOverlay:toggleLogisticsFeature(feature)
local sp = dfhack.gui.getSelectedStockpile() self.cur_stockpile = nil
local sp = dfhack.gui.getSelectedStockpile(true)
if not sp then return end
local config = logistics.logistics_getStockpileConfigs(sp.stockpile_number)[1] local config = logistics.logistics_getStockpileConfigs(sp.stockpile_number)[1]
-- logical xor -- logical xor
logistics.logistics_setStockpileConfig(config.stockpile_number, logistics.logistics_setStockpileConfig(config.stockpile_number,
(feature == 'melt') ~= (config.melt == 1), (feature == 'trade') ~= (config.trade == 1), (feature == 'melt') ~= (config.melt == 1), (feature == 'trade') ~= (config.trade == 1),
(feature == 'dump') ~= (config.dump == 1)) (feature == 'dump') ~= (config.dump == 1))
self.cur_stockpile = nil
end end
function StockpilesOverlay:toggleMinimized() function StockpilesOverlay:toggleMinimized()