Skip to content

Commit 304fc9f

Browse files
authored
Merge pull request DFHack#1013 from DFHack/revert-1012-revert-993-myk_confirm
Revert "Revert "[confirm] update conviction confirmation for 50.12""
2 parents f2fcb87 + 703d59f commit 304fc9f

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

internal/confirm/specs.lua

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -387,28 +387,29 @@ ConfirmSpec{
387387
message=function()
388388
return ('Are you sure you want to convict %s? This action is irreversible.'):format(selected_convict_name)
389389
end,
390-
intercept_keys='_MOUSE_L',
391-
intercept_frame={r=31, t=14, w=11, b=5},
390+
intercept_keys={'_MOUSE_L', 'SELECT'},
392391
context='dwarfmode/Info/JUSTICE/Convicting',
393-
predicate=function(_, mouse_offset)
394-
local justice = mi.info.justice
395-
local num_choices = #justice.conviction_list
396-
if num_choices == 0 then return false end
397-
local sw, sh = dfhack.screen.getWindowSize()
398-
local y_offset = sw >= 155 and 0 or 4
399-
local max_visible_buttons = (sh - (19 + y_offset)) // 3
400-
-- adjust detection area depending on presence of scrollbar
401-
if num_choices > max_visible_buttons and mouse_offset.x > 9 then
402-
return false
403-
elseif num_choices <= max_visible_buttons and mouse_offset.x <= 1 then
404-
return false
405-
end
406-
local num_visible_buttons = math.min(num_choices, max_visible_buttons)
407-
local selected_button_offset = (mouse_offset.y - y_offset) // 3
408-
if selected_button_offset >= num_visible_buttons then
409-
return false
392+
predicate=function(keys)
393+
local convict = dfhack.gui.getWidget(mi.info.justice, 'Tabs', 'Open cases', 'Right panel', 'Convict')
394+
local scroll_rows = dfhack.gui.getWidget(convict, 'Unit List', 1)
395+
local selected_pos
396+
if keys.SELECT then
397+
selected_pos = convict.cursor_idx
398+
else
399+
local visible_rows = scroll_rows.num_visible
400+
if visible_rows == 0 then return false end
401+
local scroll_pos = scroll_rows.scroll
402+
local first_portrait_rect = dfhack.gui.getWidget(scroll_rows, scroll_pos, 0).rect
403+
local last_name_rect = dfhack.gui.getWidget(scroll_rows, scroll_pos+visible_rows-1, 1).rect
404+
local x, y = dfhack.screen.getMousePos()
405+
if x < first_portrait_rect.x1 or x > last_name_rect.x2 or
406+
y < first_portrait_rect.y1 or y >= first_portrait_rect.y1+3*visible_rows
407+
then
408+
return false
409+
end
410+
selected_pos = scroll_pos + (y - first_portrait_rect.y1) // 3
410411
end
411-
local unit = justice.conviction_list[selected_button_offset + justice.scroll_position_conviction]
412+
local unit = dfhack.gui.getWidget(scroll_rows, selected_pos, 0).u
412413
selected_convict_name = dfhack.TranslateName(dfhack.units.getVisibleName(unit))
413414
if selected_convict_name == '' then
414415
selected_convict_name = 'this creature'

0 commit comments

Comments
 (0)