Skip to content

Commit fdd0c91

Browse files
authored
Merge pull request #1355 from myk002/myk_reserved_barrels
[gui/settings-manager] add overlay for editing reserved_barrels setting
2 parents 6cc1ec3 + de16c39 commit fdd0c91

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Template for new versions:
3030
- `fix/stuck-squad`: allow squads and messengers returning from missions to rescue squads that have gotten stuck on the world map
3131

3232
## New Features
33+
- `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)
34+
- `gui/settings-manager`: standing orders save/load now includes the reserved barrels setting
3335

3436
## Fixes
3537

docs/gui/settings-manager.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ back. You can also toggle an option to automatically load the saved settings
3939
for new embarks.
4040

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

4750
There is a similar panel on the Labor -> Work Details page that allows for
4851
saving and restoring of work detail definitions. Be aware that work detail

gui/settings-manager.lua

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
local argparse = require('argparse')
44
local control_panel = reqscript('control-panel')
5+
local dialogs = require('gui.dialogs')
56
local gui = require('gui')
67
local json = require('json')
78
local overlay = require('plugins.overlay')
@@ -376,7 +377,9 @@ end
376377
-- StandingOrdersOverlay
377378
--
378379

379-
local li = df.global.plotinfo.labor_info
380+
local plotinfo = df.global.plotinfo
381+
local li = plotinfo.labor_info
382+
local ps = plotinfo.stockpile
380383

381384
local function save_standing_orders()
382385
local standing_orders = {}
@@ -390,6 +393,7 @@ local function save_standing_orders()
390393
chores.enabled = li.flags.children_do_chores
391394
chores.labors = utils.clone(li.chores)
392395
config.data.chores = chores
396+
config.data.stockpile = {reserved_barrels=ps.reserved_barrels}
393397
config:write()
394398
end
395399

@@ -401,6 +405,10 @@ local function load_standing_orders()
401405
for i, val in ipairs(safe_index(config.data.chores, 'labors') or {}) do
402406
li.chores[i-1] = val
403407
end
408+
local reserved_barrels = safe_index(config.data.stockpile, 'reserved_barrels')
409+
if reserved_barrels then
410+
ps.reserved_barrels = reserved_barrels
411+
end
404412
end
405413

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

433+
------------------------------
434+
-- ReservedBarrelsOverlay
435+
--
436+
437+
ReservedBarrelsOverlay = defclass(ReservedBarrelsOverlay, overlay.OverlayWidget)
438+
ReservedBarrelsOverlay.ATTRS {
439+
desc='Exposes the setting for reserved barrels on the standing orders screen.',
440+
default_pos={x=59, y=18},
441+
default_enabled=true,
442+
viewscreens='dwarfmode/Info/LABOR/STANDING_ORDERS/AUTOMATED_WORKSHOPS',
443+
frame={w=26, h=6},
444+
frame_style=gui.MEDIUM_FRAME,
445+
frame_background=gui.CLEAR_PEN,
446+
}
447+
448+
function ReservedBarrelsOverlay:init()
449+
self:addviews{
450+
widgets.Label{
451+
frame={t=0, l=0},
452+
text={
453+
'Barrels reserved for use', NEWLINE,
454+
'by workshop jobs: ',
455+
{
456+
text=function() return ps.reserved_barrels end,
457+
pen=function() return ps.reserved_barrels == 0 and COLOR_YELLOW or COLOR_GREEN end,
458+
},
459+
},
460+
},
461+
widgets.HotkeyLabel{
462+
frame={t=3, l=0},
463+
key='CUSTOM_CTRL_B',
464+
label='Set num reserved',
465+
on_activate=function()
466+
dialogs.InputBox{
467+
frame_title='Set reserved barrels',
468+
text={
469+
'You can ensure a number of barrels are reserved, preventing', NEWLINE,
470+
'them from being claimed by stockpiles as container storage.', NEWLINE,
471+
'For example, if there are 5 reserved barrels, no stockpile', NEWLINE,
472+
'will claim an empty barrel for storing items until you have', NEWLINE,
473+
'at least 6 barrels lying around.', NEWLINE, NEWLINE,
474+
'This feature is most often used to ensure that a fortress has', NEWLINE,
475+
'ample empty barrels for the production of alcohol, although', NEWLINE,
476+
'empty barrels are also necessary for other jobs.',
477+
},
478+
text_pen=COLOR_YELLOW,
479+
label_text='Number of barrels to reserve: ',
480+
input=tostring(ps.reserved_barrels),
481+
on_input=function(input)
482+
input = tonumber(input)
483+
if not input or input < 0 then return end
484+
ps.reserved_barrels = math.floor(input)
485+
end,
486+
}:show()
487+
end,
488+
},
489+
}
490+
end
491+
425492
------------------------------
426493
-- WorkDetailsOverlay
427494
--
@@ -510,6 +577,7 @@ OVERLAY_WIDGETS = {
510577
embark_notification=DifficultyEmbarkNotificationOverlay,
511578
settings_difficulty=DifficultySettingsOverlay,
512579
standing_orders=StandingOrdersOverlay,
580+
reserved_barrels=ReservedBarrelsOverlay,
513581
work_details=WorkDetailsOverlay,
514582
}
515583

0 commit comments

Comments
 (0)