Thread Tools Display Modes
06-06-17, 04:05 AM   #1
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
How to set an unique style for Player-nameplate in ouf?

Hi all, I just create a style for all the nameplates, but it also changes playerplate.
Is there anyway to leave the playerplate alone?

Lua Code:
  1. local function UpdateColor(self, unit)
  2.     local name = GetUnitName(unit, false) or UNKNOWN
  3.     local status = UnitThreatSituation("player", unit) or false
  4.     local r, g, b
  5.  
  6.     if not UnitIsConnected(unit) then
  7.         r, g, b = .7, .7, .7
  8.     else
  9.         if CustomUnits and CustomUnits[name] then
  10.             r, g, b = 0, .8, .3
  11.         elseif UnitIsPlayer(unit) and UnitReaction(unit, "player") >= 5 then
  12.             if NDuiDB["Nameplate"]["FriendlyCC"] then
  13.                 r, g, b = B.UnitColor(unit)
  14.             else
  15.                 r, g, b = .3, .3, 1
  16.             end
  17.         elseif UnitIsPlayer(unit) and UnitReaction(unit, "player") <= 4 and NDuiDB["Nameplate"]["HostileCC"] then
  18.             r, g, b = B.UnitColor(unit)
  19.         elseif UnitIsTapDenied(unit) and not UnitPlayerControlled(unit) then
  20.             r, g, b = .6, .6, .6
  21.         else
  22.             r, g, b = UnitSelectionColor(unit, true)
  23.             if status and (NDuiDB["Nameplate"]["TankMode"] or DB.Role == "Tank") then
  24.                 if status == 3 then
  25.                     r, g, b = 1, 0, 1
  26.                 elseif status == 2 or status == 1 then
  27.                     r, g, b = 1, .8, 0
  28.                 end
  29.             end
  30.         end
  31.     end
  32.  
  33.     if r or g or b then
  34.         self:SetStatusBarColor(r, g, b)
  35.     end
  36.  
  37.     if not NDuiDB["Nameplate"]["TankMode"] and DB.Role ~= "Tank" then
  38.         if status and status == 3 then
  39.             self.Shadow:SetBackdropBorderColor(1, 0, 0)
  40.         elseif status and (status == 2 or status == 1) then
  41.             self.Shadow:SetBackdropBorderColor(1, 1, 0)
  42.         else
  43.             self.Shadow:SetBackdropBorderColor(0, 0, 0)
  44.         end
  45.     else
  46.         self.Shadow:SetBackdropBorderColor(0, 0, 0)
  47.     end
  48. end
  49.  
  50. local function UpdateThreatColor(self, event, unit)
  51.     if(unit ~= self.unit) then return end
  52.     local element = self.Health
  53.     unit = unit or self.unit
  54.  
  55.     UpdateColor(element, unit)
  56. end
  57.  
  58. local function UpdateTargetMark(self)
  59.     local mark = self.targetMark
  60.     if not mark then return end
  61.  
  62.     if UnitIsUnit(self.unit, "target") and not UnitIsUnit(self.unit, "player") then
  63.         mark:Show()
  64.     else
  65.         mark:Hide()
  66.     end
  67. end
  68.  
  69. lib.CreateNPs = function(self, unit)
  70.     self.mystyle = "nameplate"
  71.     if unit:match("nameplate") then
  72.         self:SetSize(NDuiDB["Nameplate"]["Width"] * 1.4, NDuiDB["Nameplate"]["Height"])
  73.         self:SetPoint("CENTER", 0, -3)
  74.  
  75.         local health = CreateFrame("StatusBar", nil, self)
  76.         health:SetAllPoints()
  77.         B.CreateSB(health)
  78.         B.SmoothBar(health)
  79.         self.Health = health
  80.         self.Health.frequentUpdates = true
  81.         self.Health.UpdateColor = UpdateColor
  82.  
  83.         lib.gen_hpstrings(self)
  84.         lib.gen_castbar(self)
  85.         lib.gen_RaidMark(self)
  86.         lib.HealPrediction(self)
  87.         lib.createAuras(self)
  88.  
  89.         self.power = B.CreateFS(self, 15, "", false, "LEFT", 0, 0)
  90.         self.power:SetPoint("LEFT", self, "RIGHT", 2, 0)
  91.         self:Tag(self.power, "[nppp]")
  92.  
  93.         if NDuiDB["Nameplate"]["Arrow"] then
  94.             local arrow = self:CreateTexture(nil, "OVERLAY")
  95.             arrow:SetSize(50, 50)
  96.             arrow:SetTexture(DB.arrowTex)
  97.             arrow:SetPoint("BOTTOM", self, "TOP", 0, 14)
  98.             arrow:Hide()
  99.             self.targetMark = arrow
  100.         else
  101.             local glow = CreateFrame("Frame", nil, self)
  102.             glow:SetPoint("TOPLEFT", -5, 5)
  103.             glow:SetPoint("BOTTOMRIGHT", 5, -5)
  104.             glow:SetBackdrop({edgeFile = DB.glowTex, edgeSize = 4})
  105.             glow:SetBackdropBorderColor(1, 1, 1)
  106.             glow:SetFrameLevel(0)
  107.             glow:Hide()
  108.             self.targetMark = glow
  109.         end
  110.         self:RegisterEvent("PLAYER_TARGET_CHANGED", UpdateTargetMark)
  111.  
  112.         local cicon = self.Health:CreateTexture(nil, "OVERLAY")
  113.         cicon:SetPoint("LEFT", self, "TOPLEFT", 0, 2)
  114.         cicon:SetSize(15, 15)
  115.         cicon:SetAlpha(.75)
  116.         self.creatureIcon = cicon
  117.  
  118.         local threatIndicator = CreateFrame("Frame", nil, self)
  119.         self.ThreatIndicator = threatIndicator
  120.         self.ThreatIndicator.Override = UpdateThreatColor
  121.     end
  122. end
  123.  
  124. local classtex = {
  125.     rare = {"Interface\\MINIMAP\\ObjectIconsAtlas", .398, .463, .725, .79},
  126.     elite = {"Interface\\MINIMAP\\Minimap_skull_elite", 0, 1, 0, 1},
  127.     rareelite = {"Interface\\MINIMAP\\ObjectIconsAtlas", .398, .463, .926, .991},
  128.     worldboss = {"Interface\\MINIMAP\\ObjectIconsAtlas", .07, .13, .27, .33},
  129. }
  130.  
  131. lib.UpdateNPs = function(self, event, unit)
  132.     UpdateTargetMark(self, event, unit)
  133.  
  134.     local class = UnitClassification(unit)
  135.     if self.creatureIcon then
  136.         if class and classtex[class] then
  137.             local tex, a, b, c, d = unpack(classtex[class])
  138.             self.creatureIcon:SetTexture(tex)
  139.             self.creatureIcon:SetTexCoord(a, b, c, d)
  140.         else
  141.             self.creatureIcon:SetTexture(nil)
  142.         end
  143.     end
  144. end
  145.  
  146. oUF:RegisterStyle("Nameplates", lib.CreateNPs)
  147. oUF:SpawnNamePlates("oUF_NPs", lib.UpdateNPs)

