diff --git a/confirm.lua b/confirm.lua index 7701ac35e6..7397d3759d 100644 --- a/confirm.lua +++ b/confirm.lua @@ -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') @@ -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 @@ -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