Skip to content

Commit

Permalink
World Map no longer uses saved positions when maximizing to fullscreen
Browse files Browse the repository at this point in the history
Added a lot of typehinting for internal datastructures
  • Loading branch information
Numynum committed Aug 25, 2024
1 parent e043e25 commit 032f0c3
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 43 deletions.
66 changes: 50 additions & 16 deletions BlizzMove.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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;
Expand All @@ -35,9 +36,13 @@ local name = ... or "BlizzMove";
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 = BlizzMove.Frames or {};
--- @type table<Frame, BlizzMove_FrameData>
BlizzMove.FrameData = BlizzMove.FrameData or {};
--- @type table<string, table<string, Frame>> # [addonName][frameName] = frame
BlizzMove.FrameRegistry = BlizzMove.FrameRegistry or {};
--- @type BlizzMove_CombatLockdownQueueItem[]
BlizzMove.CombatLockdownQueue = BlizzMove.CombatLockdownQueue or {};

------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -114,6 +119,7 @@ do
or key == "NonDraggable"
or key == "DefaultDisabled"
or key == "SilenceCompatabilityWarnings"
or key == "IgnoreSavedPositionWhenMaximized"
) then
if type(value) ~= "boolean" then validationError = true; end
elseif key == "FrameReference" then
Expand Down Expand Up @@ -402,6 +408,7 @@ local GetFramePoints;
local SetFramePoints;
local ignoreSetPointHook = false;
do
--- @param frame Frame
function GetFramePoints(frame)
local numPoints = frame:GetNumPoints();

Expand All @@ -427,7 +434,7 @@ do
return framePoints;
end

return false;
return nil;
end

function GetAbsoluteFramePosition(frame)
Expand All @@ -440,9 +447,10 @@ do
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');
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;
Expand Down Expand Up @@ -657,7 +665,7 @@ do
end

if not frameData.storage.detached then
parentReturnValue = (frameData.storage.frameParent and OnMouseDown(frameData.storage.frameParent, button));
parentReturnValue = (frameData.storage.frameParent and OnMouseDown(frameData.storage.frameParent, button)) or false;
end

