Quantcast

Save window positions in profile and do not use layout-local.txt

Ludovicus [07-31-19 - 11:06]
Save window positions in profile and do not use layout-local.txt
Filename
TomTom.lua
TomTom_CrazyArrow.lua
diff --git a/TomTom.lua b/TomTom.lua
index 2fe1c43..9bd7900 100755
--- a/TomTom.lua
+++ b/TomTom.lua
@@ -389,7 +389,6 @@ function TomTom:ShowHideCoordBlock()
             TomTomBlock:SetClampedToScreen(true)
             TomTomBlock:RegisterForDrag("LeftButton")
             TomTomBlock:RegisterForClicks("RightButtonUp")
-            TomTomBlock:SetPoint("TOP", Minimap, "BOTTOM", -20, -10)

             TomTomBlock.Text = TomTomBlock:CreateFontString(nil, "OVERLAY", "GameFontNormal")
             TomTomBlock.Text:SetJustifyH("CENTER")
@@ -411,6 +410,8 @@ function TomTom:ShowHideCoordBlock()
             TomTomBlock:SetScript("OnLeave", Block_OnLeave)
             TomTomBlock:SetScript("OnDragStop", Block_OnDragStop)
             TomTomBlock:SetScript("OnDragStart", Block_OnDragStart)
+            TomTomBlock:RegisterEvent("PLAYER_ENTERING_WORLD")
+            TomTomBlock:SetScript("OnEvent", Block_OnEvent)
         end
         -- Show the frame
         TomTomBlock:Show()
@@ -425,6 +426,15 @@ function TomTom:ShowHideCoordBlock()
         TomTomBlock:SetHeight(opt.height)
         TomTomBlock:SetWidth(opt.width)

+        -- Set the block position
+        TomTomBlock:ClearAllPoints()
+        if self.profile.block.position then
+            local pos = self.profile.block.position
+            TomTomBlock:SetPoint(pos[1], UIParent, pos[3], pos[4], pos[5])
+        else
+            TomTomBlock:SetPoint("TOP", UIParent, "BOTTOM", -20, -10)
+        end
+
         -- Update the font size
         local font,height = TomTomBlock.Text:GetFont()
         TomTomBlock.Text:SetFont(font, opt.fontsize, select(3, TomTomBlock.Text:GetFont()))
@@ -1041,6 +1051,10 @@ do

     function Block_OnDragStop(self, button, down)
         self:StopMovingOrSizing()
+        self:SetUserPlaced(false)
+        -- point, relativeTo, relativePoint, xOfs, yOfs
+        TomTom.db.profile.block.position = { self:GetPoint() }
+        TomTom.db.profile.block.position[2] = nil  -- Note we are relative to UIParent
     end

     function Block_OnClick(self, button, down)
@@ -1051,6 +1065,12 @@ do
             title = desc,
         })
     end
+
+    function Block_OnEvent(self, event, ...)
+        if (event == "PLAYER_ENTERING_WORLD") then
+            TomTom:ShowHideCoordBlock()
+        end
+    end
 end

 function TomTom:DebugListLocalWaypoints()
diff --git a/TomTom_CrazyArrow.lua b/TomTom_CrazyArrow.lua
index 2baf041..6525832 100755
--- a/TomTom_CrazyArrow.lua
+++ b/TomTom_CrazyArrow.lua
@@ -39,7 +39,6 @@ local twopi = math.pi * 2
 local wayframe = CreateFrame("Button", "TomTomCrazyArrow", UIParent)
 wayframe:SetHeight(42)
 wayframe:SetWidth(56)
-wayframe:SetPoint("CENTER", 0, 0)
 wayframe:EnableMouse(true)
 wayframe:SetMovable(true)
 wayframe:SetClampedToScreen(true)
@@ -63,12 +62,26 @@ end

 local function OnDragStop(self, button)
 	self:StopMovingOrSizing()
+	self:SetUserPlaced(false)
+	-- point, relativeTo, relativePoint, xOfs, yOfs
+	TomTom.profile.arrow.position = { self:GetPoint() }
+	TomTom.profile.arrow.position[2] = nil  -- Note we are relative to UIParent
 end

 local function OnEvent(self, event, ...)
 	if (event == "ZONE_CHANGED_NEW_AREA" or event == "ZONE_CHANGED") and TomTom.profile.arrow.enable then
 		self:Show()
+		return
 	end
+	if (event == "PLAYER_ENTERING_WORLD") then
+        wayframe:ClearAllPoints()
+        if TomTom.profile.arrow.position then
+            local pos = TomTom.profile.arrow.position
+            wayframe:SetPoint(pos[1], UIParent, pos[3], pos[4], pos[5])
+        else
+            wayframe:SetPoint("CENTER", 0, 0)
+        end
+    end
 end

 wayframe:SetScript("OnDragStart", OnDragStart)
@@ -76,6 +89,7 @@ wayframe:SetScript("OnDragStop", OnDragStop)
 wayframe:RegisterForDrag("LeftButton")
 wayframe:RegisterEvent("ZONE_CHANGED_NEW_AREA")
 wayframe:RegisterEvent("ZONE_CHANGED")
+wayframe:RegisterEvent("PLAYER_ENTERING_WORLD")
 wayframe:SetScript("OnEvent", OnEvent)

 wayframe.arrow = wayframe:CreateTexture(nil, "OVERLAY")
@@ -504,7 +518,7 @@ local function wayframe_OnEvent(self, event, arg1, ...)
 	end
 end

-wayframe:SetScript("OnEvent", wayframe_OnEvent)
+wayframe:HookScript("OnEvent", wayframe_OnEvent)

 --[[-------------------------------------------------------------------------
 --  API for manual control of Crazy Arrow