Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[confirm] use new general dialogs.showYesNoPrompt #1148

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 3 additions & 71 deletions confirm.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--@ module = true

local dialogs = require('gui.dialogs')
local gui = require('gui')
local overlay = require('plugins.overlay')
local specs = reqscript('internal/confirm/specs')
Expand Down Expand Up @@ -27,76 +28,6 @@ end
------------------------
-- Overlay

PromptWindow = defclass(PromptWindow, widgets.Window)
PromptWindow.ATTRS {
frame={w=47, h=13},
conf=DEFAULT_NIL,
propagate_fn=DEFAULT_NIL,
}

function PromptWindow:init()
self:addviews{
widgets.WrappedLabel{
frame={t=0, l=0, r=0},
text_to_wrap=self.conf.message,
},
widgets.HotkeyLabel{
frame={b=2, l=0},
label='Yes, proceed',
key='SELECT',
auto_width=true,
on_activate=self:callback('proceed'),
},
widgets.HotkeyLabel{
frame={b=2, l=32},
label='Settings',
key='CUSTOM_SHIFT_S',
auto_width=true,
on_activate=self:callback('settings'),
},
widgets.HotkeyLabel{
frame={b=0, l=0},
label='Pause confirmations while on this screen',
key='CUSTOM_SHIFT_P',
auto_width=true,
visible=self.conf.pausable,
on_activate=self:callback('pause'),
},
}
end

function PromptWindow:proceed()
self.parent_view:dismiss()
self.propagate_fn()
end

function PromptWindow:settings()
self.parent_view:dismiss()
dfhack.run_script('gui/confirm', self.conf.id)
end

function PromptWindow:pause()
self.parent_view:dismiss()
self.propagate_fn(true)
end

PromptScreen = defclass(PromptScreen, gui.ZScreenModal)
PromptScreen.ATTRS {
focus_path='confirm/prompt',
conf=DEFAULT_NIL,
propagate_fn=DEFAULT_NIL,
}

function PromptScreen:init()
self:addviews{
PromptWindow{
frame_title=self.conf.title,
conf=self.conf,
propagate_fn=self.propagate_fn,
}
}
end

local function get_contexts()
local contexts, contexts_set = {}, {}
for id, conf in pairs(specs.REGISTRY) do
Expand Down Expand Up @@ -198,7 +129,8 @@ function ConfirmOverlay:onInput(keys)
gui.simulateInput(scr, keys)
self.simulating = false
end
PromptScreen{conf=conf, propagate_fn=propagate_fn}:show()
dialogs.showYesNoPrompt(conf.title, conf.message:wrap(45), COLOR_YELLOW,
propagate_fn, nil, curry(propagate_fn, true), curry(dfhack.run_script, 'gui/confirm', tostring(conf.id)))
return true
end
end
Expand Down