Thread Tools Display Modes
03/24/15, 06:41 AM   #1
Woeler
 
Woeler's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 40
Save position to saved variables

Hello all,

I'm currently making my first addon, a very simple one. I would like to know how I can save the position of the addon to the saved variables once the user moves it to a certain position.

Thanks!
  Reply With Quote
03/24/15, 07:03 AM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Example In Lua:

Lua Code:
  1. local savedVariables --local reference for saved variables, actual object will be assigned later in EVENT_ADD_ON_LOADED event handler
  2. local defaults = { --default values for saved variables
  3.     offsetX = 200,
  4.     offsetY = 200,
  5. }
  6.  
  7. --event handler for OnMoveStop
  8. local function OnMoveStop(self)
  9.     savedVariables.offsetX = self:GetLeft()
  10.     savedVariables.offsetY = self:GetTop()
  11. end
  12.  
  13. --event handler for EVENT_ADD_ON_LOADED
  14. local function OnAddonLoaded(event, addonName)
  15.     if addonName == "YourAddon" then --addonName is in general name of your addon manifext without .txt extension
  16.  
  17.         EVENT_MANAGER:UnregisterForEvent("myUniqueEventHandlerName", EVENT_ADD_ON_LOADED)
  18.  
  19.         --saved variables (in this case account wide)
  20.         savedVariables = ZO_SavedVars:NewAccountWide("savedVariablesNameDefinedInAddonManifest", 1, "namespace", defaults)
  21.  
  22.         --create top level window, so we have something to work with
  23.         local tlw = WINDOW_MANAGER:CreateTopLevelWindow()
  24.         tlw:SetDimensions(128,128)
  25.         tlw:SetMouseEnabled(true) --enable mouse events for this window, so it will handle mouse clicks, drags etc.
  26.         tlw:SetClampedToScreen(true) --make sure that you can't drag window off the screen
  27.         tlw:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, savedVariables.offsetX, savedVariables.offsetY) --restore window position from saved variables
  28.         tlw:SetHandler("OnMoveStop", OnMoveStop) --set handler to event "OnMoveStop", it means when you stop moving the window
  29.         tlw:SetHidden(false) --set window visible
  30.         local texture = WINDOW_MANAGER:CreateControl(nil, tlw, CT_TEXTURE) --texture, so there will be something visible
  31.         texture:SetTexture("/esoui/art/icons/poi/poi_groupboss_complete.dds")
  32.         texture:SetAnchorFill(tlw)
  33.     end
  34. end
  35.  
  36. EVENT_MANAGER:RegisterForEvent("myUniqueEventHandlerName", EVENT_ADD_ON_LOADED, OnAddonLoaded)

Last edited by Garkin : 03/24/15 at 07:16 AM.
  Reply With Quote
03/24/15, 10:31 AM   #3
Woeler
 
Woeler's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 40
Thanks Garkin! I got it working!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Save position to saved variables


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