Last edited by siweia : 06-06-17 at 04:08 AM.
  Reply With Quote
06-06-17, 04:55 AM   #2
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Player's nameplate is just a random regular nameplate that's taken from an entire pool of nameplates and then assigned as player's personal nameplate. When it disappears from your screen, e.g., cinematic, auto-hide, etc, and then reappears another random nameplate will be taken from the pool.

So no, there's no way to leave player nameplate alone because technically there's no special player-only nameplate.

Default class power bars work fine, I didn't gut them.
__________________

Last edited by lightspark : 06-06-17 at 06:41 AM.
  Reply With Quote
06-06-17, 05:40 PM   #3
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Basically, Blizzard's "player nameplate" is not a nameplate in reality, it's a normal player unitframe made to look like a nameplate.
  Reply With Quote
06-06-17, 11:54 PM   #4
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by p3lim View Post
Basically, Blizzard's "player nameplate" is not a nameplate in reality, it's a normal player unitframe made to look like a nameplate.
You're soooo wrong

It's a nameplate that's made to look like a unitframe. The moment it's added, power bar, class power and other elements are attached to it. The moment it's removed, all these additional elements are removed too.

When a new nameplate is added, NamePlateDriverMixin:OnNamePlateAdded is called. If nameplate's unit is "player", these two funcs will add all player specific components:
- DefaultCompactNamePlatePlayerFrameSetup sets up castbar, power bar, etc;
- NamePlateDriverMixin.SetupClassNameplateBars adds class power bars.

