Quantcast
Why frame never attaches to UIParent? - WoWInterface
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
07-17-19, 01:16 PM   #1
Lybrial
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 86
Why frame never attaches to UIParent?

Hi,

I have the following code:

Lua Code:
  1. function LybrialAnchors:SetupFrames()
  2.     if (not self.anchorFrame) then
  3.         self.anchorFrame = CreateFrame("Frame", "LybrialUIAnchor");
  4.         self.anchorFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED");
  5.         self.anchorFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED");
  6.         self.anchorFrame.Attach = function(self, frame, frameTopLeft, frameBottomRight)
  7.             print("attach: " .. self:GetName());
  8.  
  9.             self:SetParent(frame);
  10.             self:ClearAllPoints();
  11.             self:SetPoint("TOPLEFT", frameTopLeft, "TOPLEFT", 0, 0);
  12.             self:SetPoint("BOTTOMRIGHT", frameBottomRight, "BOTTOMRIGHT", 0, 0);
  13.  
  14.             LybrialAnchors:OnUpdate();
  15.         end
  16.         self.anchorFrame.Detach = function(self)
  17.             print("detach: " .. self:GetName());
  18.  
  19.             self:SetParent(UIParent);
  20.             self:ClearAllPoints();
  21.             self:SetPoint("CENTER", UIParent, "CENTER", 0, -150);
  22.  
  23.             LybrialAnchors:OnUpdate();
  24.         end
  25.         self.anchorFrame.eventHandler = function(_, event, nameplate)
  26.             if (event == "NAME_PLATE_UNIT_ADDED") then
  27.                 if (UnitIsUnit(nameplate, "player")) then
  28.                     if (InCombatLockdown() or C_PetBattles.IsInBattle()) then
  29.                         LybrialAnchors.anchorFrame:Detach();
  30.                     else
  31.                         local frame = C_NamePlate.GetNamePlateForUnit("player");
  32.  
  33.                         if (frame) then
  34.                             LybrialAnchors.anchorFrame:Attach(frame, frame.UnitFrame.healthBar, NamePlateDriverFrame.classNamePlatePowerBar);
  35.                         else
  36.                             LybrialAnchors.anchorFrame:Detach();
  37.                         end
  38.                     end
  39.                 end
  40.             elseif (event == "NAME_PLATE_UNIT_REMOVED") then
  41.                 if (UnitIsUnit(nameplate, "player")) then
  42.                     LybrialAnchors.anchorFrame:Detach();
  43.                 end
  44.             end
  45.         end
  46.  
  47.         self.anchorFrame:SetScript("OnEvent", self.anchorFrame.eventHandler);
  48.     end
  49. end

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.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Why frame never attaches to UIParent?

Thread Tools
Display Modes

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