WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Restoring frame to previous position (https://www.wowinterface.com/forums/showthread.php?t=49604)

MaLarsson 08-08-14 06:18 PM

Restoring frame to previous position
 
1 Attachment(s)
I'm currently working on an addon that tracks the dots on your target.
I can now display both Hemorrhage and Rupture and move the icons around but the problem is that when I /reload or relog the positioning of the frame is reset to the center of the screen.
I tried using saved variables but did not manage to get any good results even tho I waited until the ADDON_LOADED event fired to use the variable.
I've attached the source code.
Attachment 8167

Phanx 08-08-14 10:06 PM

There's nothing in your code that would save or restore a position.

The simplest method would be to let the game handle it:
Code:

anchor:RegisterForDrag("LeftButton")
anchor:SetMovable(true)
anchor:SetUserPlaced(true)

anchor:SetScript("OnDragStart", anchor.StartMoving)
anchor:SetScript("OnDragStop", anchor.StopMovingOrSizing)

Or, if you want to do it yourself, then you need to save the position into your saved variables table in your OnDragStop script, and restore it when your addon loads.

MaLarsson 08-09-14 10:36 AM

Thanks for the quick reply.

I tried to use the
Lua Code:
  1. anchor:SetUserPlaced(true)
but it did not work and after reading this page wowwiki I omitted that line from my code since:
Quote:

There is usually no need to explicitly call this function; the flag is automatically set by Frame:StartMoving(), and when the frame's position is restored from the layout cache.
Is there something I'm missing? Do I need to add a saved variable in my .toc file for the SetUserPlaced method to work properly?

Lombra 08-09-14 02:44 PM

The frame needs to have a name, for one. (I didn't check your file) The only time you should need to call SetUserPlaced is when you want to save its position after positioning it with SetPoint.

MaLarsson 08-10-14 01:10 PM

I did give the frame a name, this is how i declared all the frames:
Lua Code:
  1. local frame, events = CreateFrame("Frame", "frame", UIParent), {}
  2. local name, realm = nil
  3. local anchor = CreateFrame("Frame", "anchor", UIParent)
  4. local icons = CreateFrame("Frame", "icons", anchor)
  5. local cd = CreateFrame("Cooldown", "cd", icons)
Maybe giving it the same name as the local variable name is a problem.
I will try changing the code a bit when I get home from vacation.
I'll keep you updated when I do, thanks for all the help! :)

Lombra 08-10-14 02:50 PM

Hmm no, the local variable doesn't matter, but frame names are global, and you should absolutely not use such generic names for them. (and not name them at all if avoidable) Use 'DoTrackerFrame' for example. If there's a conflict with some other global variable I guess that might cause a mess. Other than that I'm not sure why it wouldn't work. See if you have an entry for the frame in your layout-cache.txt in the character WTF folder.

Phanx 08-11-14 02:27 AM

Ew, don't know how I missed that. Your frame names (the global names passed to CreateFrame, not the local variable names) are so generic it's likely that even if you get everything else working, some other addon (or even the default UI) will leak globals (hopefully accidentally) with the same names, screwing up your addon or vice versa.

Code:

local frame, events = CreateFrame("Frame", "DoTrackerFrame", UIParent), {}
local name, realm = nil
local anchor = CreateFrame("Frame", "DoTrackerAnchor", UIParent)
local icons = CreateFrame("Frame", "DoTrackerIcon", anchor)
local cd = CreateFrame("Cooldown", "DoTrackerCD", icons)

It's conceivable this is already affecting you; if some other addon is creating globals with the same names (again, hopefully by accident, since this is something you should never, ever do on purpose) then the game is probably not able to save and restore the positions of your frames, just as if they had no global names at all.

zork 08-11-14 06:34 AM

Just in case. Make sure that when using frame:SetUserPlaced(true) the frame is created when you initialize the addon and not via PLAYER_LOGIN event or the like.

MaLarsson 08-11-14 06:49 AM

Oh, didn't realize that the names where in the global namespace. Will fix this when I get home!

Thanks for all the feedback! :D


All times are GMT -6. The time now is 12:23 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI