Commit 590caee6 authored by Blazeflack's avatar Blazeflack

Added 6 new custom tags to the collection

The following 6 new tags will all hide the text when health or power is at 100% and they have no decimals.

health:percent:hidefull
health:current:hidefull
health:current-percent:hidefull
power:percent:hidefull
power:current:hidefull
power:current-percent:hidefull
parent b9573402
......@@ -6,25 +6,85 @@ assert(ElvUF, "ElvUI was unable to locate oUF.")
--Cache global variables
--Lua functions
local _G = _G
local unpack, pairs = unpack, pairs
local unpack, pairs, assert = unpack, pairs, assert
local twipe = table.wipe
local ceil, sqrt, floor = math.ceil, math.sqrt, math.floor
local ceil, sqrt, floor, abs = math.ceil, math.sqrt, math.floor, math.abs
local format = string.format
--WoW API
local IsInGroup = IsInGroup
local IsInRaid = IsInRaid
local UnitIsUnit = UnitIsUnit
local GetNumGroupMembers = GetNumGroupMembers
local UnitHealth = UnitHealth
local UnitHealthMax = UnitHealthMax
local UnitPowerType = UnitPowerType
local UnitPower = UnitPower
local UnitPowerMax = UnitPowerMax
local textFormatStyles = {
["CURRENT"] = "%.1f",
["CURRENT_MAX"] = "%.1f - %.1f",
["CURRENT_PERCENT"] = "%.1f - %.1f%%",
["CURRENT_MAX_PERCENT"] = "%.1f - %.1f | %.1f%%",
["PERCENT"] = "%.1f%%",
["DEFICIT"] = "-%.1f"
}
local textFormatStylesNoDecimal = {
["CURRENT"] = "%s",
["CURRENT_MAX"] = "%s - %s",
["CURRENT_PERCENT"] = "%s - %.0f%%",
["CURRENT_MAX_PERCENT"] = "%s - %s | %.0f%%",
["PERCENT"] = "%.0f%%",
["DEFICIT"] = "-%s"
}
local function GetFormattedText(min, max, style, noDecimal)
assert(textFormatStyles[style] or textFormatStylesNoDecimal[style], "CustomTags Invalid format style: "..style)
assert(min, "CustomTags - You need to provide a current value. Usage: GetFormattedText(min, max, style, noDecimal)")
assert(max, "CustomTags - You need to provide a maximum value. Usage: GetFormattedText(min, max, style, noDecimal)")
if max == 0 then max = 1 end
local chosenFormat
if noDecimal then
chosenFormat = textFormatStylesNoDecimal[style]
else
chosenFormat = textFormatStyles[style]
end
if style == "DEFICIT" then
local deficit = max - min
if deficit <= 0 then
return ""
else
return format(chosenFormat, E:ShortValue(deficit))
end
elseif style == "PERCENT" then
return format(chosenFormat, min / max * 100)
elseif style == "CURRENT" or ((style == "CURRENT_MAX" or style == "CURRENT_MAX_PERCENT" or style == "CURRENT_PERCENT") and min == max) then
if noDecimal then
return format(textFormatStylesNoDecimal["CURRENT"], E:ShortValue(min))
else
return format(textFormatStyles["CURRENT"], E:ShortValue(min))
end
elseif style == "CURRENT_MAX" then
return format(chosenFormat, E:ShortValue(min), E:ShortValue(max))
elseif style == "CURRENT_PERCENT" then
return format(chosenFormat, E:ShortValue(min), min / max * 100)
elseif style == "CURRENT_MAX_PERCENT" then
return format(chosenFormat, E:ShortValue(min), E:ShortValue(max), min / max * 100)
end
end
--[[
Add custom tags below this block
--]]
ElvUF.Tags.Events['num:targeting'] = "UNIT_TARGET PLAYER_TARGET_CHANGED GROUP_ROSTER_UPDATE"
ElvUF.Tags.Methods['num:targeting'] = function(unit)
ElvUF.Tags.Events["num:targeting"] = "UNIT_TARGET PLAYER_TARGET_CHANGED GROUP_ROSTER_UPDATE"
ElvUF.Tags.Methods["num:targeting"] = function(unit)
if not IsInGroup() then return "" end
local targetedByNum = 0
--Count the amount of other people targeting the unit
for i = 1, GetNumGroupMembers() do
local groupUnit = (IsInRaid() and "raid"..i or "party"..i);
......@@ -32,11 +92,104 @@ ElvUF.Tags.Methods['num:targeting'] = function(unit)
targetedByNum = targetedByNum + 1
end
end
--Add 1 if we're targeting the unit too
--Add 1 if we"re targeting the unit too
if UnitIsUnit("playertarget", unit) then
targetedByNum = targetedByNum + 1
end
return (targetedByNum > 0 and targetedByNum or "")
end
ElvUF.Tags.Events["health:percent:hidefull"] = "UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION"
ElvUF.Tags.Methods["health:percent:hidefull"] = function(unit)
local min, max = UnitHealth(unit), UnitHealthMax(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
String = GetFormattedText(min, max, "PERCENT", true)
end
return String
end
ElvUF.Tags.Events["health:current:hidefull"] = "UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION"
ElvUF.Tags.Methods["health:current:hidefull"] = function(unit)
local min, max = UnitHealth(unit), UnitHealthMax(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
String = GetFormattedText(min, max, "CURRENT", true)
end
return String
end
ElvUF.Tags.Events["health:current-percent:hidefull"] = "UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION"
ElvUF.Tags.Methods["health:current-percent:hidefull"] = function(unit)
local min, max = UnitHealth(unit), UnitHealthMax(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
return String
end
ElvUF.Tags.Events["power:percent:hidefull"] = "UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER"
ElvUF.Tags.Methods["power:percent:hidefull"] = function(unit)
local pType = UnitPowerType(unit)
local min, max = UnitPower(unit, pType), UnitPowerMax(unit, pType)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
String = GetFormattedText(min, max, "PERCENT", true)
end
return String
end
ElvUF.Tags.Events["power:current:hidefull"] = "UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER"
ElvUF.Tags.Methods["power:current:hidefull"] = function(unit)
local pType = UnitPowerType(unit)
local min, max = UnitPower(unit, pType), UnitPowerMax(unit, pType)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
String = GetFormattedText(min, max, "CURRENT", true)
end
return String
end
ElvUF.Tags.Events["power:current-percent:hidefull"] = "UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER"
ElvUF.Tags.Methods["power:current-percent:hidefull"] = function(unit)
local pType = UnitPowerType(unit)
local min, max = UnitPower(unit, pType), UnitPowerMax(unit, pType)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
return String
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment