Thread Tools Display Modes
04/25/14, 05:21 PM   #1
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
How do I save the location of the frame??

I have my addon working. The only problem I have is I want to make it where, when the user moves the frame around on the screen to a spot they like it at it will save to that location. This way my addon doesn't pop up in the middle of the screen every single time the reload ui or log into the game. If you can please be as detailed as possible because I'm very new to coding and I have only built this addon from using tutorial code.

Here Is my current LUA

Lua Code:
  1. function MyAddonRollDice()
  2.     local num = math.random(1,100)
  3.     return num
  4. end
  5.  
  6. local function OnAddOnLoaded(eventCode, addon)
  7.     if addon == "LootDice" then
  8.         LootDice_SavedVariables = { "LootDice V 1.0", isAddOnEnabled = true}
  9.         d("LootDice_SavedVariables.isAddOnEnabled = "..tostring(LootDice_SavedVariables.isAddOnEnabled))
  10.     end
  11. end
  12.  
  13. EVENT_MANAGER:RegisterForEvent("LootDice", EVENT_ADD_ON_LOADED, OnAddOnLoaded)

Here is my current XML

Lua Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="LootDice" mouseEnabled="true" movable="true">
  4.             <Dimensions x="150" y="42" />
  5.             <Anchor point="CENTER" />              
  6.                        
  7.             <OnMouseDown>
  8.                 Roll = MyAddonRollDice()
  9.                 LootDiceRoll:SetText(Roll)
  10.             </OnMouseDown>
  11.            
  12.             <Controls>
  13.                 <Backdrop name="$(parent)BG" inherits="ZO_ThinBackdrop" />
  14.                 <Label name="$(parent)Roll" font="ZoFontWindowTitle" color="CFDCBD" wrapMode="ELLIPSIS" verticalAlignment="CENTER" horizontalAlignment="CENTER" text="LootDice" >
  15.            
  16.                     <AnchorFill />
  17.                
  18.                 </Label>
  19.             </Controls>
  20.         </TopLevelControl>
  21.     </Controls>
  22. </GuiXml>
  Reply With Quote
04/25/14, 08:50 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
In your OnMouseUp handler, you need to get and save the location of your frame.
  Reply With Quote
04/26/14, 06:14 AM   #3
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Seerah View Post
In your OnMouseUp handler, you need to get and save the location of your frame.
OnMoveStop
  Reply With Quote
04/26/14, 08:53 AM   #4
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
I understand that. Where my problem is, I don't know how to do the code to get the frame location and save the frame location yet.
  Reply With Quote
04/26/14, 11:27 AM   #5
BadVolt
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 74
Originally Posted by zireko View Post
I understand that. Where my problem is, I don't know how to do the code to get the frame location and save the frame location yet.
You can visit wiki to find out.
Lua will save/load only specific tables, you must point manually which one.

As for getting x/y. You can try this:

Saving location to table:
Lua Code:
  1. function MouseUp(self)
  2.     local name = self:GetName()
  3.     local left = self:GetLeft()
  4.     local top = self:GetTop()
  5.  
  6.     if name=="" or name ==nil then  end
  7.     d("Position of "..tostring(name).." saved")
  8.     MB.params[name]={left,top}
  9. end

Using loaded data:
Lua Code:
  1. MB_UI.Menu:SetAnchor(TOPLEFT,MBUI,TOPLEFT,MB.params.MBUI_Menu[1],MB.params.MBUI_Menu[2])

And you have to initialize save/load to SavedVariables.

Be warned, if you are getting topleft coords, you will have to create anchor with topleft attributes.
  Reply With Quote
04/26/14, 03:15 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Originally Posted by Iyanga View Post
OnMoveStop
I didn't misspeak. I use OnMouseUp.
Lua Code:
  1. znb:SetHandler("OnReceiveDrag", function(self)
  2.             --if not db.locked then
  3.                 self:StartMoving()
  4.             --end
  5.         end)
  6.     znb:SetHandler("OnMouseUp", function(self)
  7.             self:StopMovingOrResizing()
  8.             local _,a,_,b,x,y = self:GetAnchor()
  9.             db.anchor = {["a"]=a, ["b"]=b, ["x"]=x, ["y"]=y}
  10.         end)
  Reply With Quote
04/26/14, 03:43 PM   #7
BadVolt
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 74
Originally Posted by Seerah View Post
I didn't misspeak. I use OnMouseUp.
Lua Code:
  1. znb:SetHandler("OnReceiveDrag", function(self)
  2.             --if not db.locked then
  3.                 self:StartMoving()
  4.             --end
  5.         end)
  6.     znb:SetHandler("OnMouseUp", function(self)
  7.             self:StopMovingOrResizing()
  8.             local _,a,_,b,x,y = self:GetAnchor()
  9.             db.anchor = {["a"]=a, ["b"]=b, ["x"]=x, ["y"]=y}
  10.         end)
So do I. But I don't think there's much difference between it in that case.
  Reply With Quote
04/26/14, 05:43 PM   #8
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Seerah View Post
I didn't misspeak. I use OnMouseUp.
My fault, sorry.

I didn't intend to express that you misspoke.

I intended to express that OnMouseUp is as weird for that as would be OnUpdate, as there is the OnMoveStop event. But of course, there are ways to use OnMouseUp or OnUpdate and most likely a lot of other control events that can be used to save the frame position.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » How do I save the location of the frame??


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