diff --git a/oUF_P3lim.lua b/oUF_P3lim.lua index b24365b..2b36975 100644 --- a/oUF_P3lim.lua +++ b/oUF_P3lim.lua @@ -151,7 +151,7 @@ local function style(self, unit) local health = self.Health:CreateFontString(nil, 'OVERLAY', 'SempliceRight') health:SetPoint('RIGHT', self.Health, -2, 0) health.frequentUpdates = 0.25 - self:Tag(health, '[phealth]') + self:Tag(health, '[p3limhealth]') self.RaidIcon = self.Health:CreateTexture(nil, 'OVERLAY') self.RaidIcon:SetPoint('TOP', self, 0, 8) @@ -275,12 +275,12 @@ local function style(self, unit) local power = self.Health:CreateFontString(nil, 'OVERLAY', 'SempliceLeft') power:SetPoint('LEFT', self.Health, 2, 0) power.frequentUpdates = 0.1 - self:Tag(power, '[ppower][( )druidpower]') + self:Tag(power, '[p3limpower]') else local info = self.Health:CreateFontString(nil, 'OVERLAY', 'SempliceLeft') info:SetPoint('LEFT', self.Health, 2, 0) info:SetPoint('RIGHT', health, 'LEFT') - self:Tag(info, '[pname]|cff0090ff[( )rare]|r') + self:Tag(info, '[p3limname]|cff0090ff[( )rare]|r') end if(unit == 'pet') then @@ -349,7 +349,7 @@ local function style(self, unit) local info = self.Health:CreateFontString(nil, 'OVERLAY', 'Semplice') info:SetPoint('CENTER') info.frequentUpdates = 0.25 - self:Tag(info, '[pthreat]|cffff0000[( )pvptime]|r') + self:Tag(info, '[p3limthreat]|cffff0000[( )p3limpvp]|r') self.CustomAuraFilter = customFilter end diff --git a/oUF_P3lim.xml b/oUF_P3lim.xml index 2573801..41bd7ad 100644 --- a/oUF_P3lim.xml +++ b/oUF_P3lim.xml @@ -8,6 +8,6 @@ <Font name='SempliceLeft' inherits='Semplice' justifyH='LEFT' virtual='true'/> <Font name='SempliceRight' inherits='Semplice' justifyH='RIGHT' virtual='true'/> - <Script file='tags.lua'/> + <Script file='oUF_P3limTags.lua'/> <Script file='oUF_P3lim.lua'/> </Ui> diff --git a/oUF_P3limTags.lua b/oUF_P3limTags.lua new file mode 100644 index 0000000..c3ed552 --- /dev/null +++ b/oUF_P3limTags.lua @@ -0,0 +1,66 @@ +local format = string.format +local gsub = string.gsub + +local colors = setmetatable({ + power = setmetatable({ + ['MANA'] = {0, 144/255, 1} + }, {__index = oUF.colors.power}), + reaction = setmetatable({ + [2] = {1, 0, 0}, + [4] = {1, 1, 0}, + [5] = {0, 1, 0} + }, {__index = oUF.colors.reaction}), +}, {__index = oUF.colors}) + +local function shortVal(value) + if(value >= 1e6) then + return ('%.2fm'):format(value / 1e6):gsub('%.?0+([km])$', '%1') + elseif(value >= 1e4) then + return ('%.1fk'):format(value / 1e3):gsub('%.?0+([km])$', '%1') + else + return value + end +end + +local function hex(r, g, b) + if(type(r) == 'table') then + if(r.r) then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end + end + return ('|cff%02x%02x%02x'):format(r * 255, g * 255, b * 255) +end + +oUF.Tags['[p3limpvp]'] = function(unit) + return UnitIsPVP(unit) and not IsPVPTimerRunning() and '+' or IsPVPTimerRunning() and ('%d:%02d'):format((GetPVPTimer() / 1000) / 60, (GetPVPTimer() / 1000) % 60) +end + +oUF.TagEvents['[p3limthreat]'] = 'UNIT_THREAT_LIST_UPDATE' +oUF.Tags['[p3limthreat]'] = function() + local _, _, perc = UnitDetailedThreatSituation('player', 'target') + return perc and perc > 0 and ('%s%d%%|r'):format(hex(GetThreatStatusColor(UnitThreatSituation('player', 'target'))), perc) +end + +oUF.Tags['[p3limhealth]'] = 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' + local target = unit == 'target' and UnitCanAttack('player', unit) and ('%s (%d|cff0090ff%%|r)'):format(shortVal(min), min / max * 100) + local player = unit == 'player' and min ~= max and ('|cffff8080%d|r %d|cff0090ff%%|r'):format(min - max, min / max * 100) + + 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 +end + +oUF.Tags['[p3limpower]'] = function(unit) + local num, str = UnitPowerType(unit) + local manamin, manamax = UnitPower(unit, 0), UnitPowerMax(unit, 0) + return ('%s%d|r%s'):format(hex(colors.power[str] or {1, 1, 1}), oUF.Tags['[curpp]'](unit) or '', unit == 'player' and num ~= 0 and manamin ~= manamax and (' |cff0090ff%d%%|r'):format(manamin / manamax * 100) or '') +end + +oUF.TagEvents['[p3limname]'] = 'UNIT_NAME_UPDATE UNIT_REACTION UNIT_FACTION' +oUF.Tags['[p3limname]'] = function(unit) + local colorString = hex((UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) and colors.tapped or + (not UnitIsConnected(unit)) and colors.disconnected or + (not UnitIsPlayer(unit)) and colors.reaction[UnitReaction(unit, 'player')] or + (UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) and {1, 0, 0} or {1, 1, 1}) + + return ('%s%s|r'):format(colorString, UnitName(unit)) +end \ No newline at end of file diff --git a/tags.lua b/tags.lua deleted file mode 100644 index cc75556..0000000 --- a/tags.lua +++ /dev/null @@ -1,71 +0,0 @@ -local format = string.format -local gsub = string.gsub - -local colors = setmetatable({ - power = setmetatable({ - ['MANA'] = {0, 144/255, 1} - }, {__index = oUF.colors.power}), - reaction = setmetatable({ - [2] = {1, 0, 0}, - [4] = {1, 1, 0}, - [5] = {0, 1, 0} - }, {__index = oUF.colors.reaction}), -}, {__index = oUF.colors}) - -local function shortVal(value) - if(value >= 1e6) then - return ('%.2fm'):format(value / 1e6):gsub('%.?0+([km])$', '%1') - elseif(value >= 1e4) then - return ('%.1fk'):format(value / 1e3):gsub('%.?0+([km])$', '%1') - else - return value - end -end - -local function hex(r, g, b) - if(type(r) == 'table') then - if(r.r) then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end - end - return ('|cff%02x%02x%02x'):format(r * 255, g * 255, b * 255) -end - -oUF.Tags['[pvptime]'] = function(unit) - return UnitIsPVP(unit) and not IsPVPTimerRunning() and '+' or IsPVPTimerRunning() and ('%d:%02d'):format((GetPVPTimer() / 1000) / 60, (GetPVPTimer() / 1000) % 60) -end - -oUF.TagEvents['[pthreat]'] = 'UNIT_THREAT_LIST_UPDATE' -oUF.Tags['[pthreat]'] = function() - local _, _, perc = UnitDetailedThreatSituation('player', 'target') - return perc and perc > 0 and ('%s%d%%|r'):format(hex(GetThreatStatusColor(UnitThreatSituation('player', 'target'))), perc) -end - -oUF.Tags['[phealth]'] = 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' - local target = unit == 'target' and UnitCanAttack('player', unit) and ('%s (%d|cff0090ff%%|r)'):format(shortVal(min), min / max * 100) - local player = unit == 'player' and min ~= max and ('|cffff8080%d|r %d|cff0090ff%%|r'):format(min - max, min / max * 100) - - 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 -end - -oUF.Tags['[ppower]'] = function(unit) - local _, str = UnitPowerType(unit) - return ('%s%d|r'):format(hex(colors.power[str] or {1, 1, 1}), oUF.Tags['[curpp]'](unit) or '') -end - -oUF.TagEvents['[pname]'] = 'UNIT_NAME_UPDATE UNIT_REACTION UNIT_FACTION' -oUF.Tags['[pname]'] = function(unit) - local colorString = hex((UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) and colors.tapped or - (not UnitIsConnected(unit)) and colors.disconnected or - (not UnitIsPlayer(unit)) and colors.reaction[UnitReaction(unit, 'player')] or - (UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) and {1, 0, 0} or {1, 1, 1}) - - return ('%s%s|r'):format(colorString, UnitName(unit)) -end - -oUF.TagEvents['[druidpower]'] = 'UNIT_MANA UPDATE_SHAPESHIFT_FORM' -oUF.Tags['[druidpower]'] = function(unit) - local min, max = UnitPower(unit, 0), UnitPowerMax(unit, 0) - return unit == 'player' and UnitPowerType(unit) ~= 0 and min ~= max and ('|cff0090ff%d%%|r'):format(min / max * 100) -end