/
SharedUIPanelTemplates.lua
2910 lines (2340 loc) · 78.9 KB
/
SharedUIPanelTemplates.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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Panel Positions
PANEL_INSET_LEFT_OFFSET = 4;
PANEL_INSET_RIGHT_OFFSET = -6;
PANEL_INSET_BOTTOM_OFFSET = 4;
PANEL_INSET_BOTTOM_BUTTON_OFFSET = 26;
PANEL_INSET_TOP_OFFSET = -24;
PANEL_INSET_ATTIC_OFFSET = -60;
-- Magic Button code
function MagicButton_OnLoad(self)
local leftHandled = false;
local rightHandled = false;
-- Find out where this button is anchored and adjust positions/separators as necessary
for i=1, self:GetNumPoints() do
local point, relativeTo, relativePoint, offsetX, offsetY = self:GetPoint(i);
if (relativeTo:GetObjectType() == "Button" and (point == "TOPLEFT" or point == "LEFT")) then
if (offsetX == 0 and offsetY == 0) then
self:SetPoint(point, relativeTo, relativePoint, 1, 0);
end
leftHandled = true;
elseif (relativeTo:GetObjectType() == "Button" and (point == "TOPRIGHT" or point == "RIGHT")) then
if (offsetX == 0 and offsetY == 0) then
self:SetPoint(point, relativeTo, relativePoint, -1, 0);
end
rightHandled = true;
elseif (point == "BOTTOMLEFT") then
if (offsetX == 0 and offsetY == 0) then
self:SetPoint(point, relativeTo, relativePoint, 4, 4);
end
leftHandled = true;
elseif (point == "BOTTOMRIGHT") then
if (offsetX == 0 and offsetY == 0) then
self:SetPoint(point, relativeTo, relativePoint, -6, 4);
end
rightHandled = true;
elseif (point == "BOTTOM") then
if (offsetY == 0) then
self:SetPoint(point, relativeTo, relativePoint, 0, 4);
end
end
end
end
function DynamicResizeButton_Resize(self)
local padding = 40;
local width = self:GetWidth();
local textWidth = self:GetTextWidth() + padding;
self:SetWidth(math.max(width, textWidth));
end
-- Frame template utilities to show/hide various decorative elements and to resize content areas
function FrameTemplate_SetAtticHeight(self, atticHeight)
if self.bottomInset then
self.bottomInset:SetPoint("TOPLEFT", self, "TOPLEFT", PANEL_INSET_LEFT_OFFSET, -atticHeight);
else
self.Inset:SetPoint("TOPLEFT", self, "TOPLEFT", PANEL_INSET_LEFT_OFFSET, -atticHeight);
end
end
function FrameTemplate_SetButtonBarHeight(self, buttonBarHeight)
if self.topInset then
self.topInset:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", PANEL_INSET_RIGHT_OFFSET, buttonBarHeight);
else
self.Inset:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", PANEL_INSET_RIGHT_OFFSET, buttonBarHeight);
end
end
-- ButtonFrameTemplate code
function ButtonFrameTemplate_HideButtonBar(self)
FrameTemplate_SetButtonBarHeight(self, PANEL_INSET_BOTTOM_OFFSET);
end
function ButtonFrameTemplate_ShowButtonBar(self)
FrameTemplate_SetButtonBarHeight(self, PANEL_INSET_BOTTOM_BUTTON_OFFSET);
end
function ButtonFrameTemplate_HideAttic(self)
FrameTemplate_SetAtticHeight(self, -PANEL_INSET_TOP_OFFSET);
if self.TopTileStreaks then
self.TopTileStreaks:Hide();
end
end
function ButtonFrameTemplate_ShowAttic(self)
FrameTemplate_SetAtticHeight(self, -PANEL_INSET_ATTIC_OFFSET);
if self.TopTileStreaks then
self.TopTileStreaks:Show();
end
end
local function ButtonFrameTemplate_UpdateRegionAnchor(region, desiredOffsetX)
-- It's unfortunate that region needs to be checked here, but there's code that uses ButtonFrameTemplate_*Portrait calls
-- on frames that don't actually inherit from ButtonFrameTemplate.
if region then
local point, relativeTo, relativePoint, currentOffsetX, offsetY = region:GetPointByName("TOPLEFT");
if point then
region:SetPoint(point, relativeTo, relativePoint, desiredOffsetX, offsetY);
end
end
end
local function ButtonFrameTemplate_UpdateBGAnchors(self, isPortraitMode)
ButtonFrameTemplate_UpdateRegionAnchor(self.Bg, isPortraitMode and 2 or 7);
ButtonFrameTemplate_UpdateRegionAnchor(self.Inset, isPortraitMode and 4 or 9);
end
function ButtonFrameTemplate_HidePortrait(self)
self:SetBorder("ButtonFrameTemplateNoPortrait");
self:SetPortraitShown(false);
local isPortraitMode = false;
ButtonFrameTemplate_UpdateBGAnchors(self, isPortraitMode);
end
function ButtonFrameTemplate_ShowPortrait(self)
self:SetBorder("PortraitFrameTemplate");
self:SetPortraitShown(true);
local isPortraitMode = true;
ButtonFrameTemplate_UpdateBGAnchors(self, isPortraitMode);
end
function ButtonFrameTemplateMinimizable_HidePortrait(self)
self:SetBorder("ButtonFrameTemplateNoPortraitMinimizable");
self:SetPortraitShown(false);
end
function ButtonFrameTemplateMinimizable_ShowPortrait(self)
self:SetBorder("PortraitFrameTemplateMinimizable");
self:SetPortraitShown(true);
end
-- A bit ugly, we want the talent frame to display a dialog box in certain conditions.
function UIPanelCloseButton_OnClick(self)
local parent = self:GetParent();
if parent then
local continueHide = true;
if parent.onCloseCallback then
continueHide = parent.onCloseCallback(self);
end
if continueHide then
HideUIPanel(parent);
end
end
end
function UIPanelStaticPopupSpecialCloseButton_OnClick(self)
StaticPopupSpecial_Hide(self:GetParent());
end
function UIPanelCloseButton_SetBorderAtlas(self, atlas, xOffset, yOffset, textureKit)
local border = self.Border or self:CreateTexture(nil, "OVERLAY", nil, 7);
self.Border = border;
if textureKit then
-- NOTE: Using atlas as the texture kit format string here.
SetupTextureKitOnFrame(textureKit, border, atlas, TextureKitConstants.DoNotSetVisibility, TextureKitConstants.UseAtlasSize);
else
border:SetAtlas(atlas, true);
end
border:SetPoint("CENTER", self, "CENTER", xOffset or 0, yOffset or 0);
end
function UIPanelCloseButton_SetBorderShown(self, shown)
if self.Border then
self.Border:SetShown(shown);
end
end
-- Scrollframe functions
function ScrollFrame_OnLoad(self)
local scrollbar = self.ScrollBar or _G[self:GetName().."ScrollBar"];
scrollbar:SetMinMaxValues(0, 0);
scrollbar:SetValue(0);
self.offset = 0;
local scrollDownButton = scrollbar.ScrollDownButton or _G[scrollbar:GetName().."ScrollDownButton"];
local scrollUpButton = scrollbar.ScrollUpButton or _G[scrollbar:GetName().."ScrollUpButton"];
scrollDownButton:Disable();
scrollUpButton:Disable();
if ( self.scrollBarHideable ) then
scrollbar:Hide();
scrollDownButton:Hide();
scrollUpButton:Hide();
else
scrollDownButton:Disable();
scrollUpButton:Disable();
scrollDownButton:Show();
scrollUpButton:Show();
end
if ( self.noScrollThumb ) then
(scrollbar.ThumbTexture or _G[scrollbar:GetName().."ThumbTexture"]):Hide();
end
end
function ScrollFrameTemplate_OnMouseWheel(self, value, scrollBar)
scrollBar = scrollBar or self.ScrollBar or _G[self:GetName() .. "ScrollBar"];
local scrollStep = scrollBar.scrollStep or scrollBar:GetHeight() / 2
if ( value > 0 ) then
scrollBar:SetValue(scrollBar:GetValue() - scrollStep);
else
scrollBar:SetValue(scrollBar:GetValue() + scrollStep);
end
end
function ScrollFrame_OnScrollRangeChanged(self, xrange, yrange)
local name = self:GetName();
local scrollbar = self.ScrollBar or _G[name.."ScrollBar"];
if ( not yrange ) then
yrange = self:GetVerticalScrollRange();
end
-- Accounting for very small ranges
yrange = floor(yrange);
local value = min(scrollbar:GetValue(), yrange);
scrollbar:SetMinMaxValues(0, yrange);
scrollbar:SetValue(value);
local scrollDownButton = scrollbar.ScrollDownButton or _G[scrollbar:GetName().."ScrollDownButton"];
local scrollUpButton = scrollbar.ScrollUpButton or _G[scrollbar:GetName().."ScrollUpButton"];
local thumbTexture = scrollbar.ThumbTexture or _G[scrollbar:GetName().."ThumbTexture"];
if ( yrange == 0 ) then
if ( self.scrollBarHideable ) then
scrollbar:Hide();
scrollDownButton:Hide();
scrollUpButton:Hide();
thumbTexture:Hide();
else
scrollDownButton:Disable();
scrollUpButton:Disable();
scrollDownButton:Show();
scrollUpButton:Show();
if ( not self.noScrollThumb ) then
thumbTexture:Show();
end
end
else
scrollDownButton:Show();
scrollUpButton:Show();
scrollbar:Show();
if ( not self.noScrollThumb ) then
thumbTexture:Show();
end
-- The 0.005 is to account for precision errors
if ( yrange - value > 0.005 ) then
scrollDownButton:Enable();
else
scrollDownButton:Disable();
end
end
-- Hide/show scrollframe borders
local top = self.Top or name and _G[name.."Top"];
local bottom = self.Bottom or name and _G[name.."Bottom"];
local middle = self.Middle or name and _G[name.."Middle"];
if ( top and bottom and self.scrollBarHideable ) then
if ( self:GetVerticalScrollRange() == 0 ) then
top:Hide();
bottom:Hide();
else
top:Show();
bottom:Show();
end
end
if ( middle and self.scrollBarHideable ) then
if ( self:GetVerticalScrollRange() == 0 ) then
middle:Hide();
else
middle:Show();
end
end
end
function ScrollBar_AdjustAnchors(scrollBar, topAdj, bottomAdj, xAdj)
-- assumes default anchoring of topleft-topright, bottomleft-bottomright
local topY = 0;
local bottomY = 0;
local point, parent, refPoint, x, y;
for i = 1, 2 do
point, parent, refPoint, x, y = scrollBar:GetPoint(i);
if ( point == "TOPLEFT" ) then
topY = y;
elseif ( point == "BOTTOMLEFT" ) then
bottomY = y;
end
end
xAdj = xAdj or 0;
topAdj = topAdj or 0;
bottomAdj = bottomAdj or 0;
scrollBar:SetPoint("TOPLEFT", parent, "TOPRIGHT", x + xAdj, topY + topAdj);
scrollBar:SetPoint("BOTTOMLEFT", parent, "BOTTOMRIGHT", x + xAdj, bottomY + bottomAdj);
end
function ScrollBar_Disable(scrollBar)
scrollBar:Disable();
local scrollDownButton = scrollBar.ScrollDownButton or _G[scrollBar:GetName().."ScrollDownButton"];
if scrollDownButton then
scrollDownButton:Disable();
end
local scrollUpButton = scrollBar.ScrollUpButton or _G[scrollBar:GetName().."ScrollUpButton"];
if scrollUpButton then
scrollUpButton:Disable();
end
end
function ScrollBar_Enable(scrollBar)
scrollBar:Enable();
local currValue = scrollBar:GetValue();
local minVal, maxVal = scrollBar:GetMinMaxValues();
local scrollDownButton = scrollBar.ScrollDownButton or _G[scrollBar:GetName().."ScrollDownButton"];
if scrollDownButton and currValue < maxVal then
scrollDownButton:Enable();
end
local scrollUpButton = scrollBar.ScrollUpButton or _G[scrollBar:GetName().."ScrollUpButton"];
if scrollUpButton and currValue > minVal then
scrollUpButton:Enable();
end
end
function HideParentPanel(self)
HideUIPanel(self:GetParent());
end
function EditBox_HandleTabbing(self, tabList)
local editboxName = self:GetName();
local index;
for i=1, #tabList do
if ( editboxName == tabList[i] ) then
index = i;
break;
end
end
if ( IsShiftKeyDown() ) then
index = index - 1;
else
index = index + 1;
end
if ( index == 0 ) then
index = #tabList;
elseif ( index > #tabList ) then
index = 1;
end
local target = tabList[index];
_G[target]:SetFocus();
end
function EditBox_SetFocus (self)
self:SetFocus();
end
function InputBoxInstructions_OnTextChanged(self)
self.Instructions:SetShown(self:GetText() == "")
end
function InputBoxInstructions_UpdateColorForEnabledState(self, color)
if color then
self:SetTextColor(color:GetRGBA());
end
end
function InputBoxInstructions_OnDisable(self)
InputBoxInstructions_UpdateColorForEnabledState(self, self.disabledColor);
end
function InputBoxInstructions_OnEnable(self)
InputBoxInstructions_UpdateColorForEnabledState(self, self.enabledColor);
end
function SearchBoxTemplate_OnLoad(self)
self.searchIcon:SetVertexColor(0.6, 0.6, 0.6);
self:SetTextInsets(16, 20, 0, 0);
self.Instructions:SetText(SEARCH);
self.Instructions:ClearAllPoints();
self.Instructions:SetPoint("TOPLEFT", self, "TOPLEFT", 16, 0);
self.Instructions:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -20, 0);
end
function SearchBoxTemplate_OnEditFocusLost(self)
if ( self:GetText() == "" ) then
self.searchIcon:SetVertexColor(0.6, 0.6, 0.6);
self.clearButton:Hide();
end
end
function SearchBoxTemplate_OnEditFocusGained(self)
self.searchIcon:SetVertexColor(1.0, 1.0, 1.0);
self.clearButton:Show();
end
function SearchBoxTemplate_OnTextChanged(self)
if ( not self:HasFocus() and self:GetText() == "" ) then
self.searchIcon:SetVertexColor(0.6, 0.6, 0.6);
self.clearButton:Hide();
else
self.searchIcon:SetVertexColor(1.0, 1.0, 1.0);
self.clearButton:Show();
end
InputBoxInstructions_OnTextChanged(self);
end
function SearchBoxTemplateClearButton_OnClick(self)
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
local editBox = self:GetParent();
editBox:SetText("");
editBox:ClearFocus();
end
PanelTabButtonMixin = {};
function PanelTabButtonMixin:OnLoad()
self:SetFrameLevel(self:GetFrameLevel() + 4);
self:RegisterEvent("DISPLAY_SIZE_CHANGED");
end
function PanelTabButtonMixin:OnEvent(event, ...)
if self:IsVisible() then
PanelTemplates_TabResize(self, self:GetParent().tabPadding, nil, self:GetParent().minTabWidth, self:GetParent().maxTabWidth);
end
end
function PanelTabButtonMixin:OnShow()
PanelTemplates_TabResize(self, self:GetParent().tabPadding, nil, self:GetParent().minTabWidth, self:GetParent().maxTabWidth);
end
function PanelTabButtonMixin:OnEnter()
if self.Text:IsTruncated() then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:SetText(self.Text:GetText());
end
end
function PanelTabButtonMixin:OnLeave()
GameTooltip_Hide();
end
PanelTopTabButtonMixin = {};
local TOP_TAB_HEIGHT_PERCENT = 0.75;
local TOP_TAB_BOTTOM_TEX_COORD = 1 - TOP_TAB_HEIGHT_PERCENT;
function PanelTopTabButtonMixin:OnLoad()
PanelTabButtonMixin.OnLoad(self);
for _, tabTexture in ipairs(self.TabTextures) do
tabTexture:SetTexCoord(0, 1, 1, TOP_TAB_BOTTOM_TEX_COORD);
tabTexture:SetHeight(tabTexture:GetHeight() * TOP_TAB_HEIGHT_PERCENT);
end
self.Left:ClearAllPoints();
self.Left:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", -3, 0);
self.Right:ClearAllPoints();
self.Right:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", 7, 0);
self.LeftActive:ClearAllPoints();
self.LeftActive:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", -1, 0);
self.RightActive:ClearAllPoints();
self.RightActive:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", 8, 0);
self.isTopTab = true;
end
-- functions to manage tab interfaces where only one tab of a group may be selected
function PanelTemplates_Tab_OnClick(self, frame)
PanelTemplates_SetTab(frame, self:GetID())
end
function PanelTemplates_SetTab(frame, id)
frame.selectedTab = id;
PanelTemplates_UpdateTabs(frame);
end
function PanelTemplates_GetSelectedTab(frame)
return frame.selectedTab;
end
local function GetTabByIndex(frame, index)
return frame.Tabs and frame.Tabs[index] or _G[frame:GetName().."Tab"..index];
end
function PanelTemplates_UpdateTabs(frame)
if ( frame.selectedTab ) then
local tab;
for i=1, frame.numTabs, 1 do
tab = GetTabByIndex(frame, i);
if ( tab.isDisabled ) then
PanelTemplates_SetDisabledTabState(tab);
elseif ( i == frame.selectedTab ) then
PanelTemplates_SelectTab(tab);
else
PanelTemplates_DeselectTab(tab);
end
end
end
end
function PanelTemplates_GetTabWidth(tab)
local sideWidths = tab.Left:GetWidth() + tab.Right:GetWidth();
return tab:GetTextWidth() + sideWidths;
end
local TAB_SIDES_PADDING = 20;
function PanelTemplates_TabResize(tab, padding, absoluteSize, minWidth, maxWidth, absoluteTextSize)
if absoluteTextSize then
tab.Text:SetWidth(absoluteTextSize);
else
tab.Text:SetWidth(0);
end
local textWidth = tab.Text:GetStringWidth();
local width = textWidth + TAB_SIDES_PADDING + (padding or 0);
local sideWidths = tab.Left:GetWidth() + tab.Right:GetWidth();
minWidth = minWidth or sideWidths;
if absoluteSize then
if absoluteSize < sideWidths then
width = sideWidths;
else
width = absoluteSize;
end
textWidth = width - TAB_SIDES_PADDING - (padding or 0);
else
if maxWidth and width > maxWidth then
width = maxWidth;
textWidth = width - TAB_SIDES_PADDING - (padding or 0);
elseif minWidth and width < minWidth then
width = minWidth;
textWidth = width - TAB_SIDES_PADDING - (padding or 0);
end
end
tab.Text:SetWidth(textWidth);
tab:SetWidth(width);
end
function PanelTemplates_ResizeTabsToFit(frame, maxWidthForAllTabs)
local selectedIndex = PanelTemplates_GetSelectedTab(frame);
if ( not selectedIndex ) then
return;
end
local currentWidth = 0;
local truncatedText = false;
for i = 1, frame.numTabs do
local tab = GetTabByIndex(frame, i);
currentWidth = currentWidth + tab:GetWidth();
if tab.Text and tab.Text:IsTruncated() then
truncatedText = true;
end
end
if ( not truncatedText and currentWidth <= maxWidthForAllTabs ) then
return;
end
local currentTab = GetTabByIndex(frame, selectedIndex);
PanelTemplates_TabResize(currentTab, 0);
local availableWidth = maxWidthForAllTabs - currentTab:GetWidth();
local widthPerTab = availableWidth / (frame.numTabs - 1);
for i = 1, frame.numTabs do
if ( i ~= selectedIndex ) then
local tab = GetTabByIndex(frame, i);
PanelTemplates_TabResize(tab, 0, widthPerTab);
end
end
end
function PanelTemplates_SetNumTabs(frame, numTabs)
frame.numTabs = numTabs;
PanelTemplates_AnchorTabs(frame);
end
function PanelTemplates_AnchorTabs(frame, numTabs)
for i = 2, frame.numTabs do
local lastTab = GetTabByIndex(frame, i - 1);
local thisTab = GetTabByIndex(frame, i);
thisTab:SetPoint("TOPLEFT", lastTab, "TOPRIGHT", 3, 0);
end
end
function PanelTemplates_SetTabEnabled(frame, index, enabled)
if (enabled) then
PanelTemplates_EnableTab(frame, index);
else
PanelTemplates_DisableTab(frame, index);
end
end
function PanelTemplates_DisableTab(frame, index)
GetTabByIndex(frame, index).isDisabled = 1;
PanelTemplates_UpdateTabs(frame);
end
function PanelTemplates_EnableTab(frame, index)
local tab = GetTabByIndex(frame, index);
tab.isDisabled = nil;
-- Reset text color
tab:SetDisabledFontObject(GameFontHighlightSmall);
PanelTemplates_UpdateTabs(frame);
end
function PanelTemplates_HideTab(frame, index)
local tab = GetTabByIndex(frame, index);
tab:Hide();
end
function PanelTemplates_ShowTab(frame, index)
local tab = GetTabByIndex(frame, index);
tab:Show();
end
function PanelTemplates_DeselectTab(tab)
tab.Left:Show();
tab.Middle:Show();
tab.Right:Show();
tab:Enable();
local offsetY = tab.deselectedTextY or 2;
if tab.isTopTab then
offsetY = -offsetY - 6;
end
tab.Text:SetPoint("CENTER", tab, "CENTER", (tab.deselectedTextX or 0), offsetY);
tab.LeftActive:Hide();
tab.MiddleActive:Hide();
tab.RightActive:Hide();
end
function PanelTemplates_SelectTab(tab)
tab.Left:Hide();
tab.Middle:Hide();
tab.Right:Hide();
tab:Disable();
tab:SetDisabledFontObject(GameFontHighlightSmall);
local offsetY = tab.selectedTextY or -3;
if tab.isTopTab then
offsetY = -offsetY - 7;
end
tab.Text:SetPoint("CENTER", tab, "CENTER", (tab.selectedTextX or 0), offsetY);
tab.LeftActive:Show();
tab.MiddleActive:Show();
tab.RightActive:Show();
local tooltip = GetAppropriateTooltip();
if tooltip:IsOwned(tab) then
tooltip:Hide();
end
end
function PanelTemplates_SetDisabledTabState(tab)
tab.Left:Show();
tab.Middle:Show();
tab.Right:Show();
tab:Disable();
tab:SetDisabledFontObject(GameFontDisableSmall);
local offsetY = tab.deselectedTextY or 2;
if tab.isTopTab then
offsetY = -offsetY - 6;
end
tab.Text:SetPoint("CENTER", tab, "CENTER", (tab.deselectedTextX or 0), offsetY);
tab.LeftActive:Hide();
tab.MiddleActive:Hide();
tab.RightActive:Hide();
end
-- NOTE: If your edit box never shows partial lines of text, then this function will not work when you use
-- your mouse to move the edit cursor. You need the edit box to cut lines of text so that you can use your
-- mouse to highlight those partially-seen lines; otherwise you won't be able to use the mouse to move the
-- cursor above or below the current scroll area of the edit box.
function ScrollingEdit_OnUpdate(self, elapsed, scrollFrame)
local height, range, scroll, size, cursorOffset;
if ( self.handleCursorChange ) then
if ( not scrollFrame ) then
scrollFrame = self:GetParent();
end
height = scrollFrame:GetHeight();
range = scrollFrame:GetVerticalScrollRange();
scroll = scrollFrame:GetVerticalScroll();
size = height + range;
cursorOffset = -self.cursorOffset;
if ( math.floor(height) <= 0 or math.floor(range) <= 0 ) then
--Frame has no area, nothing to calculate.
return;
end
while ( cursorOffset < scroll ) do
scroll = (scroll - (height / 2));
if ( scroll < 0 ) then
scroll = 0;
end
scrollFrame:SetVerticalScroll(scroll);
end
while ( (cursorOffset + self.cursorHeight) > (scroll + height) and scroll < range ) do
scroll = (scroll + (height / 2));
if ( scroll > range ) then
scroll = range;
end
scrollFrame:SetVerticalScroll(scroll);
end
self.handleCursorChange = false;
end
end
function ScrollingEdit_OnTextChanged(self, scrollFrame)
-- force an update when the text changes
self.handleCursorChange = true;
ScrollingEdit_OnUpdate(self, 0, scrollFrame);
end
function ScrollingEdit_OnLoad(self)
ScrollingEdit_SetCursorOffsets(self, 0, 0);
end
function ScrollingEdit_SetCursorOffsets(self, offset, height)
self.cursorOffset = offset;
self.cursorHeight = height;
end
function ScrollingEdit_OnCursorChanged(self, x, y, w, h)
ScrollingEdit_SetCursorOffsets(self, y, h);
self.handleCursorChange = true;
end
NumericInputSpinnerMixin = {};
-- "public"
function NumericInputSpinnerMixin:SetValue(value)
local newValue = Clamp(value, self.min or -math.huge, self.max or math.huge);
if newValue ~= self.currentValue then
self.currentValue = newValue;
self:SetNumber(newValue);
if self.onValueChangedCallback then
self.onValueChangedCallback(self, self:GetNumber());
end
end
end
function NumericInputSpinnerMixin:SetMinMaxValues(min, max)
if self.min ~= min or self.max ~= max then
self.min = min;
self.max = max;
self:SetValue(self:GetValue());
end
end
function NumericInputSpinnerMixin:GetValue()
return self.currentValue or self.min or 0;
end
function NumericInputSpinnerMixin:SetOnValueChangedCallback(onValueChangedCallback)
self.onValueChangedCallback = onValueChangedCallback;
end
function NumericInputSpinnerMixin:Increment(amount)
self:SetValue(self:GetValue() + (amount or 1));
end
function NumericInputSpinnerMixin:Decrement(amount)
self:SetValue(self:GetValue() - (amount or 1));
end
function NumericInputSpinnerMixin:SetEnabled(enable)
self.IncrementButton:SetEnabled(enable);
self.DecrementButton:SetEnabled(enable);
getmetatable(self).__index.SetEnabled(self, enable);
end
function NumericInputSpinnerMixin:Enable()
self:SetEnabled(true)
end
function NumericInputSpinnerMixin:Disable()
self:SetEnabled(false)
end
-- "private"
function NumericInputSpinnerMixin:OnTextChanged()
self:SetValue(self:GetNumber());
end
local MAX_TIME_BETWEEN_CHANGES_SEC = .5;
local MIN_TIME_BETWEEN_CHANGES_SEC = .075;
local TIME_TO_REACH_MAX_SEC = 3;
function NumericInputSpinnerMixin:StartIncrement()
self.incrementing = true;
self.startTime = GetTime();
self.nextUpdate = MAX_TIME_BETWEEN_CHANGES_SEC;
self:SetScript("OnUpdate", self.OnUpdate);
self:Increment();
self:ClearFocus();
end
function NumericInputSpinnerMixin:EndIncrement()
self:SetScript("OnUpdate", nil);
end
function NumericInputSpinnerMixin:StartDecrement()
self.incrementing = false;
self.startTime = GetTime();
self.nextUpdate = MAX_TIME_BETWEEN_CHANGES_SEC;
self:SetScript("OnUpdate", self.OnUpdate);
self:Decrement();
self:ClearFocus();
end
function NumericInputSpinnerMixin:EndDecrement()
self:SetScript("OnUpdate", nil);
end
function NumericInputSpinnerMixin:OnUpdate(elapsed)
self.nextUpdate = self.nextUpdate - elapsed;
if self.nextUpdate <= 0 then
if self.incrementing then
self:Increment();
else
self:Decrement();
end
local totalElapsed = GetTime() - self.startTime;
local nextUpdateDelta = Lerp(MAX_TIME_BETWEEN_CHANGES_SEC, MIN_TIME_BETWEEN_CHANGES_SEC, Saturate(totalElapsed / TIME_TO_REACH_MAX_SEC));
self.nextUpdate = self.nextUpdate + nextUpdateDelta;
end
end
MaximizeMinimizeButtonFrameMixin = {};
function MaximizeMinimizeButtonFrameMixin:OnShow()
if self.isAutomaticAction then
self.isAutomaticAction = false;
elseif self.cvar then
local minimized = GetCVarBool(self.cvar);
if minimized then
self:Minimize();
else
self:Maximize();
end
end
end
function MaximizeMinimizeButtonFrameMixin:IsMinimized()
return self.isMinimized;
end
function MaximizeMinimizeButtonFrameMixin:SetMinimizedCVar(cvar)
self.cvar = cvar;
end
function MaximizeMinimizeButtonFrameMixin:SetOnMaximizedCallback(maximizedCallback)
self.maximizedCallback = maximizedCallback;
end
function MaximizeMinimizeButtonFrameMixin:Maximize(isAutomaticAction)
if self.maximizedCallback then
self.maximizedCallback(self);
end
if not isAutomaticAction and self.cvar then
SetCVar(self.cvar, 0);
end
self.isMinimized = false;
self.isAutomaticAction = isAutomaticAction;
self:SetMinimizedLook();
end
function MaximizeMinimizeButtonFrameMixin:SetOnMinimizedCallback(minimizedCallback)
self.minimizedCallback = minimizedCallback;
end
function MaximizeMinimizeButtonFrameMixin:Minimize(isAutomaticAction)
if self.minimizedCallback then
self:minimizedCallback();
end
if not isAutomaticAction and self.cvar then
SetCVar(self.cvar, 1);
end
self.isMinimized = true;
self.isAutomaticAction = isAutomaticAction;
self:SetMaximizedLook();
end
function MaximizeMinimizeButtonFrameMixin:SetMinimizedLook()
self.MaximizeButton:Hide();
self.MinimizeButton:Show();
end
function MaximizeMinimizeButtonFrameMixin:SetMaximizedLook()
self.MaximizeButton:Show();
self.MinimizeButton:Hide();
end
-- Truncated Button code
function TruncatedButton_OnSizeChanged(self, width, height)
self.Text:SetWidth(width - 5);
self.Text:SetHeight(height);
end
function TruncatedButton_OnEnter(self)
if self.Text:IsTruncated() then
local tooltip = GetAppropriateTooltip();
tooltip:SetOwner(self, "ANCHOR_RIGHT");
tooltip:SetText(self.Text:GetText());
tooltip:Show();
end
end
function TruncatedButton_OnLeave(self)
local tooltip = GetAppropriateTooltip();
if tooltip:GetOwner() == self then
tooltip:Hide();
end
end
-- Truncated Tooltip Script code
function TruncatedTooltipScript_OnEnter(self)
local text = self.truncatedTooltipScriptText or self.Text;
if text:IsTruncated() then
local tooltip = GetAppropriateTooltip();
tooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip_AddNormalLine(tooltip, text:GetText());
tooltip:Show();
end
end
function TruncatedTooltipScript_OnLeave(self)
local tooltip = GetAppropriateTooltip();
if tooltip:GetOwner() == self then
tooltip:Hide();
end
end
-- Add more methods as needed to pass functionality through to the FontString (like SetText and SetTextColor below)
TruncatedTooltipFontStringWrapperMixin = {}
function TruncatedTooltipFontStringWrapperMixin:SetText(...)
self.Text:SetText(...);
self:MarkDirty();
end
function TruncatedTooltipFontStringWrapperMixin:SetTextColor(...)
self.Text:SetTextColor(...);
end
function TruncatedTooltipFontStringWrapperMixin:OnEnter()
if self.Text:IsTruncated() then
local tooltip = GetAppropriateTooltip();
tooltip:SetOwner(self, "ANCHOR_RIGHT");
tooltip:SetText(self.Text:GetText());
tooltip:Show();
end
end
function TruncatedTooltipFontStringWrapperMixin:OnLeave()
local tooltip = GetAppropriateTooltip();
if tooltip:GetOwner() == self then
tooltip:Hide();
end
end
function GetAppropriateTopLevelParent()
return UIParent or GlueParent;
end