-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBlizzMove.lua
1535 lines (1270 loc) · 61 KB
/
BlizzMove.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- up-value the globals
local _G = getfenv(0);
local InCombatLockdown = _G.InCombatLockdown;
local LibStub = _G.LibStub;
local pairs = _G.pairs;
local type = _G.type;
local IsAddOnLoaded = _G.IsAddOnLoaded or _G.C_AddOns.IsAddOnLoaded;
local next = _G.next;
local string__gmatch = _G.string.gmatch;
local tonumber = _G.tonumber;
local string__format = _G.string.format;
local IsAltKeyDown = _G.IsAltKeyDown;
local PlaySound = _G.PlaySound;
local SOUNDKIT = _G.SOUNDKIT;
local IsControlKeyDown = _G.IsControlKeyDown;
local IsShiftKeyDown = _G.IsShiftKeyDown;
local UpdateUIPanelPositions = _G.UpdateUIPanelPositions;
local MouseIsOver = _G.MouseIsOver;
local xpcall = _G.xpcall;
local CallErrorHandler = _G.CallErrorHandler;
local Settings_OpenToCategory = _G.Settings and _G.Settings.OpenToCategory or _G.InterfaceOptionsFrame_OpenToCategory;
local strsplit = _G.strsplit;
local LoadAddOn = _G.LoadAddOn or _G.C_AddOns.LoadAddOn;
local EnableAddOn = _G.EnableAddOn or _G.C_AddOns.EnableAddOn;
local GetBuildInfo = _G.GetBuildInfo;
local tinsert = _G.tinsert;
local unpack = _G.unpack;
local wipe = _G.wipe;
local GetScreenWidth = _G.GetScreenWidth;
local GetScreenHeight = _G.GetScreenHeight;
local CreateFrame = _G.CreateFrame;
local abs = _G.abs;
local GetMouseFoci = _G.GetMouseFoci or function() return { GetMouseFocus() }; end;
local name = ... or "BlizzMove";
--- @class BlizzMove: AceAddon,AceConsole-3.0,AceEvent-3.0,AceHook-3.0
local BlizzMove = LibStub("AceAddon-3.0"):NewAddon(name, "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0");
if not BlizzMove then return; end
--- @type BlizzMoveAPI_AddonFrameTable
BlizzMove.Frames = {};
--- @type table<Frame, BlizzMove_FrameData>
BlizzMove.FrameData = {};
--- @type table<string, table<string, Frame>> # [addOnName][frameName] = frame
BlizzMove.FrameRegistry = {};
--- @type BlizzMove_CombatLockdownQueueItem[]
BlizzMove.CombatLockdownQueue = {};
--- @type table<Frame, true>
BlizzMove.CurrentMouseoverFrames = {};
local MAX_SCALE = 2.5;
local MIN_SCALE = 0.3; -- steps are in 0.1 increments, and we'd like to stay above 0.25
------------------------------------------------------------------------------------------------------
--- Debug Functions
------------------------------------------------------------------------------------------------------
do
function BlizzMove:DebugPrint(...)
if self.DB and self.DB.DebugPrints then self:Print("Debug message:\n", ...); end
end
end
------------------------------------------------------------------------------------------------------
--- Frame Registration and Enabling/Disabling Functions
------------------------------------------------------------------------------------------------------
local IsFrame;
do
function IsFrame(value)
return type(value) == "table" and type(value.IsObjectType) == "function" and value:IsObjectType("Frame");
end
function BlizzMove:ValidateFrame(frameName, frameData, isSubFrame)
return self:ValidateFrameName(frameName) and self:ValidateFrameData(frameName, frameData, isSubFrame);
end
function BlizzMove:ValidateFrameName(frameName)
return #frameName > 0;
end
function BlizzMove:ValidateFrameData(frameName, frameData, isSubFrame)
local validationError;
for key, value in pairs(frameData) do
if key == "SubFrames" then
if type(value) ~= "table" then validationError = true; end
for subFrameName, subFrameData in pairs(value) do
if not self:ValidateFrame(subFrameName, subFrameData, true) then validationError = true; break; end
end
elseif (
key == "MinVersion"
or key == "MaxVersion"
or key == "MinBuild"
or key == "MaxBuild"
) then
if (type(value) ~= "number" or value < 0) then validationError = true; end
elseif (
key == "BuildRanges"
or key == "VersionRanges"
) then
if (type(value) ~= "table") then
validationError = true;
else
for _, range in pairs(value) do
if (
type(range) ~= "table"
or (range.Min and (type(range.Min) ~= "number" or range.Min < 0))
or (range.Max and (type(range.Max) ~= "number" or range.Max < 0))
or (range.Max and range.Min and range.Max < range.Min)
or (not range.Max and not range.Min)
) then
validationError = true;
break;
end
end
end
elseif (
key == "Detachable"
or key == "ManuallyScaleWithParent"
or key == "ForceParentage"
) then
if (type(value) ~= "boolean" or (value == true and not isSubFrame)) then validationError = true; end
elseif (
key == "IgnoreMouse"
or key == "IgnoreMouseWheel"
or key == "NonDraggable"
or key == "IgnoreClamping"
or key == "DefaultDisabled"
or key == "SilenceCompatabilityWarnings"
or key == "IgnoreSavedPositionWhenMaximized"
) then
if type(value) ~= "boolean" then validationError = true; end
elseif key == "FrameReference" then
if not IsFrame(value) then validationError = true; end
else
self:Print("Ignoring unsupported key supplied in frameData, for frame:", frameName, "; key:", key);
end
if (validationError) then
self:Print('Validation error, frame:', frameName, '; key:', key, '; value:', value);
return false;
end
end
return true;
end
function BlizzMove:RegisterFrame(addOnName, frameName, frameData, skipConfigUpdate)
if not addOnName then addOnName = self.name; end
local copiedData = self:CopyTable(frameData);
self.Frames[addOnName] = self.Frames[addOnName] or {};
self.Frames[addOnName][frameName] = copiedData;
if (
not self:IsFrameDisabled(addOnName, frameName)
and IsAddOnLoaded(addOnName)
and self.initialized
) then
self:ProcessFrame(addOnName, frameName, copiedData);
end
if self.initialized and not skipConfigUpdate then
self.Config:RegisterOptions();
end
end
function BlizzMove:UnregisterFrame(addOnName, frameName, permanent)
if not addOnName then addOnName = self.name; end
if self:IsFrameDisabled(addOnName, frameName) then return; end
if not self.Frames[addOnName][frameName] then return false; end
if permanent then
self.DB.disabledFrames = self.DB.disabledFrames or {};
self.DB.disabledFrames[addOnName] = self.DB.disabledFrames[addOnName] or {};
self.DB.disabledFrames[addOnName][frameName] = true;
end
if IsAddOnLoaded(addOnName) then
self:UnprocessFrame(addOnName, frameName);
end
return true;
end
function BlizzMove:GetRegisteredAddOns()
local returnTable = {};
for addOnName, _ in pairs(self.Frames) do
if next(self:GetRegisteredFrames(addOnName)) ~= nil then
returnTable[addOnName] = addOnName;
end
end
return returnTable;
end
function BlizzMove:GetRegisteredFrames(addOnName)
if not addOnName then addOnName = self.name; end
local returnTable = {};
if not self.Frames[addOnName] then return returnTable; end
for frameName, frameData in pairs(self.Frames[addOnName]) do
if self:MatchesCurrentBuild(frameData) then
returnTable[frameName] = frameName;
end
end
return returnTable;
end
function BlizzMove:DisableFrame(addOnName, frameName)
if not addOnName then addOnName = self.name; end
if self:IsFrameDisabled(addOnName, frameName) then return; end
BlizzMove:UnregisterFrame(addOnName, frameName, true);
end
function BlizzMove:EnableFrame(addOnName, frameName)
if (not addOnName) then addOnName = self.name; end
if (not self:IsFrameDisabled(addOnName, frameName)) then return; end
if (self:IsFrameDefaultDisabled(addOnName, frameName)) then
self.DB.enabledFrames = self.DB.enabledFrames or {};
self.DB.enabledFrames[addOnName] = self.DB.enabledFrames[addOnName] or {};
self.DB.enabledFrames[addOnName][frameName] = true;
end
if (self:IsFrameDisabled(addOnName, frameName)) then
self.DB.disabledFrames[addOnName][frameName] = nil;
end
local frame = self:GetFrameFromName(addOnName, frameName)
local frameData;
if (frame and self.FrameData[frame]) then
frameData = self.FrameData[frame];
elseif (self.Frames[addOnName] and self.Frames[addOnName][frameName]) then
frameData = self.Frames[addOnName][frameName];
end
if (frameData) then
self:ProcessFrame(addOnName, frameName, frameData, (frameData.storage and frameData.storage.frameParent) or nil);
end
end
function BlizzMove:IsFrameDisabled(addOnName, frameName)
if (not addOnName) then addOnName = self.name; end
if (self.DB and self.DB.disabledFrames and self.DB.disabledFrames[addOnName] and self.DB.disabledFrames[addOnName][frameName]) then
return true;
end
if (
self:IsFrameDefaultDisabled(addOnName, frameName)
and not (self.DB and self.DB.enabledFrames and self.DB.enabledFrames[addOnName] and self.DB.enabledFrames[addOnName][frameName])
) then
return true;
end
return false;
end
function BlizzMove:IsFrameDefaultDisabled(addOnName, frameName)
if (not addOnName) then addOnName = self.name; end
if (self.Frames[addOnName] and self.Frames[addOnName][frameName] and self.Frames[addOnName][frameName].DefaultDisabled) then
return true;
end
return false;
end
end
------------------------------------------------------------------------------------------------------
--- FrameData and storage Functions
------------------------------------------------------------------------------------------------------
do
function BlizzMove:GetFrameFromName(addOnName, frameName)
if(self.FrameRegistry[addOnName] and self.FrameRegistry[addOnName][frameName]) then
return self.FrameRegistry[addOnName][frameName];
end
local frameTable = _G;
for keyName in string__gmatch(frameName, "([^.]+)") do
if not frameTable[keyName] then return nil; end
frameTable = frameTable[keyName];
end
return frameTable;
end
function BlizzMove:GetFrameName(frame)
return
frame
and self.FrameData
and self.FrameData[frame]
and self.FrameData[frame].storage
and self.FrameData[frame].storage.frameName
end
function BlizzMove:ResetScaleStorage()
wipe(self.DB.scales);
end
function BlizzMove:ResetPointStorage()
wipe(self.DB.points);
end
function BlizzMove:SetupPointStorage(frame)
local frameName = self:GetFrameName(frame);
if not frameName then return false; end
if self.DB.savePosStrategy ~= "permanent" then
if not self.FrameData[frame].storage.points then
self.FrameData[frame].storage.points = {};
end
return true;
end
if self.FrameData[frame].storage.points and self.FrameData[frame].storage.points == self.DB.points[frameName] then return true; end
if self.DB.points[frameName] == nil then
self.DB.points[frameName] = {};
end
self.FrameData[frame].storage.points = self.DB.points[frameName];
if (self.FrameData[frame].storage.points.detachPoints) then
local relativeFrameName = self.FrameData[frame].storage.points.detachPoints[1].relativeFrameName;
if (relativeFrameName and self:GetFrameFromName(nil, relativeFrameName)) then
self.FrameData[frame].storage.detached = true;
self.FrameData[frame].storage.points.detachPoints[1].relativeFrame = self:GetFrameFromName(nil, relativeFrameName);
else
wipe(self.FrameData[frame].storage.points);
end
end
return true;
end
local _, buildNumber, _, gameVersion = GetBuildInfo();
BlizzMove.gameBuild = tonumber(buildNumber);
BlizzMove.gameVersion = tonumber(gameVersion);
local function checkRanges(ranges, needle)
for _, range in ipairs(ranges) do
if not range.Min and not range.Max then
return false;
end
if range.Min and not range.Max and range.Min <= needle then
return true;
end
if not range.Min and range.Max and range.Max > needle then
return true;
end
if range.Min and range.Max and range.Min <= needle and range.Max > needle then
return true;
end
end
return false;
end
function BlizzMove:MatchesCurrentBuild(frameData)
-- Compare versus current build version.
if frameData.MinBuild and frameData.MinBuild > self.gameBuild then return false; end
if frameData.MaxBuild and frameData.MaxBuild <= self.gameBuild then return false; end
-- Compare versus current interface version.
if frameData.MinVersion and frameData.MinVersion > self.gameVersion then return false; end
if frameData.MaxVersion and frameData.MaxVersion <= self.gameVersion then return false; end
-- Compare ranges versus current build version.
if frameData.BuildRanges then
if not checkRanges(frameData.BuildRanges, self.gameBuild) then return false; end
end
-- Compare ranges versus current interface version.
if frameData.VersionRanges then
if not checkRanges(frameData.VersionRanges, self.gameVersion) then return false; end
end
return true;
end
function BlizzMove:CopyTable(table)
local copy = {};
for k, v in pairs(table) do
if (type(v) == "table") then
if(IsFrame(v)) then
copy[k] = v;
else
copy[k] = self:CopyTable(v);
end
else
copy[k] = v;
end
end
return copy;
end
end
------------------------------------------------------------------------------------------------------
--- Frame Points Helper Functions
------------------------------------------------------------------------------------------------------
local GetAbsoluteFramePosition;
local GetFramePoints;
local SetFramePoints;
local ignoreSetPointHook = false;
do
--- @param frame Frame
function GetFramePoints(frame)
local numPoints = frame:GetNumPoints();
if numPoints then
local framePoints = {};
for curPoint = 1, numPoints do
framePoints[curPoint] = {};
framePoints[curPoint].anchorPoint,
framePoints[curPoint].relativeFrame,
framePoints[curPoint].relativePoint,
framePoints[curPoint].offX,
framePoints[curPoint].offY = frame:GetPoint(curPoint);
local relativeFrame = framePoints[curPoint].relativeFrame;
if (BlizzMove:GetFrameName(relativeFrame)) then
framePoints[curPoint].relativeFrameName = BlizzMove:GetFrameName(relativeFrame);
elseif (relativeFrame and relativeFrame.GetName and relativeFrame:GetName()) then
framePoints[curPoint].relativeFrameName = relativeFrame:GetName();
end
end
return framePoints;
end
return nil;
end
function GetAbsoluteFramePosition(frame)
-- inspired by LibWindow-1.1 (https://www.wowace.com/projects/libwindow-1-1)
local scale = frame:GetScale();
if not scale then return end
if not frame:GetLeft() then
local frameData = BlizzMove.FrameData[frame];
local frameName = frameData and frameData.storage and frameData.storage.frameName or 'unknown';
local sharedText = string__format('BlizzMove: The frame you just moved (%s) is probably in a broken state, possibly because of other addons. ', frameName);
EnableAddOn('BlizzMove_Debug', UnitName('player')); -- force enable the debug module before loading it
local loaded = LoadAddOn('BlizzMove_Debug');
--- @type BlizzMove_Debug
local DebugModule = loaded and BlizzMove:GetModule('Debug'); ---@diagnostic disable-line: assign-type-mismatch
if (not DebugModule) then
error(sharedText .. 'Enable the Blizzmove_Debug plugin, to find more debugging information.');
return;
end
local result = DebugModule:FindBadAnchorConnections(frame);
local text = sharedText .. 'Copy the text from this popup window, and report it to the addon author.\n\nBad anchor connections for "' .. frameName .. '":\n';
for _, info in pairs(result) do
text = text .. string__format(
'\n\n"%s" is outside anchor family, but referenced by "%s" (created in "%s", and "%s" respectively)',
info.targetName, info.name, info.targetSource, info.source
);
end
DebugModule:GetMainFrame(text):Show();
error(sharedText .. 'Copy the text from the popup window, and report it to the addon author.');
return;
end
local left, top = frame:GetLeft() * scale, frame:GetTop() * scale
local right, bottom = frame:GetRight() * scale, frame:GetBottom() * scale
local parentWidth = GetScreenWidth();
local parentHeight = GetScreenHeight();
local horizontalOffsetFromCenter = (left + right) / 2 - parentWidth / 2;
local verticalOffsetFromCenter = (top + bottom) / 2 - parentHeight / 2;
local x, y, point = 0, 0, "";
if (left < (parentWidth - right) and left < abs(horizontalOffsetFromCenter))
then
x = left;
point = "LEFT";
elseif ((parentWidth - right) < abs(horizontalOffsetFromCenter)) then
x = right - parentWidth;
point = "RIGHT";
else
x = horizontalOffsetFromCenter;
end
if bottom < (parentHeight - top) and bottom < abs(verticalOffsetFromCenter) then
y = bottom;
point = "BOTTOM" .. point;
elseif (parentHeight - top) < abs(verticalOffsetFromCenter) then
y = top - parentHeight;
point = "TOP" .. point;
else
y = verticalOffsetFromCenter;
end
if point == "" then
point = "CENTER"
end
BlizzMove:DebugPrint("GetAbsoluteFramePosition", "x:", math.floor(x), "y:", math.floor(y), "point:", point);
-- the nested table is for backwards compatibility
return {
{
["anchorPoint"] = point,
["relativeFrame"] = "UIParent",
["relativePoint"] = point,
["offX"] = x,
["offY"] = y,
},
};
end
function SetFramePoints(frame, framePoints)
if InCombatLockdown() and frame:IsProtected() then return false; end
if framePoints and framePoints[1] then
frame:ClearAllPoints();
local SetPoint = frame.SetPointBase or frame.SetPoint;
local scale = frame:GetScale();
for curPoint = 1, #framePoints do
ignoreSetPointHook = true;
SetPoint(
frame,
framePoints[curPoint].anchorPoint,
framePoints[curPoint].relativeFrame,
framePoints[curPoint].relativePoint,
framePoints[curPoint].offX / scale,
framePoints[curPoint].offY / scale
);
ignoreSetPointHook = false;
end
end
return true;
end
end
------------------------------------------------------------------------------------------------------
--- Frame Scale Functions
------------------------------------------------------------------------------------------------------
local GetFrameScale;
local SetFrameScale;
do
function GetFrameScale(frame)
local frameData = BlizzMove.FrameData[frame];
local parentScale = (frameData.storage.frameParent and not frameData.ManuallyScaleWithParent and GetFrameScale(frameData.storage.frameParent)) or 1;
return frame:GetScale() * parentScale;
end
local function SetFrameScaleSubs(frame, oldScale, newScale)
local frameData = BlizzMove.FrameData[frame];
if frameData.SubFrames then
for subFrameName, subFrameData in pairs(frameData.SubFrames) do
if subFrameData.storage then
local subFrame = subFrameData.storage.frame;
if subFrame then
if subFrameData.ManuallyScaleWithParent and not subFrameData.storage.detached then
subFrame:SetScale((subFrame:GetScale() / oldScale) * newScale);
BlizzMove:DebugPrint("SetSubFrameScale:", subFrameName, string__format("%.2f %.2f %.2f %.2f", oldScale, newScale, subFrame:GetScale(), GetFrameScale(subFrame)));
elseif not subFrameData.ManuallyScaleWithParent and subFrameData.storage.detached then
subFrame:SetScale((oldScale * subFrame:GetScale()) / newScale);
BlizzMove:DebugPrint("SetSubFrameScale:", subFrameName, string__format("%.2f %.2f %.2f %.2f", oldScale, newScale, subFrame:GetScale(), GetFrameScale(subFrame)));
else
SetFrameScaleSubs(subFrame, oldScale, newScale);
end
end
end
end
end
end
function SetFrameScale(frame, frameScale)
if InCombatLockdown() and frame:IsProtected() then return false; end
local frameData = BlizzMove.FrameData[frame];
local oldScale = GetFrameScale(frame);
local newScale = frameScale;
if frameData.storage.detached then
local parentScale = GetFrameScale(frameData.storage.frameParent);
newScale = frameData.ManuallyScaleWithParent and frameScale or (frameScale / parentScale);
elseif frameData.ManuallyScaleWithParent then
-- not detached, but scaled directly => full reset
local parentScale = GetFrameScale(frameData.storage.frameParent);
newScale = parentScale;
end
BlizzMove.DB.scales[frameData.storage.frameName] = newScale;
frame:SetScale(newScale);
BlizzMove:DebugPrint("SetFrameScale:", frameData.storage.frameName, string__format("%.2f %.2f %.2f", frameScale, frame:GetScale(), GetFrameScale(frame)));
SetFrameScaleSubs(frame, oldScale, newScale);
return true;
end
end
------------------------------------------------------------------------------------------------------
--- Frame Parentage Functions
------------------------------------------------------------------------------------------------------
local SetFrameParent;
do
local function SetFrameParentSubs(frame, addOnName)
local frameData = BlizzMove.FrameData[frame];
local returnValue = true;
if not frameData or not frameData.SubFrames then return returnValue end
for subFrameName, subFrameData in pairs(frameData.SubFrames) do
local subFrame = BlizzMove:GetFrameFromName(addOnName, subFrameName);
if subFrame and BlizzMove:MatchesCurrentBuild(subFrameData) then
if subFrameData.ForceParentage and subFrame.GetParent and subFrame.SetParent and subFrame:GetParent() ~= frame then
subFrame:SetParent(frame);
elseif subFrameData.ForceParentage then
returnValue = false;
end
returnValue = SetFrameParentSubs(subFrame, addOnName) and returnValue;
end
end
return returnValue;
end
function SetFrameParent(frame)
local frameData = BlizzMove.FrameData[frame];
return (frameData.storage.frameParent and SetFrameParent(frameData.storage.frameParent)) or SetFrameParentSubs(frame, frameData.storage.addOnName);
end
end
------------------------------------------------------------------------------------------------------
--- Secure Script Hook Handlers
------------------------------------------------------------------------------------------------------
local OnMouseDown;
local OnMouseUp;
local OnMouseWheel;
local OnEnter;
local OnLeave;
local OnShow;
local OnSubFrameHide;
do
function OnMouseDown(frame, button)
if not BlizzMove.FrameData[frame] or not BlizzMove.FrameData[frame].storage or BlizzMove.FrameData[frame].storage.disabled then return; end
local returnValue = false;
local parentReturnValue = false;
local frameData = BlizzMove.FrameData[frame];
BlizzMove:SetupPointStorage(frame);
BlizzMove:DebugPrint("OnMouseDown:", frameData.storage.frameName, button);
if button == "LeftButton" then
if IsAltKeyDown() and frameData.Detachable and not frameData.storage.detached then
frameData.storage.points.detachPoints = GetFramePoints(frame);
frameData.storage.detached = true;
returnValue = true;
PlaySound((SOUNDKIT and SOUNDKIT.IG_CHARACTER_INFO_OPEN) or 839);
end
if not frameData.storage.detached then
parentReturnValue = (frameData.storage.frameParent and OnMouseDown(frameData.storage.frameParent, button)) or false;
end
if (
(frameData.storage.detached or not parentReturnValue)
and (not (BlizzMove.DB and BlizzMove.DB.requireMoveModifier) or IsShiftKeyDown())
) then
local userPlaced = frame:IsUserPlaced();
frame:SetMovable(true);
frame:StartMoving();
frame:SetUserPlaced(userPlaced);
frameData.storage.points.startPoints = frameData.storage.points.startPoints or GetFramePoints(frame);
frameData.storage.isMoving = true;
returnValue = true;
end
end
return returnValue or parentReturnValue;
end
function OnMouseUp(frame, button)
if not BlizzMove.FrameData[frame] or not BlizzMove.FrameData[frame].storage or BlizzMove.FrameData[frame].storage.disabled then return; end
local returnValue = false;
local parentReturnValue = false;
local frameData = BlizzMove.FrameData[frame];
BlizzMove:DebugPrint("OnMouseUp:", frameData.storage.frameName, button);
if not frameData.storage.detached then
parentReturnValue = (frameData.storage.frameParent and OnMouseUp(frameData.storage.frameParent, button)) or false;
end
if frameData.storage.detached or not parentReturnValue then
if button == "LeftButton" and frameData.storage.isMoving then
frame:StopMovingOrSizing();
frameData.storage.points.dragPoints = GetAbsoluteFramePosition(frame);
frameData.storage.points.dragged = true;
frameData.storage.isMoving = nil;
returnValue = true;
elseif button == "RightButton" then
local fullReset = false;
if IsAltKeyDown() and frameData.storage.detached then
if SetFramePoints(frame, frameData.storage.points.detachPoints) then
frameData.storage.points.detachPoints = nil;
frameData.storage.detached = nil;
returnValue = true;
fullReset = true;
PlaySound((SOUNDKIT and SOUNDKIT.IG_CHARACTER_INFO_CLOSE) or 840);
end
end
if IsControlKeyDown() or fullReset then
returnValue = SetFrameScale(frame, 1) or returnValue;
end
if IsShiftKeyDown() or fullReset then
if(frameData.storage.points) then
if (not fullReset and frameData.storage.points.startPoints) then
SetFramePoints(frame, frameData.storage.points.startPoints);
frameData.storage.points.startPoints = nil;
end
frameData.storage.points.dragPoints = nil;
frameData.storage.points.dragged = nil;
end
returnValue = true;
UpdateUIPanelPositions(frame);
end
returnValue = true;
end
end
return returnValue or parentReturnValue;
end
function OnMouseWheel(frame, delta, ...)
if not IsControlKeyDown() then return; end
if not BlizzMove.FrameData[frame] or not BlizzMove.FrameData[frame].storage or BlizzMove.FrameData[frame].storage.disabled then return; end
local returnValue = false;
local parentReturnValue = false;
local frameData = BlizzMove.FrameData[frame];
BlizzMove:DebugPrint("OnMouseWheel:", frameData.storage.frameName, delta);
if not frameData.storage.detached then
parentReturnValue = (frameData.storage.frameParent and OnMouseWheel(frameData.storage.frameParent, delta, ...)) or false;
end
if (frameData.storage.detached or not parentReturnValue) then
local oldScale = GetFrameScale(frame) or 1;
local newScale = oldScale + 0.1 * delta;
newScale = max(MIN_SCALE, min(MAX_SCALE, newScale));
returnValue = SetFrameScale(frame, newScale) or returnValue;
end
return returnValue or parentReturnValue;
end
function OnShow(frame, skipAdditionalRunNextFrame)
if not BlizzMove.FrameData[frame] or not BlizzMove.FrameData[frame].storage or BlizzMove.FrameData[frame].storage.disabled then return; end
BlizzMove:DebugPrint("OnShow:", BlizzMove:GetFrameName(frame));
if InCombatLockdown() and frame:IsProtected() then
BlizzMove:AddToCombatLockdownQueue(OnShow, frame);
BlizzMove:DebugPrint('Adding to combatLockdownQueue: OnShow - ', BlizzMove:GetFrameName(frame));
return;
end
SetFrameParent(frame);
if(BlizzMove.DB.saveScaleStrategy == 'permanent' and BlizzMove.DB.scales[BlizzMove:GetFrameName(frame)]) then
SetFrameScale(frame, BlizzMove.DB.scales[BlizzMove:GetFrameName(frame)]);
end
if not skipAdditionalRunNextFrame then
RunNextFrame(function() OnShow(frame, true) end);
end
end
function OnSubFrameHide(frame)
if not BlizzMove.FrameData[frame] or not BlizzMove.FrameData[frame].storage or BlizzMove.FrameData[frame].storage.disabled then return; end
local frameData = BlizzMove.FrameData[frame];
local parent = frameData.storage.frameParent or nil;
BlizzMove:DebugPrint("OnHide:", frameData.storage.frameName, frameData.storage.isMoving);
if parent then return OnSubFrameHide(parent); end
if frameData.storage.isMoving then
BlizzMove:WaitForGlobalMouseUp(frame);
end
end
function OnEnter(frame)
if not BlizzMove.FrameData[frame] or not BlizzMove.FrameData[frame].storage or BlizzMove.FrameData[frame].storage.disabled then return; end
BlizzMove.CurrentMouseoverFrames[frame] = true;
BlizzMove:CheckMouseWheelCapture();
end
function OnLeave(frame)
if not BlizzMove.CurrentMouseoverFrames[frame] then return; end
BlizzMove.CurrentMouseoverFrames[frame] = nil;
BlizzMove:CheckMouseWheelCapture();
end
end
------------------------------------------------------------------------------------------------------
--- MouseWheel handling
------------------------------------------------------------------------------------------------------
do
local captureFrame
--[[
General idea of this setup:
- We have a frame that spans the entire screen, and overlaps all frames.
- When the user has CTRL down, and we're mousing over a BM handled frame that has scaling enabled,
and there's no frame overlapping it that captures the mousewheel, we enable the mousewheel on this frame.
- The mousewheel is then passed to the OnMouseWheel function, which does all the scaling magic (including scaling parent-/subframes).
- Whenever mousewheel is disabled, other frames will continue to capture it as normal.
- The above condtions are checked way more often than is needed, because my faith in any alternative working as expected is low.
- And we have to do all this crap because we can't simply propegate mousewheel events to children :/
The previous solution involved manually calling childFrame:GetScript("OnMouseWheel")(childFrame, delta)
which results in scrolling being tainted, which in rare situations would cause problems.
--]]
function BlizzMove:InitMouseWheelCaptureFrame()
captureFrame = CreateFrame("Frame");
captureFrame:SetPoint("TOPLEFT", nil);
captureFrame:SetPoint("BOTTOMRIGHT", nil);
captureFrame:SetScript("OnUpdate", function() self:CheckMouseWheelCapture(); end);
captureFrame:SetScript("OnEvent", function() self:CheckMouseWheelCapture(); end);
captureFrame:RegisterEvent("MODIFIER_STATE_CHANGED")
captureFrame:SetScript("OnMouseWheel", function(_, delta)
for i, frame in ipairs(GetMouseFoci()) do
--- @type BlizzMoveAPI_FrameData?
local frameData = self.FrameData[frame];
if frameData and not (frameData.IgnoreMouse or frameData.IgnoreMouseWheel) and self.CurrentMouseoverFrames[frame] then
OnMouseWheel(frame, delta);
return;
end
end
--@debug@
self:Print('dev debug print: no frame found?? :-(');
--@end-debug@
end);
captureFrame:SetFrameStrata("TOOLTIP");
captureFrame:SetFrameLevel(9999); -- try to overlay everything ;-)
captureFrame:Show();
captureFrame:EnableMouseWheel(false);
RunNextFrame(function() self:CheckMouseWheelCapture(); end);
end
function BlizzMove:CheckMouseWheelCapture()
captureFrame:EnableMouseWheel(false);
if not IsControlKeyDown() or not next(self.CurrentMouseoverFrames) or not next(GetMouseFoci()) then
-- keep mouse wheel disabled
return;
end
for _, frame in ipairs(GetMouseFoci()) do
--- @type BlizzMoveAPI_FrameData?
local frameData = self.FrameData[frame];
local shouldHandleMouseWheel = frameData and not (frameData.IgnoreMouse or frameData.IgnoreMouseWheel);
if not shouldHandleMouseWheel and (frame:IsForbidden() or frame:IsMouseWheelEnabled() or frame:IsMouseClickEnabled()) then return; end -- some clickable/scrollable thing is in the way
if shouldHandleMouseWheel and self.CurrentMouseoverFrames[frame] then
captureFrame:EnableMouseWheel(true);
return;
end
end
end
end
------------------------------------------------------------------------------------------------------
--- Secure Hook Handlers
------------------------------------------------------------------------------------------------------
local OnSetPoint;
local OnSizeUpdate;
do
function OnSetPoint(frame, ...)
if not BlizzMove.FrameData[frame] or not BlizzMove.FrameData[frame].storage or BlizzMove.FrameData[frame].storage.disabled then return; end
if BlizzMove.DB.savePosStrategy == "off" then return; end
if ignoreSetPointHook then return; end
BlizzMove:SetupPointStorage(frame);
local frameData = BlizzMove.FrameData[frame];
if BlizzMove.FrameData[frame].storage.points.dragged then
if frameData.IgnoreSavedPositionWhenMaximized and frame.isMaximized then return; end
if BlizzMove.DB.savePosStrategy ~= "permanent" then
SetFramePoints(frame, BlizzMove.FrameData[frame].storage.points.dragPoints);
else
BlizzMove:AddToSetFramePointsQueue(frame, BlizzMove.FrameData[frame].storage.points.dragPoints);
end
end
end
function OnSizeUpdate(frame)
local frameData = BlizzMove.FrameData[frame];
if not frameData or not frameData.storage or frameData.storage.disabled or frameData.IgnoreClamping then return; end
local clampDistance = 40;
local clampWidth = (frame:GetWidth() - clampDistance) or 0;
local clampHeight = (frame:GetHeight() - clampDistance) or 0;
frame:SetClampRectInsets(clampWidth, -clampWidth, -clampHeight, clampHeight);
end
end
------------------------------------------------------------------------------------------------------
--- Secure Global Hook Handlers
------------------------------------------------------------------------------------------------------
local OnUpdateScaleForFit;
do
function OnUpdateScaleForFit(frame)
if not BlizzMove.FrameData[frame] or not BlizzMove.FrameData[frame].storage or BlizzMove.FrameData[frame].storage.disabled then return; end
BlizzMove:DebugPrint("OnUpdateScaleForFit:", BlizzMove:GetFrameName(frame));
if InCombatLockdown() and frame:IsProtected() then
BlizzMove:AddToCombatLockdownQueue(OnUpdateScaleForFit, frame);
BlizzMove:DebugPrint('Adding to combatLockdownQueue: OnUpdateScaleForFit - ', BlizzMove:GetFrameName(frame));
return;
end
if(BlizzMove.DB.scales[BlizzMove:GetFrameName(frame)]) then
SetFrameScale(frame, BlizzMove.DB.scales[BlizzMove:GetFrameName(frame)]);
end
end
end
------------------------------------------------------------------------------------------------------
--- Processing Frame Functions
------------------------------------------------------------------------------------------------------
do
local function hookScript(frame, script, handler)
BlizzMove:SecureHookScript(frame, script, handler);
if (frame:HasScript(script)) then
hooksecurefunc(frame, 'SetScript', function(self, scriptName)
if (scriptName == script and self == frame) then
BlizzMove:DebugPrint('SetScript hook triggered for ', BlizzMove:GetFrameName(frame), scriptName);
BlizzMove:Unhook(frame, script);
BlizzMove:SecureHookScript(frame, script, handler);
end
end);
end
end
--- @param frame Frame
--- @param addOnName string
--- @param frameName string
--- @param frameData BlizzMoveAPI_FrameData|BlizzMoveAPI_SubFrameData|BlizzMove_FrameData
--- @param frameParent Frame?
local function MakeFrameMovable(frame, addOnName, frameName, frameData, frameParent)
if not frame then return false; end
if InCombatLockdown() and frame:IsProtected() then return false; end
local clampFrame = false;
if not frameParent or frameData.Detachable then
clampFrame = true;