Quantcast Nameplate creation with oUF - WoWInterface
Thread Tools Display Modes
09-28-17, 08:23 PM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
Nameplate creation with oUF

Hi all,

Just now, I've started to create a nameplate for my UI with oUF and I guess the main task is coloring the health bar (I wanna override oUF's built-in ColorUpdate function so...) based on each different cases like:
  • Is unit an enemy?
  • What's unit's reaction type?
  • Is unit NPC?
  • Is unit a player controlled?
  • Am I a tanking those units (Aggro, a threat situation)?

and so on.

I am pretty sure there are more cases that I should consider, but I ain't sure of what they could be

Any ideas, please?



-- EDIT #1

Okay, I made a super simple prototype which currently has health bar, health text and name text only, but clicking a nameplate doesn't seem to select a target.

Do I have to register "OnClick" script which calls "TargetUnit" function?



-- EDIT #2

And about aura creation, should I just use aura element built in oUF?

Last edited by Layback_ : 09-28-17 at 10:09 PM.
  Reply With Quote
09-29-17, 12:23 AM   #2
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
I think I found a bug.

Before we go further, please have a look at the following video.
(Seems like I can't embed a video on post )

https://youtu.be/nyx3-vpUidA

So what is happening here is that I have cast "Brutal Slash", an AOE skill of feral druid that deals a certain amount of damage to nearby enemies.

However, as you can see, the health bar is only updated for an enemy that is currently selected as a target.

My code currently doesn't do that much and pretty sure I didn't touch anything from nameplate element in oUF.

Lua Code:
  1. function UM:CreateNameplate(frame)
  2.     local LSM = LibStub("LibSharedMedia-3.0");
  3.     local flatsmooth = LSM:Fetch("statusbar", "flatsmooth");
  4.     local fer28 = LSM:Fetch("statusbar", "fer28");
  5.     local MeatEdition = LSM:Fetch("font", "MeatEdition");
  6.     local fer8 = LSM:Fetch("border", "fer8");
  7.  
  8.     frame:SetSize(128, 16);
  9.     frame:SetPoint("CENTER");
  10.  
  11.     -- Health
  12.     local health = CreateFrame("StatusBar", "$parentHealth", frame);
  13.     health:SetStatusBarTexture(flatsmooth);
  14.     health:SetAllPoints();
  15.     health:SetBackground(0.15, 0.15, 0.15);
  16.  
  17.     local border = CreateFrame("Frame", "$parentBorder", health);
  18.     border:SetPoint("CENTER");
  19.     border:SetSize(health:GetWidth() + 2, health:GetHeight() + 2);
  20.     border:SetBackdrop({
  21.         edgeFile = fer8,
  22.         edgeSize = 8,
  23.     });
  24.  
  25.     local healthText = health:CreateFontString("$parentText", "OVERLAY");
  26.     healthText:SetFont(MeatEdition, 8, "OUTLINE");
  27.     healthText:SetPoint("RIGHT", -2, 0);
  28.  
  29.     frame:Tag(healthText, "[perhp]%");
  30.  
  31.     frame.Health = health;
  32.  
  33.     frame.border = border;
  34.     frame.healthText = healthText;
  35.  
  36.     -- NameText
  37.     local nameText = frame:CreateFontString("$parentNameText", "OVERLAY");
  38.     nameText:SetParent(frame.border);
  39.     nameText:SetFont(MeatEdition, 10, "OUTLINE");
  40.     nameText:SetPoint("BOTTOMLEFT", frame, "TOPLEFT", 0, 2);
  41.  
  42.     frame:Tag(nameText, "[smartlevel] [raidcolor][name]|r");
  43.  
  44.     frame.NameText = nameText;
  45. end

Last edited by Layback_ : 09-29-17 at 12:32 AM.
  Reply With Quote
09-29-17, 10:58 AM   #3
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 244
I have noticed this issue too, I fixed it by applying this in my CallbackUpdate

Lua Code:
  1. self:EnableMouse(false) -- For some off reason we need this so we can click our plates..??
  2. self.Health:EnableMouse(false) -- For some off reason we need this so we can click our plates..??

Just so you know the callback is called when you spawn them

Lua Code:
  1. oUF:SpawnNamePlates("KkthnxUINamePlates", CallbackUpdate, CVarUpdate)

@lightspark might be able to spread some more info on this as to why this happens.

Be sure you are applying self.Health.frequentUpdates = true in your code

Also yes you can use the auras creation off oUF.
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.

Last edited by Kkthnx : 09-29-17 at 11:03 AM.
  Reply With Quote
09-29-17, 09:12 PM   #4
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 328
Originally Posted by Kkthnx View Post
I have noticed this issue too, I fixed it by applying this in my CallbackUpdate

Lua Code:
  1. self:EnableMouse(false) -- For some off reason we need this so we can click our plates..??
  2. self.Health:EnableMouse(false) -- For some off reason we need this so we can click our plates..??
That's just how nameplates are, you have to click nameplate's base frame that's created and managed by Blizz to interact w/ the unit, otherwise, stuff gets really wonky.

But why do you explicitly disable mouse events? o_O They should be disabled by default, well, unless you do something that enables them.

Originally Posted by Kkthnx View Post
Be sure you are applying self.Health.frequentUpdates = true in your code
Yeah, you have to have nameplate health bars registered for "UNIT_HEALTH_FREQUENT" , even default ones use this event, and as you said it's done by setting `Health.frequentUpdates` to true.
__________________

Last edited by lightspark : 09-29-17 at 09:17 PM.
  Reply With Quote
09-29-17, 10:42 PM   #5
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
Thanks to both Kkthnx and lightspark.

I just revised my code and found that I had the following lines of code:

Lua Code:
  1. frame:SetScript("OnEnter", UnitFrame_OnEnter);
  2. frame:SetScript("OnLeave", UnitFrame_OnLeave);

What I thought was as long as I don't enable a mouse these functions would not run, but seems like these would automatically enable mouse even if I don't manually enable them.

Good practice haha!!



But lightspark, do you know what is going on with a bug on the video?

I really can't figure out why this is happening

Last edited by Layback_ : 09-29-17 at 11:01 PM.
  Reply With Quote
09-29-17, 10:49 PM   #6
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 328
Originally Posted by Layback_ View Post
But lightspark, do you know what is going on with a bug on the video?

I really can't figure out why this is happening
It's not a bug, Kkthnx and I already said what you should do:

Originally Posted by lightspark View Post
Yeah, you have to have nameplate health bars registered for "UNIT_HEALTH_FREQUENT" , even default ones use this event, and as you said it's done by setting `Health.frequentUpdates` to true.
__________________
  Reply With Quote
09-29-17, 10:56 PM   #7
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
Originally Posted by lightspark View Post
It's not a bug, Kkthnx and I already said what you should do:
Damn... Was that the answer to that thingy?

Sorry, my bad haha;;;;


-- EDIT #1

Thank you, it's working perfectly

Last edited by Layback_ : 09-29-17 at 10:59 PM.
  Reply With Quote
09-30-17, 09:02 AM   #8
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 244
If you need any further help please do ask! We will be more than happy to help! @lightspark, I will show a video about the whole EnableMouse(false) deal later today after I get my coffee and get my kids off with their aunt!
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.
  Reply With Quote
09-30-17, 06:45 PM   #9
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 244
Okay okay. I am dumb. Figured it out.

This code is preventing the clicks.
Lua Code:
  1. self:SetScript("OnEnter", function()
  2.         ShowUIPanel(GameTooltip)
  3.         GameTooltip:SetOwner(self, "ANCHOR_NONE")
  4.         GameTooltip:SetUnit(self.unit)
  5.         GameTooltip:Show()
  6.     end)
  7.     self:SetScript("OnLeave", function()
  8.         GameTooltip:Hide()
  9.     end)
  10.     self.hooked = true
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.

Last edited by Kkthnx : 09-30-17 at 07:01 PM.
  Reply With Quote
09-30-17, 08:41 PM   #10
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 328
It happens to all of us
__________________
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Nameplate creation with oUF

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