--[[ Blessed by Ailae of Emeriss-EU Credits to zork (of Roth UI) for texture. ]] local pguid local locked = true -- default position local defaults = { framePoint = "CENTER", xOfs = 0, yOfs = -150, } local db -- cosmetics local iconSize = 36 local Blessed = CreateFrame("Frame", nil, UIParent) Blessed:RegisterEvent("ADDON_LOADED") Blessed:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end) -- Add a prefix local function Print(...) print("|cff00aaffBlessed:|r", ...) end -- Format: [spell] = (duration) local spells = { [1044] = 6, -- Hand of Freedom [1022] = 10, -- Hand of Protection [6940] = 12, -- Hand of Sacrifice [1038] = 10, -- Hand of Salvation [53563] = 300, -- Light's Beacon [54428] = 9, -- Divine Plea [53657] = 60, -- Judgement of the Pure (Rank 3, but who hasn't got 3/3 in this?) [87342] = 20, -- Holy Shield [84963] = 12, -- Inquisition [82327] = 10, -- Holy Radiance -- [88819] = 12, -- Daybreak [85433] = 10, -- Sacred Duty [94686] = 15, -- Crusader [54149] = 15, -- Infusion of Light [91155] = 120, -- Core of Ripeness [498] = 12, -- Divine Protection [86150] = 18, -- Guardian of Ancient Kings [91024] = 20, -- Theralion's Mirror [74241] = 12, -- Power Torrent [74243] = 10, -- Windwalk [86627] = 10, -- Incite (Warrior) [871] = 12, -- Shield Wall } local INQUISITION = GetSpellInfo(84963) local colors = setmetatable({ DEATHKNIGHT = "c41e3a", DRUID = "ff7c0a", HUNTER = "aad372", MAGE = "68ccef", PALADIN = "f48cba", PRIEST = "ffffff", ROGUE = "fff468", SHAMAN = "0070dd", WARLOCK = "9382c9", WARRIOR = "c69b6d", }, { __index = function() return "ffffff" end }) -- Empty tables for our frames local frames = {} local framePool = {} function Blessed:Init() self:SetBackdrop({ bgFile = "Interface\\ChatFrame\\ChatFrameBackground", insets = {top = 0, left = 0, bottom = 0, right = 0}, }) self:SetBackdropColor(1, 1, 1, 0) self:SetWidth(iconSize) self:SetHeight(iconSize) self:SetPoint(db.framePoint, db.xOfs, db.yOfs) self:SetMovable(true) self:SetScript("OnMouseDown", function() if(IsShiftKeyDown() and not locked) then self:ClearAllPoints() self:StartMoving() end end) self:SetScript("OnMouseUp", function() self:StopMovingOrSizing() db.framePoint, _, _, db.xOfs, db.yOfs = self:GetPoint() end) local text = self:CreateFontString(nil, "OVERLAY") text:SetFontObject(SystemFont_Shadow_Med1) text:SetPoint("TOP", self, "TOP", 0, 16) text:SetTextColor(1, 0.82, 0) self.header = text end function Blessed:ADDON_LOADED(name) if name ~= "Blessed" then return end self:UnregisterEvent("ADDON_LOADED") BlessedDB = BlessedDB or defaults db = BlessedDB local class = select(2, UnitClass("player")) if class then self:RegisterEvent("PLAYER_ENTERING_WORLD") self:Init() SLASH_Blessed1 = "/blessed" SlashCmdList.Blessed = function(input) local input = string.lower(input) if (input == "test") then self:SetupIcon(54428, "Test Icon", pguid) Print("Showing test-timer.") elseif (input == "lock") then if locked then self.header:SetText("Blessed") self:SetBackdropColor(1, 1, 1, 0.25) Print("Unlocked. Press down SHIFT and drag the square to move.") else self.header:SetText("") self:SetBackdropColor(1, 1, 1, 0) Print("Locked.") end locked = not locked self:EnableMouse(not locked) elseif input == "size" then Print("Active frames:", #frames) Print("Pool:", #framePool) Print("Total:", #frames+#framePool) else Print("Incorrect or no command given. Please use '/blessed test' (display a test-timer) or '/blessed lock' (to toggle lock).") end end else Print("This addon has no use for any other class than a Paladin, you should consider disabling it for this character.") end end -- Only activate buff-tracking if the player is a paladin function Blessed:PLAYER_ENTERING_WORLD() self:UnregisterEvent("PLAYER_ENTERING_WORLD") self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") pguid = UnitGUID("player") -- this is to make sure talents are loaded or if we need -- to delay the check if (GetNumTalentTabs() == 0) then self:RegisterEvent("PLAYER_ALIVE") else self:UpdateDurations() end self.PLAYER_ALIVE = self.UpdateDurations self:RegisterEvent("CHARACTER_POINTS_CHANGED") self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") end -- Check talents for updates function Blessed:UpdateDurations() -- Hand of Freedom local rank, maxRank = select(5, GetTalentInfo(3, 4)) if rank == maxRank then spells[1044] = 10 else spells[1044] = 6 end self:UnregisterEvent("PLAYER_ALIVE") end -- Perform checks for all these events Blessed.CHARACTER_POINTS_CHANGED = Blessed.UpdateDurations Blessed.ACTIVE_TALENT_GROUP_CHANGED = Blessed.UpdateDurations -- Handle stuff, plx function Blessed:COMBAT_LOG_EVENT_UNFILTERED(timestamp, combatEvent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlagsTwo, destGUID, destName, destFlags, destFlagsTwo, spellID, ...) if sourceGUID ~= pguid or not spells[spellID] then return end if (combatEvent == "SPELL_AURA_REMOVED") then self:RemoveFrame(spellID, false) elseif (combatEvent == "SPELL_AURA_APPLIED") then self:SetupIcon(spellID, destName, destGUID) elseif (combatEvent == "SPELL_AURA_REFRESH") then self:RemoveFrame(spellID, true) self:SetupIcon(spellID, destName, destGUID) end end -- Reanchor frames function Blessed:UpdateFrames() if #frames == 0 then return end for i, frame in pairs(frames) do frame:ClearAllPoints() if i > 1 then frame:SetPoint("LEFT", frames[i - 1], "RIGHT", 15, 0) else frame:SetPoint("CENTER", self, "CENTER") end end end -- Remove bar function Blessed:RemoveFrame(spellID, refresh) if #frames == 0 then return end for i, frame in pairs(frames) do if frame.id == spellID then frame:Hide() table.remove(frames, i) table.insert(framePool, frame) self:UpdateFrames() end end end -- Update barinfo local function update(self, elapsed) self.duration = self.duration - elapsed self.update = self.update - elapsed if self.update > 0 then return end self.update = self.update + 1 if self.duration > 60 then self.timer:SetFormattedText("%.0fm", ceil(self.duration/60)) else self.timer:SetFormattedText("%.0f", floor(self.duration)) end if self.duration <= 0 then Blessed:RemoveFrame(self.id) elseif self.duration <= 5 then self.timer:SetTextColor(1, 0, 0) end end -- Framemananger, return a new frame if there's no old frame available function Blessed:GetFrame() if (#framePool > 0) then return table.remove(framePool, 1) end local frame = CreateFrame("Frame", nil, UIParent) frame:SetSize(iconSize, iconSize) frame:SetPoint("CENTER", self) -- Icon frame.icon = frame:CreateTexture(nil, "ARTWORK") frame.icon:SetSize(iconSize, iconSize) frame.icon:SetTexCoord(0.03, 0.97, 0.02, 0.97) frame.icon:SetAllPoints(frame) -- Targettext frame.target = frame:CreateFontString(nil, "OVERLAY") frame.target:SetFontObject(SystemFont_Shadow_Med1) frame.target:SetPoint("BOTTOM", frame, "TOP", 0, 5) frame.target:SetTextColor(1, 1, 1) frame.target:SetShadowOffset(1, -1) -- Timertext frame.timer = frame:CreateFontString(nil, "OVERLAY") frame.timer:SetFontObject(SystemFont_Shadow_Large) frame.timer:SetPoint("TOP", frame, "BOTTOM", 0, -5) frame.timer:SetTextColor(1, 1, 1) frame.timer:SetShadowOffset(1, -1) -- Cooldown-model (beta) frame.cd = CreateFrame("Cooldown", nil, frame, "CooldownFrameTemplate") frame.cd:SetSize(iconSize, iconSize) frame.cd:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2) frame.cd:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2) frame.cd.noCooldownCount = true -- prevent OmniCC if present -- Border frame.border = frame:CreateTexture(nil, "OVERLAY") frame.border:SetParent(frame) frame.border:SetTexture('Interface\\AddOns\\Blessed\\simplesquare_roth') frame.border:SetPoint('TOPRIGHT', frame, 2, 2) frame.border:SetPoint('BOTTOMLEFT', frame, -2, -2) frame.border:SetVertexColor(0.3, 0.3, 0.3) return frame end -- Setup a timer function Blessed:SetupIcon(spellID, targetName, targetGUID) local frame = self:GetFrame() local duration = spells[spellID] if spellID == 84963 then duration = select(6, UnitAura("player", INQUISITION)) end local icon = select(3, GetSpellInfo(spellID)) local class = select(2, GetPlayerInfoByGUID(targetGUID)) frame.icon:SetTexture(icon) frame.target:SetFormattedText("|cff%s%s|r", colors[class], targetGUID ~= pguid and string.sub(targetName, 0, 3) or "You!") if duration > 60 then frame.timer:SetFormattedText("%.0fm", ceil(duration/60)) else frame.timer:SetFormattedText("%.0f", floor(duration)) end frame.timer:SetTextColor(1, 1, 1) frame.duration = duration frame.id = spellID frame.update = 1 frame.cd:SetCooldown(GetTime(), duration) table.insert(frames, frame) frame:SetScript("OnUpdate", update) self:UpdateFrames() frame:Show() end