Repository navigation
Expand file tree
/
Copy pathPicoMenu.lua
More file actions
1054 lines (964 loc) · 33 KB
/
Copy pathPicoMenu.lua
File metadata and controls
1054 lines (964 loc) · 33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local BLOCKED_IN_COMBAT = "UI Action Blocked"
local UpdateMicroMenuVisibility
local UpdateQueueEyePosition
local UpdatePicoMenuVisibility
local ApplyButtonSide
local function IsBlockedInCombat()
return InCombatLockdown() or UnitAffectingCombat("player") or UnitAffectingCombat("pet")
end
local function ShowBlockedInCombatMessage()
UIErrorsFrame:AddMessage(BLOCKED_IN_COMBAT, 1, 0, 0)
end
-- Menu size is applied as a scale on the whole menu rather than a font size: the
-- Menu API sizes rows from Blizzard's own font, so a bigger font alone would overflow
-- them, while a scale grows text, icons and padding together.
local MIN_MENU_SCALE, MAX_MENU_SCALE = 0.5, 2
local MENU_SCALE_PRESETS = { 0.8, 0.9, 1, 1.1, 1.25, 1.5 }
local function GetMenuScale()
local scale = tonumber(PicoMenuDB.menuScale) or 1
return math.min(MAX_MENU_SCALE, math.max(MIN_MENU_SCALE, scale))
end
local function BuildMenuSizeItems()
local items = {}
for _, scale in ipairs(MENU_SCALE_PRESETS) do
table.insert(items, {
text = ("%d%%"):format(math.floor(scale * 100 + 0.5)),
isRadio = true,
value = scale,
checked = function(value)
return math.abs(GetMenuScale() - value) < 0.001
end,
func = function(value)
PicoMenuDB.menuScale = value
end,
})
end
return items
end
local function IsButtonOnLeft()
return PicoMenuDB.buttonSide == "LEFT"
end
-- The action bar's end caps are gryphons for Alliance and wyverns for Horde.
local function GetEndCapName()
return UnitFactionGroup("player") == "Horde" and "Wyvern" or "Gryphon"
end
local function BuildButtonSideItems()
local items = {}
for _, side in ipairs({ "LEFT", "RIGHT" }) do
table.insert(items, {
-- Resolved when the menu opens, since the faction isn't known at load time.
text = function()
return (side == "LEFT" and "Left " or "Right ") .. GetEndCapName()
end,
isRadio = true,
value = side,
checked = function(value)
return PicoMenuDB.buttonSide == value
end,
func = function(value)
PicoMenuDB.buttonSide = value
ApplyButtonSide()
end,
})
end
return items
end
local function IsAddOnLoadedCompat(name)
if C_AddOns and C_AddOns.IsAddOnLoaded then
return C_AddOns.IsAddOnLoaded(name)
end
return IsAddOnLoaded and IsAddOnLoaded(name)
end
local function EnsureAddOn(name)
if C_AddOns and C_AddOns.IsAddOnLoaded and C_AddOns.LoadAddOn then
if not C_AddOns.IsAddOnLoaded(name) then
C_AddOns.LoadAddOn(name)
end
elseif UIParentLoadAddOn then
UIParentLoadAddOn(name)
end
end
-- Guards against missing functions and keeps the callee's taint from spreading back
-- to us. It does NOT make the call secure: called from a menu callback, fn still runs tainted.
local function SafeCall(fn, ...)
if type(fn) ~= "function" then
return false
end
if securecallfunction then
securecallfunction(fn, ...)
else
fn(...)
end
return true
end
-- The Spellbook and Talent frames were merged into PlayerSpellsFrame in 11.0, so
-- prefer the tab-targeted PlayerSpellsUtil calls and keep the old globals as a fallback.
local function TogglePlayerSpellsTab(toggleFuncName, frameTab, legacyToggle, ...)
EnsureAddOn("Blizzard_PlayerSpells")
if PlayerSpellsUtil then
if SafeCall(PlayerSpellsUtil[toggleFuncName]) then
return
end
local tab = PlayerSpellsUtil.FrameTabs and PlayerSpellsUtil.FrameTabs[frameTab]
if tab and SafeCall(TogglePlayerSpellsFrame, tab) then
return
end
end
if SafeCall(legacyToggle, ...) then
return
end
if PlayerSpellsMicroButton then
SafeCall(PlayerSpellsMicroButton.Click, PlayerSpellsMicroButton, "LeftButton", true)
end
end
local function OpenSpellbook()
TogglePlayerSpellsTab("ToggleSpellBookFrame", "SpellBook", ToggleSpellBook, BOOKTYPE_SPELL)
end
local function OpenTalents()
TogglePlayerSpellsTab("ToggleClassTalentFrame", "ClassTalents", ToggleTalentFrame)
end
local function OpenProfessions()
EnsureAddOn("Blizzard_ProfessionsBook")
SafeCall(ToggleProfessionsBook)
end
local function OpenGreatVault()
EnsureAddOn("Blizzard_WeeklyRewards")
SafeCall(WeeklyRewards_ShowUI)
end
local function OpenCalendar()
EnsureAddOn("Blizzard_Calendar")
SafeCall(ToggleCalendar)
end
-- Binding hints. An unbound or unknown binding just yields no hint, so a binding
-- name that changes in a future patch degrades quietly instead of erroring.
local function GetBindingHint(bindingName)
if not bindingName or not GetBindingKey then
return nil
end
local key = GetBindingKey(bindingName)
if not key or key == "" then
return nil
end
if GetBindingText then
key = GetBindingText(key, "KEY_") or key
end
return key
end
-- Alert sources. Each is wrapped in pcall at the call site: these poke at APIs that
-- Blizzard reshuffles between expansions, and a broken alert must not break the button.
local function HasGreatVaultRewards()
return C_WeeklyRewards and C_WeeklyRewards.HasAvailableRewards and C_WeeklyRewards.HasAvailableRewards()
end
-- Leftover currency on its own is a false positive: capped and hero talent currencies
-- can sit above zero with nothing left to buy. Confirm a genuinely purchasable node
-- exists, the way Plumber's API.HasAnyPurchasableTraitInSystem does.
local function HasUnspentTalentPoints()
if not C_ClassTalents or not C_Traits then
return false
end
local configID = C_ClassTalents.GetActiveConfigID and C_ClassTalents.GetActiveConfigID()
if not configID then
return false
end
local configInfo = C_Traits.GetConfigInfo and C_Traits.GetConfigInfo(configID)
local treeID = configInfo and configInfo.treeIDs and configInfo.treeIDs[1]
if not treeID then
return false
end
-- Include staged changes, so points spent but not yet applied still count as spent.
local currencies = C_Traits.GetTreeCurrencyInfo(configID, treeID, false)
local unspent = currencies and currencies[1] and currencies[1].quantity or 0
if unspent <= 0 then
return false
end
for _, nodeID in ipairs(C_Traits.GetTreeNodes(treeID) or {}) do
local costs = C_Traits.GetNodeCost(configID, nodeID)
-- Assume a single currency type, as the talent trees do.
local affordable = (not costs) or (#costs == 0) or (unspent >= costs[1].amount)
if affordable then
local nodeInfo = C_Traits.GetNodeInfo(configID, nodeID)
for _, entryID in ipairs(nodeInfo and nodeInfo.entryIDs or {}) do
if C_Traits.CanPurchaseRank(configID, nodeID, entryID) then
return true
end
end
end
end
return false
end
local alertSources = {
{ label = "Great Vault rewards available", check = HasGreatVaultRewards },
{ label = "Unspent talent points", check = HasUnspentTalentPoints },
}
local function GetActiveAlerts()
local active = {}
for _, source in ipairs(alertSources) do
local ok, result = pcall(source.check)
if ok and result then
table.insert(active, source.label)
end
end
return active
end
local menuList = {
{
text = MAINMENU_BUTTON,
isTitle = true,
notCheckable = true,
},
{
text = CHARACTER_BUTTON,
binding = "TOGGLECHARACTER0",
icon = "Interface\\PaperDollInfoFrame\\UI-EquipmentManager-Toggle",
func = function()
ToggleCharacter("PaperDollFrame")
end,
notCheckable = true,
},
{
text = SPELLBOOK_ABILITIES_BUTTON,
binding = "TOGGLESPELLBOOK",
icon = "Interface\\MINIMAP\\TRACKING\\Class",
func = function()
if not IsBlockedInCombat() then
OpenSpellbook()
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
disabled = IsBlockedInCombat,
},
{
text = TALENTS,
binding = "TOGGLETALENTS",
icon = "Interface\\AddOns\\PicoMenu\\Media\\picomenu\\picomenuTalents",
func = function()
if not IsBlockedInCombat() then
OpenTalents()
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
disabled = IsBlockedInCombat,
},
{
text = TRADE_SKILLS or "Professions",
binding = "TOGGLEPROFESSIONBOOK",
icon = "Interface\\ICONS\\Trade_BlackSmithing",
func = function()
if not IsBlockedInCombat() then
OpenProfessions()
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
disabled = IsBlockedInCombat,
},
{
text = ACHIEVEMENT_BUTTON,
binding = "TOGGLEACHIEVEMENT",
icon = "Interface\\AddOns\\PicoMenu\\Media\\picomenu\\picomenuAchievement",
func = function()
ToggleAchievementFrame()
end,
notCheckable = true,
},
{
text = QUESTLOG_BUTTON,
binding = "TOGGLEQUESTLOG",
icon = "Interface\\GossipFrame\\ActiveQuestIcon",
func = function()
ToggleQuestLog()
end,
notCheckable = true,
},
{
text = CALENDAR or "Calendar",
icon = "Interface\\Calendar\\MeetingIcon",
func = function()
OpenCalendar()
end,
notCheckable = true,
},
{
isSeparator = true,
},
{
text = COMMUNITIES_FRAME_TITLE,
binding = "TOGGLEGUILDTAB",
icon = "Interface\\GossipFrame\\TabardGossipIcon",
func = function()
ToggleGuildFrame()
end,
notCheckable = true,
},
{
text = SOCIAL_BUTTON,
binding = "TOGGLESOCIAL",
icon = "Interface\\FriendsFrame\\PlusManz-BattleNet",
func = function()
ToggleFriendsFrame()
end,
notCheckable = true,
},
{
text = PLAYER_V_PLAYER,
icon = "Interface\\MINIMAP\\TRACKING\\BattleMaster",
func = function()
TogglePVPUI()
end,
notCheckable = true,
},
{
text = DUNGEONS_BUTTON,
binding = "TOGGLEGROUPFINDER",
icon = "Interface\\LFGFRAME\\BattleNetWorking0",
func = function()
ToggleLFDParentFrame()
end,
notCheckable = true,
},
{
text = CHALLENGES,
icon = "Interface\\BUTTONS\\UI-GroupLoot-DE-Up",
func = function()
PVEFrame_ToggleFrame("ChallengesFrame", nil)
end,
notCheckable = true,
},
{
text = GREAT_VAULT_REWARDS or WEEKLY_REWARDS or "Great Vault",
icon = "Interface\\ICONS\\INV_Misc_TreasureChest02c",
func = function()
if not IsBlockedInCombat() then
OpenGreatVault()
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
disabled = IsBlockedInCombat,
},
{
text = RAID,
icon = "Interface\\TARGETINGFRAME\\UI-TargetingFrame-Skull",
func = function()
if IsBlockedInCombat() then
ShowBlockedInCombatMessage()
return
end
-- If our call is the one that loads Blizzard_RaidUI, its secure raid group
-- buttons are created tainted and later Hide() calls get blocked and blamed
-- on us. Until Blizzard has loaded it, open Social and let the user click
-- the Raid tab so the load happens on a secure path.
if IsAddOnLoadedCompat("Blizzard_RaidUI") then
ToggleRaidFrame()
else
ToggleFriendsFrame()
end
end,
notCheckable = true,
disabled = IsBlockedInCombat,
},
{
text = ENCOUNTER_JOURNAL,
binding = "TOGGLEENCOUNTERJOURNAL",
icon = "Interface\\MINIMAP\\TRACKING\\Profession",
func = function()
ToggleEncounterJournal(1)
end,
notCheckable = true,
}, {
isSeparator = true,
},
{
text = HOUSING_DASHBOARD_FRAMETITLE,
icon = "Interface\\GossipFrame\\BinderGossipIcon",
func = function()
if not IsBlockedInCombat() then
HousingMicroButton:Click()
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
},
{
isSeparator = true,
},
{
text = MOUNTS,
binding = "TOGGLECOLLECTIONS",
icon = "Interface\\MINIMAP\\TRACKING\\StableMaster",
func = function()
if not IsBlockedInCombat() then
ToggleCollectionsJournal(1)
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
},
{
text = PETS,
icon = "Interface\\ICONS\\Tracking_WildPet",
func = function()
if not IsBlockedInCombat() then
ToggleCollectionsJournal(2)
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
},
{
text = TOY_BOX,
icon = "Interface\\MINIMAP\\TRACKING\\Reagents",
func = function()
if not IsBlockedInCombat() then
ToggleCollectionsJournal(3)
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
},
{
text = HEIRLOOMS,
icon = "Interface\\PaperDollInfoFrame\\UI-EquipmentManager-Toggle",
func = function()
if not IsBlockedInCombat() then
ToggleCollectionsJournal(4)
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
},
{
text = WARDROBE,
icon = "Interface\\Icons\\INV_Chest_Cloth_17",
func = function()
if not IsBlockedInCombat() then
ToggleCollectionsJournal(5)
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
},
{
isSeparator = true,
},
{
text = GM_EMAIL_NAME,
icon = "Interface\\CHATFRAME\\UI-ChatIcon-Blizz",
func = function()
ToggleHelpFrame()
end,
notCheckable = true,
},
{
text = BLIZZARD_STORE,
icon = "Interface\\CHATFRAME\\UI-ChatIcon-Blizz",
func = function()
StoreMicroButton:Click()
end,
notCheckable = true,
},
{
isSeparator = true,
},
{
text = SETTINGS,
icon = "Interface\\Buttons\\UI-OptionsButton",
notCheckable = true,
submenu = {
{
text = BATTLEFIELD_MINIMAP,
binding = "TOGGLEBATTLEFIELDMINIMAP",
-- colorCode = "|cff999999",
checked = function()
return BattlefieldMapFrame and BattlefieldMapFrame:IsShown()
end,
func = function()
ToggleBattlefieldMap()
end,
keepShownOnClick = true,
isNotRadio = true,
notCheckable = false,
},
{
text = "Show Main Menu",
checked = function()
return PicoMenuDB.showMicromenu
end,
func = function()
PicoMenuDB.showMicromenu = not PicoMenuDB.showMicromenu
UpdateMicroMenuVisibility()
end,
keepShownOnClick = true,
isNotRadio = true,
notCheckable = false,
},
{
text = "Show Pico Menu Button",
checked = function()
return PicoMenuDB.showPicomenu
end,
func = function()
PicoMenuDB.showPicomenu = not PicoMenuDB.showPicomenu
UpdatePicoMenuVisibility()
-- Hiding the button hides the only way back to this checkbox.
if not PicoMenuDB.showPicomenu then
print("|cff00ff00PicoMenu|r: button hidden. Type |cffffff00/pico|r to bring it back.")
end
end,
keepShownOnClick = true,
isNotRadio = true,
notCheckable = false,
},
{
text = "Button Position",
notCheckable = true,
submenu = BuildButtonSideItems(),
},
{
text = "Menu Size",
notCheckable = true,
submenu = BuildMenuSizeItems(),
},
{
isSeparator = true,
},
{
text = RELOADUI or "Reload UI",
icon = "Interface\\ICONS\\INV_Misc_Gear_01",
func = function()
if not IsBlockedInCombat() then
ReloadUI()
else
ShowBlockedInCombatMessage()
end
end,
notCheckable = true,
disabled = IsBlockedInCombat,
},
},
},
}
local picoMenuContextMenu
local lastPicoMenuHideTime = 0
-- Blizzard_PetBattleUI is load-on-demand, so PetBattleFrame is absent until the first pet battle.
local function GetPetBattleMicroButtonFrame()
return PetBattleFrame and PetBattleFrame.BottomFrame and PetBattleFrame.BottomFrame.MicroButtonFrame
end
UpdateMicroMenuVisibility = function()
local petBattleMicroButtons = GetPetBattleMicroButtonFrame()
if PicoMenuDB.showMicromenu then
if MicroMenu then MicroMenu:Show() end
if petBattleMicroButtons then petBattleMicroButtons:Show() end
else
if MicroMenu then MicroMenu:Hide() end
if petBattleMicroButtons then petBattleMicroButtons:Hide() end
end
UpdateQueueEyePosition()
end
local function GetMenuItemText(item)
local text = item.text
if type(text) == "function" then
text = text()
end
if item.icon then
text = "|T" .. item.icon .. ":0|t " .. text
end
-- Read live rather than caching, so rebinding a key is reflected the next time
-- the menu opens without needing a reload.
local hint = GetBindingHint(item.binding)
if hint then
text = text .. " |cff808080" .. hint .. "|r"
end
return text
end
local function IsItemDisabled(item)
if type(item.disabled) == "function" then
return item.disabled()
end
return item.disabled == true
end
local AddMenuItems
-- Submenus are separate frames, so scale whichever menu each element lands in
-- instead of only the root menu we get back from CreateContextMenu.
local function ApplyMenuScale(_, _, menu)
if menu then
menu:SetScale(GetMenuScale())
end
end
local function AddMenuItem(description, item)
if item.isSeparator then
description:CreateDivider()
elseif item.isTitle then
description:CreateTitle(GetMenuItemText(item)):AddInitializer(ApplyMenuScale)
elseif item.submenu then
local submenu = description:CreateButton(GetMenuItemText(item))
submenu:AddInitializer(ApplyMenuScale)
AddMenuItems(submenu, item.submenu)
if IsItemDisabled(item) then
submenu:SetEnabled(false)
end
elseif item.isRadio then
-- Close on pick: the new size takes effect the next time the menu opens.
local radio = description:CreateRadio(GetMenuItemText(item), item.checked, item.func, item.value)
radio:AddInitializer(ApplyMenuScale)
if MenuResponse and MenuResponse.Close then
radio:SetResponse(MenuResponse.Close)
end
elseif item.checked then
local checkbox = description:CreateCheckbox(GetMenuItemText(item), item.checked, item.func)
checkbox:AddInitializer(ApplyMenuScale)
if item.keepShownOnClick and MenuResponse and MenuResponse.Refresh then
checkbox:SetResponse(MenuResponse.Refresh)
end
if IsItemDisabled(item) then
checkbox:SetEnabled(false)
end
else
local button = description:CreateButton(GetMenuItemText(item), item.func)
button:AddInitializer(ApplyMenuScale)
if IsItemDisabled(item) then
button:SetEnabled(false)
end
end
end
AddMenuItems = function(description, items)
for _, item in ipairs(items) do
AddMenuItem(description, item)
end
end
local function OpenPicoMenu(anchor)
if not MenuUtil or not MenuUtil.CreateContextMenu then
return nil
end
local menu
menu = MenuUtil.CreateContextMenu(anchor, function(_, rootDescription)
rootDescription:SetTag("PicoMenu")
AddMenuItems(rootDescription, menuList)
end)
-- CreateContextMenu pins the menu to the cursor in unscaled coordinates, which
-- drifts once the menu has its own scale; replace that anchor, don't add to it.
menu:ClearAllPoints()
-- Open away from the bar: up and outwards from whichever end cap the button is on.
if IsButtonOnLeft() then
menu:SetPoint("BOTTOMRIGHT", anchor, "TOPLEFT", 0, 0)
else
menu:SetPoint("BOTTOMLEFT", anchor, "TOPRIGHT", 0, 0)
end
menu:HookScript("OnHide", function()
lastPicoMenuHideTime = GetTime()
end)
return menu
end
-- Pico Menu Button
local picoMenu = CreateFrame("Button", "PicoMenuButton", UIParent)
picoMenu:SetFrameStrata("MEDIUM")
picoMenu:SetFrameLevel(150)
picoMenu:Raise()
picoMenu:SetSize(40, 40)
picoMenu:RegisterForClicks("Anyup")
picoMenu:RegisterEvent("PLAYER_LOGIN")
picoMenu:RegisterEvent("PET_BATTLE_OPENING_START")
picoMenu:RegisterEvent("PET_BATTLE_CLOSE")
picoMenu:RegisterEvent("PLAYER_ENTERING_WORLD")
picoMenu:RegisterEvent("WEEKLY_REWARDS_UPDATE")
picoMenu:RegisterEvent("TRAIT_CONFIG_UPDATED")
picoMenu:RegisterEvent("PLAYER_LEVEL_UP")
picoMenu:SetNormalTexture("Interface\\AddOns\\PicoMenu\\Media\\picomenu\\picomenuNormal")
picoMenu:GetNormalTexture():SetSize(40, 40)
picoMenu:SetHighlightTexture("Interface\\AddOns\\PicoMenu\\Media\\picomenu\\picomenuHighlight")
picoMenu:GetHighlightTexture():SetAllPoints(picoMenu:GetNormalTexture())
-- Alert indicator. Hiding the Main Menu also hides Blizzard's own micro button
-- alerts, so surface anything that wants attention on the Pico Menu button itself.
local alertIndicator = picoMenu:CreateTexture(nil, "OVERLAY")
alertIndicator:SetTexture("Interface\\COMMON\\Indicator-Yellow")
alertIndicator:SetSize(14, 14)
alertIndicator:Hide()
local alertPulse = alertIndicator.CreateAnimationGroup and alertIndicator:CreateAnimationGroup()
if alertPulse then
alertPulse:SetLooping("BOUNCE")
local fade = alertPulse:CreateAnimation("Alpha")
fade:SetFromAlpha(1)
fade:SetToAlpha(0.3)
fade:SetDuration(0.9)
fade:SetSmoothing("IN_OUT")
end
local activeAlerts = {}
local function UpdateAlertIndicator()
activeAlerts = GetActiveAlerts()
if #activeAlerts > 0 then
alertIndicator:Show()
if alertPulse and not alertPulse:IsPlaying() then
alertPulse:Play()
end
else
if alertPulse then
alertPulse:Stop()
end
alertIndicator:Hide()
end
end
local function AnchorToMainBar()
if not MainActionBar then return end
picoMenu:SetParent(MainActionBar)
picoMenu:SetSize(40, 40)
picoMenu:ClearAllPoints()
local onLeft = IsButtonOnLeft()
local endCaps = MainActionBar.EndCaps
local endCap = endCaps and (onLeft and endCaps.LeftEndCap or endCaps.RightEndCap)
if endCap then
-- Nudge inwards, towards the bar, onto the body of the end cap art.
picoMenu:SetPoint("CENTER", endCap, onLeft and 15 or -15, 0)
elseif onLeft then
-- Bar art can be disabled, which removes the end caps entirely.
picoMenu:SetPoint("RIGHT", MainActionBar, "LEFT", -4, 0)
else
picoMenu:SetPoint("LEFT", MainActionBar, "RIGHT", 4, 0)
end
picoMenu:GetNormalTexture():SetSize(40, 40)
picoMenu:SetFrameStrata("MEDIUM")
picoMenu:SetFrameLevel(150)
end
local function AnchorToPetBattleBar()
local petBattleMicroButtons = GetPetBattleMicroButtonFrame()
if not petBattleMicroButtons then return end
picoMenu:SetParent(PetBattleFrame)
picoMenu:SetSize(50, 50)
picoMenu:ClearAllPoints()
picoMenu:SetPoint("CENTER", petBattleMicroButtons, 0, 0)
picoMenu:GetNormalTexture():SetSize(50, 50)
picoMenu:SetFrameStrata("MEDIUM")
picoMenu:SetFrameLevel(150)
end
UpdatePicoMenuVisibility = function()
if PicoMenuDB.showPicomenu then
picoMenu:Show()
else
picoMenu:Hide()
end
UpdateQueueEyePosition()
end
-- Queue Status Button: reposition below PicoMenu when Main Menu is hidden
local queueEyeHooked = false
local queueEyeReanchoring = false
local queueEyeOriginalParent = nil
-- Only adopt the eye when the Main Menu is hidden AND our button is actually on screen,
-- otherwise it would be parented to a hidden frame and disappear with it.
local function ShouldAnchorQueueEye()
return not PicoMenuDB.showMicromenu and PicoMenuDB.showPicomenu
end
UpdateQueueEyePosition = function()
local btn = QueueStatusButton or QueueStatusMinimapButton
if not btn then return end
if btn:IsProtected() and InCombatLockdown() then return end
if not queueEyeOriginalParent then
queueEyeOriginalParent = btn:GetParent()
end
queueEyeReanchoring = true
if ShouldAnchorQueueEye() then
btn.ignoreFramePositionManager = true
if btn.SetIgnoreParentScale then btn:SetIgnoreParentScale(true) end
if btn.SetIgnoreParentAlpha then btn:SetIgnoreParentAlpha(true) end
btn:SetParent(picoMenu)
btn:ClearAllPoints()
btn:SetPoint("TOP", picoMenu, "BOTTOM", 0, 4)
btn:SetScale(0.5)
btn:SetFrameStrata(picoMenu:GetFrameStrata())
btn:SetFrameLevel(picoMenu:GetFrameLevel() + 1)
else
btn.ignoreFramePositionManager = nil
if btn.SetIgnoreParentScale then btn:SetIgnoreParentScale(false) end
if btn.SetIgnoreParentAlpha then btn:SetIgnoreParentAlpha(false) end
btn:SetScale(1)
if queueEyeOriginalParent then
btn:SetParent(queueEyeOriginalParent)
end
end
queueEyeReanchoring = false
if not queueEyeHooked then
queueEyeHooked = true
hooksecurefunc(btn, "SetPoint", function(self)
if queueEyeReanchoring then return end
if ShouldAnchorQueueEye() then
queueEyeReanchoring = true
self:ClearAllPoints()
self:SetPoint("TOP", picoMenu, "BOTTOM", 0, 4)
queueEyeReanchoring = false
end
end)
hooksecurefunc(btn, "SetParent", function(self)
if queueEyeReanchoring then return end
if ShouldAnchorQueueEye() then
queueEyeReanchoring = true
self:SetParent(picoMenu)
self:ClearAllPoints()
self:SetPoint("TOP", picoMenu, "BOTTOM", 0, 4)
queueEyeReanchoring = false
end
end)
end
end
picoMenu:SetScript("OnMouseDown", function(self, button)
self:GetNormalTexture():ClearAllPoints()
self:GetNormalTexture():SetPoint("CENTER", 1, -1)
if button == "LeftButton" then
self.menuWasOpenOnMouseDown = picoMenuContextMenu and picoMenuContextMenu:IsShown()
end
GameTooltip:Hide()
end)
picoMenu:SetScript("OnMouseUp", function(self, button)
self:GetNormalTexture():ClearAllPoints()
self:GetNormalTexture():SetPoint("CENTER")
if not self:IsMouseOver() then
self.menuWasOpenOnMouseDown = false
return
end
if button == "LeftButton" then
local justClosed = (GetTime() - lastPicoMenuHideTime) < 0.1
if self.menuWasOpenOnMouseDown or justClosed then
if picoMenuContextMenu and picoMenuContextMenu:IsShown() then
picoMenuContextMenu:Close()
end
elseif picoMenuContextMenu and picoMenuContextMenu:IsShown() then
picoMenuContextMenu:Close()
else
picoMenuContextMenu = OpenPicoMenu(self)
end
else
if not GameMenuFrame:IsVisible() then
ShowUIPanel(GameMenuFrame)
else
HideUIPanel(GameMenuFrame)
end
end
self.menuWasOpenOnMouseDown = false
end)
picoMenu:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:SetText("PicoMenu", 1, 1, 1)
GameTooltip:AddLine("Left-click: Open menu", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
GameTooltip:AddLine("Right-click: Game menu", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
-- Naming the alerts makes the indicator actionable instead of a mystery dot.
if #activeAlerts > 0 then
GameTooltip:AddLine(" ")
for _, label in ipairs(activeAlerts) do
GameTooltip:AddLine("! " .. label, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b)
end
end
GameTooltip:Show()
end)
picoMenu:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
-- Keep the alert dot and ticket icon on the button's outer side, away from the bar.
local function AnchorSideDetails()
local onLeft = IsButtonOnLeft()
alertIndicator:ClearAllPoints()
if onLeft then
alertIndicator:SetPoint("TOPLEFT", picoMenu, "TOPLEFT", -1, 1)
else
alertIndicator:SetPoint("TOPRIGHT", picoMenu, "TOPRIGHT", 1, 1)
end
if HelpOpenWebTicketButton then
HelpOpenWebTicketButton:ClearAllPoints()
if onLeft then
HelpOpenWebTicketButton:SetPoint("RIGHT", picoMenu, "LEFT", 0, 0)
else
HelpOpenWebTicketButton:SetPoint("LEFT", picoMenu, "RIGHT", 0, 0)
end
end
end
ApplyButtonSide = function()
-- During a pet battle the button lives on the pet battle bar; PET_BATTLE_CLOSE
-- re-anchors it to the chosen side afterwards.
if not (C_PetBattles and C_PetBattles.IsInBattle and C_PetBattles.IsInBattle()) then
AnchorToMainBar()
end
AnchorSideDetails()
end
local function Initialize()
-- Move Ticket Icon
if HelpOpenWebTicketButton then
HelpOpenWebTicketButton:SetScale(0.8)
HelpOpenWebTicketButton:SetParent(picoMenu)
end
ApplyButtonSide()
-- Hide MicroButtonAndBagsBar
UpdateMicroMenuVisibility()
UpdatePicoMenuVisibility()
UpdateAlertIndicator()
end
picoMenu:SetScript("OnEvent", function(self, event)
if event == "PLAYER_LOGIN" then
Initialize()
elseif event == "PET_BATTLE_OPENING_START" then
if picoMenuContextMenu and picoMenuContextMenu:IsShown() then
picoMenuContextMenu:Close()
end
AnchorToPetBattleBar()
UpdateMicroMenuVisibility()
elseif event == "PET_BATTLE_CLOSE" then
if picoMenuContextMenu and picoMenuContextMenu:IsShown() then
picoMenuContextMenu:Close()
end
AnchorToMainBar()