That's basically what people need to replicate via callbacks. They need to add player-specific components on "NAME_PLATE_UNIT_ADDED", and clean up stuff on "NAME_PLATE_UNIT_REMOVED".
__________________

Last edited by lightspark : 06-07-17 at 12:34 AM.
  Reply With Quote
06-07-17, 03:10 AM   #5
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
So...it would be impossible to style all other plates but leaving playplate in default as well?

Mm, I may try to add a callback through the spawnNameplate.
  Reply With Quote
06-07-17, 03:47 AM   #6
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by siweia View Post
So...it would be impossible to style all other plates but leaving playplate in default as well?
Yes, I explained why.

Originally Posted by siweia View Post
Mm, I may try to add a callback through the spawnNameplate.
Well, you already did, it's your lib.UpdateNPs func, now you have to make it more flexible/smarter
__________________
  Reply With Quote
06-08-17, 06:36 AM   #7
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by lightspark View Post
When a new nameplate is added, NamePlateDriverMixin:OnNamePlateAdded is called. If nameplate's unit is "player", these two funcs will add all player specific components:
- DefaultCompactNamePlatePlayerFrameSetup sets up castbar, power bar, etc;
- NamePlateDriverMixin.SetupClassNameplateBars adds class power bars.

That's basically what people need to replicate via callbacks. They need to add player-specific components on "NAME_PLATE_UNIT_ADDED", and clean up stuff on "NAME_PLATE_UNIT_REMOVED".
Originally Posted by lightspark View Post
Well, you already did, it's your lib.UpdateNPs func, now you have to make it more flexible/smarter
Why isn't this in your nameplate guide? :P
  Reply With Quote
06-08-17, 10:25 PM   #8
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
For some of the WQs, you will get on a mount and throw spells to kill enemies.

At that situation, the player would be your petFrame.

The thing is, the PlayerPlate won't follow the real unit with you, which is your petFrame rightnow.
  Reply With Quote
06-08-17, 10:37 PM   #9
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by siweia View Post
For some of the WQs, you will get on a mount and throw spells to kill enemies.

At that situation, the player would be your petFrame.

The thing is, the PlayerPlate won't follow the real unit with you, which is your petFrame rightnow.
So, does playerplate show vehicle's info? If yes, then it works as intended.
__________________
  Reply With Quote
06-08-17, 11:18 PM   #10
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
Originally Posted by lightspark View Post
So, does playerplate show vehicle's info? If yes, then it works as intended.
For the oUF, no. It shows the random enemy's info.
For the default plate, no. Default Playerplate sticks on player's info.

Last edited by siweia : 06-08-17 at 11:58 PM.
  Reply With Quote
06-09-17, 12:43 AM   #11
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by siweia View Post
For the oUF, no. It shows the random enemy's info.
For the default plate, no. Default Playerplate sticks on player's info.
Hm, that's strange then... Although I do remember that at some point in the past default UI had the same issue.

Could you post your callback's code? If it's something on our end, I'll look at it this weekend.
__________________
  Reply With Quote
06-09-17, 12:55 AM   #12
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
Lua Code:
  1. local function UpdateTargetMark(self)
  2.     local mark = self.targetMark
  3.     if not mark then return end
  4.  
  5.     if UnitIsUnit(self.unit, "target") and not UnitIsUnit(self.unit, "player") then
  6.         mark:Show()
  7.     else
  8.         mark:Hide()
  9.     end
  10. end
  11.  
  12. local function PostUpdatePlates(self, event, unit)
  13.     -- Update Mark
  14.     UpdateTargetMark(self)
  15.  
  16.     -- Unit Classification
  17.     local class = UnitClassification(unit)
  18.     if self.creatureIcon then
  19.         if class and classtex[class] then
  20.             local tex, a, b, c, d = unpack(classtex[class])
  21.             self.creatureIcon:SetTexture(tex)
  22.             self.creatureIcon:SetTexCoord(a, b, c, d)
  23.         else
  24.             self.creatureIcon:SetTexture(nil)
  25.         end
  26.     end
  27.  
  28.     -- Update PlayerPlate
  29.     if event == "NAME_PLATE_UNIT_ADDED" then
  30.         if UnitIsUnit(unit, "player") then
  31.             self.nameFrame:Hide()
  32.             self.Power:Show()
  33.  
  34.         else
  35.             self.nameFrame:Show()
  36.             self.Power:Hide()
  37.         end
  38.     elseif event == "NAME_PLATE_UNIT_REMOVED" then
  39.         self.nameFrame:Hide()
  40.         self.Power:Hide()
  41.     end
  42. end

