forked from ornfelt/azerothcore_lua_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTidyPlatesCore.lua
More file actions
785 lines (717 loc) · 34.7 KB
/
TidyPlatesCore.lua
File metadata and controls
785 lines (717 loc) · 34.7 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
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
TidyPlates = {}
local activetheme, activethemename = {}, "None"
local numChildren = -1
local echoUpdate = 0
local echoSelf = {}
local function SetSelfEcho(plate) if plate:IsShown() then echoSelf[plate] = true; end end
local function SetEchoUpdate(echos) echoUpdate = max(echoUpdate,echos) end
SetCVar("threatWarning", 3)
local ForEachPlate -- Function
local EMPTY_TEXTURE = "Interface\\Addons\\ArenaSpectator\\Media\\Empty"
local useAutohide = false
local select, pairs, tostring = select, pairs, tostring
local select = select
local InCombat, HasTarget = false, false
local Plates, PlatesVisible = {}, {}
local players = {}
SIZENAMEPLATES = { ["WIDTH"] = 100, ["HEIGHT"] = 16, ["TEXTSIZE"] = 8 }
-------------------------------------------------------
-- Object Functions
-------------------------------------------------------
local function IsPlayerGUID(guid)
return tonumber(guid:sub(5,5)) == 0
end
local function GetPlayerTeamByName(value)
temp = ATPlayers
for _, p in pairs(temp) do
if p.name == value and IsPlayerGUID(p.guid) then
return p.team
end
end
return false
end
local function SetObjectShape(object, width, height) object:SetWidth(width); object:SetHeight(height) end
local function SetObjectFont(object, font, size, flags) object:SetFont(font, size, flags) end
local function SetObjectJustify(object, horz, vert) object:SetJustifyH(horz); object:SetJustifyV(vert) end
local function SetObjectShadow(object, shadow) if shadow then object:SetShadowColor(0,0,0,1); object:SetShadowOffset(1, -1) else object:SetShadowColor(0,0,0,0) end end
local function SetObjectAnchor(object, anchor, anchorTo, x, y) object:ClearAllPoints();object:SetPoint(anchor, anchorTo, anchor, x, y) end
local function SetObjectTexture(object, texture) object:SetTexture(texture); object:SetTexCoord(0,1,0,1) end
local function SetObjectBartexture(object, texture, orientation) object:SetStatusBarTexture(texture); object:SetOrientation(orientation) end
-- SetFontGroupObject
local function SetFontGroupObject(object, objectstyle)
SetObjectFont(object, objectstyle.typeface, objectstyle.size, objectstyle.flags)
SetObjectJustify(object, objectstyle.align, objectstyle.vertical)
SetObjectShadow(object, objectstyle.shadow)
end
-- SetAnchorGroupObject
local function SetAnchorGroupObject(object, objectstyle, anchorTo)
SetObjectShape(object, objectstyle.width, objectstyle.height) --end
SetObjectAnchor(object, objectstyle.anchor, anchorTo, objectstyle.x, objectstyle.y)
end
-- SetBarGroupObject
local function SetBarGroupObject(object, objectstyle, anchorTo)
SetObjectShape(object, objectstyle.width, objectstyle.height) --end
SetObjectAnchor(object, objectstyle.anchor, anchorTo, objectstyle.x, objectstyle.y) --end
SetObjectBartexture(object, objectstyle.texture, objectstyle.orientation) --end
end
-------------------------------------------------------
-- UpdateStyle
-------------------------------------------------------
local UpdateStyle
do
-- UpdateStyle Variables
local index, content, extended, bars, visual, style
local objectstyle, objectname, objectregion
-- Style Property Groups
local fontgroup = {"name", "level", "specialText", "specialText2"}
local anchorgroup = {"healthborder", "threatborder", "castborder", "castnostop",
"name", "specialText", "specialText2", "level",
"specialArt", "spellicon", "raidicon", "dangerskull"}
local bargroup = {"castbar", "healthbar"}
-------------------------------------------------------
-- Main Function: UpdateStyle
-------------------------------------------------------
function UpdateStyle(plate)
extended = plate.extended
bars, visual, style, unit = extended.bars, extended.visual, extended.style, extended.unit
-- Hitbox
if not InCombat then objectstyle = style.hitbox; SetObjectShape(plate, objectstyle.width, objectstyle.height) end
-- Frame
SetAnchorGroupObject(extended, style.frame, plate)
-- Anchorgroup
for i = 1, #anchorgroup do objectname = anchorgroup[i]; SetAnchorGroupObject(visual[objectname], style[objectname], extended) end
-- Bars
for i = 1, #bargroup do objectname = bargroup[i]; SetBarGroupObject(bars[objectname], style[objectname], extended) end
-- Texture
SetObjectTexture(visual.castborder, style.castborder.texture)
SetObjectTexture(visual.castnostop, style.castnostop.texture)
-- Font Group
for i = 1, #fontgroup do objectname = fontgroup[i];SetFontGroupObject(visual[objectname], style[objectname]) end
-- Show/Hide
if style.options.showName then visual.name:Show() else visual.name:Hide() end
if style.options.showSpecialText then visual.specialText:Show() else visual.specialText:Hide() end
if style.options.showSpecialText2 then visual.specialText2:Show() else visual.specialText2:Hide() end
if style.options.showSpecialArt then visual.specialArt:Show() else visual.specialArt:Hide() end
if style.options.showSpellIcon then visual.spellicon:Show() else visual.spellicon:Hide() end
if style.options.showLevel and (not unit.isBoss) then visual.level:Show() else visual.level:Hide() end
if unit.isBoss and style.options.showDangerSkull then visual.dangerskull:Show() else visual.dangerskull:Hide() end
end
end
-------------------------------------------------------
-- UpdatePlateIndicators
-------------------------------------------------------
local UpdatePlateIndicators
do
local color = {}
local extended, unit, style, bars, visual, threatborder, alpha, forcealpha, scale
-- SetIndicatorElite -- Set Border and Aggro Glow Textures
local function SetIndicatorElite()
if unit.isElite then visual.healthborder:SetTexture( style.healthborder.elitetexture)
threatborder:SetTexture(style.threatborder.elitetexture)
else visual.healthborder:SetTexture( style.healthborder.texture)
threatborder:SetTexture(style.threatborder.texture) end
end
-------------------------------------------------------
-- UpdatePlateIndicators: Updates the nameplate information depending on unit conditions
-------------------------------------------------------
function UpdatePlateIndicators(plate)
extended = plate.extended
style, bars, visual, scale, regions = extended.style, extended.bars, extended.visual, extended.scale, extended.regions
unit, unitcache = extended.unit, extended.unitcache
threatborder = visual.threatborder
visual.highlight:SetAlpha(0)
-- Set Alpha, Scale, Elite, Aggro
alpha = 1
if activetheme.SetAlpha then
alpha, forcealpha = activetheme.SetAlpha(unit)
if forcealpha then alpha = (alpha or 1) -- moved * (unit.alpha or 1) to else
else alpha = (alpha or 1) * (unit.alpha or 1) end
extended:SetAlpha(alpha)
-- visual.highlight:SetAlpha(0)
else extended:SetAlpha(unit.alpha or 1) end
-- If plate is visible, handle indicators
if alpha > 0 then
-- visual.name:Hide()
-- visual.level:Hide()
if (not IsActiveBattlefieldArena()) then
bars.healthbar:SetBackdrop(nil)
else
teamId = GetPlayerTeamByName(unit.name)
if (teamId) then
bars.healthbar:SetBackdrop({
bgFile = "",
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
tile = true,
tileSize = 1,
edgeSize = 1
})
if (teamId == 67) then
bars.healthbar:SetBackdropBorderColor(1.0, 0.0, 0.0, 1.0)
else
bars.healthbar:SetBackdropBorderColor(0.0, 0.5, 1.0, 1.0)
end
end
end
visual.name:SetText(unit.name)
visual.level:SetText(unit.level)
local tr, tg, tb = regions.level:GetTextColor()
visual.level:SetTextColor(tr, tg, tb)
-- Scale
if activetheme.SetScale then scale = activetheme.SetScale(unit); if scale then extended:SetScale( scale )end; end
-- Elite Graphics
if (unit.isElite == nil ) or unit.isElite ~= unitcache.isElite then SetIndicatorElite() end
-- Set Aggro Region
if style.options.showAggroGlow and InCombat and unit.reaction ~= "FRIENDLY" and unit.type == "NPC" then
color = style.threatcolor[unit.threatSituation]
threatborder:Show()
threatborder:SetVertexColor(color.r, color.g, color.b, color.a)
else threatborder:Hide() end
-- Set Special-Case Regions
if style.options.showSpecialText and activetheme.SetSpecialText then
visual.specialText:SetText(activetheme.SetSpecialText(unit)) end
if style.options.showSpecialText2 and activetheme.SetSpecialText2 then
visual.specialText2:SetText(activetheme.SetSpecialText2(unit)) end
if style.options.showSpecialArt and activetheme.SetSpecialArt then
visual.specialArt:SetTexture(activetheme.SetSpecialArt(unit)) end
-- Set Health Bar
if classes[unit.name] ~= nil then
local class = classes[unit.name]
local c = RAID_CLASS_COLORS[class]
bars.healthbar:SetStatusBarColor(c.r, c.g, c.b)
-- print(c.r .. ", " .. c.g .. ", " .. c.b)
elseif players[unit.name] ~= nil then
local class = players[unit.name]
local c = RAID_CLASS_COLORS[class]
bars.healthbar:SetStatusBarColor(c.r, c.g, c.b)
elseif unit.guid then
local _, class = GetPlayerInfoByGUID(unit.guid)
if class then
players[unit.name] = class
local c = RAID_CLASS_COLORS[class]
bars.healthbar:SetStatusBarColor(c.r, c.g, c.b)
end
else bars.healthbar:SetStatusBarColor(bars.health:GetStatusBarColor()) end
bars.healthbar:SetMinMaxValues(bars.health:GetMinMaxValues())
bars.healthbar:SetValue(bars.health:GetValue())
local min, max = bars.health:GetMinMaxValues()
bars.healthbar.hptext:SetText(math.ceil(bars.health:GetValue() / max * 100) .. "%")
bars.healthbar.nametext:SetText(unit.name)
end
end
end
-------------------------------------------------------
-- Update Plate / Gather Data
-- Gathers Information about the unit, and requests updates, if needed
-------------------------------------------------------
local OnShowNameplate, OnHideNameplate, OnMouseoverNameplate, OnUpdateNameplate, OnStartCast, OnStopCast, OnUpdateCast
local UpdateReferences, UpdateUnitStatus, UpdateNameplateStyle
do
local ClassReference = {}
local _, stylename, unitchanged, extended, bars, regions, unit, unitcache, style, visual
-- ColorToString: Converts a color to a string with a C- prefix
local function ColorToString(r,g,b) return "C"..math.floor((100*r) + 0.5)..math.floor((100*g) + 0.5)..math.floor((100*b) + 0.5) end
-- GetUnitCombatStatus: Determines if a unit is in combat by checking the name text color
local function GetUnitCombatStatus(r, g, b) return (r > .5 and g < .5) end
-- GetUnitAggroStatus: Determines if a unit is attacking, by looking at aggro glow region
local GetUnitAggroStatus
do
local shown
local red, green, blue
function GetUnitAggroStatus( region)
shown = region:IsShown()
if not shown then return "LOW" end
red, green, blue = region:GetVertexColor()
if green > .7 then return "MEDIUM" end
if red > .7 then return "HIGH" end
end
end
-- GetUnitReaction: Determines the reaction, and type of unit from the health bar color
local function GetUnitReaction(red, green, blue)
if red < .01 and blue < .01 and green > .99 then return "FRIENDLY", "NPC"
elseif red < .01 and blue > .99 and green < .01 then return "FRIENDLY", "PLAYER"
elseif red > .99 and blue < .01 and green > .99 then return "NEUTRAL", "NPC"
elseif red > .99 and blue < .01 and green < .01 then return "HOSTILE", "NPC"
else return "HOSTILE", "PLAYER" end
end
--
local ux, uy
local RaidIconCoordinate = { --from GetTexCoord. input is ULx and ULy (first 2 values).
[0] = { [0] = "STAR", [0.25] = "MOON", },
[0.25] = { [0] = "CIRCLE", [0.25] = "SQUARE", },
[0.5] = { [0] = "DIAMOND", [0.25] = "CROSS", },
[0.75] = { [0] = "TRIANGLE", [0.25] = "SKULL", }, }
-- Populates the class color lookup table
for classname, color in pairs(RAID_CLASS_COLORS) do
ClassReference[ColorToString(color.r, color.g, color.b)] = classname end
-- UpdateUnitStatic: Updates Static Information
local function UpdateUnitStatic()
unit.name = regions.name:GetText()
unit.isBoss = regions.dangerskull:IsShown()
unit.isDangerous = unit.isBoss
unit.isElite = regions.eliteicon:IsShown()
end
-- UpdateUnitStatus: Updates Unit Variables
function UpdateUnitStatus()
unit.level = regions.level:GetText() or 1
unit.health = bars.health:GetValue() or 0
_, unit.healthmax = bars.health:GetMinMaxValues()
if InCombat then unit.threatSituation = GetUnitAggroStatus(regions.threatglow) else unit.threatSituation = "LOW" end
unit.isMarked = regions.raidicon:IsShown()
unit.isInCombat = GetUnitCombatStatus(regions.name:GetTextColor())
unit.red, unit.green, unit.blue = bars.health:GetStatusBarColor()
unit.levelcolorRed, levelcolorGreen, levelcolorBlue = regions.level:GetTextColor()
unit.reaction, unit.type = GetUnitReaction(unit.red, unit.green, unit.blue)
unit.class = ClassReference[ColorToString(unit.red, unit.green, unit.blue)] or "UNKNOWN"
unit.InCombatLockdown = InCombat
if regions.raidicon:IsShown() then
ux, uy = regions.raidicon:GetTexCoord()
unit.raidIcon = RaidIconCoordinate[ux][uy]
else unit.raidIcon = false end
end
-- UpdateNameplateStyle
function UpdateNameplateStyle(plate, forceStyleUpdate)
if activetheme.multiStyle then stylename = activetheme.SetStyle(unit); extended.style = activetheme[stylename]
else extended.style = activetheme; stylename = tostring(activetheme) end
if extended.stylename ~= stylename or forceStyleUpdate then UpdateStyle(plate); extended.stylename = stylename; end
style = extended.style
end
-- UpdateUnitCache
local function UpdateUnitCache() for key, value in pairs(unit) do unitcache[key] = value end end
-- UpdateReferences
function UpdateReferences(plate)
unitchanged = false
extended = plate.extended
bars = extended.bars
regions = extended.regions
unit = extended.unit
unitcache = extended.unitcache
visual = extended.visual
end
-- UpdateSpecialRegions
local function UpdateSpecialRegions()
visual.highlight:SetTexture(style.healthborder.glowtexture)
visual.highlight:SetAllPoints(visual.healthborder)
visual.spellicon:SetAlpha(0)
end
-- OnShowNameplate
OnShowNameplate = function(plate)
PlatesVisible[plate] = true
UpdateReferences(plate)
UpdateUnitStatic()
UpdateUnitStatus()
--visual.highlight:SetAlpha(1)
unit.isCasting = false
bars.castbar:Hide()
plate.alpha = plate:GetAlpha()
unit.alpha = plate.alpha
unit.isTarget = false
visual.highlight:Hide()
--UpdateNameplateStyle(plate, true)
UpdateNameplateStyle(plate, false)
UpdateSpecialRegions()
if activetheme.OnInitialize then activetheme.OnInitialize(extended) end
UpdatePlateIndicators(plate)
SetSelfEcho(plate)
end
-- OnHideNameplate
OnHideNameplate = function(plate)
UpdateReferences(plate)
visual.highlight:Hide()
bars.castbar:Hide()
PlatesVisible[plate] = nil
wipe(extended.unit)
wipe(extended.unitcache)
if unit.guid then Units[unit.guid] = nil end
end
-- OnMouseoverNameplate
OnMouseoverNameplate = function(plate)
UpdateReferences(plate)
unit.isMouseover = regions.highlight:IsShown()
if unit.isMouseover then unit.guid = UnitGUID("mouseover")end
UpdatePlateIndicators(plate)
if activetheme.OnUpdate then activetheme.OnUpdate(extended, unit) end
end
-- OnUpdateNameplate
OnUpdateNameplate = function(plate)
UpdateReferences(plate)
UpdateUnitStatus()
unit.alpha = plate.alpha -- Set in PlateHandler's OnUpdate
unit.isTarget = HasTarget and unit.alpha == 1
unit.isMouseover = regions.highlight:IsShown()
if unit.isTarget then unit.guid = UnitGUID("target") end
for key, value in pairs(unit) do if unitcache[key] ~= value then unitchanged = true end end
if unitchanged then
UpdateNameplateStyle(plate)
UpdatePlateIndicators(plate)
end
if unit.raidIcon then visual.raidicon:Show(); visual.raidicon:SetTexCoord(regions.raidicon:GetTexCoord())
else visual.raidicon:Hide() end
UpdateUnitCache()
if activetheme.OnUpdate then activetheme.OnUpdate(extended, unit) end
end
-- OnStartCastNameplate, OnStopCastNameplate
OnStartCast = function(plate)
UpdateReferences(plate)
if not bars.cast:IsShown() then return end
local spell, rank, displayName, icon, startTime, endTime, isTradeSkill, castID, notInterruptible
spell, rank, displayName, icon, startTime, endTime, isTradeSkill, castID, notInterruptible = UnitCastingInfo("target")
if not spell then
spell, rank, displayName, icon, startTime, endTime, isTradeSkill, notInterruptible = UnitChannelInfo("target")
end
if spell then
unit.isCasting = true
--UpdateUnitStatus()
UpdateSpecialRegions()
UpdatePlateIndicators(plate)
--UpdateUnitCache()
bars.castbar:SetStatusBarColor(bars.cast:GetStatusBarColor())
bars.castbar:SetMinMaxValues(bars.cast:GetMinMaxValues())
bars.castbar:SetValue(bars.cast:GetValue())
bars.castbar:Show()
visual.spellicon:SetTexture(icon)
if notInterruptible then
visual.castnostop:Show(); visual.castborder:Hide()
else visual.castnostop:Hide(); visual.castborder:Show() end
--SetSelfEcho(plate)
end
--unit.isCasting = false
end
OnStopCast = function(plate)
UpdateReferences(plate)
UpdatePlateIndicators(plate)
unit.isCasting = false
SetSelfEcho(plate)
bars.castbar:Hide()
end
OnUpdateCast = function(plate)
UpdateReferences(plate)
if bars.castbar:IsShown() then
local castremain = bars.cast:GetValue()
UpdateSpecialRegions()
bars.castbar:SetStatusBarColor(bars.cast:GetStatusBarColor())
bars.castbar:SetMinMaxValues(bars.cast:GetMinMaxValues())
bars.castbar:SetValue(castremain)
bars.castbar:Show()
else OnStartCast(plate) end
end
end
-------------------------------------------------------
-- ApplyPlateExtension: Applies scripts, hooks, and adds additional frame variables and elements
-------------------------------------------------------
local ApplyPlateExtension
do
local bars, regions, health, castbar, healthbar, visual
local region
function ApplyPlateExtension(plate)
Plates[plate] = true
plate.extended = CreateFrame("Frame", nil, plate)
local extended = plate.extended
extended:SetPoint("CENTER", plate)
extended.style, extended.unit, extended.unitcache, extended.stylecache, extended.widgets = {}, {}, {}, {}, {}
extended.regions, extended.bars, extended.visual = {}, {}, {}
regions = extended.regions
bars = extended.bars
bars.health, bars.cast = plate:GetChildren()
extended.stylename = ""
-- Set Frame Levels and Parent
if (select(4, GetBuildInfo()) > 30300) then
regions.threatglow, regions.healthborder, regions.highlight, regions.name, regions.level,
regions.dangerskull, regions.raidicon, regions.eliteicon = plate:GetRegions()
regions.castborder, regions.castnostop = bars.cast:GetRegions()
else
regions.threatglow, regions.healthborder, regions.castborder, regions.castnostop,
regions.spellicon, regions.highlight, regions.name, regions.level,
regions.dangerskull, regions.raidicon, regions.eliteicon = plate:GetRegions()
end
regions.threatglow:SetTexCoord( 0, 0, 0, 0 )
regions.healthborder:SetTexCoord( 0, 0, 0, 0 )
regions.castborder:SetTexCoord( 0, 0, 0, 0 )
regions.castnostop:SetTexCoord( 0, 0, 0, 0 )
regions.dangerskull:SetTexCoord( 0, 0, 0, 0 )
regions.eliteicon:SetTexCoord( 0, 0, 0, 0 )
regions.name:SetWidth( 000.1 )
regions.level:SetWidth( 000.1 )
regions.raidicon:SetAlpha( 0 )
bars.health:SetStatusBarTexture(EMPTY_TEXTURE)
bars.cast:SetStatusBarTexture(EMPTY_TEXTURE)
-- Create Statusbars
local level = plate:GetFrameLevel()
bars.healthbar = CreateTidyPlatesStatusbar(extended)
bars.castbar = CreateTidyPlatesStatusbar(extended)
health, cast, healthbar, castbar = bars.health, bars.cast, bars.healthbar, bars.castbar
healthbar:SetFrameLevel(level)
castbar:Hide()
castbar:SetFrameLevel(level)
castbar:SetStatusBarColor(1,.8,0)
-- Create Visual Regions
visual = extended.visual
visual.threatborder = healthbar:CreateTexture(nil, "ARTWORK")
visual.specialArt = extended:CreateTexture(nil, "OVERLAY")
visual.specialText = extended:CreateFontString(nil, "OVERLAY")
visual.specialText2 = extended:CreateFontString(nil, "OVERLAY")
--visual.healthborder = extended:CreateTexture(nil, "ARTWORK")
visual.healthborder = extended:CreateTexture(nil, "BACKGROUND")
visual.threatborder = extended:CreateTexture(nil, "OVERLAY")
visual.castborder = castbar:CreateTexture(nil, "ARTWORK")
visual.castnostop = castbar:CreateTexture(nil, "ARTWORK")
visual.spellicon = castbar:CreateTexture(nil, "OVERLAY")
visual.dangerskull = extended:CreateTexture(nil, "OVERLAY")
visual.raidicon = extended:CreateTexture(nil, "OVERLAY")
visual.eliteicon = extended:CreateTexture(nil, "OVERLAY")
visual.name = healthbar:CreateFontString(nil, "ARTWORK")
visual.level = healthbar:CreateFontString(nil, "ARTWORK")
visual.name:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")
visual.level:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")
visual.specialText:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")
visual.specialText2:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")
visual.highlight = regions.highlight
visual.raidicon:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
visual.dangerskull:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Skull")
local bg = CreateFrame("StatusBar", nil, extended)
bg:SetWidth(SIZENAMEPLATES.WIDTH)
bg:SetHeight(SIZENAMEPLATES.HEIGHT)
bg:SetStatusBarTexture("Interface\\Addons\\ArenaSpectator\\BarTexture2")
bg:SetStatusBarColor(0, 0, 0)
bg:SetPoint("CENTER", 0, -5)
bg:SetFrameLevel(0)
bg:Show()
healthbar.hptext = healthbar:CreateFontString()
healthbar.hptext:SetFont(STANDARD_TEXT_FONT, SIZENAMEPLATES.TEXTSIZE, "OUTLINE")
healthbar.hptext:SetPoint("RIGHT", -5, 0)
healthbar.hptext:SetText("100%")
healthbar.nametext = healthbar:CreateFontString()
healthbar.nametext:SetFont(STANDARD_TEXT_FONT, SIZENAMEPLATES.TEXTSIZE, "OUTLINE")
healthbar.nametext:SetPoint("LEFT", 5, 0)
healthbar.nametext:SetText("Unknown")
-- print(bg)
-- bars.healthbar:SetTexture(0, 0, 0, 1)
-- Update Immediately
OnShowNameplate(plate)
UpdateReferences(plate)
UpdateUnitStatus()
UpdateNameplateStyle(plate)
UpdatePlateIndicators(plate)
-- Hook for Updates
plate:HookScript("OnShow", OnShowNameplate)
plate:HookScript("OnHide", OnHideNameplate)
--cast:HookScript("OnShow", function () OnStartCast(plate) end)
cast:HookScript("OnHide", function () OnStopCast(plate) end)
cast:HookScript("OnValueChanged", function () OnUpdateCast(plate) end)
health:HookScript("OnValueChanged", function () SetSelfEcho(plate) end)
end
end
-------------------------------------------------------
-- World Update Functions
-------------------------------------------------------
local OnUpdate, UpdateAll
do
local plate, curChildren
local PlateSetAlpha, PlateGetAlpha
-- IsFrameNameplate: Checks to see if the frame is a Blizz nameplate
local function IsFrameNameplate(frame)
local region = frame:GetRegions()
return region and region:GetObjectType() == "Texture" and region:GetTexture() == "Interface\\TargetingFrame\\UI-TargetingFrame-Flash"
end
-- OnWorldFrameChange: Checks for new Blizz Plates
local function OnWorldFrameChange(...)
UpdateSelfHealthBar()
for index = 1, select("#", ...) do
plate = select(index, ...)
if not Plates[plate] and IsFrameNameplate(plate) then
ApplyPlateExtension(plate)
if not PlateSetAlpha then
PlateSetAlpha = plate.SetAlpha
PlateGetAlpha = plate.GetAlpha
end
end
end
end
--
function ForEachPlate(functionToRun, ...)
for plate in pairs(PlatesVisible) do
if plate.extended:IsShown() then -- Plate and extended frame both explicitly visible
functionToRun(plate, ...)
end
end
end
--
do
-- This is the function that ForEachPlate calls repeatedly after UpdateAll requests an update
local function CallOnUpdate(plate, force)
if force then
local extended = plate.extended
extended.unitcache = wipe(extended.unitcache)
extended.stylename = ""
OnShowNameplate(plate)
else
OnUpdateNameplate(plate)
end
end
-- UpdateAll: Requests an update on all Tidy Plates Frames
UpdateAll = function(force) ForEachPlate(CallOnUpdate, force) end
end
-- OnUpdate: This function will look for new frames under the WorldFrame
OnUpdate = function(self)
curChildren = WorldFrame:GetNumChildren()
if (curChildren ~= numChildren) then
numChildren = curChildren
OnWorldFrameChange(WorldFrame:GetChildren())
end
if (HasTarget) then -- Restore full opacity
for plate in pairs(PlatesVisible) do
-- Save original alpha before reset
plate.alpha = PlateGetAlpha(plate)
PlateSetAlpha(plate, 1) -- Local copies of methods are faster than table method lookups
if echoSelf[plate] then
OnUpdateNameplate(plate)
echoSelf[plate] = nil
end
end
else
for plate in pairs(echoSelf) do
echoSelf[plate] = nil
OnUpdateNameplate(plate)
end
end
--[[ Testing; If I'm going to be using OnUpdate, why not use it to determine mouseover
if plate.regions.highlight:IsShown() then
print(mouseover)
end
--]]
if echoUpdate > 0 then UpdateAll(false);echoUpdate = echoUpdate - 1; end
end
end
-------------------------------------------------------
-- Event Handlers
-------------------------------------------------------
do
local events = {}
local PlateHandler = CreateFrame("Frame", nil, WorldFrame)
PlateHandler:SetFrameStrata("TOOLTIP") -- When parented to WorldFrame, causes OnUpdate handler to run close to last
PlateHandler:SetScript("OnEvent", function(self, event, ...) events[event]() end)
-- Events
function events:PLAYER_ENTERING_WORLD() PlateHandler:SetScript("OnUpdate", OnUpdate) end
function events:PLAYER_REGEN_ENABLED() InCombat = false; SetEchoUpdate(1); if useAutoHide then SetCVar("nameplateShowEnemies", 0) end end
function events:PLAYER_REGEN_DISABLED() InCombat = true; SetEchoUpdate(1); if useAutoHide then SetCVar("nameplateShowEnemies", 1) end end
function events:PLAYER_TARGET_CHANGED()
HasTarget = UnitExists("target") == 1 -- Must be bool, never nil!
if (not HasTarget) then
for plate in pairs(PlatesVisible) do
plate.alpha = 1
end
end
SetEchoUpdate(1)
end
function events:RAID_TARGET_UPDATE() SetEchoUpdate(1) end
function events:UNIT_THREAT_SITUATION_UPDATE() SetEchoUpdate(1) end
function events:UNIT_LEVEL() SetEchoUpdate(1) end
function events:UPDATE_MOUSEOVER_UNIT() ForEachPlate(OnMouseoverNameplate) end
--function events:UNIT_AURA(arg1, arg2) ForEachPlate(OnMouseoverNameplate); SetEchoUpdate(1)end
function events:PLAYER_CONTROL_LOST() SetEchoUpdate(1) end
function events:PLAYER_CONTROL_GAINED() SetEchoUpdate(1) end
function events:UNIT_FACTION() SetEchoUpdate(1) end
--function events:SPELL_AURA_APPLIED() end
--function events:SPELL_AURA_APPLIED() end
-- Event Registration
for eventname in pairs(events) do PlateHandler:RegisterEvent(eventname) end
end
-------------------------------------------------------
-- External Commands
-------------------------------------------------------
function TidyPlates:ForceUpdate() UpdateAll(true) end
TidyPlates.Update = function() SetEchoUpdate(1) end
function TidyPlates:UseAutoHide(option) useAutoHide = option; if useAutoHide and (not InCombat) then SetCVar("nameplateShowEnemies", 0) end end
function TidyPlates:ActivateTheme(theme) if theme and type(theme) == 'table' then activetheme = theme; end end
-------------------------------------------------------
-- Performance Monitoring
-------------------------------------------------------
TidyPlatesUsageMonitorLink = {}
TidyPlatesUsageMonitorLink.UpdateStyle = UpdateStyle
TidyPlatesUsageMonitorLink.UpdatePlateIndicators = UpdatePlateIndicators
TidyPlatesUsageMonitorLink.OnShowNameplate = OnShowNameplate
TidyPlatesUsageMonitorLink.OnUpdateNameplate = OnUpdateNameplate
TidyPlatesUsageMonitorLink.OnMouseoverNameplate = OnMouseoverNameplate
TidyPlatesUsageMonitorLink.ApplyPlateExtension = ApplyPlateExtension
TidyPlatesUsageMonitorLink.OnUpdate = OnUpdate
local healthbar, border
function CreateSelfHealthBar()
local yOffset = 22
bg = CreateFrame("StatusBar", nil, WorldFrame)
bg:SetWidth(SIZENAMEPLATES.WIDTH + 2)
bg:SetHeight(SIZENAMEPLATES.HEIGHT + 2)
bg:SetStatusBarTexture("Interface\\Addons\\ArenaSpectator\\BarTexture2")
bg:SetStatusBarColor(0, 0, 0)
bg:SetPoint("CENTER", 0, yOffset)
bg:SetFrameLevel(0)
bg:Show()
healthbar = CreateFrame("StatusBar", nil, bg)
healthbar:SetWidth(SIZENAMEPLATES.WIDTH)
healthbar:SetHeight(SIZENAMEPLATES.HEIGHT)
healthbar:SetStatusBarTexture("Interface\\Addons\\ArenaSpectator\\BarTexture2")
healthbar:SetPoint("CENTER", 0, 0)
healthbar:Show()
healthbar.hptext = healthbar:CreateFontString()
healthbar.hptext:SetFont(STANDARD_TEXT_FONT, 8, "OUTLINE")
healthbar.hptext:SetPoint("RIGHT", -5, 0)
healthbar.hptext:SetText("100%")
healthbar.nametext = healthbar:CreateFontString()
healthbar.nametext:SetFont(STANDARD_TEXT_FONT, 8, "OUTLINE")
healthbar.nametext:SetPoint("LEFT", 5, 0)
border = CreateFrame("frame", nil, bg)
border:SetPoint("TOPLEFT", -1, 1)
border:SetPoint("BOTTOMRIGHT", 1, -1)
-- healthbar.nametext:SetText(players[watch].name)
end
function UpdateSelfHealthBar()
if watch ~= nil then
local hasPlatesEnabled = false
for plate in pairs(PlatesVisible) do
hasPlatesEnabled = true
break
end
if hasPlatesEnabled then
bg:Show()
if ATPlayers[watch].name ~= nil then
healthbar.nametext:SetText(ATPlayers[watch].name)
end
local health, maxhealth = ATPlayers[watch].health, ATPlayers[watch].maxhealth
healthbar.hptext:SetText(math.ceil(health / maxhealth * 100) .. "%")
healthbar:SetMinMaxValues(0, maxhealth)
healthbar:SetValue(health)
if ATPlayers[watch].class ~= nil then
teamId = GetPlayerTeamByName(ATPlayers[watch].name)
if (teamId) then
border:SetBackdrop({
bgFile = "",
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
tile = true,
tileSize = 2,
edgeSize = 2,
})
if (teamId == 67) then
border:SetBackdropBorderColor(1.0, 0.0, 0.0, 0.75)
else
border:SetBackdropBorderColor(0.0, 0.5, 1.0, 0.75)
end
end
local class = ClassToTexture(ATPlayers[watch].class)
local c = RAID_CLASS_COLORS[class]
healthbar:SetStatusBarColor(c.r, c.g, c.b)
end
else
border:SetBackdrop(nil)
bg:Hide()
end
else
bg:Hide()
-- healthbar.nametext:SetText(UnitName("player"))
-- local health, maxhealth = UnitHealth("player"), UnitHealthMax("player")
-- healthbar.hptext:SetText(math.ceil(health / maxhealth * 100) .. "%")
-- healthbar:SetMinMaxValues(0, maxhealth)
-- healthbar:SetValue(health)
-- _, class = UnitClass("player")
-- local c = RAID_CLASS_COLORS[class]
-- healthbar:SetStatusBarColor(c.r, c.g, c.b)
end
end
CreateSelfHealthBar()