-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGUI.lua
823 lines (781 loc) · 23.6 KB
/
GUI.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
local addonName, addonTable = ...
local GUI = {}
local LibDD = LibStub:GetLibrary("LibUIDropDownMenu-4.0")
GUI.widgetCount = 0
function GUI:GenerateWidgetName ()
self.widgetCount = self.widgetCount + 1
return addonName .. "Widget" .. self.widgetCount
end
GUI.defaultParent = nil
function GUI:ClearEditFocus()
LibDD:CloseDropDownMenus()
for _,v in ipairs(self.editBoxes) do
v:ClearFocus()
end
end
function GUI:ClearFocus()
LibDD:CloseDropDownMenus()
self:ClearEditFocus()
end
function GUI:Lock()
for _, frames in ipairs({self.panelButtons, self.imgButtons, self.editBoxes, self.checkButtons}) do
for _, frame in pairs(frames) do
if frame:IsEnabled() then
frame.locked = true
frame:Disable()
if frame:IsMouseEnabled() then
frame:EnableMouse(false)
frame.mouseDisabled = true
elseif frame:IsMouseMotionEnabled() then
frame:SetMouseMotionEnabled(false)
frame.mouseMotionDisabled = true
end
if frame.SetTextColor then
frame.prevColor = {frame:GetTextColor()}
frame:SetTextColor (0.5, 0.5, 0.5)
end
end
end
end
for _, dropdown in pairs(self.dropdowns) do
if not dropdown.isDisabled then
dropdown:DisableDropdown()
dropdown.locked = true
end
end
end
function GUI:Unlock()
for _, frames in ipairs({self.panelButtons, self.imgButtons, self.editBoxes, self.checkButtons}) do
for _, frame in pairs(frames) do
if frame.locked then
frame:Enable()
frame.locked = nil
if frame.mouseDisabled then
frame:EnableMouse(true)
frame.mouseDisabled = nil
elseif frame.mouseMotionDisabled then
frame:SetMouseMotionEnabled(true)
frame.mouseMotionDisabled = nil
end
if frame.prevColor then
frame:SetTextColor (unpack(frame.prevColor))
frame.prevColor = nil
end
end
end
end
for _, dropdown in pairs(self.dropdowns) do
if dropdown.locked then
dropdown:EnableDropdown()
dropdown.locked = nil
end
end
end
function GUI:SetTooltip (widget, tip)
if tip then
widget:SetScript ("OnEnter", function (tipFrame)
local tooltipFunc = "SetText"
local tipText
if type(tip) == "function" then
tipText = tip()
else
tipText = tip
end
if type(tipText) == "table" then
if tipText.spellID ~= nil then
tooltipFunc = "SetSpellByID"
tipText = tipText.spellID
end
end
if tipText then
GameTooltip:SetOwner(tipFrame, "ANCHOR_LEFT")
GameTooltip[tooltipFunc](GameTooltip, tipText)
GameTooltip:Show()
end
end)
widget:SetScript ("OnLeave", function (tipFrame)
if GameTooltip:GetOwner() == tipFrame then
GameTooltip:Hide()
end
end)
else
widget:SetScript ("OnEnter", nil)
widget:SetScript ("OnLeave", nil)
end
end
GUI.editBoxes = {}
GUI.unusedEditBoxes = {}
function GUI:CreateEditBox (parent, width, height, default, setter)
local box
if #self.unusedEditBoxes > 0 then
box = tremove (self.unusedEditBoxes, 1)
box:SetParent (parent)
box:Show ()
box:SetTextColor (1, 1, 1)
box:EnableMouse (true)
self.editBoxes[box:GetName()] = box
else
box = CreateFrame ("EditBox", self:GenerateWidgetName (), parent, "InputBoxTemplate")
self.editBoxes[box:GetName()] = box
box:SetAutoFocus (false)
box:SetFontObject (ChatFontNormal)
box:SetNumeric ()
box:SetTextInsets (0, 0, 3, 3)
box:SetMaxLetters (8)
box:SetScript ("OnEnterPressed", box.ClearFocus)
box:SetScript ("OnEditFocusGained", function(frame)
LibDD:CloseDropDownMenus()
frame.prevValue = tonumber(frame:GetText())
frame:HighlightText()
end)
box.Recycle = function (box)
box:Hide ()
box:SetScript ("OnEditFocusLost", nil)
box:SetScript ("OnEnter", nil)
box:SetScript ("OnLeave", nil)
self.editBoxes[box:GetName()] = nil
tinsert (self.unusedEditBoxes, box)
end
end
if width then
box:SetWidth (width)
end
if height then
box:SetHeight (height)
end
box:SetText (default)
box:SetScript ("OnEditFocusLost", function (frame)
local value = tonumber(frame:GetText())
if not value then
value = frame.prevValue or 0
end
frame:SetText (value)
if setter then
setter (value)
end
frame.prevValue = nil
end)
return box
end
GUI.dropdowns = {}
GUI.unusedDropdowns = {}
function GUI:CreateDropdown (parent, values, options)
local sel
if #self.unusedDropdowns > 0 then
sel = tremove (self.unusedDropdowns, 1)
sel:SetParent (parent)
sel:Show ()
self.dropdowns[sel:GetName()] = sel
else
sel = LibDD:Create_UIDropDownMenu(self:GenerateWidgetName(), parent)
self.dropdowns[sel:GetName()] = sel
LibDD:UIDropDownMenu_SetInitializeFunction(sel, function (dropdown)
self:ClearEditFocus()
for _, value in ipairs(dropdown.values) do
local info = LibDD:UIDropDownMenu_CreateInfo()
info.text = value.name
info.value = value.value
info.checked = (dropdown.value == value.value)
info.category = value.category
info.func = function (inf)
LibDD:UIDropDownMenu_SetSelectedValue (dropdown, inf.value)
if dropdown.setter then dropdown.setter (dropdown,inf.value) end
dropdown.value = inf.value
end
if dropdown.menuItemDisabled then
info.disabled = dropdown.menuItemDisabled(info.value)
end
if not dropdown.menuItemHidden or not dropdown.menuItemHidden(info) then
LibDD:UIDropDownMenu_AddButton(info)
end
end
end)
sel.SetValue = function (dropdown, value)
dropdown.value = value
dropdown.selectedValue = value
for i = 1, #dropdown.values do
if dropdown.values[i].value == value then
LibDD:UIDropDownMenu_SetText (dropdown, dropdown.values[i].name)
return
end
end
LibDD:UIDropDownMenu_SetText (dropdown, "")
end
sel.EnableDropdown = function(dropdown)
LibDD:UIDropDownMenu_EnableDropDown (dropdown)
end
sel.DisableDropdown = function(dropdown)
LibDD:UIDropDownMenu_DisableDropDown (dropdown)
end
LibDD:UIDropDownMenu_JustifyText (sel, "LEFT")
sel:SetHeight (50)
sel.Left:SetHeight(50)
sel.Middle:SetHeight(50)
sel.Right:SetHeight(50)
sel.Text:SetPoint ("LEFT", sel.Left, "LEFT", 27, 1)
sel.Button:SetSize(22, 22)
sel.Button:SetPoint ("TOPRIGHT", sel.Right, "TOPRIGHT", -16, -13)
sel.Recycle = function (frame)
frame:Hide ()
frame:SetScript ("OnEnter", nil)
frame:SetScript ("OnLeave", nil)
frame.setter = nil
frame.value = nil
frame.selectedName = nil
frame.selectedID = nil
frame.selectedValue = nil
frame.menuItemDisabled = nil
frame.menuItemHidden = nil
self.dropdowns[frame:GetName()] = nil
tinsert(self.unusedDropdowns, frame)
end
end
sel.values = values
sel.setter = options.setter
sel.menuItemDisabled = options.menuItemDisabled
sel.menuItemHidden = options.menuItemHidden
LibDD:UIDropDownMenu_Initialize (sel, sel.Initialize)
sel:SetValue (options.default)
if options.width then
LibDD:UIDropDownMenu_SetWidth (sel, options.width)
end
return sel
end
GUI.checkButtons = {}
GUI.unusedCheckButtons = {}
function GUI:CreateCheckButton (parent, text, default, setter, forceNew)
local btn
if #self.unusedCheckButtons > 0 and not forceNew then
btn = tremove (self.unusedCheckButtons, 1)
btn:SetParent (parent)
btn:Show ()
self.checkButtons[btn:GetName()] = btn
else
local name = self:GenerateWidgetName ()
btn = CreateFrame ("CheckButton", name, parent, "UICheckButtonTemplate")
self.checkButtons[btn:GetName()] = btn
btn.Recycle = function (btn)
btn:Hide ()
btn:SetScript ("OnEnter", nil)
btn:SetScript ("OnLeave", nil)
btn:SetScript ("OnClick", nil)
self.checkButtons[btn:GetName()] = nil
tinsert (self.unusedCheckButtons, btn)
end
end
btn.Text:SetText(text)
btn:SetChecked (default)
if setter then
btn:SetScript ("OnClick", function (self)
setter (self:GetChecked ())
end)
end
return btn
end
GUI.imgButtons = {}
GUI.unusedImgButtons = {}
function GUI:CreateImageButton (parent, width, height, img, pus, hlt, disabledTexture, handler)
local btn
if #self.unusedImgButtons > 0 then
btn = tremove (self.unusedImgButtons, 1)
btn:SetParent (parent)
btn:Show ()
else
local name = self:GenerateWidgetName ()
btn = CreateFrame ("Button", name, parent)
self.imgButtons[btn:GetName()] = btn
btn.Recycle = function (f)
f:Hide ()
f:SetScript ("OnEnter", nil)
f:SetScript ("OnLeave", nil)
f:SetScript ("OnClick", nil)
self.imgButtons[f:GetName()] = nil
tinsert (self.unusedImgButtons, f)
end
end
btn:SetNormalTexture (img)
btn:SetPushedTexture (pus)
btn:SetHighlightTexture (hlt or img)
btn:SetDisabledTexture(disabledTexture or img)
btn:SetSize(width, height)
if handler then
btn:SetScript ("OnClick", handler)
end
return btn
end
GUI.panelButtons = {}
GUI.unusedPanelButtons = {}
function GUI:CreatePanelButton(parent, text, handler)
local btn
if #self.unusedPanelButtons > 0 then
btn = tremove(self.unusedPanelButtons, 1)
btn:SetParent(parent)
btn:Show()
self.panelButtons[btn:GetName()] = btn
else
local name = self:GenerateWidgetName ()
btn = CreateFrame("Button", name, parent, "UIPanelButtonTemplate")
self.panelButtons[btn:GetName()] = btn
btn.Recycle = function (f)
f:SetText("")
f:Hide ()
f:SetScript ("OnEnter", nil)
f:SetScript ("OnLeave", nil)
f:SetScript ("OnPreClick", nil)
f:SetScript ("OnClick", nil)
self.panelButtons[btn:GetName()] = nil
tinsert (self.unusedPanelButtons, f)
end
btn.RenderText = function(f, ...)
f:SetText(...)
f:FitToText()
end
end
btn:RenderText(text)
btn:SetScript("OnClick", handler)
return btn
end
function GUI:CreateColorPicker (parent, width, height, color, handler)
local box = CreateFrame ("Frame", nil, parent)
box:SetSize(width, height)
box:EnableMouse (true)
box.texture = box:CreateTexture (nil, "OVERLAY")
box.texture:SetAllPoints ()
box.texture:SetColorTexture (unpack (color))
box.glow = box:CreateTexture (nil, "BACKGROUND")
box.glow:SetPoint ("TOPLEFT", -2, 2)
box.glow:SetPoint ("BOTTOMRIGHT", 2, -2)
box.glow:SetColorTexture (1, 1, 1, 0.3)
box.glow:Hide ()
box:SetScript ("OnEnter", function (b) b.glow:Show() end)
box:SetScript ("OnLeave", function (b) b.glow:Hide() end)
box:SetScript ("OnMouseDown", function (b)
local function applyColor(func)
return function()
local prevR, prevG, prevB = func(ColorPickerFrame)
color[1], color[2], color[3] = prevR, prevG, prevB
b.texture:SetColorTexture(prevR, prevG, prevB)
if handler then
handler()
end
end
end
ColorPickerFrame:SetupColorPickerAndShow({
r = color[1], g = color[2], b = color[3],
swatchFunc = applyColor(ColorPickerFrame.GetColorRGB),
cancelFunc = applyColor(ColorPickerFrame.GetPreviousValues),
})
end)
return box
end
-------------------------------------------------------------------------------
function GUI:CreateHLine (x1, x2, y, w, color, parent)
parent = parent or self.defaultParent
local line = parent:CreateTexture (nil, "ARTWORK")
line:SetDrawLayer ("ARTWORK")
line:SetColorTexture (unpack(color))
if x1 > x2 then
x1, x2 = x2, x1
end
line:ClearAllPoints ()
line:SetTexCoord (0, 0, 0, 1, 1, 0, 1, 1)
line.width = w
line:SetPoint ("BOTTOMLEFT", parent, "TOPLEFT", x1, y - w / 2)
line:SetPoint ("TOPRIGHT", parent, "TOPLEFT", x2, y + w / 2)
line:Show ()
line.SetPos = function (self, x1, x2, y)
if x1 > x2 then
x1, x2 = x2, x1
end
self:ClearAllPoints ()
self:SetPoint ("BOTTOMLEFT", parent, "TOPLEFT", x1, y - self.width / 2)
self:SetPoint ("TOPRIGHT", parent, "TOPLEFT", x2, y + self.width / 2)
end
return line
end
function GUI:CreateVLine (x, y1, y2, w, color, parent)
parent = parent or self.defaultParent
local line = parent:CreateTexture (nil, "ARTWORK")
line:SetDrawLayer ("ARTWORK")
line:SetColorTexture (unpack(color))
if y1 > y2 then
y1, y2 = y2, y1
end
line:ClearAllPoints ()
line:SetTexCoord (1, 0, 0, 0, 1, 1, 0, 1)
line.width = w
line:SetPoint ("BOTTOMLEFT", parent, "TOPLEFT", x - w / 2, y1)
line:SetPoint ("TOPRIGHT", parent, "TOPLEFT", x + w / 2, y2)
line:Show ()
line.SetPos = function (self, x, y1, y2)
if y1 > y2 then
y1, y2 = y2, y1
end
self:ClearAllPoints ()
self:SetPoint ("BOTTOMLEFT", parent, "TOPLEFT", x - self.width / 2, y1)
self:SetPoint ("TOPRIGHT", parent, "TOPLEFT", x + self.width / 2, y2)
end
return line
end
--------------------------------------------------------------------------------
function GUI:CreateTable (rows, cols, firstRow, firstColumn, gridColor, parent)
parent = parent or self.defaultParent
firstRow = firstRow or 0
firstColumn = firstColumn or 0
local t = CreateFrame ("Frame", nil, parent)
t:ClearAllPoints ()
t:SetSize(400, 400)
t:SetPoint ("TOPLEFT")
t.rows = rows
t.cols = cols
t.gridColor = gridColor
t.rowPos = {}
t.colPos = {}
t.rowHeight = {}
t.colWidth = {}
t.rowPos[-1] = 0
t.rowPos[0] = firstRow
t.colPos[-1] = 0
t.colPos[0] = firstColumn
t.rowHeight[0] = firstRow
t.colWidth[0] = firstColumn
t.SetRowHeight = function (self, n, h)
if h then
if n < 0 or n > self.rows then
return
end
self.rowHeight[n] = h
if n == 0 and self.hlines then
if h == 0 then
self.hlines[-1]:Hide ()
else
self.hlines[-1]:Show ()
end
end
else
for i = 1, self.rows do
self.rowHeight[i] = n
end
end
self:OnUpdateFix ()
end
t.SetColumnWidth = function (self, n, w)
if w then
if n < 0 or n > self.cols then
return
end
self.colWidth[n] = w
if n == 0 and self.vlines then
if w == 0 then
self.vlines[-1]:Hide ()
else
self.vlines[-1]:Show ()
end
end
else
for i = 1, self.cols do
self.colWidth[i] = n
end
end
self:OnUpdateFix ()
end
t.AddRow = function (self, i, n)
i = i or (self.rows + 1)
n = n or 1
local height = ((i == self.rows + 1) and self.rowHeight[i - 1] or self.rowHeight[i])
for r = self.rows, i, -1 do
self.cells[r + n] = self.cells[r]
self.rowHeight[r + n] = self.rowHeight[r]
end
for r = i, i + n - 1 do
self.cells[r] = {}
self.rowHeight[r] = height
self.rows = self.rows + 1
if self.gridColor then
if self.hlines[self.rows] then
self.hlines[self.rows]:Show ()
else
self.hlines[self.rows] = GUI:CreateHLine (0, 0, 0, 1.5, self.gridColor, self)
end
end
end
self:OnUpdateFix ()
end
t.MoveRow = function (self, i, to)
local height = self.row[i] - self.rowPos[i - 1]
local cells = self.cells[i]
if to > i then
for r = i + 1, to do
self.cells[r - 1] = self.cells[r]
self.rowHeight[r - 1] = self.rowHeight[r]
end
elseif to < i then
for r = i - 1, to, -1 do
self.cells[r + 1] = self.cells[r]
self.rowHeight[r + 1] = self.rowHeight[r]
end
end
self.cells[to] = cells
self.rowHeight[to] = height
self:OnUpdateFix ()
end
t.DeleteRow = function (self, i)
for j = 0, self.cols do
if self.cells[i][j] then
if type (self.cells[i][j].Recycle) == "function" then
self.cells[i][j]:Recycle ()
else
self.cells[i][j]:Hide ()
end
end
end
for r = i + 1, self.rows do
self.cells[r - 1] = self.cells[r]
self.rowHeight[r - 1] = self.rowHeight[r]
end
if self.hlines and self.hlines[self.rows] then
self.hlines[self.rows]:Hide ()
end
self.rows = self.rows - 1
self:OnUpdateFix ()
end
t.ClearCells = function (self)
for i = 0, self.rows do
for j = 0, self.cols do
if self.cells[i][j] then
if type (self.cells[i][j].Recycle) == "function" then
self.cells[i][j]:Recycle ()
else
self.cells[i][j]:Hide ()
end
end
end
self.cells[i] = {}
end
end
t.GetCellY = function (self, i)
local n = ceil (i)
if n < 0 then n = 0 end
if n > self.rows then n = self.rows end
return - (self.rowPos[n] + (self.rowPos[n - 1] - self.rowPos[n]) * (n - i))
end
t.GetCellX = function (self, j)
local n = ceil (j)
if n < 0 then n = 0 end
if n > self.cols then n = self.cols end
return self.colPos[n] + (self.colPos[n - 1] - self.colPos[n]) * (n - j)
end
t.GetRowHeight = function (self, i)
return self.rowPos[i] - self.rowPos[i - 1]
end
t.GetColumnWidth = function (self, j)
return self.colPos[j] - self.colPos[j - 1]
end
t.AlignCell = function (self, i, j)
local cell = self.cells[i][j]
local x = cell.offsX or 0
local y = cell.offsY or 0
local alignment = cell.align
if alignment == "FILL" then
cell:SetPoint ("TOPLEFT", self, "TOPLEFT", self:GetCellX (j - 1) + x, self:GetCellY (i - 1) + y)
cell:SetPoint ("BOTTOMRIGHT", self, "BOTTOMRIGHT", self:GetCellX (j) + x, self:GetCellY (i) + y)
elseif alignment == "TOPLEFT" then
cell:SetPoint ("TOPLEFT", self, "TOPLEFT", self:GetCellX (j - 1) + 2 + x, self:GetCellY (i - 1) - 2 + y)
elseif alignment == "LEFT" then
cell:SetPoint ("LEFT", self, "TOPLEFT", self:GetCellX (j - 1) + 2 + x, self:GetCellY (i - 0.5) + y)
elseif alignment == "BOTTOMLEFT" then
cell:SetPoint ("BOTTOMLEFT", self, "TOPLEFT", self:GetCellX (j - 1) + 2 + x, self:GetCellY (i) + 2 + y)
elseif alignment == "TOP" then
cell:SetPoint ("TOP", self, "TOPLEFT", self:GetCellX (j - 0.5) + x, self:GetCellY (j - 1) - 2 + y)
elseif alignment == "CENTER" then
cell:SetPoint ("CENTER", self, "TOPLEFT", self:GetCellX (j - 0.5) + x, self:GetCellY (i - 0.5) + y)
elseif alignment == "BOTTOM" then
cell:SetPoint ("BOTTOM", self, "TOPLEFT", self:GetCellX (j - 0.5) + x, self:GetCellY (j) + 2 + y)
elseif alignment == "TOPRIGHT" then
cell:SetPoint ("TOPRIGHT", self, "TOPLEFT", self:GetCellX (j) - 2 + x, self:GetCellY (i - 1) - 2 + y)
elseif alignment == "RIGHT" then
cell:SetPoint ("RIGHT", self, "TOPLEFT", self:GetCellX (j) - 2 + x, self:GetCellY (i - 0.5) + y)
elseif alignment == "BOTTOMRIGHT" then
cell:SetPoint ("BOTTOMRIGHT", self, "TOPLEFT", self:GetCellX (j) - 2 + x, self:GetCellY (i) + 2 + y)
end
end
t.OnUpdateFix = function (self)
self:SetScript ("OnSizeChanged", nil)
local numAutoRows = 0
local totalHeight = 0
for i = 0, self.rows do
if self.rowHeight[i] == "AUTO" then
numAutoRows = numAutoRows + 1
else
totalHeight = totalHeight + self.rowHeight[i]
end
end
if numAutoRows == 0 then
self:SetHeight (totalHeight)
end
local remHeight = self:GetHeight () - totalHeight
for i = 0, self.rows do
if self.rowHeight[i] == "AUTO" then
self.rowPos[i] = self.rowPos[i - 1] + remHeight / numAutoRows
else
self.rowPos[i] = self.rowPos[i - 1] + self.rowHeight[i]
end
end
local numAutoCols = 0
local totalWidth = 0
for i = 0, self.cols do
if self.colWidth[i] == "AUTO" then
numAutoCols = numAutoCols + 1
else
totalWidth = totalWidth + self.colWidth[i]
end
end
if numAutoCols == 0 then
self:SetWidth (totalWidth)
end
local remWidth = self:GetWidth () - totalWidth
for i = 0, self.cols do
if self.colWidth[i] == "AUTO" then
self.colPos[i] = self.colPos[i - 1] + remWidth / numAutoCols
else
self.colPos[i] = self.colPos[i - 1] + self.colWidth[i]
end
end
if self.gridColor then
for i = -1, self.rows do
self.hlines[i]:SetPos (0, self.colPos[self.cols], -self.rowPos[i])
end
for i = -1, self.cols do
self.vlines[i]:SetPos (self.colPos[i], 0, -self.rowPos[self.rows])
end
end
for i = -1, self.rows do
for j = -1, self.cols do
if self.cells[i][j] then
self:AlignCell (i, j)
end
end
end
self:SetScript ("OnSizeChanged", function (self)
RunNextFrame(function() self:OnUpdateFix() end)
end)
if self.onUpdate then
self.onUpdate ()
end
end
if gridColor then
t.hlines = {}
t.vlines = {}
for i = -1, rows do
t.hlines[i] = self:CreateHLine (0, 0, 0, 1.5, gridColor, t)
end
for i = -1, cols do
t.vlines[i] = self:CreateVLine (0, 0, 0, 1.5, gridColor, t)
end
if firstRow == 0 then
t.hlines[-1]:Hide ()
end
if firstColumn == 0 then
t.vlines[-1]:Hide ()
end
end
t.cells = {}
for i = -1, rows do
t.cells[i] = {}
end
for i = 1, t.rows do
t.rowHeight[i] = "AUTO"
end
for j = 1, t.cols do
t.colWidth[j] = "AUTO"
end
t:OnUpdateFix ()
t:SetScript ("OnSizeChanged", function (self)
RunNextFrame(function() self:OnUpdateFix() end)
end)
t.SetCell = function (self, i, j, value, align, offsX, offsY)
align = align or "CENTER"
self.cells[i][j] = value
self.cells[i][j].align = align
self.cells[i][j].offsX = offsX
self.cells[i][j].offsY = offsY
self:AlignCell (i, j)
end
t.textTagPool = {}
t.SetCellText = function (self, i, j, text, align, color, font)
align = align or "CENTER"
color = color or {1, 1, 1}
font = font or "GameFontNormalSmall"
if self.cells[i][j] and not self.cells[i][j].istag then
if type (self.cells[i][j].Recycle) == "function" then
self.cells[i][j]:Recycle ()
else
self.cells[i][j]:Hide ()
end
self.cells[i][j] = nil
end
if self.cells[i][j] then
self.cells[i][j]:SetFontObject (font)
self.cells[i][j]:Show ()
elseif #self.textTagPool > 0 then
self.cells[i][j] = tremove (self.textTagPool, 1)
self.cells[i][j]:SetFontObject (font)
self.cells[i][j]:Show ()
else
self.cells[i][j] = self:CreateFontString (nil, "OVERLAY", font)
self.cells[i][j].Recycle = function (tag)
tag:Hide ()
tinsert (self.textTagPool, tag)
end
end
self.cells[i][j].istag = true
self.cells[i][j]:SetTextColor (unpack(color))
self.cells[i][j]:SetText (text)
self.cells[i][j].align = align
self:AlignCell (i, j)
end
return t
end
function GUI.CreateStaticPopup(name, text, options)
StaticPopupDialogs[name] = {
text = text,
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = true,
editBoxWidth = 350,
OnAccept = function (self)
options.func(self.editBox:GetText ())
end,
EditBoxOnEnterPressed = function (self)
local importStr = self:GetParent ().editBox:GetText ()
if importStr ~= "" then
options.func(importStr)
self:GetParent ():Hide ()
end
end,
EditBoxOnTextChanged = function (self, data)
if data ~= "" then
self:GetParent ().button1:Enable ()
else
self:GetParent ().button1:Disable ()
end
end,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide();
end,
OnShow = function (self)
LibDD:CloseDropDownMenus()
self.editBox:SetText ("")
self.button1:Disable ()
self.editBox:SetFocus ()
end,
OnHide = function (self)
ChatEdit_FocusActiveWindow()
self.editBox:SetText ("")
end,
timeout = 0,
whileDead = true,
hideOnEscape = true
}
end
addonTable.GUI = GUI