forked from vikinghug/VikingNameplates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VikingNameplates.lua
1432 lines (1191 loc) · 51.4 KB
/
VikingNameplates.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
-----------------------------------------------------------------------------------------------
-- Client Lua Script for VikingNameplates
-- Copyright (c) NCsoft. All rights reserved
-----------------------------------------------------------------------------------------------
require "Window"
require "ChallengesLib"
require "Unit"
require "GameLib"
require "Apollo"
require "PathMission"
require "Quest"
require "Episode"
require "math"
require "string"
require "DialogSys"
require "PublicEvent"
require "PublicEventObjective"
require "CommunicatorLib"
require "GroupLib"
require "PlayerPathLib"
require "GuildLib"
require "GuildTypeLib"
local VikingNameplates = {}
-- TODO Delete strings:
-- VikingNameplates_GuildDisplay
-- Disabled DrawLevel as it isn't currently being used
-- Disabled castBarLabel as it isn't currently being used
-- Disabled healthHealthLabel as it isn't currently being used
-----------------------------------------------------------------------------------------------
-- Constants
-----------------------------------------------------------------------------------------------
local knHealthRed = 0.3
local knHealthYellow = 0.5
local tColors = {
black = ApolloColor.new("ff201e2d"),
white = ApolloColor.new("ffffffff"),
lightGrey = ApolloColor.new("ffbcb7da"),
green = ApolloColor.new("cc06ff5e"),
yellow = ApolloColor.new("ffffd161"),
lightPurple = ApolloColor.new("ff645f7e"),
purple = ApolloColor.new("ff28253a"),
red = ApolloColor.new("ffe05757"),
blue = ApolloColor.new("cc49e8ee")
}
local karDisposition =
{
tTextColors =
{
[Unit.CodeEnumDisposition.Hostile] = tColors.red,
[Unit.CodeEnumDisposition.Neutral] = tColors.lightGrey,
[Unit.CodeEnumDisposition.Friendly] = tColors.green,
},
tTargetPrimary =
{
[Unit.CodeEnumDisposition.Hostile] = "CRB_VikingNameplates:sprNP_BaseSelectedRed",
[Unit.CodeEnumDisposition.Neutral] = "CRB_VikingNameplates:sprNP_BaseSelectedYellow",
[Unit.CodeEnumDisposition.Friendly] = "CRB_VikingNameplates:sprNP_BaseSelectedGreen",
},
tTargetSecondary =
{
[Unit.CodeEnumDisposition.Hostile] = "sprNp_Target_HostileSecondary",
[Unit.CodeEnumDisposition.Neutral] = "sprNp_Target_NeutralSecondary",
[Unit.CodeEnumDisposition.Friendly] = "sprNp_Target_FriendlySecondary",
},
tHealthBar =
{
[Unit.CodeEnumDisposition.Hostile] = "CRB_VikingNameplates:sprNP_RedProg",
[Unit.CodeEnumDisposition.Neutral] = "CRB_VikingNameplates:sprNP_YellowProg",
[Unit.CodeEnumDisposition.Friendly] = "CRB_VikingNameplates:sprNP_GreenProg",
},
tHealthTextColor =
{
[Unit.CodeEnumDisposition.Hostile] = tColors.red,
[Unit.CodeEnumDisposition.Neutral] = tColors.lightGrey,
[Unit.CodeEnumDisposition.Friendly] = tColors.green,
},
}
local ktHealthBarSprites =
{
"sprNp_Health_FillGreen",
"sprNp_Health_FillOrange",
"sprNp_Health_FillRed"
}
local karConColors = -- differential value, color
{
{-4, ApolloColor.new("ConTrivial")},
{-3, ApolloColor.new("ConInferior")},
{-2, ApolloColor.new("ConMinor")},
{-1, ApolloColor.new("ConEasy")},
{0, ApolloColor.new("ConAverage")},
{1, ApolloColor.new("ConModerate")},
{2, ApolloColor.new("ConTough")},
{3, ApolloColor.new("ConHard")},
{4, ApolloColor.new("ConImpossible")}
}
local kcrScalingHex = "ffffbf80"
local kcrScalingCColor = CColor.new(1.0, 191/255, 128/255, 0.7)
local karPathSprite =
{
[PlayerPathLib.PlayerPathType_Soldier] = "CRB_TargetFrameRewardPanelSprites:sprTargetFrame_PathSol",
[PlayerPathLib.PlayerPathType_Settler] = "CRB_TargetFrameRewardPanelSprites:sprTargetFrame_PathSet",
[PlayerPathLib.PlayerPathType_Scientist] = "CRB_TargetFrameRewardPanelSprites:sprTargetFrame_PathSci",
[PlayerPathLib.PlayerPathType_Explorer] = "CRB_TargetFrameRewardPanelSprites:sprTargetFrame_PathExp",
}
local knCharacterWidth = 8 -- the average width of a character in the font used. TODO: Not this.
local knRewardWidth = 23 -- the width of a reward icon + padding
local knTextHeight = 15 -- text window height
local knNameRewardWidth = 400 -- the width of the name/reward container
local knNameRewardHeight = 20 -- the width of the name/reward container
local knTargetRange = 40000 -- the distance^2 that normal nameplates should draw within (max targeting range)
local knNameplatePoolLimit = 500 -- the window pool max size
-- Todo: break these out onto options
local kcrUnflaggedGroupmate = ApolloColor.new("DispositionFriendlyUnflaggedDull")
local kcrUnflaggedGuildmate = ApolloColor.new("DispositionGuildmateUnflagged")
local kcrUnflaggedAlly = ApolloColor.new("DispositionFriendlyUnflagged")
local kcrFlaggedAlly = ApolloColor.new("DispositionFriendly")
local kcrUnflaggedEnemyWhenUnflagged = ApolloColor.new("DispositionNeutral")
local kcrFlaggedEnemyWhenUnflagged = ApolloColor.new("DispositionPvPFlagMismatch")
local kcrUnflaggedEnemyWhenFlagged = ApolloColor.new("DispositionPvPFlagMismatch")
local kcrFlaggedEnemyWhenFlagged = ApolloColor.new("DispositionHostile")
local kcrDeadColor = ApolloColor.new("crayGray")
local kcrDefaultTaggedColor = ApolloColor.new("crayGray")
-- Control types
-- 0 - custom
-- 1 - single check
local karSavedProperties =
{
--General nameplate drawing
["bShowMainObjectiveOnly"] = { default=true, nControlType=1, strControlName="MainShowObjectives" },
["bShowMainGroupOnly"] = { default=true, nControlType=1, strControlName="MainShowGroup" },
["bShowMyNameplate"] = { default=false, nControlType=1, strControlName="MainShowMine" },
["bShowOrganization"] = { default=true, nControlType=1, strControlName="MainShowOrganization" },
["bShowVendor"] = { default=true, nControlType=1, strControlName="MainShowVendors" },
["bShowTaxi"] = { default=true, nControlType=1, strControlName="MainShowTaxis" },
["bShowDispositionHostile"] = { default=true, nControlType=1, strControlName="MainShowDisposition_1" },
["bShowDispositionNeutral"] = { default=false, nControlType=1, strControlName="MainShowDisposition_2" },
["bShowDispositionFriendly"] = { default=false, nControlType=1, strControlName="MainShowDisposition_3" },
["bShowDispositionFriendlyPlayer"] = { default=false, nControlType=1, strControlName="MainShowDisposition_FriendlyPlayer" },
["bUseOcclusion"] = { default=true, nControlType=1, strControlName="MainUseOcclusion" },
--Draw distance
["nMaxRange"] = { default=70.0, nControlType=0 },
--Individual
["bShowNameMain"] = { default=true, nControlType=1, strControlName="IndividualShowName", fnCallback="OnSettingNameChanged" },
["bShowTitle"] = { default=true, nControlType=1, strControlName="IndividualShowAffiliation", fnCallback="OnSettingTitleChanged" },
["bShowCertainDeathMain"] = { default=true, nControlType=1, strControlName="IndividualShowCertainDeath" },
["bShowCastBarMain"] = { default=false, nControlType=1, strControlName="IndividualShowCastBar" },
["bShowRewardsMain"] = { default=true, nControlType=1, strControlName="IndividualShowRewardIcons", fnCallback="UpdateAllNameplateRewards" },
["bShowThreatIndicator"] = { default=false, nControlType=1, strControlName="IndividualShowThreatIndicator", fnCallback="OnSettingThreatIndicatorChanged" },
["bShowInterrupt"] = { default=false, nControlType=1, strControlName="IndividualShowInterrupt", fnCallback="OnSettingInterruptChanged" },
--Reward icons
["bShowRewardTypeQuest"] = { default=true, nControlType=1, strControlName="ShowRewardTypeQuest", fnCallback="UpdateAllNameplateRewards" },
["bShowRewardTypeMission"] = { default=true, nControlType=1, strControlName="ShowRewardTypeMission", fnCallback="UpdateAllNameplateRewards" },
["bShowRewardTypeAchievement"] = { default=false, nControlType=1, strControlName="ShowRewardTypeAchievement", fnCallback="UpdateAllNameplateRewards" },
["bShowRewardTypeChallenge"] = { default=true, nControlType=1, strControlName="ShowRewardTypeChallenge", fnCallback="UpdateAllNameplateRewards" },
["bShowRewardTypeReputation"] = { default=false, nControlType=1, strControlName="ShowRewardTypeReputation", fnCallback="UpdateAllNameplateRewards" },
["bShowRewardTypePublicEvent"] = { default=true, nControlType=1, strControlName="ShowRewardTypePublicEvent", fnCallback="UpdateAllNameplateRewards" },
["bShowRivals"] = { default=true, nControlType=1, strControlName="ShowRewardTypeRival", fnCallback="UpdateAllNameplateRewards" },
["bShowFriends"] = { default=true, nControlType=1, strControlName="ShowRewardTypeFriend", fnCallback="UpdateAllNameplateRewards" },
--Info panel
["bShowHealthMain"] = { default=false, nControlType=0, fnCallback="OnSettingHealthChanged" },
["bShowHealthMainDamaged"] = { default=true, nControlType=0, fnCallback="OnSettingHealthChanged" },
--target components
["bShowMarkerTarget"] = { default=true, nControlType=1, strControlName="TargetedShowMarker" },
["bShowNameTarget"] = { default=true, nControlType=1, strControlName="TargetedShowName", fnCallback="OnSettingNameChanged" },
["bShowRewardsTarget"] = { default=true, nControlType=1, strControlName="TargetedShowRewards"},
["bShowGuildNameTarget"] = { default=true, nControlType=1, strControlName="TargetedShowGuild", fnCallback="OnSettingTitleChanged" },
["bShowHealthTarget"] = { default=true, nControlType=1, strControlName="TargetedShowHealth", fnCallback="OnSettingHealthChanged" },
["bShowRangeTarget"] = { default=false, nControlType=0 },
["bShowCastBarTarget"] = { default=true, nControlType=1, strControlName="TargetedShowCastBar" },
--Non-targeted nameplates in combat
["bHideInCombat"] = { default=false, nControlType=0 }
}
function VikingNameplates:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
o.arPreloadUnits = {}
o.bAddonRestoredOrLoaded = false
o.arWindowPool = {}
o.arUnit2Nameplate = {}
o.arWnd2Nameplate = {}
o.bPlayerInCombat = false
o.guildDisplayed = nil
o.guildWarParty = nil
return o
end
function VikingNameplates:Init()
local tDependencies = {
"VikingLibrary",
"Tooltips",
"RewardIcons"
}
Apollo.RegisterAddon(self, true, "VikingNameplates", tDependencies)
end
function VikingNameplates:OnDependencyError(strDependency, strError)
return true
end
-----------------------------------------------------------------------------------------------
-- VikingNameplates OnLoad
-----------------------------------------------------------------------------------------------
function VikingNameplates:OnLoad()
Apollo.RegisterEventHandler("UnitCreated", "OnPreloadUnitCreated", self)
self.xmlDoc = XmlDoc.CreateFromFile("VikingNameplates.xml")
self.xmlDoc:RegisterCallback("OnDocumentReady", self)
end
function VikingNameplates:OnPreloadUnitCreated(unitNew)
self.arPreloadUnits[unitNew:GetId()] = unitNew
end
function VikingNameplates:OnDocumentReady()
Apollo.RemoveEventHandler("UnitCreated", self)
if self.xmlDoc == nil then
return
end
Apollo.RegisterEventHandler("WindowManagementReady", "OnWindowManagementReady", self)
Apollo.RegisterEventHandler("UnitCreated", "OnUnitCreated", self)
Apollo.RegisterEventHandler("UnitDestroyed", "OnUnitDestroyed", self)
Apollo.RegisterEventHandler("VarChange_FrameCount", "OnFrame", self)
Apollo.RegisterEventHandler("UnitTextBubbleCreate", "OnUnitTextBubbleToggled", self)
Apollo.RegisterEventHandler("UnitTextBubblesDestroyed", "OnUnitTextBubbleToggled", self)
Apollo.RegisterEventHandler("TargetUnitChanged", "OnTargetUnitChanged", self)
Apollo.RegisterEventHandler("UnitEnteredCombat", "OnEnteredCombat", self)
Apollo.RegisterEventHandler("UnitNameChanged", "OnUnitNameChanged", self)
Apollo.RegisterEventHandler("UnitTitleChanged", "OnUnitTitleChanged", self)
Apollo.RegisterEventHandler("PlayerTitleChange", "OnPlayerTitleChanged", self)
Apollo.RegisterEventHandler("UnitGuildNameplateChanged", "OnUnitGuildNameplateChanged",self)
--Apollo.RegisterEventHandler("UnitLevelChanged", "OnUnitLevelChanged", self)
Apollo.RegisterEventHandler("UnitMemberOfGuildChange", "OnUnitMemberOfGuildChange", self)
Apollo.RegisterEventHandler("GuildChange", "OnGuildChange", self)
Apollo.RegisterEventHandler("UnitGibbed", "OnUnitGibbed", self)
local tRewardUpdateEvents = {
"QuestObjectiveUpdated", "QuestStateChanged", "ChallengeAbandon", "ChallengeLeftArea",
"ChallengeFailTime", "ChallengeFailArea", "ChallengeActivate", "ChallengeCompleted",
"ChallengeFailGeneric", "PublicEventObjectiveUpdate", "PublicEventUnitUpdate",
"PlayerPathMissionUpdate", "FriendshipAdd", "FriendshipPostRemove", "FriendshipUpdate"
}
for i, str in pairs(tRewardUpdateEvents) do
Apollo.RegisterEventHandler(str, "UpdateAllNameplateRewards", self)
end
self.wndMain = Apollo.LoadForm(self.xmlDoc, "VikingNameplatesForm", nil, self)
Apollo.RegisterTimerHandler("VisibilityTimer", "OnVisibilityTimer", self)
Apollo.CreateTimer("VisibilityTimer", 0.5, true)
self.wndOptionsMain = Apollo.LoadForm(self.xmlDoc, "StandardModule", self.wndMain:FindChild("ContentMain"), self)
self.wndOptionsTargeted = Apollo.LoadForm(self.xmlDoc, "TargetedModule", self.wndMain:FindChild("ContentTarget"), self)
self.wndMain:Show(false)
self.wndMain:FindChild("ContentMain"):Show(true)
self.wndMain:FindChild("ContentTarget"):Show(false)
self.wndMain:FindChild("ContentToggleContainer:NormalViewCheck"):SetCheck(true)
self.arUnit2Nameplate = {}
self.arWnd2Nameplate = {}
for property,tData in pairs(karSavedProperties) do
if self[property] == nil then
self[property] = tData.default
end
if tData.nControlType == 1 then
local wndControl = self.wndMain:FindChild(tData.strControlName)
if wndControl ~= nil then
wndControl:SetData(property)
end
end
end
for key, guildCurr in pairs(GuildLib.GetGuilds()) do
local eGuildType = guildCurr:GetType()
if eGuildType == GuildLib.GuildType_Guild then
self.guildDisplayed = guildCurr
end
if eGuildType == GuildLib.GuildType_WarParty then
self.guildWarParty = guildCurr
end
end
-- Cache defaults
local wndTemp = Apollo.LoadForm(self.xmlDoc, "NameplateNew", nil, self)
self.nFrameLeft, self.nFrameTop, self.nFrameRight, self.nFrameBottom = wndTemp:FindChild("Container:Health:HealthBars:MaxHealth"):GetAnchorOffsets()
self.nHealthWidth = self.nFrameRight - self.nFrameLeft
wndTemp:Destroy()
self:CreateUnitsFromPreload()
end
function VikingNameplates:OnSave(eType)
if eType ~= GameLib.CodeEnumAddonSaveLevel.Character then
return
end
local tSave = {}
for property,tData in pairs(karSavedProperties) do
tSave[property] = self[property]
end
return tSave
end
function VikingNameplates:OnRestore(eType, tSavedData)
if eType ~= GameLib.CodeEnumAddonSaveLevel.Character then
return
end
for property,tData in pairs(karSavedProperties) do
if tSavedData[property] ~= nil then
self[property] = tSavedData[property]
end
end
self:CreateUnitsFromPreload()
end
function VikingNameplates:OnWindowManagementReady()
Event_FireGenericEvent("WindowManagementAdd", {wnd = self.wndMain, strName = Apollo.GetString("Nameplates_Options")})
end
function VikingNameplates:CreateUnitsFromPreload()
if self.bAddonRestoredOrLoaded then
self.unitPlayer = GameLib.GetPlayerUnit()
-- Process units created while form was loading
for idUnit, unitNew in pairs(self.arPreloadUnits) do
self:OnUnitCreated(unitNew)
end
self.arPreloadUnits = nil
end
self.bAddonRestoredOrLoaded = true
end
function VikingNameplates:OnVisibilityTimer()
self:UpdateAllNameplateVisibility()
end
function VikingNameplates:UpdateAllNameplateRewards()
for idx, tNameplate in pairs(self.arUnit2Nameplate) do
self:UpdateNameplateRewardInfo(tNameplate)
end
end
function VikingNameplates:UpdateNameplateRewardInfo(tNameplate)
local tFlags =
{
bVert = false,
bHideQuests = not self.bShowRewardTypeQuest,
bHideChallenges = not self.bShowRewardTypeChallenge,
bHideMissions = not self.bShowRewardTypeMission,
bHidePublicEvents = not self.bShowRewardTypePublicEvent,
bHideRivals = not self.bShowRivals,
bHideFriends = not self.bShowFriends
}
if RewardIcons ~= nil and RewardIcons.GetUnitRewardIconsForm ~= nil then
RewardIcons.GetUnitRewardIconsForm(tNameplate.wnd.questRewards, tNameplate.unitOwner, tFlags)
end
end
function VikingNameplates:UpdateAllNameplateVisibility()
for idx, tNameplate in pairs(self.arUnit2Nameplate) do
self:UpdateNameplateVisibility(tNameplate)
end
end
function VikingNameplates:UpdateNameplateVisibility(tNameplate)
tNameplate.bOnScreen = tNameplate.wndNameplate:IsOnScreen()
tNameplate.bOccluded = tNameplate.wndNameplate:IsOccluded()
tNameplate.eDisposition = tNameplate.unitOwner:GetDispositionTo(self.unitPlayer)
local bNewShow = self:HelperVerifyVisibilityOptions(tNameplate) and self:CheckDrawDistance(tNameplate)
if bNewShow ~= tNameplate.bShow then
tNameplate.wndNameplate:Show(bNewShow)
tNameplate.bShow = bNewShow
end
end
function VikingNameplates:OnUnitCreated(unitNew) -- build main options here
if not unitNew:ShouldShowNamePlate()
or unitNew:GetType() == "Collectible"
or unitNew:GetType() == "PinataLoot" then
-- Never have nameplates
return
end
local idUnit = unitNew:GetId()
if self.arUnit2Nameplate[idUnit] ~= nil and self.arUnit2Nameplate[idUnit].wndNameplate:IsValid() then
return
end
local wnd = nil
local wndReferences = nil
if next(self.arWindowPool) ~= nil then
local poolEntry = table.remove(self.arWindowPool)
wnd = poolEntry[1]
wndReferences = poolEntry[2]
end
if wnd == nil or not wnd:IsValid() then
wnd = Apollo.LoadForm(self.xmlDoc, "NameplateNew", "InWorldHudStratum", self)
wndReferences = nil
end
wnd:Show(false, true)
wnd:SetUnit(unitNew, 1)
local tNameplate =
{
unitOwner = unitNew,
idUnit = unitNew:GetId(),
wndNameplate = wnd,
bOnScreen = wnd:IsOnScreen(),
bOccluded = wnd:IsOccluded(),
bSpeechBubble = false,
bHasThreat = false,
bIsTarget = false,
bIsCluster = false,
bIsCasting = false,
bGibbed = false,
bIsGuildMember = self.guildDisplayed and self.guildDisplayed:IsUnitMember(unitNew) or false,
bIsWarPartyMember = self.guildWarParty and self.guildWarParty:IsUnitMember(unitNew) or false,
nVulnerableTime = 0,
eDisposition = unitNew:GetDispositionTo(self.unitPlayer),
bShow = false,
wnd = wndReferences,
}
if wndReferences == nil then
tNameplate.wnd =
{
health = wnd:FindChild("Container:Health"),
background = wnd:FindChild("Container:BackgroundContainer"),
castBar = wnd:FindChild("Container:CastBar"),
vulnerable = wnd:FindChild("Container:Vulnerable"),
guild = wnd:FindChild("Guild"),
name = wnd:FindChild("NameRewardContainer:Name"),
certainDeath = wnd:FindChild("TargetAndDeathContainer:CertainDeath"),
targetScalingMark = wnd:FindChild("TargetScalingMark"),
nameRewardContainer = wnd:FindChild("NameRewardContainer:RewardContainer"),
healthMaxShield = wnd:FindChild("Container:Health:HealthBars:MaxShield"),
healthHealthFill = wnd:FindChild("Container:Health:HealthBars:MaxHealth:HealthFill"),
healthShieldFill = wnd:FindChild("Container:Health:HealthBars:MaxShield:ShieldFill"),
healthMaxAbsorb = wnd:FindChild("Container:Health:HealthBars:MaxAbsorb"),
healthAbsorbFill = wnd:FindChild("Container:Health:HealthBars:MaxAbsorb:AbsorbFill"),
healthMaxHealth = wnd:FindChild("Container:Health:HealthBars:MaxHealth"),
--healthHealthLabel = wnd:FindChild("Container:Health:HealthLabel"),
--castBarLabel = wnd:FindChild("Container:CastBar:Label"),
castBarCastFill = wnd:FindChild("Container:CastBar:CastFill"),
vulnerableVulnFill = wnd:FindChild("Container:Vulnerable:VulnFill"),
questRewards = wnd:FindChild("NameRewardContainer:RewardContainer:QuestRewards"),
targetMarkerArrow = wnd:FindChild("TargetAndDeathContainer:TargetMarkerArrow"),
threatIndicator = wnd:FindChild("Container:ThreatIndicatorContainer:ThreatIndicatorMarker"),
interrupt = wnd:FindChild("Container:InterruptContainer:InterruptMarker")
}
end
self.arUnit2Nameplate[idUnit] = tNameplate
self.arWnd2Nameplate[wnd:GetId()] = tNameplate
self:DrawName(tNameplate)
self:DrawGuild(tNameplate)
--self:DrawLevel(tNameplate)
self:UpdateNameplateRewardInfo(tNameplate)
self:DrawRewards(tNameplate)
self:DrawThreatIndicator(tNameplate)
self:DrawInterrupt(tNameplate)
end
function VikingNameplates:OnUnitDestroyed(unitOwner)
local idUnit = unitOwner:GetId()
if self.arUnit2Nameplate[idUnit] == nil then
return
end
local tNameplate = self.arUnit2Nameplate[idUnit]
local wndNameplate = tNameplate.wndNameplate
self.arWnd2Nameplate[wndNameplate:GetId()] = nil
if #self.arWindowPool < knNameplatePoolLimit then
wndNameplate:Show(false, true)
wndNameplate:SetUnit(nil)
table.insert(self.arWindowPool, {wndNameplate, tNameplate.wnd})
else
wndNameplate:Destroy()
end
self.arUnit2Nameplate[idUnit] = nil
end
function VikingNameplates:OnFrame()
self.unitPlayer = GameLib.GetPlayerUnit()
for idx, tNameplate in pairs(self.arUnit2Nameplate) do
self:DrawNameplate(tNameplate)
end
end
function VikingNameplates:DrawNameplate(tNameplate)
if not tNameplate.bShow then
return
end
local unitPlayer = self.unitPlayer
local unitOwner = tNameplate.unitOwner
local wndNameplate = tNameplate.wndNameplate
if unitOwner:IsMounted() and wndNameplate:GetUnit() == unitOwner then
wndNameplate:SetUnit(unitOwner:GetUnitMount(), 1)
elseif not unitOwner:IsMounted() and wndNameplate:GetUnit() ~= unitOwner then
wndNameplate:SetUnit(unitOwner, 1)
end
self:DrawHealth(tNameplate)
local nCon = self:HelperCalculateConValue(unitOwner)
tNameplate.wnd.certainDeath:Show(self.bShowCertainDeathMain and nCon == #karConColors and tNameplate.eDisposition ~= Unit.CodeEnumDisposition.Friendly and unitOwner:GetHealth() and unitOwner:ShouldShowNamePlate() and not unitOwner:IsDead())
tNameplate.wnd.targetScalingMark:Show(unitOwner:IsScaled())
self:DrawRewards(tNameplate)
self:DrawCastBar(tNameplate)
self:DrawVulnerable(tNameplate)
self:ColorNameplate(tNameplate)
self:DrawThreatIndicator(tNameplate)
self:DrawInterrupt(tNameplate)
end
function VikingNameplates:ColorNameplate(tNameplate)
local unitPlayer = self.unitPlayer
local unitOwner = tNameplate.unitOwner
local wndNameplate = tNameplate.wndNameplate
local eDisposition = tNameplate.eDisposition
local nCon = self:HelperCalculateConValue(unitOwner)
local crLevelColorToUse = karConColors[nCon][2]
if tNameplate.wnd.targetScalingMark:IsShown() then
crLevelColorToUse = kcrScalingCColor
elseif unitOwner:GetLevel() == nil then
crLevelColorToUse = karConColors[1][2]
end
local crColorToUse = karDisposition.tTextColors[eDisposition]
local unitController = unitOwner:GetUnitOwner() or unitOwner
local strUnitType = unitOwner:GetType()
if strUnitType == "Player" or strUnitType == "Pet" or strUnitType == "Esper Pet" then
if eDisposition == Unit.CodeEnumDisposition.Friendly or unitOwner:IsThePlayer() then
crColorToUse = kcrUnflaggedAlly
if unitController:IsPvpFlagged() then
crColorToUse = kcrFlaggedAlly
elseif unitController:IsInYourGroup() then
crColorToUse = kcrUnflaggedGroupmate
elseif tNameplate.bIsGuildMember then
crColorToUse = kcrUnflaggedGuildmate
end
else
local bIsUnitFlagged = unitController:IsPvpFlagged()
local bAmIFlagged = GameLib.IsPvpFlagged()
if not bAmIFlagged and not bIsUnitFlagged then
crColorToUse = kcrUnflaggedEnemyWhenUnflagged
elseif bAmIFlagged and not bIsUnitFlagged then
crColorToUse = kcrUnflaggedEnemyWhenFlagged
elseif not bAmIFlagged and bIsUnitFlagged then
crColorToUse = kcrFlaggedEnemyWhenUnflagged
elseif bAmIFlagged and bIsUnitFlagged then
crColorToUse = kcrFlaggedEnemyWhenFlagged
end
end
end
if unitOwner:GetType() ~= "Player" and unitOwner:IsTagged() and not unitOwner:IsTaggedByMe() and not unitOwner:IsSoftKill() then
crColorToUse = kcrDefaultTaggedColor
end
if unitOwner:IsDead() then
crColorToUse = kcrDeadColor
crLevelColorToUse = kcrDeadColor
end
--tNameplate.wnd.level:SetTextColor(crLevelColorToUse)
tNameplate.wnd.name:SetTextColor(crColorToUse)
tNameplate.wnd.guild:SetTextColor(crColorToUse)
end
function VikingNameplates:DrawName(tNameplate)
local wndNameplate = tNameplate.wndNameplate
local unitOwner = tNameplate.unitOwner
local wndName = tNameplate.wnd.name
local bUseTarget = tNameplate.bIsTarget
local bShow = self.bShowNameMain
if bUseTarget then
bShow = self.bShowNameTarget
end
if wndName:IsShown() ~= bShow then
wndName:Show(bShow)
end
if bShow then
local strNewName
if self.bShowTitle then
strNewName = unitOwner:GetTitleOrName()
else
strNewName = unitOwner:GetName()
end
if wndName:GetText() ~= strNewName then
local wndNameRewardContainer = tNameplate.wnd.nameRewardContainer
local nNameWidth = Apollo.GetTextWidth("VikingNameplates", strNewName)
local nHalfNameWidth = math.ceil(nNameWidth / 2)
-- Rewards also depend on name
local nLeft, nTop, nRight, nBottom = wndNameRewardContainer:GetAnchorOffsets()
wndNameRewardContainer:SetAnchorOffsets(nHalfNameWidth, nTop, nHalfNameWidth + wndNameRewardContainer:ArrangeChildrenHorz(0), nBottom)
wndName:SetText(strNewName)
end
end
end
function VikingNameplates:DrawGuild(tNameplate)
local wndNameplate = tNameplate.wndNameplate
local unitOwner = tNameplate.unitOwner
local wndGuild = tNameplate.wnd.guild
local bUseTarget = tNameplate.bIsTarget
local bShow = self.bShowTitle
if bUseTarget then
bShow = self.bShowGuildNameTarget
end
local strNewGuild = unitOwner:GetAffiliationName()
if unitOwner:GetType() == "Player" and strNewGuild ~= nil and strNewGuild ~= "" then
strNewGuild = String_GetWeaselString(Apollo.GetString("Nameplates_GuildDisplay"), strNewGuild)
end
if strNewGuild ~= wndGuild:GetText() then
wndGuild:SetTextRaw(strNewGuild)
end
local bShow = bShow and strNewGuild ~= nil and strNewGuild ~= ""
if wndGuild:IsShown() ~= bShow then
wndGuild:Show(bShow)
wndNameplate:ArrangeChildrenVert(2)
end
end
function VikingNameplates:DrawLevel(tNameplate)
local unitOwner = tNameplate.unitOwner
tNameplate.wnd.level:SetText(unitOwner:GetLevel() or "-")
end
function VikingNameplates:DrawHealth(tNameplate)
local wndNameplate = tNameplate.wndNameplate
local unitOwner = tNameplate.unitOwner
local wndHealth = tNameplate.wnd.health
if unitOwner:GetHealth() == nil then
self:ToggleNamePlatesVisiblity(tNameplate, false)
return
end
local bUseTarget = tNameplate.bIsTarget
if bUseTarget then
self:ToggleNamePlatesVisiblity(tNameplate, self.bShowHealthTarget)
else
if self.bShowHealthMain then
self:ToggleNamePlatesVisiblity(tNameplate, true)
elseif self.bShowHealthMainDamaged then
self:ToggleNamePlatesVisiblity(tNameplate, unitOwner:GetHealth() ~= unitOwner:GetMaxHealth())
else
self:ToggleNamePlatesVisiblity(tNameplate, false)
end
end
if wndHealth:IsShown() then
self:HelperDoHealthShieldBar(wndHealth, unitOwner, tNameplate.eDisposition, tNameplate)
end
end
function VikingNameplates:ToggleNamePlatesVisiblity(tNameplate, bShow)
tNameplate.wnd.background:Show(bShow)
tNameplate.wnd.health:Show(bShow)
end
function VikingNameplates:DrawCastBar(tNameplate)
local wndNameplate = tNameplate.wndNameplate
local unitOwner = tNameplate.unitOwner
-- Casting; has some onDraw parameters we need to check
tNameplate.bIsCasting = unitOwner:ShouldShowCastBar()
local bShowTarget = tNameplate.bIsTarget
local wndCastBar = tNameplate.wnd.castBar
local bShow = tNameplate.bIsCasting and self.bShowCastBarMain
if tNameplate.bIsCasting and bShowTarget then
bShow = self.bShowCastBarTarget
end
wndCastBar:Show(bShow)
if bShow then
--tNameplate.wnd.castBarLabel:SetText(unitOwner:GetCastName())
tNameplate.wnd.castBarCastFill:SetMax(unitOwner:GetCastDuration())
tNameplate.wnd.castBarCastFill:SetProgress(unitOwner:GetCastElapsed())
end
end
function VikingNameplates:DrawVulnerable(tNameplate)
local wndNameplate = tNameplate.wndNameplate
local unitOwner = tNameplate.unitOwner
local bUseTarget = tNameplate.bIsTarget
local wndVulnerable = tNameplate.wnd.vulnerable
local bIsVulnerable = false
if (not bUseTarget and (self.bShowHealthMain or self.bShowHealthMainDamaged)) or (bUseTarget and self.bShowHealthTarget) then
local nVulnerable = unitOwner:GetCCStateTimeRemaining(Unit.CodeEnumCCState.Vulnerability)
if nVulnerable == nil then
wndVulnerable:Show(false)
elseif nVulnerable == 0 and nVulnerable ~= tNameplate.nVulnerableTime then
tNameplate.nVulnerableTime = 0 -- casting done, set back to 0
wndVulnerable:Show(false)
elseif nVulnerable ~= 0 and nVulnerable > tNameplate.nVulnerableTime then
tNameplate.nVulnerableTime = nVulnerable
wndVulnerable:Show(true)
bIsVulnerable = true
elseif nVulnerable ~= 0 and nVulnerable < tNameplate.nVulnerableTime then
tNameplate.wnd.vulnerableVulnFill:SetMax(tNameplate.nVulnerableTime)
tNameplate.wnd.vulnerableVulnFill:SetProgress(nVulnerable)
bIsVulnerable = true
end
end
end
function VikingNameplates:DrawRewards(tNameplate)
local wndNameplate = tNameplate.wndNameplate
local unitOwner = tNameplate.unitOwner
local bUseTarget = tNameplate.bIsTarget
local bShow = self.bShowRewardsMain
if bUseTarget then
bShow = self.bShowRewardsTarget
end
tNameplate.wnd.questRewards:Show(bShow)
local tRewardsData = tNameplate.wnd.questRewards:GetData()
if bShow and tRewardsData ~= nil and tRewardsData.nIcons ~= nil and tRewardsData.nIcons > 0 then
local strName = tNameplate.wnd.name:GetText()
local nNameWidth = Apollo.GetTextWidth("CRB_Interface9_BBO", strName)
local nHalfNameWidth = nNameWidth / 2
local wndnameRewardContainer = tNameplate.wnd.nameRewardContainer
local nLeft, nTop, nRight, nBottom = wndnameRewardContainer:GetAnchorOffsets()
wndnameRewardContainer:SetAnchorOffsets(nHalfNameWidth, nTop, nHalfNameWidth + wndnameRewardContainer:ArrangeChildrenHorz(0), nBottom)
end
end
function VikingNameplates:DrawTargeting(tVikingNameplates)
local wndNameplate = tNameplate.wndNameplate
local unitOwner = tNameplate.unitOwner
local bUseTarget = tNameplate.bIsTarget
local bShowTargetMarkerArrow = bUseTarget and self.bShowMarkerTarget and not tVikingNameplates.wnd.health:IsShown()
tNameplate.wnd.targetMarkerArrow:SetSprite(karDisposition.tTargetSecondary[tNameplate.eDisposition])
tNameplate.wnd.targetMarkerArrow:Show(bShowTargetMarkerArrow, not bShowTargetMarkerArrow)
end
function VikingNameplates:DrawThreatIndicator(tNameplate)
local unitOwner = tNameplate.unitOwner
local bShow = self.bShowThreatIndicator
local bHasThreat = unitOwner:GetTarget() == self.unitPlayer
local bIsAlive = not unitOwner:IsDead()
local bIsPlayer = unitOwner:GetType() == "Player"
tNameplate.wnd.threatIndicator:Show(bShow and bHasThreat and bIsAlive and not bIsPlayer)
end
function VikingNameplates:DrawInterrupt(tNameplate)
local unitOwner = tNameplate.unitOwner
local nArmorValue = unitOwner:GetInterruptArmorValue()
local nMaxArmor = unitOwner:GetInterruptArmorMax()
local bShow = self.bShowInterrupt
local bInfinite = nMaxArmor == -1
local bHasArmor = nArmorValue > 0
local bIsDead = unitOwner:IsDead()
local bDisplayIfDamage = self.bShowHealthMainDamaged
local bPlayerIsDamaged = unitOwner:GetHealth() ~= unitOwner:GetMaxHealth()
if not bShow or not bDisplayIfDamage then
tNameplate.wnd.interrupt:Show(false)
return
end
if nMaxArmor == 0 or nArmorValue == nil or bIsDead then
tNameplate.wnd.interrupt:Show(false)
else
tNameplate.wnd.interrupt:Show(true)
if nMaxArmor == -1 then
tNameplate.wnd.interrupt:SetTextColor("xkcdPastelOrange")
tNameplate.wnd.interrupt:SetText("X")
elseif nArmorValue == 0 and nMaxArmor > 0 then
tNameplate.wnd.interrupt:SetText("0")
elseif nMaxArmor > 0 then
tNameplate.wnd.interrupt:SetText(nArmorValue)
end
end
end
function VikingNameplates:CheckDrawDistance(tNameplate)
local unitPlayer = self.unitPlayer
local unitOwner = tNameplate.unitOwner
if not unitOwner or not unitPlayer then
return false
end
tPosTarget = unitOwner:GetPosition()
tPosPlayer = unitPlayer:GetPosition()
if tPosTarget == nil then
return
end
local nDeltaX = tPosTarget.x - tPosPlayer.x
local nDeltaY = tPosTarget.y - tPosPlayer.y
local nDeltaZ = tPosTarget.z - tPosPlayer.z
local nDistance = (nDeltaX * nDeltaX) + (nDeltaY * nDeltaY) + (nDeltaZ * nDeltaZ)
if tNameplate.bIsTarget or tNameplate.bIsCluster then
bInRange = nDistance < knTargetRange
return bInRange
else
bInRange = nDistance < (self.nMaxRange * self.nMaxRange) -- squaring for quick maths
return bInRange
end
end
function VikingNameplates:HelperVerifyVisibilityOptions(tNameplate)
local unitPlayer = self.unitPlayer
local unitOwner = tNameplate.unitOwner
local eDisposition = tNameplate.eDisposition
local bHiddenUnit = not unitOwner:ShouldShowNamePlate()
if bHiddenUnit and not tNameplate.bIsTarget then
return false
end
if (self.bUseOcclusion and tNameplate.bOccluded) or not tNameplate.bOnScreen then
return false
end
if tNameplate.bGibbed or tNameplate.bSpeechBubble then
return false
end
local bShowNameplate = false
if self.bShowMainObjectiveOnly and tNameplate.bIsObjective then
bShowNameplate = true
end
if self.bShowMainGroupOnly and unitOwner:IsInYourGroup() then
bShowNameplate = true
end
if self.bShowDispositionHostile and eDisposition == Unit.CodeEnumDisposition.Hostile then
bShowNameplate = true
end
if self.bShowDispositionNeutral and eDisposition == Unit.CodeEnumDisposition.Neutral then
bShowNameplate = true
end
if self.bShowDispositionFriendly and eDisposition == Unit.CodeEnumDisposition.Friendly then
bShowNameplate = true
end
if self.bShowDispositionFriendlyPlayer and eDisposition == Unit.CodeEnumDisposition.Friendly and unitOwner:GetType() == "Player" then
bShowNameplate = true
end
local tActivation = unitOwner:GetActivationState()
if self.bShowVendor and tActivation.Vendor ~= nil then
bShowNameplate = true
end
if self.bShowTaxi and (tActivation.FlightPathSettler ~= nil or tActivation.FlightPath ~= nil or tActivation.FlightPathNew) then
bShowNameplate = true
end
if self.bShowOrganization and tNameplate.bIsGuildMember then
bShowNameplate = true
end
if self.bShowMainObjectiveOnly then
-- QuestGivers too
if tActivation.QuestReward ~= nil then
bShowNameplate = true
end
if tActivation.QuestNew ~= nil or tActivation.QuestNewMain ~= nil then
bShowNameplate = true
end
if tActivation.QuestReceiving ~= nil then
bShowNameplate = true
end
if tActivation.TalkTo ~= nil then
bShowNameplate = true
end
end
if bShowNameplate then
bShowNameplate = not (self.bPlayerInCombat and self.bHideInCombat)
end
if unitOwner:IsThePlayer() then
if self.bShowMyNameplate and not unitOwner:IsDead() then
bShowNameplate = true
else
bShowNameplate = false
end
end
return bShowNameplate or tNameplate.bIsTarget
end
function VikingNameplates:HelperDoHealthShieldBar(wndHealth, unitOwner, eDisposition, tNameplate)
local nVulnerabilityTime = unitOwner:GetCCStateTimeRemaining(Unit.CodeEnumCCState.Vulnerability)
if unitOwner:GetType() == "Simple" or unitOwner:GetHealth() == nil then
--tNameplate.wnd.healthHealthLabel:SetText("")
return
end
local wndHealth = tNameplate.wnd.healthHealthFill
local wndShield = tNameplate.wnd.healthShieldFill
local wndAbsorb = tNameplate.wnd.healthAbsorbFill
local nHealthCurr = unitOwner:GetHealth()
local nHealthMax = unitOwner:GetMaxHealth()
local nShieldCurr = unitOwner:GetShieldCapacity()
local nShieldMax = unitOwner:GetShieldCapacityMax()
local nAbsorbCurr = 0
local nAbsorbMax = unitOwner:GetAbsorptionMax()
if nAbsorbMax > 0 then
nAbsorbCurr = unitOwner:GetAbsorptionValue() -- Since it doesn't clear when the buff drops off
end
local nTotalMax = nHealthMax + nShieldMax + nAbsorbMax