-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathPlater_Resources.lua
1488 lines (1262 loc) · 57.9 KB
/
Plater_Resources.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local Plater = _G.Plater
local GameCooltip = GameCooltip2
local DF = DetailsFramework
local _
local UnitPower = _G.UnitPower
local UnitPowerMax = _G.UnitPowerMax
local abs = _G.abs
local IS_WOW_PROJECT_MAINLINE = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
local IS_WOW_PROJECT_NOT_MAINLINE = WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE
local IS_WOW_PROJECT_CLASSIC_ERA = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
local IS_WOW_PROJECT_CLASSIC_WRATH = IS_WOW_PROJECT_NOT_MAINLINE and ClassicExpansionAtLeast and LE_EXPANSION_WRATH_OF_THE_LICH_KING and ClassicExpansionAtLeast(LE_EXPANSION_WRATH_OF_THE_LICH_KING)
--local IS_WOW_PROJECT_CLASSIC_CATACLYSM = IS_WOW_PROJECT_NOT_MAINLINE and ClassicExpansionAtLeast and LE_EXPANSION_CATACLYSM and ClassicExpansionAtLeast(LE_EXPANSION_CATACLYSM)
local PlayerClass = select(2, UnitClass("player"))
local CONST_SPECID_MONK_WINDWALKER = 269
local CONST_SPECID_MAGE_ARCANE = 62
local CONST_SPECID_ROGUE_ASSASSINATION = 259
local CONST_SPECID_ROGUE_OUTLAW = 260
local CONST_SPECID_ROGUE_SUBTLETY = 261
local CONST_SPECID_DRUID_FERAL = 103
local CONST_SPECID_PALADIN_HOLY = 65
local CONST_SPECID_PALADIN_PROTECTION = 66
local CONST_SPECID_PALADIN_RETRIBUTION = 70
local CONST_SPECID_WARLOCK_AFFLICTION = 265
local CONST_SPECID_WARLOCK_DEMONOLOGY = 266
local CONST_SPECID_WARLOCK_DESTRUCTION = 267
local CONST_SPECID_DK_UNHOLY = 252
local CONST_SPECID_DK_FROST = 251
local CONST_SPECID_DK_BLOOD = 250
local CONST_SPECID_EVOKER_DEVASTATION = 1467
local CONST_SPECID_EVOKER_PRESERVATION = 1468
local CONST_SPECID_EVOKER_AUGMENTATION = 1473
local CONST_NUM_RESOURCES_WIDGETS = PlayerClass == "DEATHKNIGHT" and 6 or 10
local CONST_WIDGET_WIDTH = 20
local CONST_WIDGET_HEIGHT = 20
--store the time of the last combo point gained in order to play the show animation when a combo point is awarded
local lastComboPointGainedTime = 0
--when 'runOnNextFrame' is used instead of 'C_Timer.After', it's to indicate the func will skip the current frame and run on the next one
local runOnNextFrame = function(func)
_G.C_Timer.After(0, func)
end
--[=[
resource frame: the frame which is anchored into the health bar, controls the size, scale and position
resource bar: is anchored (setallpoints) into the resource frame, hold all combo points textures and animations
widget: is each individual widget representing a single resource
default settings:
alignment settings
resource_padding = 1,
size settings:
block_size = 20,
block_texture_background = "Interface\\COMMON\\Indicator-Gray"
block_texture_artwork = "Interface\\COMMON\\Indicator-Yellow"
block_texture_overlay = "Interface\\CHARACTERFRAME\\TempPortraitAlphaMaskSmall"
--]=]
--this table store the resource creation functions, these functions are declared in the Plater_Resources_Frames file
local resourceWidgetCreationFunctions = {}
function Plater.Resources.GetResourceWidgetCreationTable()
return resourceWidgetCreationFunctions
end
function Plater.Resources.GetCreateResourceWidgetFunctionForSpecId(specId)
--function to create the resource bar
return resourceWidgetCreationFunctions[specId]
end
--store functions to create the widgets for the class and the function to update them
local resourceWidgetsFunctions = {} --this table has created when only monk combo point was finished, perhaps in the future this need to be more organized
--store functions used to create the resource bar for each type of resource
local resourceBarCreateFuncByEnumName = {}
--power
local PowerEnum = Enum.PowerType
local SPELL_POWER_MANA = SPELL_POWER_MANA or (PowerEnum and PowerEnum.Mana) or 0
local SPELL_POWER_RAGE = SPELL_POWER_RAGE or (PowerEnum and PowerEnum.Rage) or 1
local SPELL_POWER_FOCUS = SPELL_POWER_FOCUS or (PowerEnum and PowerEnum.Focus) or 2
local SPELL_POWER_ENERGY = SPELL_POWER_ENERGY or (PowerEnum and PowerEnum.Energy) or 3
local SPELL_POWER_COMBO_POINTS = SPELL_POWER_COMBO_POINTS or (PowerEnum and PowerEnum.ComboPoints) or 4
local SPELL_POWER_RUNES = SPELL_POWER_RUNES or (PowerEnum and PowerEnum.Runes) or 5
local SPELL_POWER_RUNIC_POWER = SPELL_POWER_RUNIC_POWER or (PowerEnum and PowerEnum.RunicPower) or 6
local SPELL_POWER_SOUL_SHARDS = SPELL_POWER_SOUL_SHARDS or (PowerEnum and PowerEnum.SoulShards) or 7
local SPELL_POWER_LUNAR_POWER = SPELL_POWER_LUNAR_POWER or (PowerEnum and PowerEnum.LunarPower) or 8
local SPELL_POWER_HOLY_POWER = SPELL_POWER_HOLY_POWER or (PowerEnum and PowerEnum.HolyPower) or 9
local SPELL_POWER_ALTERNATE_POWER = SPELL_POWER_ALTERNATE_POWER or (PowerEnum and PowerEnum.Alternate) or 10
local SPELL_POWER_MAELSTROM = SPELL_POWER_MAELSTROM or (PowerEnum and PowerEnum.Maelstrom) or 11
local SPELL_POWER_CHI = SPELL_POWER_CHI or (PowerEnum and PowerEnum.Chi) or 12
local SPELL_POWER_INSANITY = SPELL_POWER_INSANITY or (PowerEnum and PowerEnum.Insanity) or 13
local SPELL_POWER_OBSOLETE = SPELL_POWER_OBSOLETE or (PowerEnum and PowerEnum.Obsolete) or 14
local SPELL_POWER_OBSOLETE2 = SPELL_POWER_OBSOLETE2 or (PowerEnum and PowerEnum.Obsolete2) or 15
local SPELL_POWER_ARCANE_CHARGES = SPELL_POWER_ARCANE_CHARGES or (PowerEnum and PowerEnum.ArcaneCharges) or 16
local SPELL_POWER_FURY = SPELL_POWER_FURY or (PowerEnum and PowerEnum.Fury) or 17
local SPELL_POWER_PAIN = SPELL_POWER_PAIN or (PowerEnum and PowerEnum.Pain) or 18
local SPELL_POWER_ESSENCE = SPELL_POWER_ESSENCE or (PowerEnum and PowerEnum.Essence) or 19
local specsWithResource = {
[CONST_SPECID_MONK_WINDWALKER] = true,
[CONST_SPECID_MAGE_ARCANE] = true,
[CONST_SPECID_ROGUE_ASSASSINATION] = true,
[CONST_SPECID_ROGUE_OUTLAW] = true,
[CONST_SPECID_ROGUE_SUBTLETY] = true,
[CONST_SPECID_DRUID_FERAL] = true,
[CONST_SPECID_PALADIN_HOLY] = true,
[CONST_SPECID_PALADIN_PROTECTION] = true,
[CONST_SPECID_PALADIN_RETRIBUTION] = true,
[CONST_SPECID_WARLOCK_AFFLICTION] = true,
[CONST_SPECID_WARLOCK_DEMONOLOGY] = true,
[CONST_SPECID_WARLOCK_DESTRUCTION] = true,
[CONST_SPECID_DK_UNHOLY] = true,
[CONST_SPECID_DK_FROST] = true,
[CONST_SPECID_DK_BLOOD] = true,
[CONST_SPECID_EVOKER_DEVASTATION] = true,
[CONST_SPECID_EVOKER_PRESERVATION] = true,
[CONST_SPECID_EVOKER_AUGMENTATION] = true,
}
local resourceTypes = {
[SPELL_POWER_INSANITY] = true, --shadow priest
[SPELL_POWER_CHI] = true, --monk
[SPELL_POWER_HOLY_POWER] = true, --paladins
[SPELL_POWER_LUNAR_POWER] = true, --balance druids
[SPELL_POWER_SOUL_SHARDS] = true, --warlock affliction
[SPELL_POWER_COMBO_POINTS] = true, --combo points
[SPELL_POWER_MAELSTROM] = true, --shamans
[SPELL_POWER_PAIN] = true, --demonhunter tank
[SPELL_POWER_RUNES] = true, --dk
[SPELL_POWER_ARCANE_CHARGES] = true, --mage
[SPELL_POWER_FURY] = true, --warrior demonhunter dps
[SPELL_POWER_ESSENCE] = true, --evoker
}
local energyTypes = {
[SPELL_POWER_MANA] = true,
[SPELL_POWER_RAGE] = true,
[SPELL_POWER_ENERGY] = true,
[SPELL_POWER_RUNIC_POWER] = true,
[SPELL_POWER_ESSENCE] = true,
}
local resourcePowerType = {
[SPELL_POWER_COMBO_POINTS] = SPELL_POWER_ENERGY, --combo points
[SPELL_POWER_SOUL_SHARDS] = SPELL_POWER_MANA, --warlock
[SPELL_POWER_LUNAR_POWER] = SPELL_POWER_MANA, --druid
[SPELL_POWER_HOLY_POWER] = SPELL_POWER_MANA, --paladin
[SPELL_POWER_INSANITY] = SPELL_POWER_MANA, --shadowpriest
[SPELL_POWER_MAELSTROM] = SPELL_POWER_MANA, --shaman
[SPELL_POWER_CHI] = SPELL_POWER_MANA, --monk
[SPELL_POWER_PAIN] = SPELL_POWER_ENERGY, --demonhuinter
[SPELL_POWER_RUNES] = SPELL_POWER_RUNIC_POWER, --dk
[SPELL_POWER_ARCANE_CHARGES] = SPELL_POWER_MANA, --mage
[SPELL_POWER_FURY] = SPELL_POWER_RAGE, --warrior
[SPELL_POWER_ESSENCE] = SPELL_POWER_MANA, --evoker
}
-- the power types which update functions should update on
local classPowerTypes = {
["ROGUE"] = "COMBO_POINTS",
["MONK"] = "CHI",
["PALADIN"] = "HOLY_POWER",
["WARLOCK"] = "SOUL_SHARDS",
["DRUID"] = "COMBO_POINTS",
["MAGE"] = "ARCANE_CHARGES",
["DEATHKNIGHT"] = "RUNES",
["EVOKER"] = "ESSENCE",
}
local doesClassUseResource = function(class)
return classPowerTypes[class]
end
local doesSpecUseResource = function(specId)
return specsWithResource[specId]
end
--these power types can active a combo point function
local powerTypesFilter = {
["COMBO_POINTS"] = true,
["CHI"] = true,
["HOLY_POWER"] = true,
["SOUL_SHARDS"] = true,
["ARCANE_CHARGES"] = true,
["RUNES"] = true,
["ESSENCE"] = true,
}
local eventsFilter = {
["UNIT_POWER_POINT_CHARGE"] = true,
["RUNE_POWER_UPDATE"] = true,
["RUNE_TYPE_UPDATE"] = IS_WOW_PROJECT_NOT_MAINLINE,
["UPDATE_SHAPESHIFT_FORM"] = true,
}
local CONST_ENUMNAME_COMBOPOINT = "ComboPoints"
local CONST_ENUMNAME_HOLYPOWER = "HolyPower"
local CONST_ENUMNAME_RUNES = "Runes"
local CONST_ENUMNAME_ARCANECHARGES = "ArcaneCharges"
local CONST_ENUMNAME_CHI = "Chi"
local CONST_ENUMNAME_SOULCHARGES = "SoulShards"
local CONST_ENUMNAME_ESSENCE = "Essence"
--cache
local DB_USE_PLATER_RESOURCE_BAR = false
local DB_PLATER_RESOURCE_BAR_ON_PERSONAL = false
local DB_PLATER_RESOURCE_BAR_ANCHOR
--local DB_PLATER_RESOURCE_BAR_HEIGHT
local DB_PLATER_RESOURCE_BAR_SCALE
local DB_PLATER_RESOURCE_PADDING
local DB_PLATER_RESOURCE_GROW_DIRECTON
local DB_PLATER_RESOURCE_SHOW_DEPLETED
local DB_PLATER_RESOURCE_SHOW_NUMBER
local getPlateFrameForResourceFrame = function()
local plateFrame = nil
if (not DB_USE_PLATER_RESOURCE_BAR) then
-- do nothing
elseif (not DB_PLATER_RESOURCE_BAR_ON_PERSONAL or IS_WOW_PROJECT_NOT_MAINLINE) then
--target nameplate
plateFrame = C_NamePlate.GetNamePlateForUnit("target")
elseif (IS_WOW_PROJECT_MAINLINE) then
--personal bar
plateFrame = C_NamePlate.GetNamePlateForUnit("player")
end
return plateFrame
end
--Plater.Resources
--when plater in the main file refreshes its upvalues, this function is also called
--called from plater.lua on Plater.RefreshDBUpvalues()
function Plater.Resources.RefreshResourcesDBUpvalues()
local profile = Plater.db.profile
--resourceGlobalSettings: where options for all resources are stored
local resourceGlobalSettings = profile.resources_settings.global_settings
DB_USE_PLATER_RESOURCE_BAR = resourceGlobalSettings.show
DB_PLATER_RESOURCE_BAR_ON_PERSONAL = resourceGlobalSettings.personal_bar
DB_PLATER_RESOURCE_BAR_ANCHOR = resourceGlobalSettings.anchor
--DB_PLATER_RESOURCE_BAR_HEIGHT = resourceGlobalSettings.width
DB_PLATER_RESOURCE_BAR_SCALE = resourceGlobalSettings.scale
DB_PLATER_RESOURCE_PADDING = resourceGlobalSettings.padding
DB_PLATER_RESOURCE_GROW_DIRECTON = resourceGlobalSettings.grow_direction
DB_PLATER_RESOURCE_SHOW_DEPLETED = resourceGlobalSettings.show_depleted
DB_PLATER_RESOURCE_SHOW_NUMBER = resourceGlobalSettings.show_number
--check if the frame exists if the player opt-in to use plater resources
if (DB_USE_PLATER_RESOURCE_BAR) then
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
if (not mainResourceFrame) then
C_Timer.After(0, function()
--create on next frame
Plater.Resources.CreateMainResourceFrame()
Plater.Resources.UpdateResourceFrameToUse()
Plater.Resources.UpdateResourceFramePosition()
end)
else
Plater.Resources.CreateMainResourceFrame()
Plater.Resources.UpdateResourceFrameToUse()
Plater.Resources.UpdateResourceFramePosition()
local resourceBar = Plater.Resources.GetResourceBarInUse()
--characters without resources to show may not have a resource bar created for them
if (not resourceBar) then
return
end
--amount of resources the player has now
local currentResources = PlayerClass == "DEATHKNIGHT" and 6 or UnitPower("player", Plater.Resources.playerResourceId)
--resources amount got updated?
if (currentResources) then
--which update method to use
if (DB_PLATER_RESOURCE_SHOW_DEPLETED) then
Plater.Resources.UpdateResources_WithDepleted(resourceBar, currentResources)
else
Plater.Resources.UpdateResources_NoDepleted(resourceBar, currentResources)
end
end
--update the resource bar
Plater.Resources.UpdateResourceBar(nil, resourceBar)
end
else
--player opt-out of using plater resources on this character
Plater.Resources.HidePlaterResourceFrame()
end
end
--base frame for the class or spec resource bar, it's a child of the main resource frame 'PlaterNameplatesResourceFrame'
--the function passed is responsible to build textures and animations
local createResourceBar = function(parent, frameName, func, widgetWidth, widgetHeight)
local resourceBar = CreateFrame("frame", frameName, parent)
resourceBar:EnableMouse(false)
resourceBar:EnableMouseWheel(false)
--store all widgets
resourceBar.widgets = {}
--store all background textures (created on plater_resources_frames), this texture is the default texture shown when the combo point isn't active
resourceBar.widgetsBackground = {}
--create widgets which are frames holding textures and animations
if (func) then
for i = 1, CONST_NUM_RESOURCES_WIDGETS do
local newWidget = func(resourceBar, "$parentCPO" .. i)
resourceBar.widgets[#resourceBar.widgets + 1] = newWidget
newWidget:EnableMouse(false)
newWidget:EnableMouseWheel(false)
newWidget:SetSize(widgetWidth or CONST_WIDGET_WIDTH, widgetHeight or CONST_WIDGET_HEIGHT)
newWidget:Hide()
local CPOID = DF:CreateLabel(newWidget, i, 12, "white", nil, nil, nil, "overlay")
CPOID:SetPoint("bottom", newWidget, "top", 0, 5)
CPOID:Hide()
newWidget.numberId = CPOID
end
end
return resourceBar
end
local function updateWotLKDKRuneTextures(resourceBar)
if IS_WOW_PROJECT_NOT_MAINLINE then
--wrath classic
local RUNETYPE_BLOOD = 1
local RUNETYPE_FROST = 2
local RUNETYPE_UNHOLY = 3
local RUNETYPE_DEATH = 4
local iconTextures = {}
iconTextures[RUNETYPE_BLOOD] = "Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Blood"
iconTextures[RUNETYPE_FROST] = "Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Frost"
iconTextures[RUNETYPE_UNHOLY] = "Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Unholy"
iconTextures[RUNETYPE_DEATH] = "Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Death"
for i =1, #resourceBar.widgets do
local runeType = GetRuneType(i)
resourceBar.widgets[i].texture:SetTexture(iconTextures[runeType])
resourceBar.widgets[i].texture:Show()
end
end
end
--> functions for class and specs resources
resourceBarCreateFuncByEnumName[CONST_ENUMNAME_CHI] = function(mainResourceFrame)
local resourceWidgetCreationFunc = Plater.Resources.GetCreateResourceWidgetFunctionForSpecId(CONST_SPECID_MONK_WINDWALKER)
local newResourceBar = createResourceBar(mainResourceFrame, "$parentMonk2Resource", resourceWidgetCreationFunc, 25, 25) --windwalker chi
mainResourceFrame.widgetWidth = 25
mainResourceFrame.widgetHeight = 25
mainResourceFrame.resourceBars[CONST_SPECID_MONK_WINDWALKER] = newResourceBar
newResourceBar.resourceId = SPELL_POWER_CHI
newResourceBar.updateResourceFunc = resourceWidgetsFunctions.OnResourceChanged
tinsert(mainResourceFrame.allResourceBars, newResourceBar)
mainResourceFrame.resourceBarsByEnumName[CONST_ENUMNAME_CHI] = newResourceBar
return newResourceBar
end
resourceBarCreateFuncByEnumName[CONST_ENUMNAME_ARCANECHARGES] = function(mainResourceFrame)
local resourceWidgetCreationFunc = Plater.Resources.GetCreateResourceWidgetFunctionForSpecId(CONST_SPECID_MAGE_ARCANE)
local newResourceBar = createResourceBar(mainResourceFrame, "$parentArcaneMageResource", resourceWidgetCreationFunc)
mainResourceFrame.resourceBars[CONST_SPECID_MAGE_ARCANE] = newResourceBar
newResourceBar.resourceId = SPELL_POWER_ARCANE_CHARGES
newResourceBar.updateResourceFunc = resourceWidgetsFunctions.OnResourceChanged
tinsert(mainResourceFrame.allResourceBars, newResourceBar)
mainResourceFrame.resourceBarsByEnumName[CONST_ENUMNAME_ARCANECHARGES] = newResourceBar
return newResourceBar
end
resourceBarCreateFuncByEnumName[CONST_ENUMNAME_COMBOPOINT] = function(mainResourceFrame)
local size = IS_WOW_PROJECT_MAINLINE and 20 or 13
local resourceWidgetCreationFunc = Plater.Resources.GetCreateResourceWidgetFunctionForSpecId(CONST_SPECID_ROGUE_OUTLAW)
local newResourceBar = createResourceBar(mainResourceFrame, "$parentRogueResource", resourceWidgetCreationFunc, size, size)
mainResourceFrame.widgetWidth = size
mainResourceFrame.widgetHeight = size
mainResourceFrame.resourceBars[CONST_SPECID_ROGUE_ASSASSINATION] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_ROGUE_OUTLAW] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_ROGUE_SUBTLETY] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_DRUID_FERAL] = newResourceBar
newResourceBar.resourceId = SPELL_POWER_COMBO_POINTS
newResourceBar.updateResourceFunc = resourceWidgetsFunctions.OnComboPointsChanged
tinsert(mainResourceFrame.allResourceBars, newResourceBar)
mainResourceFrame.resourceBarsByEnumName[CONST_ENUMNAME_COMBOPOINT] = newResourceBar
return newResourceBar
end
resourceBarCreateFuncByEnumName[CONST_ENUMNAME_SOULCHARGES] = function(mainResourceFrame)
local resourceWidgetCreationFunc = Plater.Resources.GetCreateResourceWidgetFunctionForSpecId(CONST_SPECID_WARLOCK_AFFLICTION)
local newResourceBar = createResourceBar(mainResourceFrame, "$parentWarlockResource", resourceWidgetCreationFunc, 17, 22)
mainResourceFrame.widgetWidth = 17
mainResourceFrame.widgetHeight = 22
mainResourceFrame.resourceBars[CONST_SPECID_WARLOCK_AFFLICTION] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_WARLOCK_DEMONOLOGY] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_WARLOCK_DESTRUCTION] = newResourceBar
newResourceBar.resourceId = SPELL_POWER_SOUL_SHARDS
newResourceBar.updateResourceFunc = resourceWidgetsFunctions.OnSoulChardsChanged
tinsert(mainResourceFrame.allResourceBars, newResourceBar)
mainResourceFrame.resourceBarsByEnumName[CONST_ENUMNAME_SOULCHARGES] = newResourceBar
return newResourceBar
end
resourceBarCreateFuncByEnumName[CONST_ENUMNAME_HOLYPOWER] = function(mainResourceFrame)
local resourceWidgetCreationFunc = Plater.Resources.GetCreateResourceWidgetFunctionForSpecId(CONST_SPECID_PALADIN_RETRIBUTION)
local newResourceBar = createResourceBar(mainResourceFrame, "$parentPaladinResource", resourceWidgetCreationFunc, 25, 19)
mainResourceFrame.widgetWidth = 25
mainResourceFrame.widgetHeight = 19
mainResourceFrame.resourceBars[CONST_SPECID_PALADIN_HOLY] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_PALADIN_PROTECTION] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_PALADIN_RETRIBUTION] = newResourceBar
newResourceBar.resourceId = SPELL_POWER_HOLY_POWER
newResourceBar.updateResourceFunc = resourceWidgetsFunctions.OnResourceChanged
tinsert(mainResourceFrame.allResourceBars, newResourceBar)
mainResourceFrame.resourceBarsByEnumName[CONST_ENUMNAME_HOLYPOWER] = newResourceBar
return newResourceBar
end
resourceBarCreateFuncByEnumName[CONST_ENUMNAME_RUNES] = function(mainResourceFrame)
local resourceWidgetCreationFunc = Plater.Resources.GetCreateResourceWidgetFunctionForSpecId(CONST_SPECID_DK_FROST)
mainResourceFrame.widgetWidth = IS_WOW_PROJECT_MAINLINE and 16 or 18--24
mainResourceFrame.widgetHeight = IS_WOW_PROJECT_MAINLINE and 16 or 18--24
local newResourceBar = createResourceBar(mainResourceFrame, "$parentDeathKnightResource", resourceWidgetCreationFunc, mainResourceFrame.widgetWidth, mainResourceFrame.widgetHeight)
mainResourceFrame.resourceBars[CONST_SPECID_DK_UNHOLY] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_DK_FROST] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_DK_BLOOD] = newResourceBar
newResourceBar.resourceId = SPELL_POWER_RUNES
-- for rune sorting
newResourceBar.runeIndexes = {};
for i = 1, #newResourceBar.widgets do
tinsert(newResourceBar.runeIndexes, i);
end
if IS_WOW_PROJECT_MAINLINE then
newResourceBar.updateResourceFunc = resourceWidgetsFunctions.OnRunesChanged
else
newResourceBar.updateResourceFunc = resourceWidgetsFunctions.OnRunesChangedWotLK
updateWotLKDKRuneTextures(newResourceBar)
end
tinsert(mainResourceFrame.allResourceBars, newResourceBar)
mainResourceFrame.resourceBarsByEnumName[CONST_ENUMNAME_RUNES] = newResourceBar
return newResourceBar
end
resourceBarCreateFuncByEnumName[CONST_ENUMNAME_ESSENCE] = function(mainResourceFrame)
local resourceWidgetCreationFunc = Plater.Resources.GetCreateResourceWidgetFunctionForSpecId(CONST_SPECID_EVOKER_DEVASTATION)
local newResourceBar = createResourceBar(mainResourceFrame, "$parentEvokerResource", resourceWidgetCreationFunc, 24, 24)
mainResourceFrame.widgetWidth = 24
mainResourceFrame.widgetHeight = 24
mainResourceFrame.resourceBars[CONST_SPECID_EVOKER_DEVASTATION] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_EVOKER_PRESERVATION] = newResourceBar
mainResourceFrame.resourceBars[CONST_SPECID_EVOKER_AUGMENTATION] = newResourceBar
newResourceBar.resourceId = SPELL_POWER_ESSENCE
newResourceBar.updateResourceFunc = resourceWidgetsFunctions.OnEssenceChanged
tinsert(mainResourceFrame.allResourceBars, newResourceBar)
mainResourceFrame.resourceBarsByEnumName[CONST_ENUMNAME_ESSENCE] = newResourceBar
return newResourceBar
end
--> this funtion is called once at the logon, it initializes the main frame
function Plater.Resources.CreateMainResourceFrame()
if (not DB_USE_PLATER_RESOURCE_BAR) then
--ignore if the settings are off
--return
--nop, can't ignore because must have a main resource frame
end
if (_G.PlaterNameplatesResourceFrame) then
--ignore if the resource frame is already created
return
end
--create the main frame, this frame is the fundation for the resource bar
--this frame is anchored to nameplates to show the amount of resources
local mainResourceFrame = CreateFrame("frame", "PlaterNameplatesResourceFrame", UIParent)
--> create tables to store the resource bars created
--store the resources bars by class or spec (hash table with class name or spec e.g. resourceBars[73] = resourceBar)
mainResourceFrame.resourceBars = {}
--store all resource bars created (index table)
mainResourceFrame.allResourceBars = {}
--store the resource bar by its _G.Enum.PowerType name (hash table where the key is a string from _G.Enum.PowerType), e.g. resourceBarsByEnum["HolyPower"] = resourceBar
mainResourceFrame.resourceBarsByEnumName = {}
--set the OnEvent function
mainResourceFrame:SetScript("OnEvent", function(self, event, unit, powerType, ...)
--if (event == "UPDATE_SHAPESHIFT_FORM") then
--it's guarantee to trigger only on druids
--else
--get the current shown resource bar, then get its update func and call it passing the mainResourceFrame as #1 and the resourceBar itself as #2 argument
local currentResourceBar = self.currentResourceBarShown
if (currentResourceBar) then
local updateResourceFunc = currentResourceBar.updateResourceFunc
if (updateResourceFunc) then
--check if the power type passes the filter
if (powerTypesFilter[powerType] or eventsFilter[event]) then
lastComboPointGainedTime = GetTime()
Plater.StartLogPerformanceCore("Plater-Resources", "Events", event)
updateResourceFunc(self, currentResourceBar, false, event, unit, powerType)
Plater.EndLogPerformanceCore("Plater-Resources", "Events", event)
end
end
end
--end
end)
--get/create the resource frame set in the options panel
Plater.Resources.UpdateResourceFrameToUse()
end
--this function get the value set by the player in the options panel and create a resource bar for what the player selected
--for instance, players could select to use paladin style combo points on the rogues
function Plater.Resources.UpdateResourceFrameToUse()
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
if (not mainResourceFrame) then
Plater.Resources.CreateMainResourceFrame()
mainResourceFrame = Plater.Resources.GetMainResourceFrame()
end
--grab the player class
local playerClass = PlayerClass or select(2, UnitClass("player"))
--the resourceId to query the amount of resources the player has
Plater.Resources.playerResourceId = Plater.Resources.GetResourceIdForPlayer()
if (IS_WOW_PROJECT_NOT_MAINLINE) then --classic
if (playerClass == "ROGUE" or playerClass == "DRUID") then
local classResourceFunc = resourceBarCreateFuncByEnumName[CONST_ENUMNAME_COMBOPOINT]
if (classResourceFunc) then
local resourceBar = classResourceFunc(mainResourceFrame)
mainResourceFrame.currentResourceBarShown = resourceBar
Plater.Resources.UpdateResourceBar(nil, resourceBar)
return resourceBar
end
elseif (playerClass == "DEATHKNIGHT") then
local classResourceFunc = resourceBarCreateFuncByEnumName[CONST_ENUMNAME_RUNES]
if (classResourceFunc) then
local resourceBar = classResourceFunc(mainResourceFrame)
mainResourceFrame.currentResourceBarShown = resourceBar
Plater.Resources.UpdateResourceBar(nil, resourceBar)
return resourceBar
end
end
else
--return if there's no resource for this character
if (not Plater.Resources.playerResourceId) then
return
end
--get the resource to use on this character, players can change which resource model to use in the options panel
local resourceEnumName = Plater.Resources.GetResourceEnumNameForPlayer()
--if no enum name, this class does not use a resource bar
if (not resourceEnumName) then
return
end
--hide all resource bars already created
for _, thisResourceBar in pairs(mainResourceFrame.resourceBarsByEnumName) do
thisResourceBar:Hide()
end
--get the resource bar
local resourceBar = mainResourceFrame.resourceBarsByEnumName[resourceEnumName]
--if the resource bar isn't yet created, create now
if (not resourceBar) then
local createResourceBarFunc = resourceBarCreateFuncByEnumName[resourceEnumName]
if (createResourceBarFunc) then
resourceBar = createResourceBarFunc(mainResourceFrame)
end
end
mainResourceFrame.currentResourceBarShown = resourceBar
Plater.Resources.UpdateResourceBar(nil, resourceBar)
return resourceBar
end
end
function Plater.Resources.GetMainResourceFrame()
local mainResourceFrame = _G.PlaterNameplatesResourceFrame
if (mainResourceFrame) then
return mainResourceFrame
else
Plater.Resources.CreateMainResourceFrame()
mainResourceFrame = _G.PlaterNameplatesResourceFrame
return mainResourceFrame
end
end
function Plater.Resources.GetResourceBarInUse()
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
if (mainResourceFrame) then
return mainResourceFrame.currentResourceBarShown
end
end
function Plater.Resources.EnableEvents()
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
if (not mainResourceFrame or mainResourceFrame.eventsEnabled) then
return
end
mainResourceFrame:RegisterUnitEvent("UNIT_POWER_FREQUENT", "player")
mainResourceFrame:RegisterUnitEvent("UNIT_MAXPOWER", "player")
if (IS_WOW_PROJECT_MAINLINE and (PlayerClass == "ROGUE" or PlayerClass == "EVOKER")) then
mainResourceFrame:RegisterUnitEvent("UNIT_POWER_POINT_CHARGE", "player")
end
if (PlayerClass == "DRUID") then
mainResourceFrame:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
end
if (PlayerClass == "DEATHKNIGHT") then
mainResourceFrame:RegisterEvent("RUNE_POWER_UPDATE")
if IS_WOW_PROJECT_NOT_MAINLINE then
mainResourceFrame:RegisterEvent("RUNE_TYPE_UPDATE")
end
end
mainResourceFrame.eventsEnabled = true
mainResourceFrame.currentResourceBarShown.updateResourceFunc(mainResourceFrame, mainResourceFrame.currentResourceBarShown, true)
end
function Plater.Resources.DisableEvents()
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
if (not mainResourceFrame or not mainResourceFrame.eventsEnabled) then
return
end
mainResourceFrame:UnregisterEvent("UNIT_POWER_FREQUENT")
mainResourceFrame:UnregisterEvent("UNIT_MAXPOWER")
if (IS_WOW_PROJECT_MAINLINE and (PlayerClass == "ROGUE" or PlayerClass == "EVOKER")) then
mainResourceFrame:UnregisterEvent("UNIT_POWER_POINT_CHARGE")
end
if (PlayerClass == "DRUID") then
mainResourceFrame:UnregisterEvent("UPDATE_SHAPESHIFT_FORM")
end
mainResourceFrame.eventsEnabled = false
end
--> called when use plater resource bar is disabled or when no match on rules to show it; only called from inside this file
function Plater.Resources.HidePlaterResourceFrame()
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
if (mainResourceFrame) then
Plater.Resources.DisableEvents()
mainResourceFrame:Hide()
return
end
end
--> currently is called from:
--player spec change (PLAYER_SPECIALIZATION_CHANGED)
function Plater.Resources.OnSpecChanged()
-- update DK rune visuals:
if PlayerClass == "DEATHKNIGHT" then
local resourceBar = Plater.Resources.GetResourceBarInUse()
if not resourceBar then return end
if IS_WOW_PROJECT_MAINLINE then
local specIndex = GetSpecialization()
for i =1, #resourceBar.widgets do
resourceBar.widgets[i].texture:SetAtlas("DK-"..Plater.Resources.GetRuneKeyBySpec(specIndex).."-Rune-Ready")
resourceBar.widgets[i].cooldown:SetSwipeTexture("Interface\\PlayerFrame\\DK-"..Plater.Resources.GetRuneKeyBySpec(specIndex).."-Rune-CDFill")
resourceBar.widgets[i].cooldown:SetEdgeTexture("Interface\\PlayerFrame\\DK-"..Plater.Resources.GetCDEdgeBySpec(specIndex).."-Rune-CDSpark")
end
else
updateWotLKDKRuneTextures(resourceBar)
end
end
Plater.Resources.CanUsePlaterResourceFrame()
end
--> check if plater settings allow the use of these resources and check if the class and spec has a resource to show
--decides if the resource is shown or not
--TODO: hide/show here?
function Plater.Resources.CanUsePlaterResourceFrame()
Plater.StartLogPerformanceCore("Plater-Resources", "Update", "CanUsePlaterResourceFrame")
local retVal = false
--check first if this class has any resource to be used
if (not doesClassUseResource(PlayerClass)) then
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "CanUsePlaterResourceFrame")
return retVal
end
--nameplate which will have the resource bar
local plateFrame = getPlateFrameForResourceFrame()
if (not plateFrame) then
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "CanUsePlaterResourceFrame")
return retVal
end
local playerClass = PlayerClass
if (IS_WOW_PROJECT_NOT_MAINLINE) then
if (playerClass == "ROGUE" or playerClass == "DEATHKNIGHT" or (playerClass == "DRUID" and (GetShapeshiftFormID() == 1 or Plater.db.profile.resources_settings.druid_show_always))) then
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "CanUsePlaterResourceFrame")
return true
end
else
--spec index from 1 to 4 (see specialization frame pressing N ingame), characters below level 10 might have a bigger index
local specIndexSelected = GetSpecialization()
local specId = GetSpecializationInfo(specIndexSelected)
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
if (specId) then
local doesSpecIdUseResource = doesSpecUseResource(specId)
--player maybe in guardian spec but is using feral form
local isInFeralForm = PlayerClass == "DRUID" and (GetShapeshiftFormID() == 1 or Plater.db.profile.resources_settings.druid_show_always)
if (doesSpecIdUseResource or isInFeralForm or playerClass == "ROGUE") then --TODO: Druid can use it in all specs. stance check needed! (implementing)
--get the resource bar
local resourceBar = Plater.Resources.GetResourceBarInUse()
if (resourceBar) then
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "CanUsePlaterResourceFrame")
return true
end
else
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "CanUsePlaterResourceFrame")
return retVal
end
else
--if no specialization, player might be low level
if (UnitLevel("player") < 10) then
--should get by class?
if (playerClass == "ROGUE") then
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "CanUsePlaterResourceFrame")
return true
end
end
end
end
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "CanUsePlaterResourceFrame")
return retVal
end
--> currently is called from:
--player target has changed, this is called from Plater.lua target changed function
function Plater.Resources.UpdateResourceFramePosition()
Plater.Resources.UpdateMainResourceFrame(getPlateFrameForResourceFrame())
end
--this function receives the nameplate where the resource bar will be attached
function Plater.Resources.UpdateMainResourceFrame(plateFrame)
Plater.StartLogPerformanceCore("Plater-Resources", "Update", "UpdateMainResourceFrame")
--get the main resource frame
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
if (not mainResourceFrame) then
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "UpdateMainResourceFrame")
return
end
if (not plateFrame) then
Plater.Resources.HidePlaterResourceFrame()
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "UpdateMainResourceFrame")
return
end
if (not Plater.Resources.CanUsePlaterResourceFrame()) then
Plater.Resources.HidePlaterResourceFrame()
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "UpdateMainResourceFrame")
return
end
Plater.Resources.EnableEvents()
if (IS_WOW_PROJECT_NOT_MAINLINE) then
local resourceBar = Plater.Resources.GetResourceBarInUse()
Plater.Resources.UpdateResourceBar(plateFrame, resourceBar)
else
local resourceBar = Plater.Resources.GetResourceBarInUse()
Plater.Resources.UpdateResourceBar(plateFrame, resourceBar)
end
--make its parent be the healthBar from the nameplate where it is anchored to
local healthBar = plateFrame.unitFrame.healthBar
mainResourceFrame:SetParent(healthBar)
--update the resource anchor
Plater.SetAnchor(mainResourceFrame, DB_PLATER_RESOURCE_BAR_ANCHOR)
--update the size
mainResourceFrame:SetWidth(healthBar:GetWidth())
mainResourceFrame:SetHeight(2)
mainResourceFrame:SetScale(DB_PLATER_RESOURCE_BAR_SCALE)
mainResourceFrame:SetFrameStrata(healthBar:GetFrameStrata())
mainResourceFrame:SetFrameLevel(healthBar:GetFrameLevel() + 25)
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "UpdateMainResourceFrame")
end
--called from 'UpdateMainResourceFrame'
--this funtion receives the nameplate and the bar to show
function Plater.Resources.UpdateResourceBar(plateFrame, resourceBar) --note: plateFrame not in use in this function
Plater.StartLogPerformanceCore("Plater-Resources", "Update", "UpdateResourceBar")
--main resource frame
local mainResourceFrame = Plater.Resources.GetMainResourceFrame()
--hide all resourcebar widgets
for i = 1, #resourceBar.widgets do
resourceBar.widgets[i]:Hide()
resourceBar.widgets[i].numberId:SetShown(DB_PLATER_RESOURCE_SHOW_NUMBER) --numberId is a fontstring above the combo point showing the combo point number
end
--check if the bar already shown isn't the bar asking to be shown
if (mainResourceFrame.currentResourceBarShown) then
if (mainResourceFrame.currentResourceBarShown ~= resourceBar) then
mainResourceFrame.currentResourceBarShown:Hide()
end
end
mainResourceFrame.currentResourceBarShown = resourceBar
--show the resource bar
resourceBar:Show()
resourceBar:SetHeight(1)
mainResourceFrame:Show()
-- hide blizzard resources
if DB_USE_PLATER_RESOURCE_BAR then
local resourceFrame = NamePlateDriverFrame and NamePlateDriverFrame.classNamePlateMechanicFrame
if (resourceFrame and not resourceFrame:IsForbidden()) then
resourceFrame:Hide()
end
local alternatePowerFrame = NamePlateDriverFrame and NamePlateDriverFrame.classNamePlateAlternatePowerBar
if (alternatePowerFrame and not alternatePowerFrame:IsForbidden()) then
alternatePowerFrame:Hide()
end
end
if (DB_PLATER_RESOURCE_SHOW_DEPLETED) then
Plater.Resources.UpdateResourcesFor_ShowDepleted(mainResourceFrame, resourceBar)
else
Plater.Resources.UpdateResourcesFor_HideDepleted(mainResourceFrame, resourceBar)
end
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "UpdateResourceBar")
end
--update the resources widgets when hiding the resources background for depleted
--on this type, the location of each resource icon is depending on the amount shown
function Plater.Resources.UpdateResourcesFor_HideDepleted(mainResourceFrame, resourceBar)
Plater.StartLogPerformanceCore("Plater-Resources", "Update", "UpdateResourcesFor_HideDepleted")
--get the table with the widgets created
local widgetTable = resourceBar.widgets
--fallback if it is not implemented/created
if (not widgetTable[1]) then
return
end
--store the amount of widgets currently in use - as we are hiding before update: 0
resourceBar.widgetsInUseAmount = 0
--set the amount of resources the player has - 0 before update
resourceBar.lastResourceAmount = 0
for i = 1, CONST_NUM_RESOURCES_WIDGETS do
local thisResourceWidget = widgetTable[i]
thisResourceWidget.inUse = false
thisResourceWidget:Hide()
resourceBar.widgetsBackground[i]:Hide()
end
mainResourceFrame.currentResourceBarShown.updateResourceFunc(mainResourceFrame, mainResourceFrame.currentResourceBarShown, true)
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "UpdateResourcesFor_HideDepleted")
end
--update the resources widgets when using the resources showing the background of depleted
--on this type, the location of each resource icon is precomputed
function Plater.Resources.UpdateResourcesFor_ShowDepleted(mainResourceFrame, resourceBar)
Plater.StartLogPerformanceCore("Plater-Resources", "Update", "UpdateResourcesFor_ShowDepleted")
--get the table with the widgets created
local widgetTable = resourceBar.widgets
--fallback if it is not implemented/created
if (not widgetTable[1]) then
return
end
--warning: calling UnitPowerMax with a nil resource id is returning a default resource amount, example in shadow priest which returns max insanity amount
local totalWidgetsShown = PlayerClass == "DEATHKNIGHT" and 6 or UnitPowerMax("player", Plater.Resources.playerResourceId)
--store the amount of widgets currently in use
resourceBar.widgetsInUseAmount = totalWidgetsShown
--set the amount of resources the player has
resourceBar.lastResourceAmount = 0
--get the default size of each widget
local widgetWidth = mainResourceFrame.widgetWidth or CONST_WIDGET_WIDTH
local widgetHeight = mainResourceFrame.widgetHeight or CONST_WIDGET_HEIGHT
--sum of the width of all resources shown
local totalWidth = 0
local isGrowingToLeft = DB_PLATER_RESOURCE_GROW_DIRECTON == "left"
local firstWidgetIndex = 1
local firstWindowPoint = isGrowingToLeft and "right" or "left"
--set the point of the first widget within the resource bar
local firstWidget = widgetTable[firstWidgetIndex]
firstWidget:SetPoint(firstWindowPoint, resourceBar, firstWindowPoint, 0, 0)
local firstWidgetBackground = resourceBar.widgetsBackground[firstWidgetIndex]
firstWidgetBackground:SetSize(widgetWidth, widgetHeight)
firstWidgetBackground:Show()
firstWidgetBackground:ClearAllPoints()
firstWidgetBackground:SetPoint(firstWindowPoint, resourceBar, firstWindowPoint, 0, 0)
for i = 1, totalWidgetsShown do
local thisResourceWidget
local lastResourceWidget
if (isGrowingToLeft and false) then
i = abs(i-(totalWidgetsShown+1))
thisResourceWidget = widgetTable[i]
lastResourceWidget = widgetTable[i+1]
else
thisResourceWidget = widgetTable[i]
lastResourceWidget = widgetTable[i-1]
end
thisResourceWidget:SetSize(widgetWidth, widgetHeight)
if (i ~= firstWidgetIndex) then
--adjust the point of widgets
thisResourceWidget:ClearAllPoints()
if (isGrowingToLeft) then
thisResourceWidget:SetPoint("right", lastResourceWidget, "left", -DB_PLATER_RESOURCE_PADDING, 0)
else
thisResourceWidget:SetPoint("left", lastResourceWidget, "right", DB_PLATER_RESOURCE_PADDING, 0)
end
thisResourceWidget:Hide() -- ensure 'reset'. will be shown through update later, if needed.
local widgetBackground = resourceBar.widgetsBackground[i]
widgetBackground:SetSize(widgetWidth, widgetHeight)
widgetBackground:Show()
--add the spacing into the total width occupied
totalWidth = totalWidth + DB_PLATER_RESOURCE_PADDING
end
totalWidth = totalWidth + widgetWidth
end
for i = totalWidgetsShown+1, CONST_NUM_RESOURCES_WIDGETS do
local thisResourceWidget = widgetTable[i]
thisResourceWidget.inUse = false
thisResourceWidget:Hide()
resourceBar.widgetsBackground[i]:Hide()
end
resourceBar:SetWidth(totalWidth)
resourceBar:SetPoint("center", mainResourceFrame, "center", 0, 0)
--[[
for i = 1, totalWidgetsShown do
local thisResourceWidget = widgetTable[i]
local widgetBackground = resourceBar.widgetsBackground[i]
--print(widgetBackground:GetSize())
--print(widgetBackground:IsShown())
--print(widgetBackground:GetPoint(1))
--print(widgetBackground:GetName())
--print(widgetBackground:GetTexture())
end
]]--
mainResourceFrame.currentResourceBarShown.updateResourceFunc(mainResourceFrame, mainResourceFrame.currentResourceBarShown, true)
Plater.EndLogPerformanceCore("Plater-Resources", "Update", "UpdateResourcesFor_ShowDepleted")
end
--realign the combat points after the amount of available combo points change
--this amount isn't the max amount of combo points but the current resources deom UnitPower