-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.lua
More file actions
1279 lines (1118 loc) · 51.5 KB
/
Options.lua
File metadata and controls
1279 lines (1118 loc) · 51.5 KB
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 addon_name, addon = ...
local module = addon:NewModule("Options", "AceConsole-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("PetCall")
local AceConfigRegistry = LibStub("AceConfigRegistry-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceConfig = LibStub("AceConfig-3.0")
local AceDBOptions = LibStub("AceDBOptions-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local LibPetJournal = LibStub("LibPetJournal-2.0")
local error, hooksecurefunc, ipairs, pairs, PlaySound, select,
setmetatable, strfind, string, table, tinsert, tostring, tremove,
type, wipe
= error, hooksecurefunc, ipairs, pairs, PlaySound, select,
setmetatable, strfind, string, table, tinsert, tostring, tremove,
type, wipe
local LibDBIcon = LibStub("LibDBIcon-1.0")
--
--
--
local W = 8
local L_WeightValues = {
-- value, short, long
{0, false, "|cffff0000"..L["Never"].."|r"},
{W^-2, "|cffff6600-2", "|cffff6600"..L["Extra Low Priority"].."|r"},
{W^-1, "|cffff9900-1", "|cffff9900"..L["Low Priority"].."|r"},
{W^0, true, "|cffddff00"..L["Normal"].."|r"},
{W^1, "|cff99ff00+1", "|cff99ff00"..L["High Priority"].."|r"},
{W^2, "|cff00ff00+2", "|cff00ff00"..L["Extra High Priority"].."|r"},
}
local L_WeightValuesFlat = {}
for _, item in ipairs(L_WeightValues) do
L_WeightValuesFlat[item[1]] = item[3]
end
local L_SetPriority = {}
for _, item in ipairs(L_WeightValues) do
if item[2] ~= false then
L_SetPriority[item[1]] = item[3]
end
end
local options = {
name = "PetCall",
handler = addon,
type = 'group',
args = {
main = {
name = GENERAL,
type = 'group',
childGroups = "tab",
args = {
general = {
name = GENERAL,
type = "group",
order = 10,
get = function(info) return addon.db.profile[info[#info]] end,
set = function(info, val)
addon.db.profile[info[#info]] = val
addon.Ready:UpdateChecks()
end,
args = {
enable = {
type = "toggle",
name = ENABLE,
desc = L["Automatically summon a companion pet when entering a new area or when idle. Respects your pet selection, filters, and trigger settings."],
order = 10,
width = "full",
get = function(info) return addon:IsEnabledSummoning() end,
set = function(info,v) addon:EnableSummoning(v) end,
},
nearPEWOnly = {
type = "toggle",
name = L["Only Summon After Zoning"],
desc = L["Only summon a pet when entering a new area or zone. When disabled, a pet is also summoned after standing still for the configured wait time."],
order = 11,
width = "double"
},
enableInBattleground = {
type = "toggle",
name = L["Enable In Battlegrounds/Arena"],
desc = L["Allow PetCall to summon pets while in battlegrounds and arenas. Cannot be combined with Dismiss In Battlegrounds."],
order = 13,
width = "double",
disabled = function() return addon.db.profile.dismissInBattleground end,
},
enableInPVE = {
type = "toggle",
name = L["Enable In PVE Instances"],
desc = L["Allow PetCall to summon pets while in dungeons and raids. Cannot be combined with Dismiss In PVE Instances."],
order = 13,
width = "double",
disabled = function() return addon.db.profile.dismissInPVE end,
},
disableOutsideCities = {
type = "toggle",
name = L["Only Enable in Cities"],
desc = L["Restrict pet summoning to city areas only. Your pet will be dismissed when you leave a city."],
order = 14,
width = "double",
},
dismissWhenStealthed = {
type = "toggle",
name = L["Dismiss When Stealthed or Invisible"],
desc = L["Automatically dismiss your pet when you enter stealth or use an invisibility effect."],
order = 15,
width = "double",
},
dismissInBattleground = {
type = "toggle",
name = L["Dismiss In Battlegrounds/Arena"],
desc = L["Automatically dismiss your pet when entering a battleground or arena. Cannot be combined with Enable In Battlegrounds."],
order = 17,
width = "double",
disabled = function() return addon.db.profile.enableInBattleground end,
},
dismissInPVE = {
type = "toggle",
name = L["Dismiss In PVE Instances"],
desc = L["Automatically dismiss your pet when entering a dungeon or raid. Cannot be combined with Enable In PVE Instances."],
order = 17,
width = "double",
disabled = function() return addon.db.profile.enableInPVE end,
},
overrideSetLoadout = {
type = "toggle",
name = L["Override Pet Battle Loadout"],
desc = L["Re-summon your PetCall pet after the game auto-summons one via the Pet Battle Loadout screen."],
order = 30,
width = "double",
},
waitTimerValue = {
type = "range",
name = L["Wait Time (Seconds)"],
desc = L["Seconds of inactivity before PetCall summons a pet. Only applies when Only Summon After Zoning is disabled."],
order = 40,
min = 1,
step = .5,
bigStep = 1,
max = 30,
get = function()
return addon.db.profile.waitTimer
end,
set = function(info,v)
addon.db.profile.waitTimer = v
end
},
verbose = {
type = "toggle",
name = L["Verbose"],
desc = L["Print a message in the chat window each time a pet is summoned or dismissed."],
order = 100,
width = "double",
},
showMinimapButton = {
type = "toggle",
name = L["Show Minimap Button"],
desc = L["Show the PetCall icon on the minimap for quick access to the pet selection menu."],
order = 101,
width = "double",
get = function()
return not addon.db.profile.minimap.hide
end,
set = function(info, v)
addon.db.profile.minimap.hide = not v
if v then
LibDBIcon:Show("PetCall")
else
LibDBIcon:Hide("PetCall")
end
end
}
},
},
autoSwitch = {
name = L["Auto Switch Pet"],
type = "group",
order = 30,
args = {
autoSwitchTimerEnable = {
type = "toggle",
name = L["Enable Timed Auto Switch"],
desc = L["Automatically switch to a different random pet from your selection after a set amount of time."],
width = "double",
order = 31,
get = function() return addon.db.profile.autoSwitch.timer end,
set = function(info,v)
addon.db.profile.autoSwitch.timer = v
if(v) then
addon.SwitchTimer:Start()
end
end
},
autoSwitchTimerValue = {
type = "range",
name = L["Seconds between switch"],
desc = L["How often (in seconds) to automatically switch to a different pet from your selection."],
order = 32,
min = 60,
step = 1,
bigStep = 60,
max = 3600,
disabled = function() return not addon.db.profile.autoSwitch.timer end,
get = function()
return addon.db.profile.autoSwitch.timerValue
end,
set = function(info,v)
addon.db.profile.autoSwitch.timerValue = v
addon.SwitchTimer:Start()
end
},
autoSwitchCitiesOnly = {
type = "toggle",
name = L["Only use Timed Auto Switch in cities"],
desc = L["Restrict timed pet switching to city areas. Automatic switching pauses when you leave a city."],
width = "double",
order = 33,
get = function() return addon.db.profile.autoSwitch.citiesOnly end,
set = function(info,v) addon.db.profile.autoSwitch.citiesOnly = v end,
},
autoSwitchOnZone = {
type = "toggle",
name = L["Auto Switch when changing maps"],
desc = L["Switch to a different random pet each time you travel to a new map or zone."],
width = "double",
order = 40,
get = function() return addon.db.profile.autoSwitch.onZone end,
set = function(info,v) addon.db.profile.autoSwitch.onZone = v end,
}
}
}
}
}
},
plugins = {}
}
local options_slashcmd = {
name = "PetCall Slash Command",
handler = addon,
type = "group",
order = -2,
args = {
config = {
type = "execute",
name = L["Open Configuration"],
dialogHidden = true,
order = 1,
func = function(info) addon:OpenOptions() end
},
resummon = {
type = "execute",
name = L["Summon Another Pet"],
desc = L["Dismiss your current pet and summon another pet. Enable summoning if needed."],
order = 20,
func = function(info) addon:ResummonPet(true, true) end
},
dismiss = {
type = "execute",
name = L["Dismiss Pet"],
desc = L["Dismiss your currently summoned pet. Disable summoning."],
order = 21,
func = function(info) addon:DismissPet(true) end
},
desummon = {
-- included for backwards compat
type = "execute",
name = L["Dismiss Pet"],
hidden = true,
func = function(info) addon:DismissPet(true) end
},
togglePet = {
type = "execute",
name = L["Toggle Non-Combat Pet"],
order = 22,
func = function(info) addon:TogglePet() end
},
enable = options.args.main.args.general.args.enable,
dismissWhenStealthed = options.args.main.args.general.args.dismissWhenStealthed,
debugstate = {
type = "execute",
name = "Debug State",
hidden = true,
func = function(info) addon:DumpDebugState() end
},
migrate = {
type = "execute",
name = "Import PetLeash",
hidden = true,
func = function(info) addon:ManualMigratePrompt() end
}
},
}
function module:OnInitialize()
self.db = addon.db
self.options = options
self.options.args.profiles = AceDBOptions:GetOptionsTable(self.db)
self.options_slashcmd = options_slashcmd
AceConfig:RegisterOptionsTable(addon.name, options)
AceConfig:RegisterOptionsTable(addon.name .. "SlashCmd", options_slashcmd)
-- Register slash commands manually so that bare /pcall opens the config panel
-- instead of printing AceConfigCmd help text.
local AceConfigCmd = LibStub("AceConfigCmd-3.0")
local function slashHandler(input)
if not input or input:trim() == "" then
module:OpenOptions()
else
AceConfigCmd:HandleCommand("petcall", addon.name .. "SlashCmd", input)
end
end
addon:RegisterChatCommand("petcall", slashHandler)
addon:RegisterChatCommand("pcall", slashHandler)
-- WoW 10.0+: Settings API requires categories to be registered at load time
-- (old lazy-init pattern no longer works; AddToBlizOptions must run on startup)
self:SetupOptions()
end
function module:OpenOptions()
self:SetupOptions()
-- WoW 10.0+: Settings.OpenToCategory replaces InterfaceOptionsFrame_OpenToCategory
-- AceConfigDialog v92+ returns (frame, categoryID) from AddToBlizOptions
if self._mainCategoryID then
Settings.OpenToCategory(self._mainCategoryID)
end
end
function module:SetupOptions()
-- we delay setting up options until here so that plugins in seperate
-- addons will load properly
if self.didSetup then return end
self.didSetup = true
-- AceConfigDialog v92+ returns (frame, categoryID); capture both
self.optionsFrame, self._mainCategoryID = AceConfigDialog:AddToBlizOptions(addon.name, addon.name, nil, "main")
self._mainCategoryID = self._mainCategoryID or (self.optionsFrame and self.optionsFrame.name)
self.PetSelection = AceGUI:Create("BlizOptionsGroup")
self.PetSelection:SetUserData("options", {
showSetConfig = false,
showList = false,
showTriggerTab = false
})
self.PetSelection:SetName(L["Pet Selection"], addon.name)
self.PetSelection:SetTitle(L["Pet Selection"])
self.PetSelection:SetLayout("flow")
self.PetSelection:SetCallback("OnShow", function() self:PetSelection_Fill(self.PetSelection, "$Default") end)
self.PetSelection:SetCallback("OnHide", function() self:PetSelection_Clear(self.PetSelection) end)
-- WoW 10.0+: register as subcategory under addon.name
-- Use BlizOptionsIDMap + Settings.GetCategory (AceConfigDialog v92+ pattern)
do
local idMap = AceConfigDialog.BlizOptionsIDMap
local parentID = idMap and idMap[addon.name]
local parentCat = parentID and Settings.GetCategory(parentID)
local cat
if parentCat then
cat = Settings.RegisterCanvasLayoutSubcategory(parentCat, self.PetSelection.frame, L["Pet Selection"])
else
cat = Settings.RegisterCanvasLayoutCategory(self.PetSelection.frame, L["Pet Selection"])
Settings.RegisterAddOnCategory(cat)
end
self.PetSelection.frame.settingsCategory = cat
end
self.PetTriggers = AceGUI:Create("BlizOptionsGroup")
self.PetTriggers:SetUserData("options", {
showSetConfig = true,
showList = true,
showTriggerTab = true
})
self.PetTriggers:SetName(L["Pet Triggers"], addon.name)
self.PetTriggers:SetTitle(L["Pet Triggers"])
self.PetTriggers:SetLayout("flow")
self.PetTriggers:SetCallback("OnShow", function() self:PetSelection_Fill(self.PetTriggers) end)
self.PetTriggers:SetCallback("OnHide", function() self:PetSelection_Clear(self.PetTriggers) end)
do
local idMap = AceConfigDialog.BlizOptionsIDMap
local parentID = idMap and idMap[addon.name]
local parentCat = parentID and Settings.GetCategory(parentID)
local cat
if parentCat then
cat = Settings.RegisterCanvasLayoutSubcategory(parentCat, self.PetTriggers.frame, L["Pet Triggers"])
else
cat = Settings.RegisterCanvasLayoutCategory(self.PetTriggers.frame, L["Pet Triggers"])
Settings.RegisterAddOnCategory(cat)
end
self.PetTriggers.frame.settingsCategory = cat
end
for name, module in addon:IterateModules() do
local f = module["SetupOptions"]
if f then
f(module, function(appName, name) AceConfigDialog:AddToBlizOptions(appName, name, addon.name) end)
end
end
self.Profile = AceConfigDialog:AddToBlizOptions(addon.name, L["Profiles"], addon.name, "profiles")
-- Custom About panel (replaces LibAboutPanel)
do
local aboutFrame = CreateFrame("Frame", nil, UIParent)
aboutFrame:Hide() -- must be hidden first so OnShow fires when Settings shows it
-- Register as subcategory under PetCall (WoW 10.0+ Settings API)
do
local idMap = AceConfigDialog.BlizOptionsIDMap
local parentID = idMap and idMap[addon.name]
local parentCat = parentID and Settings.GetCategory(parentID)
local cat
if parentCat then
cat = Settings.RegisterCanvasLayoutSubcategory(parentCat, aboutFrame, "About")
else
cat = Settings.RegisterCanvasLayoutCategory(aboutFrame, "About")
Settings.RegisterAddOnCategory(cat)
end
aboutFrame.settingsCategory = cat
end
-- Build content lazily on first show (frame geometry is available after show)
aboutFrame:SetScript("OnShow", function(self)
if self._built then return end
self._built = true
-- Own scroll frame (canvas layout doesn't auto-scroll)
local sf = CreateFrame("ScrollFrame", nil, self, "UIPanelScrollFrameTemplate")
sf:SetPoint("TOPLEFT", self, "TOPLEFT", 0, -4)
sf:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -28, 4)
local c = CreateFrame("Frame", nil, sf)
c:SetWidth(sf:GetWidth())
sf:SetScrollChild(c)
local PAD = 20
local INDENT = 12
local LINE_SM = 20
local LINE_MD = 24
local function div(atY)
local d = c:CreateTexture(nil, "ARTWORK")
d:SetColorTexture(0.25, 0.25, 0.40, 0.35)
d:SetHeight(1)
d:SetPoint("TOPLEFT", c, "TOPLEFT", PAD, atY)
d:SetPoint("TOPRIGHT", c, "TOPRIGHT", -PAD, atY)
end
local function head(text, atY)
local fs = c:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fs:SetPoint("TOPLEFT", c, "TOPLEFT", PAD, atY)
fs:SetText("|cffd4af37" .. text .. "|r")
end
local function body(text, atY, extraIndent)
local fs = c:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
fs:SetPoint("TOPLEFT", c, "TOPLEFT", PAD + (extraIndent or 0), atY)
fs:SetPoint("TOPRIGHT", c, "TOPRIGHT", -PAD, atY)
fs:SetJustifyH("LEFT")
fs:SetNonSpaceWrap(true)
fs:SetText(text)
end
local function twoCol(label, value, atY, labelW)
labelW = labelW or 140
local lbl = c:CreateFontString(nil, "OVERLAY", "GameFontNormal")
lbl:SetPoint("TOPLEFT", c, "TOPLEFT", PAD + INDENT, atY)
lbl:SetWidth(labelW)
lbl:SetJustifyH("LEFT")
lbl:SetText(label)
local val = c:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
val:SetPoint("TOPLEFT", c, "TOPLEFT", PAD + INDENT + labelW + 8, atY)
val:SetPoint("TOPRIGHT", c, "TOPRIGHT", -PAD, atY)
val:SetJustifyH("LEFT")
val:SetText("|cff888899" .. value .. "|r")
end
local y = -PAD
-- ── HEADER ───────────────────────────────────────────────────
local ver = C_AddOns.GetAddOnMetadata("PetCall", "Version") or "1.0.1"
local titleFS = c:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
titleFS:SetPoint("TOPLEFT", c, "TOPLEFT", PAD, y)
titleFS:SetText("|cffd4af37PetCall|r |cff777799" .. ver .. "|r")
y = y - 30
body("Automatically summons your companion pet based on configurable triggers, filters, and priority sets.", y)
y = y - 44
local buildFS = c:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
buildFS:SetPoint("TOPLEFT", c, "TOPLEFT", PAD, y)
buildFS:SetText("|cff555577WoW: Midnight · Interface 120001|r")
y = y - 28
-- ── WHAT'S NEW ───────────────────────────────────────────────
div(y - 6); y = y - 24
head("What's New — " .. ver, y); y = y - LINE_MD
local changes = addon.releaseNotes or {}
for _, line in ipairs(changes) do
body("|cff667766•|r " .. line, y, INDENT)
y = y - LINE_SM
end
-- ── COMMANDS ─────────────────────────────────────────────────
div(y - 4); y = y - 22
head("Commands", y); y = y - LINE_MD
local cmds = {
{ "|cff77cc77/petcall|r, |cff77cc77/pcall|r", "Open configuration panel" },
{ "|cff77cc77/petcall resummon|r", "Summon another pet; enable if needed" },
{ "|cff77cc77/petcall dismiss|r", "Dismiss current pet; disable summoning" },
{ "|cff77cc77/petcall togglePet|r", "Toggle pet on / off without changing enable state" },
{ "|cff77cc77/petcall enable|r", "Toggle auto-summon on / off" },
{ "|cff77cc77/petcall migrate|r", "Import PetLeash profile data" },
}
for _, row in ipairs(cmds) do
twoCol(row[1], row[2], y, 210)
y = y - LINE_SM
end
-- ── KEY BINDINGS ─────────────────────────────────────────────
div(y - 4); y = y - 22
head("Key Bindings", y); y = y - LINE_MD
local binds = {
{ "Summon Another Pet", "PETCALL_SUMMON" },
{ "Dismiss Pet", "PETCALL_DESUMMON" },
{ "Toggle Non-Combat Pet", "PETCALL_TOGGLE" },
{ "Open Configuration", "PETCALL_CONFIG" },
}
for _, row in ipairs(binds) do
local key = GetBindingKey(row[2]) or "|cff555566not bound|r"
twoCol("|cffcccccc" .. row[1] .. "|r", key, y, 210)
y = y - LINE_SM
end
body("|cff444466Configure in Game Menu > Key Bindings > AddOns > PetCall.|r", y, INDENT)
y = y - LINE_SM
-- ── CREDITS ──────────────────────────────────────────────────
div(y - 8); y = y - 26
head("Credits", y); y = y - LINE_MD
local credits = {
{ "|cffddddddCryzer|r", "WoW 12.0 refactor, new features" },
{ "|cffddddddEnd|r", "Original PetLeash 3.1.5 (2018)" },
{ "|cffff8c42Claude AI|r", "Development assistance (Anthropic)" },
}
for _, row in ipairs(credits) do
twoCol(row[1], row[2], y, 120)
y = y - LINE_SM
end
body("|cff444466Translations maintained by the WoW community.|r", y, INDENT)
y = y - LINE_SM
-- Set content height so the scroll frame knows the full extent
c:SetHeight(-y + PAD)
end)
module.About = aboutFrame
end
end
--
-- Pet Selection Options
--
do
--
-- mainTree
--
local mainPage_Fill, mainPage_FillList
function module:PetSelection_Fill(frame, set)
if not set then
mainPage_FillList(frame)
else
mainPage_Fill(frame, set)
end
end
function module:PetSelection_Clear(frame)
frame:ReleaseChildren()
end
do
--
-- mainPage (List)
--
local function newSet_onEnterPressed(frame, event, value)
value = string.gsub(value, "^%s*(.-)%s*$", "%1")
if #value == 0 or strfind(value, "^%$") then
PlaySound(SOUNDKIT.IG_PLAYER_INVITE_DECLINE)
UIErrorsFrame:AddMessage("Set name cannot be empty or begin with '$'.", 1, 0.3, 0.3)
return
end
addon:NewSet(value)
mainPage_FillList(frame:GetUserData("mainPage"))
frame:SetText("")
end
local function setEditButton_OnClick(frame, event)
module:PetSelection_Fill(frame:GetUserData("mainPage"),
frame:GetUserData("setName"))
end
StaticPopupDialogs["PETCALL_DELETE_SET"] = {
text = "Delete \"%s\"?\nThis cannot be undone.",
button1 = DELETE,
button2 = CANCEL,
OnAccept = function(self, data)
local set = addon:GetSetByName(data.setName)
if set then set:Delete() end
data.onDeleted()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
local function setDeleteButton_OnClick(frame, event)
StaticPopup_Show("PETCALL_DELETE_SET",
frame:GetUserData("setName"), nil,
{ setName = frame:GetUserData("setName"),
onDeleted = function()
mainPage_FillList(frame:GetUserData("mainPage"))
end })
end
local setsTmp = {}
function mainPage_FillList(frame)
frame:ReleaseChildren()
frame:PauseLayout()
frame:SetTitle(L["Pet Triggers"])
local desc = AceGUI:Create("Label")
desc:SetText("Each set defines when and which companion to summon. Use Edit to configure its trigger conditions and pet pool.")
desc:SetFullWidth(true)
desc.label:SetFontObject(GameFontNormal)
frame:AddChild(desc)
local addNew = AceGUI:Create("EditBox")
addNew:SetLabel("Add New Set")
addNew:SetRelativeWidth(0.50)
addNew:DisableButton(true)
addNew:SetCallback("OnEnterPressed", newSet_onEnterPressed)
addNew:SetUserData("mainPage", frame)
frame:AddChild(addNew)
local createButton = AceGUI:Create("Button")
createButton:SetText("Create")
createButton:SetRelativeWidth(0.23)
createButton:SetCallback("OnClick", function()
newSet_onEnterPressed(addNew, nil, addNew:GetText())
end)
frame:AddChild(createButton)
local importButton = AceGUI:Create("Button")
importButton:SetText("Import Set")
importButton:SetRelativeWidth(0.25)
importButton:SetCallback("OnClick", function()
addon:ShowImportDialog(function()
mainPage_FillList(frame)
end)
end)
frame:AddChild(importButton)
local scroll = AceGUI:Create("ScrollFrame")
scroll:SetLayout("Flow")
scroll:SetFullWidth(true)
scroll:SetFullHeight(true)
frame:SetUserData("scrollFrame", scroll)
frame:AddChild(scroll)
local setDB = addon.db.profile.sets
wipe(setsTmp)
for setName in pairs(setDB) do
if not strfind(setName, "^%$") then
tinsert(setsTmp, setName)
end
end
table.sort(setsTmp)
if #setsTmp == 0 then
local emptyLabel = AceGUI:Create("Label")
emptyLabel:SetText("|cffaaaaadNo sets yet. Type a name above and press Enter to create your first trigger set.|r")
emptyLabel:SetFullWidth(true)
scroll:AddChild(emptyLabel)
end
for _,setName in pairs(setsTmp) do
local setData = setDB[setName]
-- Two-column layout: each card is ~half the scroll width.
-- Card title: gray + "(disabled)" when the set is off.
local titleStr = setData.name or setName
if setData.enabled == false then
titleStr = "|cffaaaaad" .. titleStr .. " (disabled)|r"
end
local group = AceGUI:Create("InlineGroup")
group:SetTitle(titleStr)
group:SetRelativeWidth(0.49)
group:SetLayout("Flow")
local trigCount = #(setData.trigger or {})
local petCount = 0
if setData.pets then
for _, w in pairs(setData.pets) do
if type(w) == "number" and w > 0 then petCount = petCount + 1 end
end
end
-- Orange text when set has no triggers (won't activate).
local summaryFmt = trigCount == 0
and "|cffff9933%d trigger%s \194\183 %d pet%s selected|r"
or "%d trigger%s \194\183 %d pet%s selected"
local summary = AceGUI:Create("Label")
summary:SetText(string.format(summaryFmt,
trigCount, trigCount == 1 and "" or "s",
petCount, petCount == 1 and "" or "s"))
summary:SetFullWidth(true)
summary.label:SetFontObject(GameFontNormal)
group:AddChild(summary)
-- Three equal-width buttons.
local editButton = AceGUI:Create("Button")
editButton:SetText(L["Edit"])
editButton:SetRelativeWidth(0.30)
editButton:SetUserData("setName", setName)
editButton:SetUserData("mainPage", frame)
editButton:SetCallback("OnClick", setEditButton_OnClick)
group:AddChild(editButton)
local deleteButton = AceGUI:Create("Button")
deleteButton:SetText(DELETE)
deleteButton:SetRelativeWidth(0.30)
deleteButton:SetUserData("setName", setName)
deleteButton:SetUserData("mainPage", frame)
deleteButton:SetCallback("OnClick", setDeleteButton_OnClick)
group:AddChild(deleteButton)
local exportButton = AceGUI:Create("Button")
exportButton:SetText("Export")
exportButton:SetRelativeWidth(0.30)
exportButton:SetUserData("setName", setName)
exportButton:SetCallback("OnClick", function(btn)
addon:ShowExportDialog(btn:GetUserData("setName"))
end)
group:AddChild(exportButton)
scroll:AddChild(group)
end
frame:ResumeLayout()
frame:DoLayout()
end
end
do
--
-- mainPage
--
local selectTab_Fill
local filterTriggerTab_Fill
local deleteRenameTab_Fill
local function backButton_OnClick(frame, event)
module:PetSelection_Fill(frame:GetUserData("mainPage"), nil)
end
local function enabled_OnValueChanged(frame, event, value)
local set = frame:GetUserData("set")
set.settings.enabled = value
set:Refresh()
end
local function priority_OnValueChanged(frame, event, key)
local set = frame:GetUserData("set")
set.settings.priority = key
set:Refresh()
end
local function immediate_OnValueChanged(frame, event, v)
local set = frame:GetUserData("set")
set.settings.immediate = v
set:Refresh()
end
local function tab_onGroupSelected(frame, event, value)
frame:PauseLayout()
local set = frame:GetUserData("set")
if value == "select" then
selectTab_Fill(frame, set)
elseif value == "filter" then
filterTriggerTab_Fill(frame, set, "filter")
elseif value == "trigger" then
filterTriggerTab_Fill(frame, set, "trigger")
elseif value == "deleteRename" then
deleteRenameTab_Fill(frame, set)
end
frame:ResumeLayout()
frame:DoLayout()
end
function mainPage_Fill(parent, setName)
parent:ReleaseChildren()
parent:PauseLayout()
local options = parent:GetUserData("options")
local set = addon:GetSetByName(setName)
if options.showList then
parent:SetTitle("") -- create our own title to put back button on same line
local title = AceGUI:Create("Label")
title:SetText(setName)
title:SetFontObject(GameFontNormalLarge)
title:SetColor(1.0, 0.82, 0)
parent:AddChild(title)
local backButton = AceGUI:Create("Button")
backButton:SetText(L[" <<< Back "])
backButton:SetUserData("mainPage", parent)
backButton:SetCallback("OnClick", backButton_OnClick)
parent:AddChild(backButton)
end
if options.showSetConfig then
local enabledGroup = AceGUI:Create("SimpleGroup")
enabledGroup:SetFullWidth(true)
enabledGroup:SetLayout("Flow")
parent:AddChild(enabledGroup)
local enabled = AceGUI:Create("CheckBox")
enabled:SetUserData("set", set)
enabled:SetLabel(ENABLE)
enabled:SetWidth(145)
enabled:SetValue(set.settings.enabled)
enabled:SetCallback("OnValueChanged", enabled_OnValueChanged)
enabledGroup:AddChild(enabled)
local prio = AceGUI:Create("Dropdown")
prio:SetUserData("set", set)
prio:SetWidth(145)
prio:SetLabel(L["Priority"])
prio:SetList(L_SetPriority)
prio:SetValue(set.settings.priority)
prio:SetCallback("OnValueChanged", priority_OnValueChanged)
enabledGroup:AddChild(prio)
local immediate = AceGUI:Create("CheckBox")
immediate:SetUserData("set", set)
immediate:SetWidth(145)
immediate:SetLabel(L["Immediate"])
immediate:SetValue(set.settings.immediate)
immediate:SetCallback("OnValueChanged", immediate_OnValueChanged)
enabledGroup:AddChild(immediate)
local configHint = AceGUI:Create("Label")
configHint:SetText("|cffaaaaadPriority: when multiple sets match, the highest-priority one wins. Immediate: summon without waiting for the idle timer.|r")
configHint:SetFullWidth(true)
parent:AddChild(configHint)
end
local tabTree = { { text = L["Select Pets"], value= "select" }, { text = L["Filters"], value = "filter" } }
if options.showTriggerTab then
tinsert(tabTree, 1, { text = "Triggers", value= "trigger" })
tinsert(tabTree, { text = "Delete/Rename", value= "deleteRename" })
end
local tabs = AceGUI:Create("TabGroup")
tabs:SetTabs(tabTree)
tabs:SetLayout("Fill")
tabs:SetFullWidth(true)
tabs:SetFullHeight(true)
tabs:SetCallback("OnGroupSelected", tab_onGroupSelected)
tabs:SetUserData("mainPage", parent)
parent:AddChild(tabs)
tabs:SetUserData("setName", setName)
tabs:SetUserData("set", set)
if options.showTriggerTab then
tabs:SelectTab("trigger")
else
tabs:SelectTab("select")
end
parent:ResumeLayout()
parent:DoLayout()
end
do
--
-- selectTab
--
local function selector_OnDefaultChanged(self, event, value)
local set = self:GetUserData("set")
if set.settings.defaultValue ~= value then
set.settings.defaultValue = value
end
set:Refresh()
end
local function selector_OnClear(self, event)
local set = self:GetUserData("set")
set:Refresh()
end
function selectTab_Fill(frame, set)
frame:ReleaseChildren()
local selector = AceGUI:Create("PetCall_PetSelectList")
selector:SetFullWidth(true)
selector:SetFullHeight(true)
selector:SetDefault(set.settings.defaultValue)
selector:SetTable(set.settings.pets)
selector:SetWeightValues(L_WeightValues)
selector:SetCallback("OnDefaultChanged", selector_OnDefaultChanged)
selector:SetCallback("OnClear", selector_OnClear)
frame:AddChild(selector)
selector:SetUserData("set", set)
end
end
do
--
-- filterTab/triggerTab
--
local filterTrigger = {
filter = {
addHeading = L["Add Filter"],
settingsKey = "filter",
iterator = "IterateFilters",
get = "GetFilterByKey",
hasPriority = true,
},
trigger = {
addHeading = L["Add Trigger Condition"],
settingsKey = "trigger",
iterator = "IterateTriggers",
get = "GetTriggerByKey",
hasPriority = false,
}
}
local function filterTriggerTab_reload(tab)
filterTriggerTab_Fill(tab, tab:GetUserData("set"), tab:GetUserData("type"))
end
local function addButton_OnClick(frame, event)
local settings = frame:GetUserData("settings")
local ft = frame:GetUserData("ft")
tinsert(settings, ft:New())
filterTriggerTab_reload(frame:GetUserData("tab"))
end
local function prio_OnValueChanged(frame, event, value)
local settings = frame:GetUserData("settings")
settings[2] = value
end
local function deleteButton_onClick(frame, event)
tremove(frame:GetUserData("settings"), frame:GetUserData("i"))
filterTriggerTab_reload(frame:GetUserData("tab"))
end
local function cmpButton(a, b)
return a:GetUserData("ft"):GetName() < b:GetUserData("ft"):GetName()
end
local addButtonTmp = {}
local function filterTriggerTab_FillItems(tab, frame, type, settings, isRoot)
if not tab then
tab = frame:GetUserData("tab")
end
frame:SetUserData("settings", settings)