Skip to content

Commit 6749ada

Browse files
authored
Merge pull request #1446 from ChrisJohnsen/cj/confirm
`confirm` fixes: pausing, Escape from uniform, order-remove descriptions
2 parents 48571b2 + d38c6e0 commit 6749ada

File tree

3 files changed

+91
-30
lines changed

3 files changed

+91
-30
lines changed

changelog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ Template for new versions:
3737
- `deathcause`: added functionality to this script to fetch cause of death programatically
3838

3939
## Fixes
40+
- `confirm`: only show pause option for pausable confirmations
41+
- `confirm`: when editing a uniform, confirm discard of changes when exiting with Escape
42+
- `confirm`: when removing a manager order, show correct order description when using non-100% interface setting
43+
- `confirm`: when removing a manager order, show correct order description after prior order removal or window resize (when scrolled to bottom of order list)
44+
- `confirm`: when removing a manager order, show specific item/job type for ammo, shield, helm, gloves, shoes, trap component, and meal orders
45+
- `confirm`: the pause option now pauses individual confirmation types, allowing multiple different confirmations to be paused independently
4046
- `immortal-cravings`: prioritize high-value meals, properly split of portions, and don't go eating or drinking on a full stomach
4147

4248
## Misc Improvements

confirm.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function ConfirmOverlay:init()
6363
}
6464
end
6565
end
66+
self.paused_confs = {}
6667
end
6768

6869
function ConfirmOverlay:preUpdateLayout()
@@ -77,11 +78,14 @@ function ConfirmOverlay:preUpdateLayout()
7778
end
7879

7980
function ConfirmOverlay:overlay_onupdate()
80-
if self.paused_conf and
81-
not dfhack.gui.matchFocusString(self.paused_conf.context,
81+
for conf in pairs(self.paused_confs) do
82+
if not dfhack.gui.matchFocusString(conf.context,
8283
dfhack.gui.getDFViewscreen(true))
83-
then
84-
self.paused_conf = nil
84+
then
85+
self.paused_confs[conf] = nil
86+
end
87+
end
88+
if not next(self.paused_confs) then
8589
self.overlay_onupdate_max_freq_seconds = 300
8690
end
8791
end
@@ -108,19 +112,22 @@ function ConfirmOverlay:matches_conf(conf, keys, scr)
108112
end
109113

110114
function ConfirmOverlay:onInput(keys)
111-
if self.paused_conf or self.simulating then
115+
if self.simulating then
112116
return false
113117
end
114118
local scr = dfhack.gui.getDFViewscreen(true)
115119
for id, conf in pairs(specs.REGISTRY) do
116120
if specs.config.data[id].enabled and self:matches_conf(conf, keys, scr) then
121+
if self.paused_confs[conf] then
122+
return false
123+
end
117124
local mouse_pos = xy2pos(dfhack.screen.getMousePos())
118125
local propagate_fn = function(pause)
119126
if conf.on_propagate then
120127
conf.on_propagate()
121128
end
122129
if pause then
123-
self.paused_conf = conf
130+
self.paused_confs[conf] = true
124131
self.overlay_onupdate_max_freq_seconds = 0
125132
end
126133
if keys._MOUSE_L then
@@ -131,8 +138,9 @@ function ConfirmOverlay:onInput(keys)
131138
gui.simulateInput(scr, keys)
132139
self.simulating = false
133140
end
141+
local pause_fn = conf.pausable and curry(propagate_fn, true) or nil
134142
dialogs.showYesNoPrompt(conf.title, utils.getval(conf.message):wrap(45), COLOR_YELLOW,
135-
propagate_fn, nil, curry(propagate_fn, true), curry(dfhack.run_script, 'gui/confirm', tostring(conf.id)))
143+
propagate_fn, nil, pause_fn, curry(dfhack.run_script, 'gui/confirm', tostring(conf.id)))
136144
return true
137145
end
138146
end

internal/confirm/specs.lua

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
local json = require('json')
99
local trade_internal = reqscript('internal/caravan/trade')
10+
local gui = require('gui')
1011

1112
local CONFIG_FILE = 'dfhack-config/confirm.json'
1213

