Quantcast

-Updated RestoreLayout and SaveLayout to be more uniform with the rest of my addons.

Xruptor [04-18-12 - 15:22]
-Updated RestoreLayout and SaveLayout to be more uniform with the rest of my addons.
Filename
XanDurability.lua
XanDurability.toc
diff --git a/XanDurability.lua b/XanDurability.lua
index ca10e00..da5f482 100644
--- a/XanDurability.lua
+++ b/XanDurability.lua
@@ -209,62 +209,49 @@ function f:UpdatePercent()
 end

 function f:SaveLayout(frame)
-
+	if type(frame) ~= "string" then return end
+	if not _G[frame] then return end
 	if not XanDUR_DB then XanDUR_DB = {} end
+
+	local opt = XanDUR_DB[frame] or nil

-	local opt = XanDUR_DB[frame] or nil;
-
-	if opt == nil then
+	if not opt then
 		XanDUR_DB[frame] = {
 			["point"] = "CENTER",
 			["relativePoint"] = "CENTER",
-			["PosX"] = 0,
-			["PosY"] = 0,
+			["xOfs"] = 0,
+			["yOfs"] = 0,
 		}
-		opt = XanDUR_DB[frame];
+		opt = XanDUR_DB[frame]
+		return
 	end

-	local f = getglobal(frame);
-	local scale = f:GetEffectiveScale();
-	opt.PosX = f:GetLeft() * scale;
-	opt.PosY = f:GetTop() * scale;
-
+	local point, relativeTo, relativePoint, xOfs, yOfs = _G[frame]:GetPoint()
+	opt.point = point
+	opt.relativePoint = relativePoint
+	opt.xOfs = xOfs
+	opt.yOfs = yOfs
 end

 function f:RestoreLayout(frame)
+	if type(frame) ~= "string" then return end
+	if not _G[frame] then return end
+	if not XanDUR_DB then XanDUR_DB = {} end

-	if not XanDUR_DB then XanDUR_DB = {} end
-
-	local f = getglobal(frame);
-	local opt = XanDUR_DB[frame] or nil;
+	local opt = XanDUR_DB[frame] or nil

-	if opt == nil then
+	if not opt then
 		XanDUR_DB[frame] = {
 			["point"] = "CENTER",
 			["relativePoint"] = "CENTER",
-			["PosX"] = 0,
-			["PosY"] = 0,
+			["xOfs"] = 0,
+			["yOfs"] = 0,
 		}
-		opt = XanDUR_DB[frame];
+		opt = XanDUR_DB[frame]
 	end

-	local x = opt.PosX;
-	local y = opt.PosY;
-	local s = f:GetEffectiveScale();
-
-	if (not x or not y) or (x==0 and y==0) then
-		f:ClearAllPoints();
-		f:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
-		return
-	end
-
-	--calculate the scale
-	x,y = x/s,y/s;
-
-	--set the location
-	f:ClearAllPoints();
-	f:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y);
-
+	_G[frame]:ClearAllPoints()
+	_G[frame]:SetPoint(opt.point, UIParent, opt.relativePoint, opt.xOfs, opt.yOfs)
 end

 function f:BackgroundToggle()
diff --git a/XanDurability.toc b/XanDurability.toc
index f65ddf5..475eba3 100644
--- a/XanDurability.toc
+++ b/XanDurability.toc
@@ -2,7 +2,7 @@
 ## Title: xanDurability
 ## Notes: A small window that displays the total current armour durability.
 ## Author: Xruptor
-## Version: 2.4
+## Version: 2.5
 ## SavedVariablesPerCharacter: XanDUR_DB

 xanDurability.lua