Code:
-- Absorb Field
-- Author: Kar (EU-Silvermoon)
local amountAbsorb, totalAbsorb
local UnitBuff = UnitBuff
local UnitExists = UnitExists
local spells = {
{
["Name"] = "Blood Shield",
["Icon"] = "spell_deathknight_butcher2",
},
{
["Name"] = "Guard",
["Icon"] = "ability_monk_guard",
},
{
["Name"] = "Power Word: Shield",
["Icon"] = "spell_holy_powerwordshield",
},
{
["Name"] = "Divine Aegis",
["Icon"] = "spell_holy_devineaegis",
},
{
["Name"] = "Illuminated Healing",
["Icon"] = "spell_holy_absolution",
},
{
["Name"] = "Sacred Shield",
["Icon"] = "ability_paladin_blessedmending",
},
{
["Name"] = "Total",
["Icon"] = "spell_arcane_arcaneresilience",
},
}
local function Absorb_SavePosition(frame)
AbsorbField_Settings[frame.Unit.."PosX"] = frame:GetLeft()
AbsorbField_Settings[frame.Unit.."PosY"] = frame:GetBottom()
end
local function Absorb_FormatValue(value)
if value > 999 then
value = value / 1000
if value < 100 then
value = format("%.1fk",value)
else
value = format("%.0fk",value)
end
end
return value
end
local hide_if_zero = true
local hidden_alpha = 0
local full_alpha = 1
local focus_hidedetails = true
local function Absorb_UpdateAbsorbs(unit)
totalAbsorb = 0
for i = 1, 4 do
if UnitBuff(unit, spells[i]["Name"]) then
amountAbsorb = select(14, UnitBuff(unit, spells[i]["Name"]))
totalAbsorb = totalAbsorb + amountAbsorb
if(unit == "focus" and focus_hidedetails) then
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"]:Hide()
else
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"]:Show()
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"].Amount:SetText(Absorb_FormatValue(amountAbsorb))
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"].Amount:SetTextColor(0.2, 1.0, 0.2)
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"].Icon:SetDesaturated(nil)
end
else
if(unit == "focus" and focus_hidedetails) then
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"]:Hide()
else
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"]:Show()
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"].Amount:SetText("0")
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"].Amount:SetTextColor(0.4, 0.4, 0.4)
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"].Icon:SetDesaturated(true)
end
end
end
if totalAbsorb > 0 then
_G["AbsorbField"..unit.."_Frame7Coloumn"].Amount:SetText(Absorb_FormatValue(totalAbsorb))
_G["AbsorbField"..unit.."_Frame7Coloumn"].Amount:SetTextColor(0.1, 0.7, 1.0)
_G["AbsorbField"..unit.."_Frame7Coloumn"].Icon:SetDesaturated(nil)
if hide_if_zero then
_G["AbsorbField"..unit.."_Frame7Coloumn"]:SetAlpha(full_alpha)
for i = 1, 4 do
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"]:SetAlpha(full_alpha)
end
end
else
_G["AbsorbField"..unit.."_Frame7Coloumn"].Amount:SetText(0)
_G["AbsorbField"..unit.."_Frame7Coloumn"].Amount:SetTextColor(0.4, 0.4, 0.4)
_G["AbsorbField"..unit.."_Frame7Coloumn"].Icon:SetDesaturated(true)
if hide_if_zero then
_G["AbsorbField"..unit.."_Frame7Coloumn"]:SetAlpha(hidden_alpha)
for i = 1, 4 do
_G["AbsorbField"..unit.."_Frame"..i.."Coloumn"]:SetAlpha(hidden_alpha)
end
end
end
end
local function Absorb_CreateColumn(icon, name, id, unit)
local button = CreateFrame("Button", "AbsorbField"..unit.."_Frame"..id.."Coloumn", _G["AbsorbField"..unit.."_Frame"])
button:SetWidth(50)
button:SetHeight(15)
button:SetPoint("LEFT", _G["AbsorbField"..unit.."_Frame"], "LEFT", (id - 1) * 51, 0)
button.Name = name
button:EnableMouse(false)
local texture = button:CreateTexture(nil, "ARTWORK")
texture:SetWidth(15)
texture:SetHeight(15)
texture:SetPoint("LEFT", button, "LEFT", 0, 0)
texture:SetTexture("Interface\\Icons\\"..icon)
texture:SetDesaturated(true)
texture:SetTexCoord(.1, .9, .1, .9)
button.Icon = texture
local amount = button:CreateFontString(nil, "OVERLAY")
amount:SetFont("Interface\\AddOns\\SharedMedia\\fonts\\Homespun.TTF", 10, "OUTLINE")
amount:SetText("0")
amount:SetTextColor(0.4, 0.4, 0.4)
amount:SetPoint("CENTER", button, "CENTER", 7, 0)
amount:SetJustifyH("CENTER")
button.Amount = amount
if hide_if_zero then button:SetAlpha(0) end
end
local function Absorb_CreateField(unit)
local frame = CreateFrame("Frame", "AbsorbField"..unit.."_Frame", UIParent)
frame:SetWidth(254)
frame:SetHeight(15)
if not AbsorbField_Settings[unit.."PosX"] then
if unit == "player" then
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 200)
else
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 150)
end
else
frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", AbsorbField_Settings[unit.."PosX"], AbsorbField_Settings[unit.."PosY"])
end
local texture = frame:CreateTexture(nil, "BACKGROUND")
texture:SetAllPoints(true)
texture:Hide()
frame.Unit = unit
frame.BG = texture
for i = 1, #spells do
Absorb_CreateColumn(spells[i]["Icon"], spells[i]["Name"], i, unit)
end
if unit == "focus" then
frame:Hide()
end
end
function AbsorbField_SlashHandler(msg)
msg = string.lower(msg)
if msg == "unlock" then
AbsorbFieldplayer_Frame:RegisterForDrag("LeftButton")
AbsorbFieldplayer_Frame:SetMovable(true)
AbsorbFieldplayer_Frame:EnableMouse(true)
AbsorbFieldplayer_Frame.BG:SetTexture(0.2, 1.0, 0.2)
AbsorbFieldplayer_Frame.BG:Show()
AbsorbFieldplayer_Frame:SetScript("OnDragStart", function (self) self:StartMoving() end)
AbsorbFieldplayer_Frame:SetScript("OnDragStop", function (self) self:StopMovingOrSizing() Absorb_SavePosition(self) end)
AbsorbFieldfocus_Frame:RegisterForDrag("LeftButton")
AbsorbFieldfocus_Frame:SetMovable(true)
AbsorbFieldfocus_Frame:EnableMouse(true)
AbsorbFieldfocus_Frame.BG:SetTexture(0.2, 0.2, 1.0)
AbsorbFieldfocus_Frame.BG:Show()
AbsorbFieldfocus_Frame:SetScript("OnDragStart", function (self) self:StartMoving() end)
AbsorbFieldfocus_Frame:SetScript("OnDragStop", function (self) self:StopMovingOrSizing() Absorb_SavePosition(self) end)
AbsorbFieldfocus_Frame:Show()
elseif msg == "lock" then
AbsorbFieldplayer_Frame:RegisterForDrag(nil)
AbsorbFieldplayer_Frame:SetMovable(false)
AbsorbFieldplayer_Frame:EnableMouse(false)
AbsorbFieldplayer_Frame.BG:Hide()
AbsorbFieldplayer_Frame:SetScript("OnDragStart", nil)
AbsorbFieldplayer_Frame:SetScript("OnDragStop", nil)
AbsorbFieldfocus_Frame:RegisterForDrag(nil)
AbsorbFieldfocus_Frame:SetMovable(false)
AbsorbFieldfocus_Frame:EnableMouse(false)
AbsorbFieldfocus_Frame.BG:Hide()
AbsorbFieldfocus_Frame:SetScript("OnDragStart", nil)
AbsorbFieldfocus_Frame:SetScript("OnDragStop", nil)
if not UnitExists("focus") then
AbsorbFieldfocus_Frame:Hide()
end
end
end
function AbsorbField_OnEvent(self, event, ...)
if event == "VARIABLES_LOADED" then
if not AbsorbField_Settings then
AbsorbField_Settings = {}
end
Absorb_CreateField("player")
Absorb_CreateField("focus")
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("PLAYER_FOCUS_CHANGED")
SlashCmdList["ABSORBFIELDCOMMANDS"] = AbsorbField_SlashHandler;
SLASH_ABSORBFIELDCOMMANDS1 = "/abf"
elseif event == "UNIT_AURA" then
local arg1 = ...
if arg1 == "player" then
Absorb_UpdateAbsorbs("player")
elseif arg1 == "focus" then
Absorb_UpdateAbsorbs("focus")
end
elseif event == "PLAYER_FOCUS_CHANGED" then
if UnitExists("focus") then
AbsorbFieldfocus_Frame:Show()
Absorb_UpdateAbsorbs("focus")
else
AbsorbFieldfocus_Frame:Hide()
end
end
end
local frame = CreateFrame("Frame", "AbsorbField")
frame:SetScript("OnEvent", AbsorbField_OnEvent)
frame:RegisterEvent("VARIABLES_LOADED")
If your further want to adjust it, just add any spells you want, then replace references to "Frame7Column" with increasing numbers (correspondent to the index of the "Total" pseudo-spell in the table).