Quantcast

- Further changes for #1306 to cover more scenarios

urnati [07-23-21 - 00:21]
- Further changes for #1306 to cover more scenarios
Filename
Titan/TitanMovable.lua
diff --git a/Titan/TitanMovable.lua b/Titan/TitanMovable.lua
index 3bf5f36..2bddc5e 100755
--- a/Titan/TitanMovable.lua
+++ b/Titan/TitanMovable.lua
@@ -92,6 +92,31 @@ end)
 --]]

 --[[ local
+NAME: f_list table
+DESC: Holds the list of frames Titan may adjust with additional data.
+Each record contains:
+name - frame name (string) to adjust
+user_movable - true if Blizzard allows the user to move the frame via its UI
+debug - set true if debugging the adjust of that frame
+:DESC
+NOTE:
+- The index MUST be the frame name as used by MData.
+:NOTE
+--]]
+local f_list = {
+	PlayerFrame = {name = "PlayerFrame", place = TITAN_PANEL_PLACE_TOP, user_movable = true, debug = true},
+	TargetFrame = {name = "TargetFrame", place = TITAN_PANEL_PLACE_TOP, user_movable = true, debug = false},
+	PartyMemberFrame1 = {name = "PartyMemberFrame1", place = TITAN_PANEL_PLACE_TOP, user_movable = false, debug = false},
+	TicketStatusFrame = {name = "TicketStatusFrame", place = TITAN_PANEL_PLACE_TOP, user_movable = false, debug = false},
+	BuffFrame = {name = "BuffFrame", place = TITAN_PANEL_PLACE_TOP, user_movable = false, debug = false},
+	MinimapCluster = {name = "MinimapCluster", place = TITAN_PANEL_PLACE_TOP, user_movable = false, debug = false},
+	MultiBarRight = {name = "MultiBarRight", place = TITAN_PANEL_PLACE_BOTTOM, user_movable = false, debug = false},
+	MicroButtonAndBagsBar = {name = "MicroButtonAndBagsBar", place = TITAN_PANEL_PLACE_BOTTOM, user_movable = false, debug = false},
+	MainMenuBar = {name = "MainMenuBar", place = TITAN_PANEL_PLACE_BOTTOM, user_movable = false, debug = false},
+	ExtraActionBarFrame = {name = "ExtraActionBarFrame", place = TITAN_PANEL_PLACE_BOTTOM, user_movable = false, debug = false},
+}
+
+--[[ local
 NAME: DoAdjust
 DESC: See if Titan should adjust based only on its own flags.
 VAR: place   - top or bottom
@@ -103,7 +128,7 @@ local function DoAdjust(place, force)
 	-- When that happens we need to adjust

 	-- We did it to ourselves - if (Aux)ScreenAdjust is true / 1 it means the user wants Titan to NOT adjust...
-	if place == TITAN_PANEL_PLACE_TOP then
+	if place == TITAN_PANEL_PLACE_TOP or place == TITAN_PANEL_PLACE_BOTH then
 		if TitanPanelGetVar("ScreenAdjust") == 1 then
 			-- do not adjust
 		else
@@ -113,9 +138,8 @@ local function DoAdjust(place, force)
 				res = true
 			end
 		end
-	elseif place == TITAN_PANEL_PLACE_BOTTOM then
-		if TitanPanelGetVar("AuxScreenAdjust") == 1
-			or ActionBarController_GetCurrentActionBarState() == LE_ACTIONBAR_STATE_OVERRIDE then
+	elseif place == TITAN_PANEL_PLACE_BOTTOM or place == TITAN_PANEL_PLACE_BOTH then
+		if TitanPanelGetVar("AuxScreenAdjust") == 1 then
 			-- do not adjust
 		else
 			if force then
@@ -292,31 +316,24 @@ Titan does not control the frames as other addons so we honor a user placed fram
 :NOTE
 --]]
 local function SetPosition(frame, ...)
-	local function UserMovable(frame)
-		local fname = frame:GetName()
-		local res = false
-		-- user may move these frames via the UI
-		if (fname == 'PlayerFrame' or fname == 'TargetFrame')
-		then
-			res = true
-		else
-			res = false
-		end
-		return res
+	local fname = frame:GetName()
+	local um = false
+	if f_list[fname] and f_list[fname].user_movable then
+		um = true
+	else
+		um = false
 	end
+
     if type(frame) == 'string' then
         UIPARENT_MANAGED_FRAME_POSITIONS[frame] = nil
         frame = _G[frame]
     end
     if type(frame) == 'table' and type(frame.IsObjectType) == 'function' and frame:IsObjectType('Frame') then
-		if UserMovable(frame) then
+		if um then
 			-- Back off if the user has moved them via the UI
 		else
-			local name = frame:GetName()
 			-- Titan does not set in case the user needs to
-			if name then
-				UIPARENT_MANAGED_FRAME_POSITIONS[name] = nil
-			end
+			UIPARENT_MANAGED_FRAME_POSITIONS[fname] = nil
         end

         frame:SetMovable(true)          -- allow frame to move
@@ -332,7 +349,7 @@ local function SetPosition(frame, ...)
             frame:SetPoint(...)
         end
 		-- Need to add in case user (not an addon) wants to move this frames
-		if UserMovable(frame) then
+		if um then
 			-- do nothing
 		else
 			frame:SetMovable(false)         -- lock frame from moving
@@ -389,32 +406,44 @@ OUT: None
 --]]
 local function MoveFrame(frame_ptr, start_y, top_bottom, force)
 	local frame = _G[frame_ptr]
+	local y = 0
+	local op = "?"

 	if frame and (frame:IsUserPlaced() or
 			frame.MALockPointHook  -- Allow MoveAnything to be used w/o error
 		)
 	then
 		-- skip this frame
+		op = "skip - MoveAnything"
 	else
 		if DoAdjust(top_bottom, force) and frame:IsShown() then
 			local scale = TitanPanelGetVar("Scale")
-			local y = 0
-				y = TitanMovable_GetPanelYOffset(top_bottom)
-					+ (start_y or 0)
+			y = TitanMovable_GetPanelYOffset(top_bottom)
+				+ (start_y or 0)
 			local point, relativeTo, relativePoint, xOfs, yOfs = frame:GetPoint()
 			-- check for nil which will cause an error
 			if point and relativeTo and relativePoint and xOfs then -- do not care about yOfs
 				-- should be safe...
 				SetPosition(frame, point, relativeTo:GetName(), relativePoint, xOfs, y)
+				op = "move - y "..tostring(y)
 			else
+				op = "skip - :GetPoint invalid"
 				-- do not proceed
 			end
 		else
 			--[[
 			Some frames such as the ticket frame may not be visible or even created
 			--]]
+			op = "skip - adj "..tostring(DoAdjust(top_bottom, force)).." shown "..tostring(frame:IsShown())
 		end
 	end
+
+	if f_list[frame_ptr] and f_list[frame_ptr].debug then
+		TitanDebug ("MoveFrame"
+		.." "..tostring(frame_ptr)
+		.." "..tostring(op)
+		)
+	end
 end

 --[[ local
@@ -588,31 +617,46 @@ XXZZ_calc_bars = calc_bars
 NAME: MData table
 DESC: MData is a local table that holds each frame Titan may need to adjust. It controls the offsets needed to make room for the Titan bar(s).
 Each frame can be adjusted by modifying its 'move' function.
-The index is the frame name. Each record contains:
-frameName - frame name (string) to adjust
+The f_list and MData MUST have matching index so the name and move function correspond.
+Each record contains:
+move - function to adjust that frame
 addonAdj - true if another addon is taking responsibility of adjusting this frame, if false Titan will use the user settings to adjust or not
 :DESC
 NOTE:
+- f_list MUST have frame name as the index so the extra data can be used.
 - MoveFrame calculates and offsets for the Titan bars, if shown
 - When calculating the initial Y offset, consider the points and relative points of the frame being adjusted. See the move function for specific frame adjustments
 - Of course Blizzard had to make the MainMenuBar act differently <sigh>. :GetPoint() does not work on it so a special helper routine was needed.
+- The move function sets info in the frame itself. It so inside the move because some frames, such as the ticket frame, may not be created until needed.
 :NOTE
 --]]
