View Single Post
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