-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.lua
1970 lines (1885 loc) · 65.3 KB
/
core.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
-- GLOBALS: BINDING_HEADER_PRIOTARGET_HEADER,SLASH_PRIOTARGET1,SLASH_PRIOTARGET2
local ADDON,private = ...
private.functions,private.data = {},{}
local Fn, D = private.functions,private.data
Fn.GUI, Fn.UTILS, Fn.API = {},{},{}
local L = PriorityTarget_Localization
local EasyMenu = function(...)
if _G.EasyMenu then
return _G.EasyMenu(...)
else
local LibEasyMenu = LibStub:GetLibrary("LibEasyMenu",true)
if LibEasyMenu then
return LibEasyMenu:EasyMenu(...)
end
end
end
D._unload = CreateAtlasMarkup("common-icon-rotateleft",18,18,0,-2)
D.Presets,D.PresetLoaders,D.PresetLinks,D.Tooltip = {},{},{},{}
D.Tree = {
{value = L["Menu_General_Value"], text = L["Menu_General"]}, -- 1
{
value = L["Menu_Lists_Value"],
text = L["Menu_Lists"],
children = {},
}, -- 2
{value = L["Menu_Loaders_Value"], text = L["Menu_Loaders"]}, -- 3
}
local gui_lists = D.Tree[2].children
local DBName,DBPCName,DB,DBPC = format("%sDB",ADDON), format("%sDBPC",ADDON)
local DBVersion = 3 -- change this if we need to upgrade/reset variables
local label = format("|TInterface\\AddOns\\%s\\Reticule:0:|t|cff996666%s|r",ADDON,ADDON)
local pName = UnitName("player")
local theButton,timer
local AG = LibStub("AceGUI-3.0")
local ACM = LibStub("AceComm-3.0")
local ASZ = LibStub("AceSerializer-3.0")
local LDI = LibStub("LibDBIcon-1.0", true)
local LDB = LibStub("LibDataBroker-1.1", true)
local defaults = {
Lists = {},
Loaders = {},
Exact = true,
SafeTargeting = false,
AutoAccept = false,
DBVersion = DBVersion
}
local defaultsPC = {
Linked = {},
Minimap = true,
Visible = true,
AutoLoad = false
}
local events = CreateFrame("Frame")
events.ON_EVENT = function(self,event,...)
return self[event] and self[event](...)
end
events:SetScript("OnEvent",events.ON_EVENT)
events:RegisterEvent("ADDON_LOADED")
local combat_queue, delay_queue = {},{}
-- delayed execution
events.OnFinished = function(self,requested)
while next(delay_queue) do
if events.nocombat then
events.CombatCheck(tremove(delay_queue, 1))
else
tremove(delay_queue, 1)()
end
end
end
events.ag = events:CreateAnimationGroup()
events.ag:SetLooping("NONE")
events.ag.timer = events.ag:CreateAnimation("Animation")
events.timer = events.ag.timer
events.timer:SetScript("OnFinished",events.OnFinished)
events.RunAfter = function(seconds,nocombat)
events.nocombat = nocombat
if not events.ag:IsPlaying() then
events.timer:SetDuration(seconds)
events.ag:Play()
end
end
-- combat queue: FIFO
events.PLAYER_REGEN_ENABLED = function()
while next(combat_queue) do
tremove(combat_queue, 1)()
end
events:UnregisterEvent("PLAYER_REGEN_ENABLED")
end
events.CombatCheck = function(func)
if Fn.InCombat() then
if not tContains(combat_queue,func) then
tinsert(combat_queue,func)
events:RegisterEvent("PLAYER_REGEN_ENABLED")
end
else
func()
end
end
events.ADDON_LOADED = function(addonName)
if addonName == ADDON then
if IsLoggedIn() then
events.PLAYER_LOGIN()
else
events:RegisterEvent("PLAYER_LOGIN")
end
events:UnregisterEvent("ADDON_LOADED")
end
if addonName == "ElvUI" then
Fn.SkinButton()
end
end
events.PLAYER_LOGIN = function()
_G[DBName] = _G[DBName] or CopyTable(defaults)
_G[DBPCName] = _G[DBPCName] or CopyTable(defaultsPC)
DB,DBPC = _G[DBName], _G[DBPCName]
DB.Lists = DB.Lists or {}
DB.Loaders = DB.Loaders or {}
Fn.MigrateDB()
Fn.CopyPresets()
SlashCmdList["PRIOTARGET"] = Fn.Slasher
SLASH_PRIOTARGET1 = "/ptarget"
SLASH_PRIOTARGET2 = "/priotarget"
events.CombatCheck(Fn.theButton)
ACM.RegisterComm(Fn,ADDON,"OnListReceived")
Fn.SetAutoLoad(not not DBPC.AutoLoad)
if LDB then
D.Broker = LDB:NewDataObject(ADDON, {
type = "launcher",
label = ADDON,
icon = format("Interface\\AddOns\\%s\\Reticule",ADDON),
OnClick = function(self, mbutton)
if mbutton == "RightButton" then
Fn.OptionsGUI()
elseif (mbutton == "MiddleButton") or IsControlKeyDown() then
Fn.unloadList()
else
Fn.ToggleButton()
end
end,
OnEnter = function(self)
GameTooltip:SetOwner(self,"ANCHOR_TOPLEFT")
GameTooltip:SetText(label,1,1,1)
GameTooltip:AddLine(L["Minimap_Click"])
GameTooltip:AddLine(L["Minimap_RightClick"])
GameTooltip:AddLine(L["Minimap_MiddleClick"])
GameTooltip:Show()
end,
OnLeave = function(self)
if GameTooltip:IsOwned(self) then GameTooltip_Hide() end
end,
})
end
if LDI then
LDI:Register(ADDON, D.Broker, DBPC)
Fn.GUI.MinimapIcon()
end
end
events.UPDATE_BINDINGS = function()
if theButton then
local key1, key2 = GetBindingKey("CLICK prioTarget:LeftButton")
local keytext = ""
if key1 then
keytext = GetBindingText(key1,nil,1)
elseif key2 then
keytext = GetBindingText(key2,nil,1)
end
theButton.hotkey:SetText(keytext)
end
end
events.ZONE_CHANGED_NEW_AREA = function()
Fn.CheckForLoad("loc")
end
events.ZONE_CHANGED = events.ZONE_CHANGED_NEW_AREA
events.UNIT_TARGET = function()
Fn.CheckForLoad("npc")
end
events.PLAYER_TARGET_CHANGED = events.UNIT_TARGET
events.UPDATE_MOUSEOVER_UNIT = events.UNIT_TARGET
local numTemp = {}
Fn.UTILS.Numerize = function(empty,...)
wipe(numTemp)
for i=1,select("#",...) do
local arg_raw = (select(i,...))
local arg_num
if arg_raw == "" then arg_raw = empty end
arg_num = tonumber(arg_raw)
if arg_num then
tinsert(numTemp,arg_num)
else
tinsert(numTemp,arg_raw)
end
end
return unpack(numTemp)
end
local sortTbl,sortIter = {}
Fn.UTILS.sortedpairs = function(t)
wipe(sortTbl)
for k in pairs(t) do
tinsert(sortTbl,k)
end
sort(sortTbl)
local i = 0
sortIter = function()
i = i+1
local key = sortTbl[i]
if key then return key,t[key] end
end
return sortIter
end
Fn.UTILS.TargetIndexByName = function(list,targetName)
for idx, target in ipairs(list) do
if target.Name == targetName then return idx end
end
end
Fn.UTILS.validateInput = function(text)
return true
-- does not work with utf-8
-- local chError = strmatch(text,"[^%w_%-:\' %(%)]")
-- if chError then
-- return false,chError
-- else
-- return true
-- end
end
Fn.UTILS.targetListContains = function(list, targetName)
for _, name in ipairs(list) do
if name == targetName then
return true
end
end
end
Fn.SVtoGUIList = function()
wipe(gui_lists)
local sortedpairs = Fn.UTILS.sortedpairs
for key,list in sortedpairs(DB.Lists) do
-- for key,list in pairs(DB.Lists) do
tinsert(gui_lists,{value=key,text=key})
end
end
Fn.unloadList = function()
DB.Selected = D._unload
events.CombatCheck(Fn.SetMacro)
if D.OptionsFrame and D.OptionsFrame.Tree then
D.OptionsFrame.Tree:SelectByValue(L["Menu_Lists_Value"])
end
end
Fn.CheckForLoad = function(loaderType)
if not DBPC.AutoLoad then return end
if loaderType == "npc" then
local unitID = "mouseover"
if not UnitExists(unitID) then unitID = "target" end
if not UnitExists(unitID) then return end
local npcid = Fn.GetNPCID(unitID)
local loader = npcid and format("%s:%d",loaderType,npcid)
if loader and DBPC.Linked[loader] then
local listname = DBPC.Linked[loader]
if DB.Selected ~= listname then
DB.Selected = listname
print(format("%s: %s > |cff00ff00%s|r",label,DB.Loaders[loader],listname))
events.CombatCheck(Fn.SetMacro)
if D.OptionsFrame and D.OptionsFrame.Tree then
D.OptionsFrame.Tree:SelectByValue(L["Menu_Lists_Value"])
end
end
end
elseif loaderType == "loc" then
if WorldMapFrame:IsVisible() then return end
local mapID,mapname = Fn.GetMapData()
local posData = mapID and C_Map.GetPlayerMapPosition(mapID,"player") or nil
local pX, pY
if posData then
pX,pY = posData:GetXY()
else
px,pY = 0, 0
end
if not pX then pX,pY = 0,0 end
pX, pY = pX*100, pY*100
for loader,listname in pairs(DBPC.Linked) do
local l_mapID,west,east,north,south = Fn.UTILS.Numerize("0",strmatch(loader,"loc:(%d+):?(%d*):?(%d*):?(%d*):?(%d*)"))
if l_mapID then
if mapID == l_mapID then
local out_bounds =
(west~=0 and pX < west) or
(east~=0 and pX > east) or
(north~=0 and pY < north) or
(south~=0 and pY > south)
if not out_bounds then
if DB.Selected ~= listname then
DB.Selected = listname
print(format("%s: %s > |cff00ff00%s|r",label,DB.Loaders[loader],listname))
events.CombatCheck(Fn.SetMacro)
if D.OptionsFrame and D.OptionsFrame.Tree then
D.OptionsFrame.Tree:SelectByValue(L["Menu_Lists_Value"])
end
end
return
end
end
end
end
end
end
Fn.GetNPCID = function(unitid)
local npcGUID = not UnitIsPlayer(unitid) and UnitGUID(unitid)
if npcGUID then
local _, _, _, _, _, npcID = strsplit("-",npcGUID)
return tonumber(npcID)
end
return false
end
Fn.GetMapData = function()
local mapID,mapname
if WorldMapFrame:IsVisible() then
mapID = WorldMapFrame:GetMapID()
if mapID and C_Map.MapHasArt(mapID) then
local mapInfo = mapID and C_Map.GetMapInfo(mapID)
mapname = mapInfo and mapInfo.name
end
else
mapID = C_Map.GetBestMapForUnit("player")
local mapInfo = mapID and C_Map.GetMapInfo(mapID)
mapname = mapInfo and mapInfo.name
end
return mapID,mapname
end
Fn.UnLink = function(listname)
if not DBPC.Linked then return end
if not next(DBPC.Linked) then return end
for loader,list in pairs(DBPC.Linked) do
if list == listname then
DBPC.Linked[loader] = nil
end
end
end
Fn.MoveLink = function(sourselist,destlist)
for loaderkey,list in pairs(DBPC.Linked) do
if list == sourselist then
DBPC.Linked[sourselist] = nil
DBPC.Linked[destlist] = loaderkey
end
end
end
Fn.PrintMessage = function(message)
print(format("%s: %s", label, message))
end
Fn.CopyPresets = function(replace)
listsCopied, loadersCopied, linksCopied = Fn.CopyListPresets(replace), Fn.CopyLoaderPresets(replace), Fn.CopyLinkPresets(replace)
if listsCopied > 0 or loadersCopied > 0 or linksCopied > 0 then
Fn.PrintMessage(format(L["Presets_Loaded"],listsCopied,loadersCopied,linksCopied))
end
end
Fn.CopyListPresets = function(replace)
local copied = 0
for key,list in pairs(D.Presets) do
if not DB.Lists[key] or replace then
presetList = {}
DB.Lists[key] = presetList
for idx, targetName in ipairs(list) do
presetList[#presetList + 1] = { Name = targetName, Enabled = true }
end
copied = copied + 1
end
end
return copied
end
Fn.CopyLoaderPresets = function(replace)
local copied = 0
for key,name in pairs(D.PresetLoaders) do
if not DB.Loaders[key] or replace then
DB.Loaders[key] = name
copied = copied + 1
end
end
for key,name in pairs(D.PresetLoaders) do
if not DB.Loaders[key] or replace then
DB.Loaders[key] = name
copied = copied + 1
end
end
return copied
end
Fn.CopyLinkPresets = function(replace)
local isDirty
local copied = 0
for loader,list in pairs(D.PresetLinks) do
if not DBPC.Linked[loader] or replace then
DBPC.Linked[loader] = list
copied = copied + 1
end
end
if isDirty and D.OptionsFrame and D.OptionsFrame.Links:IsShown() then
D.OptionsFrame.Links:Hide()
end
return copied
end
Fn.MigrateDB = function() -- incremental saved variables migration
if not DB.DBVersion or DB.DBVersion < 2 then
local migratedLists = {}
for listName, list in pairs(DB.Lists) do
local newList = {}
for _, targetName in pairs(list) do
newList[#newList + 1] = { Name = targetName, Enabled = true }
end
migratedLists[listName] = newList
end
DB.Lists = migratedLists
end
if DB.DBVersion == 2 then
DB.Loaders["npc:91809"] = nil -- incorrect HFC Gorefiend id
DBPC.Linked["npc:91809"] = nil
DB.Loaders["npc:91809"] = nil -- incorrect HFC Tyran Velhari id
DBPC.Linked["npc:91809"] = nil
end
DB.DBVersion = DBVersion
end
Fn.SetAutoLoad = function(enable)
if enable then
events:RegisterEvent("UNIT_TARGET")
events:RegisterEvent("PLAYER_TARGET_CHANGED")
events:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
events:RegisterEvent("ZONE_CHANGED_NEW_AREA")
events:RegisterEvent("ZONE_CHANGED")
Fn.CheckForLoad("loc")
else
events:UnregisterEvent("UNIT_TARGET")
events:UnregisterEvent("PLAYER_TARGET_CHANGED")
events:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
events:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
events:UnregisterEvent("ZONE_CHANGED")
end
end
Fn.SendListComm = function(listname,list)
local dist,target
if UnitIsGroupLeader("player") then
if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
dist = "INSTANCE_CHAT"
elseif IsInRaid() then
dist = "RAID"
elseif IsInGroup() then
dist = "PARTY"
end
end
if theButton.DEBUG and not dist then dist,target = "WHISPER",pName end
if not dist then return end
local strData = ASZ:Serialize(listname,list)
ACM.SendCommMessage(Fn,ADDON,strData,dist,target)
Fn.PrintMessage(format(L["List_Sent"],listname))
end
Fn.OnListReceived = function(_, prefix, msg, dist, sender)
if prefix ~= ADDON then return end
if sender == pName and not theButton.DEBUG then return end
if not (UnitIsGroupLeader(sender) or theButton.DEBUG) then return end
local ok,listname,list = ASZ:Deserialize(msg)
if ok then
if not not DB.AutoAccept then
DB.Lists[listname] = list
DB.Selected = listname
Fn.SVtoGUIList()
D.OptionsFrame.Tree:RefreshTree()
events.CombatCheck(Fn.SetMacro)
else
Fn.GUI.ShowPopup(sender,listname,list)
end
end
end
Fn.Slasher = function(cmd)
cmd = cmd or ""
local cmdl = strlower(cmd)
if cmdl == "button" or cmdl == "but" then
-- show/hide button (ooc only)
Fn.ToggleButton()
elseif cmdl == "clear" or cmdl == "cl" then
Fn.unloadList()
elseif cmdl == "options" or cmdl == "opt" then
-- create (ooc to avoid 'script ran too long') or open options
Fn.OptionsGUI()
else
-- help
print(label)
print(L["CommandHelp_Button"])
print(L["CommandHelp_Clear"])
print(L["CommandHelp_Options"])
end
end
Fn.GUI.MinimapIcon = function()
if LDI then
if DBPC.Minimap then
LDI:Show(ADDON)
else
LDI:Hide(ADDON)
end
end
end
Fn.GUI.General = function(widget)
widget:ReleaseChildren()
if D.OptionsFrame and D.OptionsFrame.Links and D.OptionsFrame.Links:IsVisible() then
D.OptionsFrame.Links:Hide()
end
local head1 = AG:Create("Heading")
head1:SetText("Help")
head1:SetFullWidth(true)
local help = AG:Create("Label")
help:SetText(L["HelpText"])
help:SetFullWidth(true)
local head2 = AG:Create("Heading")
head2:SetText(L["AccountSettings"])
head2:SetFullWidth(true)
local exact = AG:Create("CheckBox")
exact.OnValueChanged = function(widget,event,value)
DB.Exact = not not value
Fn.SetMacro()
end
exact.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["ExactTargetMatchingCheckBox_Tooltip"],1,1,1)
GameTooltip:AddLine(L["ExactTargetMatchingCheckBox_Tooltip_Checked"])
GameTooltip:AddLine(L["ExactTargetMatchingCheckBox_Tooltip_Unchecked"])
GameTooltip:Show()
end
exact.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
exact:SetLabel(L["ExactTargetMatchingCheckBox_Label"])
exact:SetWidth(L["ExactTargetMatchingCheckBox_Width"])
exact:SetValue(not not DB.Exact) -- cast to boolean
exact:SetCallback("OnValueChanged",exact.OnValueChanged)
exact:SetCallback("OnEnter",exact.OnEnter)
exact:SetCallback("OnLeave",exact.OnLeave)
local safeTargeting = AG:Create("CheckBox")
safeTargeting.OnValueChanged = function(widget,event,value)
DB.SafeTargeting = not not value
Fn.SetMacro()
end
safeTargeting.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["SafeTargetingCheckBox_Tooltip"],1,1,1)
GameTooltip:AddLine(L["SafeTargetingCheckBox_Tooltip_Checked"])
GameTooltip:AddLine(L["SafeTargetingCheckBox_Tooltip_Unchecked"])
GameTooltip:Show()
end
safeTargeting.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
safeTargeting:SetLabel(L["SafeTargetingCheckBox_Label"])
safeTargeting:SetWidth(L["SafeTargetingCheckBox_Width"])
safeTargeting:SetValue(not not DB.SafeTargeting)
safeTargeting:SetCallback("OnValueChanged",safeTargeting.OnValueChanged)
safeTargeting:SetCallback("OnEnter",safeTargeting.OnEnter)
safeTargeting:SetCallback("OnLeave",safeTargeting.OnLeave)
local auto = AG:Create("CheckBox")
auto.OnValueChanged = function(widget,event,value)
DB.AutoAccept = not not value
end
auto.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["AutoAcceptCheckBox_Tooltip"],1,1,1)
GameTooltip:AddLine(L["AutoAcceptCheckBox_Tooltip_Checked"])
GameTooltip:AddLine(L["AutoAcceptCheckBox_Tooltip_Unchecked"])
GameTooltip:Show()
end
auto.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
auto:SetLabel(L["AutoAcceptCheckBox_Label"])
auto:SetWidth(L["AutoAcceptCheckBox_Width"])
auto:SetValue(not not DB.AutoAccept)
auto:SetCallback("OnValueChanged",auto.OnValueChanged)
auto:SetCallback("OnEnter",auto.OnEnter)
auto:SetCallback("OnLeave",auto.OnLeave)
local reloadpresets = AG:Create("Button")
reloadpresets:SetWidth(L["PresetsButton_Width"])
reloadpresets.OnClick = function(_,event,mbutton)
Fn.CopyPresets(true)
if DB.Selected and D.Presets[DB.Selected] then events.CombatCheck(Fn.SetMacro) end
end
reloadpresets.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["Presets_Tooltip"],1,1,1)
GameTooltip:AddLine(L["Presets_Tooltip_Detail"])
GameTooltip:Show()
end
reloadpresets.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
reloadpresets:SetText(L["Presets"])
reloadpresets:SetCallback("OnClick",reloadpresets.OnClick)
reloadpresets:SetCallback("OnEnter",reloadpresets.OnEnter)
reloadpresets:SetCallback("OnLeave",reloadpresets.OnLeave)
local head3 = AG:Create("Heading")
head3:SetText(L["Keybind"])
head3:SetFullWidth(true)
local keybind = AG:Create("Keybinding")
keybind.OnKeyChanged = function(widget,event,key)
local bindingset = GetCurrentBindingSet()
local isDirty
local key1,key2 = GetBindingKey("CLICK prioTarget:LeftButton")
if key and key ~= "" then
if key2 then
if key2 == key then
SetBinding(key1)
SaveBindings(bindingset)
return
else
SetBinding(key2)
isDirty = true
end
end
if key1 then
if key1 ~= key then
SetBinding(key1)
isDirty = true
else
if isDirty then SaveBindings(bindingset) end
return
end
end
SetBinding(key,"CLICK prioTarget:LeftButton")
SaveBindings(bindingset)
elseif key == "" then
if key2 then SetBinding(key2);isDirty = true end
if key1 then SetBinding(key1);isDirty = true end
if isDirty then SaveBindings(bindingset) end
end
end
local key1,key2 = GetBindingKey("CLICK prioTarget:LeftButton")
keybind:SetKey(key1 or key2 or "")
keybind:SetWidth(200)
keybind:SetCallback("OnKeyChanged",keybind.OnKeyChanged)
local head4 = AG:Create("Heading")
head4:SetText(L["CharacterSettings"])
head4:SetFullWidth(true)
local visible = AG:Create("CheckBox")
visible.OnValueChanged = function(widget,event,value)
DBPC.Visible = not not value
theButton:SetShown(DBPC.Visible)
end
visible.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["ButtonCheckBox_Tooltip"],1,1,1)
GameTooltip:AddLine(L["ButtonCheckBox_Tooltip_Checked"])
GameTooltip:AddLine(L["ButtonCheckBox_Tooltip_Unchecked"])
GameTooltip:Show()
end
visible.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
visible:SetLabel(L["ButtonCheckBox_Label"])
visible:SetWidth(L["ButtonCheckBox_Width"])
visible:SetValue(not not DBPC.Visible)
visible:SetCallback("OnValueChanged",visible.OnValueChanged)
visible:SetCallback("OnEnter",visible.OnEnter)
visible:SetCallback("OnLeave",visible.OnLeave)
local minimap = AG:Create("CheckBox")
minimap.OnValueChanged = function(widget,event,value)
DBPC.Minimap = not not value
Fn.GUI.MinimapIcon()
end
minimap.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["MinimapIconCheckBox_Tooltip"],1,1,1)
GameTooltip:AddLine(L["MinimapIconCheckBox_Tooltip_Checked"])
GameTooltip:AddLine(L["MinimapIconCheckBox_Tooltip_Unchecked"])
GameTooltip:Show()
end
minimap.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
minimap:SetLabel(L["MinimapIconCheckBox_Label"])
minimap:SetWidth(L["MinimapIconCheckBox_Width"])
minimap:SetValue(not not DBPC.Minimap)
minimap:SetCallback("OnValueChanged",minimap.OnValueChanged)
minimap:SetCallback("OnEnter",minimap.OnEnter)
minimap:SetCallback("OnLeave",minimap.OnLeave)
local autoLoad = AG:Create("CheckBox")
autoLoad.OnValueChanged = function(widget,event,value)
DBPC.AutoLoad = not not value
Fn.SetAutoLoad(DBPC.AutoLoad)
end
autoLoad.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["AutoLoadCheckBox_Tooltip"],1,1,1)
GameTooltip:AddLine(L["AutoLoadCheckBox_Tooltip_Checked"],nil,nil,nil,true)
GameTooltip:AddLine(L["AutoLoadCheckBox_Tooltip_Unchecked"],nil,nil,nil,true)
GameTooltip:Show()
end
autoLoad.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
autoLoad:SetLabel(L["AutoLoadCheckBox_Label"])
autoLoad:SetWidth(L["AutoLoadCheckBox_Width"])
autoLoad:SetValue(not not DBPC.AutoLoad)
autoLoad:SetCallback("OnValueChanged",autoLoad.OnValueChanged)
autoLoad:SetCallback("OnEnter",autoLoad.OnEnter)
autoLoad:SetCallback("OnLeave",autoLoad.OnLeave)
widget:AddChildren(head1,help,head2,exact,safeTargeting,auto,reloadpresets,head3,keybind,head4,visible,minimap,autoLoad)
end
local linkNPCs,linkMaps = {},{}
Fn.GUI.Links = function(listname)
-- if not theButton.DEBUG then return end -- for now
if not D.OptionsFrame.Links then
local linkframe = AG:Create("Frame")
linkframe:SetTitle("")
linkframe:SetStatusText(L["AutoLoadOptions_Text"])
linkframe:SetLayout("Fill")
linkframe:SetWidth(300)
linkframe:SetHeight(260)
linkframe:EnableResize(false)
linkframe:ClearAllPoints()
linkframe:SetPoint("TOPLEFT",D.OptionsFrame.frame,"TOPRIGHT",0,0)
linkframe.OnClose = function(widget,event)
linkframe.Group:ReleaseChildren()
end
linkframe:SetCallback("OnClose",linkframe.OnClose)
local group = AG:Create("InlineGroup")
group:SetFullWidth(true)
group:SetFullHeight(true)
group:SetLayout("Flow")
linkframe.Group = group
linkframe:AddChild(group)
linkframe:Hide()
D.OptionsFrame.Links = linkframe
end
if D.OptionsFrame.Links:IsShown() then
D.OptionsFrame.Links:Hide()
else
local group = D.OptionsFrame.Links.Group
local npclink = AG:Create("Dropdown")
npclink:SetWidth(250)
npclink:SetLabel(L["AutoLoadOptions_LinkToNPC"])
npclink:SetMultiselect(false)
npclink.RefreshList = function()
linkNPCs = wipe(linkNPCs)
npclink:SetUserData("LOADER",nil)
linkNPCs["_none"] = NONE
for loaderkey,name in pairs(DB.Loaders) do
if strfind(loaderkey,"^npc:") then
linkNPCs[loaderkey] = name
if DBPC.Linked[loaderkey] and DBPC.Linked[loaderkey] == listname then
npclink:SetUserData("LOADER",loaderkey)
end
end
end
npclink:SetList(linkNPCs)
local linked = npclink:GetUserData("LOADER")
if linked then npclink:SetValue(linked) else npclink:SetValue("_none") end
end
npclink.OnValueChanged = function(_,event,key)
if key~="_none" and DB.Loaders[key] then
DBPC.Linked[key] = listname
npclink:SetUserData("LOADER",key)
end
end
npclink:SetCallback("OnValueChanged",npclink.OnValueChanged)
npclink.RefreshList()
local spacer = AG:Create("Heading")
spacer:SetFullWidth(true)
local loclink = AG:Create("Dropdown")
loclink:SetWidth(250)
loclink:SetLabel(L["AutoLoadOptions_LinkToLocation"])
loclink:SetMultiselect(false)
loclink.RefreshList = function()
linkMaps = wipe(linkMaps)
loclink:SetUserData("LOADER",nil)
linkMaps["_none"] = NONE
for loaderkey,name in pairs(DB.Loaders) do
if strfind(loaderkey,"^loc:") then
linkMaps[loaderkey] = name
if DBPC.Linked[loaderkey] and DBPC.Linked[loaderkey] == listname then
loclink:SetUserData("LOADER",loaderkey)
end
end
end
loclink:SetList(linkMaps)
local linked = loclink:GetUserData("LOADER")
if linked then loclink:SetValue(linked) else loclink:SetValue("_none") end
end
loclink.OnValueChanged = function(_,event,key)
if key~="_none" and DB.Loaders[key] then
DBPC.Linked[key] = listname
loclink:SetUserData("LOADER",key)
Fn.CheckForLoad("loc")
end
end
loclink:SetCallback("OnValueChanged",loclink.OnValueChanged)
loclink.RefreshList()
local unlink = AG:Create("Button")
unlink:SetWidth(250)
unlink.OnClick = function(_,event,mbutton)
Fn.UnLink(listname)
npclink.RefreshList()
loclink:RefreshList()
end
unlink.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["AutoLoadOptions_UnlinkButton_Tooltip"],1,1,1)
GameTooltip:AddLine(format(L["AutoLoadOptions_UnlinkButton_Tooltip_Detail"],listname))
GameTooltip:Show()
end
unlink.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
unlink:SetText(L["AutoLoadOptions_UnlinkButton_Label"])
unlink:SetCallback("OnClick",unlink.OnClick)
unlink:SetCallback("OnEnter",unlink.OnEnter)
unlink:SetCallback("OnLeave",unlink.OnLeave)
group:AddChildren(npclink,spacer,loclink,unlink)
D.OptionsFrame.Links:SetTitle(listname)
D.OptionsFrame.Links:Show()
end
end
local fmt_label_npc,s_wowheadnpc = L["AutoLoadOptions_NPC_Label"], L["AutoLoadOptions_NPCWowheadLink"]
local fmt_label_loc,s_notsaved = L["AutoLoadOptions_Location_Label"], L["AutoLoadOptions_NotSaved"]
Fn.GUI.Loaders = function(widget)
widget:ReleaseChildren()
widget.RefreshLoaders = function()
sort(DB.Loaders)
widget.loaderList:SetList(DB.Loaders)
end
local overlay = Fn.MapMonitor()
local head1 = AG:Create("Heading")
head1:SetText(L["AutoLoadOptions_LoadByNPC"])
head1:SetFullWidth(true)
local npclabel = AG:Create("Label")
npclabel.SetTextFields = function()
local id,name = npclabel:GetUserData("NPC_ID"),npclabel:GetUserData("LOADER")
id = id or ""; name = name or s_notsaved
npclabel:SetText(format(fmt_label_npc,id,(id~="" and s_wowheadnpc or id),id,name))
end
npclabel.ClearData = function()
wipe(npclabel:GetUserDataTable())
end
npclabel:SetFullWidth(true)
npclabel.SetTextFields()
local npcloader = AG:Create("EditBox")
npcloader.OnEnterPressed = function(_,event,text)
text = strtrim(text)
text = text:gsub("%[npc%]","")
if not text or text == "" then
npcloader:ClearFocus()
return
end
local valid, invalid = Fn.UTILS.validateInput(text)
if not valid then
print(format(L["AutoLoadOptions_InvalidInput"],label,invalid))
return
end
if valid then
local npc_id = npclabel:GetUserData("NPC_ID")
local loaderkey = npc_id and format("npc:%d",npc_id)
if loaderkey then
local loadername = format("[npc]%s",text)
DB.Loaders[loaderkey] = loadername
npclabel:SetUserData("LOADER",loadername)
npclabel.SetTextFields()
widget.RefreshLoaders()
end
end
npcloader:SetText("")
npcloader:ClearFocus()
end
npcloader.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["AutoLoadOptions_LoaderName_Tooltip"],1,1,1)
GameTooltip:AddLine(L["AutoLoadOptions_LoaderName_Tooltip_Detail"],nil,nil,nil,true)
GameTooltip:Show()
end
npcloader.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
npcloader:SetMaxLetters(50)
npcloader:SetWidth(180)
npcloader:SetCallback("OnEnterPressed",npcloader.OnEnterPressed)
npcloader:SetCallback("OnEnter",npcloader.OnEnter)
npcloader:SetCallback("OnLeave",npcloader.OnLeave)
npcloader:SetLabel(L["AutoLoadOptions_SaveLoader"])
local npcid = AG:Create("EditBox")
npcid:SetWidth(120)
npcid:SetMaxLetters(10)
npcid:SetLabel(L["AutoLoadOptions_NPCID_Label"])
npcid.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOPLEFT")
GameTooltip:SetText(L["AutoLoadOptions_NPCID_Tooltip"],1,1,1)
local id = npcid:GetText()
if not id or id == "" then
GameTooltip:AddLine(L["AutoLoadOptions_NPCID_Tooltip_Detail1"],nil,nil,nil,true)
end
GameTooltip:AddLine(L["AutoLoadOptions_NPCID_Tooltip_Detail2"],nil,nil,nil,true)
GameTooltip:AddLine(L["AutoLoadOptions_NPCID_Tooltip_Detail3"],nil,nil,nil,true)
GameTooltip:Show()
end
npcid.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
npcid.OnEnterPressed = function(_,event,text)
text = strtrim(text)
if not text or text == "" then
npcid:ClearFocus()
return
end
local id = tonumber(text)
if not id then
print(format(L["AutoLoadOptions_InvalidInput"],label,text))
return
end
npcid:SetText("")
npcid:ClearFocus()
if id then
npclabel.ClearData()
npclabel:SetUserData("NPC_ID",id)
npclabel.SetTextFields()
npcloader:SetFocus()
end
end
npcid:SetCallback("OnEnterPressed",npcid.OnEnterPressed)
npcid:SetCallback("OnEnter",npcid.OnEnter)
npcid:SetCallback("OnLeave",npcid.OnLeave)
local addnpcid = AG:Create("Icon")
addnpcid:SetImage("Interface\\ICONS\\INV_Misc_Head_Gnoll_01")
addnpcid:SetImageSize(22,22)
addnpcid:SetWidth(25)
addnpcid:SetHeight(30)
addnpcid.OnEnter = function(widget)
GameTooltip:SetOwner(widget.frame,"ANCHOR_TOP")
GameTooltip:SetText(L["AutoLoadOptions_TargetNPCID_Tooltip"],1,1,1)
GameTooltip:AddLine(L["AutoLoadOptions_TargetNPCID_Tooltip_Detail"],nil,nil,nil,true)
GameTooltip:Show()
end
addnpcid.OnLeave = function(widget)
if GameTooltip:IsOwned(widget.frame) then GameTooltip_Hide() end
end
addnpcid.OnClick = function(_,event,mbutton)
if UnitExists("target") then
local npc_id = Fn.GetNPCID("target")
npclabel.ClearData()
npclabel.SetTextFields()
if npc_id then
npcid:SetText(npc_id)
npcid:SetFocus()
else
npcid:SetText("")
end
end
end
-- addnpcid:SetCallback("OnClick",addnpcid.OnClick) -- icon widget calls AceGUI:ClearFocus() after firing the OnClick callback...
addnpcid:SetCallback("OnEnter",addnpcid.OnEnter)
addnpcid:SetCallback("OnLeave",addnpcid.OnLeave)
addnpcid.frame:SetScript("PostClick",addnpcid.OnClick)
local head2 = AG:Create("Heading")
head2:SetText(L["AutoLoadOptions_LoadByLocation"])
head2:SetFullWidth(true)
local loclabel = AG:Create("Label")
loclabel.SetTextFields = function()
local id,name = loclabel:GetUserData("MAP_ID"),loclabel:GetUserData("LOADER")
local mapname = loclabel:GetUserData("MAP_NAME")
mapname = mapname or ""
id = id or ""; name = name or s_notsaved
local w,n,e,s = loclabel:GetUserData("BOUND_WEST"),loclabel:GetUserData("BOUND_NORTH"),loclabel:GetUserData("BOUND_EAST"),loclabel:GetUserData("BOUND_SOUTH")
w = w or ""; n = n or ""; e = e or ""; s = s or ""
loclabel:SetText(format(fmt_label_loc,id,w,n,e,s,mapname,name))