Reply
Thread Tools Display Modes
Unread 02-16-13, 05:35 PM   #1
Spyro
A Deviate Faerie Dragon
 
Spyro's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2011
Posts: 14
Question Nameplate threat texture

Hi guyz.

I want to show and change the color of the Threat Region of nameplates, that texture that glows with aggro changes etc.

Once I have intercepted the nameplate, I get the Threat Region and then I do a SetVertexColor(0, 1, 0, 1) on it and a Show() to show it in green, but when I do it, nothing happens, the texture doesn't appears. I'm sure I get the region correctly (I saw it on LibNameplate's source code). I also get other regions correctly (name, level, etc).

This is basically what I do

Lua Code:
  1. local function GetThreatRegion(Plate)
  2.   return select(1, (Plate:GetChildren()):GetRegions())
  3. end
  4.  
  5. TheNameplate:SetScript("OnShow", function(Plate)
  6.   GetThreatRegion(Plate):SetVertexColor(0, 1, 0, 1)
  7.   GetThreatRegion(Plate):Show()
  8. )

Anybody that has worked with nameplates knows why?
Spyro is offline   Reply With Quote
Unread 02-16-13, 11:41 PM   #2
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 123
Originally Posted by Spyro View Post
Hi guyz.
Lua Code:
  1. local function GetThreatRegion(Plate)
  2.   return select(1, (Plate:GetChildren()):GetRegions())
  3. end
  4.  
  5. TheNameplate:SetScript("OnShow", function(Plate)
  6.   GetThreatRegion(Plate):SetVertexColor(0, 1, 0, 1)
  7.   GetThreatRegion(Plate):Show()
  8. )
What are you passing to 'GetThreatRegion()'?

If 'TheNameplate' is a stock UI nameplate, is SetScript not a bit dangerous? HookScript does the same as SetScript if no function already exists for the handler in question with the added bonus of not inadvertently removing the script set by Blizz (or another addon). If it's your own nameplate, sorry for misunderstanding.

In your example, is 'TheNameplate' the same object as 'Plate'? If so...

Lua Code:
  1. local nameplate = ?;
  2.  
  3. nameplate:HookScript("OnShow", function(self)
  4.     GetThreatRegion(self):SetVertexColor(0, 1, 0, 1);
  5.     GetThreatRegion(self):Show();
  6. )


If it were me, I'd use print to test the code to make sure you're on the right track. Notably, I'd definitely check the return value of GetThreatRegion().

Lua Code:
  1. print( select( 1, (nameOfNameplate:GetChildren()):GetRegions() ) );

I'm not sure, but using the first return from GetRegions (from the first return of GetChildren) seems a bit off.
__________________
__________________

Last edited by Aanson : 02-16-13 at 11:55 PM.
Aanson is offline   Reply With Quote
Unread 02-17-13, 01:41 AM   #3
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,571
Originally Posted by Aanson View Post
What are you passing to 'GetThreatRegion()'?
That seems pretty obvious just from looking at the snippet he posted and you quoted... Plate is a reference to the nameplate object itself. Am I misinterpreting your question?

Anyway, the whole GetThreatRegion() function is extremely inefficient. You should identify all of the nameplate's children and regions once -- the first time you see the nameplate -- and attach them to the nameplate as table key/value pairs, eg. nameplate.threatRegion = x so you can get a reference to each region from a simple table lookup, instead of needing to do a whole chain of function lookups every time.

See http://www.wowinterface.com/forums/s...ad.php?t=44971 for an example.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 02-17-13, 05:29 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,391
I tried playing with the threat frame when I did my nameplate stuff. Afaik the threatplate aswell as the newly introduced tapped coloring are done via OnUpdate or the like outside of Lua.

You can show it but it will hide itself on the next update because you have no threat state and Blizzard only shows orange or red threat state. Adding any hook to the threat plate does not work. I tried hooking the SetVertexColor function of the threat texture since that had to fire when the threat plate changed threat color. It never did. I would not bother playing with that.
__________________
| Simple is beautiful.
| Roth UI | Roth UI FAQ | GoogleCode | Zork | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
zork is online now   Reply With Quote
Unread 02-17-13, 07:21 AM   #5
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 123
Originally Posted by Phanx View Post
That seems pretty obvious just from looking at the snippet he posted and you quoted... Plate is a reference to the nameplate object itself. Am I misinterpreting your question?
I think so.

Plate is a reference, yes, but I was asking what object was actually getting passed to the func.
__________________
__________________
Aanson is offline   Reply With Quote
Unread 02-17-13, 09:28 AM   #6
Spyro
A Deviate Faerie Dragon
 
Spyro's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2011
Posts: 14
Cool

Originally Posted by Aanson View Post
If 'TheNameplate' is a stock UI nameplate
Sorry if the code wasn't very clear, I wanted to show the idea in a small piece of code, "TheNameplate" was an example of any nameplate I intercept and work with. I get the nameplates with an OnUpdate that runs only when the number of childrens of the WorldFrame changes. This is my PlateProcess() function if you are curious:
Lua Code:
  1. local NumChildren = -1
  2.  
  3. local function PlateProcess()
  4.   if WorldFrame:GetNumChildren() == NumChildren then return end
  5.   NumChildren = WorldFrame:GetNumChildren()
  6.  
  7.   for _, Plate in pairs({WorldFrame:GetChildren()}) do
  8.     if Plate:GetName() and Plate:GetName():find("NamePlate%d") and not Plate.Scripted then
  9.       if Plate:IsVisible() then Plate_OnShow(Plate) end
  10.       Plate:SetScript("OnShow", Plate_OnShow)
  11.       Plate:SetScript("OnHide", Plate_OnHide)
  12.       Plate.Scripted = true
  13.     end
  14.   end
  15. end
  16.  
  17. SpyroTest:SetScript("OnUpdate", PlateProcess)
Originally Posted by Aanson View Post
If it were me, I'd use print to test the code to make sure you're on the right track. Notably, I'd definitely check the return value of GetThreatRegion().
Yeah I already did this and the change applies, but now after the explaniation of zork I know why I doesn't show anything.
Originally Posted by Phanx View Post
Anyway, the whole GetThreatRegion() function is extremely inefficient. You should identify all of the nameplate's children and regions once -- the first time you see the nameplate -- and attach them to the nameplate as table key/value pairs
On my code I do a ThreatRegion = GetThreatRegion(Plate) and then I work with ThreatRegion, but your idea definitely looks better performance-wise and design-wise, I will implement it. I already add information to the nameplate to mark it as "seen" the first time I see it, so it will be easy.
Originally Posted by zork View Post
I tried playing with the threat frame when I did my nameplate stuff...
Thanks for the info, it's impossible then. I will do the color changes in the nameplate border then, it's and addon for Arenas for altering the nameplate of enemys that are out of combat, to do flashy things like Shadow Dance->Sap and I thought that showing the threat texture in green to show the "out of combat status" would look pretty cool.
Spyro is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » Nameplate threat texture

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