From c805435e62c0f38876245255a012a72990e9d4a1 Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Sun, 27 Jun 2010 06:27:02 +0200 Subject: [PATCH] Don't use an unnessisary table --- oUF_P3lim.lua | 103 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/oUF_P3lim.lua b/oUF_P3lim.lua index 052b2e8..878a037 100644 --- a/oUF_P3lim.lua +++ b/oUF_P3lim.lua @@ -21,63 +21,62 @@ local function ShortenValue(value) end end -for name, func in pairs({ - ['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' - - 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 power = UnitPower(unit) - if(power > 0 and not UnitIsDeadOrGhost(unit)) then - local _, type = UnitPowerType(unit) - local colors = _COLORS.power - return ('%s%d|r'):format(Hex(colors[type] or colors['RUNES']), power) - end - 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') - - 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(_COLORS.reaction[reaction]) - elseif(UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) then - r, g, b = 1, 0, 0 - end +oUF.TagEvents['p3lim:threat'] = 'UNIT_THREAT_LIST_UPDATE' +oUF.Tags['p3lim: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 + +oUF.Tags['p3lim: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' + + 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 + +oUF.Tags['p3lim:power'] = function(unit) + local power = UnitPower(unit) + if(power > 0 and not UnitIsDeadOrGhost(unit)) then + local _, type = UnitPowerType(unit) + local colors = _COLORS.power + return ('%s%d|r'):format(Hex(colors[type] or colors['RUNES']), power) + end +end - return ('%s%s|r'):format(Hex(r, g, b), UnitName(unit)) +oUF.Tags['p3lim: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 -}) do - oUF.Tags['p3lim:'..name] = func end oUF.TagEvents['p3lim:name'] = 'UNIT_NAME_UPDATE UNIT_REACTION UNIT_FACTION' -oUF.TagEvents['p3lim:threat'] = 'UNIT_THREAT_LIST_UPDATE' +oUF.Tags['p3lim:name'] = 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(_COLORS.reaction[reaction]) + elseif(UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) then + r, g, b = 1, 0, 0 + end + + return ('%s%s|r'):format(Hex(r, g, b), UnitName(unit)) +end local function SpawnMenu(self) ToggleDropDownMenu(1, nil, _G[string.gsub(self.unit, '^.', string.upper)..'FrameDropDown'], 'cursor') -- 1.7.9.5