Originally Posted by Lysiander
I couldn't find any reference to the actual positioning, so I assume that the movement part is handled on Blizzards non lua end and is not easily emulated?
|
Correct. The NamePlate positioning is based off sensitive unit and camera position data Blizzard doesn't want us to have access to. It's done by C code, which is the game engine directly manipulating the Lua environment itself.
Originally Posted by Lysiander
I guess I could go with a default position and an OnUpdate event that looks for the nameplate and attaches the frame once it's found it and then moves it back when it vanishes. Not too sure if this is a good idea though.
|
Using an
OnUpdate script is actually a worse approach than I mentioned previously. It's a little more complicated now that they're properly recycling the player NamePlate. I have working prototype code, but it's running into some taint issues.
Lua Code:
local PlayerPlate,PlayerUF,CloneUF;
hooksecurefunc(NamePlateBaseMixin,"OnAdded",function(self,unit,driver)
if UnitIsUnit(unit,"player") then
-- Save these to restore later
PlayerPlate,PlayerUF=self,self.UnitFrame;
-- Create our clone if we didn't already
if not CloneUF then
CloneUF=CreateFrame("Button","PlayerNamePlateUnitFrame",self,"NamePlateUnitFrameTemplate");
CloneUF:SetParent(WorldFrame);-- The template writes itself to Parent.UnitFrame, so we're setting the real parent here
CompactUnitFrame_SetUpFrame(CloneUF,driver.namePlateSetupFunctions.player);
CloneUF.RaidTargetFrame.RaidTargetIcon:Hide();-- Unused texture on player NamePlate
CloneUF:EnableMouse(false);-- No mouse interaction
end
-- Now for the deception
self.UnitFrame=CloneUF;-- Set ourselves as the "official" UnitFrame
CloneUF:SetAllPoints(self);-- Anchor to the NamePlate
CompactUnitFrame_SetUnit(PlayerUF,nil);-- Hide old UnitFrame
CompactUnitFrame_SetUnit(CloneUF,unit);-- Show our clone
end
end);
hooksecurefunc(NamePlateBaseMixin,"OnRemoved",function(self)
if self==PlayerPlate then
-- Restore the old UnitFrame
self.UnitFrame=PlayerUF;
-- Update unit and freeze positioning
CompactUnitFrame_SetUnit(CloneUF,"player");
CloneUF:ClearAllPoints();
-- Clear our vars
PlayerPlate,PlayerUF=nil,nil;
end
end);
hooksecurefunc(NamePlateDriverFrame,"SetupClassNameplateBar",function(self,ontarget,bar)
-- Return if disabled (or not applicable)
if GetCVar("nameplateShowSelf")=="0" or ontarget or not (CloneUF and NamePlatePlayerResourceFrame and bar) then return; end
-- Claim NamePlatePlayerResourceFrame (Similar code to original function with changed parent)
NamePlatePlayerResourceFrame:SetParent(CloneUF);
NamePlatePlayerResourceFrame:ClearAllPoints();
NamePlatePlayerResourceFrame:SetPoint("TOP",CloneUF.healthBar,"BOTTOM",0,-1);
bar:SetParent(NamePlatePlayerResourceFrame); bar:Show();
NamePlatePlayerResourceFrame:Layout();
NamePlatePlayerResourceFrame:Show();
end);