Thread Tools Display Modes
07-14-10, 08:37 AM   #1
Bleckpan
A Fallenroot Satyr
 
Bleckpan's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 22
Simple position.

In my addon here, I am trying to figure out how to save the position of where it was before the character logged out. (I attached an attachment just for good measure)

I am new to programming addons, and I can't find just a simple way to save the position so that I can recall it when they log back in. So, how can I save the position and then have the frame go back to that position when you log in?

Please just give me the basics of how to do this if you can.
Thanks in advance.
Attached Files
File Type: lua World_BG.lua (2.6 KB, 664 views)
__________________
“This is my last message to you: in sorrow, seek happiness.”
― Fyodor Dostoyevsky, The Brothers Karamazov

Last edited by Bleckpan : 07-14-10 at 08:38 AM. Reason: Bad grammer
  Reply With Quote
07-14-10, 09:20 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,932
If you are meaning the position of the frame for the addon then for the most part it is automatically saved and restored. The following is what I have been using for most if not all of my addons recently. Just place the functions at the top of your addon and call them as needed.

Code:
--[[ Handle simple movement of the appropriate frame ]]--
local function StartMoving(self,button)
  if ( button ~= "LeftButton" ) 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

--[[ Handle stopping movement for the appropriate frame  ]]--
local function StopMoving(self,button)
  if ( button ~= "LeftButton" ) then return end
  if ( self.isMoving ) then
    self:StopMovingOrSizing();
    self.isMoving = false;
    self.hasMoved = true;
  end
end	

--[[ Unlock the frame so it can be moved.  ]]--
local function UnLock(frame)
  frame.isLocked = false;
  frame:RegisterForDrag("LeftButton");
  frame:EnableMouse(true);
  frame:SetMovable(true);	
  frame:SetScript("OnMouseDown",StartMoving);
  frame:SetScript("OnMouseUp",StopMoving);
  frame:SetScript("OnHide",StopMoving);
end

--[[ Lock the frame from movement ]]--
local function LockFrame (frame)
  frame.isLocked = true;
  frame:RegisterForDrag(nil);
  frame:EnableMouse(false);
  frame:SetMovable(false);
  frame:SetScript("OnMouseDown",nil);
  frame:SetScript("OnMouseUp",nil);
  frame:SetScript("OnHide",nil);
end
And here is an example of the functions in use:
Code:
local function InitialiseFrame()
  local frame = CreateFrame("Frame","MyUniqueFrameName",UIParent);
  frame:SetAlpha(1.0);        
  frame:SetClampedToScreen(true);
  UnLock(frame);
  SetBackDrop(frame);
  InitialiseContents(frame);	
  PositionFrame(frame);
  ResizeFrame(frame);
  ScaleFrame(frame);
  return frame;
end

local function OnEvent(self,event,...)
  if ( event == "ADDON_LOADED" ) then
    if ( arg1 == addonName ) then
      myUniqueFrame = InitialiseFrame(); 	
    end
  elseif ( event == "VARIABLES_LOADED" ) then
    PositionFrame(myUniqueFrame);
  end
end
If you want more control though such as storing the position of the frame yourself and restoring it you need to reposition after the VARIABLES_LOADED event is triggered as at this point blizzard has done the automatic positioning of all frames it has internally kept track of. Despite having access to your own addons WTF data when ADDON_LOADED event is triggered the positioning is adjusted internally which is possibly what you are seeing. It took me a long while to get that through my head.

Hopefully this will help you get that part of your addon down so you can concentrate on the rest of the functionality.
__________________


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 : 07-14-10 at 10:00 AM.
  Reply With Quote
07-14-10, 09:30 AM   #3
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
You might want to be careful with your comment syntax Xrystal
  Reply With Quote
07-14-10, 09:59 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,932
Originally Posted by Slakah View Post
You might want to be careful with your comment syntax Xrystal
Oh ? I know they can't be nested but I use --[[ ]]-- only above function declarations and -- for inside them.

Anything else that I should be aware of with that style of comment ?
__________________


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
  Reply With Quote
