From 0963719096c2057e2785dd40422b7f7fa18238eb Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Tue, 16 Feb 2010 18:53:14 +0100 Subject: [PATCH] Update tags to the new standard - Also syntax change and cleanup --- oUF_P3lim.lua | 8 ++-- oUF_P3limTags.lua | 110 +++++++++++++++++++++++++++-------------------------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/oUF_P3lim.lua b/oUF_P3lim.lua index fbd43a1..c1514dc 100644 --- a/oUF_P3lim.lua +++ b/oUF_P3lim.lua @@ -132,7 +132,7 @@ local function Style(self, unit) healthValue.frequentUpdates = 1/4 self.Health = health - self:Tag(healthValue, '[p3limhealth]') + self:Tag(healthValue, '[p3lim:health]') if(slimUnit) then local debuffs = CreateFrame('Frame', nil, self) @@ -250,14 +250,14 @@ local function Style(self, unit) powerValue:SetFont(FONT, 8, 'OUTLINE') powerValue:SetJustifyH('LEFT') powerValue.frequentUpdates = 0.1 - self:Tag(powerValue, '[p3limpower][( )p3limdruid]') + self:Tag(powerValue, '[p3lim:power][ >p3lim:druid<]') else local name = health:CreateFontString(nil, 'OVERLAY') name:SetPoint('LEFT', health, 2, 0) name:SetPoint('RIGHT', healthValue, 'LEFT') name:SetFont(FONT, 8, 'OUTLINE') name:SetJustifyH('LEFT') - self:Tag(name, '[p3limname]|cff0090ff[( )rare]|r') + self:Tag(name, '[p3lim:name][|cff0090ff >rare<|r]') end if(unit == 'player' or unit == 'target') then @@ -308,7 +308,7 @@ local function Style(self, unit) info:SetPoint('CENTER') info:SetFont(FONT, 8, 'OUTLINE') info.frequentUpdates = 1/4 - self:Tag(info, '[p3limthreat][( )p3limpvp]') + self:Tag(info, '[p3lim:threat][ >p3lim:pvp<]') buffs.CustomFilter = CustomBuffFilter diff --git a/oUF_P3limTags.lua b/oUF_P3limTags.lua index 07fabc6..7aeb27e 100644 --- a/oUF_P3limTags.lua +++ b/oUF_P3limTags.lua @@ -14,63 +14,65 @@ local function ShortenValue(value) end end -oUF.Tags['[p3limpvp]'] = function(unit) - local running = IsPVPTimerRunning() - if(UnitIsPVP(unit) and not running) then - return '|cffff0000+|r' - elseif(running) then - local timer = GetPVPTimer() - return ('|cffff0000%d:%02d'):format((timer / 1000) / 60, (timer / 1000) % 60) - end -end +for name, func in pairs({ + ['pvp'] = function(unit) + local running = IsPVPTimerRunning() + if(UnitIsPVP(unit) and not running) then + return '|cffff0000+|r' + elseif(running) then + local timer = GetPVPTimer() / 1e3 + return ('|cffff0000%d:%02d|r'):format(timer / 60, timer % 60) + end + end, + ['threat'] = function(unit) + local tanking, status, percent = UnitDetailedThreatSituation('player', 'target') + if(percent and percent > 0) then + return ('%s%d%%|r'):format(Hex(GetThreatStatusColor(status)), percent) + end + end, + ['health'] = function(unit) + local min, max = UnitHealth(unit), UnitHealthMax(unit) + local status = not UnitIsConnected(unit) and 'Offline' or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and 'Dead' -oUF.TagEvents['[p3limthreat]'] = 'UNIT_THREAT_LIST_UPDATE' -oUF.Tags['[p3limthreat]'] = function() - local _, _, perc = UnitDetailedThreatSituation('player', 'target') - local r, g, b = GetThreatStatusColor(UnitThreatSituation('player', 'target')) - return perc and perc > 0 and ('|cff%02x%02x%02x%d%%|r'):format(r * 255, g * 255, b * 255, perc) -end + if(status) then + return status + elseif(unit == 'target' and UnitCanAttack('player', unit)) then + return ('%s (%d|cff0090ff%%|r)'):format(ShortenValue(min), min / max * 100) + elseif(unit == 'player' and min ~= max) then + return ('|cffff8080%d|r %d|cff0090ff%%|r'):format(min - max, min / max * 100) + elseif(min ~= max) then + return ('%s |cff0090ff/|r %s'):format(ShortenValue(min), ShortenValue(max)) + else + return max + end + end, + ['power'] = function(unit) + local _, type = UnitPowerType(unit) + return ('%s%d|r'):format(Hex(oUF.colors.power[type or 'RUNES']), UnitPower(unit)) + end, + ['druid'] = function(unit) + local min, max = UnitPower(unit, 0), UnitPowerMax(unit, 0) + if(UnitPowerType(unit) ~= 0 and min ~= max) then + return ('|cff0090ff%d%%|r'):format(min / max * 100) + end + end, + ['name'] = function(unit) + local reaction = UnitReaction(unit, 'player') -oUF.Tags['[p3limhealth]'] = function(unit) - local min, max = UnitHealth(unit), UnitHealthMax(unit) + local r, g, b = 1, 1, 1 + if((UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) or not UnitIsConnected(unit)) then + r, g, b = 3/5, 3/5, 3/5 + elseif(not UnitIsPlayer(unit) and reaction) then + r, g, b = unpack(oUF.colors.reaction[reaction]) + elseif(UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) then + r, g, b = 1, 0, 0 + end - local status = not UnitIsConnected(unit) and 'Offline' or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and 'Dead' - if(status) then - return status - elseif(unit == 'target' and UnitCanAttack('player', unit)) then - return ('%s (%d|cff0090ff%%|r)'):format(ShortenValue(min), min / max * 100) - elseif(unit == 'player' and min ~= max) then - return ('|cffff8080%d|r %d|cff0090ff%%|r'):format(min - max, min / max * 100) - elseif(min ~= max) then - return ('%s |cff0090ff/|r %s'):format(ShortenValue(min), ShortenValue(max)) - else - return max + return ('%s%s|r'):format(Hex(r, g, b), UnitName(unit)) end +}) do + oUF.Tags['p3lim:'..name] = func end -oUF.Tags['[p3limpower]'] = function(unit) - local _, str = UnitPowerType(unit) - local r, g, b = unpack(ns.colors.power[str]) - return ('|cff%02x%02x%02x%d|r'):format(r or 1* 255, g or 1 * 255, b or 1 * 255, UnitPower(unit)) -end - -oUF.Tags['[p3limdruid]'] = function(unit) - local min, max = UnitPower(unit, 0), UnitPowerMax(unit, 0) - return UnitPowerType(unit) ~= 0 and min ~= max and ('|cff0090ff%d%%|r'):format(min / max * 100) -end - -oUF.TagEvents['[p3limname]'] = 'UNIT_NAME_UPDATE UNIT_REACTION UNIT_FACTION' -oUF.Tags['[p3limname]'] = function(unit) - local reaction = UnitReaction(unit, 'player') - - local r, g, b = 1, 1, 1 - if((UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) or not UnitIsConnected(unit)) then - r, g, b = 3/5, 3/5, 3/5 - elseif(not UnitIsPlayer(unit) and reaction) then - r, g, b = unpack(ns.colors.reaction[reaction]) - elseif(UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) then - r, g, b = 1, 0, 0 - end - - return ('|cff%02x%02x%02x%s|r'):format(r * 255, g * 255, b * 255, UnitName(unit)) -end +oUF.TagEvents['p3lim:name'] = 'UNIT_NAME_UPDATE UNIT_REACTION UNIT_FACTION' +oUF.TagEvents['p3lim:threat'] = 'UNIT_THREAT_LIST_UPDATE' -- 1.7.9.5