WoWInterface SVN oUF_P3lim

[/] [trunk/] [oUF_P3lim/] [customtags.lua] - Blame information for rev 86

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 85 p3lim-52096
local format = string.format
2 p3lim-52096
local gsub = string.gsub
3 p3lim-52096
 
4 p3lim-52096
local colors = setmetatable({
5 p3lim-52096
        power = setmetatable({
6 p3lim-52096
                ['MANA'] = {0, 144/255, 1}
7 p3lim-52096
        }, {__index = oUF.colors.power}),
8 p3lim-52096
        reaction = setmetatable({
9 p3lim-52096
                [2] = {1, 0, 0},
10 p3lim-52096
                [4] = {1, 1, 0},
11 p3lim-52096
                [5] = {0, 1, 0}
12 p3lim-52096
        }, {__index = oUF.colors.reaction}),
13 p3lim-52096
}, {__index = oUF.colors})
14 p3lim-52096
 
15 p3lim-52096
local function shortVal(value)
16 p3lim-52096
        if(value >= 1e6) then
17 p3lim-52096
                return ('%.2fm'):format(value / 1e6):gsub('%.?0+([km])$', '%1')
18 p3lim-52096
        elseif(value >= 1e4) then
19 p3lim-52096
                return ('%.1fk'):format(value / 1e3):gsub('%.?0+([km])$', '%1')
20 p3lim-52096
        else
21 p3lim-52096
                return value
22 p3lim-52096
        end
23 p3lim-52096
end
24 p3lim-52096
 
25 p3lim-52096
local function hex(r, g, b)
26 p3lim-52096
        if(type(r) == 'table') then
27 p3lim-52096
                if(r.r) then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end
28 p3lim-52096
        end
29 p3lim-52096
        return ('|cff%02x%02x%02x'):format(r * 255, g * 255, b * 255)
30 p3lim-52096
end
31 p3lim-52096
 
32 p3lim-52096
oUF.Tags['[pvptime]'] = function(unit)
33 p3lim-52096
        return UnitIsPVP(unit) and not IsPVPTimerRunning() and '*' or IsPVPTimerRunning() and ('%d:%02d'):format((GetPVPTimer() / 1000) / 60, (GetPVPTimer() / 1000) % 60)
34 p3lim-52096
end
35 p3lim-52096
 
36 p3lim-52096
oUF.TagEvents['[pthreat]'] = 'UNIT_THREAT_LIST_UPDATE'
37 p3lim-52096
oUF.Tags['[pthreat]'] = function()
38 p3lim-52096
        local _, _, perc = UnitDetailedThreatSituation('player', 'target')
39 86 p3lim-52096
        return perc and ('%s%d%%|r'):format(hex(GetThreatStatusColor(UnitThreatSituation('player', 'target'))), perc)
40 85 p3lim-52096
end
41 p3lim-52096
 
42 p3lim-52096
oUF.Tags['[phealth]'] = function(unit)
43 p3lim-52096
        local min, max = UnitHealth(unit), UnitHealthMax(unit)
44 p3lim-52096
 
45 p3lim-52096
        local status = not UnitIsConnected(unit) and 'Offline' or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and 'Dead'
46 p3lim-52096
        local target = unit == 'target' and UnitCanAttack('player', unit) and ('%s (%d|cff0090ff%%|r)'):format(shortVal(min), min / max * 100)
47 p3lim-52096
        local player = unit == 'player' and min ~= max and ('|cffff8080%d|r %d|cff0090ff%%|r'):format(min - max, min / max * 100)
48 p3lim-52096
 
49 p3lim-52096
        return status and status or target and target or player and player or min ~= max and ('%s |cff0090ff/|r %s'):format(shortVal(min), shortVal(max)) or max
50 p3lim-52096
end
51 p3lim-52096
 
52 p3lim-52096
oUF.Tags['[ppower]'] = function(unit)
53 p3lim-52096
        local _, str = UnitPowerType(unit)
54 p3lim-52096
        return ('%s%d|r'):format(hex(colors.power[str] or {1, 1, 1}), oUF.Tags['[curpp]'](unit) or '')
55 p3lim-52096
end
56 p3lim-52096
 
57 p3lim-52096
oUF.TagEvents['[pname]'] = 'UNIT_NAME_UPDATE UNIT_REACTION UNIT_FACTION'
58 p3lim-52096
oUF.Tags['[pname]'] = function(unit)
59 p3lim-52096
        local colorString = hex((UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) and colors.tapped or
60 p3lim-52096
                (not UnitIsConnected(unit)) and colors.disconnected or
61 p3lim-52096
                (not UnitIsPlayer(unit)) and colors.reaction[UnitReaction(unit, 'player')] or
62 p3lim-52096
                (UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) and {1, 0, 0} or {1, 1, 1})
63 p3lim-52096
 
64 p3lim-52096
        return ('%s%s|r'):format(colorString, UnitName(unit))
65 p3lim-52096
end
66 p3lim-52096
 
67 p3lim-52096
oUF.TagEvents['[druidpower]'] = 'UNIT_MANA UPDATE_SHAPESHIFT_FORM'
68 p3lim-52096
oUF.Tags['[druidpower]'] = function(unit)
69 p3lim-52096
        local value = UnitPower(unit, 0)
70 p3lim-52096
        return UnitPowerType(unit) ~= 0 and ('|cff0090ff%d - %d%%|r'):format(value, value / UnitPowerMax(unit, 0) * 100)
71 p3lim-52096
end