-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGerm.lua
More file actions
executable file
·1298 lines (1075 loc) · 52 KB
/
Germ.lua
File metadata and controls
executable file
·1298 lines (1075 loc) · 52 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
-- Germ
-- is a button on the actionbars that opens & closes a copy of a flyout menu from the catalog.
-- One flyout menu can be duplicated across numerous actionbar buttons, each being a seperate germ.
-- is a standard bliz CheckButton frame but with extra attributes attached.
-- Once created it always exists at its original actionbar slot, but, may be assigned a different flyout menu or none at all.
-- a.k.a launchpad, egg, exploder, torpedo, detonator, originator, impetus, genesis, bigBang, singularity...
-------------------------------------------------------------------------------
-- Module Loading
-------------------------------------------------------------------------------
---@type Ufo
local ADDON_NAME, Ufo = ...
Ufo.Wormhole() -- Lua voodoo magic that replaces the current Global namespace with the Ufo object
local zebug = Zebug:new(Z_VOLUME_GLOBAL_OVERRIDE or Zebug.INFO)
---@alias GERM_INHERITANCE UfoMixIn | Button_Mixin | ActionButtonTemplate | SecureActionButtonTemplate | Button | Frame | ScriptObject
---@alias GERM_TYPE Germ | GERM_INHERITANCE
---@class Germ : UfoMixin
---@field ufoType string The classname
---@field flyoutId number Identifies which flyout is currently copied into this germ
---@field primeBtnIndex number Identifies which button on the flyout is currently the PRIME_BTN
---@field flyoutMenu FM_TYPE The UI object serving as the onscreen flyoutMenu (there's only one and it's reused by all germs)
---@field clickScriptUpdaters table secure scriptlets that must be run during any update()
---@field bbInfo table definition of the actionbar/button where the Germ lives
---@field visibleIf string for RegisterStateDriver -- uses macro-conditionals to control visibility automatically
---@field visibilityDriver string primarily for debugging
---@field myName string duh
---@field mainKeyBindingsKeyNames table<string,boolean> the names of the keys bound to this Germ's action bar button
---@field label string human friendly identifier
---@type Germ | GERM_INHERITANCE
Germ = {
ufoType = "Germ",
--clickScriptUpdaters = {},
clickers = {},
mainKeyBindingsKeyNames = {},
primeBtnIndex = 1,
}
UfoMixIn:mixInto(Germ)
GLOBAL_Germ = Germ
---@class GermClickBehavior
GermClickBehavior = {
OPEN = "OPEN",
PRIME_BTN = "PRIME_BTN",
RANDOM_BTN = "RANDOM_BTN",
CYCLE_ALL_BTNS = "CYCLE_ALL_BTNS",
--REVERSE_CYCLE_ALL_BTNS = "REVERSE_CYCLE_ALL_BTNS",
}
---@type table<GermClickBehavior, MouseClick>
RESERVED_CLICKER_BEHAVES_AS = {
[GermClickBehavior.OPEN] = MouseClick.SEVEN,
[GermClickBehavior.PRIME_BTN] = MouseClick.EIGHT,
[GermClickBehavior.RANDOM_BTN] = MouseClick.NINE,
[GermClickBehavior.CYCLE_ALL_BTNS] = MouseClick.TEN,
}
---@type Germ|GERM_INHERITANCE
local GermClickBehaviorAssignmentFunction = { }
-------------------------------------------------------------------------------
-- Data
-------------------------------------------------------------------------------
---@type GERM_TYPE for the benefit of my IDE's autocomplete
local ScriptHandlers = {}
local SEC_ENV_SCRIPT_FOR_ON_CLICK
---@type table<string,Germ> all keybindings currently in use by any Germs
local mainKeyBindingsForAllGerms = {}
-------------------------------------------------------------------------------
-- Constants
-------------------------------------------------------------------------------
local GERM_UI_NAME_PREFIX = "UfoGerm"
local MOUSE_BUTTONS = {
MouseClick.LEFT,
MouseClick.MIDDLE,
MouseClick.RIGHT,
MouseClick.FOUR,
MouseClick.FIVE,
}
-------------------------------------------------------------------------------
-- Functions / Methods
-------------------------------------------------------------------------------
function Germ:new(flyoutId, btnSlotIndex, event)
local parentBlizActionBarBtn = BlizActionBarButtonHelper:get(btnSlotIndex, "Germ:New() for btnSlotIndex"..btnSlotIndex)
local parentBtn3rdParty = ThirdPartyAddonSupport:getBtnParentAsProvidedByAddon(parentBlizActionBarBtn)
local parentBtn = parentBtn3rdParty or parentBlizActionBarBtn
--print("Germ parentActionBarBtn",parentActionBarBtn, "parentActionBarBtn.GetName", parentActionBarBtn.GetName)
local myName = GERM_UI_NAME_PREFIX .. "On_" .. parentBtn:GetName()
---@type GERM_TYPE | Germ
local self = CreateFrame(
FrameType.CHECK_BUTTON,
myName,
parentBtn,
"GermTemplate"
)
_G[myName] = self -- so that keybindings can reference it
parentBtn.germ = self
self.isNew = true -- a flag to silence messages during 1st time creation
-- one-time only initialization --
self.myName = myName -- who
self.btnSlotIndex = btnSlotIndex -- where
self.flyoutId = flyoutId -- what
-- manipulate methods
self:installMyToString() -- do this as soon as possible for the sake of debugging output
-- self.originalHide = self:override("Hide", self.hide)
-- install event handlers
self:HookScript(Script.ON_HIDE, function(self) zebug.info:owner(self):event("Script.ON_HIDE"):print('byeeeee'); end) -- This fires IF the germ is on a dynamic action bar that switches (stance / druid form / etc. or on clearAndDisable() or on a spec change which throws away placeholders
self:SetScript(Script.ON_ENTER, ScriptHandlers.ON_ENTER)
self:SetScript(Script.ON_LEAVE, ScriptHandlers.ON_LEAVE)
self:SetScript(Script.ON_RECEIVE_DRAG, ScriptHandlers.ON_RECEIVE_DRAG)
self:SetScript(Script.ON_MOUSE_DOWN, ScriptHandlers.ON_MOUSE_DOWN)
self:SetScript(Script.ON_MOUSE_UP, ScriptHandlers.ON_MOUSE_UP) -- is this short-circuiting my attempts to get the buttons to work on mouse up?
self:SetScript(Script.ON_DRAG_START, ScriptHandlers.ON_DRAG_START) -- this is required to get OnDrag to work
self:registerForBlizUiActions(event)
-- Secure Shenanigans required before initFlyoutMenu()
SecureHandler_OnLoad(self) -- install self:SetFrameRef()
-- FlyoutMenu
self.flyoutMenu = self:initFlyoutMenu(event)
self:initializeSecEnv(event) -- depends on initFlyoutMenu() above
self:assignAllMouseClickers(event) -- depends on initializeSecureClickers() above
-- UI positioning & appearance
self:ClearAllPoints()
self:SetAllPoints(parentBtn)
self:initLabelString()
self:applyConfigForShowLabel(event)
self:doIcon(event)
self:setVisibilityDriver(parentBlizActionBarBtn.visibleIf) -- do I even need this? when the parent Hides so will the Germ automatically
-- secure tainty stuff
--self:copyDoCloseOnClickConfigValToAttribute()
self:doMyKeybindings(event) -- bind me to my action bar slot's keybindings (if any)
-- Initialize the Primary Button option
local isPrimeDefinedAsRecent = Config:isPrimeDefinedAsRecent()
self:SetAttribute("IS_PRIME_RECENT", isPrimeDefinedAsRecent)
-- Blizz things
ButtonStateBehaviorMixin.OnLoad(self)
self:UpdateArrowShown()
self:UpdateArrowPosition()
self:UpdateArrowRotation()
self.isNew = false
return self
end
function Germ:render(event)
if self:isInactive(event) then return end
self:safelySetSecEnvAttribute(SecEnvAttribute.flyoutDirection, self:getDirection(event))
self:UpdateArrowRotation() -- VOLATILE if action bar changes direction... and changes when open/closed
self:renderCooldownsAndCountsAndStatesEtc(event) -- TODO: v11.1 verify this is working properly. do I need to do more? -- What happens if I remove this?
self.flyoutMenu:renderAllBtnCooldownsEtc(event)
end
function Germ:notifyOfChangeToFlyoutDef(event)
self:closeFlyout() -- in case the number of buttons changed?
self:applyConfigFromFlyoutDef(event)
end
function Germ:applyConfigFromFlyoutDef(event)
self:doIcon(event)
self:applyConfigForShowLabel(event)
self:updateClickerForPrimaryButton(event)
self:closeFlyout() -- in case the buttons' number/ordering changes
self.flyoutMenu:applyConfigForGerm(self, event)
end
function Germ:applyConfigForShowLabel(event)
local txt = Config:get("showLabels") and self:getUfoLabel() or ""
self.Name:SetText(txt)
end
function Germ:getName()
return self:GetName()
end
function Germ:copyToCursor(eventId)
self:copyFlyoutToCursor(self.flyoutId, eventId)
end
function Germ:getLabel()
return self:getUfoLabel()
--self.label = self.flyoutId and self:getFlyoutDef().name
--return self.label
end
Germ.initLabelString = Germ.getLabel
function Germ:getBtnSlotIndex()
return self.btnSlotIndex
end
---@return string
function Germ:getFlyoutId()
return self.flyoutId
end
function Germ:isActive(event)
--zebug.trace:event(event or "UnKnOwN"):owner(self):print("am I active?", self.flyoutId and true or false)
return self.flyoutId and true or false
end
function Germ:isInactive(event)
return not (self.flyoutId and true or false)
end
function Germ:isActiveAndHasFoo(funcName, event)
if not self:isActive() then return false end
local flyoutDef = self:getFlyoutDef()
local func = flyoutDef[funcName]
local hasIt = func(flyoutDef, event)
zebug.info:event(event):owner(self):print(funcName,hasIt)
return hasIt
end
function Germ:hasItemsAndIsActive(event)
return self:isActiveAndHasFoo("hasItem", event)
end
function Germ:hasMacrosAndIsActive(event)
return self:isActiveAndHasFoo("hasMacro", event)
end
function Germ:hasSpellsAndIsActive(event)
return self:isActiveAndHasFoo("hasSpell", event)
end
function Germ:hasFlyoutId(flyoutId)
return self:getFlyoutId() == flyoutId
end
---@return string
function Germ:getFlyoutName()
return self:getFlyoutDef():getName()
end
function Germ:getIcon()
if not self.flyoutId then return DEFAULT_ICON end
local flyoutDef = FlyoutDefsDb:get(self.flyoutId)
local usableFlyout = flyoutDef:filterOutUnusable()
return usableFlyout:getIcon(self.primeBtnIndex) or flyoutDef.fallbackIcon or DEFAULT_ICON
end
function Germ:doIcon(event)
local icon = self:getIcon()
self:setIcon(icon, event)
end
function Germ:glowStart()
SharedActionButton_RefreshSpellHighlight(self, true)
end
function Germ:glowStop()
SharedActionButton_RefreshSpellHighlight(self, false)
end
function Germ:initFlyoutMenu(event)
self.flyoutMenu = FlyoutMenu:new(self, event)
zebug.info:event(event):owner(self):line("20","initFlyoutMenu",self.flyoutMenu)
self.flyoutMenu:applyConfigForGerm(self, event)
self:SetPopup(self.flyoutMenu) -- put my FO where Bliz expects it
self.flyoutMenu.isForGerm = true
return self.flyoutMenu
end
-- set conditional visibility based on which bar we're on. Some bars are only visible for certain class stances, etc.
function Germ:setVisibilityDriver(visibleIf)
-- TODO - fix bug: actionbar #1 buttons vanish
self.visibleIf = visibleIf
zebug.trace:owner(self):print("visibleIf",visibleIf)
if visibleIf then
local stateCondition = "nopetbattle,nooverridebar,novehicleui,nopossessbar," .. visibleIf
self.visibilityDriver = "["..stateCondition.."] show; hide"
RegisterStateDriver(self, "visibility", self.visibilityDriver)
else
UnregisterStateDriver(self, "visibility")
self.visibilityDriver = nil -- just for debugging
end
end
function Germ:closeFlyout()
self.flyoutMenu:close()
end
-- will replace Germ:Hide() via Germ:new()
function Germ:hide(event)
--VisibleRegion:Hide(self) -- L-O-FUCKING-L this threw "attempt to index global 'VisibleRegion' (a nil value)" was called from SecureStateDriver.lua:103
zebug.info:event(event or "Blizz-Call"):owner(self):print("hiding.")
-- evidently, self:Hide() is called several times per second during state driver of visibility state==hide
local hide = self.originalHide or self.Hide
hide(self)
end
function Germ:clearAndDisable(event)
if self:isInactive(event) then return end
zebug.info:event(event):owner(self):print("DISABLE GERM :-(")
self:closeFlyout()
self:hide(event)
self:clearKeybinding()
self:setVisibilityDriver(nil) -- must be restored if Germ comes back -- TODO: move into registerForBlizUiActions() ?
self:unregisterForBlizUiActions()
self:invalidateFlyoutCache() -- provides a workaround for when the API lies to isUsable() -- drag & drop a germ to re-init
self:Disable() -- replaces all (well, most) of the above?
self.flyoutId = nil
self.label = nil
end
Germ.clearAndDisable = Pacifier:wrap(Germ.clearAndDisable)
function Germ:changeFlyoutIdAndEnable(flyoutId, event)
-- seems like if the new flyoutId is the same as a the old one, then, I could skip a lot (all?) of this...
-- but I vaguely remember that I tried that and something went wrong... but I can't remember why.
self.flyoutId = flyoutId
self:initLabelString()
zebug.info:event(event):owner(self):print("EnAbLe GeRm :-)")
self:closeFlyout()
self:doIcon(event)
self.flyoutMenu:applyConfigForGerm(self, event)
self:registerForBlizUiActions(event)
self:clearKeybinding()
self:doMyKeybindings(event)
self:Show()
self:updateClickerForPrimaryButton(event)
self:Enable()
end
function Germ:pickupFromSlotAndClear(event)
if isInCombatLockdown("Drag and drop") then return end
-- grab needed info before it gets cleared
local btnSlotIndex = self:getBtnSlotIndex()
local pickingUpThisFlyoutId = self.flyoutId
-- erase Ufo From the slot
GermCommander:eraseUfoFrom(btnSlotIndex, self, event)
-- the ON_DRAG_START event apparently precedes the cursor change
-- so, handle whatever is currently on the cursor, if anything.
local cursorBeforeItDrops = Cursor:get()
if cursorBeforeItDrops then
zebug.info:event(event):owner(self):print("cursorBeforeItDrops", cursorBeforeItDrops)
if cursorBeforeItDrops:isUfoProxyForFlyout() then
-- the user is dragging a UFO
local droppingThisFlyoutId = UfoProxy:getFlyoutId()
GermCommander:dropDraggedUfoFromCursorOntoActionBar(btnSlotIndex, droppingThisFlyoutId, event)
else
-- the user is just dragging a normal Bliz spell/item/etc.
-- Cursor:dropOntoActionBar(btnSlotIndex, eventId) -- this is already happening without me needing to do anything, yes?
end
end
UfoProxy:pickupUfoOntoCursor(pickingUpThisFlyoutId, event)
end
---@return BlizActionBarButton
function Germ:getParent()
return self:GetParent()
end
function Germ:getDirection(event)
-- TODO: fix bug where edit-mode -> change direction doesn't automatically update existing germs
local parent = self:getParent()
-- check if my ThirdPartyAddonSupport has provided a method
if parent.GetSpellFlyoutDirection then
return parent:GetSpellFlyoutDirection(event)
end
-- use the std Bliz method
return parent.bar:GetSpellFlyoutDirection(event)
end
function Germ:updateAllBtnHotKeyLabels(event)
self.flyoutMenu:applyConfigForGerm(self, event)
end
--[[
function Germ:copyDoCloseOnClickConfigValToAttribute()
-- haven't figured out why it doesn't work on the germ but does on the flyout
--zebug.trace:mCross():owner(self):print("self.flyoutMenu",self.flyoutMenu, "setting new value from Config.opts.doCloseOnClick", Config.opts.doCloseOnClick)
local doCloseOnClick = Config.opts.doCloseOnClick
UFO_DUM_DUM:setSecEnvAttribute("doCloseOnClick", doCloseOnClick)
self:setSecEnvAttribute("doCloseOnClick", doCloseOnClick)
return self.flyoutMenu and self.flyoutMenu:setSecEnvAttribute("doCloseOnClick", doCloseOnClick)
end
Germ.copyDoCloseOnClickConfigValToAttribute = Pacifier:wrap(Germ.copyDoCloseOnClickConfigValToAttribute, L10N.RECONFIGURE_AUTO_CLOSE)
]]
function Germ:setToolTip()
local btn = self:getPrimeBtn()
if btn and btn.hasDef and btn:hasDef() then
btn:setTooltip()
return
end
local flyoutDef = FlyoutDefsDb:get(self.flyoutId)
local label = flyoutDef.name or flyoutDef.id
if GetCVar("UberTooltips") == "1" then
GameTooltip_SetDefaultAnchor(GameTooltip, self)
else
GameTooltip:SetOwner(self, TooltipAnchor.LEFT)
end
GameTooltip:SetText(label)
end
---@return FlyoutDef
function Germ:getFlyoutDef()
return FlyoutDefsDb:get(self.flyoutId)
end
function Germ:getUsableFlyoutDef()
return self:getFlyoutDef():filterOutUnusable()
end
function Germ:getBtnDef(n)
return self:getUsableFlyoutDef():getButtonDef(n)
end
-- required by Button_Mixin
function Germ:getDef()
return self:getBtnDef(self.primeBtnIndex or 1)
end
---@return BOFM_TYPE
function Germ:getPrimeBtn()
return self.flyoutMenu:getBtn(self.primeBtnIndex or 1)
end
function Germ:invalidateFlyoutCache()
self:getFlyoutDef():invalidateCache()
end
function Germ:refreshFlyoutDefAndApply(event)
zebug.info:event(event):owner(self):print("re-configuring...") -- name("refreshFlyoutDefAndApply"):
self:getFlyoutDef():invalidateCacheOfUsableFlyoutDefOnly(event)
self:applyConfigFromFlyoutDef(event) -- exclude clickers?
end
-------------------------------------------------------------------------------
-- Key Bindings & UI actions Registerings
-------------------------------------------------------------------------------
function Germ:doneSaid(key)
local result
if not self.DONE_SAID then
self.DONE_SAID = { }
end
result = self.DONE_SAID[key]
self.DONE_SAID[key] = true
return result
end
function Germ:fullModifiedKeyName(key, ...)
if select("#", ...) == 0 then return key end -- nothing in "..." means no modifiers means no work to do.
local fullKey = strjoin("-", ...) .. "-" .. strupper(key)
return fullKey
end
function Germ:bindKeyNameTo(keyName, mouseClick)
return self:addModifiersToKeyNameAndBind(keyName, mouseClick) -- no args for any modifiers (shift/alt/etc)
end
---@param unmodifiedKeyName string
---@param mouseClick MouseClick
---@vararg ModifierKey list of 0 or more
---@return string original name plus modifiers (if any) IF it was successfully bound or is a Germ binding still in use
function Germ:addModifiersToKeyNameAndBind(unmodifiedKeyName, mouseClick, --[[modifiers]] ...)
local keyName = strupper(unmodifiedKeyName)
local isMainBinding
local modCount = select("#", ...)
if modCount == 0 then
-- if we didn't pass in any modifiers, then this is the Germ's base binding
isMainBinding = true
self.mainKeyBindingsKeyNames[keyName] = true
else
-- filter out any modifiers that are already present in the in base binding to avoid something like SHIFT-SHIFT-Z
local filteredModifiers
for i = 1, modCount do
local modifier = strupper( select(i, ...) )
local hasAlready = string.find(keyName, modifier)
if not hasAlready then
zebug.trace:owner(self):print("KEY",keyName, "ok to add modifier",modifier)
if not filteredModifiers then filteredModifiers = {} end
filteredModifiers[#filteredModifiers+1] = modifier
else
zebug.trace:owner(self):print("KEY",keyName, "already includes modifier",modifier)
end
end
if not filteredModifiers then
zebug.info:owner(self):print("KEY",keyName, "ABORT - all desired modifiers already in base binding", ...)
return
end
local keyNamePlusModifiers = strjoin("-", unpack(filteredModifiers) ) .. "-" .. keyName -- TODO: does the order matter? Is ALT-SHIFT-Z as good as SHIFT-ALT-Z
keyName = keyNamePlusModifiers
end
local isAlreadyProcessedAndBoundToMe = tableContainsVal(self.keybinds, keyName)
if isAlreadyProcessedAndBoundToMe then
zebug.info:owner(self):print("KEY",keyName, "SKIP: already bound! self.keybinds contains this key.")
-- returning the name to signal the caller that this one is still in use so don't remove it
return keyName
end
if isMainBinding then
self:claimMainKeyBinding(keyName)
else
-- decide if we can steal a key that is already bound
local isOkForExtra = true
local otherGerm = self:isAlreadyMainKeyBindingOfSomeOtherGerm(keyName)
if otherGerm then
-- never steal a "main binding" from another germ
zebug.info:owner(self):print("KEY",keyName, "Will not add extra binding for this key because existing UFO", otherGerm, "is already bound to it.")
if not self.isNew then
msgUser(self:forUser(), "with keybinding", unmodifiedKeyName, "will not bind", keyName, "because that one is already bound to", otherGerm:forUser())
end
isOkForExtra = false
return
end
local action
local targetBtn
local isNoClobber = Config:get("doNotOverwriteExistingKeybindings")
if isNoClobber then
-- check for an existing key binding
action = GetBindingAction(keyName, true) -- returns empty string instead of nil - FU Bliz
action = exists(action) and action or nil -- ensure a meaningful value and not Bliz BS
if action then
-- but, is it an action bar button?
targetBtn = BlizActionBarButtonHelper:getViaKeyBinding(action)
if targetBtn then
zebug.info:owner(self):print("KEY", keyName, "existingBinding", action, "btn", targetBtn)
-- is that button EMPTY?
isOkForExtra = targetBtn:isEmpty()
if not isOkForExtra then
zebug.info:owner(self):print("KEY", keyName, "Will not add extra binding for this key because it conflicts with", targetBtn)
--if not self:doneSaid(keyName) then
if not self.isNew then
msgUser(self:forUser(), "with keybinding", unmodifiedKeyName, "will not bind", keyName, "because that one is already bound to", targetBtn:forUser())
end
--end
return
end
else
-- there is an action but it's not a button, eg FORWARD or TOGGLERUN. Don't touch it!
isOkForExtra = false
end
end
end
zebug.info:owner(self):print("KEY", keyName, "existingBinding", action, "btn", targetBtn, "isOkForExtra",isOkForExtra)
if not isOkForExtra then
return
end
end
local myGlobalVarName = self:GetName()
SetOverrideBindingClick(self, true, keyName, myGlobalVarName, mouseClick)
-- debugging err check - remove when done
local newBinding = GetBindingAction(keyName, true)
zebug.info:owner(self):print("KEY", keyName, "BOUND! newBinding", newBinding)
return keyName
end
---@return Germ the germ that is already bound to this keyName
function Germ:isAlreadyMainKeyBindingOfSomeOtherGerm(keyName)
---@type Germ
local someGerm = mainKeyBindingsForAllGerms[keyName]
if someGerm then
-- is that Germ me?
return (someGerm ~= self) and someGerm
end
return nil -- no Germ claims this binding
end
function Germ:isMyBoundKey(isMyBoundKey)
for keyName, foo in pairs(self.mainKeyBindingsKeyNames) do
if keyName == isMyBoundKey then return true end
end
end
function Germ:claimMainKeyBinding(keyName)
---@type Germ
self.mainKeyBindingsKeyNames[keyName] = true
mainKeyBindingsForAllGerms[keyName] = self
end
function Germ:doMyKeybindings(event)
if isInCombatLockdown("Keybind") then return end
local parent = self:getParent()
local btnName = parent.btnYafName or parent.btnName
local ucBtnName = string.upper(btnName)
local myGlobalVarName = self:GetName()
local keybindingsAssignedToMyActionBarButton
if GetBindingKey(ucBtnName) then
keybindingsAssignedToMyActionBarButton = { GetBindingKey(ucBtnName) }
end
-- add new keybinds
local newKeyBindings = {}
if keybindingsAssignedToMyActionBarButton then
for i, keyName in ipairs(keybindingsAssignedToMyActionBarButton) do
-- handle the MAIN keybinding(s)
table.insert(newKeyBindings, keyName)
local isAdded = self:bindKeyNameTo(keyName, MouseClick.RESERVED_FOR_KEYBIND)
if isAdded then
zebug.info:event(event):owner(self):print("bound keyName", keyName)
local keybind1 = keybindingsAssignedToMyActionBarButton[1]
self:setHotKeyOverlay(keybind1)
if not isNumber(keybind1) then
-- store it for use inside the secure code
-- so we can make the first button's keybind be the same as the UFO's
self:setSecEnvAttribute("UFO_KEYBIND_1", keybind1)
end
else
zebug.info:event(event):owner(self):print("NOT binding keyName", keyName, "because it's already bound.")
end
-- handle the MODIFIED (shift/alt/etc) keybinding(s)
if Config:get("enableBonusModifierKeys") then
local bonusModifierKeys = Config:get("bonusModifierKeys")
---@param modifierKey ModifierKey
---@param behavior GermClickBehavior
for modifierKey, behavior in pairs(bonusModifierKeys) do
local clicker = RESERVED_CLICKER_BEHAVES_AS[behavior]
-- DONE? - I must differentiate between KB I create VS those in the Bliz Opt
zebug.info:event(event):owner(self):print("CONFIG OPTS LOOP - binding - keyName", keyName, "modifierKey",modifierKey, "behavior",behavior)
local modName = self:addModifiersToKeyNameAndBind(keyName, clicker, modifierKey)
if modName then
table.insert(newKeyBindings, modName)
else
zebug.info:event(event):owner(self):print("NOT binding BonusModifier for Key", keyName, "plus",modifierKey)
end
end
else
zebug.info:event(event):owner(self):print("CONFIG OPTS - nope! No bonusModifierKeys for you!")
end
end
else
self:setHotKeyOverlay(nil)
self:clearKeybinding()
end
-- remove deleted keybinds
if (self.keybinds) then
for i, keyName in ipairs(self.keybinds) do
if not tableContainsVal(newKeyBindings, keyName) then
zebug.trace:event(event):owner(self):print("myGlobalVarName", myGlobalVarName, "UN-binding keyName",keyName)
SetOverrideBinding(self, true, keyName, nil)
else
zebug.trace:event(event):owner(self):print("myGlobalVarName", myGlobalVarName, "NOT UN-binding keyName",keyName, "because it's still bound.")
end
end
end
self.keybinds = newKeyBindings
end
Germ.doMyKeybindings = Pacifier:wrap(Germ.doMyKeybindings, L10N.CHANGE_KEYBINDING)
function Germ:clearKeybinding()
if not (self.keybinds) then return end
exeOnceNotInCombat("Keybind removal "..self:getName(), function()
-- FUNC START
ClearOverrideBindings(self)
self.keybinds = nil
for keyName, foo in pairs(self.mainKeyBindingsKeyNames) do
mainKeyBindingsForAllGerms[keyName] = nil
end
self.mainKeyBindingsKeyNames = { }
self:setHotKeyOverlay(nil)
-- FUNC END
end)
end
function Germ:registerForBlizUiActions(event)
self:maybeRegisterForClicksDependingOnCursorIsEmpty(event) -- this must be done regardless of isEventStuffRegistered
if self.isEventStuffRegistered then return end
self:EnableMouseMotion(true)
self:RegisterForDrag(MouseClick.LEFT)
--self:RegisterEvent("CURSOR_CHANGED") -- now handled by Ufo.lua
self.isEventStuffRegistered = true
end
function Germ:maybeRegisterForClicksDependingOnCursorIsEmpty(event)
local type, id = GetCursorInfo()
local enable = not type
local wut = enable and "cursor is empty so clicks are Enabled" or "cursor is occupied so clicks are IGNORED"
--zebug.info:mStar():mMoon():mCross():event(event):owner(self):print("enable",enable, "GetCursorInfo->",GetCursorInfo, "GetCursorInfo->type",type, "GetCursorInfo->id",id, "Cursor:getFresh()",Cursor:getFresh(event), wut)
zebug.trace:event(event):owner(self):print(wut)
if enable then
self:RegisterForClicks("AnyDown", "AnyUp") -- protected. Pacify.
else
self:RegisterForClicks()
end
end
Germ.maybeRegisterForClicksDependingOnCursorIsEmpty = Pacifier:wrap(Germ.maybeRegisterForClicksDependingOnCursorIsEmpty)
-- and here
function Germ:unregisterForBlizUiActions()
if not self.isEventStuffRegistered then return end
self:EnableMouseMotion(false)
self:RegisterForDrag("Button6Down")
self:RegisterForClicks("Button6Down")
self.isEventStuffRegistered = false
end
function Germ:handleReceiveDrag(event)
if isInCombatLockdown("Drag and drop") then return end
local cursor = Cursor:get()
if cursor then
Ufo.germLock = event
local flyoutIdOld = self.flyoutId
if cursor:isUfoProxyForFlyout() then
-- soup to nuts. do everything without relying on the ACTIONBAR_SLOT_CHANGED handler
-- don't let the UfoProxy hit the actionbar.
zebug.info:event(event):owner(self):print("cursor is a proxy",cursor)
local flyoutIdNew = UfoProxy:getFlyoutId()
self:changeFlyoutIdAndEnable(flyoutIdNew, event)
Placeholder:put(self.btnSlotIndex, event) -- will discard the UfoProxy in favor of a Placeholder
GermCommander:savePlacement(self.btnSlotIndex, flyoutIdNew, event)
elseif cursor:isUfoProxyForButton() then
-- The user has dropped the fake button proxy onto the action bar.
ButtonOnFlyoutMenu:abortIfUnusable(Ufo.pickedUpBtn)
-- ignore it
Ufo.germLock = nil
return
else
zebug.info:event(event):owner(self):print("just got hit by rando",cursor)
self:clearAndDisable(event)
GermCommander:forgetPlacement(self.btnSlotIndex, event)
cursor:dropOntoActionBar(self.btnSlotIndex, event)
end
if flyoutIdOld then
zebug.info:mMoon():event(event):owner(self):print("--------- PRE UfoProxy:PICKUP", GetCursorInfo(), Cursor:get())
UfoProxy:pickupUfoOntoCursor(flyoutIdOld, event)
zebug.info:mMoon():event(event):owner(self):print("--------- POST UfoProxy:PICKUP", GetCursorInfo(), Cursor:get())
else
cursor:clear(event) -- will discard the UfoProxy if it's still there
end
Ufo.germLock = nil
end
end
-------------------------------------------------------------------------------
-- Handlers
-------------------------------------------------------------------------------
function ScriptHandlers:ON_MOUSE_DOWN(mouseClick)
local cursor = Cursor:get()
zebug.info:mDiamond():owner(self):newEvent(self, "ScriptHandlers.ON_MOUSE_DOWN"):run(function(event)
self:OnMouseDown() -- Call Bliz super()
if cursor then
-- self:handleReceiveDrag(event)
else
zebug.info:owner(self):event(event):name("ScriptHandlers:ON_MOUSE_DOWN"):print("not dragging, so, exiting. proxy",UfoProxy)
end
end, cursor)
end
function ScriptHandlers:ON_MOUSE_UP()
zebug.info:mCross():owner(self):newEvent(self, "ScriptHandlers.ON_MOUSE_UP"):run(function(event)
self:OnMouseUp() -- Call Bliz super()
local isDragging = GetCursorInfo()
local mySlotBtn = BlizActionBarButtonHelper:get(self.btnSlotIndex, event)
if isDragging then
self:handleReceiveDrag(event)
else
zebug.info:owner(self):event(event):name("ScriptHandlers:ON_MOUSE_UP"):print("not dragging, so, exiting. proxy",UfoProxy, "mySlotBtn",mySlotBtn)
end
end)
end
-- A germ on the action bar was just hit by something dropping off the user's cursor
-- The something is either a std Bliz thingy,
-- or, a UFO (which itself is represented by the "proxy" macro)
---@param self GERM_TYPE
function ScriptHandlers:ON_RECEIVE_DRAG()
if isInCombatLockdown("Drag and drop") then return end
zebug.info:mCircle():owner(self):newEvent(self, "ON_RECEIVE_DRAG"):run(function(event)
self:handleReceiveDrag(event)
end)
end
function ScriptHandlers:ON_DRAG_START()
local cvarLockActionBars = C_CVar.GetCVar("lockActionBars")
if isTrueEnough(cvarLockActionBars) then
zebug.info:owner(self):print("lockActionBars", cvarLockActionBars, "IsModifierKeyDown() ",IsModifierKeyDown() )
-- only permit pickup when shift/control/alt/etc is pressed -- originally was IsShiftKeyDown()
if not IsModifierKeyDown() then
msgUser(L10N.YOUR_ACTION_BARS_ARE_LOCKED)
return
end
end
if isInCombatLockdown("Drag and drop") then return end
self:OnDragStart() -- Call Bliz super()
zebug.info:mCircle():owner(self):newEvent(self, "ON_DRAG_START"):run(function(event)
self:pickupFromSlotAndClear(event)
end)
end
function ScriptHandlers:ON_ENTER()
if self:isInactive() then return end
self:OnEnter() -- Call Bliz super()
zebug.info:mDiamond():owner(self):newEvent(self, "ON_ENTER"):run(function(event)
self:setToolTip()
end)
end
function ScriptHandlers:ON_LEAVE()
self:OnLeave() -- Call Bliz super()
GameTooltip:Hide()
end
function Germ:initializeSecEnv(event)
assert(self.flyoutMenu, "do initFlyoutMenu() first")
-- set attributes used inside the secure scripts
self:setSecEnvAttribute("DO_DEBUG", not zebug.info:isMute() )
self:setSecEnvAttribute("UFO_NAME", self:getUfoLabel())
self:setSecEnvAttribute(SecEnvAttribute.flyoutDirection, self:getDirection(event))
self:setSecEnvAttribute("doKeybindTheButtonsOnTheFlyout", Config:get("doKeybindTheButtonsOnTheFlyout"))
self:SetFrameRef("flyoutMenu", self.flyoutMenu)
self:SetFrameRef("UFO_DUM_DUM", _G["UFO_DUM_DUM"])
-- set global variables inside the restricted environment of the germ
self:Execute([=[
germ = self
flyoutMenu = self:GetFrameRef("flyoutMenu")
UFO_DUM_DUM= self:GetFrameRef("UFO_DUM_DUM")
myName = self:GetAttribute("UFO_NAME")
doDebug = self:GetAttribute("DO_DEBUG") or false
]=])
SecEnv:installSecEnvScriptFor_OpenMyFlyout(self)
self:installSecEnvScriptFor_ON_CLICK()
end
function Germ:assignAllMouseClickers(event)
-- loop over all mouse buttons: LEFT, MIDDLE, etc.
for _, mouseClick in ipairs(MOUSE_BUTTONS) do
-- assign each one a behavior: OPEN, RANDOM_BTN, etc.
local behaviorName = Config:getGermClickBehavior(self.flyoutId, mouseClick)
self:assignTheMouseClicker(mouseClick, behaviorName, event)
end
-- these mouse clicks are unconditionally reserved & hardcoded for special key bindings
for behavior, click in pairs(RESERVED_CLICKER_BEHAVES_AS) do
self:assignTheMouseClicker(click, behavior, event)
end
self:applyConfigForMainKeybind(event)
end
-- sets secure environment scripts to handle mouse clicks (left button, right button, etc)
---@param mouseClick MouseClick
---@param behaviorName GermClickBehavior
function Germ:assignTheMouseClicker(mouseClick, behaviorName, event)
if not behaviorName then
GermClickBehaviorAssignmentFunction.NONE(self, mouseClick, event)
return
end
if not GermClickBehavior[behaviorName] then
error("Invalid 'behaviorName' arg: " .. (behaviorName or "NiL")) -- type checking in Lua!
end
local behave = GermClickBehaviorAssignmentFunction[behaviorName]
if not behave then
error(behave, "there is no method defined for GermClickBehavior of ".. behaviorName)
end
zebug.info:owner(self):event(event):print("mouseClick",mouseClick, "behaviorName", behaviorName, "handler", behave)
behave(self, mouseClick, event)
-- tell the ButtonOnFlyoutMenu that this mouseClick is PRIME_BTN
local isPrime = behaviorName == GermClickBehavior.PRIME_BTN
local n = MouseClickAsSecEnvN[mouseClick]
self:SetAttribute("IS_A_PRIME_BTN_"..n, isPrime) -- assume earlier code blocked exe during combat
end
-- the secEnv handler for Primary Button is special.
-- it won't automatically accommodate changes to the flyout buttons and must be re-applied for any changes to flyoutDef
-- TODO: consider folding it into the ON_CLICK script along with the RANDOM_BTN and CYCLE_ALL_BTNS
function Germ:updateClickerForPrimaryButton(event)
-- loop over all mouse buttons
for _, mouseClick in ipairs(MOUSE_BUTTONS) do
local behaviorName = Config:getGermClickBehavior(self.flyoutId, mouseClick)
if behaviorName == GermClickBehavior.PRIME_BTN then
self:assignTheMouseClicker(mouseClick, behaviorName, event)
end
end
end
function Germ:applyConfigForMainKeybind(event)
local keybindBehavior = Config.opts.keybindBehavior or Config.optDefaults.keybindBehavior
self:assignTheMouseClicker(MouseClick.RESERVED_FOR_KEYBIND, keybindBehavior, event)
end
function Germ:removeSecEnvMouseClickBehaviorVia_ON_CLICK(mouseClick)
self:assignSecEnvMouseClickBehaviorVia_ON_CLICK(mouseClick, nil)
end
---@param mouseClick MouseClick
---@param clickBehavior GermClickBehavior
function Germ:assignSecEnvMouseClickBehaviorVia_ON_CLICK(mouseClick, clickBehavior)
local name = SecEnv.ON_CLICK_SCRIPT_NAME_PREFIX_FOR___ARBITRARY_BEHAVIOR .. mouseClick
self:setSecEnvAttribute(name, clickBehavior)
end
function Germ:setRecentIcon(icon)
if not self:isActive() then return end
if not Config:isAnyClickerUsingRecent(self.flyoutId) then return end
-- icon = icon or self.promoter:GetAttribute("UFO_ICON")
zebug.info:owner(self):print("sneaky! icon", icon)
self:setIcon(icon,"promoter")
end
---@param btn ButtonOnFlyoutMenu
function Germ:promoteButtonToPrime(btn)
if not self:isActive() then return end
local n = btn:getId()
self.primeBtnIndex = n or 1
self:setIcon(btn.iconTexture, "promoter")
end
-------------------------------------------------------------------------------
--
-- SecEnv - GermClickBehaviorAssignmentFunction
-- deal with OPEN / PRIME_BTN / RANDOM_BTN / CYCLE_ALL_BTNS
--
-------------------------------------------------------------------------------
---@param mouseClick MouseClick
function GermClickBehaviorAssignmentFunction:NONE(mouseClick, event)
self:removeSecEnvMouseClickBehaviorVia_ON_CLICK(mouseClick)