@@ -325,13 +326,13 @@ ConfirmSpec{
325326
id='uniform-discard-changes',
326327
title='Discard uniform changes',
327328
message='Are you sure you want to discard changes to this uniform?',
328-
intercept_keys={'_MOUSE_L', '_MOUSE_R'},
329+
intercept_keys={'LEAVESCREEN', '_MOUSE_L', '_MOUSE_R'},
329330
-- sticks out the left side so it can move with the panel
330331
-- when the screen is resized too narrow
331332
intercept_frame={r=32, t=19, w=101, b=3},
332333
context='dwarfmode/Squads/Equipment/Customizing/Default',
333334
predicate=function(keys, mouse_offset)
334-
if keys._MOUSE_R then
335+
if keys.LEAVESCREEN or keys._MOUSE_R then
335336
return uniform_has_changes()
336337
end
337338
if clicked_on_confirm_button(mouse_offset) then
@@ -430,7 +431,7 @@ ConfirmSpec{
430431
end,
431432
}
432433

433-
local function make_order_desc(order, noun)
434+
local function make_order_material_desc(order, noun)
434435
local desc = ''
435436
if order.mat_type >= 0 then
436437
local matinfo = dfhack.matinfo.decode(order.mat_type, order.mat_index)
@@ -451,35 +452,81 @@ end
451452
local orders = df.global.world.manager_orders.all
452453
local itemdefs = df.global.world.raws.itemdefs
453454
local reactions = df.global.world.raws.reactions.reactions
455+
456+
local meal_type_by_ingredient_count = {
457+
[2] = 'easy',
458+
[3] = 'fine',
459+
[4] = 'lavish',
460+
}
461+
462+
local function make_order_desc(order)
463+
if order.job_type == df.job_type.CustomReaction then
464+
for _, reaction in ipairs(reactions) do
465+
if reaction.code == order.reaction_name then
466+
return reaction.name
467+
end
468+
end
469+
return ''
470+
elseif order.job_type == df.job_type.PrepareMeal then
471+
-- DF uses mat_type as ingredient count?
472+
local meal_type = meal_type_by_ingredient_count[order.mat_type]
473+
if meal_type then
474+
return 'prepare ' .. meal_type .. ' meal'
475+
end
476+
return 'prepare meal'
477+
end
478+
local noun
479+
if order.job_type == df.job_type.MakeArmor then
480+
noun = itemdefs.armor[order.item_subtype].name
481+
elseif order.job_type == df.job_type.MakeWeapon then
482+
noun = itemdefs.weapons[order.item_subtype].name
483+
elseif order.job_type == df.job_type.MakeShield then
484+
noun = itemdefs.shields[order.item_subtype].name
485+
elseif order.job_type == df.job_type.MakeAmmo then
486+
noun = itemdefs.ammo[order.item_subtype].name
487+
elseif order.job_type == df.job_type.MakeHelm then
488+
noun = itemdefs.helms[order.item_subtype].name
489+
elseif order.job_type == df.job_type.MakeGloves then
490+
noun = itemdefs.gloves[order.item_subtype].name
491+
elseif order.job_type == df.job_type.MakePants then
492+
noun = itemdefs.pants[order.item_subtype].name
493+
elseif order.job_type == df.job_type.MakeShoes then
494+
noun = itemdefs.shoes[order.item_subtype].name
495+
elseif order.job_type == df.job_type.MakeTool then
496+
noun = itemdefs.tools[order.item_subtype].name
497+
elseif order.job_type == df.job_type.MakeTrapComponent then
498+
noun = itemdefs.trapcomps[order.item_subtype].name
499+
elseif order.job_type == df.job_type.SmeltOre then
500+
noun = 'ore'
501+
else
502+
-- caption is usually "verb noun(-phrase)"
503+
noun = df.job_type.attrs[order.job_type].caption
504+
end
505+
return make_order_material_desc(order, noun)
506+
end
507+
454508
ConfirmSpec{
455509
id='order-remove',
456510
title='Remove manger order',
457511
message=function()
458512
local order_desc = ''
459513
local scroll_pos = mi.info.work_orders.scroll_position_work_orders
460-
local y_offset = dfhack.screen.getWindowSize() > 154 and 8 or 10
514+
local ir = gui.get_interface_rect()
515+
local y_offset = ir.width > 154 and 8 or 10
516+
local order_rows = (ir.height - y_offset - 9) // 3
517+
local max_scroll_pos = math.max(0, #orders - order_rows) -- DF keeps list view "full" (no empty rows at bottom), if possible
518+
if scroll_pos > max_scroll_pos then
519+
-- sometimes, DF does not adjust scroll_position_work_orders (when
520+
-- scrolled to bottom: order removed, or list view height grew);
521+
-- compensate to keep order_idx in sync (and in bounds)
522+
scroll_pos = max_scroll_pos
523+
end
461524
local _, y = dfhack.screen.getMousePos()
462525
if y then
463526
local order_idx = scroll_pos + (y - y_offset) // 3
464-
local order = orders[order_idx]
465-
if order.job_type == df.job_type.CustomReaction then
466-
for _, reaction in ipairs(reactions) do
467-
if reaction.code == order.reaction_name then
468-
order_desc = reaction.name
469-
end
470-
end
471-
elseif order.job_type == df.job_type.MakeArmor then
472-
order_desc = make_order_desc(order, itemdefs.armor[order.item_subtype].name)
473-
elseif order.job_type == df.job_type.MakeWeapon then
474-
order_desc = make_order_desc(order, itemdefs.weapons[order.item_subtype].name)
475-
elseif order.job_type == df.job_type.MakePants then
476-
order_desc = make_order_desc(order, itemdefs.pants[order.item_subtype].name)
477-
elseif order.job_type == df.job_type.SmeltOre then
478-
order_desc = make_order_desc(order, 'ore')
479-
elseif order.job_type == df.job_type.MakeTool then
480-
order_desc = make_order_desc(order, itemdefs.tools[order.item_subtype].name)
481-
else
482-
order_desc = make_order_desc(order, df.job_type.attrs[order.job_type].caption)
527+
local order = safe_index(orders, order_idx)
528+
if order then
529+
order_desc = make_order_desc(order)
483530
end
484531
end
485532
return ('Are you sure you want to remove this manager order?\n\n%s'):format(dfhack.capitalizeStringWords(order_desc))

0 commit comments

Comments
 (0)