-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirm.lua
84 lines (81 loc) · 2.96 KB
/
confirm.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
if not ItemTrig then return end
local Cls = ItemTrig.UI.WSingletonWindow:makeSubclass("Confirm")
ItemTrig:registerWindow("genericConfirm", Cls)
local FRAMES_NEEDED_FOR_THE_RESIZE_TO_BLOODY_WORK = 2
--
-- If we're resizing down (i.e. we showed a long prompt and now we need to
-- show a short one), then resizing on the first possible frame actually
-- makes us slightly too small; seems the getters for text height are busted.
function Cls:_construct()
self.result = nil
self.text = self:controlByPath("Body", "Text")
self.buttonYes = self:controlByPath("Buttons", "Y")
self.buttonNo = self:controlByPath("Buttons", "N")
do -- Set up onAfterShow
--
-- We need to be able to resize the confirmation dialog to fit all of
-- its text, but we can only do that on the frame after it is shown.
--
self._fireAfterShow = false
ZO_PreHookHandler(self:asControl(), "OnUpdate",
function(self)
local window = Cls:getInstance()
if window and window._fireAfterShow > 0 then
if not window:asControl():IsHidden() then
window._fireAfterShow = window._fireAfterShow - 1
window:onAfterShow()
end
end
end
)
end
--
local control = self:asControl()
local fragment = ZO_SimpleSceneFragment:New(control)
ItemTrig.SCENE_TRIGEDIT:AddFragment(fragment)
SCENE_MANAGER:RegisterTopLevel(control, false)
end
function Cls:getDefaultOptions()
return {
centerIfModal = true,
modalOnly = true,
}
end
function Cls:handleModalDeferredOnHide(deferred)
if self.result then
deferred:resolve()
else
deferred:reject()
end
end
function Cls:onBeforeShow(options)
assert(options ~= nil, "You must specify options for this modal in the form of a table, passed to showModal, containing at minimum a 'text' key.")
assert(options.text ~= nil, "You must specify the text for this modal.")
self:setTitle(options.title or GetString(ITEMTRIG_STRING_UI_GENERIC_CONFIRM_TITLE))
self.text:SetText(options.text)
self.buttonYes:SetText(options.yesText or GetString(ITEMTRIG_STRING_UI_GENERIC_CONFIRM_YES))
self.buttonNo:SetText( options.noText or GetString(ITEMTRIG_STRING_UI_GENERIC_CONFIRM_NO))
if options.showCloseButton == nil then
options.showCloseButton = true
end
self:shouldShowCloseButton(options.showCloseButton)
self.result = nil
self._fireAfterShow = FRAMES_NEEDED_FOR_THE_RESIZE_TO_BLOODY_WORK
return true
end
function Cls:onAfterShow()
local control = self:asControl()
do -- height
local height = self.text:GetTextHeight()
local avail = self.text:GetParent():GetHeight()
control:SetHeight(control:GetHeight() - avail + height + 30)
end
end
function Cls:yes()
self.result = true
self:hide()
end
function Cls:no()
self.result = false
self:hide()
end