WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Nameplate threat texture (https://www.wowinterface.com/forums/showthread.php?t=45831)

Spyro 02-16-13 05:35 PM

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?

Aanson 02-16-13 11:41 PM

Quote:

Originally Posted by Spyro (Post 273072)
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.

Phanx 02-17-13 01:41 AM

Quote:

Originally Posted by Aanson (Post 273078)
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.

zork 02-17-13 05:29 AM

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.

Aanson 02-17-13 07:21 AM

Quote:

Originally Posted by Phanx (Post 273080)
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.

Spyro 02-17-13 09:28 AM

Quote:

Originally Posted by Aanson (Post 273078)
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)
Quote:

Originally Posted by Aanson (Post 273078)
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.
Quote:

Originally Posted by Phanx (Post 273080)
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.
Quote:

Originally Posted by zork (Post 273085)
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 :D and I thought that showing the threat texture in green to show the "out of combat status" would look pretty cool.


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

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI