Thread Tools Display Modes
01-15-17, 12:52 PM   #1
Lysiander
An Aku'mai Servant
Join Date: Dec 2007
Posts: 37
Anchoring Player Frame to Blizzard's player Nameplate (Moving one)

Hello all,

I have recently returned to the game. I have an old oUF Layout that I wrote back in MoP and have kept somewhat updated. Im rather fond of it, but the code is old and I have to admit that at this point I have trouble understanding parts of it.

I've fallen in love with the concept of the player bar directly under the character (the one that moves based on the camera angle). I was wondering if it is possible to anchor an oUF Player Frame to that.

I've tried anchoring to the various things that framestack gave me but the only one that works is "NamePlatePlayerResourceFrame" which hides everything but the healthbar from my layout.

I've looked at Blizzards code and as far as I can gather they treat this frame as another nameplate, but I couldn't find anything to hook that would mirror its position.

Is it even possible to achieve?
  Reply With Quote
01-15-17, 07:23 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
The problem I came across doing this is when the game decides it no longer wants to display the player nameplate. It stops moving it in accordance to the camera zoom and pitch. It also isn't created until the first time it decides to be shown, which would be when you enter combat or perform some abilities.

If you insist in still doing this, you could listen for the first time NAME_PLATE_UNIT_ADDED fires for the player by using UnitIsUnit() on the provided NamePlate UnitID. Once the nameplate for the player gets created, it seems to reserve that specific nameplate for the player for the entire session.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
01-17-17, 03:14 PM   #3
Lysiander
An Aku'mai Servant
Join Date: Dec 2007
Posts: 37
I see. Thanks for your input.

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.

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?`
  Reply With Quote
01-18-17, 06:08 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Lysiander View Post
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 View Post
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:
  1. local PlayerPlate,PlayerUF,CloneUF;
  2. hooksecurefunc(NamePlateBaseMixin,"OnAdded",function(self,unit,driver)
  3.     if UnitIsUnit(unit,"player") then
  4. --      Save these to restore later
  5.         PlayerPlate,PlayerUF=self,self.UnitFrame;
  6.  
  7. --      Create our clone if we didn't already
  8.         if not CloneUF then
  9.             CloneUF=CreateFrame("Button","PlayerNamePlateUnitFrame",self,"NamePlateUnitFrameTemplate");
  10.             CloneUF:SetParent(WorldFrame);--    The template writes itself to Parent.UnitFrame, so we're setting the real parent here
  11.             CompactUnitFrame_SetUpFrame(CloneUF,driver.namePlateSetupFunctions.player);
  12.             CloneUF.RaidTargetFrame.RaidTargetIcon:Hide();-- Unused texture on player NamePlate
  13.             CloneUF:EnableMouse(false);--   No mouse interaction
  14.         end
  15.  
  16. --      Now for the deception
  17.         self.UnitFrame=CloneUF;--   Set ourselves as the "official" UnitFrame
  18.         CloneUF:SetAllPoints(self);--   Anchor to the NamePlate
  19.         CompactUnitFrame_SetUnit(PlayerUF,nil);--   Hide old UnitFrame
  20.         CompactUnitFrame_SetUnit(CloneUF,unit);--   Show our clone
  21.     end
  22. end);
  23.  
  24. hooksecurefunc(NamePlateBaseMixin,"OnRemoved",function(self)
  25.     if self==PlayerPlate then
  26. --      Restore the old UnitFrame
  27.         self.UnitFrame=PlayerUF;
  28.  
  29. --      Update unit and freeze positioning
  30.         CompactUnitFrame_SetUnit(CloneUF,"player");
  31.         CloneUF:ClearAllPoints();
  32.  
  33. --      Clear our vars
  34.         PlayerPlate,PlayerUF=nil,nil;
  35.     end
  36. end);
  37.  
  38. hooksecurefunc(NamePlateDriverFrame,"SetupClassNameplateBar",function(self,ontarget,bar)
  39. --  Return if disabled (or not applicable)
  40.     if GetCVar("nameplateShowSelf")=="0" or ontarget or not (CloneUF and NamePlatePlayerResourceFrame and bar) then return; end
  41.  
  42. --  Claim NamePlatePlayerResourceFrame (Similar code to original function with changed parent)
  43.     NamePlatePlayerResourceFrame:SetParent(CloneUF);
  44.     NamePlatePlayerResourceFrame:ClearAllPoints();
  45.     NamePlatePlayerResourceFrame:SetPoint("TOP",CloneUF.healthBar,"BOTTOM",0,-1);
  46.     bar:SetParent(NamePlatePlayerResourceFrame); bar:Show();
  47.     NamePlatePlayerResourceFrame:Layout();
  48.     NamePlatePlayerResourceFrame:Show();
  49. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 01-18-17 at 07:31 AM.
  Reply With Quote
01-26-17, 06:34 AM   #5
Lysiander
An Aku'mai Servant
Join Date: Dec 2007
Posts: 37
Thanks for your help, the code and sorry for the late reply. I'll think about how to best solve this.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Anchoring Player Frame to Blizzard's player Nameplate (Moving one)


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