--Dispell Module for Gladius
--Mavvo
local Gladius = _G.Gladius
if not Gladius then
DEFAULT_CHAT_FRAME:AddMessage(format("Module %s requires Gladius", "Dispell"))
end
local L = Gladius.L
local LSM
-- global functions
local strfind = string.find
local pairs = pairs
local strformat = string.format
local UnitName, UnitClass, UnitFactionGroup, UnitLevel = UnitName, UnitClass, UnitFactionGroup, UnitLevel
local Dispell = Gladius:NewModule("Dispell", false, true, {
dispellAttachTo = "Frame",
dispellAnchor = "TOPLEFT",
dispellRelativePoint = "TOPRIGHT",
dispellGridStyleIcon = false,
dispellGridStyleIconColor = { r = 0, g = 1, b = 0, a = 1 },
dispellGridStyleIconUsedColor = { r = 1, g = 0, b = 0, a = 1 },
dispellAdjustSize = true,
dispellSize = 52,
dispellOffsetX = 52,
dispellOffsetY = 0,
dispellFrameLevel = 2,
dispellIconCrop = false,
dispellGloss = true,
dispellGlossColor = { r = 1, g = 1, b = 1, a = 0.4 },
dispellCooldown = true,
dispellCooldownReverse = false,
dispellFaction = true,
}, { "Dispell icon", "Grid style health bar", "Grid style power bar" })
function Dispell:OnEnable()
--self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
LSM = Gladius.LSM
if (not self.frame) then
self.frame = {}
end
end
function Dispell:OnDisable()
self:UnregisterAllEvents()
for unit in pairs(self.frame) do
self.frame[unit]:SetAlpha(0)
end
end
function Dispell:GetAttachTo()
return Gladius.db.dispellAttachTo
end
function Dispell:GetFrame(unit)
return self.frame[unit]
end
function Dispell:SetTemplate(template)
if (template == 1) then
-- reset width
if (Gladius.db.targetBarAttachTo == "HealthBar" and not Gladius.db.healthBarAdjustWidth) then
Gladius.db.healthBarAdjustWidth = true
end
-- reset to default
for k, v in pairs(self.defaults) do
Gladius.db[k] = v
end
elseif (template == 2) then
if (Gladius.db.modules["HealthBar"]) then
if (Gladius.db.healthBarAdjustWidth) then
Gladius.db.healthBarAdjustWidth = false
Gladius.db.healthBarWidth = Gladius.db.barWidth - Gladius.db.healthBarHeight
else
Gladius.db.healthBarWidth = Gladius.db.healthBarWidth - Gladius.db.healthBarHeight
end
Gladius.db.dispellGridStyleIcon = true
Gladius.db.dispellAdjustHeight = false
Gladius.db.dispellHeight = Gladius.db.healthBarHeight
Gladius.db.dispellAttachTo = "HealthBar"
Gladius.db.dispellAnchor = "TOPLEFT"
Gladius.db.dispellRelativePoint = "TOPRIGHT"
Gladius.db.dispellOffsetX = 52
Gladius.db.dispellOffsetY = 0
end
else
if (Gladius.db.modules["PowerBar"]) then
if (Gladius.db.powerBarAdjustWidth) then
Gladius.db.powerBarAdjustWidth = false
Gladius.db.powerBarWidth = Gladius.db.powerBarWidth - Gladius.db.powerBarHeight
else
Gladius.db.powerBarWidth = Gladius.db.powerBarWidth - Gladius.db.powerBarHeight
end
Gladius.db.dispellGridStyleIcon = true
Gladius.db.dispellAdjustHeight = false
Gladius.db.dispellHeight = Gladius.db.powerBarHeight
Gladius.db.dispellAttachTo = "PowerBar"
Gladius.db.dispellAnchor = "TOPLEFT"
Gladius.db.dispellRelativePoint = "TOPRIGHT"
Gladius.db.dispellOffsetX = 52
Gladius.db.dispellOffsetY = 0
end
end
end
function Dispell:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
if select(2, ...)=="SPELL_DISPEL" then
local spell = select(12, ...)
local unit = select(4, ...)
--if (not strfind(unit, "arena") or strfind(unit, "pet")) then return end
if (not(UnitGUID("arena1")==unit or UnitGUID("arena2")==unit or UnitGUID("arena3")==unit or UnitGUID("arena4")==unit or UnitGUID("arena5")==unit)) then return end
if (spell == 527 -- priest Purify [url=http://mop.wowhead.com/spell=527]http://mop.wowhead.com/spell=527[/url]
or spell == 4987 --paladin Cleanse [url=http://mop.wowhead.com/spell=4987]http://mop.wowhead.com/spell=4987[/url]
or spell == 77130 --shaman Purify Spirit [url=http://mop.wowhead.com/spell=77130]http://mop.wowhead.com/spell=77130[/url]
or spell == 88423 --druid Nature's cure [url=http://mop.wowhead.com/spell=88423]http://mop.wowhead.com/spell=88423[/url]
) then
if UnitGUID("arena1")==unit then
self:UpdateDispell("arena1", 8) end
if UnitGUID("arena2")==unit then
self:UpdateDispell("arena2", 8) end
if UnitGUID("arena3")==unit then
self:UpdateDispell("arena3", 8) end
if UnitGUID("arena4")==unit then
self:UpdateDispell("arena4", 8) end
if UnitGUID("arena5")==unit then
self:UpdateDispell("arena5", 8) end
end
-- wotf
-- if (spell == GetSpellInfo(7744)) then
-- self:UpdateDispell(unit, 45)
-- end
end
end
function Dispell:UpdateDispell(unit, duration)
-- grid style icon
if (Gladius.db.dispellGridStyleIcon) then
self.frame[unit].texture:SetVertexColor(Gladius.db.dispellGridStyleIconUsedColor.r, Gladius.db.dispellGridStyleIconUsedColor.g, Gladius.db.dispellGridStyleIconUsedColor.b, Gladius.db.dispellGridStyleIconUsedColor.a)
end
-- announcement
if (Gladius.db.announcements.dispell) then
Gladius:Call(Gladius.modules.Announcements, "Send", strformat(L["DISPELL USED: %s (%s)"], UnitName(unit) or "test", UnitClass(unit) or "test"), 2, unit)
end
if (Gladius.db.announcements.dispell or Gladius.db.dispellGridStyleIcon) then
self.frame[unit].timeleft = duration
self.frame[unit]:SetScript("OnUpdate", function(f, elapsed)
self.frame[unit].timeleft = self.frame[unit].timeleft - elapsed
if (self.frame[unit].timeleft <= 0) then
-- dispell
if (Gladius.db.dispellGridStyleIcon) then
self.frame[unit].texture:SetVertexColor(Gladius.db.dispellGridStyleIconColor.r, Gladius.db.dispellGridStyleIconColor.g, Gladius.db.dispellGridStyleIconColor.b, Gladius.db.dispellGridStyleIconColor.a)
end
-- announcement
if (Gladius.db.announcements.dispell) then
Gladius:Call(Gladius.modules.Announcements, "Send", strformat(L["DISPELL READY: %s (%s)"], UnitName(unit) or "", UnitClass(unit) or ""), 2, unit)
end
self.frame[unit]:SetScript("OnUpdate", nil)
end
end)
end
-- cooldown
Gladius:Call(Gladius.modules.Timer, "SetTimer", self.frame[unit], duration)
end
function Dispell:CreateFrame(unit)
local button = Gladius.buttons[unit]
if (not button) then return end
-- create frame
self.frame[unit] = CreateFrame("CheckButton", "Gladius" .. self.name .. "Frame" .. unit, button, "ActionButtonTemplate")
self.frame[unit]:EnableMouse(false)
self.frame[unit]:SetNormalTexture("Interface\\AddOns\\Gladius\\images\\gloss")
self.frame[unit].texture = _G[self.frame[unit]:GetName().."Icon"]
self.frame[unit].normalTexture = _G[self.frame[unit]:GetName().."NormalTexture"]
self.frame[unit].cooldown = _G[self.frame[unit]:GetName().."Cooldown"]
end
function Dispell:Update(unit)
-- create frame
if (not self.frame[unit]) then
self:CreateFrame(unit)
end
-- update frame
self.frame[unit]:ClearAllPoints()
-- anchor point
local parent = Gladius:GetParent(unit, Gladius.db.dispellAttachTo)
self.frame[unit]:SetPoint(Gladius.db.dispellAnchor, parent, Gladius.db.dispellRelativePoint, Gladius.db.dispellOffsetX, Gladius.db.dispellOffsetY)
-- frame level
self.frame[unit]:SetFrameLevel(Gladius.db.dispellFrameLevel)
if (Gladius.db.dispellAdjustSize) then
if (self:GetAttachTo() == "Frame") then
local height = false
--[[ need to rethink that
for _, module in pairs(Gladius.modules) do
if (module:GetAttachTo() == self.name) then
height = false
end
end]]
if (height) then
self.frame[unit]:SetWidth(Gladius.buttons[unit].height)
self.frame[unit]:SetHeight(Gladius.buttons[unit].height)
else
self.frame[unit]:SetWidth(Gladius.buttons[unit].frameHeight)
self.frame[unit]:SetHeight(Gladius.buttons[unit].frameHeight)
end
else
self.frame[unit]:SetWidth(Gladius:GetModule(self:GetAttachTo()).frame[unit]:GetHeight() or 1)
self.frame[unit]:SetHeight(Gladius:GetModule(self:GetAttachTo()).frame[unit]:GetHeight() or 1)
end
else
self.frame[unit]:SetWidth(Gladius.db.dispellSize)
self.frame[unit]:SetHeight(Gladius.db.dispellSize)
end
-- set frame mouse-interactable area
if (self:GetAttachTo() == "Frame") then
local left, right, top, bottom = Gladius.buttons[unit]:GetHitRectInsets()
if (strfind(Gladius.db.dispellRelativePoint, "LEFT")) then
left = -self.frame[unit]:GetWidth() + Gladius.db.dispellOffsetX
else
right = -self.frame[unit]:GetWidth() + -Gladius.db.dispellOffsetX
end
-- search for an attached frame
--[[for _, module in pairs(Gladius.modules) do
if (module.attachTo and module:GetAttachTo() == self.name and module.frame and module.frame[unit]) then
local attachedPoint = module.frame[unit]:GetPoint()
if (strfind(Gladius.db.trinketRelativePoint, "LEFT") and (not attachedPoint or (attachedPoint and strfind(attachedPoint, "RIGHT")))) then
left = left - module.frame[unit]:GetWidth()
elseif (strfind(Gladius.db.trinketRelativePoint, "RIGHT") and (not attachedPoint or (attachedPoint and strfind(attachedPoint, "LEFT")))) then
right = right - module.frame[unit]:GetWidth()
end
end
end]]
-- top / bottom
if (self.frame[unit]:GetHeight() > Gladius.buttons[unit]:GetHeight()) then
bottom = -(self.frame[unit]:GetHeight() - Gladius.buttons[unit]:GetHeight()) + Gladius.db.dispellOffsetY
end
Gladius.buttons[unit]:SetHitRectInsets(left, right, 0, 0)
Gladius.buttons[unit].secure:SetHitRectInsets(left, right, 0, 0)
end
-- style action button
self.frame[unit].normalTexture:SetHeight(self.frame[unit]:GetHeight() + self.frame[unit]:GetHeight() * 0.4)
self.frame[unit].normalTexture:SetWidth(self.frame[unit]:GetWidth() + self.frame[unit]:GetWidth() * 0.4)
self.frame[unit].normalTexture:ClearAllPoints()
self.frame[unit].normalTexture:SetPoint("CENTER", 0, 0)
self.frame[unit]:SetNormalTexture("Interface\\AddOns\\Gladius\\images\\gloss")
self.frame[unit].texture:ClearAllPoints()
self.frame[unit].texture:SetPoint("TOPLEFT", self.frame[unit], "TOPLEFT")
self.frame[unit].texture:SetPoint("BOTTOMRIGHT", self.frame[unit], "BOTTOMRIGHT")
if (not Gladius.db.dispellIconCrop and not Gladius.db.dispellGridStyleIcon) then
self.frame[unit].texture:SetTexCoord(0, 1, 0, 1)
else
self.frame[unit].texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
end
self.frame[unit].normalTexture:SetVertexColor(Gladius.db.dispellGlossColor.r, Gladius.db.dispellGlossColor.g,
Gladius.db.dispellGlossColor.b, Gladius.db.dispellGloss and Gladius.db.dispellGlossColor.a or 0)
-- cooldown
if (Gladius.db.dispellCooldown) then
self.frame[unit].cooldown:Show()
else
self.frame[unit].cooldown:Hide()
end
self.frame[unit].cooldown:SetReverse(Gladius.db.dispellCooldownReverse)
Gladius:Call(Gladius.modules.Timer, "RegisterTimer", self.frame[unit], Gladius.db.dispellCooldown)
-- hide
self.frame[unit]:SetAlpha(0)
end
function Dispell:Show(unit)
local testing = Gladius.test
-- show frame
self.frame[unit]:SetAlpha(1)
if (Gladius.db.dispellGridStyleIcon) then
self.frame[unit].texture:SetTexture(LSM:Fetch(LSM.MediaType.STATUSBAR, "Minimalist"))
self.frame[unit].texture:SetVertexColor(Gladius.db.dispellGridStyleIconColor.r, Gladius.db.dispellGridStyleIconColor.g, Gladius.db.dispellGridStyleIconColor.b, Gladius.db.dispellGridStyleIconColor.a)
else
local dispellIcon
local playerClass, englishClass = UnitClass(unit);
if (not testing) then
if (englishClass == "PRIEST" ) then
dispellIcon = "Interface\\Icons\\spell_holy_dispelmagic"
elseif (englishClass == "SHAMAN" ) then
dispellIcon = "Interface\\Icons\\ability_shaman_cleansespirit"
elseif (englishClass == "PALADIN" ) then
dispellIcon = "Interface\\Icons\\spell_holy_purify"
elseif (englishClass == "DRUID" ) then
dispellIcon = "Interface\\Icons\\ability_shaman_cleansespirit"
elseif (englishClass == "MAGE" ) then
dispellIcon = "Interface\\Icons\\spell_nature_removecurse"
end
else
if (englishClass == "PRIEST" or unit=="arena1") then
dispellIcon = "Interface\\Icons\\spell_holy_dispelmagic"
elseif (englishClass == "SHAMAN" or unit=="arena2") then
dispellIcon = "Interface\\Icons\\ability_shaman_cleansespirit"
elseif (englishClass == "PALADIN" or unit=="arena3") then
dispellIcon = "Interface\\Icons\\spell_holy_purify"
elseif (englishClass == "DRUID" or unit=="arena4") then
dispellIcon = "Interface\\Icons\\ability_shaman_cleansespirit"
elseif (englishClass == "MAGE" or unit=="arena5") then
dispellIcon = "Interface\\Icons\\spell_nature_removecurse"
end
end
self.frame[unit].texture:SetTexture(dispellIcon)
if (Gladius.db.dispellIconCrop) then
self.frame[unit].texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
end
self.frame[unit].texture:SetVertexColor(1, 1, 1, 1)
end
end
function Dispell:Reset(unit)
if (not self.frame[unit]) then return end
-- reset frame
local dispellIcon
if (UnitFactionGroup("player") == "Horde" and Gladius.db.dispellFaction) then
dispellIcon = "Interface\\Icons\\INV_Jewelry_Necklace_38"
else
dispellIcon = "Interface\\Icons\\INV_Jewelry_Necklace_37"
end
self.frame[unit].texture:SetTexture(dispellIcon)
if (Gladius.db.dispellIconCrop) then
self.frame[unit].texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
end
self.frame[unit]:SetScript("OnUpdate", nil)
-- reset cooldown
Gladius:Call(Gladius.modules.Timer, "HideTimer", self.frame[unit])
-- hide
self.frame[unit]:SetAlpha(0)
end
function Dispell:Test(unit)
-- test
if (unit == "arena1") then
self:UpdateDispell(unit, 8)
end
if (unit == "arena2") then
self:UpdateDispell(unit, 8)
end
if (unit == "arena3") then
self:UpdateDispell(unit, 8)
end
if (unit == "arena4") then
self:UpdateDispell(unit, 8)
end
end
-- Add the announcement toggle
function Dispell:OptionsLoad()
Gladius.options.args.Announcements.args.general.args.announcements.args.dispell = {
type="toggle",
name=L["Dispell"],
desc=L["Announces when an enemy cast a dispell."],
disabled=function() return not Gladius.db.modules[self.name] end,
}
end
function Dispell:GetOptions()
return {
general = {
type="group",
name=L["General"],
order=1,
args = {
widget = {
type="group",
name=L["Widget"],
desc=L["Widget settings"],
inline=true,
order=1,
args = {
dispellGridStyleIcon = {
type="toggle",
name=L["Dispell Grid Style Icon"],
desc=L["Toggle dispell grid style icon"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
order=5,
},
sep = {
type = "description",
name="",
width="full",
order=7,
},
dispellGridStyleIconColor = {
type="color",
name=L["Dispell Grid Style Icon Color"],
desc=L["Color of the dispell grid style icon"],
hasAlpha=true,
get=function(info) return Gladius:GetColorOption(info) end,
set=function(info, r, g, b, a) return Gladius:SetColorOption(info, r, g, b, a) end,
disabled=function() return not Gladius.dbi.profile.dispellGridStyleIcon or not Gladius.dbi.profile.modules[self.name] end,
order=10,
},
dispellGridStyleIconUsedColor = {
type="color",
name=L["Dispell Grid Style Icon Used Color"],
desc=L["Color of the dispell grid style icon when it's on cooldown"],
hasAlpha=true,
get=function(info) return Gladius:GetColorOption(info) end,
set=function(info, r, g, b, a) return Gladius:SetColorOption(info, r, g, b, a) end,
disabled=function() return not Gladius.dbi.profile.dispellGridStyleIcon or not Gladius.dbi.profile.modules[self.name] end,
order=12,
},
sep1 = {
type = "description",
name="",
width="full",
order=13,
},
dispellCooldown = {
type="toggle",
name=L["Dispell Cooldown Spiral"],
desc=L["Display the cooldown spiral for important auras"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
hidden=function() return not Gladius.db.advancedOptions end,
order=15,
},
dispellCooldownReverse = {
type="toggle",
name=L["Dispell Cooldown Reverse"],
desc=L["Invert the dark/bright part of the cooldown spiral"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
hidden=function() return not Gladius.db.advancedOptions end,
order=20,
},
sep2 = {
type = "description",
name="",
width="full",
order=23,
},
dispellGloss = {
type="toggle",
name=L["Dispell Gloss"],
desc=L["Toggle gloss on the dispell icon"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
hidden=function() return not Gladius.db.advancedOptions end,
order=25,
},
dispellGlossColor = {
type="color",
name=L["Dispell Gloss Color"],
desc=L["Color of the dispell icon gloss"],
get=function(info) return Gladius:GetColorOption(info) end,
set=function(info, r, g, b, a) return Gladius:SetColorOption(info, r, g, b, a) end,
hasAlpha=true,
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
hidden=function() return not Gladius.db.advancedOptions end,
order=30,
},
sep3 = {
type = "description",
name="",
width="full",
hidden=function() return not Gladius.db.advancedOptions end,
order=33,
},
dispellIconCrop = {
type="toggle",
name=L["Dispell Icon Border Crop"],
desc=L["Toggle if the borders of the dispell icon should be cropped"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
order=35,
},
dispellFaction = {
type="toggle",
name=L["Dispell Icon Faction"],
desc=L["Toggle if the dispell icon should be changing based on the opponents faction"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
order=40,
},
sep3 = {
type = "description",
name="",
width="full",
order=43,
},
dispellFrameLevel = {
type="range",
name=L["Dispell Frame Level"],
desc=L["Frame level of the dispell"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
hidden=function() return not Gladius.db.advancedOptions end,
min=1, max=5, step=1,
width="double",
order=45,
},
},
},
size = {
type="group",
name=L["Size"],
desc=L["Size settings"],
inline=true,
order=2,
args = {
dispellAdjustSize = {
type="toggle",
name=L["Dispell Adjust Size"],
desc=L["Adjust dispell size to the frame size"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
order=5,
},
dispellSize = {
type="range",
name=L["Dispell Size"],
desc=L["Size of the dispell"],
min=10, max=100, step=1,
disabled=function() return Gladius.dbi.profile.dispellAdjustSize or not Gladius.dbi.profile.modules[self.name] end,
order=10,
},
},
},
position = {
type="group",
name=L["Position"],
desc=L["Position settings"],
inline=true,
order=3,
args = {
dispellAttachTo = {
type="select",
name=L["Dispell Attach To"],
desc=L["Attach dispell to the given frame"],
values=function() return Gladius:GetModules(self.name) end,
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
arg="general",
order=5,
},
dispellPosition = {
type="select",
name=L["Dispell Position"],
desc=L["Position of the dispell"],
values={ ["LEFT"] = L["Left"], ["RIGHT"] = L["Right"] },
get=function() return strfind(Gladius.db.dispellAnchor, "RIGHT") and "LEFT" or "RIGHT" end,
set=function(info, value)
if (value == "LEFT") then
Gladius.db.dispellAnchor = "TOPRIGHT"
Gladius.db.dispellRelativePoint = "TOPLEFT"
else
Gladius.db.dispellAnchor = "TOPLEFT"
Gladius.db.dispellRelativePoint = "TOPRIGHT"
end
Gladius:UpdateFrame(info[1])
end,
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
hidden=function() return Gladius.db.advancedOptions end,
order=6,
},
sep = {
type = "description",
name="",
width="full",
order=7,
},
dispellAnchor = {
type="select",
name=L["Dispell Anchor"],
desc=L["Anchor of the dispell"],
values=function() return Gladius:GetPositions() end,
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
hidden=function() return not Gladius.db.advancedOptions end,
order=10,
},
dispellRelativePoint = {
type="select",
name=L["Dispell Relative Point"],
desc=L["Relative point of the dispell"],
values=function() return Gladius:GetPositions() end,
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
hidden=function() return not Gladius.db.advancedOptions end,
order=15,
},
sep2 = {
type = "description",
name="",
width="full",
order=17,
},
dispellOffsetX = {
type="range",
name=L["Dispell Offset X"],
desc=L["X offset of the dispell"],
min=-100, max=100, step=1,
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
order=20,
},
dispellOffsetY = {
type="range",
name=L["Dispell Offset Y"],
desc=L["Y offset of the dispell"],
disabled=function() return not Gladius.dbi.profile.modules[self.name] end,
min=-50, max=50, step=1,
order=25,
},
},
},
},
},
}
end