Hi,
I have the following code:
Lua Code:
function LybrialAnchors:SetupFrames()
if (not self.anchorFrame) then
self.anchorFrame = CreateFrame("Frame", "LybrialUIAnchor");
self.anchorFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED");
self.anchorFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED");
self.anchorFrame.Attach = function(self, frame, frameTopLeft, frameBottomRight)
print("attach: " .. self:GetName());
self:SetParent(frame);
self:ClearAllPoints();
self:SetPoint("TOPLEFT", frameTopLeft, "TOPLEFT", 0, 0);
self:SetPoint("BOTTOMRIGHT", frameBottomRight, "BOTTOMRIGHT", 0, 0);
LybrialAnchors:OnUpdate();
end
self.anchorFrame.Detach = function(self)
print("detach: " .. self:GetName());
self:SetParent(UIParent);
self:ClearAllPoints();
self:SetPoint("CENTER", UIParent, "CENTER", 0, -150);
LybrialAnchors:OnUpdate();
end
self.anchorFrame.eventHandler = function(_, event, nameplate)
if (event == "NAME_PLATE_UNIT_ADDED") then
if (UnitIsUnit(nameplate, "player")) then
if (InCombatLockdown() or C_PetBattles.IsInBattle()) then
LybrialAnchors.anchorFrame:Detach();
else
local frame = C_NamePlate.GetNamePlateForUnit("player");
if (frame) then
LybrialAnchors.anchorFrame:Attach(frame, frame.UnitFrame.healthBar, NamePlateDriverFrame.classNamePlatePowerBar);
else
LybrialAnchors.anchorFrame:Detach();
end
end
end
elseif (event == "NAME_PLATE_UNIT_REMOVED") then
if (UnitIsUnit(nameplate, "player")) then
LybrialAnchors.anchorFrame:Detach();
end
end
end
self.anchorFrame:SetScript("OnEvent", self.anchorFrame.eventHandler);
end
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?