2014-12-02 12:00:16 -07:00
|
|
|
local _ENV = mkmodule('plugins.stockpiles')
|
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local argparse = require('argparse')
|
2023-04-22 20:03:58 -06:00
|
|
|
local gui = require('gui')
|
|
|
|
local logistics = require('plugins.logistics')
|
|
|
|
local overlay = require('plugins.overlay')
|
|
|
|
local widgets = require('gui.widgets')
|
2014-12-02 12:00:16 -07:00
|
|
|
|
2023-04-23 00:13:50 -06:00
|
|
|
local STOCKPILES_DIR = 'dfhack-config/stockpiles';
|
|
|
|
local STOCKPILES_LIBRARY_DIR = 'hack/data/stockpiles';
|
2014-12-02 12:00:16 -07:00
|
|
|
|
2023-04-22 20:03:58 -06:00
|
|
|
--------------------
|
|
|
|
-- plugin logic
|
|
|
|
--------------------
|
2023-04-23 00:13:50 -06:00
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local function get_sp_name(name, num)
|
|
|
|
if #name > 0 then return name end
|
|
|
|
return ('Stockpile %d'):format(num)
|
2014-12-04 03:52:38 -07:00
|
|
|
end
|
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local STATUS_FMT = '%6s %s'
|
|
|
|
local function print_status()
|
|
|
|
local sps = df.global.world.buildings.other.STOCKPILE
|
|
|
|
print(('Current stockpiles: %d'):format(#sps))
|
|
|
|
if #sps > 0 then
|
|
|
|
print()
|
|
|
|
print(STATUS_FMT:format('ID', 'Name'))
|
|
|
|
print(STATUS_FMT:format('------', '----------'))
|
2014-12-05 06:49:40 -07:00
|
|
|
end
|
2023-04-23 00:13:50 -06:00
|
|
|
for _, sp in ipairs(sps) do
|
2023-03-15 18:16:42 -06:00
|
|
|
print(STATUS_FMT:format(sp.id, get_sp_name(sp.name, sp.stockpile_number)))
|
2014-12-05 06:49:40 -07:00
|
|
|
end
|
2023-03-15 18:16:42 -06:00
|
|
|
end
|
2014-12-05 06:49:40 -07:00
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local function list_dir(path, prefix, filters)
|
|
|
|
local paths = dfhack.filesystem.listdir_recursive(path, 0, false)
|
|
|
|
if not paths then
|
|
|
|
dfhack.printerr(('Cannot find stockpile settings directory: "%s"'):format(path))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local normalized_filters = {}
|
2023-04-23 00:13:50 -06:00
|
|
|
for _, filter in ipairs(filters or {}) do table.insert(normalized_filters, filter:lower()) end
|
|
|
|
for _, v in ipairs(paths) do
|
2023-03-15 18:16:42 -06:00
|
|
|
local normalized_path = prefix .. v.path:lower()
|
|
|
|
if v.isdir or not normalized_path:endswith('.dfstock') then goto continue end
|
|
|
|
normalized_path = normalized_path:sub(1, -9)
|
|
|
|
if #normalized_filters > 0 then
|
|
|
|
local matched = false
|
2023-04-23 00:13:50 -06:00
|
|
|
for _, filter in ipairs(normalized_filters) do
|
2023-03-15 18:16:42 -06:00
|
|
|
if normalized_path:find(filter, 1, true) then
|
|
|
|
matched = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not matched then goto continue end
|
2014-12-05 06:49:40 -07:00
|
|
|
end
|
2023-03-15 18:16:42 -06:00
|
|
|
print(('%s%s'):format(prefix, v.path:sub(1, -9)))
|
|
|
|
::continue::
|
2014-12-05 06:49:40 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local function list_settings_files(filters)
|
|
|
|
list_dir(STOCKPILES_DIR, '', filters)
|
|
|
|
list_dir(STOCKPILES_LIBRARY_DIR, 'library/', filters)
|
2014-12-05 06:49:40 -07:00
|
|
|
end
|
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local function assert_safe_name(name)
|
2023-04-23 00:13:50 -06:00
|
|
|
if not name or #name == 0 then qerror('name missing or empty') end
|
2023-04-11 00:07:18 -06:00
|
|
|
if name:find('[^%w._]') then
|
2023-03-23 00:58:02 -06:00
|
|
|
qerror('name can only contain numbers, letters, periods, and underscores')
|
2014-12-02 12:00:16 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local function get_sp_id(opts)
|
|
|
|
if opts.id then return opts.id end
|
|
|
|
local sp = dfhack.gui.getSelectedStockpile()
|
|
|
|
if sp then return sp.id end
|
|
|
|
return nil
|
2015-07-29 12:17:14 -06:00
|
|
|
end
|
|
|
|
|
2023-04-23 00:13:50 -06:00
|
|
|
local included_elements = {containers=1, general=2, categories=4, types=8, features=16}
|
2023-03-15 22:54:48 -06:00
|
|
|
|
2023-05-20 17:00:59 -06:00
|
|
|
function export_stockpile(name, opts)
|
2023-03-15 18:16:42 -06:00
|
|
|
assert_safe_name(name)
|
|
|
|
name = STOCKPILES_DIR .. '/' .. name
|
2023-03-15 22:54:48 -06:00
|
|
|
|
|
|
|
local includedElements = 0
|
2023-04-23 00:13:50 -06:00
|
|
|
for _, inc in ipairs(opts.includes) do
|
2023-04-18 09:22:52 -06:00
|
|
|
includedElements = includedElements | included_elements[inc]
|
2023-03-15 22:54:48 -06:00
|
|
|
end
|
|
|
|
|
2023-03-20 01:32:19 -06:00
|
|
|
if includedElements == 0 then
|
2023-04-23 00:13:50 -06:00
|
|
|
for _, v in pairs(included_elements) do includedElements = includedElements | v end
|
2023-03-20 01:32:19 -06:00
|
|
|
end
|
|
|
|
|
2023-03-15 22:54:48 -06:00
|
|
|
stockpiles_export(name, get_sp_id(opts), includedElements)
|
2015-07-29 12:17:14 -06:00
|
|
|
end
|
|
|
|
|
2023-05-28 03:26:06 -06:00
|
|
|
local function normalize_name(name)
|
2023-03-15 18:16:42 -06:00
|
|
|
local is_library = false
|
|
|
|
if name:startswith('library/') then
|
|
|
|
name = name:sub(9)
|
|
|
|
is_library = true
|
2015-07-29 12:17:14 -06:00
|
|
|
end
|
2023-03-15 18:16:42 -06:00
|
|
|
assert_safe_name(name)
|
|
|
|
if not is_library and dfhack.filesystem.exists(STOCKPILES_DIR .. '/' .. name .. '.dfstock') then
|
2023-05-28 03:26:06 -06:00
|
|
|
return STOCKPILES_DIR .. '/' .. name
|
2023-03-15 18:16:42 -06:00
|
|
|
end
|
2023-05-28 03:26:06 -06:00
|
|
|
return STOCKPILES_LIBRARY_DIR .. '/' .. name
|
|
|
|
end
|
|
|
|
|
|
|
|
function import_stockpile(name, opts)
|
|
|
|
name = normalize_name(name)
|
|
|
|
stockpiles_import(name, get_sp_id(opts), opts.mode, table.concat(opts.filters or {}, ','))
|
|
|
|
end
|
|
|
|
|
|
|
|
function import_route(name, route_id, stop_id, mode, filters)
|
|
|
|
name = normalize_name(name)
|
|
|
|
stockpiles_route_import(name, route_id, stop_id, mode, table.concat(filters or {}, ','))
|
2023-03-15 22:54:48 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
local function parse_include(arg)
|
|
|
|
local includes = argparse.stringList(arg, 'include')
|
2023-04-23 00:13:50 -06:00
|
|
|
for _, v in ipairs(includes) do
|
|
|
|
if not included_elements[v] then qerror(('invalid included element: "%s"'):format(v)) end
|
2023-03-15 22:54:48 -06:00
|
|
|
end
|
|
|
|
return includes
|
|
|
|
end
|
|
|
|
|
|
|
|
local valid_modes = {set=true, enable=true, disable=true}
|
|
|
|
|
|
|
|
local function parse_mode(arg)
|
2023-04-23 00:13:50 -06:00
|
|
|
if not valid_modes[arg] then qerror(('invalid mode: "%s"'):format(arg)) end
|
2023-03-15 22:54:48 -06:00
|
|
|
return arg
|
2015-07-29 12:17:14 -06:00
|
|
|
end
|
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local function process_args(opts, args)
|
|
|
|
if args[1] == 'help' then
|
|
|
|
opts.help = true
|
2014-12-04 03:52:38 -07:00
|
|
|
return
|
|
|
|
end
|
2014-12-05 06:49:40 -07:00
|
|
|
|
2023-03-15 22:54:48 -06:00
|
|
|
opts.includes = {}
|
|
|
|
opts.mode = 'set'
|
2023-03-21 00:25:52 -06:00
|
|
|
opts.filters = {}
|
2023-03-15 22:54:48 -06:00
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
return argparse.processArgsGetopt(args, {
|
2023-04-23 00:13:50 -06:00
|
|
|
{
|
|
|
|
'h',
|
|
|
|
'help',
|
|
|
|
handler=function()
|
|
|
|
opts.help = true
|
|
|
|
end,
|
|
|
|
}, {
|
|
|
|
'm',
|
|
|
|
'mode',
|
|
|
|
hasArg=true,
|
|
|
|
handler=function(arg)
|
|
|
|
opts.mode = parse_mode(arg)
|
|
|
|
end,
|
|
|
|
}, {
|
|
|
|
'f',
|
|
|
|
'filter',
|
|
|
|
hasArg=true,
|
|
|
|
handler=function(arg)
|
|
|
|
opts.filters = argparse.stringList(arg)
|
|
|
|
end,
|
|
|
|
}, {
|
|
|
|
'i',
|
|
|
|
'include',
|
|
|
|
hasArg=true,
|
|
|
|
handler=function(arg)
|
|
|
|
opts.includes = parse_include(arg)
|
|
|
|
end,
|
|
|
|
}, {
|
|
|
|
's',
|
|
|
|
'stockpile',
|
|
|
|
hasArg=true,
|
|
|
|
handler=function(arg)
|
|
|
|
opts.id = argparse.nonnegativeInt(arg, 'stockpile')
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
})
|
2014-12-02 12:00:16 -07:00
|
|
|
end
|
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
function parse_commandline(args)
|
|
|
|
local opts = {}
|
|
|
|
local positionals = process_args(opts, args)
|
2014-12-04 03:52:38 -07:00
|
|
|
|
2023-04-23 00:13:50 -06:00
|
|
|
if opts.help or not positionals then return false end
|
2014-12-02 12:00:16 -07:00
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
local command = table.remove(positionals, 1)
|
|
|
|
if not command or command == 'status' then
|
|
|
|
print_status()
|
|
|
|
elseif command == 'list' then
|
|
|
|
list_settings_files(positionals)
|
|
|
|
elseif command == 'export' then
|
|
|
|
export_stockpile(positionals[1], opts)
|
|
|
|
elseif command == 'import' then
|
|
|
|
import_stockpile(positionals[1], opts)
|
|
|
|
else
|
|
|
|
return false
|
2014-12-04 03:52:38 -07:00
|
|
|
end
|
2014-12-02 12:00:16 -07:00
|
|
|
|
2023-03-15 18:16:42 -06:00
|
|
|
return true
|
2014-12-02 12:23:12 -07:00
|
|
|
end
|
|
|
|
|
2023-04-23 17:09:31 -06:00
|
|
|
--------------------
|
2023-04-23 00:13:50 -06:00
|
|
|
-- dialogs
|
2023-04-22 20:03:58 -06:00
|
|
|
--------------------
|
2023-04-23 00:13:50 -06:00
|
|
|
|
|
|
|
StockpilesExport = defclass(StockpilesExport, widgets.Window)
|
|
|
|
StockpilesExport.ATTRS{
|
2023-04-23 17:09:31 -06:00
|
|
|
frame_title='Export stockpile settings',
|
2023-04-23 00:13:50 -06:00
|
|
|
frame={w=50, h=45},
|
|
|
|
resizable=true,
|
2023-04-23 17:09:31 -06:00
|
|
|
resize_min={w=50, h=20},
|
2023-04-23 00:13:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function StockpilesExport:init()
|
|
|
|
self:addviews{
|
2023-04-23 17:09:31 -06:00
|
|
|
widgets.EditField{}, widgets.Label{frame={}, text='Include which elements?'},
|
|
|
|
widgets.ToggleHotkeyLabel{},
|
2023-04-23 00:13:50 -06:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function StockpilesExport:onInput(keys)
|
|
|
|
-- if required
|
|
|
|
end
|
|
|
|
|
|
|
|
StockpilesExportScreen = defclass(StockpilesExportScreen, gui.ZScreenModal)
|
|
|
|
StockpilesExportScreen.ATTRS{focus_path='stockpiles/export'}
|
|
|
|
|
|
|
|
function StockpilesExportScreen:init()
|
|
|
|
self:addviews{StockpilesExport{}}
|
|
|
|
end
|
|
|
|
|
|
|
|
function StockpilesExportScreen:onDismiss()
|
|
|
|
export_view = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local function do_export()
|
|
|
|
export_view = export_view and export_view:raise() or StockpilesExportScreen{}:show()
|
|
|
|
end
|
|
|
|
|
2023-04-23 17:09:31 -06:00
|
|
|
--------------------
|
2023-04-23 20:44:22 -06:00
|
|
|
-- MinimizeButton
|
2023-04-22 20:03:58 -06:00
|
|
|
--------------------
|
|
|
|
|
2023-04-23 20:44:22 -06:00
|
|
|
MinimizeButton = defclass(MinimizeButton, widgets.Widget)
|
|
|
|
MinimizeButton.ATTRS{
|
|
|
|
label_unminimized='minimize',
|
|
|
|
label_minimized='restore',
|
|
|
|
label_pos='left',
|
|
|
|
get_minimized_fn=DEFAULT_NIL,
|
|
|
|
on_click=DEFAULT_NIL,
|
|
|
|
}
|
2023-04-23 17:09:31 -06:00
|
|
|
|
|
|
|
function MinimizeButton:init()
|
2023-04-23 20:44:22 -06:00
|
|
|
self.hovered = false
|
|
|
|
|
|
|
|
local is_hovered = function() return self.hovered end
|
|
|
|
local is_not_hovered = function() return not self.hovered end
|
|
|
|
local get_action_symbol = function()
|
|
|
|
return self.get_minimized_fn() and string.char(31) or string.char(30)
|
|
|
|
end
|
|
|
|
local get_label = function()
|
|
|
|
local label = self.get_minimized_fn() and self.label_minimized or self.label_unminimized
|
|
|
|
return (' %s '):format(label)
|
|
|
|
end
|
|
|
|
|
|
|
|
local hovered_text = {'[', {text=get_action_symbol}, ']'}
|
|
|
|
table.insert(hovered_text,
|
|
|
|
self.label_pos == 'left' and 1 or nil,
|
|
|
|
{text=get_label, hpen=dfhack.pen.parse{fg=COLOR_BLACK, bg=COLOR_WHITE}})
|
2023-04-23 17:09:31 -06:00
|
|
|
|
|
|
|
self:addviews{
|
|
|
|
widgets.Label{
|
2023-04-23 20:44:22 -06:00
|
|
|
view_id='unhovered_label',
|
|
|
|
frame={t=0, r=0, w=3, h=1},
|
|
|
|
text={'[', {text=get_action_symbol}, ']'},
|
2023-04-23 17:09:31 -06:00
|
|
|
text_pen=dfhack.pen.parse{fg=COLOR_BLACK, bg=COLOR_LIGHTRED},
|
|
|
|
text_hpen=dfhack.pen.parse{fg=COLOR_WHITE, bg=COLOR_RED},
|
2023-04-23 20:44:22 -06:00
|
|
|
on_click=function() self.on_click() self:updateLayout() end,
|
|
|
|
visible=is_not_hovered,
|
2023-04-23 17:09:31 -06:00
|
|
|
}, widgets.Label{
|
2023-04-23 20:44:22 -06:00
|
|
|
view_id='hovered_label',
|
|
|
|
frame={t=0, r=0, h=1},
|
|
|
|
text=hovered_text,
|
|
|
|
auto_width=true,
|
2023-04-23 17:10:54 -06:00
|
|
|
text_pen=dfhack.pen.parse{fg=COLOR_BLACK, bg=COLOR_LIGHTRED},
|
|
|
|
text_hpen=dfhack.pen.parse{fg=COLOR_WHITE, bg=COLOR_RED},
|
2023-04-23 20:44:22 -06:00
|
|
|
on_click=function() self.on_click() self:updateLayout() end,
|
|
|
|
visible=is_hovered,
|
2023-04-23 17:09:31 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-04-23 20:44:22 -06:00
|
|
|
function MinimizeButton:onRenderFrame()
|
|
|
|
local prev_hovered = self.hovered
|
|
|
|
if self.hovered then
|
|
|
|
self.hovered = self.subviews.hovered_label:getMousePos()
|
|
|
|
else
|
|
|
|
self.hovered = self.subviews.unhovered_label:getMousePos()
|
|
|
|
end
|
|
|
|
if self.hovered ~= prev_hovered then
|
|
|
|
self:updateLayout()
|
|
|
|
df.global.gps.force_full_display_count = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------
|
|
|
|
-- StockpilesOverlay
|
|
|
|
--------------------
|
|
|
|
|
2023-04-22 20:03:58 -06:00
|
|
|
StockpilesOverlay = defclass(StockpilesOverlay, overlay.OverlayWidget)
|
|
|
|
StockpilesOverlay.ATTRS{
|
2023-04-23 00:13:50 -06:00
|
|
|
default_pos={x=53, y=-6},
|
|
|
|
default_enabled=true,
|
|
|
|
viewscreens='dwarfmode/Some/Stockpile',
|
|
|
|
frame={w=27, h=11},
|
2023-04-22 20:03:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function StockpilesOverlay:init()
|
|
|
|
self.minimized = false
|
2023-04-23 00:13:50 -06:00
|
|
|
self.hovered = false
|
|
|
|
|
|
|
|
local main_panel = widgets.ResizingPanel{
|
|
|
|
view_id='main',
|
|
|
|
frame={t=0, l=0, r=0},
|
|
|
|
frame_style=gui.MEDIUM_FRAME,
|
|
|
|
frame_background=gui.CLEAR_PEN,
|
|
|
|
autoarrange_subviews=true,
|
|
|
|
visible=function()
|
|
|
|
return not self.minimized
|
|
|
|
end,
|
|
|
|
subviews={
|
2023-04-22 20:03:58 -06:00
|
|
|
widgets.HotkeyLabel{
|
2023-04-23 00:13:50 -06:00
|
|
|
frame={t=0, l=0},
|
2023-04-23 20:44:22 -06:00
|
|
|
label='import settings',
|
2023-04-23 00:13:50 -06:00
|
|
|
key='CUSTOM_CTRL_I',
|
|
|
|
on_activate=do_import,
|
|
|
|
}, widgets.HotkeyLabel{
|
|
|
|
frame={t=1, l=0},
|
|
|
|
label='export settings',
|
|
|
|
key='CUSTOM_CTRL_E',
|
|
|
|
on_activate=do_export,
|
|
|
|
}, widgets.Panel{
|
|
|
|
frame={t=2, h=4},
|
|
|
|
subviews={
|
|
|
|
widgets.Label{
|
|
|
|
frame={t=1, l=0, h=2},
|
|
|
|
auto_height=false,
|
|
|
|
text={'Designate items brought', NEWLINE, 'to this stockpile for:'},
|
|
|
|
},
|
2023-04-22 20:03:58 -06:00
|
|
|
},
|
2023-04-23 00:13:50 -06:00
|
|
|
visible=function()
|
|
|
|
return self.hovered or self.subviews.melt:getOptionValue() or
|
|
|
|
self.subviews.trade:getOptionValue() or
|
|
|
|
self.subviews.dump:getOptionValue()
|
|
|
|
end,
|
|
|
|
}, widgets.ToggleHotkeyLabel{
|
|
|
|
view_id='melt',
|
|
|
|
frame={t=6, l=2},
|
|
|
|
label='melting',
|
|
|
|
key='CUSTOM_CTRL_M',
|
|
|
|
on_change=self:callback('toggleLogisticsFeature', 'melt'),
|
|
|
|
visible=function()
|
|
|
|
return self.hovered or self.subviews.melt:getOptionValue()
|
|
|
|
end,
|
|
|
|
}, widgets.ToggleHotkeyLabel{
|
|
|
|
view_id='trade',
|
|
|
|
frame={t=7, l=2},
|
|
|
|
label='trading',
|
|
|
|
key='CUSTOM_CTRL_T',
|
|
|
|
on_change=self:callback('toggleLogisticsFeature', 'trade'),
|
|
|
|
visible=function()
|
|
|
|
return self.hovered or self.subviews.trade:getOptionValue()
|
|
|
|
end,
|
|
|
|
}, widgets.ToggleHotkeyLabel{
|
|
|
|
view_id='dump',
|
|
|
|
frame={t=8, l=2},
|
|
|
|
label='dumping',
|
|
|
|
key='CUSTOM_CTRL_D',
|
|
|
|
on_change=self:callback('toggleLogisticsFeature', 'dump'),
|
|
|
|
visible=function()
|
|
|
|
return self.hovered or self.subviews.dump:getOptionValue()
|
|
|
|
end,
|
2023-04-22 20:03:58 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-04-23 20:44:22 -06:00
|
|
|
self:addviews{
|
|
|
|
main_panel,
|
|
|
|
MinimizeButton{
|
|
|
|
frame={t=0, r=1},
|
|
|
|
get_minimized_fn=function() return self.minimized end,
|
|
|
|
on_click=self:callback('toggleMinimized'),
|
2023-04-22 20:03:58 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function StockpilesOverlay:overlay_onupdate()
|
2023-04-23 00:13:50 -06:00
|
|
|
-- periodically pick up changes made from other interfaces
|
2023-04-22 20:03:58 -06:00
|
|
|
self.cur_stockpile = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function StockpilesOverlay:onRenderFrame()
|
|
|
|
local sp = dfhack.gui.getSelectedStockpile()
|
2023-04-23 00:13:50 -06:00
|
|
|
local sp_updated = false
|
2023-04-22 20:03:58 -06:00
|
|
|
if self.cur_stockpile ~= sp then
|
|
|
|
local config = logistics.logistics_getStockpileConfigs(sp.stockpile_number)[1]
|
|
|
|
self.subviews.melt:setOption(config.melt == 1)
|
|
|
|
self.subviews.trade:setOption(config.trade == 1)
|
|
|
|
self.subviews.dump:setOption(config.dump == 1)
|
|
|
|
self.cur_stockpile = sp
|
2023-04-23 00:13:50 -06:00
|
|
|
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
|
2023-04-22 20:03:58 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function StockpilesOverlay:toggleLogisticsFeature(feature)
|
|
|
|
local sp = dfhack.gui.getSelectedStockpile()
|
|
|
|
local config = logistics.logistics_getStockpileConfigs(sp.stockpile_number)[1]
|
|
|
|
-- logical xor
|
|
|
|
logistics.logistics_setStockpileConfig(config.stockpile_number,
|
2023-04-23 00:13:50 -06:00
|
|
|
(feature == 'melt') ~= (config.melt == 1), (feature == 'trade') ~= (config.trade == 1),
|
|
|
|
(feature == 'dump') ~= (config.dump == 1))
|
|
|
|
self.cur_stockpile = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function StockpilesOverlay:toggleMinimized()
|
|
|
|
self.minimized = not self.minimized
|
|
|
|
self.cur_stockpile = nil
|
2023-04-22 20:03:58 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function StockpilesOverlay:onInput(keys)
|
|
|
|
if keys.CUSTOM_ALT_M then
|
2023-04-23 00:13:50 -06:00
|
|
|
self:toggleMinimized()
|
2023-04-22 20:03:58 -06:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
return StockpilesOverlay.super.onInput(self, keys)
|
|
|
|
end
|
|
|
|
|
2023-04-23 00:13:50 -06:00
|
|
|
OVERLAY_WIDGETS = {overlay=StockpilesOverlay}
|
|
|
|
|
2014-12-02 12:00:16 -07:00
|
|
|
return _ENV
|