07-17-19, 01:16 PM | #1 |
Why frame never attaches to UIParent?
Hi,
I have the following code: Lua Code:
What it should do: It should create a frame and attach that frame to the UIParent by default. But when the player nameplate is getting added AND when im not in combat the frame should get attached to the personal player resources. What it does: It never attaches to the UI Parent. When im in combat and I hide and show the UI again the print method tells me that the "Detach" was called but still the frame is getting anchored to the nameplate. I dont get how this is possible. It is always attaching to the nameplate even though the print method tells me the "Detach" method is getting called. Anyone an idea why this is happening? Last edited by Lybrial : 07-17-19 at 11:29 PM. |
|
07-18-19, 10:40 AM | #2 |
I haven't tested this but ...
Shouldn't it be: Code:
print("attach: " .. (self.anchorFrame:GetParent()):GetName()); Code:
print("detach: " .. (self.anchorFrame:GetParent()):GetName()); |
|
07-18-19, 10:51 AM | #3 |
Name doesnt matter. I just wanted to make sure that "Detach" is getting called.
But yes, If I would want to output the parent frame you would be right. Code:
print("detach: " .. (self:GetParent()):GetName()) Still all frames are still attached to nameplate and not UIParent. Last edited by Lybrial : 07-18-19 at 10:57 AM. |
|
07-18-19, 11:23 AM | #4 |
Oh, right, I see your point now.
Still, on a second look at your code, you are passing self as argument to self.anchorFrame.Attach(self) and to self.anchorFrame.Detach(self). You then call frame methods on self that I believe you want to be called on self.anchorFrame instead. I'm unsure about this, but that may be the problem. If I'm right, the easy fix would be to use self.anchorFrame as prefix to :SetParent, etc. |
|
07-18-19, 11:38 AM | #5 |
In this case self is the anchorFrame
Look what happens if I add some outputs to Detach function: Lua Code:
output: Code:
Detach called attached to: NamePlate1 Last edited by Lybrial : 07-18-19 at 11:45 AM. |
|
07-18-19, 03:23 PM | #6 |
You are right and I would agree the output of your prints does not make sense.
That is actually why I went ahead and guessed at the possibility that the use of the reserved word "self" as a parent table to the frame itself might be causing a problem. In other words, I understood the logic of your use of "self" and it is correct AFAIK, but there have been times where the WoW API seems to contradict Lua logic (maybe I just don't get it but... recently I got a C_Stack_Overflow on a semi-personal addon of mine (and I couldn't figure out why); come Blizzard's latest hotfixes and the error was gone!). Getting back to your case, have you tried :SetParent(nil) before setting a new parent? I know, should not be needed, but... |
|
07-18-19, 05:05 PM | #7 | |
To my knowledge one of the more recent updates included a change to anchoring, including Nameplates. With it came the change that you can only anchor children of a Nameplate to the plate itself or one of its other children.
Blue post summary:
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison |
||
07-19-19, 01:48 AM | #8 |
And that happens even if you clearAllPoints() Oo
God I hate these 8.2 changes, seriously.... |
|
07-19-19, 03:53 AM | #9 |
And in the light of jeruku's post, I winged up an addon with your (slightly edited) code and my previous suggestion does work. I.e.:
Lua Code:
Code:
Detach called attached to: UIParent Furthermore, :GetPoint should be added to the list jeruku quoted under "The following APIs are now blocked from being called on restricted frames:" If you add thiese two lines to the end of the snippet above: Lua Code:
Code:
Detach called attached to: UIParent at point #1: CENTER, UIParent, CENTER, 0, -150 Code:
Message: Interface\AddOns\alkaTestLyabral\alkaTestLyabral.lua:22: Action[FrameMeasurement] failed because[Can't measure restricted regions]: attempted from: LybrialUIAnchor:GetPoint(). Time: Fri Jul 19 10:47:09 2019 Count: 1 Stack: Interface\AddOns\alkaTestLyabral\alkaTestLyabral.lua:22: Action[FrameMeasurement] failed because[Can't measure restricted regions]: attempted from: LybrialUIAnchor:GetPoint(). [C]: in function `GetPoint' Interface\AddOns\alkaTestLyabral\alkaTestLyabral.lua:22: in function `Attach' Interface\AddOns\alkaTestLyabral\alkaTestLyabral.lua:64: in function <Interface\AddOns\alkaTestLyabral\alkaTestLyabral.lua:55> Locals: (*temporary) = LybrialUIAnchor { 0 = <userdata> Attach = <function> defined @Interface\AddOns\alkaTestLyabral\alkaTestLyabral.lua:12 Detach = <function> defined @Interface\AddOns\alkaTestLyabral\alkaTestLyabral.lua:32 TestTexture = <unnamed> { } eventHandler = <function> defined @Interface\AddOns\alkaTestLyabral\alkaTestLyabral.lua:55 } (*temporary) = 1 Finally, I also created a texture on the frame. And it's weird. The texture reportedly attaches correctly to the frame, wich on Detach is reportedly positioned at "CENTER, UIParent, CENTER, 0, -150". Code: Lua Code:
Code:
Detach called attached to: UIParent at point #1: CENTER, UIParent, CENTER, 0, -150 Texture at point #1: TOPLEFT, LybrialUIAnchor, TOPLEFT, 0, 0 I'm actually rather unfamiliar with working with textures, so I may be missing something. For reference, here's the full code I ran: Lua Code:
I'll be going back to my own nerve-wrecking projects now. But if anyone has any more insight on any of this, I'd be curious. And... happy coding, Lybrial! |
|
WoWInterface » Developer Discussions » Lua/XML Help » Why frame never attaches to UIParent? |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|