-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKTracker.lua
3851 lines (3418 loc) · 131 KB
/
KTracker.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 addonName, addon = ...
local L = addon.L
local utils = addon.utils
local _G = _G
_G["KTracker"] = addon
--
-- default addon options
--
local def = {
-- maximum allowed groups, columns and rows
maxGroups = 64,
maxColumns = 8,
maxRows = 7,
-- account DB template
DB = {sync = true, groups = {}},
-- character DB template
CharDB = {enabled = true, locked = false, groups = {}},
-- default group template
group = {
enabled = true,
name = "",
spec = 0,
columns = 4,
rows = 1,
hspacing = 0,
vspacing = 0,
scale = 2,
combat = false,
created = 0,
icons = {},
position = {},
style = {}
},
-- default icon template
icon = {
enabled = false,
name = "",
type = "",
subtype = "",
when = 1,
unit = "player",
mine = false,
timer = false,
filepath = nil,
effect = "none"
},
-- group parts, account's and character's.
DBGroup = {
name = "",
columns = 4,
rows = 1,
created = 0,
icons = {}
},
CharDBGroup = {
enabled = false,
hspacing = 0,
vspacing = 0,
scale = 2,
spec = 0,
combat = false,
position = {},
style = {}
}
}
--
-- SavedVariables
--
KTrackerDB = {}
KTrackerCharDB = {}
--
-- simple title holder
--
local titleString = "|cfff58cbaKader|r|caaf49141Tracker|r"
--
-- whether we're using and cooldown addon
--
local hasOmniCC, hasElvUI
--
-- addon synchronization
--
local syncPrefix = "KaderTracker"
local syncHandlers = {}
-- placeholders
local holderGroup = "KTrackerGroup%d"
local holderIcon = "KTrackerGroup%dIcon%d"
--
-- textures to be used
--
local textures = {
"Interface\\Icons\\INV_Misc_QuestionMark",
"Interface\\Icons\\INV_Misc_PocketWatch_01"
}
local Group, Icon = {}, {}
local groups, numGroups = {}, 0
local minimapButton
local Icon_EffectTrigger, Icon_EffectReset
--
-- cache some globals
--
local tinsert, tremove = _G.table.insert, _G.table.remove
local pairs, ipairs = _G.pairs, _G.ipairs
local type, select = _G.type, _G.select
local find, format, gsub = _G.string.find, _G.string.format, _G.string.gsub
local tostring, tonumber = _G.tostring, _G.tonumber
local time, GetTime = _G.time, _G.GetTime
local GetBuildInfo = _G.GetBuildInfo
local IsAddOnLoaded, CreateFrame = _G.IsAddOnLoaded, _G.CreateFrame
local wipe = _G.wipe
local GetInventorySlotInfo = _G.GetInventorySlotInfo
local GetInventoryItemTexture = _G.GetInventoryItemTexture
local GetWeaponEnchantInfo = _G.GetWeaponEnchantInfo
local GetTotemInfo = _G.GetTotemInfo
local GetCursorPosition = _G.GetCursorPosition
local IsSpellInRange, IsUsableSpell = _G.IsSpellInRange, _G.IsUsableSpell
local UnitName, UnitClass, UnitGUID = _G.UnitName, _G.UnitClass, _G.UnitGUID
local UnitExists, UnitIsDead = _G.UnitExists, _G.UnitIsDead
local UnitAura, UnitReaction = _G.UnitAura, _G.UnitReaction
local UnitBuff, UnitDebuff = _G.UnitBuff, _G.UnitDebuff
local unitName = UnitName("player")
local GetSpellInfo = _G.GetSpellInfo
local GetSpellTexture = _G.GetSpellTexture
local GetSpellCooldown = _G.GetSpellCooldown
local GetItemInfo = _G.GetItemInfo
local GetItemCooldown = _G.GetItemCooldown
-- external libraries
local LBF = LibStub:GetLibrary("LibButtonFacade", true)
local LiCD = LibStub:GetLibrary("LibInternalCooldowns", true)
-- we override GetItemCooldown and use LibInternalCooldowns one:
if LiCD and LiCD.GetItemCooldown then
GetItemCooldown = function(...)
return LiCD:GetItemCooldown(...)
end
end
--------------------------------------------------------------------------
-- AddOn initialization
local mainFrame, LoadDatabase = CreateFrame("Frame", "KTracker_EventFrame")
do
--
-- makes sure to properly setup or load database
--
function LoadDatabase()
-- we fill the account's DB if empty.
if utils.isEmpty(KTrackerDB) then
utils.fillTable(KTrackerDB, def.DB)
end
-- we fill the character's DB if empty.
if utils.isEmpty(KTrackerCharDB) then
utils.fillTable(KTrackerCharDB, def.CharDB)
end
-- keep reference of addon enable and lock statuses
addon.sync = KTrackerDB.sync
addon.enabled = KTrackerCharDB.enabled
addon.locked = KTrackerCharDB.locked
-- minimap button
if KTrackerCharDB.minimap == nil then
KTrackerCharDB.minimap = true
end
addon.minimap = KTrackerCharDB.minimap
if not addon.minimap then
addon:HideMinimapButton()
end
-- this step is crucial. If the account has not groups
-- or all groups were deleted we make sure to create
-- the default group.
if utils.isEmpty(KTrackerDB.groups) then
local group = utils.deepCopy(def.group)
group.name = L["Default Group"]
group.enabled = true
Group:Save(group)
end
-- check if the character has all groups added to his/her table
Group:Check()
end
--
-- addon's slash command handler
--
local function SlashCommandHandler(cmd)
if cmd == "config" or cmd == "options" then
addon:Config()
elseif cmd == "reset" then
StaticPopup_Show("KTRACKER_DIALOG_RESET")
else
addon:Toggle()
end
L_CloseDropDownMenus() -- always close them.
end
--
-- handles main frame events
--
local function EventHandler(self, event, ...)
-- on ADDON_LOADED event.
if event == "ADDON_LOADED" then
local name = ...
if name:upper() == addonName:upper() then
mainFrame:UnregisterEvent("ADDON_LOADED")
mainFrame:RegisterEvent("PLAYER_LOGIN")
mainFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
mainFrame:RegisterEvent("CHAT_MSG_ADDON")
LoadDatabase()
SlashCmdList["KTRACKER"] = SlashCommandHandler
SLASH_KTRACKER1, SLASH_KTRACKER2 = "/ktracker", "/kt"
-- ButtonFacade calllback
if LBF then
LBF:RegisterSkinCallback(addonName, addon.OnSkin, addon)
end
addon:Print(L["addon loaded"])
end
elseif event == "PLAYER_LOGIN" then
mainFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
-- using a cooldown count?
if OmniCC or CooldownCount or YarkoCooldowns or ElvUI then
hasOmniCC = true
end
-- using ElvUI?
if ElvUI then
hasElvUI = true
end
addon:Initialize(true)
elseif event == "PLAYER_ENTERING_WORLD" then
mainFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
addon:Initialize()
elseif event == "PLAYER_TALENT_UPDATE" then
-- addon messages
addon:SetCurrentSpec()
addon:Initialize()
elseif event == "CHAT_MSG_ADDON" and addon.sync then
local prefix, msg, channel, sender = ...
if msg and prefix == syncPrefix and sender ~= unitName then
local handler = syncHandlers[prefix]
if handler and type(handler) == "function" then
handler(msg, channel, sender)
end
end
end
end
-- register required event and script
mainFrame:RegisterEvent("ADDON_LOADED")
mainFrame:SetScript("OnEvent", EventHandler)
end
--
-- called when the addon needs to be initialized
--
function addon:Load()
Group:Check()
wipe(groups)
for i = 1, def.maxGroups do
Group:Load(i)
end
numGroups = #groups
end
--
-- toggle addon's locked/unlocked status
--
function addon:Toggle()
PlaySound("UChatScrollButton")
StaticPopup_Hide("KTRACKER_DIALOG_RESET")
StaticPopup_Hide("KTRACKER_DIALOG_CLEAR")
StaticPopup_Hide("KTRACKER_DIALOG_NAME")
StaticPopup_Hide("KTRACKER_DIALOG_UNITNAME")
StaticPopup_Hide("KTRACKER_DIALOG_SHARE_SEND")
StaticPopup_Hide("KTRACKER_DIALOG_SHARE_RECEIVE")
L_CloseDropDownMenus()
KTrackerCharDB.locked = not KTrackerCharDB.locked
self.locked = KTrackerCharDB.locked
self:Initialize()
end
--
-- addon synchronization
--
function addon:Sync(msg, channel, target)
if self.sync then
utils.sync(syncPrefix, msg, channel, target)
end
end
--
-- ButtonFacade skin handler
--
function addon:OnSkin(skin, glossAlpha, gloss, group, _, colors)
local style
if not utils.isEmpty(groups) then
for k, v in pairs(groups) do
if v.name == group then
style = KTrackerCharDB.groups[v.created].style
break
end
end
end
if style then
style[1] = skin
style[2] = glossAlpha
style[3] = gloss
style[4] = colors
end
end
--------------------------------------------------------------------------
-- Groups functions
--
-- this function is useful and makes sure the character has
-- all groups references and options added to his/her table.
--
function Group:Check()
local DBGroups = KTrackerDB.groups
local CharDBGroups = KTrackerCharDB.groups
-- hold the time we are doing the check.
local checkTime = time()
-- list of the groups that the current character
-- doesn't have on his database.
local checked = {}
-- first step: delete groups that were probably deleted but
-- their data accidentally remained in character's database
local safe = {}
for _, obj in ipairs(DBGroups) do
for id, _ in pairs(CharDBGroups) do
if obj.created == id then
safe[id] = true
end
end
end
for id, _ in pairs(CharDBGroups) do
if not safe[id] then
CharDBGroups[id] = nil
end
end
-- second step: add missing groups to character
for _, obj in ipairs(DBGroups) do
if obj.created == 0 then
obj.created = checkTime
end
if not CharDBGroups[obj.created] then
local group = checked[obj.created] or utils.deepCopy(def.CharDBGroup)
CharDBGroups[obj.created] = group
end
end
end
--
-- creates a new group from the def table
--
function Group:Save(obj, id)
-- are we updating and existing group?
if id and KTrackerDB.groups[id] then
local DB = KTrackerDB.groups[id]
-- creation date:
obj.created = DB.created or time()
-- check character's database
local db = KTrackerCharDB.groups[DB.created]
if not db then
KTrackerCharDB.groups[DB.created] = utils.deepCopy(def.CharDBGroup)
KTrackerCharDB.groups[DB.created].enabled = true
db = KTrackerCharDB.groups[DB.created]
end
-- we proceed to update
for k, v in pairs(obj) do
if def.DBGroup[k] ~= nil then
DB[k] = v -- account
end
if def.CharDBGroup[k] ~= nil then
db[k] = v -- character
end
end
return true
end
-- creating a new group
obj = obj or {}
if type(obj) == "string" then
obj = {name = obj}
end
-- creation date:
obj.created = time()
-- prepare account and character tables
local DB, db = utils.deepCopy(def.DBGroup), utils.deepCopy(def.CharDBGroup)
for k, v in pairs(obj) do
if def.DBGroup[k] ~= nil then
DB[k] = v -- account
end
if def.CharDBGroup[k] ~= nil then
db[k] = v -- character
end
end
-- fill the group with required number of icons
local num = DB.columns * DB.rows
for i = 1, num do
if not DB.icons[i] then
local icon = utils.deepCopy(def.icon)
tinsert(DB.icons, i, icon)
end
end
-- save the final results to tables.
tinsert(KTrackerDB.groups, DB)
KTrackerCharDB.groups[obj.created] = db
return #KTrackerDB.groups
end
do
--
-- resize button OnMouseDown and OnMouseUp functions
--
local Sizer_OnMouseDown, Sizer_OnMouseUp
do
--
-- handles group resizing
--
local function Sizer_OnUpdate(self)
local uiScale = UIParent:GetScale()
local f = self:GetParent()
local cursorX, cursorY = GetCursorPosition(UIParent)
-- calculate the new scale
local newXScale =
f.oldScale * (cursorX / uiScale - f.oldX * f.oldScale) /
(self.oldCursorX / uiScale - f.oldX * f.oldScale)
local newYScale =
f.oldScale * (cursorY / uiScale - f.oldY * f.oldScale) /
(self.oldCursorY / uiScale - f.oldY * f.oldScale)
local newScale = math.max(0.6, newXScale, newYScale)
f:SetScale(newScale)
-- calculate new frame position
local newX = f.oldX * f.oldScale / newScale
local newY = f.oldY * f.oldScale / newScale
f:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", newX, newY)
end
--
-- called on OnMouseDown event
--
function Sizer_OnMouseDown(self, button)
-- resize only if the addon is not locked
if addon.locked then
return
end
if button == "LeftButton" then
local f = self:GetParent()
f.oldScale = f:GetScale()
self.oldCursorX, self.oldCursorY = GetCursorPosition(UIParent)
f.oldX, f.oldY = f:GetLeft(), f:GetTop()
self:SetScript("OnUpdate", Sizer_OnUpdate)
end
end
--
-- called on OnMouseUp event
--
function Sizer_OnMouseUp(self, button)
self:SetScript("OnUpdate", nil)
if addon.locked then
return
end
-- Left button released? save scale
if button == "LeftButton" then
local f = self:GetParent()
local id = f:GetID()
local DB = KTrackerDB.groups[id]
local db = KTrackerCharDB.groups[DB.created]
if DB and db then
db.scale = f:GetScale()
Group:Load(id)
end
end
end
end
do
--
-- hide all group icons before loading -- hotfix
--
local function ResetGroupIcons(id)
local i = 1
local btnName = format(holderIcon, id, i)
local btn = _G[btnName]
while btn ~= nil do
btn:Hide()
i = i + 1
btnName = format(holderIcon, id, i)
btn = _G[btnName]
end
end
--
-- load a group and draws it into screen
--
function Group:Load(id)
-- make sure the the group exists
if not KTrackerDB.groups[id] then
return
end
ResetGroupIcons(id)
local obj = utils.deepCopy(KTrackerDB.groups[id])
local db = KTrackerCharDB.groups[obj.created]
if db then
utils.mixTable(obj, db)
if obj.spacing then -- fix old spacing
obj.hspacing = obj.hspacing or obj.spacing
obj.vspacing = obj.vspacing or obj.spacing
db.spacing = nil
end
end
utils.fillTable(obj, def.group)
-- cache the group
if not groups[id] then
tinsert(groups, id, obj)
end
-- we create the group frame
local groupName = format(holderGroup, id)
local group = _G[groupName]
if not group then
group = CreateFrame("Frame", groupName, UIParent, "KTrackerGroupTemplate")
end
group:SetID(id)
if LBF then
LBF:Group(addonName, obj.name):Skin(unpack(obj.style))
end
-- set the group title
group.title = _G[groupName .. "Title"]
group.title:SetText(obj.name)
-- hold group resize button
group.sizer = _G[groupName .. "Resizer"]
group.sizer:RegisterForClicks("AnyUp")
local sizerTexture = _G[groupName .. "ResizerTexture"]
sizerTexture:SetVertexColor(0.6, 0.6, 0.6)
if addon.locked then
local spec = addon:GetCurrentSpec()
if obj.spec > 0 and obj.spec ~= spec then
obj.enabled = false
end
group.title:Hide()
group.sizer:Hide()
else
group.title:Show()
group.sizer:Show()
-- set resize button tooltip and scripts.
utils.setTooltip(group.sizer, L["Click and drag to change size."], nil, L["Resize"])
group.sizer:SetScript("OnMouseDown", Sizer_OnMouseDown)
group.sizer:SetScript("OnMouseUp", Sizer_OnMouseUp)
end
if obj.enabled then
-- group's width and height
local width, height = 36, 36
-- draw icons
for r = 1, obj.rows do
for c = 1, obj.columns do
local i = (r - 1) * obj.columns + c
local iconName = format(holderIcon, id, i)
local icon = _G[iconName] or CreateFrame("Button", iconName, group, "KTrackerIconTemplate")
icon:SetID(i)
if c > 1 then
icon:SetPoint("TOPLEFT", _G[groupName .. "Icon" .. (i - 1)], "TOPRIGHT", obj.hspacing, 0)
-- we set the group width from the first row only.
if r == 1 and c <= obj.columns then
width = width + 36 + obj.hspacing
end
elseif r > 1 and c == 1 then
icon:SetPoint(
"TOPLEFT",
_G[groupName .. "Icon" .. (i - obj.columns)],
"BOTTOMLEFT",
0,
-obj.vspacing
)
height = height + obj.vspacing + 36 -- increment the height
elseif i == 1 then
icon:SetPoint("TOPLEFT", group, "TOPLEFT")
end
-- we update the icon now
if not obj.enabled then
Icon:ClearScripts(icon)
end
-- add the name of the icon
icon.fname = iconName
Icon:Load(icon, id, i)
if LBF then
LBF:Group(addonName, obj.name):AddButton(icon)
else
_G[iconName .. "Icon"]:SetSize(36, 36)
icon:SetNormalTexture(nil)
icon.texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
icon:SetBackdrop(
{
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 2,
edgeSize = 4,
insets = {left = 0, right = 0, top = 0, bottom = 0}
}
)
end
end
end
-- we make sure to change group size in order to be fully
-- clamped to screen, then we set its scale.
group:SetSize(width, height)
group:SetScale(obj.scale)
-- we position the group only if it was moved
if not utils.isEmpty(obj.position) then
group:ClearAllPoints()
group:SetPoint(
obj.position.point or "CENTER",
obj.position.relativeTo or UIParent,
obj.position.relativePoint or "CENTER",
obj.position.xOfs or 0,
obj.position.yOfs or 0
)
end
end
-- register/unregister group events
if obj.combat and obj.enabled and addon.locked then
group:RegisterEvent("PLAYER_REGEN_ENABLED")
group:RegisterEvent("PLAYER_REGEN_DISABLED")
group:SetScript(
"OnEvent",
function(self, event)
if event == "PLAYER_REGEN_ENABLED" then
self:Hide()
elseif event == "PLAYER_REGEN_DISABLED" then
self:Show()
end
end
)
group:Hide()
else
group:UnregisterEvent("PLAYER_REGEN_ENABLED")
group:UnregisterEvent("PLAYER_REGEN_DISABLED")
group:SetScript("OnEvent", nil)
utils.showHide(group, obj.enabled)
end
end
end
end
--------------------------------------------------------------------------
-- Icons functions
do
--
-- current selected icon and menu
--
local current, menu = {}
--
-- icon general, reactive and aura checkers
---
local Icon_ReactiveCheck
--
-- opens the menu for the current icon
--
local Icon_OpenMenu
do
--
-- icon menu list
--
local menuList, menu = {
-- icon type --
IconType = {
{text = L["Cooldown"], arg1 = "type", arg2 = "cooldown", value = "spell"},
{text = L["Buff or Debuff"], arg1 = "type", arg2 = "aura", value = "HELPFUL"},
{text = L["Reactive spell or ability"], arg1 = "type", arg2 = "reactive", value = "spell"},
{text = L["Temporary weapon enchant"], arg1 = "type", arg2 = "wpnenchant", value = "mainhand"},
{text = L["Totem/non-MoG Ghoul"], arg1 = "type", arg2 = "totem", value = ""}
},
SpellType = {
{text = L["Spell"], arg1 = "subtype", arg2 = "spell"},
{text = L["Item"], arg1 = "subtype", arg2 = "item"},
{text = L["Talent"], arg1 = "subtype", arg2 = "talent"}
},
AuraType = {
{text = L["Buff"], arg1 = "subtype", arg2 = "HELPFUL"},
{text = L["Debuff"], arg1 = "subtype", arg2 = "HARMFUL"}
},
WpnEnchantType = {
{text = L["Main Hand"], arg1 = "subtype", arg2 = "mainhand"},
{text = L["Off-Hand"], arg1 = "subtype", arg2 = "offhand"}
},
SpellWhen = {
{text = L["Usable"], arg1 = "when", arg2 = 1},
{text = L["Unusable"], arg1 = "when", arg2 = -1},
{text = L["Always"], arg1 = "when", arg2 = 0}
},
TalentWhen = {
{text = L["Off Cooldown"], arg1 = "when", arg2 = 1},
{text = L["On Cooldown"], arg1 = "when", arg2 = -1},
{text = L["Always"], arg1 = "when", arg2 = 0}
},
AuraWhen = {
{text = L["Present"], arg1 = "when", arg2 = 1},
{text = L["Absent"], arg1 = "when", arg2 = -1},
{text = L["Always"], arg1 = "when", arg2 = 0}
},
Unit = {
{text = L["Player"], arg1 = "unit", arg2 = "player"},
{text = L["Target"], arg1 = "unit", arg2 = "target"},
{text = L["Target's Target"], arg1 = "unit", arg2 = "targettarget"},
{text = L["Focus"], arg1 = "unit", arg2 = "focus"},
{text = L["Focus Target"], arg1 = "unit", arg2 = "focustarget"},
{text = L["Pet"], arg1 = "unit", arg2 = "pet"},
{text = L["Pet's Target"], arg1 = "unit", arg2 = "pettarget"},
{disabled = true},
{text = L["Party Unit"], hasArrow = true, value = "UnitParty"},
{text = L["Arena Unit"], hasArrow = true, value = "UnitArena"},
{disabled = true}
},
UnitParty = {
{text = L:F("Party %d", 1), arg1 = "unit", arg2 = "party1"},
{text = L:F("Party %d", 2), arg1 = "unit", arg2 = "party2"},
{text = L:F("Party %d", 3), arg1 = "unit", arg2 = "party3"},
{text = L:F("Party %d", 4), arg1 = "unit", arg2 = "party4"}
},
UnitArena = {
{text = L:F("Arena %d", 1), arg1 = "unit", arg2 = "arena1"},
{text = L:F("Arena %d", 2), arg1 = "unit", arg2 = "arena2"},
{text = L:F("Arena %d", 3), arg1 = "unit", arg2 = "arena3"},
{text = L:F("Arena %d", 4), arg1 = "unit", arg2 = "arena4"},
{text = L:F("Arena %d", 5), arg1 = "unit", arg2 = "arena5"}
}
}
--
-- used for true and false values
--
local function Icon_OptionToggle()
local g, i = current.group, current.icon
local obj = KTrackerDB.groups[g].icons[i]
if obj and obj[this.value] ~= nil then
KTrackerDB.groups[g].icons[i][this.value] = this.checked
local iconName = format(holderIcon, g, i)
Icon:Load(_G[iconName], g, i)
end
end
--
-- used to set strings and numbers
--
local function Icon_OptionChoose(self, arg1, arg2)
local g, i = current.group, current.icon
local obj = KTrackerDB.groups[g].icons[i]
-- double check the icon
if obj and obj[arg1] ~= nil then
KTrackerDB.groups[g].icons[i][arg1] = arg2
if arg1 == "type" then
KTrackerDB.groups[g].icons[i].filepath = nil
if
this.value == "spell" or this.value == "talent" or this.value == "HELPFUL" or
this.value == "mainhand" or
this.value == "none"
then
KTrackerDB.groups[g].icons[i].subtype = this.value
end
L_CloseDropDownMenus()
end
local iconName = format(holderIcon, g, i)
Icon:Load(_G[iconName], g, i)
return
end
L_CloseDropDownMenus()
end
--
-- clear the selected icon
--
local function Icon_OptionClear()
local i, g = current.icon, current.group
if KTrackerDB.groups[g].icons[i] then
KTrackerDB.groups[g].icons[i] = utils.deepCopy(def.icon)
local iconName = format(holderIcon, g, i)
Icon:Load(_G[iconName], g, i)
end
L_CloseDropDownMenus()
end
--
-- the main menu handler function
--
function Icon_OpenMenu(icon)
if not icon then
return
end
local i, g = icon:GetID(), icon:GetParent():GetID()
local obj = KTrackerDB.groups[g].icons[i]
if not obj then
return
end
current.icon, current.group = i, g
if addon.effects and not menuList.Effects then
menuList.Effects = {
{
text = L["None"],
arg1 = "effect",
arg2 = "none"
}
}
for i, effect in ipairs(addon.effects) do
tinsert(
menuList.Effects,
i + 1,
{
text = effect.name,
arg1 = "effect",
arg2 = effect.id
}
)
end
end
-- generate the menu
if not menu then
menu = CreateFrame("Frame", "KTrackerIconMenu")
end
menu.displayMode = "MENU"
menu.initialize = function(self, level)
local info = L_UIDropDownMenu_CreateInfo()
level = level or 1
if level >= 2 then
local tar = L_UIDROPDOWNMENU_MENU_VALUE
local menuItems = {}
if tar == "Unit" then
menuItems = utils.deepCopy(menuList.Unit)
tinsert(
menuItems,
{
text = L["Custom Unit"],
func = function()
StaticPopup_Show("KTRACKER_DIALOG_UNITNAME", nil, nil, icon)
end
}
)
elseif menuList[tar] then
menuItems = utils.deepCopy(menuList[tar])
end
for _, v in ipairs(menuItems) do
info = utils.deepCopy(v)
info.checked = (v.arg2 and obj[v.arg1] == v.arg2)
info.func = v.func and v.func or Icon_OptionChoose
L_UIDropDownMenu_AddButton(info, level)
wipe(info)
end
return
end
-- display icon's name if set
if obj.name and obj.name ~= "" then
local name
if obj.name:len() >= 24 then
name = obj.name:sub(0, 21) .. "..."
else
name = obj.name
end
info.text = name
info.isTitle = true
info.notCheckable = true
L_UIDropDownMenu_AddButton(info, level)
wipe(info)
end
-- let the player choose the name if the icon
-- type is not set to weapon enchant.
if obj.type ~= "wpnenchant" then
info.text = L["Choose Name"]
info.notCheckable = true
info.func = function()
StaticPopup_Show("KTRACKER_DIALOG_NAME")
end
L_UIDropDownMenu_AddButton(info, level)
wipe(info)
end
-- toggle icon enable status
info.text = L["Enabled"]
info.value = "enabled"
info.checked = obj.enabled
info.isNotRadio = true
info.func = Icon_OptionToggle
info.keepShownOnClick = true
L_UIDropDownMenu_AddButton(info, level)
wipe(info)
-- icon type selection
info.text = L["Icon Type"]
info.value = "IconType"
info.hasArrow = true
info.notCheckable = true
L_UIDropDownMenu_AddButton(info, level)
wipe(info)
-- in case no type is set
if obj.type == "" then
info.text = L["More Options"]
info.disabled = true
info.notCheckable = true
L_UIDropDownMenu_AddButton(info)
wipe(info)
else
-- icon effect (animation) -- not available for talents
if (obj.subtype ~= "talent") and (addon.effects and menuList.Effects) then
info.text = L["Icon Effect"]
info.value = "Effects"
info.hasArrow = true
info.notCheckable = true
L_UIDropDownMenu_AddButton(info, level)
wipe(info)
end
info.disabled = true
L_UIDropDownMenu_AddButton(info)
wipe(info)
if obj.type == "cooldown" then
info.text = L["Cooldown Type"]
info.value = "SpellType"
info.hasArrow = true
info.notCheckable = true
L_UIDropDownMenu_AddButton(info, level)
wipe(info)