Thread Tools Display Modes
11-09-10, 11:20 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Threat check

I want to color some of my textures in threat color.

Has anyone a running threat code to spare.

Not sure if tags can help me much since I need to adjust the VertexColor of textures based on given threat.

What I used in oUF 1.3.x was

function
Code:
  -- check threat
  local function check_threat(self,event,unit)
    if unit then
      if self.unit ~= unit then
        return
      end
      local threat = UnitThreatSituation(unit)
      if threat == 3 then
        self.Portrait_glosst:SetVertexColor(1,0,0)
      elseif threat == 2 then
        self.Portrait_glosst:SetVertexColor(1,0.6,0)
      else
        self.Portrait_glosst:SetVertexColor(0.37,0.3,0.3)
      end
    end
  end
call
Code:
self:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", check_threat)
Is this still the way to go or are there any other options?
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
11-09-10, 11:56 AM   #2
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
This is currently working:

lua Code:
  1. --[[ Colors the border according to the current threat-situation
  2.         VOID UpdateThreat(FRAME self, EVENT event, UNIT unit)
  3.     ]]
  4.     core.UpdateThreat = function(self, event, unit)
  5.         if (unit ~= self.unit) then return end
  6.         local status = UnitThreatSituation(unit)
  7.         if self.threatStatus == status then return end
  8.         if not status then status = 0 end
  9.         self.threatStatus = status
  10.         local r, g, b = unpack(settings.src.threatColors[status])
  11.         lib.SetBorderColor(self, r, g, b)
  12.     end

with

lua Code:
  1. self.Threat = CreateFrame('Frame', self, nil)
  2.         self.Threat.Override = core.UpdateThreat
applied to the frame in question.

Here's SetBorderColor()

lua Code:
  1. --[[ Apply a color to the border
  2.         VOID SetBorderColor(FRAME self, FLOAT r, FLOAT g, FLOAT b)
  3.     ]]
  4.     lib.SetBorderColor = function(self, r, g, b)
  5.         if not self or type(self) ~= "table" then return end
  6.         local i
  7.         if not self.borderTextures then
  8.             lib.CreateBorder(self)
  9.         end
  10.         if not r then
  11.             r, g, b = 0.5, 0.5, 0.5
  12.         end
  13.  
  14.         for i, tex in ipairs(self.borderTextures) do
  15.             tex:SetVertexColor(r, g, b)
  16.         end
  17.     end

and settings.src.threatColors

lua Code:
  1. ['threatColors'] = {
  2.             [0] = { 0.5, 0.5, 0.5 },
  3.             [1] = { 1, 1, 0 },
  4.             [2] = { 1, 1, 0 },
  5.             [3] = { 1, 0.3, 0.3 },
  6.         },
__________________
  Reply With Quote
11-09-10, 03:59 PM   #3
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Using this for ages, no issues.

This will hide the frame (and/or not color the frame) if no threat status, yellow color @2 and red color @3.

Code:
-- threat highlight
local function updateThreatStatus(self, event, u)
	if (self.unit ~= u) then return end
	local s = UnitThreatSituation(u)
	if s and s > 1 then
		local r, g, b = GetThreatStatusColor(s)
		self.ThreatHlt:Show()
		self.ThreatHlt:SetVertexColor(r, g, b, 0.6)
	else
		self.ThreatHlt:Hide()
	end
end
in shared style
Code:
self:RegisterEvent("UNIT_THREAT_LIST_UPDATE", updateThreatStatus)
I'm using a separate (that only shows when there's actually threat) frame for my current layout, though. However, this can be applied to any "normal" frame (like borders or art textures, ...), too.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Threat check


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