forked from Boboseb/FloFlyout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FloFlyout.lua
executable file
·1927 lines (1695 loc) · 65.8 KB
/
FloFlyout.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
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
-- You can obtain one at http://mozilla.org/MPL/2.0/.
local MY_NAME, MY_GLOBALS = ...
local debug = MY_GLOBALS.DEBUG
local L = FLOFLYOUT_L10N_STRINGS -- auto loaded from locales directory
FloFlyout = LibStub("AceAddon-3.0"):NewAddon(MY_NAME, "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0")
FloFlyout.openers = {} -- copies of flyouts that sit on the action bars
-------------------------------------------------------------------------------
-- Constants
-------------------------------------------------------------------------------
local V_MAJOR = 10
local V_MINOR = 0
local V_PATCH = 7
local VERSION = table.concat({V_MAJOR, V_MINOR, V_PATCH}, ".")
local NAME = MY_NAME
local MAX_FLYOUT_SIZE = 20
local NON_SPEC_SLOT = 5
local SPELLFLYOUT_DEFAULT_SPACING = 4
local SPELLFLYOUT_INITIAL_SPACING = 7
local SPELLFLYOUT_FINAL_SPACING = 4
local STRIPE_COLOR = {r=0.9, g=0.9, b=1}
local STRATA_DEFAULT = "MEDIUM"
local STRATA_MAX = "TOOLTIP"
local DUMMY_MACRO_NAME = "__ffodnd"
local MAX_GLOBAL_MACRO_ID = 120
local STRUCT_FLYOUT_DEF = { spells={}, actionTypes={}, mountIndex={}, spellNames={}, macroOwners={}, pets={} } -- "spell" can mean also item, mount, macro, etc.
local BLIZ_BAR_METADATA = {
[1] = {name="Action", visibleIf="bar:1,nobonusbar:1,nobonusbar:2,nobonusbar:3,nobonusbar:4"}, -- primary "ActionBar" - page #1 - no stance/shapeshift --- ff: actionBarPage = 1
[2] = {name="Action", visibleIf="bar:2"}, -- primary "ActionBar" - page #2 (regardless of stance/shapeshift) --- ff: actionBarPage = 2
[3] = {name="MultiBarRight", classicType=2}, -- config UI -> Action Bars -> checkbox #4
[4] = {name="MultiBarLeft", classicType=2}, -- config UI -> Action Bars -> checkbox #5
[5] = {name="MultiBarBottomRight", classicType=1}, -- config UI -> Action Bars -> checkbox #3
[6] = {name="MultiBarBottomLeft", classicType=1}, -- config UI -> Action Bars -> checkbox #2
[7] = {name="Action", visibleIf="bar:1,bonusbar:1"}, -- primary "ActionBar" - page #1 - bonusbar 1 - druid CAT
[8] = {name="Action", visibleIf="bar:1,bonusbar:2"}, -- primary "ActionBar" - page #1 - bonusbar 2 - unknown?
[9] = {name="Action", visibleIf="bar:1,bonusbar:3"}, -- primary "ActionBar" - page #1 - bonusbar 3 - druid BEAR
[10] = {name="Action", visibleIf="bar:1,bonusbar:4"}, -- primary "ActionBar" - page #1 - bonusbar 4 - druid MOONKIN
[11] = {name="Action", visibleIf="bar:1,bonusbar:5"}, -- primary "ActionBar" - page #1 - bonusbar 5 - dragon riding
[12] = {name="Action", visibleIf="bar:1,bonusbar:6"--[[just a guess]]}, -- unknown?
[13] = {name="MultiBar5"}, -- config UI -> Action Bars -> checkbox #6
[14] = {name="MultiBar6"}, -- config UI -> Action Bars -> checkbox #7
[15] = {name="MultiBar7"}, -- config UI -> Action Bars -> checkbox #8
}
-- unique flyout definitions shown in the config panel
local DEFAULT_FLOFLYOUT_CONFIG = {
flyouts = {
--[[ Sample config : each flyout can have a list of actions and an icon
[1] = {
actionTypes = {
[1] = "spell",
[2] = "item",
[3] = "macro",
[4] = "battlepet"
},
spells = {
[1] = 8024, -- Flametongue
[2] = 8033, -- Frostbite
[3] = 8232, -- Windfury
[4] = 8017, -- RockBite
[5] = 51730, -- earthliving
},
icon = ""
},
[2] = { ... etc ... }, etc...
]]
},
}
-- assigned action bar button slots
local DEFAULT_PLACEMENTS_CONFIG = {
-- each class spec has its own set of placements
[1] = {
-- config format:
-- [action bar slot] = flyout Id
-- each button on the bliz action bars has a slot ID which is which we place a flyout ID (see above)
-- [13] = 1, -- button #13 holds flyout #1
-- [49] = 3, -- button #49 holds flyout #3
-- [125] = 2, -- button #125 holds flyout #2
},
[2] = {
},
[3] = {
},
[4] = {
},
-- spec-agnostic slot
[5] = {
},
}
-------------------------------------------------------------------------------
-- Variables
-------------------------------------------------------------------------------
local _
local _classicUI
local Db = nil -- initialized by Ace in OnInitialize
-------------------------------------------------------------------------------
-- Ace -> Bliz Config UI definition
-------------------------------------------------------------------------------
local escMenuConfigDef = {
name = MY_NAME,
type = "group",
args = {
respectSpec = {
name = "Swap with spec",
desc = "Auto swap flyout locations on the action bars when you change your class spec.",
type = "toggle",
set = function(info, val)
Db.profile.respectSpec = val
end,
get = function()
return Db.profile.respectSpec
end
},
debug = {
name = "Show debug info",
desc = "Enable / disable debug information",
type = "toggle",
set = function(info, val)
Db.profile.debug = val
end,
get = function()
return Db.profile.debug
end
},
--aceProfileUi = {} -- will be populated by Ace in OnInitialize()
}
}
local defaultConfigOptions = {
profile = { -- required by AceDB
debug = false,
respectSpec = true,
}
}
-------------------------------------------------------------------------------
-- Ace Addon lifecycle
-------------------------------------------------------------------------------
-- called by Ace directly after the addon is fully loaded
function FloFlyout:OnInitialize()
--print("FloFlyout:OnInitialize() aces! -- this happens after FloFlyout_OnLoad")
-- AceDB manages SavedVariables and adds profile management -- must match the .toc ## SavedVariables
Db = LibStub("AceDB-3.0"):New("FLOFLYOUT_ACCOUNT_CONFIG", defaultConfigOptions)
-- grabs Ace's profile management UI def and adds it as another submenu of ours
--escMenuConfigDef.args.aceProfileUi = LibStub("AceDBOptions-3.0"):GetOptionsTable(Db)
-- Ace-only config registry (required by AceConfigDialog below). Also adds slash commands {the, stuff, on, the, end}
LibStub("AceConfig-3.0"):RegisterOptionsTable(MY_NAME, escMenuConfigDef, { "ff", MY_NAME, string.lower(MY_NAME) })
-- inserts our custom config into the Bliz addon config UI
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(MY_NAME)
-- if the user switches to a different profile in the addon config options
--Db.RegisterCallback(self, "OnProfileChanged", "HandleConfigChanges")
--Db.RegisterCallback(self, "OnProfileCopied", "HandleConfigChanges")
--Db.RegisterCallback(self, "OnProfileReset", "HandleConfigChanges")
self:InitializeFlyoutConfigIfEmpty(true)
self:InitializePlacementConfigIfEmpty(true)
initializeOnClickHandlersForFlyouts()
end
function FloFlyout:UpdateVersionId()
FLOFLYOUT_ACCOUNT_CONFIG.v = VERSION
FLOFLYOUT_ACCOUNT_CONFIG.V_MAJOR = V_MAJOR
FLOFLYOUT_ACCOUNT_CONFIG.V_MINOR = V_MINOR
FLOFLYOUT_ACCOUNT_CONFIG.V_PATCH = V_PATCH
end
--[[
-- called by Ace during the PLAYER_LOGIN event, when most of the data provided by the game is already present
function FloFlyoutAce:OnEnable()
end
-- called by Ace only when your addon is manually being disabled
function FloFlyoutAce:OnDisable()
end
]]
-------------------------------------------------------------------------------
-- FloFlyout Methods
-------------------------------------------------------------------------------
-- obsolete - hold-over from when I was using AceDB profile switching
--function FloFlyout:HandleConfigChanges()
-- self:InitializeFlyoutConfigIfEmpty()
-- self:InitializePlacementConfigIfEmpty()
-- self:ApplyConfig()
--end
-- compares the config's stored version to input parameters
function isConfigOlderThan(major, minor, patch)
local configMajor = FLOFLYOUT_ACCOUNT_CONFIG.V_MAJOR
local configMinor = FLOFLYOUT_ACCOUNT_CONFIG.V_MINOR
local configPatch = FLOFLYOUT_ACCOUNT_CONFIG.V_PATCH
if not (configMajor and configMinor and configPatch) then
return true
elseif configMajor < major then
return true
elseif configMinor < minor then
return true
elseif configPatch < patch then
return true
else
return false
end
end
function FloFlyout:InitializeFlyoutConfigIfEmpty(mayUseLegacyData)
if self:GetFlyoutsConfig() then
return
end
local flyouts
-- support older versions of the addon
local legacyData = mayUseLegacyData and FLOFLYOUT_CONFIG and FLOFLYOUT_CONFIG.flyouts
if legacyData then
flyouts = deepcopy(legacyData)
fixLegacyFlyoutsNils(flyouts)
FLOFLYOUT_CONFIG.flyouts_note = "the flyouts field is old and no longer used by the current version of this addon"
else
flyouts = deepcopy(DEFAULT_FLOFLYOUT_CONFIG)
end
self:PutFlyoutConfig(flyouts)
end
function FloFlyout:InitializePlacementConfigIfEmpty(mayUseLegacyData)
if self:GetFlyoutPlacementsForToon() then
return
end
local placementsForAllSpecs
local legacyData = mayUseLegacyData and FLOFLYOUT_CONFIG and FLOFLYOUT_CONFIG.actions
if legacyData then
placementsForAllSpecs = deepcopy(legacyData)
fixLegacyActionsNils(placementsForAllSpecs)
FLOFLYOUT_CONFIG.actions_note = "the actions field is old and no longer used by the current version of this addon"
else
placementsForAllSpecs = deepcopy(DEFAULT_PLACEMENTS_CONFIG)
end
self:PutFlyoutPlacementsForToon(placementsForAllSpecs)
end
-- the flyout definitions are stored account-wide and thus shared between all toons
function FloFlyout:PutFlyoutConfig(flyouts)
if not FLOFLYOUT_ACCOUNT_CONFIG then
FLOFLYOUT_ACCOUNT_CONFIG = {}
end
FLOFLYOUT_ACCOUNT_CONFIG.flyouts = flyouts
end
function FloFlyout:GetFlyoutsConfig()
return FLOFLYOUT_ACCOUNT_CONFIG and FLOFLYOUT_ACCOUNT_CONFIG.flyouts
--return Db.profile.flyouts
end
local doneChecked = {} -- flag for the GetFlyoutConfig() method
-- get and validate the requested flyout config
function FloFlyout:GetFlyoutConfig(flyoutId)
local config = self:GetFlyoutsConfig()
local flyoutConfig = config and (config[flyoutId])
-- check that the data structure is complete
-- because old versions of the addon may have saved less data than now needed
-- but check each specific flyoutId only once
if doneChecked[flyoutId] then return flyoutConfig end
doneChecked[flyoutId] = true
if not flyoutConfig then return nil end
-- init any missing parts
for k,_ in pairs(STRUCT_FLYOUT_DEF) do
if not flyoutConfig[k] then
flyoutConfig[k] = {}
end
end
return flyoutConfig
end
function FloFlyout:GetSpecificConditionalFlyoutPlacements()
local placements = self:GetFlyoutPlacementsForToon()
local spec = self:GetSpecSlotId()
return placements and placements[spec]
end
-- the placement of flyouts on the action bars is stored separately for each toon
function FloFlyout:PutFlyoutPlacementsForToon(flyoutPlacements)
if not FLOFLYOUT_CONFIG then
FLOFLYOUT_CONFIG = {}
end
FLOFLYOUT_CONFIG.flyoutPlacements = flyoutPlacements
--if not Db.profile.placementsPerToonAndSpec then
-- Db.profile.placementsPerToonAndSpec = {}
--end
--local playerId = getIdForCurrentToon()
--Db.profile.placementsPerToonAndSpec[playerId] = flyoutPlacements
end
function FloFlyout:GetFlyoutPlacementsForToon()
return FLOFLYOUT_CONFIG and FLOFLYOUT_CONFIG.flyoutPlacements
--local playerId = getIdForCurrentToon()
--local ppts = Db.profile.placementsPerToonAndSpec
--return ppts and ppts[playerId]
end
function getIdForCurrentToon()
local name, realm = UnitFullName("player") -- FU Bliz, realm is arbitrarily nil sometimes but not always
realm = GetRealmName()
return name.." - "..realm
end
function FloFlyout:GetSpecSlotId()
if Db.profile.respectSpec then
return GetSpecialization()
else
return NON_SPEC_SLOT
end
end
function initializeOnClickHandlersForFlyouts()
for i, button in ipairs({FloFlyoutFrame:GetChildren()}) do
if button:GetObjectType() == "CheckButton" then
SecureHandlerWrapScript(button, "OnClick", button, "self:GetParent():Hide()")
end
end
FloFlyoutConfigFlyoutFrame.IsConfig = true
end
function fixLegacyFlyoutsNils(flyouts)
for _, flyout in ipairs(flyouts) do
if flyout.actionTypes == nil then
flyout.actionTypes = {}
for i, _ in ipairs(flyout.spells) do
flyout.actionTypes[i] = "spell"
end
end
if flyout.mountIndex == nil then
flyout.mountIndex = {}
end
if flyout.spellNames == nil then
flyout.spellNames = {}
end
end
end
function fixLegacyActionsNils(actions)
for i=3,5 do
if actions[i] == nil then
actions[i] = {}
end
end
end
function FloFlyout.ReadCmd(line)
local cmd, arg1, arg2 = strsplit(' ', line or "", 3);
if cmd == "addflyout" then
DEFAULT_CHAT_FRAME:AddMessage("New flyout : "..FloFlyout:AddFlyout().flyoutId)
elseif cmd == "removeflyout" and FloFlyout:IsValidFlyoutId(arg1) then
FloFlyout:RemoveFlyout(arg1)
FloFlyout:ApplyConfig()
elseif cmd == "addspell" and FloFlyout:IsValidFlyoutId(arg1) then
DEFAULT_CHAT_FRAME:AddMessage("New spell : "..FloFlyout:AddSpell(arg1, arg2))
FloFlyout:ApplyConfig()
elseif cmd == "removespell" and FloFlyout:IsValidFlyoutId(arg1) and FloFlyout:IsValidSpellPos(arg1, arg2) then
FloFlyout:RemoveSpell(arg1, arg2)
FloFlyout:ApplyConfig()
elseif cmd == "bind" and tonumber(arg1) and FloFlyout:IsValidFlyoutId(arg2) then
FloFlyout:AddAction(arg1, arg2)
FloFlyout:ApplyConfig()
elseif cmd == "unbind" and tonumber(arg1) then
FloFlyout:RemoveAction(arg1)
FloFlyout:ApplyConfig()
elseif cmd == "apply" then
FloFlyout:ApplyConfig()
else
DEFAULT_CHAT_FRAME:AddMessage(L["USAGE"]);
return;
end
end
-- Executed on load, calls general set-up functions
function FloFlyout_OnLoad(self)
--print("FloFlyout_OnLoad() -- this happens before Ace's FloFlyout:OnInitialize")
DEFAULT_CHAT_FRAME:AddMessage( "|cffd78900"..NAME.." v"..VERSION.."|r loaded." )
SLASH_FLOFLYOUT1 = "/floflyout"
SLASH_FLOFLYOUT2 = "/ffo"
SlashCmdList["FLOFLYOUT"] = FloFlyout.ReadCmd
StaticPopupDialogs["CONFIRM_DELETE_FLO_FLYOUT"] = {
text = L["CONFIRM_DELETE"],
button1 = YES,
button2 = NO,
OnAccept = function (self) FloFlyout:RemoveFlyout(self.data); FloFlyout.ConfigPane_Update(); FloFlyout:ApplyConfig(); end,
OnCancel = function (self) end,
hideOnEscape = 1,
timeout = 0,
exclusive = 1,
whileDead = 1,
}
-- self:RegisterEvent("ADDON_LOADED") -- replaced with Ace
self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
--self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_ALIVE")
self:RegisterEvent("UPDATE_BINDINGS")
self:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
_classicUI = _G["ClassicUI"]
if _classicUI then
DEFAULT_CHAT_FRAME:AddMessage( NAME.." : |cffd78900ClassicUI v".._classicUI.VERSION.."|r detected." )
local cuipew = _classicUI.MF_PLAYER_ENTERING_WORLD
_classicUI.MF_PLAYER_ENTERING_WORLD = function (cui)
cuipew(cui)
FloFlyout:ApplyConfig()
end
end
end
function FloFlyout_OnEvent(FloFlyoutListener, event, arg1, ...)
if event == "PLAYER_ENTERING_WORLD" --[[or event == "PLAYER_ALIVE"]] then
if not _classicUI or not _classicUI:IsEnabled() then
FloFlyout:ApplyConfig()
end
--elseif event == "SPELL_UPDATE_COOLDOWN" or event == "ACTIONBAR_UPDATE_USABLE" then
elseif event == "ACTIONBAR_SLOT_CHANGED" then
local idAction = arg1
-- Dans tous les cas, si nous avions un flyout sur cette action, il faut l'enlever de l'action et le mettre dans le curseur
local configChanged
local oldFlyoutId = FloFlyout:GetSpecificConditionalFlyoutPlacements()[idAction]
local actionType, id, subType = GetActionInfo(idAction)
-- Si actionType vide, c'est sans doute que l'on vient de détruire la macro bidon
if not actionType then
return
elseif actionType == "macro" then
local name, texture, body = GetMacroInfo(id)
--print("GetMacroInfo: for ID = ", id, "name =",name, "texture =",texture, "body =",body)
if name == DUMMY_MACRO_NAME then
FloFlyout:AddAction(idAction, body)
-- La pseudo macro a fait son travail
DeleteMacro(DUMMY_MACRO_NAME)
configChanged = true
end
end
if oldFlyoutId then
FloFlyout:PickupFlyout(oldFlyoutId)
if not configChanged then
FloFlyout:RemoveAction(idAction)
configChanged = true
end
end
if configChanged then
FloFlyout:ApplyConfig()
end
elseif event == "UPDATE_BINDINGS" then
elseif event == "PLAYER_SPECIALIZATION_CHANGED" then
FloFlyout:ApplyConfig()
else
end
end
function FloFlyout:ApplyOperationToAllOpenerInstancesUnlessInCombat(callback)
if InCombatLockdown() then return end
self:ApplyOperationToAllOpenerInstances(callback)
end
function FloFlyoutFrame_OnEvent(self, event, ...)
if event == "SPELL_UPDATE_COOLDOWN" then
local i = 1
local button = _G[self:GetName().."Button"..i]
while (button and button:IsShown() and not isEmpty(button.spellID)) do
SpellFlyoutButton_UpdateCooldown(button)
i = i+1
button = _G[self:GetName().."Button"..i]
end
elseif event == "CURRENT_SPELL_CAST_CHANGED" then
local i = 1
local button = _G[self:GetName().."Button"..i]
while (button and button:IsShown() and button.spellID) do
SpellFlyoutButton_UpdateState(button)
i = i+1
button = _G[self:GetName().."Button"..i]
end
elseif event == "SPELL_UPDATE_USABLE" then
local i = 1
local button = _G[self:GetName().."Button"..i]
while (button and button:IsShown() and button.spellID) do
SpellFlyoutButton_UpdateUsable(button)
i = i+1
button = _G[self:GetName().."Button"..i]
end
elseif event == "BAG_UPDATE" then
local i = 1
local button = _G[self:GetName().."Button"..i]
while (button and button:IsShown() and button.spellID) do
SpellFlyoutButton_UpdateCount(button)
SpellFlyoutButton_UpdateUsable(button)
i = i+1
button = _G[self:GetName().."Button"..i]
end
elseif event == "SPELL_FLYOUT_UPDATE" then
local i = 1
local button = _G[self:GetName().."Button"..i]
while (button and button:IsShown() and not isEmpty(button.spellID)) do
SpellFlyoutButton_UpdateCooldown(button)
SpellFlyoutButton_UpdateState(button)
SpellFlyoutButton_UpdateUsable(button)
SpellFlyoutButton_UpdateCount(button)
i = i+1
button = _G[self:GetName().."Button"..i]
end
end
end
function getPetNameAndIcon(petGuid)
--print("getPetNameAndIcon(): petGuid =",petGuid)
local speciesID, customName, level, xp, maxXp, displayID, isFavorite, name, icon, petType, creatureID, sourceText, description, isWild, canBattle, tradable, unique, obtainable = C_PetJournal.GetPetInfoByPetID(petGuid)
--print("getPetNameAndIcon(): petGuid =",petGuid, "| name =", name, "| icon =", icon)
return name, icon
end
function getTexture(actionType, spellId, petId)
local id = pickSpellIdOrPetId(actionType, spellId, petId)
--print("getTexture(): actionType =",actionType, "| spellId =",spellId, "| petId =",petId, "| id =",id)
if actionType == "spell" then
return GetSpellTexture(id)
elseif actionType == "item" then
return GetItemIcon(id)
elseif actionType == "macro" then
local _, texture, _ = GetMacroInfo(id)
return texture
elseif actionType == "battlepet" then
local _, icon = getPetNameAndIcon(id)
return icon
end
end
function getThingyNameById(actionType, id)
if actionType == "spell" then
return GetSpellInfo(id)
elseif actionType == "item" then
return GetItemInfo(id)
elseif actionType == "macro" then
local name, _, _ = GetMacroInfo(id)
return name
elseif actionType == "battlepet" then
return getPetNameAndIcon(id)
end
end
function isThingyUsable(id, actionType, mountId, macroOwner,petId)
if mountId or petId then
-- TODO: figure out how to find a mount
return true -- GetMountInfoByID(mountId)
elseif actionType == "spell" then
return IsSpellKnown(id)
elseif actionType == "item" then
local n = GetItemCount(id)
local t = PlayerHasToy(id) -- TODO: update the config code so it sets actionType = toy
return t or n > 0
elseif actionType == "macro" then
return isMacroGlobal(id) or getIdForCurrentToon() == macroOwner
end
end
function isMacroGlobal(macroId)
return macroId <= MAX_GLOBAL_MACRO_ID
end
function FloFlyout:BindFlyoutToActionBarSlot(flyoutId, btnSlotIndex)
-- examine the action/bonus/multi bar
local barNum = ActionButtonUtil.GetPageForSlot(btnSlotIndex)
local blizBarDef = BLIZ_BAR_METADATA[barNum]
assert(blizBarDef, "No "..MY_NAME.." config defined for button bar #"..barNum) -- in case Blizzard adds more bars, complain here clearly.
local blizBarName = blizBarDef.name
local visibleIf = blizBarDef.visibleIf
local typeActionButton = blizBarDef.classicType -- for WoW classic
-- examine the button
local btnNum = (btnSlotIndex % NUM_ACTIONBAR_BUTTONS) -- defined in bliz internals ActionButtonUtil.lua
if (btnNum == 0) then btnNum = NUM_ACTIONBAR_BUTTONS end -- button #12 divided by 12 is 1 remainder 0. Thus, treat a 0 as a 12
local btnName = blizBarName .. "Button" .. btnNum
local btnObj = _G[btnName] -- grab the button object from Blizzard's GLOBAL dumping ground
-- ask the bar instance what direction to fly
local barObj = btnObj and btnObj.bar
local direction = barObj and barObj:GetSpellFlyoutDirection() or "UP" -- TODO: fix bug where edit-mode -> change direction doesn't automatically update existing openers
--local foo = btnObj and "FOUND" or "NiL"
--print ("###--->>> ffUniqueId =", ffUniqueId, "barNum =",barNum, "slotId = ", btnSlotIndex, "btnObj =",foo, "blizBarName = ",blizBarName, "btnName =",btnName, "btnNum =",btnNum, "direction =",direction, "visibleIf =", visibleIf)
self:CreateOpener(btnSlotIndex, flyoutId, direction, btnObj, visibleIf, typeActionButton)
end
function Opener_OnReceiveDrag(self)
if InCombatLockdown() then
return
end
local cursor = GetCursorInfo()
if cursor then
PlaceAction(self.actionId)
end
end
function Opener_OnDragStart(self)
if not InCombatLockdown() and (LOCK_ACTIONBAR ~= "1" or IsShiftKeyDown()) then
FloFlyout:PickupFlyout(self.flyoutId)
FloFlyout:RemoveAction(self.actionId)
FloFlyout:ApplyConfig()
end
end
function Opener_UpdateFlyout(self)
-- print("========== Opener_UpdateFlyout()") this is being called continuously while a flyout exists on any bar
-- Update border and determine arrow position
local arrowDistance;
-- Update border
local isMouseOverButton = GetMouseFocus() == self;
local isFlyoutShown = FloFlyoutFrame and FloFlyoutFrame:IsShown() and FloFlyoutFrame:GetParent() == self;
if isFlyoutShown or isMouseOverButton then
self.FlyoutBorderShadow:Show();
arrowDistance = 5;
else
self.FlyoutBorderShadow:Hide();
arrowDistance = 2;
end
-- Update arrow
local isButtonDown = self:GetButtonState() == "PUSHED"
local flyoutArrowTexture = self.FlyoutArrowContainer.FlyoutArrowNormal
if isButtonDown then
flyoutArrowTexture = self.FlyoutArrowContainer.FlyoutArrowPushed;
self.FlyoutArrowContainer.FlyoutArrowNormal:Hide();
self.FlyoutArrowContainer.FlyoutArrowHighlight:Hide();
elseif isMouseOverButton then
flyoutArrowTexture = self.FlyoutArrowContainer.FlyoutArrowHighlight;
self.FlyoutArrowContainer.FlyoutArrowNormal:Hide();
self.FlyoutArrowContainer.FlyoutArrowPushed:Hide();
else
self.FlyoutArrowContainer.FlyoutArrowHighlight:Hide();
self.FlyoutArrowContainer.FlyoutArrowPushed:Hide();
end
self.FlyoutArrowContainer:Show();
flyoutArrowTexture:Show();
flyoutArrowTexture:ClearAllPoints();
local direction = self:GetAttribute("flyoutDirection");
if (direction == "LEFT") then
flyoutArrowTexture:SetPoint("LEFT", self, "LEFT", -arrowDistance, 0);
SetClampedTextureRotation(flyoutArrowTexture, 270);
elseif (direction == "RIGHT") then
flyoutArrowTexture:SetPoint("RIGHT", self, "RIGHT", arrowDistance, 0);
SetClampedTextureRotation(flyoutArrowTexture, 90);
elseif (direction == "DOWN") then
flyoutArrowTexture:SetPoint("BOTTOM", self, "BOTTOM", 0, -arrowDistance);
SetClampedTextureRotation(flyoutArrowTexture, 180);
else
flyoutArrowTexture:SetPoint("TOP", self, "TOP", 0, arrowDistance);
SetClampedTextureRotation(flyoutArrowTexture, 0);
end
end
-- throttle OnUpdate because it fires as often as FPS and is very resource intensive
local ON_UPDATE_TIMER_FREQUENCY = 1.5
local onUpdateTimer = 0
function Opener_UpdateFlyout_OnUpdate(self, elapsed)
onUpdateTimer = onUpdateTimer + elapsed
if onUpdateTimer < ON_UPDATE_TIMER_FREQUENCY then
return
end
onUpdateTimer = 0
Opener_UpdateFlyout(self)
end
function pickSpellIdOrPetId(type, spellId, petId)
return ((type == "battlepet") and petId) or spellId
end
function Opener_PreClick(self, button, down)
self:SetChecked(not self:GetChecked())
local direction = self:GetAttribute("flyoutDirection");
local spellList = fknSplit(self:GetAttribute("spelllist"))
--print("~~~~~~ /spellList/ =",self:GetAttribute("spellList"))
--print("~~~~~~ spellList -->")
--DevTools_Dump(spellList)
local typeList = fknSplit(self:GetAttribute("typelist"))
--print("~~~~~~ /typeList/ =",self:GetAttribute("typelist"))
--print("~~~~~~ typeList -->")
--DevTools_Dump(typeList)
local pets = fknSplit(self:GetAttribute("petlist"))
--print("~~~~~~ /pets/ =",self:GetAttribute("petlist"))
--print("~~~~~~ pets -->")
--DevTools_Dump(pets)
local buttonFrames = { FloFlyoutFrame:GetChildren() }
table.remove(buttonFrames, 1)
for i, buttonFrame in ipairs(buttonFrames) do
local type = typeList[i]
if not isEmpty(type) then
local spellId = spellList[i]
local pet = pets[i]
--print("Opener_PreClick(): i =",i, "| spellID =",spellId, "| type =",type, "| pet =", pet)
buttonFrame.spellID = spellId
buttonFrame.actionType = type
buttonFrame.battlepet = pet
local icon = getTexture(type, spellId, pet)
_G[buttonFrame:GetName().."Icon"]:SetTexture(icon)
if not isEmpty(spellId) then
SpellFlyoutButton_UpdateCooldown(buttonFrame)
SpellFlyoutButton_UpdateState(buttonFrame)
SpellFlyoutButton_UpdateUsable(buttonFrame)
SpellFlyoutButton_UpdateCount(buttonFrame)
end
end
end
FloFlyoutFrame.Background.End:ClearAllPoints()
FloFlyoutFrame.Background.Start:ClearAllPoints()
local distance = 3
if (direction == "UP") then
FloFlyoutFrame.Background.End:SetPoint("TOP", 0, SPELLFLYOUT_INITIAL_SPACING);
SetClampedTextureRotation(FloFlyoutFrame.Background.End, 0);
SetClampedTextureRotation(FloFlyoutFrame.Background.VerticalMiddle, 0);
FloFlyoutFrame.Background.Start:SetPoint("TOP", FloFlyoutFrame.Background.VerticalMiddle, "BOTTOM");
SetClampedTextureRotation(FloFlyoutFrame.Background.Start, 0);
FloFlyoutFrame.Background.HorizontalMiddle:Hide();
FloFlyoutFrame.Background.VerticalMiddle:Show();
FloFlyoutFrame.Background.VerticalMiddle:ClearAllPoints();
FloFlyoutFrame.Background.VerticalMiddle:SetPoint("TOP", FloFlyoutFrame.Background.End, "BOTTOM");
FloFlyoutFrame.Background.VerticalMiddle:SetPoint("BOTTOM", 0, distance);
elseif (direction == "DOWN") then
FloFlyoutFrame.Background.End:SetPoint("BOTTOM", 0, -SPELLFLYOUT_INITIAL_SPACING);
SetClampedTextureRotation(FloFlyoutFrame.Background.End, 180);
SetClampedTextureRotation(FloFlyoutFrame.Background.VerticalMiddle, 180);
FloFlyoutFrame.Background.Start:SetPoint("BOTTOM", FloFlyoutFrame.Background.VerticalMiddle, "TOP");
SetClampedTextureRotation(FloFlyoutFrame.Background.Start, 180);
FloFlyoutFrame.Background.HorizontalMiddle:Hide();
FloFlyoutFrame.Background.VerticalMiddle:Show();
FloFlyoutFrame.Background.VerticalMiddle:ClearAllPoints();
FloFlyoutFrame.Background.VerticalMiddle:SetPoint("BOTTOM", FloFlyoutFrame.Background.End, "TOP");
FloFlyoutFrame.Background.VerticalMiddle:SetPoint("TOP", 0, -distance);
elseif (direction == "LEFT") then
FloFlyoutFrame.Background.End:SetPoint("LEFT", -SPELLFLYOUT_INITIAL_SPACING, 0);
SetClampedTextureRotation(FloFlyoutFrame.Background.End, 270);
SetClampedTextureRotation(FloFlyoutFrame.Background.HorizontalMiddle, 180);
FloFlyoutFrame.Background.Start:SetPoint("LEFT", FloFlyoutFrame.Background.HorizontalMiddle, "RIGHT");
SetClampedTextureRotation(FloFlyoutFrame.Background.Start, 270);
FloFlyoutFrame.Background.VerticalMiddle:Hide();
FloFlyoutFrame.Background.HorizontalMiddle:Show();
FloFlyoutFrame.Background.HorizontalMiddle:ClearAllPoints();
FloFlyoutFrame.Background.HorizontalMiddle:SetPoint("LEFT", FloFlyoutFrame.Background.End, "RIGHT");
FloFlyoutFrame.Background.HorizontalMiddle:SetPoint("RIGHT", -distance, 0);
elseif (direction == "RIGHT") then
FloFlyoutFrame.Background.End:SetPoint("RIGHT", SPELLFLYOUT_INITIAL_SPACING, 0);
SetClampedTextureRotation(FloFlyoutFrame.Background.End, 90);
SetClampedTextureRotation(FloFlyoutFrame.Background.HorizontalMiddle, 0);
FloFlyoutFrame.Background.Start:SetPoint("RIGHT", FloFlyoutFrame.Background.HorizontalMiddle, "LEFT");
SetClampedTextureRotation(FloFlyoutFrame.Background.Start, 90);
FloFlyoutFrame.Background.VerticalMiddle:Hide();
FloFlyoutFrame.Background.HorizontalMiddle:Show();
FloFlyoutFrame.Background.HorizontalMiddle:ClearAllPoints();
FloFlyoutFrame.Background.HorizontalMiddle:SetPoint("RIGHT", FloFlyoutFrame.Background.End, "LEFT");
FloFlyoutFrame.Background.HorizontalMiddle:SetPoint("LEFT", distance, 0);
end
FloFlyoutFrame:SetBorderColor(0.7, 0.7, 0.7)
FloFlyoutFrame:SetBorderSize(47);
end
-- ##########################################################################################
-- CLASS: FloFlyout
-- ##########################################################################################
local DELIMITER = "\a"
local EMPTY_ELEMENT = "\t" -- strjoin skips "" as if they were nil, but "" isn't treated as nil. omfg Lua, get it together.
-- I had to create this function to replace lua's strjoin() because
-- lua poops the bed in the strsplit(strjoin(array)) roundtrip whenever the "array" is actually a table because an element was set to nil
function fknJoin(array)
array = array or {}
local n = lastIndex(array)
--print ("OOOOO fknJoin() n =",n, "| array -->")
--DevTools_Dump(array)
local omfgDumbAssLanguage = {}
for i=1,n,1 do
--print("$$$$$ fknJoin() i =",i, "| array[",i,"] =",array[i])
omfgDumbAssLanguage[i] = array[i] or EMPTY_ELEMENT
end
local result = strjoin(DELIMITER,unpack(omfgDumbAssLanguage,1,n)) or ""
--print("$$$$= fknJoin() #omfgDumbAssLanguage =",#omfgDumbAssLanguage, "result =",result)
return result
end
-- because lua arrays turn into tables when an element = nil
function lastIndex(table)
local biggest = 0
for k,v in pairs(table) do
if (k > biggest) then
biggest = k
end
end
return biggest
end
-- ensures then special characters introduced by fknJoin()
function fknSplit(str)
local omfgDumbassLanguage = { strsplit(DELIMITER, str or "") }
omfgDumbassLanguage = stripEmptyElements(omfgDumbassLanguage)
return omfgDumbassLanguage
end
function stripEmptyElements(table)
for k,v in ipairs(table) do
if (v == EMPTY_ELEMENT) then
table[k] = nil
end
end
return table
end
local snippet_Opener_Click = [=[
local DELIMITER = "]=]..DELIMITER..[=["
local EMPTY_ELEMENT = "]=]..EMPTY_ELEMENT..[=["
local ref = self:GetFrameRef("FloFlyoutFrame")
local direction = self:GetAttribute("flyoutDirection")
local prevButton = nil;
if ref:IsShown() and ref:GetParent() == self then
ref:Hide()
else
ref:SetParent(self)
ref:ClearAllPoints()
if direction == "UP" then
ref:SetPoint("BOTTOM", self, "TOP", 0, 0)
elseif direction == "DOWN" then
ref:SetPoint("TOP", self, "BOTTOM", 0, 0)
elseif direction == "LEFT" then
ref:SetPoint("RIGHT", self, "LEFT", 0, 0)
elseif direction == "RIGHT" then
ref:SetPoint("LEFT", self, "RIGHT", 0, 0)
end
local spellNameList = table.new(strsplit(DELIMITER, self:GetAttribute("spellnamelist")or""))
local typeList = table.new(strsplit(DELIMITER, self:GetAttribute("typelist")or""))
local pets = table.new(strsplit(DELIMITER, self:GetAttribute("petlist")or""))
local buttonList = table.new(ref:GetChildren())
table.remove(buttonList, 1)
for i, buttonRef in ipairs(buttonList) do
if typeList[i] then
buttonRef:ClearAllPoints()
if direction == "UP" then
if prevButton then
buttonRef:SetPoint("BOTTOM", prevButton, "TOP", 0, ]=]..SPELLFLYOUT_DEFAULT_SPACING..[=[)
else
buttonRef:SetPoint("BOTTOM", "$parent", 0, ]=]..SPELLFLYOUT_INITIAL_SPACING..[=[)
end
elseif direction == "DOWN" then
if prevButton then
buttonRef:SetPoint("TOP", prevButton, "BOTTOM", 0, -]=]..SPELLFLYOUT_DEFAULT_SPACING..[=[)
else
buttonRef:SetPoint("TOP", "$parent", 0, -]=]..SPELLFLYOUT_INITIAL_SPACING..[=[)
end
elseif direction == "LEFT" then
if prevButton then
buttonRef:SetPoint("RIGHT", prevButton, "LEFT", -]=]..SPELLFLYOUT_DEFAULT_SPACING..[=[, 0)
else
buttonRef:SetPoint("RIGHT", "$parent", -]=]..SPELLFLYOUT_INITIAL_SPACING..[=[, 0)
end
elseif direction == "RIGHT" then
if prevButton then
buttonRef:SetPoint("LEFT", prevButton, "RIGHT", ]=]..SPELLFLYOUT_DEFAULT_SPACING..[=[, 0)
else
buttonRef:SetPoint("LEFT", "$parent", ]=]..SPELLFLYOUT_INITIAL_SPACING..[=[, 0)
end
end
local type = typeList[i]
local thisId = ((typeList[i] == "battlepet") and pets[i]) or spellNameList[i]
-- It appears that SecureActionButtonTemplate
-- provides no support for summoning battlepets
-- because summoning a battlepet is not a protected action.
-- But, here we are, in FloFlyout's SecureActionButtonTemplate code,
-- so, fake it with an adhoc macro!
if (type == "battlepet") then
-- here I was fumbling around guessing at a solution:
-- buttonRef:SetAttribute("pet", thisId)
-- buttonRef:SetAttribute("companion", thisId)
-- buttonRef:SetAttribute("CompanionPet", thisId)
-- summon the pet via a macro
local petMacro = "/run C_PetJournal.SummonPetByGUID(\"" .. thisId .. "\")"
buttonRef:SetAttribute("type", "macro")
buttonRef:SetAttribute("macrotext", petMacro)
else
buttonRef:SetAttribute("type", type)
buttonRef:SetAttribute(type, thisId)
end
buttonRef:Show()
prevButton = buttonRef
else
buttonRef:Hide()
end
end
local numButtons = table.maxn(typeList)
if direction == "UP" or direction == "DOWN" then
ref:SetWidth(prevButton:GetWidth())
ref:SetHeight((prevButton:GetHeight()+]=]..SPELLFLYOUT_DEFAULT_SPACING..[=[) * numButtons - ]=]..SPELLFLYOUT_DEFAULT_SPACING..[=[ + ]=]..SPELLFLYOUT_INITIAL_SPACING..[=[ + ]=]..SPELLFLYOUT_FINAL_SPACING..[=[)
else
ref:SetHeight(prevButton:GetHeight())
ref:SetWidth((prevButton:GetWidth()+]=]..SPELLFLYOUT_DEFAULT_SPACING..[=[) * numButtons - ]=]..SPELLFLYOUT_DEFAULT_SPACING..[=[ + ]=]..SPELLFLYOUT_INITIAL_SPACING..[=[ + ]=]..SPELLFLYOUT_FINAL_SPACING..[=[)
end
ref:Show()
--ref:RegisterAutoHide(1)
--ref:AddToAutoHide(self)
end
]=]
function FloFlyout:CreateOpener(actionId, flyoutId, direction, actionButton, visibleIf, typeActionButton)
local flyoutConf = self:GetFlyoutConfig(flyoutId)
if not flyoutId then return end -- because one toon can delete a flyout while other toons still have it on their bars
local name = "FloFlyoutOpener"..actionId
local opener = self.openers[name] or CreateFrame("CheckButton", name, actionButton, "ActionButtonTemplate, SecureHandlerClickTemplate")
self.openers[name] = opener
opener.flyoutId = flyoutId
opener.actionId = actionId
if _classicUI then
_classicUI.LayoutActionButton(opener, typeActionButton)
opener:SetScale(actionButton:GetScale())
end
if actionButton then
if actionButton:GetSize() and actionButton:IsRectValid() then
opener:SetAllPoints(actionButton)
else
local spacerName = "ActionBarButtonSpacer"..tostring(actionButton.index)
local children = {actionButton:GetParent():GetChildren()}
for _, child in ipairs(children) do
if child:GetName() == spacerName then
opener:SetAllPoints(child)
break;
end
end
end
end
opener:SetFrameStrata(STRATA_DEFAULT)
opener:SetFrameLevel(100)
opener:SetToplevel(true)
opener:SetAttribute("flyoutDirection", direction)