-
Notifications
You must be signed in to change notification settings - Fork 0
/
HotbarProfiles.lua
1460 lines (1161 loc) · 41.3 KB
/
HotbarProfiles.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 AceGUI = LibStub("AceGUI-3.0")
local DEBUG = "|cffff0000Debug:|r "
local S2KFI = LibStub("LibS2kFactionalItems-1.0")
HotbarProfiles = LibStub("AceAddon-3.0"):NewAddon("HotbarProfiles", "AceConsole-3.0")
local HotbarProfiles = HotbarProfiles
local function log(msg)
HotbarProfiles:Print(msg)
end
HotbarPopup = AceGUI:Create("Frame")
local function toggleHBP()
HotbarProfiles.db.profile.drop.hide = not HotbarProfiles.db.profile.drop.hide
log(HotbarProfiles.db.profile.drop.hide)
if HotbarProfiles.db.profile.drop.hide then
HotbarPopup:Hide()
else
HotbarPopup:Show()
end
end
function HotbarProfiles:encodeLink(data)
return data:gsub(".", function(x)
return ((x:byte() < 32 or x:byte() == 127 or x == "|" or x == ":" or x == "[" or x == "]" or x == "~") and string.format("~%02x", x:byte())) or x
end)
end
function HotbarProfiles:saveActions(profile)
local flyouts, tsNames, tsIds = {}, {}, {}
local book
for book = 1, GetNumSpellTabs() do
local offset, count, _, spec = select(3, GetSpellTabInfo(book))
if spec == 0 then
local index
for index = offset + 1, offset + count do
local type, id = GetSpellBookItemInfo(index, BOOKTYPE_SPELL)
local name = GetSpellBookItemName(index, BOOKTYPE_SPELL)
if type == "FLYOUT" then
flyouts[id] = name
elseif type == "SPELL" and IsTalentSpell(index, BOOKTYPE_SPELL) then
tsNames[name] = id
end
end
end
end
local talents = {}
local tier
for tier = 1, MAX_TALENT_TIERS do
local column = select(2, GetTalentTierInfo(tier, 1))
if column and column > 0 then
local id, name = GetTalentInfo(tier, column, 1)
if tsNames[name] then
tsIds[tsNames[name]] = id
end
talents[tier] = GetTalentLink(id)
end
end
profile.talents = talents
local actions = {}
local savedMacros = {}
local slot
for slot = 1, HBP_MAX_ACTION_BUTTONS do
local type, id, sub = GetActionInfo(slot)
if type == "spell" then
if tsIds[id] then
actions[slot] = GetTalentLink(tsIds[id])
else
actions[slot] = GetSpellLink(id)
end
elseif type == "flyout" then
if flyouts[id] then
actions[slot] = string.format(
"|cffff0000|Habp:flyout:%d|h[%s]|h|r",
id, flyouts[id]
)
end
elseif type == "item" then
actions[slot] = select(2, GetItemInfo(id))
elseif type == "companion" then
if sub == "MOUNT" then
actions[slot] = GetSpellLink(id)
end
elseif type == "summonpet" then
actions[slot] = C_PetJournal.GetBattlePetLink(id)
elseif type == "summonmount" then
if id == 0xFFFFFFF then
actions[slot] = GetSpellLink(HBP_RANDOM_MOUNT_SPELL_ID)
else
actions[slot] = GetSpellLink(({ C_MountJournal.GetMountInfoByID(id) })[2])
end
elseif type == "macro" then
if id > 0 then
local name, icon, body = GetMacroInfo(id)
icon = icon or HBP_EMPTY_ICON_TEXTURE_ID
if id > MAX_ACCOUNT_MACROS then
actions[slot] = string.format(
"|cffff0000|Habp:macro:%s:%s|h[%s]|h|r",
icon, self:encodeLink(body), name
)
else
actions[slot] = string.format(
"|cffff0000|Habp:macro:%s:%s:1|h[%s]|h|r",
icon, self:encodeLink(body), name
)
end
savedMacros[id] = true
end
elseif type == "equipmentset" then
actions[slot] = string.format(
"|cffff0000|Habp:equip|h[%s]|h|r",
id
)
end
end
profile.actions = actions
local macros = {}
local allMacros, charMacros = GetNumMacros()
local index
for index = 1, allMacros do
local name, icon, body = GetMacroInfo(index)
icon = icon or HBP_EMPTY_ICON_TEXTURE_ID
if body and not savedMacros[index] then
table.insert(macros, string.format(
"|cffff0000|Habp:macro:%s:%s:1|h[%s]|h|r",
icon, self:encodeLink(body), name
))
end
end
for index = MAX_ACCOUNT_MACROS + 1, MAX_ACCOUNT_MACROS + charMacros do
local name, icon, body = GetMacroInfo(index)
icon = icon or HBP_EMPTY_ICON_TEXTURE_ID
if body and not savedMacros[index] then
table.insert(macros, string.format(
"|cffff0000|Habp:macro:%s:%s|h[%s]|h|r",
icon, self:encodeLink(body), name
))
end
end
profile.macros = macros
end
function HotbarProfiles:saveBars(name)
local list = self.db.profile.list
local profile = { name = name, default = false }
self:saveActions(profile)
list[name] = profile
HotbarPopup:updateProfileList()
HotbarPopup:SetStatusText("Profile '" .. name .. "' saved");
end
function HotbarProfiles:deleteProfile(profile)
local list = self.db.profile.list
list[profile.name] = nil
HotbarPopup:SetStatusText("Profile '" .. profile.name .. "' deleted");
end
function HotbarProfiles:cPrintf(cond, ...)
if cond then self:Printf(...) end
end
function HotbarPopup:getDropDownProfileList(list)
local name, profile
local optimizedList = {}
for name, profile in pairs(list) do
optimizedList[name] = name
end
return optimizedList
end
function HotbarPopup:selectDefaultProfile()
local defaultProfile = nil
local name, profile
for name, profile in pairs(HotbarProfiles.db.profile.list) do
if profile.default then
defaultProfile = name
end
end
self.profilesDropdown:SetValue(defaultProfile)
end
function HotbarPopup:updateProfileList()
local list = self:getDropDownProfileList(HotbarProfiles.db.profile.list)
self.profilesDropdown:SetList(list)
self:selectDefaultProfile()
end
function HotbarPopup:deleteProfile()
HotbarProfiles:deleteProfile(self.selectedProfile)
self:updateProfileList()
end
function HotbarPopup:useProfile()
if not self.selectedProfile then
return
end
HotbarProfiles:UseProfile(self.selectedProfile)
HotbarPopup:SetStatusText("Profile '" .. self.selectedProfile.name .. "' set");
end
function HotbarPopup:updateSavedContainer()
--self.savedProfilesContainer:Release()
self.profilesDropdown = AceGUI:Create("Dropdown")
local list = self:getDropDownProfileList(HotbarProfiles.db.profile.list)
self.profilesDropdown:SetList(list)
self.profilesDropdown:SetCallback("OnValueChanged", function(this, event, key)
self.selectedProfile = HotbarProfiles.db.profile.list[key]
end)
self.savedProfilesContainer:AddChild(self.profilesDropdown)
local profileDeleteBtn = AceGUI:Create("Button")
profileDeleteBtn:SetText("Delete profile")
profileDeleteBtn:SetCallback("OnClick", function ()
HotbarPopup:deleteProfile()
end)
self.savedProfilesContainer:AddChild(profileDeleteBtn)
local profileUseBtn = AceGUI:Create("Button")
profileUseBtn:SetText("Use profile")
--profileUseBtn:SetDisabled(true) -- temporary to not click it :)
profileUseBtn:SetCallback("OnClick", function ()
HotbarPopup:useProfile()
end)
self.savedProfilesContainer:AddChild(profileUseBtn)
local name, profile
for name, profile in pairs(HotbarProfiles.db.profile.list) do
if profile.default then
self.profilesDropdown:SetValue(name)
end
end
end
function HotbarPopup:drawHotbarPopup()
self.selectedProfile = nil
local scrollContainer = AceGUI:Create("SimpleGroup")
scrollContainer:SetFullWidth(true)
scrollContainer:SetLayout("List") -- important!
self:AddChild(scrollContainer)
--top section frame
local mainFrame = AceGUI:Create("InlineGroup")
mainFrame:SetLayout("Flow")
local saveActionBars = AceGUI:Create("Label")
saveActionBars:SetText("Enter name to save your current setup")
mainFrame:AddChild(saveActionBars)
local saveABName = AceGUI:Create("EditBox")
saveABName:SetLabel("Name:")
saveABName:SetCallback("OnEnterPressed", function (widget, event, text)
HotbarProfiles:saveBars(text)
end)
mainFrame:AddChild(saveABName)
-- bottom part
self.savedProfilesContainer = AceGUI:Create("InlineGroup")
self.savedProfilesContainer:SetLayout("Flow")
self:updateSavedContainer()
scrollContainer:AddChild(mainFrame)
scrollContainer:AddChild(self.savedProfilesContainer)
end
function HotbarPopup:createHotbarPopup()
self:SetTitle("HotbarProfiles")
self:SetCallback("OnClose", function(widget)
HotbarProfiles.db.profile.drop.hide = true
self:Hide()
end)
self:SetLayout("Fill")
self:drawHotbarPopup()
end
function HotbarProfiles:RestorePetJournalFilters(saved)
C_PetJournal.SetSearchFilter(saved.text)
local i
for i in table.s2k_values(PET_JOURNAL_FLAGS) do
C_PetJournal.SetFilterChecked(i, saved.flag[i])
end
for i = 1, C_PetJournal.GetNumPetSources() do
C_PetJournal.SetPetSourceChecked(i, saved.source[i])
end
for i = 1, C_PetJournal.GetNumPetTypes() do
C_PetJournal.SetPetTypeFilter(i, saved.type[i])
end
end
function HotbarProfiles:SavePetJournalFilters()
local saved = { flag = {}, source = {}, type = {} }
saved.text = C_PetJournal.GetSearchFilter()
local i
for i in table.s2k_values(PET_JOURNAL_FLAGS) do
saved.flag[i] = C_PetJournal.IsFilterChecked(i)
end
for i = 1, C_PetJournal.GetNumPetSources() do
saved.source[i] = C_PetJournal.IsPetSourceChecked(i)
end
for i = 1, C_PetJournal.GetNumPetTypes() do
saved.type[i] = C_PetJournal.IsPetTypeChecked(i)
end
return saved
end
log("HotbarProfiles use /hbp to enable the addon")
local hpLDB = LibStub("LibDataBroker-1.1"):NewDataObject("HotbarProfiles", {
type = "data source",
text = "HotbarProfiles",
icon = "Interface\\Icons\\INV_Chest_Cloth_17",
OnClick = function()
log("HotbarProfiles addon by Mike")
toggleHBP()
end,
})
local icon = LibStub("LibDBIcon-1.0")
function HotbarProfiles:OnInitialize()
-- Obviously you'll need a ## SavedVariables: HotbarProfilesDB line in your TOC, duh!
self.db = LibStub("AceDB-3.0"):New("HotbarProfilesDB", {
profile = {
minimap = {
hide = false,
},
drop = {
hide = true,
},
list = {},
},
})
icon:Register("HotbarProfiles", hpLDB, self.db.profile.minimap)
self:RegisterChatCommand("hbp", "HotbarProfilesControll")
log("Fisto sucks!")
HotbarPopup:createHotbarPopup()
HotbarPopup:Hide()
end
icon:Show("HotbarProfiles")
function HotbarProfiles:HotbarProfilesControll()
toggleHBP()
end
--[[
Copy from ActionBarProfiles
https://github.com/Silencer2K/wow-action-bar-profiles/
--]]
function HotbarProfiles:GetProfiles(filter, case)
local list = self.db.profile.list
local sorted = {}
local name, profile
for name, profile in pairs(list) do
if not filter or name == filter or (case and name:lower() == filter:lower()) then
profile.name = name
table.insert(sorted, profile)
end
end
if #sorted > 1 then
local class = select(2, UnitClass("player"))
table.sort(sorted, function(a, b)
if a.class == b.class then
return a.name < b.name
else
return a.class == class
end
end)
end
return unpack(sorted)
end
function HotbarProfiles:UseProfile(profile, check, cache)
if type(profile) ~= "table" then
local list = self.db.profile.list
profile = list[profile]
if not profile then
return 0, 0
end
end
cache = cache or self:MakeCache()
local macros = cache.macros
local talents = cache.talents
local res = { fail = 0, total = 0 }
if not profile.skipMacros then
self:RestoreMacros(profile, check, cache, res)
end
--if not profile.skipTalents then
--self:RestoreTalents(profile, check, cache, res)
--end
if not profile.skipActions then
self:RestoreActions(profile, check, cache, res)
end
if not profile.skipPetActions then
self:RestorePetActions(profile, check, cache, res)
end
--if not profile.skipBindings then
--self:RestoreBindings(profile, check, cache, res)
--end
cache.macros = macros
cache.talents = talents
return res.fail, res.total
end
function HotbarProfiles:DecodeLink(data)
return data:gsub("~[0-9A-Fa-f][0-9A-Fa-f]", function(x)
return string.char(tonumber(x:sub(2), 16))
end)
end
function HotbarProfiles:RestoreMacros(profile, check, cache, res)
local fail, total = 0, 0
local all, char = GetNumMacros()
local macros
if self.db.profile.replace_macros then
macros = { id = {}, name = {} }
if not check then
local index
for index = 1, all do
DeleteMacro(1)
end
for index = 1, char do
DeleteMacro(MAX_ACCOUNT_MACROS + 1)
end
end
all, char = 0, 0
else
macros = table.s2k_copy(cache.macros)
end
local slot
for slot = 1, HBP_MAX_ACTION_BUTTONS do
local link = profile.actions[slot]
if link then
-- has action
local data, name = link:match("^|c.-|H(.-)|h%[(.-)%]|h|r$")
link = link:gsub("|Habp:.+|h(%[.+%])|h", "%1")
if data then
local type, sub, icon, body, global = strsplit(":", data)
if type == "abp" and sub == "macro" then
local ok
total = total + 1
body = self:DecodeLink(body)
if self:GetFromCache(macros, self:PackMacro(body)) then
ok = true
elseif (global and all < MAX_ACCOUNT_MACROS) or (not global and char < MAX_CHARACTER_MACROS) then
if check or CreateMacro(name, icon, body, not global) then
ok = true
self:UpdateCache(macros, -1, self:PackMacro(body), name)
end
if ok then
all = all + ((global and 1) or 0)
char = char + ((global and 0) or 1)
end
end
if not ok then
fail = fail + 1
self:cPrintf(not check, "L.msg_cant_create_macro", link)
end
end
else
self:cPrintf(profile.skipActions and not check, "L.msg_bad_link", link)
end
end
end
if self.db.profile.replace_macros and profile.macros then
for slot = 1, #profile.macros do
local link = profile.macros[slot]
local data, name = link:match("^|c.-|H(.-)|h%[(.-)%]|h|r$")
link = link:gsub("|Habp:.+|h(%[.+%])|h", "%1")
if data then
local type, sub, icon, body, global = strsplit(":", data)
if type == "abp" and sub == "macro" then
local ok
total = total + 1
body = self:DecodeLink(body)
if self:GetFromCache(macros, self:PackMacro(body)) then
ok = true
elseif (global and all < MAX_ACCOUNT_MACROS) or (not global and char < MAX_CHARACTER_MACROS) then
if check or CreateMacro(name, icon, body, not global) then
ok = true
self:UpdateCache(macros, -1, self:PackMacro(body), name)
end
if ok then
all = all + ((global and 1) or 0)
char = char + ((global and 0) or 1)
end
end
if not ok then
fail = fail + 1
self:cPrintf(not check, "L.msg_cant_create_macro", link)
end
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
end
end
if not check then
-- correct macro ids
self:PreloadMacros(macros)
end
cache.macros = macros
if res then
res.fail = res.fail + fail
res.total = res.total + total
end
return fail, total
end
function HotbarProfiles:RestoreTalents(profile, check, cache, res)
local fail, total = 0, 0
-- hack: update cache
local talents = { id = {}, name = {} }
local rest = self.auraState or IsResting()
local tier
for tier = 1, MAX_TALENT_TIERS do
local link = profile.talents[tier]
if link then
-- has action
local ok
total = total + 1
local data, name = link:match("^|c.-|H(.-)|h%[(.-)%]|h|r$")
link = link:gsub("|Habp:.+|h(%[.+%])|h", "%1")
if data then
local type, sub = strsplit(":", data)
local id = tonumber(sub)
if type == "talent" then
local found = self:GetFromCache(cache.allTalents[tier], id, name, not check and link)
if found then
if self:GetFromCache(cache.talents, id) or rest or select(2, GetTalentTierInfo(tier, 1)) == 0 then
ok = true
-- hack: update cache
self:UpdateCache(talents, found, id, select(2, GetTalentInfoByID(id)))
if not check then
LearnTalent(found)
end
else
self:cPrintf(not check, "L.msg_cant_learn_talent", link)
end
else
self:cPrintf(not check, "L.msg_talent_not_exists", link)
end
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
if not ok then
fail = fail + 1
end
end
end
-- hack: update cache
cache.talents = talents
if res then
res.fail = res.fail + fail
res.total = res.total + total
end
return fail, total
end
function HotbarProfiles:RestoreActions(profile, check, cache, res)
local fail, total = 0, 0
local slot
for slot = 1, HBP_MAX_ACTION_BUTTONS do
local link = profile.actions[slot]
if link then
-- has action
local ok
total = total + 1
local data, name = link:match("^|c.-|H(.-)|h%[(.-)%]|h|r$")
link = link:gsub("|Habp:.+|h(%[.+%])|h", "%1")
if data then
local type, sub, p1, p2, _, _, _, p6 = strsplit(":", data)
local id = tonumber(sub)
if type == "spell" then
if id == HBP_RANDOM_MOUNT_SPELL_ID then
ok = true
if not check then
self:PlaceMount(slot, 0, link)
end
else
local found = self:FindSpellInCache(cache.spells, id, name, not check and link)
if found then
ok = true
if not check then
self:PlaceSpell(slot, found, link)
end
end
end
self:cPrintf(not ok and not check, "L.msg_spell_not_exists " .. name, link)
elseif type == "talent" then
local found = self:GetFromCache(cache.talents, id, name, not check and link)
if found then
ok = true
if not check then
self:PlaceTalent(slot, found, link)
end
end
self:cPrintf(not ok and not check, "L.msg_spell_not_exists", link)
elseif type == "item" then
if PlayerHasToy(id) then
ok = true
if not check then
self:PlaceItem(slot, id, link)
end
else
local found = self:FindItemInCache(cache.equip, id, name, not check and link)
if found then
ok = true
if not check then
self:PlaceInventoryItem(slot, found, link)
end
else
found = self:FindItemInCache(cache.bags, id, name, not check and link)
if found then
ok = true
if not check then
self:PlaceContainerItem(slot, found[1], found[2], link)
end
end
end
end
if not ok and not check then
self:PlaceItem(slot, S2KFI:GetConvertedItemId(id) or id, link)
end
ok = true -- sic!
elseif type == "battlepet" then
local found = self:GetFromCache(cache.pets, p6, id, not check and link)
if found then
ok = true
if not check then
self:PlacePet(slot, found, link)
end
end
self:cPrintf(not ok and not check, "L.msg_pet_not_exists", link)
elseif type == "abp" then
id = tonumber(p1)
if sub == "flyout" then
local found = self:FindFlyoutInCache(cache.flyouts, id, name, not check and link)
if found then
ok = true
if not check then
self:PlaceFlyout(slot, found, BOOKTYPE_SPELL, link)
end
end
self:cPrintf(not ok and not check, "L.msg_spell_not_exists", link)
elseif sub == "macro" then
local found = self:GetFromCache(cache.macros, self:PackMacro(self:DecodeLink(p2)), name, not check and link)
if found then
ok = true
if not check then
self:PlaceMacro(slot, found, link)
end
end
if profile.skipMacros then
self:cPrintf(not ok and not check, "L.msg_macro_not_exists", link)
else
total = total - 1
if not ok then
fail = fail - 1
end
end
elseif sub == "equip" then
if GetEquipmentSetInfoByName(name) then
ok = true
if not check then
self:PlaceEquipment(slot, name, link)
end
end
self:cPrintf(not ok and not check, "L.msg_equip_not_exists", link)
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
if not ok then
fail = fail + 1
if not profile.skipEmptySlots and not check then
self:ClearSlot(slot)
end
end
else
if not profile.skipEmptySlots and not check then
self:ClearSlot(slot)
end
end
end
if res then
res.fail = res.fail + fail
res.total = res.total + total
end
return fail, total
end
function HotbarProfiles:RestorePetActions(profile, check, cache, res)
if not HasPetSpells() or not profile.petActions then
return 0, 0
end
local fail, total = 0, 0
local slot
for slot = 1, NUM_PET_ACTION_SLOTS do
local link = profile.petActions[slot]
if link then
-- has action
local ok
total = total + 1
local data, name = link:match("^|c.-|H(.-)|h%[(.-)%]|h|r$")
link = link:gsub("|Habp:.+|h(%[.+%])|h", "%1")
if data then
local type, sub, p1 = strsplit(":", data)
local id = tonumber(sub)
if type == "spell" or (type == "abp" and sub == "pet") then
if type == "spell" then
name = GetSpellInfo(id) or name
else
id = -2
name = _G[name] or name
end
local found = self:GetFromCache(cache.petSpells, id, name, type == "spell" and link)
if found then
ok = true
if not check then
self:PlacePetSpell(slot, found, link)
end
end
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
else
self:cPrintf(not check, "L.msg_bad_link", link)
end
if not ok then
fail = fail + 1
if not check then
self:ClearPetSlot(slot)
end
end
else
-- empty slot
if not check then
self:ClearPetSlot(slot)
end
end
end
if res then
res.fail = res.fail + fail
res.total = res.total + total
end
return fail, total
end
function HotbarProfiles:RestoreBindings(profile, check, cache, res)
if check then
return 0, 0
end
-- clear
local index
for index = 1, GetNumBindings() do
local bind = { GetBinding(index) }
if bind[3] then
local idx, key
for idx, key in pairs({ select(3, unpack(bind)) }) do
SetBinding(key)
end
end
end
-- restore
local cmd, keys
for cmd, keys in pairs(profile.bindings) do
local idx, key
for idx, key in pairs(keys) do
SetBinding(key, cmd)
end
end
if LibStub("AceAddon-3.0"):GetAddon("Dominos", true) and profile.bindingsDominos then
for index = 13, 60 do
local idx, key
-- clear
for idx, key in pairs({ GetBindingKey(string.format("CLICK DominosActionButton%d:LeftButton", index)) }) do
SetBinding(key)
end
-- restore
if profile.bindingsDominos[index] then
for idx, key in pairs(profile.bindingsDominos[index]) do
SetBindingClick(key, string.format("DominosActionButton%d", index), "LeftButton")
end
end
end
end
SaveBindings(GetCurrentBindingSet())
return 0, 0
end
function HotbarProfiles:UpdateCache(cache, value, id, name)
cache.id[id] = value
if cache.name and name then
cache.name[name] = value
end
end
function HotbarProfiles:GetFromCache(cache, id, name, link)
if cache.id[id] then
return cache.id[id]
end
if cache.name and name and cache.name[name] then
self:cPrintf(link, DEBUG .. "L.msg_found_by_name " .. name, link)
return cache.name[name]
end
end
function HotbarProfiles:FindSpellInCache(cache, id, name, link)
name = GetSpellInfo(id) or name
local found = self:GetFromCache(cache, id, name, link)
if found then
return found
end
local similar = HBP_SIMILAR_SPELLS[id]