if (
Expand Down Expand Up @@ -688,7 +696,7 @@ do
BlizzMove:DebugPrint("OnMouseUp:", frameData.storage.frameName, button);

if not frameData.storage.detached then
parentReturnValue = (frameData.storage.frameParent and OnMouseUp(frameData.storage.frameParent, button));
parentReturnValue = (frameData.storage.frameParent and OnMouseUp(frameData.storage.frameParent, button)) or false;
end

if frameData.storage.detached or not parentReturnValue then
Expand Down Expand Up @@ -770,7 +778,7 @@ do
local onChildren = not IsControlKeyDown() and not nestedOnMouseWheelCall and OnMouseWheelChildren(frame, delta, ...);

if not onChildren and not nestedOnMouseWheelCall and not frameData.storage.detached then
parentReturnValue = (frameData.storage.frameParent and OnMouseWheel(frameData.storage.frameParent, delta, ...));
parentReturnValue = (frameData.storage.frameParent and OnMouseWheel(frameData.storage.frameParent, delta, ...)) or false;
end

if (not nestedOnMouseWheelCall and (frameData.storage.detached or not parentReturnValue) and IsControlKeyDown()) then
Expand Down Expand Up @@ -841,7 +849,10 @@ do

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
Expand Down Expand Up @@ -901,6 +912,11 @@ do
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

Expand Down Expand Up @@ -936,7 +952,7 @@ do
frameData.storage.frameName = frameName;
frameData.storage.addOnName = addOnName;
frameData.storage.frameParent = frameParent;
BlizzMove.FrameData[frame] = frameData;
BlizzMove.FrameData[frame] = frameData; ---@diagnostic disable-line: assign-type-mismatch
end

if not frame or (frameData.storage and frameData.storage.hooked) then return false; end
Expand Down Expand Up @@ -966,13 +982,15 @@ do
BlizzMove:SecureHook(frame, "SetWidth", OnSizeUpdate);
BlizzMove:SecureHook(frame, "SetHeight", OnSizeUpdate);

frameData.storage = {};
frameData.storage.hooked = true;
frameData.storage.frame = frame;
frameData.storage.frameName = frameName;
frameData.storage.frameParent = frameParent;
frameData.storage = {
hooked = true,
frame = frame,
frameName = frameName,
frameParent = frameParent,
addOnName = addOnName,
};

BlizzMove.FrameData[frame] = frameData;
BlizzMove.FrameData[frame] = frameData; ---@diagnostic disable-line: assign-type-mismatch

OnShow(frame);
OnSizeUpdate(frame);
Expand All @@ -999,6 +1017,11 @@ do
return true;
end

--- @param frame Frame
--- @param addOnName string
--- @param frameName string
--- @param frameData BlizzMoveAPI_FrameData|BlizzMoveAPI_SubFrameData|BlizzMove_FrameData
--- @param frameParent Frame?
function BlizzMove:MakeFrameMovable(frame, addOnName, frameName, frameData, frameParent)
return xpcall(MakeFrameMovable, CallErrorHandler, frame, addOnName, frameName, frameData, frameParent);
end
Expand All @@ -1007,6 +1030,11 @@ do
return xpcall(MakeFrameUnmovable, CallErrorHandler, frame, frameData);
end

--- @param addOnName string
--- @param frameName string
--- @param frameData BlizzMoveAPI_FrameData|BlizzMoveAPI_SubFrameData|BlizzMove_FrameData
--- @param frameParent Frame?
--- @param retriedAfterNotFound boolean?
function BlizzMove:ProcessFrame(addOnName, frameName, frameData, frameParent, retriedAfterNotFound)
if self:IsFrameDisabled(addOnName, frameName) then return; end

Expand Down Expand Up @@ -1143,7 +1171,10 @@ do
local count = 0;
for frame, framePoints in pairs(setFramePointsQueue) do
count = count + 1;
SetFramePoints(frame, framePoints);
local frameData = self.FrameData[frame];
if not (frameData and frameData.IgnoreSavedPositionWhenMaximized and frame.isMaximized) then
SetFramePoints(frame, framePoints);
end
end
if count == 0 then return; end

Expand Down Expand Up @@ -1178,6 +1209,7 @@ do
self.initialized = true;

_G.BlizzMoveDB = _G.BlizzMoveDB or {};
--- @type BlizzMoveDB
self.DB = _G.BlizzMoveDB;
self:InitDefaults();

Expand All @@ -1189,9 +1221,9 @@ do
self:RegisterChatCommand('bm'..command, function(message) self:OnSlashCommand(command..' '..message); end);
end

if UIPanelUpdateScaleForFit then
if _G.UIPanelUpdateScaleForFit then
self:SecureHook('UIPanelUpdateScaleForFit', OnUpdateScaleForFit);
elseif UpdateScaleForFit then
elseif _G.UpdateScaleForFit then
self:SecureHook('UpdateScaleForFit', OnUpdateScaleForFit);
end

Expand All @@ -1218,9 +1250,10 @@ do
or arg1 == commands.debugAnchor
or arg1 == commands.dumpTopLevelFrames
) then
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 self:GetModule('Debug');
local DebugModule = loaded and BlizzMove:GetModule('Debug'); ---@diagnostic disable-line: assign-type-mismatch
if (not DebugModule) then
self:Print('Could not load BlizzMove_Debug plugin');

Expand Down Expand Up @@ -1270,6 +1303,7 @@ do
Settings_OpenToCategory('BlizzMove');
end

