WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Nameplate creation with oUF (https://www.wowinterface.com/forums/showthread.php?t=55770)

Layback_ 09-28-17 08:23 PM

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 :confused:

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?

Layback_ 09-29-17 12:23 AM

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

Kkthnx 09-29-17 10:58 AM

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.

lightspark 09-29-17 09:12 PM

Quote:

Originally Posted by Kkthnx (Post 325330)
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.

Quote:

Originally Posted by Kkthnx (Post 325330)
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.

Layback_ 09-29-17 10:42 PM

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 :confused:

lightspark 09-29-17 10:49 PM

Quote:

Originally Posted by Layback_ (Post 325338)
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 :confused:

It's not a bug, Kkthnx and I already said what you should do:

Quote:

Originally Posted by lightspark (Post 325337)
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.


Layback_ 09-29-17 10:56 PM

Quote:

Originally Posted by lightspark (Post 325339)
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 :banana:

Kkthnx 09-30-17 09:02 AM

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! :eek:

Kkthnx 09-30-17 06:45 PM

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

lightspark 09-30-17 08:41 PM

It happens to all of us :p


All times are GMT -6. The time now is 04:07 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI