Thread Tools Display Modes
09-07-16, 01:24 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Issue with :SetPoint() when moving objects

Hello!

I'm having an issue with moving objects and keeping their positions on the screen when loading saved variables after reloading the UI.

Normal Layout


Layout after moving objects


Layout after reloading UI


Setting data to Saved Variables (after finishing with move)
Lua Code:
  1. point,_,relativePoint,x,y = LargeIconGrpTop:GetPoint(1);
  2. Auras.db.char.frames.eleGrp.LargeIconGrpTopEle.point = point;
  3. Auras.db.char.frames.eleGrp.LargeIconGrpTopEle.relativeTo = "AuraGroupEle";
  4. Auras.db.char.frames.eleGrp.LargeIconGrpTopEle.relativePoint = relativePoint;
  5. Auras.db.char.frames.eleGrp.LargeIconGrpTopEle.x = x;
  6. Auras.db.char.frames.eleGrp.LargeIconGrpTopEle.y = y;

Setting Point(s) upon "Auras:OnEnable()"
Lua Code:
  1. local function InitializeGroup(group,width,height,point,relativeTo,relativePoint,x,y)
  2.     if (width ~= nil) then
  3.         group:SetWidth(width);
  4.         group:SetHeight(height);
  5.     end
  6.     group:ClearAllPoints();
  7.     --group:SetPoint(point,(SSA[relativeTo] or UIParent),relativePoint,x,y); (what I've also tried)
  8.     group:SetPoint(point,x,y)
  9. end
  10.  
  11. local dbEle = Auras.db.char.frames.eleGrp;
  12. for groupObj in pairs(dbEle) do
  13.     InitializeGroup(SSA[groupObj],dbEle[groupObj].width,dbEle[groupObj].height,dbEle[groupObj].point,SSA[dbEle[groupObj].relativeTo],dbEle[groupObj].relativePoint,dbEle[groupObj].x,dbEle[groupObj].y);
  14. end

Last edited by Sweetsour : 09-07-16 at 01:31 PM.
  Reply With Quote
09-07-16, 02:17 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Try:
Code:
group:SetDontSavePosition(true)
__________________
Grab your sword and fight the Horde!
  Reply With Quote
09-07-16, 03:08 PM   #3
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Lombra View Post
Try:
Code:
group:SetDontSavePosition(true)
Hmm, doesn't seem to be making a difference

I should have posted my move start and end code:
Lua Code:
  1. Object:RegisterForDrag("LeftButton"); -- Forgot to add this in the intialization function
  2.  
  3. -- Enable Movement
  4. Object:EnableMouse(true);
  5. Object:SetMovable(true);
  6. Object:SetUserPlaced(true); -- just tried this to no avail
  7. Object:SetScript("OnDragStart", AuraObjects[i].StartMoving);
  8. Object:SetScript("OnDragStop", AuraObjects[i].StopMovingOrSizing);
  9.  
  10. -- Disable Movement
  11. Objects:EnableMouse(false);
  12. Object:SetMovable(false);
  13. Object:SetScript("OnDragStart", nil);
  14. Object:SetScript("OnDragStop", nil);

Last edited by Sweetsour : 09-07-16 at 03:15 PM.
  Reply With Quote
09-07-16, 03:15 PM   #4
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
Err, are you waiting for event ADDON_LOADED with arg1=="<your_addon_name>" before trying to set points from saved variables?
__________________
"In this world nothing can be said to be certain, except that fractional reserve banking is a Ponzi scheme and that you won't believe it." - Mandrill
  Reply With Quote
09-07-16, 03:32 PM   #5
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Banknorris View Post
Err, are you waiting for event ADDON_LOADED with arg1=="<your_addon_name>" before trying to set points from saved variables?
This was something I hadn't thought of. Though, after trying, there still wasn't any difference

I even tried running the :SetPoint() at "PLAYER_LOGIN" and still nothing.
  Reply With Quote
09-07-16, 04:27 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Why are you not using the relativeTo frame returned from GetPoint?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-07-16, 04:37 PM   #7
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by Sweetsour View Post
Hmm, doesn't seem to be making a difference

I should have posted my move start and end code:
Lua Code:
  1. Object:RegisterForDrag("LeftButton"); -- Forgot to add this in the intialization function
  2.  
  3. -- Enable Movement
  4. Object:EnableMouse(true);
  5. Object:SetMovable(true);
  6. Object:SetUserPlaced(true); -- just tried this to no avail
  7. Object:SetScript("OnDragStart", AuraObjects[i].StartMoving);
  8. Object:SetScript("OnDragStop", AuraObjects[i].StopMovingOrSizing);
  9.  
  10. -- Disable Movement
  11. Objects:EnableMouse(false);
  12. Object:SetMovable(false);
  13. Object:SetScript("OnDragStart", nil);
  14. Object:SetScript("OnDragStop", nil);
Do the same for Object instead. (assuming that's not the same frame) Then reload two times.

If you use AceAddon :OnEnable = PLAYER_LOGIN I believe, so that should be fine for using the saved variables. Ideally you'd do it at ADDON_LOADED, though.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
09-07-16, 04:48 PM   #8
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Seerah View Post
Why are you not using the relativeTo frame returned from GetPoint?
I was getting strange results from trying to reference the parent object in the saved variables, so I just keep the parent's name in "relativeTo" part of my saved variables, then access the parent via SSA[relativeTo]

Originally Posted by Lombra View Post
Do the same for Object instead. (assuming that's not the same frame) Then reload two times.

If you use AceAddon :OnEnable = PLAYER_LOGIN I believe, so that should be fine for using the saved variables. Ideally you'd do it at ADDON_LOADED, though.
Sorry, what do you mean by "the same for Object instead"? Also yes, it is the same frame

Last edited by Sweetsour : 09-07-16 at 04:53 PM.
  Reply With Quote
09-07-16, 05:10 PM   #9
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
I just realized something interesting.

In one of the pictures above, it shows the GetPoint values with "point" and "relativePoint" both as "BOTTOM". After further inspection, the row with Flame Shock, Earth Shock, Lava Burst, and Elemental Blast is in the correct location and its point and relativePoint are both still set to "CENTER" (as all the other icons groups' points are set to originally).

However, the two side icons and the other horizontal set of icons get set to "BOTTOM" during the move. It's only these object that have incorrect screen positions after reloading the UI.
  Reply With Quote
09-07-16, 05:48 PM   #10
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Another update:

I setup a script to run "OnUpdate" to display a specific object's :GetPoint() values in real-time as I drag the object. The moment the object becomes draggable, the "relativeTo" display the correct parent object. However, the moment I start dragging it, the "relativeTo" go to "nil". Not sure why this is happening =/
  Reply With Quote
09-07-16, 06:14 PM   #11
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by Sweetsour View Post
Another update:

I setup a script to run "OnUpdate" to display a specific object's :GetPoint() values in real-time as I drag the object. The moment the object becomes draggable, the "relativeTo" display the correct parent object. However, the moment I start dragging it, the "relativeTo" go to "nil". Not sure why this is happening =/
That's because once you start dragging it, it clears all points and positions it relative to the UIParent. (or maybe its own parent, not sure)

Can you post some more code? Can't really tell what's going on from little bits of information here and there. I don't really understand what the exact issue is from the original post. I gather that there is some undesired positioning.

Frames that have a name will have their position automatically saved in layout-cache. (a file in the WTF folder that saves frame positions and dimensions) These values then get loaded and applied at some point in the loading process. (probably after ADDON_LOADED, maybe before PLAYER_LOGIN) This may override or conflict with any anchor points you want to explicitly set yourself. Doing frame:SetDontSavePosition(true) ensures that the frame will not be saved in layout-cache. Other than that it's hard to tell.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
09-07-16, 06:22 PM   #12
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Lombra View Post
That's because once you start dragging it, it clears all points and positions it relative to the UIParent. (or maybe its own parent, not sure)

Can you post some more code? Can't really tell what's going on from little bits of information here and there. I don't really understand what the exact issue is from the original post. I gather that there is some undesired positioning.

Frames that have a name will have their position automatically saved in layout-cache. (a file in the WTF folder that saves frame positions and dimensions) These values then get loaded and applied at some point in the loading process. (probably after ADDON_LOADED, maybe before PLAYER_LOGIN) This may override or conflict with any anchor points you want to explicitly set yourself. Doing frame:SetDontSavePosition(true) ensures that the frame will not be saved in layout-cache. Other than that it's hard to tell.
I managed to do some reading before you posted this, so I now know a lot more about how frames behave when moving them. As a result, it turns out I left an important piece of information out that the objects I was moving were children of a frame that contains them all (in the circumstance where the user would want to move all the objects at once, instead of one at a time).

Thankfully, however, I found someone who ran into the same issue that I did and provided a great fix that seems to be working

Lua Code:
  1. Object:SetScript("OnMouseDown",function(self)
  2.     local framePt,_,parentPt,x,y = self:GetPoint(1)
  3.     self.framePt = framePt
  4.     self.parentPt = parentPt
  5.     self.frameX = x
  6.     self.frameY = y
  7.     self:StartMoving()
  8.     -- once it has done so, we need the starting offset relative to UIParent
  9.     -- so we can determine later what the relative movement was
  10.     _,_,_,x,y = self:GetPoint(1)
  11.     self.screenX = x
  12.     self.screenY = y
  13. end);
  14. Object:SetScript("OnMouseUp",function(self)
  15.     local framePt,_,parentPt,x,y = self:GetPoint(1)
  16.     self:StopMovingOrSizing()
  17.     -- once we have it, subtract the starting screen-offset to get the delta,
  18.     -- and then add that to the starting frame-offset to get a new frame-offset
  19.     x = (x - self.screenX) + self.frameX
  20.     y = (y - self.screenY) + self.frameY
  21.     self:ClearAllPoints()
  22.     self:SetPoint(self.framePt, self:GetParent(), self.parentPt, x, y)
  23.     -- and finally, clean up
  24.     self.framePt = nil
  25.     self.parentPt = nil
  26.     self.frameX = nil
  27.     self.frameY =nil
  28.     self.screenX = nil
  29.     self.screenY = nil
  30. end);

Original thread that I found the solution: https://forums.wowace.com/showthread.php?t=15268

Thank you all for all of your assistance
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issue with :SetPoint() when moving objects


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