-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickInputMenu.lua
More file actions
104 lines (77 loc) · 2.11 KB
/
QuickInputMenu.lua
File metadata and controls
104 lines (77 loc) · 2.11 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
QuickInputMenu = QuickInputMenu or class()
QuickInputMenu._menu_id_key = "quick_input_menu_id_"
QuickInputMenu._menu_id_index = 0
function QuickInputMenu:new( ... )
return self:init( ... )
end
function QuickInputMenu:init( title, text, user_text, options, show_immediately, config )
QuickInputMenu._menu_id_index = QuickInputMenu._menu_id_index + 1
self.dialog_data = {
id = QuickInputMenu._menu_id_key .. tostring( QuickInputMenu._menu_id_index ),
title = title,
text = text,
user_text = user_text or "",
button_list = {},
}
if config then
for k, v in pairs(config) do
self.dialog_data[k] = self.dialog_data[k] or v
end
end
self.visible = false
local add_default = false
if (not options) or (options ~= nil and type(options) ~= "table") or (options ~= nil and type(options) == "table" and #options == 0) then
add_default = true
end
if add_default then
local tbl = {
text = "OK",
is_cancel_button = true,
}
table.insert( options, tbl )
end
for _, option in ipairs( options ) do
option.data = option.data
option.callback = option.callback
local button = {}
local callback_data = {
data = option.data,
callback = option.callback
}
button.text = option.text
button.callback_func = callback( self, self, "_callback", callback_data )
button.cancel_button = option.is_cancel_button or false
if option.is_focused_button then
self.dialog_data.focus_button = #self.dialog_data.button_list + 1
end
table.insert( self.dialog_data.button_list, button )
end
if show_immediately then
self:show()
end
return self
end
function QuickInputMenu:_callback( callback_data, ... )
if callback_data.callback then
callback_data.callback( callback_data.data, ... )
end
self.visible = false
end
function QuickInputMenu:Show()
if not self.visible then
self.visible = true
managers.system_menu:show_input( self.dialog_data )
end
end
function QuickInputMenu:show()
self:Show()
end
function QuickInputMenu:Hide()
if self.visible then
managers.system_menu:close( self.dialog_data.id )
self.visible = false
end
end
function QuickInputMenu:hide()
self:Hide()
end