-local save_y = 0
 local MData = {
-	[1] = {frameName = "PlayerFrame",
-		move = function (force) MoveFrame("PlayerFrame", 0, TITAN_PANEL_PLACE_TOP, force) end,
+	[1] = {
+		frameName = "PlayerFrame",
+		move = function (force)
+			MoveFrame("PlayerFrame", 0, TITAN_PANEL_PLACE_TOP, force)
+			end,
 		addonAdj = false, },
-	[2] = {frameName = "TargetFrame",
-		move = function (force) MoveFrame("TargetFrame", 0, TITAN_PANEL_PLACE_TOP, force) end,
+	[2] = {
+		frameName = "TargetFrame",
+		move = function (force)
+			MoveFrame("TargetFrame", 0, TITAN_PANEL_PLACE_TOP, force)
+			end,
 		addonAdj = false, },
-	[3] = {frameName = "PartyMemberFrame1",
-		move = function (force) MoveFrame("PartyMemberFrame1", 0, TITAN_PANEL_PLACE_TOP, force) end,
+	[3] = {
+		frameName = "PartyMemberFrame1",
+		move = function (force)
+			MoveFrame("PartyMemberFrame1", 0, TITAN_PANEL_PLACE_TOP, force)
+			end,
 		addonAdj = false, },
-	[4] = {frameName = "TicketStatusFrame",
-		move = function (force) MoveFrame("TicketStatusFrame", 0, TITAN_PANEL_PLACE_TOP, force) end,
+	[4] = {
+		frameName = "TicketStatusFrame",
+		move = function (force)
+			MoveFrame("TicketStatusFrame", 0, TITAN_PANEL_PLACE_TOP, force)
+			end,
 		addonAdj = false, },
-	[5] = {frameName = "BuffFrame",
+	[5] = {
+		frameName = "BuffFrame",
 		move = function (force)
 			-- The main frames have no adjustment (tops align) to UIParent.
 			-- But we need to properly adjust for
@@ -639,27 +683,37 @@ local MData = {
 			MoveFrame("BuffFrame", yOffset, TITAN_PANEL_PLACE_TOP, force)
 			end,
 		addonAdj = false, },
-	[6] = {frameName = "MinimapCluster",
+	[6] = {
+		frameName = "MinimapCluster",
 		move = function (force)
 			local yOffset = 0
 			if MinimapBorderTop
 			and not MinimapBorderTop:IsShown() then
 				yOffset = yOffset + (MinimapBorderTop:GetHeight() * 3/5) - 5
 			end
-			MoveFrame("MinimapCluster", yOffset, TITAN_PANEL_PLACE_TOP, force) end,
+			MoveFrame("MinimapCluster", yOffset, TITAN_PANEL_PLACE_TOP, force)
+			end,
 		addonAdj = false, },
-	[7] = {frameName = "MultiBarRight",
+	[7] = {
+		frameName = "MultiBarRight",
 		move = function (force)
-			MoveFrame("MultiBarRight", 0, TITAN_PANEL_PLACE_BOTTOM, force) end,
+			MoveFrame("MultiBarRight", 0, TITAN_PANEL_PLACE_BOTTOM, force)
+			end,
 		addonAdj = false, },
-	[8] = {frameName = "MicroButtonAndBagsBar",
-		move = function (force) MoveFrame("MicroButtonAndBagsBar", 0, TITAN_PANEL_PLACE_BOTTOM, force) end,
+	[8] = {
+		frameName = "MicroButtonAndBagsBar",
+		move = function (force)
+			MoveFrame("MicroButtonAndBagsBar", 0, TITAN_PANEL_PLACE_BOTTOM, force)
+			end,
 		addonAdj = false, },
-	[9] = {frameName = "MainMenuBar", -- MainMenuBar
+	[9] = {
+		frameName = "MainMenuBar", -- MainMenuBar
 		move = function (force)
-			MoveMenuFrame("MainMenuBar", 0, TITAN_PANEL_PLACE_BOTTOM, force) end,
+			MoveMenuFrame("MainMenuBar", 0, TITAN_PANEL_PLACE_BOTTOM, force)
+			end,
 		addonAdj = false, },
-	[10] = {frameName = "ExtraActionBarFrame",
+	[10] = {
+		frameName = "ExtraActionBarFrame",
 		move = function (force)
 			-- Only spend cycles if the frame is shown.
 			if ExtraActionBarFrame
@@ -682,7 +736,7 @@ local MData = {
 					+ calc_bars() -- offset of WoW bars shown
 					+ start_y -- center of extra action button
 				MoveFrame("ExtraAbilityContainer", yOfs, TITAN_PANEL_PLACE_BOTTOM, force)
-			end
+			end
 			end,
 		addonAdj = false, },
 }
@@ -728,7 +782,7 @@ DESC: Loop through MData calling each frame's 'move' function for each Titan con
 Then update the chat and open bag frames.
 OUT: None
 --]]
-local function TitanMovableFrame_MoveFrames(force)
+local function TitanMovableFrame_MoveFrames(place, force)
 	local move_count = 0 -- debug
 	local str = "" -- debug
 	local force = force or false
@@ -752,18 +806,11 @@ local function TitanMovableFrame_MoveFrames(force)
 				if MData[i].addonAdj then
 					-- An addon has taken control of the frame so skip
 				else
-					-- Adjust the frame per MData
-					MData[i].move(force)
---[[
-					local ok, msg = pcall(function () MData[i].move() end)
-					if ok then
-						-- all is well
-					else
-						TitanPrint("Cannot Move"
-							.." '"..(MData[i].frameName or "?").."."
-							.." "..msg, "error")
+					local md = MData[i]
+					if place == f_list[md.frameName].place or place == TITAN_PANEL_PLACE_BOTH then
+						-- Adjust the frame per MData
+						md.move(force)
 					end
---]]
 				end
 			end
 		end
@@ -812,7 +859,7 @@ function TitanPanel_AdjustFrames(force, reason)

 	-- Adjust frame positions top and bottom based on user choices
 	if hooks_done then
-		TitanMovableFrame_MoveFrames(f)
+		TitanMovableFrame_MoveFrames(TITAN_PANEL_PLACE_BOTH, f)
 	end
 end

@@ -885,11 +932,15 @@ function Titan_Hook_Frames() -- UIParent_ManageFramePositions hook
 		reason = reason.."skinned override bar"
 		-- Override bar in place; hide Titan bottom bar(s)
 		TitanPanelBarButton_HideBottomBars()
+
+		-- Blizzard could have updated player frame or other
+		TitanMovableFrame_MoveFrames(TITAN_PANEL_PLACE_TOP, false)
+
 	-- If we have a non-skinned override bar of some sort, use the MainMenuBarArtFrame
 	elseif ( HasBonusActionBar() or HasOverrideActionBar() or HasVehicleActionBar() or HasTempShapeshiftActionBar() or C_PetBattles.IsInBattle() ) then
 		reason = reason.."non-skinned override bar"
-		-- Override bar in place; hide Titan bottom bar(s)
-		TitanPanelBarButton_HideBottomBars()
+		-- BonusActionBar is rogue in stealth
+		-- TitanPanelBarButton_HideBottomBars()
 	elseif ( OrderHallCommandBar and OrderHallCommandBar:IsShown() ) then
 		reason = reason.."Order Hall bar"
 		-- Override bar in place; hide Titan bottom bar(s)