-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathVikingUnitFrames.lua
executable file
·905 lines (696 loc) · 26.3 KB
/
VikingUnitFrames.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
require "Window"
require "Unit"
require "GameLib"
require "Apollo"
require "ApolloColor"
require "Window"
local VikingLib
local VikingUnitFrames = {
_VERSION = 'VikingUnitFrames.lua 0.1.0',
_URL = 'https://github.com/vikinghug/VikingUnitFrames',
_DESCRIPTION = '',
_LICENSE = [[
MIT LICENSE
Copyright (c) 2014 Kevin Altman
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
}
-- GameLib.CodeEnumClass.Warrior = 1
-- GameLib.CodeEnumClass.Engineer = 2
-- GameLib.CodeEnumClass.Esper = 3
-- GameLib.CodeEnumClass.Medic = 4
-- GameLib.CodeEnumClass.Stalker = 5
-- GameLib.CodeEnumClass.Spellslinger = 7
local tClassName = {
[GameLib.CodeEnumClass.Warrior] = "Warrior",
[GameLib.CodeEnumClass.Engineer] = "Engineer",
[GameLib.CodeEnumClass.Esper] = "Esper",
[GameLib.CodeEnumClass.Medic] = "Medic",
[GameLib.CodeEnumClass.Stalker] = "Stalker",
[GameLib.CodeEnumClass.Spellslinger] = "Spellslinger"
}
local tClassToSpriteMap = {
[GameLib.CodeEnumClass.Warrior] = "VikingSprites:ClassWarrior",
[GameLib.CodeEnumClass.Engineer] = "VikingSprites:ClassEngineer",
[GameLib.CodeEnumClass.Esper] = "VikingSprites:ClassEsper",
[GameLib.CodeEnumClass.Medic] = "VikingSprites:ClassMedic",
[GameLib.CodeEnumClass.Stalker] = "VikingSprites:ClassStalker",
[GameLib.CodeEnumClass.Spellslinger] = "VikingSprites:ClassSpellslinger"
}
local tRankToSpriteMap = {
[Unit.CodeEnumRank.Elite] = "spr_TargetFrame_ClassIcon_Elite",
[Unit.CodeEnumRank.Superior] = "spr_TargetFrame_ClassIcon_Superior",
[Unit.CodeEnumRank.Champion] = "spr_TargetFrame_ClassIcon_Champion",
[Unit.CodeEnumRank.Standard] = "spr_TargetFrame_ClassIcon_Standard",
[Unit.CodeEnumRank.Minion] = "spr_TargetFrame_ClassIcon_Minion",
[Unit.CodeEnumRank.Fodder] = "spr_TargetFrame_ClassIcon_Fodder"
}
local tTargetMarkSpriteMap = {
"Icon_Windows_UI_CRB_Marker_Bomb",
"Icon_Windows_UI_CRB_Marker_Ghost",
"Icon_Windows_UI_CRB_Marker_Mask",
"Icon_Windows_UI_CRB_Marker_Octopus",
"Icon_Windows_UI_CRB_Marker_Pig",
"Icon_Windows_UI_CRB_Marker_Chicken",
"Icon_Windows_UI_CRB_Marker_Toaster",
"Icon_Windows_UI_CRB_Marker_UFO"
}
function VikingUnitFrames:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function VikingUnitFrames:Init()
Apollo.RegisterAddon(self, nil, nil, {"VikingLibrary"})
end
function VikingUnitFrames:OnLoad()
self.xmlDoc = XmlDoc.CreateFromFile("VikingUnitFrames.xml")
self.xmlDoc:RegisterCallback("OnDocumentReady", self)
end
function VikingUnitFrames:OnDocumentReady()
if self.xmlDoc == nil then
return
end
Apollo.RegisterEventHandler("WindowManagementReady" , "OnWindowManagementReady" , self)
Apollo.RegisterEventHandler("WindowManagementUpdate" , "OnWindowManagementUpdate" , self)
Apollo.RegisterEventHandler("TargetUnitChanged" , "OnTargetUnitChanged" , self)
Apollo.RegisterEventHandler("AlternateTargetUnitChanged" , "OnFocusUnitChanged" , self)
Apollo.RegisterEventHandler("PlayerLevelChange" , "OnUnitLevelChange" , self)
Apollo.RegisterEventHandler("UnitLevelChanged" , "OnUnitLevelChange" , self)
Apollo.RegisterEventHandler("VarChange_FrameCount" , "OnFrame" , self)
Apollo.RegisterEventHandler("ChangeWorld" , "OnWorldChanged" , self)
Apollo.RegisterEventHandler("UnitDestroyed" , "OnUnitDestroyed" , self)
Apollo.RegisterSlashCommand("focus", "OnFocusSlashCommand", self)
Apollo.RegisterSlashCommand("targetfocus", "OnTargetfocusSlashCommand", self)
self.bDocLoaded = true
self:OnRequiredFlagsChanged()
end
function VikingUnitFrames:OnWindowManagementReady()
Event_FireGenericEvent("WindowManagementAdd", { wnd = self.tPlayerFrame.wndUnitFrame, strName = "Viking Player Frame" })
Event_FireGenericEvent("WindowManagementAdd", { wnd = self.tTargetFrame.wndUnitFrame, strName = "Viking Target Frame" })
Event_FireGenericEvent("WindowManagementAdd", { wnd = self.tFocusFrame.wndUnitFrame, strName = "Viking Focus Target" })
Event_FireGenericEvent("WindowManagementAdd", { wnd = self.tToTFrame.wndUnitFrame, strName = "Viking Target of Target Frame" })
end
function VikingUnitFrames:OnRequiredFlagsChanged()
if GameLib.GetPlayerUnit() then
self:OnCharacterLoaded()
else
Apollo.RegisterEventHandler("CharacterCreated", "OnCharacterLoaded", self)
end
end
function VikingUnitFrames:OnWindowManagementUpdate(tWindow)
if tWindow and tWindow.wnd and (tWindow.wnd == self.tPlayerFrame.wndUnitFrame or tWindow.wnd == self.tTargetFrame.wndUnitFrame or tWindow.wnd == self.tFocusFrame.wndUnitFrame) then
local bMoveable = tWindow.wnd:IsStyleOn("Moveable")
tWindow.wnd:SetStyle("Sizable", bMoveable)
tWindow.wnd:SetStyle("RequireMetaKeyToMove", bMoveable)
tWindow.wnd:SetStyle("IgnoreMouse", not bMoveable)
end
end
function VikingUnitFrames:OnUnitLevelChange()
self:SetUnitLevel(self.tPlayerFrame)
self:SetUnitLevel(self.tTargetFrame)
end
--
-- CreateUnitFrame
--
-- Builds a UnitFrame instance
function VikingUnitFrames:CreateUnitFrame(name)
local sFrame = "t" .. name .. "Frame"
local wndUnitFrame = Apollo.LoadForm(self.xmlDoc, "UnitFrame", "FixedHudStratumLow" , self)
local tFrame = {
name = name,
wndUnitFrame = wndUnitFrame,
wndHealthBar = wndUnitFrame:FindChild("Bars:Health"),
wndShieldBar = wndUnitFrame:FindChild("Bars:Shield"),
wndAbsorbBar = wndUnitFrame:FindChild("Bars:Absorb"),
wndCastBar = wndUnitFrame:FindChild("Bars:Cast"),
wndTargetMark = wndUnitFrame:FindChild("TargetExtra:Mark"),
wndInterrupt = wndUnitFrame:FindChild("TargetExtra:InterruptArmor"),
bCasting = false
}
tFrame.wndUnitFrame:SetSizingMinimum(140, 60)
tFrame.locDefaultPosition = WindowLocation.new(self.db.char.position[name:lower() .. "Frame"])
tFrame.wndUnitFrame:MoveToLocation(tFrame.locDefaultPosition)
self:InitColors(tFrame)
return tFrame
end
function VikingUnitFrames:GetDefaults()
local tColors = VikingLib.Settings.GetColors()
return {
char = {
style = 0,
position = {
playerFrame = {
fPoints = {0.5, 1, 0.5, 1},
nOffsets = {-350, -200, -100, -120}
},
targetFrame = {
fPoints = {0.5, 1, 0.5, 1},
nOffsets = {100, -200, 350, -120}
},
focusFrame = {
fPoints = {0, 1, 0, 1},
nOffsets = {40, -500, 250, -440}
},
totFrame = {
fPoints = {0.5, 1, 0.5, 1},
nOffsets = {350, -300, 600, -220}
}
},
textStyle = {
Value = false,
Percent = true,
BigNumberFormat = true,
OutlineFont = false,
},
castBar = {
PlayerCastBar = true,
TargetCastBar = true,
FocusCastBar = true,
ToTCastBar = true,
},
buffs = {
BuffGoodShow = true,
BuffBadShow = true,
},
colors = {
Health = { high = "ff" .. tColors.green, average = "ff" .. tColors.yellow, low = "ff" .. tColors.red },
Shield = { high = "ff" .. tColors.blue, average = "ff" .. tColors.blue, low = "ff" .. tColors.blue },
Absorb = { high = "ff" .. tColors.yellow, average = "ff" .. tColors.yellow, low = "ff" .. tColors.yellow },
},
ToT = {
ToTFrame = true
}
}
}
end
--
-- OnCharacterLoaded
--
--
function VikingUnitFrames:OnCharacterLoaded()
local playerUnit = GameLib.GetPlayerUnit()
if not playerUnit then
return
end
if VikingLib == nil then
VikingLib = Apollo.GetAddon("VikingLibrary")
end
if VikingLib ~= nil then
self.db = VikingLib.Settings.RegisterSettings(self, "VikingUnitFrames", self:GetDefaults(), "Unit Frames")
self.generalDb = self.db.parent
end
-- PlayerFrame
self.tPlayerFrame = self:CreateUnitFrame("Player")
self:SetUnit(self.tPlayerFrame, playerUnit)
self:SetUnitName(self.tPlayerFrame, playerUnit:GetName())
self:SetUnitLevel(self.tPlayerFrame)
self.tPlayerFrame.wndUnitFrame:Show(true, false)
self:SetClass(self.tPlayerFrame)
-- Target Frame
self.tTargetFrame = self:CreateUnitFrame("Target")
self:UpdateUnitFrame(self.tTargetFrame, GameLib.GetTargetUnit())
-- Focus Frame
self.tFocusFrame = self:CreateUnitFrame("Focus")
self:UpdateUnitFrame(self.tFocusFrame, playerUnit:GetAlternateTarget())
-- ToT Frame
self.tToTFrame = self:CreateUnitFrame("ToT")
self.eClassID = playerUnit:GetClassId()
end
local LoadingTimer
function VikingUnitFrames:OnWorldChanged()
self:OnRequiredFlagsChanged()
LoadingTimer = ApolloTimer.Create(0.01, true, "OnLoading", self)
end
function VikingUnitFrames:OnLoading()
local playerUnit = GameLib.GetPlayerUnit()
if not playerUnit then return end
self:SetUnit(self.tPlayerFrame, playerUnit)
self:SetUnitLevel(self.tPlayerFrame)
self.tPlayerFrame.unit = playerUnit
LoadingTimer:Stop()
end
--
-- OnTargetUnitChanged
--
function VikingUnitFrames:OnTargetUnitChanged(unit)
self:UpdateUnitFrame(self.tTargetFrame, unit)
end
--
-- OnFocusUnitChanged
--
function VikingUnitFrames:OnFocusUnitChanged(unit)
self:UpdateUnitFrame(self.tFocusFrame, unit)
end
function VikingUnitFrames:UpdateUnitFrame(tFrame, unit)
tFrame.wndUnitFrame:Show(unit ~= nil)
if unit ~= nil then
self:SetUnit(tFrame, unit)
self:SetUnitName(tFrame, unit:GetName())
self:SetClass(tFrame)
end
end
function VikingUnitFrames:OnFocusSlashCommand()
local unitTarget = GameLib.GetTargetUnit()
GameLib.GetPlayerUnit():SetAlternateTarget(unitTarget)
end
function VikingUnitFrames:OnTargetfocusSlashCommand()
local unitTarget = GameLib.GetPlayerUnit():GetAlternateTarget()
GameLib.SetTargetUnit(unitTarget)
end
--
-- OnFrame
--
-- Render loop
function VikingUnitFrames:OnFrame()
if not self.tPlayerFrame.unit then return end
if self.tPlayerFrame ~= nil and self.tTargetFrame ~= nil then
-- UnitFrame
self:UpdateBars(self.tPlayerFrame)
self:SetInterruptArmor(self.tPlayerFrame)
-- TargetFrame
self:UpdateBars(self.tTargetFrame)
self:SetUnitLevel(self.tTargetFrame)
self:SetInterruptArmor(self.tTargetFrame)
-- FocusFrame
self:UpdateBars(self.tFocusFrame)
self:SetUnitLevel(self.tFocusFrame)
self:SetInterruptArmor(self.tFocusFrame)
-- ToTFrame
if self.db.char.ToT["ToTFrame"] == true then
local targetOfTarget = GameLib:GetPlayerUnit():GetTargetOfTarget()
self:UpdateUnitFrame(self.tToTFrame, targetOfTarget)
else
self:UpdateUnitFrame(self.tToTFrame, nil)
end
self:UpdateBars(self.tToTFrame)
self:SetUnitLevel(self.tToTFrame)
self:SetInterruptArmor(self.tToTFrame)
end
end
--
-- UpdateBars
--
-- Update the bars for a unit on UnitFrame
function VikingUnitFrames:UpdateBars(tFrame)
local tHealthMap = {
bar = "Health",
current = "GetHealth",
max = "GetMaxHealth"
}
local tShieldMap = {
bar = "Shield",
current = "GetShieldCapacity",
max = "GetShieldCapacityMax"
}
local tAbsorbMap = {
bar = "Absorb",
current = "GetAbsorptionValue",
max = "GetAbsorptionMax"
}
self:ShowCastBar(tFrame)
self:ShowBuffBar(tFrame)
self:SetBar(tFrame, tHealthMap)
self:SetBar(tFrame, tShieldMap)
self:SetBar(tFrame, tAbsorbMap)
self:SetTargetMark(tFrame)
end
-- SetBar
--
-- Set Bar Value on UnitFrame
function VikingUnitFrames:SetBar(tFrame, tMap)
if tFrame.unit ~= nil and tMap ~= nil then
local unit = tFrame.unit
local nCurrent = unit[tMap.current](unit)
local nMax = unit[tMap.max](unit)
local wndBar = tFrame["wnd" .. tMap.bar .. "Bar"]
local wndProgress = wndBar:FindChild("ProgressBar")
local wndText = wndBar:FindChild("Text")
local sProgressMax = self:NumberToHuman(nMax)
local sProgressCurr = self:NumberToHuman(nCurrent)
local sText = ""
--Temp fix for shiled not displaying correctly when gear is changed
if nCurrent ~= nil and tMap.bar == "Shield" and nCurrent > nMax then
nCurrent = nMax
end
local isValidBar = (nMax ~= nil and nMax ~= 0) and true or false
wndBar:Show(isValidBar, false)
if isValidBar then
wndProgress:SetMax(nMax)
wndProgress:SetProgress(nCurrent)
-- Set text
if self.db.char.textStyle["Value"] and self.db.char.textStyle["Percent"] then
if self.db.char.textStyle["BigNumberFormat"] then
sText = (string.format("%s/%s (%d%%)", sProgressCurr, sProgressMax, math.floor(nCurrent / nMax * 100)))
else
sText = (string.format("%d/%d (%d%%)", nCurrent, nMax, math.floor(nCurrent / nMax * 100)))
end
elseif self.db.char.textStyle["Value"] then
if self.db.char.textStyle["BigNumberFormat"] then
sText = sProgressCurr .. "/" .. sProgressMax
else
sText = nCurrent .. "/" .. nMax
end
elseif self.db.char.textStyle["Percent"] then
sText = math.floor(nCurrent / nMax * 100) .. "%"
else
sText = ""
end
wndText:SetText(sText)
if self.db.char.textStyle["OutlineFont"] then
wndText:SetFont("CRB_InterfaceSmall_O")
else
wndText:SetFont("Default")
end
local nLowBar = 0.3
local nAverageBar = 0.5
-- Set our bar color based on the percent full
local tColors = self.db.char.colors[tMap.bar]
local color = tColors.high
if nCurrent / nMax <= nLowBar then
color = tColors.low
elseif nCurrent / nMax <= nAverageBar then
color = tColors.average
end
wndProgress:SetBarColor(ApolloColor.new(color))
end
end
end
-- Number formating
--
--Uses k instead of 1000
function VikingUnitFrames:NumberToHuman(num)
if num ~= nil and num > 999 then
local decimalPlaces = 10^1
local roundedNum = math.floor(num)
local sizes = {
{ 'Billions', 1000000000 },
{ 'Millions', 1000000 },
{ 'Short', 1000 },
}
for i, value in ipairs(sizes) do
local abbrev = value[1]
local size = value[2]
if roundedNum >= size then
local number = math.floor(roundedNum * decimalPlaces / size) / decimalPlaces
local sType = number % 1 ~= 0 and "Float" or "Whole"
local sFormatString = Apollo.GetString('TargetFrame_' .. abbrev .. 'Number' .. sType)
return String_GetWeaselString(sFormatString, number)
end
end
end
return num
end
--
-- SetClass
--
-- Set Class on UnitFrame
function VikingUnitFrames:SetClass(tFrame)
local sPlayerIconSprite, sRankIconSprite, locNameText
local sUnitType = tFrame.unit:GetType()
if sUnitType == "Player" then
locNameText = { 24, 0, -30, 26 }
sRankIconSprite = ""
sPlayerIconSprite = tClassToSpriteMap[tFrame.unit:GetClassId()]
else
locNameText = { 34, 0, -30, 26 }
sPlayerIconSprite = ""
sRankIconSprite = tRankToSpriteMap[tFrame.unit:GetRank()]
end
tFrame.wndUnitFrame:FindChild("TargetInfo:UnitName"):SetAnchorOffsets(locNameText[1], locNameText[2], locNameText[3], locNameText[4])
tFrame.wndUnitFrame:FindChild("TargetInfo:ClassIcon"):SetSprite(sPlayerIconSprite)
tFrame.wndUnitFrame:FindChild("TargetInfo:RankIcon"):SetSprite(sRankIconSprite)
end
--
-- SetDisposition
--
-- Set Disposition on UnitFrame
function VikingUnitFrames:SetTargetMark(tFrame)
if not tFrame.unit then return else end
local nMarkerID = tFrame.unit:GetTargetMarker() or 0
if nMarkerID ~= 0 then
local sprite = tTargetMarkSpriteMap[nMarkerID]
tFrame.wndTargetMark:Show(true, false)
tFrame.wndTargetMark:SetSprite(sprite)
else
tFrame.wndTargetMark:Show(false, true)
end
end
--
-- SetDisposition
--
-- Set Disposition on UnitFrame
function VikingUnitFrames:SetDisposition(tFrame, targetUnit)
tFrame.disposition = targetUnit:GetDispositionTo(self.tPlayerFrame.unit)
local dispositionColor = ApolloColor.new(self.generalDb.char.dispositionColors[tFrame.disposition])
tFrame.wndUnitFrame:FindChild("TargetInfo:UnitName"):SetTextColor(dispositionColor)
end
--
-- SetUnit
--
-- Set Unit on UnitFrame
function VikingUnitFrames:SetUnit(tFrame, unit)
tFrame.unit = unit
tFrame.wndUnitFrame:FindChild("Good"):SetUnit(unit)
tFrame.wndUnitFrame:FindChild("Bad"):SetUnit(unit)
self:SetDisposition(tFrame, unit)
-- Set the Data to the unit, for mouse events
tFrame.wndUnitFrame:SetData(tFrame.unit)
end
--
-- SetUnitName
--
-- Set Name on UnitFrame
function VikingUnitFrames:SetUnitName(tFrame, sName)
tFrame.wndUnitFrame:FindChild("UnitName"):SetText(sName)
end
--
-- SetUnitLevel
--
-- Set Level on UnitFrame
function VikingUnitFrames:SetUnitLevel(tFrame)
if tFrame.unit == nil then return end
local sLevel = tFrame.unit:GetLevel()
tFrame.wndUnitFrame:FindChild("UnitLevel"):SetText(sLevel)
end
--
-- SetInterruptArmor
--
-- Set Level on UnitFrame
function VikingUnitFrames:SetInterruptArmor(tFrame)
if tFrame.unit == nil then return end
local bShowInterrupt = true
local bIsDead = tFrame.unit:IsDead()
local nInterruptArmorCurrent = tFrame.unit:GetInterruptArmorValue()
local nInterruptArmorMax = tFrame.unit:GetInterruptArmorMax()
if nInterruptArmorMax == 0 or nInterruptArmorCurrent == nil or bIsDead then
bShowInterrupt = false
end
tFrame.wndInterrupt:Show(bShowInterrupt, false)
if not bShowInterrupt then return end
if nInterruptArmorMax == -1 then
nInterruptArmorCurrent = "∞"
end
tFrame.wndInterrupt:FindChild("Text"):SetText(nInterruptArmorCurrent)
end
--
-- InitColor
--
-- Let's initialize some colors from settings
function VikingUnitFrames:InitColors(tFrame)
local colors = {
background = {
wnd = tFrame.wndUnitFrame:FindChild("Background"),
color = ApolloColor.new(self.generalDb.char.colors.background)
},
gradient = {
wnd = tFrame.wndUnitFrame,
color = ApolloColor.new(self.generalDb.char.colors.gradient)
},
interrupt = {
wnd = tFrame.wndInterrupt,
color = ApolloColor.new(self.generalDb.char.colors.gradient)
}
}
for k,v in pairs(colors) do
v.wnd:SetBGColor(v.color)
end
end
-- ShowCastBar
--
-- Check to see if a unit is casting, if so, render the cast bar
function VikingUnitFrames:ShowCastBar(tFrame)
-- If no unit then don't do anything
if tFrame.unit == nil then return end
local bStopCast = false
local bCasting = tFrame.unit:ShouldShowCastBar()
local bShowCastBar = self.db.char.castBar[tFrame.name .. "CastBar"]
if bShowCastBar == false then
bStopCast = true
bCasting = false
self:UpdateCastBar(tFrame, bCasting, bStopCast)
return
end
self:UpdateCastBar(tFrame, bCasting, bStopCast)
end
--ShowBuffBar
--
-- Check to see if Buff's should be displayed
function VikingUnitFrames:ShowBuffBar(tFrame)
-- If no unit then don't do anything
if tFrame.unit == nil then return end
local BuffGood = self.db.char.buffs["BuffGoodShow"]
local BuffBad = self.db.char.buffs["BuffBadShow"]
tFrame.wndUnitFrame:FindChild("Good"):Show(BuffGood)
tFrame.wndUnitFrame:FindChild("Bad"):Show(BuffBad)
end
--
-- UpdateCastBar
--
-- Casts that have timers use this method to indicate their progress
function VikingUnitFrames:UpdateCastBar(tFrame, bCasting, bStopCast)
-- If just started casting
if bCasting and tFrame.bCasting == false then
tFrame.bCasting = true
local wndProgressBar = tFrame.wndCastBar:FindChild("ProgressBar")
local wndText = tFrame.wndCastBar:FindChild("Text")
local sCastName = tFrame.unit:GetCastName()
tFrame.nTimePrevious = 0
tFrame.nTimeMax = tFrame.unit:GetCastDuration()
tFrame.wndCastBar:Show(true, false)
wndProgressBar:SetProgress(0)
wndProgressBar:SetMax(tFrame.nTimeMax)
wndText:SetText(sCastName)
tFrame.CastTimerTick = ApolloTimer.Create(0.01, true, "OnCast" .. tFrame.name .. "FrameTimerTick", self)
elseif tFrame.bCasting == true then
if not bCasting or bCasting and bStopCast then
VikingUnitFrames:KillCastTimer(tFrame)
tFrame.bCasting = false
else return
end
end
end
--
-- Unit Destroyed
--
-- Checks if focussed unit is dead and then remove focus
function VikingUnitFrames:OnUnitDestroyed(unit)
local PlayerUnit = GameLib:GetPlayerUnit()
if PlayerUnit == nil then return end
local DestroyedUnit = unit
local FocusUnit = GameLib:GetPlayerUnit():GetAlternateTarget()
if DestroyedUnit == FocusUnit then
FocusUnit:SetAlternateTarget(nil)
end
end
-----------------------------------------------------------------------------------------------
-- Cast Timer
-----------------------------------------------------------------------------------------------
function VikingUnitFrames:OnCastPlayerFrameTimerTick()
self:UpdateCastTimer(self.tPlayerFrame)
end
function VikingUnitFrames:OnCastTargetFrameTimerTick()
self:UpdateCastTimer(self.tTargetFrame)
end
function VikingUnitFrames:OnCastFocusFrameTimerTick()
self:UpdateCastTimer(self.tFocusFrame)
end
function VikingUnitFrames:OnCastToTFrameTimerTick()
self:UpdateCastTimer(self.tToTFrame)
end
function VikingUnitFrames:UpdateCastTimer(tFrame)
local wndProgressBar = tFrame.wndCastBar:FindChild("ProgressBar")
local nMin = tFrame.unit:GetCastElapsed() or 0
local nTimeCurrent = math.min(nMin, tFrame.nTimeMax)
wndProgressBar:SetProgress(nTimeCurrent, nTimeCurrent - tFrame.nTimePrevious * 1000)
tFrame.nTimePrevious = nTimeCurrent
end
function VikingUnitFrames:KillCastTimer(tFrame)
tFrame.CastTimerTick:Stop()
local wndProgressBar = tFrame.wndCastBar:FindChild("ProgressBar")
wndProgressBar:SetProgress(tFrame.nTimeMax)
tFrame.wndCastBar:Show(false, .002)
end
---------------------------------------------------------------------------------------------------
-- UnitFrame Functions
---------------------------------------------------------------------------------------------------
function VikingUnitFrames:OnMouseButtonUp( wndHandler, wndControl, eMouseButton, nLastRelativeMouseX, nLastRelativeMouseY, bDoubleClick, bStopPropagation )
if wndHandler ~= wndControl then return end
local unit = wndHandler:GetData()
if eMouseButton == GameLib.CodeEnumInputMouse.Left and unit ~= nil then
GameLib.SetTargetUnit(unit)
return
end
-- Player Menu
if eMouseButton == GameLib.CodeEnumInputMouse.Right and unit ~= nil then
Event_FireGenericEvent("GenericEvent_NewContextMenuPlayerDetailed", nil, unit:GetName(), unit)
end
end
function VikingUnitFrames:OnGenerateBuffTooltip(wndHandler, wndControl, tType, splBuff)
if wndHandler == wndControl then
return
end
Tooltip.GetBuffTooltipForm(self, wndControl, splBuff, {bFutureSpell = false})
end
---------------------------------------------------------------------------------------------------
-- VikingSettings Functions
---------------------------------------------------------------------------------------------------
function VikingUnitFrames:UpdateSettingsForm(wndContainer)
-- Text Style
wndContainer:FindChild("TextStyle:Content:Value"):SetCheck(self.db.char.textStyle["Value"])
wndContainer:FindChild("TextStyle:Content:Percent"):SetCheck(self.db.char.textStyle["Percent"])
wndContainer:FindChild("TextStyle:Content:BigNumberFormat"):SetCheck(self.db.char.textStyle["BigNumberFormat"])
wndContainer:FindChild("TextStyle:Content:OutlineFont"):SetCheck(self.db.char.textStyle["OutlineFont"])
--Cast Bar
wndContainer:FindChild("CastBar:Content:PlayerCastBar"):SetCheck(self.db.char.castBar["PlayerCastBar"])
wndContainer:FindChild("CastBar:Content:TargetCastBar"):SetCheck(self.db.char.castBar["TargetCastBar"])
wndContainer:FindChild("CastBar:Content:FocusCastBar"):SetCheck(self.db.char.castBar["FocusCastBar"])
-- Target of Target Frame
wndContainer:FindChild("ToT:Content:ToTFrame"):SetCheck(self.db.char.ToT["ToTFrame"])
-- Buffs
wndContainer:FindChild("Buffs:Content:BuffGoodShow"):SetCheck(self.db.char.buffs["BuffGoodShow"])
wndContainer:FindChild("Buffs:Content:BuffBadShow"):SetCheck(self.db.char.buffs["BuffBadShow"])
-- Bar colors
for sBarName, tBarColorData in pairs(self.db.char.colors) do
local wndColorContainer = wndContainer:FindChild("Colors:Content:" .. sBarName)
if wndColorContainer then
for sColorState, sColor in pairs(tBarColorData) do
local wndColor = wndColorContainer:FindChild(sColorState)
if wndColor then wndColor:SetBGColor(sColor) end
end
end
end
end
function VikingUnitFrames:OnSettingsTextStyle(wndHandler, wndControl, eMouseButton)
self.db.char.textStyle[wndControl:GetName()] = wndControl:IsChecked()
end
function VikingUnitFrames:OnSettingsBarColor( wndHandler, wndControl, eMouseButton )
VikingLib.Settings.ShowColorPickerForSetting(self.db.char.colors[wndControl:GetParent():GetName()], wndControl:GetName(), nil, wndControl)
end
function VikingUnitFrames:OnSettingsCastBar(wndHandler, wndControl, eMouseButton)
self.db.char.castBar[wndControl:GetName()] = wndControl:IsChecked()
end
function VikingUnitFrames:OnSettingsToT(wndHandler, wndControl, eMouseButton)
self.db.char.ToT[wndControl:GetName()] = wndControl:IsChecked()
end
function VikingUnitFrames:OnSettingsBuffs(wndHandler, wndControl, eMouseButton)
self.db.char.buffs[wndControl:GetName()] = wndControl:IsChecked()
end
local VikingUnitFramesInst = VikingUnitFrames:new()
VikingUnitFramesInst:Init()