forked from kahluamods/kore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKKoreDialogs.lua
334 lines (289 loc) · 8.37 KB
/
KKoreDialogs.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
--[[
KahLua Kore - useful simple dialogs
WWW: http://kahluamod.com/kore
Git: https://github.com/kahluamods/kore
IRC: #KahLua on irc.freenode.net
E-mail: [email protected]
Please refer to the file LICENSE.txt for the Apache License, Version 2.0.
Copyright 2008-2020 James Kean Johnston. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
local K, KM = LibStub:GetLibrary("KKore")
assert(K, "KKoreKonfer requires KKore")
assert(tonumber(KM) >= 4, "KKoreKonfer requires KKore r4 or later")
local KUI, KM = LibStub:GetLibrary("KKoreUI")
assert(KUI, "KKoreKonfer requires KKoreUI")
assert(tonumber(KM) >= 4, "KKoreKonfer requires KKoreUI r4 or later")
local L = LibStub("AceLocale-3.0"):GetLocale("KKore")
-- Local aliases for global or LUA library functions
local _G = _G
local tinsert = table.insert
local tremove = table.remove
local setmetatable = setmetatable
local tconcat = table.concat
local tsort = table.sort
local tostring = tostring
local GetTime = GetTime
local min = math.min
local max = math.max
local strfmt = string.format
local strsub = string.sub
local strlen = string.len
local strfind = string.find
local xpcall, pcall = xpcall, pcall
local pairs, next, type = pairs, next, type
local select, assert, loadstring = select, assert, loadstring
local printf = K.printf
local MakeFrame= KUI.MakeFrame
local ucolor = K.ucolor
local ecolor = K.ecolor
local icolor = K.icolor
function K.ConfirmationDialog(kmod, ttxt, msg, val, func, farg, isshown, height, option)
local height = height or 240
local scd = kmod.confirmdialog
if (not scd) then
local arg = {
x = "CENTER", y = "MIDDLE",
name = "KKoreConfirmDialog",
title = "",
border = true,
width = 450,
height = height,
canmove = true,
canresize = false,
escclose = false,
blackbg = true,
okbutton = { text = K.OK_STR },
cancelbutton = { text = K.CANCEL_STR },
}
local ret = KUI:CreateDialogFrame(arg)
arg = {}
arg = {
x = "CENTER", y = -4, height = 24, autosize = false,
font = "GameFontNormal", text = "",
color = {r = 1, g = 1, b = 1, a = 1 }, border = true,
justifyh = "CENTER",
}
ret.str1 = KUI:CreateStringLabel(arg, ret)
arg = {}
arg = {
x = 8, y = -35, width = 410, height = height - 95 - (option and 24 or 0),
autosize = false,
color = {r = 1, g = 0, b = 0, a = 1 }, text = "",
font = "GameFontNormal", justifyv = "TOP",
}
ret.str2 = KUI:CreateStringLabel(arg, ret)
arg = {}
arg = {
x = "CENTER", y = -height + 85, label = { text = ""},
}
ret.opt = KUI:CreateCheckBox(arg, ret)
ret.optval = false
ret.opt:Catch("OnValueChanged", function(this, evt, val)
ret.optval = val
end)
arg = {}
ret.OnCancel = function(this)
local tcd = this.kmod.confirmdialog
tcd:Hide()
if (tcd.isshown) then
tcd.kmod.mainwin:Show()
end
tcd.isshown = nil
end
ret.OnAccept = function(this)
local tcd = this.kmod.confirmdialog
tcd:Hide()
if (tcd.isshown) then
tcd.kmod.mainwin:Show()
end
tcd.runfunction(tcd.arg, tcd.optval)
tcd.isshown = nil
end
ret.kmod = kmod
kmod.confirmdialog = ret
scd = kmod.confirmdialog
end
scd:SetHeight(height)
scd.str2:SetHeight(height - 95 - (option and 24 or 0))
scd.opt:SetPoint("TOP", confirmdialog, "BOTTOM", 0, 56)
if (option) then
scd.opt:SetText(option)
scd.opt:Show()
scd.optval = false
scd.opt:SetChecked(false)
else
scd.opt:Hide()
end
scd:SetTitleText(ttxt)
scd.str1:SetText(val)
scd.str2:SetText(msg)
scd.runfunction = func
scd.arg = farg
scd.isshown = isshown
scd.kmod.mainwin:Hide()
scd:Show()
end
function K.RenameDialog(kmod, ttxt, oldlbl, oldval, newlbl, len, func, farg, shown)
local srd = kmod.renamedialog
if (not srd) then
local arg = {
x = "CENTER", y = "MIDDLE",
name = "KKoreRenameDialog",
title = "",
border = true,
width = 450,
height = 125,
canmove = true,
canresize = false,
escclose = true,
blackbg = true,
okbutton = { text = K.OK_STR },
cancelbutton = { text = K.CANCEL_STR },
}
local ret = KUI:CreateDialogFrame(arg)
arg = {}
arg = {
x = 0, y = 0, width = 150, height = 24, autosize = false,
justifyh = "RIGHT", font = "GameFontNormal", text = "",
}
ret.str1 = KUI:CreateStringLabel(arg, ret)
arg = {}
arg = {
x = 0, y = 0, width = 200, height = 24, autosize = false,
justifyh = "LEFT", font = "GameFontNormal", text = "",
color = {r = 1, g = 1, b = 1, a = 1 }, border = true,
}
ret.str2 = KUI:CreateStringLabel(arg, ret)
arg = {}
ret.str2:ClearAllPoints()
ret.str2:SetPoint("TOPLEFT", ret.str1, "TOPRIGHT", 8, 0)
arg = {
x = 0, y = -30, width = 150, height = 24, autosize = false,
justifyh = "RIGHT", font = "GameFontNormal", text = "",
}
ret.str3 = KUI:CreateStringLabel(arg, ret)
arg = {}
arg = {
x = 0, y = -30, width = 200, height = 20,
}
ret.input = KUI:CreateEditBox(arg, ret)
ret.input:SetFocus()
arg = {}
ret.input:ClearAllPoints()
ret.input:SetPoint("TOPLEFT", ret.str3, "TOPRIGHT", 12, 0)
ret.OnCancel = function(this)
local trd = this.kmod.renamedialog
trd:Hide()
if (trd.isshown) then
trd.kmod.mainwin:Show()
end
trd.isshown = nil
end
ret.OnAccept = function(this)
local trd = this.kmod.renamedialog
local rv = trd.runfunction(trd.input:GetText(), trd.arg, true)
if (rv) then
trd:Show()
trd.input:SetFocus()
else
trd:Hide()
if (trd.isshown) then
trd.kmod.mainwin:Show()
end
trd.isshown = nil
end
end
ret.input.OnEnterPressed = function(this)
local tp = this:GetParent():GetParent()
tp.OnAccept(tp)
end
ret.kmod = kmod
kmod.renamedialog = ret
srd = kmod.renamedialog
end
srd:SetTitleText(ttxt)
srd.str1:SetText(oldlbl)
srd.str2:SetText(oldval)
srd.str3:SetText(newlbl)
srd.input:SetMaxLetters(len)
srd.runfunction = func
srd.arg = farg
srd.isshown = shown
srd.kmod.mainwin:Hide()
srd:Show()
srd.input:SetText("")
srd.input:SetFocus()
end
function K.PopupSelectionList(kmod, name, list, title, width, height, parent, itemheight, func, topspace, botspace)
if (kmod.popupwindow) then
kmod.popupwindow:Hide()
kmod.popupwindow = nil
end
assert(name)
local arg = {
name = name,
itemheight = itemheight,
width = width,
height = height,
header = topspace,
footer = botspace,
title = title,
titlewidth = width - 110,
canmove = true,
canresize = true,
escclose = true,
blackbg = true,
xbutton = false,
level = 32,
border = "THICK",
x = "CENTER",
y = "MIDDLE",
func = function(lst, idx, arg)
func(lst[idx].value)
end,
timeout = 3,
}
local rv = KUI:CreatePopupList(arg, parent)
assert(rv)
rv.kmod = kmod
rv:UpdateList(list)
rv:Show()
return rv
end
function K.SingleStringInputDialog(kmod, name, title, text, width, height)
local arg = {
x = "CENTER", y = "MIDDLE",
name = name,
title = title,
border = "THICK",
width = width,
height = height,
canmove = true,
canresize = false,
escclose = true,
xbutton = false,
blackbg = true,
okbutton = { text = K.ACCEPTSTR },
cancelbutton = { text = K.CANCELSTR },
}
local ret = KUI:CreateDialogFrame(arg)
assert(ret)
ret.kmod = kmod
arg = {
x = 8, y = 0, width = width - 40, height = height - 90, autosize = false,
font = "GameFontNormal", text = text, }
ret.str1 = KUI:CreateStringLabel(arg, ret)
arg = { x = "CENTER", y = -(height - 85), len = 32 }
ret.ebox = KUI:CreateEditBox(arg, ret)
ret.ebox:SetFocus()
return ret, ret.ebox
end