"self.nameFrame" is the parent for healthBar's name and health value.

How to disable castbar for playerplate? It seems like not working if I just simply show/hide in callbacks.
  Reply With Quote
06-09-17, 01:09 AM   #13
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by siweia View Post
"self.nameFrame" is the parent for healthBar's name and health value.

How to disable castbar for playerplate? It seems like not working if I just simply show/hide in callbacks.
Like w/ any other oUF unit frame, you're better off using unitframe:ElementEnable("element") and unitframe:ElementDisable("element") instead of simple element:Show() and element:Hide().

You need to add this:
Lua Code:
  1. -- enables castbar
  2. if not self:IsElementEnabled("Castbar") then
  3.     self:EnableElement("Castbar")
  4.     self.Castbar:ForceUpdate()
  5. end
  6.  
  7. -- disables castbar
  8. if self:IsElementEnabled("Castbar") then
  9.     self:DisableElement("Castbar")
  10. end

Sorry for numerous edits I'm having a lunch break at work right now
__________________

Last edited by lightspark : 06-09-17 at 01:14 AM.
  Reply With Quote
06-09-17, 01:44 AM   #14
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Question. Player's nameplate disappears when you enter any vehicle and reappears when you exit it. Technically you aren't supposed to see anything, so what exactly are we talking about here? o_O



You mentioned WQs, which ones? Any names, links? That'd help a lot. I'll test it when I get back home in 5 hours and if any is available on EU realms.

P.S. Break is over. I'm off.
__________________

Last edited by lightspark : 06-09-17 at 01:47 AM.
  Reply With Quote
06-09-17, 01:59 AM   #15
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
Originally Posted by lightspark View Post
Like w/ any other oUF unit frame, you're better off using unitframe:ElementEnable("element") and unitframe:ElementDisable("element") instead of simple element:Show() and element:Hide().

You need to add this:
Lua Code:
  1. -- enables castbar
  2. if not self:IsElementEnabled("Castbar") then
  3.     self:EnableElement("Castbar")
  4.     self.Castbar:ForceUpdate()
  5. end
  6.  
  7. -- disables castbar
  8. if self:IsElementEnabled("Castbar") then
  9.     self:DisableElement("Castbar")
  10. end

Sorry for numerous edits I'm having a lunch break at work right now
Love you. <3

Originally Posted by lightspark View Post
Question. Player's nameplate disappears when you enter any vehicle and reappears when you exit it. Technically you aren't supposed to see anything, so what exactly are we talking about here? o_O



You mentioned WQs, which ones? Any names, links? That'd help a lot. I'll test it when I get back home in 5 hours and if any is available on EU realms.

P.S. Break is over. I'm off.
The WQ is "Cry More Thunder!" at Cullen's Post, Stormheim. And some other quests during legion invaion may occur as well. The PlayerPlate shows when you entering combat even in vehicle at that situation.

Last edited by siweia : 06-09-17 at 02:32 AM.
  Reply With Quote
06-09-17, 05:30 AM   #16
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by siweia View Post
The WQ is "Cry More Thunder!" at Cullen's Post, Stormheim. And some other quests during legion invaion may occur as well. The PlayerPlate shows when you entering combat even in vehicle at that situation.
Welp, we'll have to wait till it's available here again o_O It's in WQ rotation yesterday T_T
__________________
  Reply With Quote
06-10-17, 09:57 AM   #17
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
K, it's indeed oUF bug. Thanks for highlighting it <3

Will release an update soon.

-- edit #1

Done.
__________________

Last edited by lightspark : 06-10-17 at 10:40 AM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » How to set an unique style for Player-nameplate in 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