Skip to content

Commit

Permalink
add overlay for editing reserved_barrels setting
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Dec 26, 2024
1 parent 6cc1ec3 commit de16c39
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Template for new versions:
- `fix/stuck-squad`: allow squads and messengers returning from missions to rescue squads that have gotten stuck on the world map

## New Features
- `gui/settings-manager`: new overlay on the Labor -> Standing Orders tab for configuring the number of barrels to reserve for job use (so you can brew alcohol and not have all your barrels claimed by stockpiles for container storage)
- `gui/settings-manager`: standing orders save/load now includes the reserved barrels setting

## Fixes

Expand Down
11 changes: 7 additions & 4 deletions docs/gui/settings-manager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ back. You can also toggle an option to automatically load the saved settings
for new embarks.

When a fort is loaded, you can also go to the Labor -> Standing Orders page.
You will see a new panel that allows you to save and restore your settings for
standing orders. You can also toggle whether the saved standing orders are
automatically restored when you embark on a new fort. This will toggle the
relevant command in `gui/control-panel` on the Automation -> Autostart page.
You will see tow new panels. The first allows you to configure how many barrels
to reserve for use by workshop jobs (instead of being claimed by stockpiles for
container storage). The second panel allows you to save and restore your
settings for standing orders. You can also toggle whether the saved standing
orders are automatically restored when you embark on a new fort. This will
toggle the relevant command in `gui/control-panel` on the Automation ->
Autostart page.

There is a similar panel on the Labor -> Work Details page that allows for
saving and restoring of work detail definitions. Be aware that work detail
Expand Down
70 changes: 69 additions & 1 deletion gui/settings-manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

local argparse = require('argparse')
local control_panel = reqscript('control-panel')
local dialogs = require('gui.dialogs')
local gui = require('gui')
local json = require('json')
local overlay = require('plugins.overlay')
Expand Down Expand Up @@ -376,7 +377,9 @@ end
-- StandingOrdersOverlay
--

local li = df.global.plotinfo.labor_info
local plotinfo = df.global.plotinfo
local li = plotinfo.labor_info
local ps = plotinfo.stockpile

local function save_standing_orders()
local standing_orders = {}
Expand All @@ -390,6 +393,7 @@ local function save_standing_orders()
chores.enabled = li.flags.children_do_chores
chores.labors = utils.clone(li.chores)
config.data.chores = chores
config.data.stockpile = {reserved_barrels=ps.reserved_barrels}
config:write()
end

Expand All @@ -401,6 +405,10 @@ local function load_standing_orders()
for i, val in ipairs(safe_index(config.data.chores, 'labors') or {}) do
li.chores[i-1] = val
end
local reserved_barrels = safe_index(config.data.stockpile, 'reserved_barrels')
if reserved_barrels then
ps.reserved_barrels = reserved_barrels
end
end

local function has_saved_standing_orders()
Expand All @@ -422,6 +430,65 @@ StandingOrdersOverlay.ATTRS {
autostart_command='gui/settings-manager load-standing-orders',
}

------------------------------
-- ReservedBarrelsOverlay
--

ReservedBarrelsOverlay = defclass(ReservedBarrelsOverlay, overlay.OverlayWidget)
ReservedBarrelsOverlay.ATTRS {
desc='Exposes the setting for reserved barrels on the standing orders screen.',
default_pos={x=59, y=18},
default_enabled=true,
viewscreens='dwarfmode/Info/LABOR/STANDING_ORDERS/AUTOMATED_WORKSHOPS',
frame={w=26, h=6},
frame_style=gui.MEDIUM_FRAME,
frame_background=gui.CLEAR_PEN,
}

function ReservedBarrelsOverlay:init()
self:addviews{
widgets.Label{
frame={t=0, l=0},
text={
'Barrels reserved for use', NEWLINE,
'by workshop jobs: ',
{
text=function() return ps.reserved_barrels end,
pen=function() return ps.reserved_barrels == 0 and COLOR_YELLOW or COLOR_GREEN end,
},
},
},
widgets.HotkeyLabel{
frame={t=3, l=0},
key='CUSTOM_CTRL_B',
label='Set num reserved',
on_activate=function()
dialogs.InputBox{
frame_title='Set reserved barrels',
text={
'You can ensure a number of barrels are reserved, preventing', NEWLINE,
'them from being claimed by stockpiles as container storage.', NEWLINE,
'For example, if there are 5 reserved barrels, no stockpile', NEWLINE,
'will claim an empty barrel for storing items until you have', NEWLINE,
'at least 6 barrels lying around.', NEWLINE, NEWLINE,
'This feature is most often used to ensure that a fortress has', NEWLINE,
'ample empty barrels for the production of alcohol, although', NEWLINE,
'empty barrels are also necessary for other jobs.',
},
text_pen=COLOR_YELLOW,
label_text='Number of barrels to reserve: ',
input=tostring(ps.reserved_barrels),
on_input=function(input)
input = tonumber(input)
if not input or input < 0 then return end
ps.reserved_barrels = math.floor(input)
end,
}:show()
end,
},
}
end

------------------------------
-- WorkDetailsOverlay
--
Expand Down Expand Up @@ -510,6 +577,7 @@ OVERLAY_WIDGETS = {
embark_notification=DifficultyEmbarkNotificationOverlay,
settings_difficulty=DifficultySettingsOverlay,
standing_orders=StandingOrdersOverlay,
reserved_barrels=ReservedBarrelsOverlay,
work_details=WorkDetailsOverlay,
}

Expand Down

0 comments on commit de16c39

Please sign in to comment.