forked from pereira-a/MBB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMBB.lua
More file actions
1088 lines (993 loc) · 30.2 KB
/
Copy pathMBB.lua
File metadata and controls
1088 lines (993 loc) · 30.2 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
--[[
Addon to reduces minimap buttons and makes them accessible through a menu!
Author: karlsnyder
Previous Authors: Tunhadil, Fixed by Pericles for patch 2.23 til 4.0, fixed by yossa for patch 4.0.1, updated for 4.2+ by karlsnyder
]]
MBB_Version = "4.0.29";
-- Setup some variable for debugging.
MBB_DebugFlag = 0;
MBB_DebugInfo = {};
MBB_DragFlag = 0;
MBB_ShowTimeout = -1;
MBB_CheckTime = 0;
MBB_IsShown = 0;
MBB_FuBar_MinimapContainer = "FuBarPlugin-MinimapContainer-2.0";
MBB_Buttons = {};
MBB_Exclude = {};
MBB_DefaultOptions = {
["ButtonPos"] = {-18, -100},
["AttachToMinimap"] = 1,
["DetachedButtonPos"] = "CENTER",
["CollapseTimeout"] = 1,
["ExpandDirection"] = 1,
["MaxButtonsPerLine"] = 0,
["AltExpandDirection"] = 4,
["Hidden"] = 0 -- 0 = MBB minimap button visible, 1 = hidden
};
BACKDROP_MAXBUTTONS_OPTIONS = {
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
--tileEdge = true,
tileSize = 8,
edgeSize = 8
};
BACKDROP_TOOLTIP_OPTIONS = {
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileEdge = true,
tileSize = 32,
edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 },
};
-- Buttons to force include
MBB_Include = {
[1] = "BagSync_MinimapButton" -- doesn't have de OnClick script
};
-- Button names to always ignore.
MBB_Ignore = {
[1] = "MiniMapTrackingFrame",
[2] = "MiniMapMeetingStoneFrame",
[3] = "MiniMapMailFrame",
[4] = "MiniMapBattlefieldFrame",
[5] = "MiniMapWorldMapButton",
[6] = "MiniMapPing",
[7] = "MinimapBackdrop",
[8] = "MinimapZoomIn",
[9] = "MinimapZoomOut",
[10] = "BookOfTracksFrame",
[11] = "GatherNote",
[12] = "FishingExtravaganzaMini",
[13] = "MiniNotePOI",
[14] = "RecipeRadarMinimapIcon",
[15] = "FWGMinimapPOI",
[16] = "CartographerNotesPOI",
[17] = "MBB_MinimapButtonFrame",
[18] = "EnhancedFrameMinimapButton",
[19] = "GFW_TrackMenuFrame",
[20] = "GFW_TrackMenuButton",
[21] = "TDial_TrackingIcon",
[22] = "TDial_TrackButton",
[23] = "MiniMapTracking",
[24] = "GatherMatePin",
[25] = "HandyNotesPin",
[26] = "TimeManagerClockButton",
[27] = "GameTimeFrame",
[28] = "DA_Minimap",
[29] = "ElvConfigToggle",
[30] = "MiniMapInstanceDifficulty",
[31] = "MinimapZoneTextButton",
[32] = "GuildInstanceDifficulty",
[33] = "MiniMapVoiceChatFrame",
[34] = "MiniMapRecordingButton",
[35] = "QueueStatusMinimapButton",
[36] = "GatherArchNote",
[37] = "ZGVMarker",
[38] = "QuestPointerPOI", -- QuestPointer
[39] = "poiMinimap", -- QuestPointer
[40] = "MiniMapLFGFrame", -- LFG
[41] = "PremadeFilter_MinimapButton", -- PreMadeFilter
[42] = "GarrisonMinimapButton",
[43] = "TukuiMinimapZone",
[44] = "GPSArrow",
[45] = "HandyNotes_.*Pin", -- Handy Notes plugins support,
[46] = "DugisArrowMinimapPoint1", --Dugi Guides arrow
[47] = "DugisArrowMinimapPoint2", --Dugi Guides arrow
[48] = "DugisArrowMinimapPoint3", --Dugi Guides arrow
[49] = "TTMinimapButton", -- Tom tom / Wow-pro guides
[50] = "QueueStatusButton" -- ElvUI Queue Button
};
MBB_IgnoreSize = {
[1] = "AM_MinimapButton",
[2] = "STC_HealthstoneButton",
[3] = "STC_ShardButton",
[4] = "STC_SoulstoneButton",
[5] = "STC_SpellstoneButton",
[6] = "STC_FirestoneButton"
};
MBB_ExtraSize = {
["GathererMinimapButton"] = function()
GathererMinimapButton.mask:SetHeight(31);
GathererMinimapButton.mask:SetWidth(31);
end
};
function MBB_OnLoad()
-- hooksecurefunc("SecureHandlerClickTemplate_onclick", MBB_SecureOnClick);
-- hooksecurefunc("SecureHandlerClickTemplate_OnEnter", MBB_SecureOnEnter);
-- hooksecurefunc("SecureHandlerClickTemplate_OnLeave", MBB_SecureOnLeave);
if( AceLibrary ) then
if( AceLibrary:HasInstance(MBB_FuBar_MinimapContainer) ) then
AceLibrary(MBB_FuBar_MinimapContainer).oldAddPlugin = AceLibrary(MBB_FuBar_MinimapContainer).AddPlugin;
AceLibrary(MBB_FuBar_MinimapContainer).AddPlugin = function(...)
local plugin = select(2, ...);
local self = select(1, ...);
local value = AceLibrary(MBB_FuBar_MinimapContainer):oldAddPlugin(plugin);
local button = plugin.minimapFrame:GetName();
local frame = _G[button]
if( not frame.oshow ) then
MBB_PrepareButton(button);
--if( not MBB_IsExcluded(button) ) then
if( not MBB_IsInArray(MBB_Exclude, button) ) then
MBB_AddButton(button);
MBB_SetPositions();
end
end
return value;
end
AceLibrary(MBB_FuBar_MinimapContainer).oldRemovePlugin = AceLibrary(MBB_FuBar_MinimapContainer).RemovePlugin;
AceLibrary(MBB_FuBar_MinimapContainer).RemovePlugin = function(...)
local self = select(1, ...);
local plugin = select(2, ...);
local button = plugin.minimapFrame:GetName();
local frame = _G[button]
if( not frame.oshow ) then
MBB_PrepareButton(button);
end
local value = AceLibrary(MBB_FuBar_MinimapContainer):oldRemovePlugin(plugin);
return value;
end
end
end
MBBFrame:RegisterEvent("ADDON_LOADED");
SLASH_MBB1 = "/mbb";
SLASH_MBB2 = "/minimapbuttonbag";
SLASH_MBB3 = "/mmbb";
SlashCmdList["MBB"] = MBB_SlashHandler;
end
function MBB_SlashHandler(cmd)
if( cmd == "buttons" ) then
MBB_Print("MBB Buttons:");
if( #MBB_Buttons > 0 ) then
for i,name in ipairs(MBB_Buttons) do
MBB_Print(" " .. name);
end
else
MBB_Print("No Minimap buttons are currently stored.");
end
elseif( cmd == "hide" ) then
-- Toggle the visibility of the MBB minimap button.
-- Typing "/mbb hide" while it is already hidden restores it.
MBB_ToggleHidden();
elseif( string.sub(cmd, 1, 6) == "debug " ) then
local iStart, iEnd, sFrame = string.find(cmd, "debug (.+)");
local hasClick, hasMouseUp, hasMouseDown, hasEnter, hasLeave = MBB_TestFrame(sFrame);
MBB_Debug("Frame: " .. sFrame);
if( hasClick ) then
MBB_Debug(" has OnClick script");
else
MBB_Debug(" has no OnClick script");
end
if( hasMouseUp ) then
MBB_Debug(" has OnMouseUp script");
else
MBB_Debug(" has no OnMouseUp script");
end
if( hasMouseDown ) then
MBB_Debug(" has OnMouseDown script");
else
MBB_Debug(" has no OnMouseDown script");
end
if( hasEnter ) then
MBB_Debug(" has OnEnter script");
else
MBB_Debug(" has no OnEnter script");
end
if( hasLeave ) then
MBB_Debug(" has OnLeave script");
else
MBB_Debug(" has no OnLeave script");
end
elseif( cmd == "reset position" ) then
-- Reset the main button position.
MBB_ResetButtonPosition()
elseif( cmd == "reset all" ) then
MBB_Options = MBB_DefaultOptions;
-- Reset the main button position.
MBB_ResetButtonPosition()
for i=1,table.maxn(MBB_Exclude) do
MBB_AddButton(MBB_Exclude[i]);
end
MBB_SetPositions();
-- "reset all" restores every default, so make sure the button is shown again.
MBB_Options.Hidden = 0;
MBB_ApplyHidden();
elseif( cmd == "errors" ) then
if( table.maxn(MBB_DebugInfo) > 0 ) then
for name, arr in pairs(MBB_DebugInfo) do
MBB_Print(name);
for _, error in pairs(arr) do
MBB_Print(" " .. error);
end
end
else
MBB_Print(MBB_NOERRORS);
end
else
MBB_Print("MBB v" .. MBB_Version .. ":");
MBB_Print(MBB_HELP1);
MBB_Print(MBB_HELP2);
MBB_Print(MBB_HELP3);
MBB_Print(MBB_HELP4);
-- Use the localized help string if present, otherwise fall back to English.
MBB_Print(MBB_HELP5 or " |c00ffffffhide|r: Toggles the MBB minimap button (hide / show)");
end
end
-- Apply the current hidden state to the MBB minimap button.
--
-- IMPORTANT: we do NOT call MBB_MinimapButtonFrame:Hide(). Its OnUpdate script
-- (defined in MBB.xml) is what periodically scans the minimap and collects the
-- other addon buttons into the bag, and OnUpdate does not fire on a hidden
-- frame. So hiding the frame silently stops button collection. Instead we make
-- the button invisible and non-interactive but keep it shown, which keeps the
-- OnUpdate scan running.
function MBB_ApplyHidden()
if( MBB_Options.Hidden == 1 ) then
MBB_MinimapButtonFrame:SetAlpha(0);
MBB_MinimapButtonFrame:EnableMouse(false);
else
MBB_MinimapButtonFrame:SetAlpha(1);
MBB_MinimapButtonFrame:EnableMouse(true);
end
end
-- Toggle the MBB minimap button between hidden and shown, persisting the
-- choice in MBB_Options (a SavedVariablePerCharacter declared in MBB.toc).
function MBB_ToggleHidden()
if( MBB_Options.Hidden == 1 ) then
MBB_Options.Hidden = 0;
MBB_Print("MBB minimap button shown.");
else
MBB_Options.Hidden = 1;
MBB_Print("MBB minimap button hidden. Type /mbb hide again to restore it.");
end
MBB_ApplyHidden();
end
function MBB_TestFrame(name)
local hasClick = false;
local hasMouseUp = false;
local hasMouseDown = false;
local hasEnter = false;
local hasLeave = false;
local testframe = _G[name]
if( testframe ) then
if( not testframe.HasScript ) then
if( testframe:GetName() ) then
if( not MBB_DebugInfo[testframe:GetName()] ) then
MBB_DebugInfo[testframe:GetName()] = {};
end
if( not MBB_IsInArray(MBB_DebugInfo[testframe:GetName()], "No HasScript") ) then
table.insert(MBB_DebugInfo[testframe:GetName()], "No HasScript");
end
end
else
if( testframe:HasScript("OnClick") ) then
local test = testframe:GetScript("OnClick");
if( test ) then
hasClick = true;
end
end
if( testframe:HasScript("OnMouseUp") ) then
local test = testframe:GetScript("OnMouseUp");
if( test ) then
hasMouseUp = true;
end
end
if( testframe:HasScript("OnMouseDown") ) then
local test = testframe:GetScript("OnMouseDown");
if( test ) then
hasMouseDown = true;
end
end
if( testframe:HasScript("OnEnter") ) then
local test = testframe:GetScript("OnEnter");
if( test ) then
hasEnter = true;
end
end
if( testframe:HasScript("OnLeave") ) then
local test = testframe:GetScript("OnLeave");
if( test ) then
hasLeave = true;
end
end
end
end
return hasClick, hasMouseUp, hasMouseDown, hasEnter, hasLeave;
end
function MBB_OnEvent(self, event, ...)
if( MBB_Options ) then
for opt,val in pairs(MBB_DefaultOptions) do
if( not MBB_Options[opt] ) then
MBB_Debug(opt .. " option set to default: " .. tostring(val));
MBB_Options[opt] = val;
else
MBB_Debug(opt .. " option exists: " .. tostring(MBB_Options[opt]));
end
end
else
MBB_Options = MBB_DefaultOptions;
end
MBB_SetButtonPosition();
-- Restore the saved hidden state after the button position is set.
MBB_ApplyHidden();
end
function MBB_PrepareButton(name)
local buttonframe = _G[name]
local hasHeader;
if( buttonframe.GetAttribute ) then
hasHeader = buttonframe:GetAttribute("anchorchild");
if( hasHeader and hasHeader == "$parent" and not buttonframe.hasParentFrame ) then
MBB_Debug("buttonframe has header parent");
buttonframe.hasParentFrame = true;
end
else
if( buttonframe:GetName() ) then
if( not MBB_DebugInfo[buttonframe:GetName()] ) then
MBB_DebugInfo[buttonframe:GetName()] = {};
end
if( not MBB_IsInArray(MBB_DebugInfo[buttonframe:GetName()], "No GetAttribute") ) then
table.insert(MBB_DebugInfo[buttonframe:GetName()], "No GetAttribute");
end
end
end
if( buttonframe ) then
if( buttonframe.RegisterForClicks ) then
buttonframe:RegisterForClicks("LeftButtonDown","RightButtonDown");
end
buttonframe.isvisible = buttonframe:IsVisible();
if( buttonframe.hasParentFrame ) then
local parent = buttonframe:GetParent();
parent.MBBChild = buttonframe:GetName();
buttonframe.parentisvisible = parent:IsVisible();
parent.oshow = parent.Show;
parent.Show = function(...)
local self = select(1, ...);
local parent = select(1, ...);
MBB_Debug("Parent Frame: " .. parent:GetName());
local child = _G[parent.MBBChild]
MBB_Debug("Child Frame: " .. child:GetName());
child.parentisvisible = true;
MBB_Debug("Showing frame: " .. parent:GetName());
if( not MBB_IsInArray(MBB_Exclude, child:GetName()) ) then
MBB_SetPositions();
end
if( MBB_IsInArray(MBB_Exclude, child:GetName()) or MBB_IsShown == 1 ) then
parent.oshow(select(1, ...));
--child.oshow(child);
end
end
parent.ohide = parent.Hide;
parent.Hide = function(...)
local parent = select(1, ...);
MBB_Debug("Parent Frame: " .. parent:GetName());
local child = _G[parent.MBBChild]
MBB_Debug("Child Frame: " .. child:GetName());
child.parentisvisible = false;
MBB_Debug("Hiding frame: " .. parent:GetName());
parent.ohide(select(1, ...));
if( not MBB_IsInArray(MBB_Exclude, child:GetName()) ) then
MBB_SetPositions();
end
end
end
buttonframe.oshow = buttonframe.Show;
buttonframe.Show = function(...)
local innerframe = select(1, ...);
innerframe.isvisible = true;
MBB_Debug("Showing innerframe: " .. innerframe:GetName());
if( not MBB_IsInArray(MBB_Exclude, innerframe:GetName()) ) then
MBB_SetPositions();
end
if( MBB_IsInArray(MBB_Exclude, innerframe:GetName()) or MBB_IsShown == 1 ) then
--[[if( innerframe.hasParentFrame ) then
local parent = innerframe:GetParent();
parent.oshow(parent);
else]]
innerframe.oshow(select(1, ...));
--end
end
end
buttonframe.ohide = buttonframe.Hide;
buttonframe.Hide = function(...)
local innerframe = select(1, ...);
MBB_Debug("Hiding innerframe: " .. innerframe:GetName());
if( innerframe ~= buttonframe ) then
innerframe.isvisible = false;
innerframe.ohide(innerframe);
end
if( not MBB_IsInArray(MBB_Exclude, innerframe:GetName()) ) then
MBB_SetPositions();
end
end
if( buttonframe:HasScript("OnClick") and not hasHeader ) then
buttonframe.oclick = buttonframe:GetScript("OnClick");
buttonframe:SetScript("OnClick", function(...)
local self = select(1, ...);
local arg1 = select(2, ...);
if( arg1 and arg1 == "RightButton" and IsControlKeyDown() ) then
local name = self:GetName();
if( MBB_IsInArray(MBB_Exclude, name) ) then
MBB_AddButton(name);
else
MBB_RestoreButton(name);
end
MBB_SetPositions();
elseif( self.oclick ) then
self.oclick(select(1, ...));
end
end);
elseif( buttonframe:HasScript("OnMouseUp") and not hasHeader ) then
buttonframe.omouseup = buttonframe:GetScript("OnMouseUp");
buttonframe:SetScript("OnMouseUp", function(...)
local self = select(1, ...);
local arg1 = select(2, ...);
if( arg1 and arg1 == "RightButton" and IsControlKeyDown() ) then
local name = self:GetName();
if( MBB_IsInArray(MBB_Exclude, name) ) then
MBB_AddButton(name);
else
MBB_RestoreButton(name);
end
MBB_SetPositions();
elseif( self.omouseup ) then
self.omouseup(select(1, ...));
end
end);
elseif( buttonframe:HasScript("OnMouseDown") and not hasHeader ) then
buttonframe.omousedown = buttonframe:GetScript("OnMouseDown");
buttonframe:SetScript("OnMouseDown", function(...)
local self = select(1, ...);
local arg1 = select(2, ...);
if( arg1 and arg1 == "RightButton" and IsControlKeyDown() ) then
local name = self:GetName();
if( MBB_IsInArray(MBB_Exclude, name) ) then
MBB_AddButton(name);
else
MBB_RestoreButton(name);
end
MBB_SetPositions();
elseif( self.omousedown ) then
self.omousedown(select(1, ...));
end
end);
end
if( buttonframe:HasScript("OnEnter") and not hasHeader ) then
buttonframe.oenter = buttonframe:GetScript("OnEnter");
buttonframe:SetScript("OnEnter", function(...)
local self = select(1, ...);
if( IsControlKeyDown() ) then
local button;
if( MBB_IsInArray(MBB_Exclude, self:GetName()) ) then
button = _G["MBB_ButtonAdd"]
else
button = _G["MBB_ButtonRemove"]
end
button.MBBButtonName = self:GetName();
button:ClearAllPoints();
button:SetPoint("BOTTOM", self, "TOP", 0, 0);
button:Show();
end
if( not MBB_IsInArray(MBB_Exclude, self:GetName()) ) then
MBB_ShowTimeout = -1;
end
if( self.oenter ) then
self.oenter(select(1, ...));
end
end);
end
if( buttonframe:HasScript("OnLeave") and not hasHeader ) then
buttonframe.oleave = buttonframe:GetScript("OnLeave");
buttonframe:SetScript("OnLeave", function(...)
local self = select(1, ...);
if( not MBB_IsInArray(MBB_Exclude, self:GetName()) ) then
MBB_ShowTimeout = 0;
end
if( self.oleave ) then
self.oleave(select(1, ...));
end
end);
end
end
end
function MBB_AddButton(name)
local child = _G[name]
child.opoint = {child:GetPoint()};
if( not child.opoint[1] ) then
child.opoint = {"TOP", Minimap, "BOTTOM", 0, 0};
end
child.osize = {child:GetHeight(),child:GetWidth()};
child.oclearallpoints = child.ClearAllPoints;
child.ClearAllPoints = function() end;
child.osetpoint = child.SetPoint;
child.SetPoint = function() end;
if( MBB_IsShown == 0 ) then
if( child.hasParentFrame ) then
local parent = child:GetParent();
child.oshow(child);
parent.ohide(parent);
else
-- TODO: Not sure why ohide would be nil but it is. We'll fix this later.
if(child.ohide) then
child.ohide(child);
end
end
end
table.insert(MBB_Buttons, name);
local i = MBB_IsInArray(MBB_Exclude, name);
if( i ) then
table.remove(MBB_Exclude, i);
end
end
function MBB_RestoreButton(name)
local button = _G[name]
button.oclearallpoints(button);
button.osetpoint(button, button.opoint[1], button.opoint[2], button.opoint[3], button.opoint[4], button.opoint[5]);
button:SetHeight(button.osize[1]);
button:SetWidth(button.osize[1]);
button.ClearAllPoints = button.oclearallpoints;
button.SetPoint = button.osetpoint;
MBB_Debug("EVENT Restoring Button");
if( button.hasParentFrame ) then
local parent = button:GetParent();
parent.oshow(parent);
else
button.oshow(button);
end
table.insert(MBB_Exclude, name);
local i = MBB_IsInArray(MBB_Buttons, button:GetName());
if( i ) then
table.remove(MBB_Buttons, i);
end
end
function MBB_SetPositions()
local directions = {
[1] = {"RIGHT", "LEFT"},
[2] = {"BOTTOM", "TOP"},
[3] = {"LEFT", "RIGHT"},
[4] = {"TOP", "BOTTOM"}
};
local offsets = {
[1] = {-5, 0},
[2] = {0, 5},
[3] = {5, 0},
[4] = {0, -5}
};
local pos = {0, 0};
local parentid = 0;
local firstid = 1;
local count = 1;
for i,name in ipairs(MBB_Buttons) do
local positionframe = _G[name]
if( not positionframe.hasParentFrame ) then
positionframe.parentisvisible = true;
end
if( positionframe.isvisible and positionframe.parentisvisible ) then
local parent;
if( parentid==0 ) then
parent = MBB_MinimapButtonFrame;
else
parent = _G[MBB_Buttons[parentid]]
end
if( not MBB_IsInArray(MBB_IgnoreSize, name) ) then
if( MBB_ExtraSize[name] ) then
local func = MBB_ExtraSize[name];
func();
else
positionframe:SetHeight(31); -- 33
positionframe:SetWidth(31);
end
end
local direction;
if( MBB_Options.MaxButtonsPerLine > 0 and count > MBB_Options.MaxButtonsPerLine ) then
parent = _G[MBB_Buttons[firstid]]
direction = {directions[MBB_Options.AltExpandDirection][1], directions[MBB_Options.AltExpandDirection][2]};
if( MBB_ExtraSize[name] or MBB_IsInArray(MBB_IgnoreSize, name) or MBB_ExtraSize[parent:GetName()] or MBB_IsInArray(MBB_IgnoreSize, parent:GetName()) ) then
pos = offsets[MBB_Options.AltExpandDirection];
else
pos = {0, 0};
end
count = 2;
firstid = i;
else
direction = {directions[MBB_Options.ExpandDirection][1], directions[MBB_Options.ExpandDirection][2]};
if( MBB_ExtraSize[name] or MBB_IsInArray(MBB_IgnoreSize, name) or MBB_ExtraSize[parent:GetName()] or MBB_IsInArray(MBB_IgnoreSize, parent:GetName()) ) then
pos = offsets[MBB_Options.ExpandDirection];
else
pos = {0, 0};
end
count = count + 1;
end
positionframe.oclearallpoints(positionframe);
positionframe.osetpoint(positionframe, direction[1], parent, direction[2], pos[1], pos[2]);
parentid = i;
end
end
end
function MBB_OnClick(arg1)
if( arg1 and arg1 == "RightButton" and IsControlKeyDown() ) then
if( MBB_Options.AttachToMinimap == 1 ) then
--[[local xpos,ypos = GetCursorPosition();
local scale = GetCVar("uiScale");]]
MBB_Options.AttachToMinimap = 0;
MBB_Options.ButtonPos = {0, 0}; --{(xpos/scale)-10, (ypos/scale)-10};
MBB_Options.DetachedButtonPos = MBB_DefaultOptions.DetachedButtonPos;
else
MBB_Options.AttachToMinimap = 1;
MBB_Options.ButtonPos = MBB_DefaultOptions.ButtonPos;
end
MBB_SetButtonPosition();
elseif( arg1 and arg1 == "RightButton" ) then
MBB_OptionsFrame:Show();
else
if( MBB_IsShown == 1 ) then
MBB_HideButtons();
else
MBB_Debug("EVENT OnClick");
for i,name in ipairs(MBB_Buttons) do
local clickframe = _G[name]
if( not clickframe.hasParentFrame ) then
clickframe.parentisvisible = true;
end
if( clickframe.isvisible and clickframe.parentisvisible ) then
if( clickframe.hasParentFrame and clickframe.hasParentFrame ) then
local parent = clickframe:GetParent();
if( parent.oshow ) then
parent.oshow(parent);
else
if( parent:GetName() ) then
if( not MBB_DebugInfo[parent:GetName()] ) then
MBB_DebugInfo[parent:GetName()] = {};
end
if( not MBB_IsInArray(MBB_DebugInfo[parent:GetName()], "No oshow") ) then
table.insert(MBB_DebugInfo[parent:GetName()], "No oshow");
end
end
end
else
clickframe.oshow(clickframe);
end
end
end
MBB_IsShown = 1;
--MBB_ShowTimeout = 0;
end
end
end
function MBB_HideButtons()
MBB_ShowTimeout = -1;
for i,name in ipairs(MBB_Buttons) do
local buttonhideframe = _G[name]
if( buttonhideframe.hasParentFrame ) then
local parent = buttonhideframe:GetParent();
if( parent.ohide ) then
parent.ohide(parent);
else
if( parent:GetName() ) then
if( not MBB_DebugInfo[parent:GetName()] ) then
MBB_DebugInfo[parent:GetName()] = {};
end
if( not MBB_IsInArray(MBB_DebugInfo[parent:GetName()], "No ohide") ) then
table.insert(MBB_DebugInfo[parent:GetName()], "No ohide");
end
end
buttonhideframe.ohide(buttonhideframe);
end
else
buttonhideframe.ohide(buttonhideframe);
end
end
MBB_IsShown = 0;
end
function MBB_IsKnownButton(name, opt)
if( not opt ) then
opt = 1;
end
if( opt <= 1 ) then
for _, button in ipairs(MBB_Buttons) do
if( button == name ) then
return true;
end
end
end
if( opt <= 2 ) then
for _, button in ipairs(MBB_Exclude) do
if( button == name ) then
return true;
end
end
end
if( opt <= 3 ) then
for _, button in ipairs(MBB_Ignore) do
if( string.find(name, button) ) then
return true;
end
end
end
return false;
end
function MBB_isButtonToBeIncluded(name)
for _, button in ipairs(MBB_Include) do
if( string.find(name, button) ) then
return true;
end
end
end
function MBB_OnUpdate(elapsed)
if( MBB_CheckTime >= 3 ) then
MBB_CheckTime = 0;
local children = {Minimap:GetChildren()};
for _, child in ipairs(children) do
if( child:GetName() and not child.oshow and ((child:HasScript("OnClick") and not MBB_IsKnownButton(child:GetName(), 3)) or (MBB_isButtonToBeIncluded(child:GetName()))) ) then
MBB_PrepareButton(child:GetName());
if( not MBB_IsInArray(MBB_Exclude, child:GetName()) ) then
MBB_AddButton(child:GetName());
MBB_SetPositions();
end
end
end
else
MBB_CheckTime = MBB_CheckTime + elapsed;
end
if( MBB_DragFlag == 1 and MBB_Options.AttachToMinimap == 1 ) then
local xpos,ypos = GetCursorPosition();
local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom();
xpos = xmin-xpos/Minimap:GetEffectiveScale()+70;
ypos = ypos/Minimap:GetEffectiveScale()-ymin-70;
local angle = math.deg(math.atan2(ypos,xpos));
MBB_MinimapButtonFrame:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 83-(cos(angle)*99), -83+(sin(angle)*99));
end
if( MBB_Options.CollapseTimeout and MBB_Options.CollapseTimeout ~= 0 ) then
if( MBB_ShowTimeout >= MBB_Options.CollapseTimeout and MBB_IsShown == 1 ) then
MBB_HideButtons();
end
if( MBB_ShowTimeout ~= -1 ) then
MBB_ShowTimeout = MBB_ShowTimeout + elapsed;
end
end
end
function MBB_ResetButtonPosition()
MBB_Options.AttachToMinimap = MBB_DefaultOptions.AttachToMinimap;
MBB_Options.ButtonPos = MBB_DefaultOptions.ButtonPos;
MBB_Options.DetachedButtonPos = MBB_DefaultOptions.DetachedButtonPos;
MBB_SetButtonPosition();
end
function MBB_SetButtonPosition()
if( MBB_Options.AttachToMinimap == 1 ) then
MBB_MinimapButtonFrame:ClearAllPoints();
MBB_MinimapButtonFrame:SetPoint("TOPLEFT", Minimap, "TOPLEFT", MBB_Options.ButtonPos[1], MBB_Options.ButtonPos[2]);
else
MBB_MinimapButtonFrame:ClearAllPoints();
MBB_MinimapButtonFrame:SetPoint(MBB_Options.DetachedButtonPos, UIParent, MBB_Options.DetachedButtonPos, MBB_Options.ButtonPos[1], MBB_Options.ButtonPos[2]);
end
end
function MBB_RadioButton_OnClick(id, alt)
local substring;
if( alt ) then
substring = "Alt";
else
substring = "";
end
local buttons = {
[1] = "Left",
[2] = "Top",
[3] = "Right",
[4] = "Bottom"
};
for i,name in ipairs(buttons) do
if( i == id ) then
_G["MBB_OptionsFrame_" .. name .. substring .. "Radio"]:SetChecked(true)
else
_G["MBB_OptionsFrame_" .. name .. substring .. "Radio"]:SetChecked(nil);
end
end
end
function MBB_UpdateAltRadioButtons()
local buttons = {
[1] = "Left",
[2] = "Top",
[3] = "Right",
[4] = "Bottom"
};
local exchecked = 1;
for i,name in pairs(buttons) do
if( _G["MBB_OptionsFrame_" .. name .. "Radio"]:GetChecked() ) then
exchecked = i;
break;
end
end
local checked = false;
local textbox = _G["MBB_OptionsFrame_MaxButtonsTextBox"]
for i,name in pairs(buttons) do
local radio = _G["MBB_OptionsFrame_" .. name .. "AltRadio"]
local label = _G["MBB_OptionsFrame_" .. name .. "AltRadioLabel"]
if( textbox:GetText() == "" or tonumber(textbox:GetText()) == 0 ) then
radio:Disable();
radio:SetChecked(nil);
label:SetTextColor(0.5, 0.5, 0.5);
else
if( exchecked % 2 == i % 2 ) then
if( radio:GetChecked() ) then
checked = true;
if( i == 4 ) then
_G["MBB_OptionsFrame_LeftAltRadio"]:SetChecked(true);
else
_G["MBB_OptionsFrame_" .. buttons[i+1] .. "AltRadio"]:SetChecked(true);
end
end
radio:Disable();
radio:SetChecked(nil);
label:SetTextColor(0.5, 0.5, 0.5);
else
if( radio:GetChecked() ) then
checked = true;
end
radio:Enable();
label:SetTextColor(1, 1, 1);
end
end
end
if( not checked and tonumber(textbox:GetText()) ~= 0 and textbox:GetText() ~= "" ) then
if( exchecked % 2 == 1 ) then
_G["MBB_OptionsFrame_TopAltRadio"]:SetChecked(true);
else
_G["MBB_OptionsFrame_LeftAltRadio"]:SetChecked(true);
end
end
end
function MBB_Debug(msg)
if (MBB_DebugFlag == 1) then
MBB_Print("MBB Debug : " .. tostring(msg));
end
end
function MBB_Test()
local children = {Minimap:GetChildren()};
for _, child in ipairs(children) do
if( child:GetName() and not MBB_IsKnownButton(child:GetName()) ) then
ChatFrame1:AddMessage(child:GetName());
end
end
end
function MBB_IsInArray(array, needle)
if(type(array) == "table") then
--MBB_Debug("Looking for " .. tostring(needle) .. " in " .. tostring(array));
for i, element in pairs(array) do
if(type(element) == type(needle) and element == needle) then
return i;
end
end
end
return nil;
end
function MBB_SecureOnClick(self, button, down)
local name = self:GetName();
if(name) then -- trap to check for nils
MBB_Debug("Name: " .. name);
MBB_Debug("Button: " .. button);
if( MBB_IsInArray(MBB_Buttons, name) ) then
if( button == "RightButton" and IsControlKeyDown() ) then
MBB_Debug("Restoring button: " .. name);
MBB_RestoreButton(name);
MBB_SetPositions();
end
elseif( MBB_IsInArray(MBB_Exclude, name) ) then
if( button == "RightButton" and IsControlKeyDown() ) then
MBB_Debug("Adding button: " .. name);
MBB_AddButton(name);
MBB_SetPositions();
end
end
end
end
function MBB_SecureOnEnter(self)
local name = self:GetName();
if(name) then -- trap to check for nils
MBB_Debug("Name: " .. name);
if( MBB_IsInArray(MBB_Buttons, name) ) then
if( IsControlKeyDown() ) then
local button = _G["MBB_ButtonRemove"]
button.MBBButtonName = name;
button:ClearAllPoints();
button:SetPoint("BOTTOM", self, "TOP", 0, 0);
button:Show();
end
MBB_ShowTimeout = -1;
elseif( MBB_IsInArray(MBB_Exclude, name) ) then
if( IsControlKeyDown() ) then