View Single Post
04-22-10, 05:11 PM   #19
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Originally Posted by eddiemars View Post
Wow, okay. Saved Variables making is so confusing! I've followed a couple guides (ie: http://www.wowwiki.com/Saving_variab..._game_sessions) but, none of them explain how to put frame placement info into the savedvariable file. I'm sure it's supposed to be self explanatory but I am very lost. Anyone know a better (or more frame specific) tutorial for this? Or maybe you enjoy helping out nubs, for those of you that do I will include the very bungled .lua I have going on. As it is right now, it just does nothing. If you think the file is a total lost cause by all means don't feel compelled to help out just because I'm asking! I understand! I do however truly appreciate all the help.
*snipped*
This is how I've recently cottoned onto dealing with it.

I have in my SavedVariables table these set of values:
Code:
	["ptSelf"] = "CENTER",
	["anchor"] = "UIParent",
	["ptAnchor"] = "CENTER",
	["xOffset"] = 0,
	["yOffset"] = 0,
I have the anchor in text to store the name of the frame that is being used as an anchor. It's easier to do _G[name] to get the frame than to have the frame not store in the saved variables ... *table omitted etc comment in WTF files rofl*

This is how I initially fill the table up after the frame has been created. I have a set of hard coded defaults set up that the addon can fall back onto if problems arise or the user after doing some customising gets messed up and whats to reset everything rofl.
Code:
xsf.InitialiseVariables = function(self)
	XSF_Data = XSF_Data or {};
	XSF_Data[self:GetName()] = XSF_Data[self:GetName()] or {};
	self.Data = XSF_Data[self:GetName()];
				
	self.Data["ptSelf"] 		= self.Data["ptSelf"] 			or self.Defaults["ptSelf"];
	self.Data["anchor"] 		= self.Data["anchor"] 			or self.Defaults["anchor"];
	self.Data["ptAnchor"] 		= self.Data["ptAnchor"] 		or self.Defaults["ptAnchor"];
	self.Data["xOffset"]		= self.Data["xOffset"] 			or self.Defaults["xOffset"];
	self.Data["yOffset"] 		= self.Data["yOffset"] 			or self.Defaults["yOffset"];
end
I then have these scripts set up to carry out the movement and when it is finished store the final anchor position. xsf being the name of the frame in question.

Code:
	xsf.OnMouseDown = function(self)
		if ( not self ) then return; end
		if ( ( not self.isLocked ) or ( self.isLocked == 0 ) ) then
			if ( self:IsMovable() ) then
				self:StartMoving();
				self.isMoving = true;
				self.hasMoved = false;
			end
		end
	end

	xsf.OnMouseUp = function(self)
		if ( not self ) then return; end
		if ( self.isMoving ) then
			self:StopMovingOrSizing();
			if ( self.isMoving ) then
				self.isMoving = false;
				self.hasMoved = true;
			end
		end
		if ( self.hasMoved and self.StoreAnchor ) then
			self:StoreAnchor();
		end
	end	

	xsf.OnHide = function(self)
		if ( not self ) then return; end
		if ( self.isMoving ) then
			self:StopMovingOrSizing();
			self.isMoving = false;
		end
	end
I then have 3 anchor functions. StoreAnchor, GetAnchor and SetAnchor as follows. self.Data is a table link to the saved variables table segment for this frame:
Code:
xsf.SetAnchor = function(self)
	if ( self.isLocked ) then return end
	local ptSelf = self.Data["ptSelf"];
	local anchor = self.Data["anchor"];
	local ptAnchor = self.Data["ptAnchor"];
	local xOffset = self.Data["xOffset"];
	local yOffset = self.Data["yOffset"];
	self:ClearAllPoints();
	self:SetPoint(ptSelf,_G[anchor],ptAnchor,xOffset,yOffset);
end

xsf.GetAnchor = function(self)
	ptSelf,anchor,ptAnchor,xOffset,yOffset = self:GetPoint(1);	
	if ( anchor ) then
		anchor = anchor:GetName();
	else
		anchor = self:GetParent():GetName();
	end
	return ptSelf,anchor,ptAnchor,xOffset,yOffset; 
end
	
xsf.StoreAnchor = function(self)	
	local ptSelf,anchor,ptAnchor,xOffset,yOffset = self:GetAnchor();
	if ( not ptSelf ) then
		ptSelf = self.Data["ptSelf"];
		anchor = self.Data["anchor"];
		ptAnchor = self.Data["ptAnchor"];
		xOffset = self.Data["xOffset"];
		yOffset = self.Data["yOffset"];
	end
	self.Data["ptSelf"] = ptSelf;
	self.Data["anchor"] = anchor;
	self.Data["ptAnchor"] = ptAnchor;
	self.Data["xOffset"] = xOffset;
	self.Data["yOffset"] = yOffset;
end
And here is the resulting WTF saved variables output since I last logged out after playing with this code. Notice it keeps track of the 'nearest anchor point' that blizz automatically uses to anchor too.:
Code:
XSF_Data = {
	["XSFrame"] = {
		["ptAnchor"] = "CENTER",
		["yOffset"] = -11.31710682698755,
		["xOffset"] = 0.9366468145787907,
		["anchor"] = "TestFrame",
		["ptSelf"] = "CENTER",
	},
}
So basically I do the following:

1. Initialise anchor as center of UIParent.
2. Make any necessary changes to anchor if the parent is no longer UIParent.
3. After moving the frame store the anchor settings.
4. After blizzard has finished its own frame movement code ( VARIABLES_LOADED) then SetAnchor to what we last stored it as.

I have some other functions set up as well to handle changes on an addon by addon basis as this is all in a file that I plan to make generic to all my addons needing its functionality but this is enough to handle a one on one frame setup.

So far it has been working as I expected. You could even validate what GetPoint returns and change it if you want it to store it a different way. Also, you could always add extra points and utilise GetPoint and the other functions to handle all points the frames have and save them all. In my case the anchors being saved are generally single anchors so I haven't needed to expand onto that area yet
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 04-22-10 at 05:17 PM.
  Reply With Quote