/
Functions.lua
1668 lines (1444 loc) · 44.2 KB
/
Functions.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
local _, ns = ...
local B, C, L, DB = unpack(ns)
local cr, cg, cb = DB.r, DB.g, DB.b
local type, pairs, tonumber, wipe, next, select, unpack = type, pairs, tonumber, table.wipe, next, select, unpack
local strmatch, gmatch, strfind, format, gsub = string.match, string.gmatch, string.find, string.format, string.gsub
local min, max, floor, rad = math.min, math.max, math.floor, math.rad
-- Math
do
-- Numberize
function B.Numb(n)
if NDuiADB["NumberFormat"] == 1 then
if n >= 1e12 then
return format("%.2ft", n / 1e12)
elseif n >= 1e9 then
return format("%.2fb", n / 1e9)
elseif n >= 1e6 then
return format("%.2fm", n / 1e6)
elseif n >= 1e3 then
return format("%.1fk", n / 1e3)
else
return format("%.0f", n)
end
elseif NDuiADB["NumberFormat"] == 2 then
if n >= 1e12 then
return format("%.2f"..L["NumberCap3"], n / 1e12)
elseif n >= 1e8 then
return format("%.2f"..L["NumberCap2"], n / 1e8)
elseif n >= 1e4 then
return format("%.1f"..L["NumberCap1"], n / 1e4)
else
return format("%.0f", n)
end
else
return format("%.0f", n)
end
end
function B:Round(number, idp)
idp = idp or 0
local mult = 10 ^ idp
return floor(number * mult + .5) / mult
end
-- Cooldown calculation
local day, hour, minute = 86400, 3600, 60
function B.FormatTime(s)
if s >= day then
return format("%d"..DB.MyColor.."d", s/day), s%day
elseif s >= hour then
return format("%d"..DB.MyColor.."h", s/hour), s%hour
elseif s >= minute then
return format("%d"..DB.MyColor.."m", s/minute), s%minute
elseif s > 10 then
return format("|cffcccc33%d|r", s), s - floor(s)
elseif s > 3 then
return format("|cffffff00%d|r", s), s - floor(s)
else
if NDuiDB["Actionbar"]["DecimalCD"] then
return format("|cffff0000%.1f|r", s), s - format("%.1f", s)
else
return format("|cffff0000%d|r", s + .5), s - floor(s)
end
end
end
function B.FormatTimeRaw(s)
if s >= day then
return format("%dd", s/day)
elseif s >= hour then
return format("%dh", s/hour)
elseif s >= minute then
return format("%dm", s/minute)
elseif s >= 3 then
return floor(s)
else
return format("%d", s)
end
end
function B:CooldownOnUpdate(elapsed, raw)
local formatTime = raw and B.FormatTimeRaw or B.FormatTime
self.elapsed = (self.elapsed or 0) + elapsed
if self.elapsed >= .1 then
local timeLeft = self.expiration - GetTime()
if timeLeft > 0 then
local text = formatTime(timeLeft)
self.timer:SetText(text)
else
self:SetScript("OnUpdate", nil)
self.timer:SetText(nil)
end
self.elapsed = 0
end
end
-- GUID to npcID
function B.GetNPCID(guid)
local id = tonumber(strmatch((guid or ""), "%-(%d-)%-%x-$"))
return id
end
-- Table
function B.CopyTable(source, target)
for key, value in pairs(source) do
if type(value) == "table" then
if not target[key] then target[key] = {} end
for k in pairs(value) do
target[key][k] = value[k]
end
else
target[key] = value
end
end
end
function B.SplitList(list, variable, cleanup)
if cleanup then wipe(list) end
for word in gmatch(variable, "%S+") do
list[word] = true
end
end
end
-- Color
do
function B.HexRGB(r, g, b)
if r then
if type(r) == "table" then
if r.r then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end
end
return format("|cff%02x%02x%02x", r*255, g*255, b*255)
end
end
function B.ClassColor(class)
local color = DB.ClassColors[class]
if not color then return 1, 1, 1 end
return color.r, color.g, color.b
end
function B.UnitColor(unit)
local r, g, b = 1, 1, 1
if UnitIsPlayer(unit) then
local class = select(2, UnitClass(unit))
if class then
r, g, b = B.ClassColor(class)
end
elseif UnitIsTapDenied(unit) then
r, g, b = .6, .6, .6
else
local reaction = UnitReaction(unit, "player")
if reaction then
local color = FACTION_BAR_COLORS[reaction]
r, g, b = color.r, color.g, color.b
end
end
return r, g, b
end
end
-- Itemlevel
do
local iLvlDB = {}
local itemLevelString = gsub(ITEM_LEVEL, "%%d", "")
local enchantString = gsub(ENCHANTED_TOOLTIP_LINE, "%%s", "(.+)")
local essenceTextureID = 2975691
local essenceDescription = GetSpellDescription(277253)
local ITEM_SPELL_TRIGGER_ONEQUIP = ITEM_SPELL_TRIGGER_ONEQUIP
local RETRIEVING_ITEM_INFO = RETRIEVING_ITEM_INFO
local tip = CreateFrame("GameTooltip", "NDui_iLvlTooltip", nil, "GameTooltipTemplate")
function B:InspectItemTextures()
if not tip.gems then
tip.gems = {}
else
wipe(tip.gems)
end
if not tip.essences then
tip.essences = {}
else
for _, essences in pairs(tip.essences) do
wipe(essences)
end
end
local step = 1
for i = 1, 10 do
local tex = _G[tip:GetName().."Texture"..i]
local texture = tex and tex:IsShown() and tex:GetTexture()
if texture then
if texture == essenceTextureID then
local selected = (tip.gems[i-1] ~= essenceTextureID and tip.gems[i-1]) or nil
if not tip.essences[step] then tip.essences[step] = {} end
tip.essences[step][1] = selected --essence texture if selected or nil
tip.essences[step][2] = tex:GetAtlas() --atlas place 'tooltip-heartofazerothessence-major' or 'tooltip-heartofazerothessence-minor'
tip.essences[step][3] = texture --border texture placed by the atlas
step = step + 1
if selected then tip.gems[i-1] = nil end
else
tip.gems[i] = texture
end
end
end
return tip.gems, tip.essences
end
function B:InspectItemInfo(text, slotInfo)
local itemLevel = strfind(text, itemLevelString) and strmatch(text, "(%d+)%)?$")
if itemLevel then
slotInfo.iLvl = tonumber(itemLevel)
end
local enchant = strmatch(text, enchantString)
if enchant then
slotInfo.enchantText = enchant
end
end
function B:CollectEssenceInfo(index, lineText, slotInfo)
local step = 1
local essence = slotInfo.essences[step]
if essence and next(essence) and (strfind(lineText, ITEM_SPELL_TRIGGER_ONEQUIP, nil, true) and strfind(lineText, essenceDescription, nil, true)) then
for i = 5, 2, -1 do
local line = _G[tip:GetName().."TextLeft"..index-i]
local text = line and line:GetText()
if text and (not strmatch(text, "^[ +]")) and essence and next(essence) then
local r, g, b = line:GetTextColor()
essence[4] = r
essence[5] = g
essence[6] = b
step = step + 1
essence = slotInfo.essences[step]
end
end
end
end
function B.GetItemLevel(link, arg1, arg2, fullScan)
if fullScan then
tip:SetOwner(UIParent, "ANCHOR_NONE")
tip:SetInventoryItem(arg1, arg2)
if not tip.slotInfo then tip.slotInfo = {} else wipe(tip.slotInfo) end
local slotInfo = tip.slotInfo
slotInfo.gems, slotInfo.essences = B:InspectItemTextures()
for i = 1, tip:NumLines() do
local line = _G[tip:GetName().."TextLeft"..i]
if line then
local text = line:GetText() or ""
if i == 1 and text == RETRIEVING_ITEM_INFO then
return "tooSoon"
else
B:InspectItemInfo(text, slotInfo)
B:CollectEssenceInfo(i, text, slotInfo)
end
end
end
return slotInfo
else
if iLvlDB[link] then return iLvlDB[link] end
tip:SetOwner(UIParent, "ANCHOR_NONE")
if arg1 and type(arg1) == "string" then
tip:SetInventoryItem(arg1, arg2)
elseif arg1 and type(arg1) == "number" then
tip:SetBagItem(arg1, arg2)
else
tip:SetHyperlink(link)
end
local firstLine = _G.NDui_iLvlTooltipTextLeft1:GetText()
if firstLine == RETRIEVING_ITEM_INFO then
return "tooSoon"
end
for i = 2, 5 do
local line = _G[tip:GetName().."TextLeft"..i]
if line then
local text = line:GetText() or ""
local found = strfind(text, itemLevelString)
if found then
local level = strmatch(text, "(%d+)%)?$")
iLvlDB[link] = tonumber(level)
break
end
end
end
return iLvlDB[link]
end
end
end
-- Kill regions
do
function B:Dummy()
return
end
B.HiddenFrame = CreateFrame("Frame")
B.HiddenFrame:Hide()
function B:HideObject()
if self.UnregisterAllEvents then
self:UnregisterAllEvents()
self:SetParent(B.HiddenFrame)
else
self.Show = self.Hide
end
self:Hide()
end
function B:HideOption()
self:SetAlpha(0)
self:SetScale(.0001)
end
local blizzTextures = {
"Inset",
"inset",
"InsetFrame",
"LeftInset",
"RightInset",
"NineSlice",
"BG",
"border",
"Border",
"BorderFrame",
"bottomInset",
"BottomInset",
"bgLeft",
"bgRight",
"FilligreeOverlay",
"PortraitOverlay",
"ArtOverlayFrame",
"Portrait",
"portrait",
"ScrollFrameBorder",
}
function B:StripTextures(kill)
local frameName = self.GetName and self:GetName()
for _, texture in pairs(blizzTextures) do
local blizzFrame = self[texture] or (frameName and _G[frameName..texture])
if blizzFrame then
B.StripTextures(blizzFrame, kill)
end
end
if self.GetNumRegions then
for i = 1, self:GetNumRegions() do
local region = select(i, self:GetRegions())
if region and region.IsObjectType and region:IsObjectType("Texture") then
if kill and type(kill) == "boolean" then
B.HideObject(region)
elseif tonumber(kill) then
if kill == 0 then
region:SetAlpha(0)
elseif i ~= kill then
region:SetTexture("")
end
else
region:SetTexture("")
end
end
end
end
end
end
-- UI widgets
do
-- Fontstring
function B:CreateFS(size, text, color, anchor, x, y)
local fs = self:CreateFontString(nil, "OVERLAY")
fs:SetFont(DB.Font[1], size, DB.Font[3])
fs:SetText(text)
fs:SetWordWrap(false)
if color and type(color) == "boolean" then
fs:SetTextColor(cr, cg, cb)
elseif color == "system" then
fs:SetTextColor(1, .8, 0)
end
if anchor and x and y then
fs:SetPoint(anchor, x, y)
else
fs:SetPoint("CENTER", 1, 0)
end
return fs
end
-- Gametooltip
function B:HideTooltip()
GameTooltip:Hide()
end
local function Tooltip_OnEnter(self)
GameTooltip:SetOwner(self, self.anchor)
GameTooltip:ClearLines()
if self.title then
GameTooltip:AddLine(self.title)
end
if tonumber(self.text) then
GameTooltip:SetSpellByID(self.text)
elseif self.text then
local r, g, b = 1, 1, 1
if self.color == "class" then
r, g, b = cr, cg, cb
elseif self.color == "system" then
r, g, b = 1, .8, 0
elseif self.color == "info" then
r, g, b = .6, .8, 1
end
GameTooltip:AddLine(self.text, r, g, b, 1)
end
GameTooltip:Show()
end
function B:AddTooltip(anchor, text, color)
self.anchor = anchor
self.text = text
self.color = color
self:SetScript("OnEnter", Tooltip_OnEnter)
self:SetScript("OnLeave", B.HideTooltip)
end
-- Frame
function B:Scale(x)
local mult = C.mult
return mult * floor(x / mult + .5)
end
-- Glow parent
function B:CreateGlowFrame(size)
local frame = CreateFrame("Frame", nil, self)
frame:SetPoint("CENTER")
frame:SetSize(size+8, size+8)
return frame
end
-- Gradient Frame
function B:CreateGF(w, h, o, r, g, b, a1, a2)
self:SetSize(w, h)
self:SetFrameStrata("BACKGROUND")
local gf = self:CreateTexture(nil, "BACKGROUND")
gf:SetAllPoints()
gf:SetTexture(DB.normTex)
gf:SetGradientAlpha(o, r, g, b, a1, r, g, b, a2)
end
-- Background texture
function B:CreateTex()
if self.Tex then return end
local frame = self
if self:GetObjectType() == "Texture" then frame = self:GetParent() end
self.Tex = frame:CreateTexture(nil, "BACKGROUND", nil, 1)
self.Tex:SetAllPoints(self)
self.Tex:SetTexture(DB.bgTex, true, true)
self.Tex:SetHorizTile(true)
self.Tex:SetVertTile(true)
self.Tex:SetBlendMode("ADD")
end
-- Backdrop shadow
function B:CreateSD(size, override)
if not override and not NDuiDB["Skins"]["Shadow"] then return end
if self.__shadow then return end
local frame = self
if self:GetObjectType() == "Texture" then frame = self:GetParent() end
self.__shadow = CreateFrame("Frame", nil, frame, "BackdropTemplate")
self.__shadow:SetOutside(self, size or 4, size or 4)
self.__shadow:SetBackdrop({edgeFile = DB.glowTex, edgeSize = B:Scale(size or 5)})
self.__shadow:SetBackdropBorderColor(0, 0, 0, size and 1 or .4)
self.__shadow:SetFrameLevel(1)
return self.__shadow
end
end
-- UI skins
do
-- ls, Azil, and Simpy made this to replace Blizzard's SetBackdrop API while the textures can't snap
local PIXEL_BORDERS = {"TOP", "BOTTOM", "LEFT", "RIGHT"}
function B:SetBackdrop(frame, a)
local borders = frame.pixelBorders
if not borders then return end
local size = C.mult
borders.CENTER:SetPoint("TOPLEFT", frame)
borders.CENTER:SetPoint("BOTTOMRIGHT", frame)
borders.TOP:SetHeight(size)
borders.BOTTOM:SetHeight(size)
borders.LEFT:SetWidth(size)
borders.RIGHT:SetWidth(size)
B:SetBackdropColor(frame, 0, 0, 0, a)
B:SetBackdropBorderColor(frame, 0, 0, 0)
end
function B:SetBackdropColor(frame, r, g, b, a)
if frame.pixelBorders then
frame.pixelBorders.CENTER:SetVertexColor(r, g, b, a)
end
end
function B:SetBackdropBorderColor(frame, r, g, b, a)
if frame.pixelBorders then
for _, v in pairs(PIXEL_BORDERS) do
frame.pixelBorders[v]:SetVertexColor(r or 0, g or 0, b or 0, a)
end
end
end
function B:SetBackdropColor_Hook(r, g, b, a)
if self:IsForbidden() then return end
B:SetBackdropColor(self, r, g, b, a)
end
function B:SetBackdropBorderColor_Hook(r, g, b, a)
if self:IsForbidden() then return end
B:SetBackdropBorderColor(self, r, g, b, a)
end
function B:PixelBorders(frame)
if frame and not frame.pixelBorders then
local borders = {}
for _, v in pairs(PIXEL_BORDERS) do
borders[v] = frame:CreateTexture(nil, "BORDER", nil, 1)
borders[v]:SetTexture(DB.bdTex)
end
borders.CENTER = frame:CreateTexture(nil, "BACKGROUND", nil, -1)
borders.CENTER:SetTexture(DB.bdTex)
borders.TOP:Point("BOTTOMLEFT", borders.CENTER, "TOPLEFT", C.mult, -C.mult)
borders.TOP:Point("BOTTOMRIGHT", borders.CENTER, "TOPRIGHT", -C.mult, -C.mult)
borders.BOTTOM:Point("TOPLEFT", borders.CENTER, "BOTTOMLEFT", C.mult, C.mult)
borders.BOTTOM:Point("TOPRIGHT", borders.CENTER, "BOTTOMRIGHT", -C.mult, C.mult)
borders.LEFT:Point("TOPRIGHT", borders.TOP, "TOPLEFT", 0, 0)
borders.LEFT:Point("BOTTOMRIGHT", borders.BOTTOM, "BOTTOMLEFT", 0, 0)
borders.RIGHT:Point("TOPLEFT", borders.TOP, "TOPRIGHT", 0, 0)
borders.RIGHT:Point("BOTTOMLEFT", borders.BOTTOM, "BOTTOMRIGHT", 0, 0)
hooksecurefunc(frame, "SetBackdropColor", B.SetBackdropColor_Hook)
hooksecurefunc(frame, "SetBackdropBorderColor", B.SetBackdropBorderColor_Hook)
frame.pixelBorders = borders
end
end
-- Setup backdrop
C.frames = {}
function B:CreateBD(a)
if self.SetBackdrop then
self:SetBackdrop(nil)
end
B:PixelBorders(self)
B:SetBackdrop(self, a or NDuiDB["Skins"]["SkinAlpha"])
if not a then tinsert(C.frames, self) end
end
function B:CreateGradient()
local tex = self:CreateTexture(nil, "BORDER")
tex:SetInside()
tex:SetTexture(DB.bdTex)
if NDuiDB["Skins"]["FlatMode"] then
tex:SetVertexColor(.3, .3, .3, .25)
else
tex:SetGradientAlpha("Vertical", 0, 0, 0, .5, .3, .3, .3, .3)
end
return tex
end
-- Handle frame
function B:CreateBDFrame(a, gradient)
local frame = self
if self:GetObjectType() == "Texture" then frame = self:GetParent() end
local lvl = frame:GetFrameLevel()
local bg = CreateFrame("Frame", nil, frame, "BackdropTemplate")
bg:SetOutside(self)
bg:SetFrameLevel(lvl == 0 and 0 or lvl - 1)
B.CreateBD(bg, a)
if gradient then
self.__gradient = B.CreateGradient(bg)
end
return bg
end
function B:SetBD(a, x, y, x2, y2)
local bg = B.CreateBDFrame(self, a)
if x then
bg:SetPoint("TOPLEFT", self, x, y)
bg:SetPoint("BOTTOMRIGHT", self, x2, y2)
end
B.CreateSD(bg)
B.CreateTex(bg)
return bg
end
-- Handle icons
function B:ReskinIcon(shadow)
self:SetTexCoord(unpack(DB.TexCoord))
return B.CreateBDFrame(self, nil, shadow)
end
function B:PixelIcon(texture, highlight)
self.bg = B.CreateBDFrame(self)
self.bg:SetAllPoints()
self.Icon = self:CreateTexture(nil, "ARTWORK")
self.Icon:SetInside()
self.Icon:SetTexCoord(unpack(DB.TexCoord))
if texture then
local atlas = strmatch(texture, "Atlas:(.+)$")
if atlas then
self.Icon:SetAtlas(atlas)
else
self.Icon:SetTexture(texture)
end
end
if highlight and type(highlight) == "boolean" then
self:EnableMouse(true)
self.HL = self:CreateTexture(nil, "HIGHLIGHT")
self.HL:SetColorTexture(1, 1, 1, .25)
self.HL:SetInside()
end
end
function B:AuraIcon(highlight)
self.CD = CreateFrame("Cooldown", nil, self, "CooldownFrameTemplate")
self.CD:SetInside()
self.CD:SetReverse(true)
B.PixelIcon(self, nil, highlight)
B.CreateSD(self)
end
function B:CreateGear(name)
local bu = CreateFrame("Button", name, self)
bu:SetSize(24, 24)
bu.Icon = bu:CreateTexture(nil, "ARTWORK")
bu.Icon:SetAllPoints()
bu.Icon:SetTexture(DB.gearTex)
bu.Icon:SetTexCoord(0, .5, 0, .5)
bu:SetHighlightTexture(DB.gearTex)
bu:GetHighlightTexture():SetTexCoord(0, .5, 0, .5)
return bu
end
local AtlasToQuality = {
["auctionhouse-itemicon-border-gray"] = LE_ITEM_QUALITY_POOR,
["auctionhouse-itemicon-border-white"] = LE_ITEM_QUALITY_COMMON,
["auctionhouse-itemicon-border-green"] = LE_ITEM_QUALITY_UNCOMMON,
["auctionhouse-itemicon-border-blue"] = LE_ITEM_QUALITY_RARE,
["auctionhouse-itemicon-border-purple"] = LE_ITEM_QUALITY_EPIC,
["auctionhouse-itemicon-border-orange"] = LE_ITEM_QUALITY_LEGENDARY,
["auctionhouse-itemicon-border-artifact"] = LE_ITEM_QUALITY_ARTIFACT,
["auctionhouse-itemicon-border-account"] = LE_ITEM_QUALITY_HEIRLOOM,
}
local function updateIconBorderColorByAtlas(self, atlas)
local quality = AtlasToQuality[atlas]
local color = DB.QualityColors[quality or 1]
self.__owner.bg:SetBackdropBorderColor(color.r, color.g, color.b)
end
local function updateIconBorderColor(self, r, g, b)
if r == .65882 then r, g, b = 0, 0, 0 end
self.__owner.bg:SetBackdropBorderColor(r, g, b)
end
local function resetIconBorderColor(self)
self.__owner.bg:SetBackdropBorderColor(0, 0, 0)
end
function B:ReskinIconBorder()
self:SetAlpha(0)
self.__owner = self:GetParent()
if not self.__owner.bg then return end
if self.__owner.useCircularIconBorder then -- for auction item display
hooksecurefunc(self, "SetAtlas", updateIconBorderColorByAtlas)
else
hooksecurefunc(self, "SetVertexColor", updateIconBorderColor)
end
hooksecurefunc(self, "Hide", resetIconBorderColor)
end
-- Handle statusbar
function B:CreateSB(spark, r, g, b)
self:SetStatusBarTexture(DB.normTex)
if r and g and b then
self:SetStatusBarColor(r, g, b)
else
self:SetStatusBarColor(cr, cg, cb)
end
local bg = B.SetBD(self)
self.__shadow = bg.__shadow
if spark then
self.Spark = self:CreateTexture(nil, "OVERLAY")
self.Spark:SetTexture(DB.sparkTex)
self.Spark:SetBlendMode("ADD")
self.Spark:SetAlpha(.8)
self.Spark:SetPoint("TOPLEFT", self:GetStatusBarTexture(), "TOPRIGHT", -10, 10)
self.Spark:SetPoint("BOTTOMRIGHT", self:GetStatusBarTexture(), "BOTTOMRIGHT", 10, -10)
end
end
-- Handle button
local function Button_OnEnter(self)
if not self:IsEnabled() then return end
if NDuiDB["Skins"]["FlatMode"] then
self.__gradient:SetVertexColor(cr / 4, cg / 4, cb / 4)
else
self.__bg:SetBackdropColor(cr, cg, cb, .25)
end
self.__bg:SetBackdropBorderColor(cr, cg, cb)
end
local function Button_OnLeave(self)
if NDuiDB["Skins"]["FlatMode"] then
self.__gradient:SetVertexColor(.3, .3, .3, .25)
else
self.__bg:SetBackdropColor(0, 0, 0, 0)
end
self.__bg:SetBackdropBorderColor(0, 0, 0)
end
local blizzRegions = {
"Left",
"Middle",
"Right",
"Mid",
"LeftDisabled",
"MiddleDisabled",
"RightDisabled",
"TopLeft",
"TopRight",
"BottomLeft",
"BottomRight",
"TopMiddle",
"MiddleLeft",
"MiddleRight",
"BottomMiddle",
"MiddleMiddle",
"TabSpacer",
"TabSpacer1",
"TabSpacer2",
"_RightSeparator",
"_LeftSeparator",
"Cover",
"Border",
"Background",
"TopTex",
"TopLeftTex",
"TopRightTex",
"LeftTex",
"BottomTex",
"BottomLeftTex",
"BottomRightTex",
"RightTex",
"MiddleTex",
"Center",
}
function B:Reskin(noHighlight, override)
if self.SetNormalTexture and not override then self:SetNormalTexture("") end
if self.SetHighlightTexture then self:SetHighlightTexture("") end
if self.SetPushedTexture then self:SetPushedTexture("") end
if self.SetDisabledTexture then self:SetDisabledTexture("") end
local buttonName = self.GetName and self:GetName()
for _, region in pairs(blizzRegions) do
region = buttonName and _G[buttonName..region] or self[region]
if region then
region:SetAlpha(0)
end
end
self.__bg = B.CreateBDFrame(self, 0, true)
self.__bg:SetAllPoints()
if not noHighlight then
self:HookScript("OnEnter", Button_OnEnter)
self:HookScript("OnLeave", Button_OnLeave)
end
end
local function Menu_OnEnter(self)
self.bg:SetBackdropBorderColor(cr, cg, cb)
end
local function Menu_OnLeave(self)
self.bg:SetBackdropBorderColor(0, 0, 0)
end
local function Menu_OnMouseUp(self)
self.bg:SetBackdropColor(0, 0, 0, NDuiDB["Skins"]["SkinAlpha"])
end
local function Menu_OnMouseDown(self)
self.bg:SetBackdropColor(cr, cg, cb, .25)
end
function B:ReskinMenuButton()
B.StripTextures(self)
self.bg = B.SetBD(self)
self:SetScript("OnEnter", Menu_OnEnter)
self:SetScript("OnLeave", Menu_OnLeave)
self:HookScript("OnMouseUp", Menu_OnMouseUp)
self:HookScript("OnMouseDown", Menu_OnMouseDown)
end
-- Handle tabs
function B:ReskinTab()
self:DisableDrawLayer("BACKGROUND")
local bg = B.CreateBDFrame(self)
bg:SetPoint("TOPLEFT", 8, -3)
bg:SetPoint("BOTTOMRIGHT", -8, 0)
self:SetHighlightTexture(DB.bdTex)
local hl = self:GetHighlightTexture()
hl:ClearAllPoints()
hl:SetInside(bg)
hl:SetVertexColor(cr, cg, cb, .25)
end
local function resetTabAnchor(tab)
local text = tab.Text or _G[tab:GetName().."Text"]
if text then
text:SetPoint("CENTER", tab)
end
end
hooksecurefunc("PanelTemplates_DeselectTab", resetTabAnchor)
hooksecurefunc("PanelTemplates_SelectTab", resetTabAnchor)
-- Handle scrollframe
local function Scroll_OnEnter(self)
local thumb = self.thumb
if not thumb then return end
thumb.bg:SetBackdropColor(cr, cg, cb, .25)
thumb.bg:SetBackdropBorderColor(cr, cg, cb)
end
local function Scroll_OnLeave(self)
local thumb = self.thumb
if not thumb then return end
thumb.bg:SetBackdropColor(0, 0, 0, 0)
thumb.bg:SetBackdropBorderColor(0, 0, 0)
end
local function GrabScrollBarElement(frame, element)
local frameName = frame:GetDebugName()
return frame[element] or frameName and (_G[frameName..element] or strfind(frameName, element)) or nil
end
function B:ReskinScroll()
B.StripTextures(self:GetParent())
B.StripTextures(self)
local thumb = GrabScrollBarElement(self, "ThumbTexture") or GrabScrollBarElement(self, "thumbTexture") or self.GetThumbTexture and self:GetThumbTexture()
if thumb then
thumb:SetAlpha(0)
thumb:SetWidth(17)
self.thumb = thumb
local bg = B.CreateBDFrame(self, 0, true)
bg:SetPoint("TOPLEFT", thumb, 0, -2)
bg:SetPoint("BOTTOMRIGHT", thumb, 0, 4)
thumb.bg = bg
end
local up, down = self:GetChildren()
B.ReskinArrow(up, "up")
B.ReskinArrow(down, "down")
self:HookScript("OnEnter", Scroll_OnEnter)
self:HookScript("OnLeave", Scroll_OnLeave)
end
-- Handle dropdown
function B:ReskinDropDown()
B.StripTextures(self)
local frameName = self.GetName and self:GetName()
local down = self.Button or frameName and (_G[frameName.."Button"] or _G[frameName.."_Button"])
down:ClearAllPoints()
down:SetPoint("RIGHT", -18, 2)
B.ReskinArrow(down, "down")
down:SetSize(20, 20)
local bg = B.CreateBDFrame(self, 0, true)
bg:SetPoint("TOPLEFT", 16, -4)
bg:SetPoint("BOTTOMRIGHT", -18, 8)
end
-- Handle close button
function B:Texture_OnEnter()
if self:IsEnabled() then
if self.pixels then
for _, pixel in pairs(self.pixels) do
pixel:SetVertexColor(cr, cg, cb)
end
elseif self.bg then
self.bg:SetBackdropColor(cr, cg, cb, .25)
else
self.__texture:SetVertexColor(cr, cg, cb)
end
end
end
function B:Texture_OnLeave()
if self.pixels then
for _, pixel in pairs(self.pixels) do
pixel:SetVertexColor(1, 1, 1)
end
elseif self.bg then
self.bg:SetBackdropColor(0, 0, 0, .25)
else
self.__texture:SetVertexColor(1, 1, 1)
end
end
function B:ReskinClose(a1, p, a2, x, y)
self:SetSize(17, 17)
if not a1 then
self:SetPoint("TOPRIGHT", -6, -6)
else
self:ClearAllPoints()
self:SetPoint(a1, p, a2, x, y)
end
B.StripTextures(self)
local bg = B.CreateBDFrame(self, 0, true)
bg:SetAllPoints()
self:SetDisabledTexture(DB.bdTex)
local dis = self:GetDisabledTexture()
dis:SetVertexColor(0, 0, 0, .4)
dis:SetDrawLayer("OVERLAY")
dis:SetAllPoints()
self.pixels = {}
for i = 1, 2 do
local tex = self:CreateTexture()
tex:SetColorTexture(1, 1, 1)
tex:SetSize(11, 2)
tex:SetPoint("CENTER")
tex:SetRotation(rad((i-1/2)*90))
tinsert(self.pixels, tex)
end
self:HookScript("OnEnter", B.Texture_OnEnter)
self:HookScript("OnLeave", B.Texture_OnLeave)
end
-- Handle editbox
function B:ReskinEditBox(height, width)
local frameName = self.GetName and self:GetName()
for _, region in pairs(blizzRegions) do
region = frameName and _G[frameName..region] or self[region]
if region then
region:SetAlpha(0)
end
end
local bg = B.CreateBDFrame(self, 0, true)
bg:SetPoint("TOPLEFT", -2, 0)
bg:SetPoint("BOTTOMRIGHT")
if height then self:SetHeight(height) end
if width then self:SetWidth(width) end
end
B.ReskinInput = B.ReskinEditBox -- Deprecated
-- Handle arrows
local direcIndex = {
["up"] = DB.arrowUp,
["down"] = DB.arrowDown,
["left"] = DB.arrowLeft,
["right"] = DB.arrowRight,
}