07-14-10, 10:55 AM   #5
Bleckpan
A Fallenroot Satyr
 
Bleckpan's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 22
So what you are saying is that when you lock the frame, it will stay right where it is if you were to log out and back in, so it is saved automatically?
__________________
“This is my last message to you: in sorrow, seek happiness.”
― Fyodor Dostoyevsky, The Brothers Karamazov

Last edited by Bleckpan : 07-14-10 at 11:00 AM.
  Reply With Quote
07-14-10, 11:02 AM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,932
Yep. The scripts OnMouseDown/OnMouseUp automatically handle saving position of the frames and gets automatically restored once blizzard updates its own information regarding the frame.

If you choose to Lock the frame it will be immovable by the user once you position it. So you would either position it specifically somewhere and use the Lock function to keep it there or use the UnLock function to allow the user to move the frame where they want and let Blizzard keep track of it for you. Of course you can keep track yourself but that will include quite a few more blocks of code to enforce the store and restore of positioning information.
__________________


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 : 07-14-10 at 11:04 AM.
  Reply With Quote
07-14-10, 11:06 AM   #7
Bleckpan
A Fallenroot Satyr
 
Bleckpan's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 22
So, in the first line right here, I need to replace (frame) with the name of the frame, right?
Code:
local function LockFrame (frame)
  frame.isLocked = true;
  frame:RegisterForDrag(nil);
  frame:EnableMouse(false);
  frame:SetMovable(false);
  frame:SetScript("OnMouseDown",nil);
  frame:SetScript("OnMouseUp",nil);
  frame:SetScript("OnHide",nil);
end
Oh, never mind, that is the variable frame.
__________________
“This is my last message to you: in sorrow, seek happiness.”
― Fyodor Dostoyevsky, The Brothers Karamazov

Last edited by Bleckpan : 07-14-10 at 11:15 AM.
  Reply With Quote
07-14-10, 11:08 AM   #8
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Originally Posted by Xrystal View Post
Oh ? I know they can't be nested but I use --[[ ]]-- only above function declarations and -- for inside them.

Anything else that I should be aware of with that style of comment ?
A multi-lined comment is "-- [[ ]]". This is what Slakah may be referring to. Your ending "--" might cause problems in uncareful situations. (Easy fix though.)

I don't know what else he might be referring to.
__________________
Never be satisfied with satisfactory.
  Reply With Quote
07-14-10, 11:18 AM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,932
Originally Posted by Cralor View Post
A multi-lined comment is "-- [[ ]]". This is what Slakah may be referring to. Your ending "--" might cause problems in uncareful situations. (Easy fix though.)

I don't know what else he might be referring to.
Ah yeah, I saw alot of examples without the -- but saw that the way I am using it didn't have any problems. It just seems imbalanced without the extra -- rofl but yeah, like you said if it causes a problem I can simply remove the --
__________________


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
  Reply With Quote
07-14-10, 11:40 AM   #10
Bleckpan
A Fallenroot Satyr
 
Bleckpan's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 22
Well, now it is broke, but thanks for the help anyways.
__________________
“This is my last message to you: in sorrow, seek happiness.”
― Fyodor Dostoyevsky, The Brothers Karamazov
  Reply With Quote
07-14-10, 11:48 AM   #11
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Originally Posted by Xrystal View Post
Ah yeah, I saw alot of examples without the -- but saw that the way I am using it didn't have any problems. It just seems imbalanced without the extra -- rofl but yeah, like you said if it causes a problem I can simply remove the --
Yeah. I understand! Symmetrical things look nicer!
__________________
Never be satisfied with satisfactory.
  Reply With Quote
07-15-10, 08:38 AM   #12
Bleckpan
A Fallenroot Satyr
 
Bleckpan's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 22
Got it fixed now, thank you so much for your help, I'll give proper credit to you...
__________________
“This is my last message to you: in sorrow, seek happiness.”
― Fyodor Dostoyevsky, The Brothers Karamazov
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Simple position.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off