Skip to content

Commit

Permalink
implement conviction confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jan 4, 2024
1 parent 2b6a311 commit 3fba976
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
2 changes: 1 addition & 1 deletion confirm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function ConfirmOverlay:matches_conf(conf, keys, scr)
end
if not matched_keys then return false end
local mouse_offset
if conf.intercept_frame then
if keys._MOUSE_L and conf.intercept_frame then
local mousex, mousey = self.subviews[conf.id]:getMouseFramePos()
if not mousex then
return false
Expand Down
2 changes: 1 addition & 1 deletion gui/confirm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local widgets = require('gui.widgets')
Confirm = defclass(Confirm, widgets.Window)
Confirm.ATTRS{
frame_title='Confirmation dialogs',
frame={w=37, h=17},
frame={w=42, h=17},
initial_id=DEFAULT_NIL,
}

Expand Down
63 changes: 42 additions & 21 deletions internal/confirm/specs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ ConfirmSpec{
ConfirmSpec{
id='uniform-delete',
title='Delete uniform',
message="Are you sure you want to delete this uniform?",
message='Are you sure you want to delete this uniform?',
intercept_keys='_MOUSE_L',
intercept_frame={r=131, t=23, w=6, h=27},
context='dwarfmode/AssignUniform',
Expand All @@ -253,6 +253,44 @@ ConfirmSpec{
pausable=true,
}

local selected_convict_name = 'this creature'
ConfirmSpec{
id='convict',
title='Confirm conviction',
message=function()
return ('Are you sure you want to convict %s? This action is irreversible.'):format(selected_convict_name)
end,
intercept_keys='_MOUSE_L',
intercept_frame={r=31, t=14, w=11, b=5},
debug_frame=true,
context='dwarfmode/Info/JUSTICE/Convicting',
predicate=function(mouse_offset)
local justice = mi.info.justice
local num_choices = #justice.conviction_list
if num_choices == 0 then return false end
local sw, sh = dfhack.screen.getWindowSize()
local y_offset = sw >= 155 and 0 or 4
local max_visible_buttons = (sh - (19 + y_offset)) // 3
-- adjust detection area depending on presence of scrollbar
if num_choices > max_visible_buttons and mouse_offset.x > 9 then
return false
elseif num_choices <= max_visible_buttons and mouse_offset.x <= 1 then
return false
end
local num_visible_buttons = math.min(num_choices, max_visible_buttons)
local selected_button_offset = (mouse_offset.y - y_offset) // 3
if selected_button_offset >= num_visible_buttons then
return false
end
local unit = justice.conviction_list[selected_button_offset + justice.scroll_position_conviction]
selected_convict_name = dfhack.TranslateName(dfhack.units.getVisibleName(unit))
if selected_convict_name == '' then
selected_convict_name = 'this creature'
end
return true
end,
}

ConfirmSpec{
id='order-remove',
title='Remove manger order',
Expand Down Expand Up @@ -295,26 +333,9 @@ ConfirmSpec{
pausable=true,
}

-- these confirmations have more complex button detection requirements
--[[
convict = defconf('convict')
convict.title = "Confirm conviction"
function convict.intercept_key(key)
return key == keys.SELECT and
screen.cur_column == df.viewscreen_justicest.T_cur_column.ConvictChoices
end
function convict.get_message()
name = dfhack.TranslateName(dfhack.units.getVisibleName(screen.convict_choices[screen.cursor_right]))
if name == "" then
name = "this creature"
end
return "Are you sure you want to convict " .. name .. "?\n" ..
"This action is irreversible."
end
]]--
--------------------------
-- Config file management
--

local function get_config()
local f = json.open(CONFIG_FILE)
Expand Down

0 comments on commit 3fba976

Please sign in to comment.