--[[----------------------------------------------------------------------- oUF: Stardust - a layout for the oUF framework Copyright (c) 2016 Andrew Mordecai <armordecai@protonmail.ch> This code is released under the zlib license; see LICENSE for details. -------------------------------------------------------------------------]] local _, Stardust = ... oUF.Tags.Events["unitcolor"] = "UNIT_HEALTH UNIT_CLASSIFICATION_CHANGED UNIT_CONNECTION UNIT_FACTION UNIT_REACTION" oUF.Tags.Methods["unitcolor"] = function(unit) local color if UnitIsDeadOrGhost(unit) or not UnitIsConnected(unit) then color = oUF.colors.disconnected elseif UnitIsPlayer(unit) then local _, class = UnitClass(unit) color = oUF.colors.class[class] elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) and not UnitIsTappedByAllThreatList(unit) then color = oUF.colors.tapped elseif UnitIsEnemy(unit, "player") then color = oUF.colors.reaction[1] else color = oUF.colors.reaction[UnitReaction(unit, "player") or 5] end return color and ("|cff%02x%02x%02x"):format(color[1] * 255, color[2] * 255, color[3] * 255) or "|cffffffff" end oUF.Tags.Events["powercolor"] = "UNIT_DISPLAYPOWER" oUF.Tags.Methods["powercolor"] = function(unit) local _, type = UnitPowerType(unit) local color = ns.colors.power[type] or ns.colors.power.FUEL return format("|cff%02x%02x%02x", color[1] * 255, color[2] * 255, color[3] * 255) end local threatcolors = { [0] = "|cffffffff", [1] = "|cffffff33", [2] = "|cffff9933", [3] = "|cffff3333", } oUF.Tags.Events["threatpct"] = "UNIT_THREAT_LIST_UPDATE" oUF.Tags.Methods["threatpct"] = function(unit) local isTanking, status, percentage, rawPercentage = UnitDetailedThreatSituation("player", unit) local pct = rawPercentage if isTanking then pct = UnitThreatPercentageOfLead("player", unit) end if pct and pct > 0 and pct < 200 then return format("%s%d%%", threatcolors[status] or threatcolors[0], pct + 0.5) end end