--- @type BlizzMoveDB
local defaults = {
savePosStrategy = "session",
saveScaleStrategy = "session",
Expand Down
27 changes: 0 additions & 27 deletions BlizzMoveAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,6 @@ function BlizzMoveAPI:ToggleDebugPrints()
BlizzMove:Print("Debug prints have been:", (BlizzMove.DB.DebugPrints and "Enabled") or "Disabled");
end

--- @alias BlizzMoveAPI_FrameTable table<string, BlizzMoveAPI_FrameData> # Frame name as key
--- @alias BlizzMoveAPI_AddonFrameTable table<string, BlizzMoveAPI_FrameTable> # Addon name as key, these can be LoD addons

--- @class BlizzMoveAPI_FrameData
--- @field SubFrames table<string, BlizzMoveAPI_SubFrameData>|nil # Sub frame name as key, sub frames may be nested to any depth
--- @field FrameReference Frame|nil # Reference to the frame to be moved, if nil, the frame will be looked up by name
--- @field MinVersion number|nil # First Interface version that is considered compatible
--- @field MaxVersion number|nil # Last Interface version that is consider compatible
--- @field MinBuild number|nil # First Interface build number that is considered compatible
--- @field MaxBuild number|nil # Last Interface build number that is considered compatible
--- @field VersionRanges BlizzMoveAPI_Range[]|nil # Interface version ranges, can be combined with MinVersion and MaxVersion
--- @field BuildRanges BlizzMoveAPI_Range[]|nil # Interface build number ranges, can be combined with MinBuild and MaxBuild
--- @field SilenceCompatabilityWarnings boolean|nil # Suppress warnings caused by compatibility checks against Interface version and build number
--- @field IgnoreMouse boolean|nil # Ignore all mouse events, same as setting both IgnoreMouseWheel and NonDraggable to true
--- @field IgnoreMouseWheel boolean|nil # Ignore mouse wheel events
--- @field NonDraggable boolean|nil # Ignore mouse drag events
--- @field DefaultDisabled boolean|nil # Disables moving the frame in the settings by default, requiring the user to enable it manually

--- @class BlizzMoveAPI_SubFrameData: BlizzMoveAPI_FrameData
--- @field Detachable boolean|nil # Allow the frame to be detached from the parent and moved independently
--- @field ForceParentage boolean|nil # Will call child:SetParent(parent) on registration
--- @field ManuallyScaleWithParent boolean|nil # Manually scale the frame with the parent; will call SetScale on the child whenever the parent's scale is updated

--- @class BlizzMoveAPI_Range
--- @field Min number|nil # Either Min, Max, or both must be filled
--- @field Max number|nil # Either Min, Max, or both must be filled

--- @param framesTable BlizzMoveAPI_FrameTable
function BlizzMoveAPI:RegisterFrames(framesTable)
for frameName, frameData in pairs(framesTable) do
Expand Down
1 change: 1 addition & 0 deletions Frames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ BlizzMoveAPI:RegisterFrames(
{
MinVersion = 40000, -- No longer fullscreen when?
SilenceCompatabilityWarnings = true,
IgnoreSavedPositionWhenMaximized = true,
SubFrames =
{
["QuestMapFrame"] =
Expand Down
81 changes: 81 additions & 0 deletions Types.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
--- @meta _

----------------------------------------
-- BlizzMove API Types
----------------------------------------
--- @alias BlizzMoveAPI_FrameTable table<string, BlizzMoveAPI_FrameData> # Frame name as key
--- @alias BlizzMoveAPI_AddonFrameTable table<string, BlizzMoveAPI_FrameTable> # Addon name as key, these can be LoD addons

--- @class BlizzMoveAPI_FrameData
--- @field SubFrames table<string, BlizzMoveAPI_SubFrameData>|nil # Sub frame name as key, sub frames may be nested to any depth
--- @field FrameReference Frame|nil # Reference to the frame to be moved, if nil, the frame will be looked up by name
--- @field MinVersion number|nil # First Interface version that is considered compatible
--- @field MaxVersion number|nil # Last Interface version that is consider compatible
--- @field MinBuild number|nil # First Interface build number that is considered compatible
--- @field MaxBuild number|nil # Last Interface build number that is considered compatible
--- @field VersionRanges BlizzMoveAPI_Range[]|nil # Interface version ranges, can be combined with MinVersion and MaxVersion
--- @field BuildRanges BlizzMoveAPI_Range[]|nil # Interface build number ranges, can be combined with MinBuild and MaxBuild
--- @field SilenceCompatabilityWarnings boolean|nil # Suppress warnings caused by compatibility checks against Interface version and build number
--- @field IgnoreMouse boolean|nil # Ignore all mouse events, same as setting both IgnoreMouseWheel and NonDraggable to true
--- @field IgnoreMouseWheel boolean|nil # Ignore mouse wheel events
--- @field NonDraggable boolean|nil # Ignore mouse drag events
--- @field DefaultDisabled boolean|nil # Disables moving the frame in the settings by default, requiring the user to enable it manually
--- @field IgnoreSavedPositionWhenMaximized boolean|nil # Ignore the stored position when the frame is maximized (checks frame.isMaximized for this)

--- @class BlizzMoveAPI_SubFrameData: BlizzMoveAPI_FrameData
--- @field Detachable boolean|nil # Allow the frame to be detached from the parent and moved independently
--- @field ForceParentage boolean|nil # Will call child:SetParent(parent) on registration
--- @field ManuallyScaleWithParent boolean|nil # Manually scale the frame with the parent; will call SetScale on the child whenever the parent's scale is updated

--- @class BlizzMoveAPI_Range
--- @field Min number|nil # Either Min, Max, or both must be filled
--- @field Max number|nil # Either Min, Max, or both must be filled

----------------------------------------
-- BlizzMove Internal Types
----------------------------------------
--- @class BlizzMove_FrameData: BlizzMoveAPI_SubFrameData
--- @field storage BlizzMove_FrameStorage
--- @field SubFrames table<string, BlizzMove_FrameData>|nil

--- @class BlizzMove_FrameStorage
--- @field frame Frame
--- @field frameName string
--- @field addOnName string
--- @field frameParent Frame?
--- @field points BlizzMove_PointsStorage?
--- @field isMoving boolean?
--- @field detached boolean?
--- @field disabled boolean?
--- @field hooked boolean

--- @class BlizzMove_PointsStorage
--- @field dragged boolean|nil
--- @field startPoints BlizzMove_FramePoint[]|nil
--- @field dragPoints BlizzMove_FramePoint[]|nil
--- @field detachPoints BlizzMove_FramePoint[]|nil

--- @class BlizzMove_FramePoint
--- @field anchorPoint FramePoint
--- @field relativeFrame Frame?
--- @field relativeFrameName string?
--- @field relativePoint FramePoint
--- @field offX number
--- @field offY number

--- @class BlizzMove_CombatLockdownQueueItem
--- @field func function
--- @field args any[]

--- @class BlizzMoveDB
--- @field DebugPrints boolean?
--- @field requireMoveModifier boolean?
--- @field savePosStrategy BlizzMove_SavePosStrategy
--- @field saveScaleStrategy BlizzMove_SaveScaleStrategy
--- @field points table<string, BlizzMove_PointsStorage> # [frameName] = BlizzMove_PointsStorage
--- @field scales table<string, number> # [frameName] = scale
--- @field disabledFrames table<string, table<string, boolean>>|nil # [addonName][frameName] = true
--- @field enabledFrames table<string, table<string, boolean>>|nil # [addonName][frameName] = true

--- @alias BlizzMove_SavePosStrategy "session"|"permanent"|"off"
--- @alias BlizzMove_SaveScaleStrategy "session"|"permanent"|

0 comments on commit 032f0c3

Please sign in to comment.