/trunk
Credits to zork (of Roth UI) for texture. |
]] |
local ADDON, ns = ... |
local pguid |
local locked = true |
local db |
-- cosmetics |
local font = SystemFont_Shadow_Med1 |
local fontTimer = SystemFont_Shadow_Large |
local iconSize = 36 |
local Blessed = CreateFrame("Frame", "Blessed_Anchor", UIParent) |
local Blessed = CreateFrame("Frame", nil, UIParent) |
Blessed:RegisterEvent("ADDON_LOADED") |
Blessed:SetScript("OnEvent", function(self, event, ...) |
end) |
-- Add a prefix |
local function Print(output) |
print("|cff00aaffBlessed:|r " .. output) |
local function Print(...) |
print("|cff00aaffBlessed:|r", ...) |
end |
-- Format: [spell] = (duration) |
[54149] = 15, -- Infusion of Light |
} |
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]=], |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
insets = {top = 0, left = 0, bottom = 0, right = 0}, |
}) |
self:SetBackdropColor(1, 1, 1, 0) |
self:SetMovable(true) |
-- yeh bebe, move it! |
self:SetScript("OnMouseDown", function() |
if(IsShiftKeyDown() and not locked) then |
self:ClearAllPoints() |
end) |
local text = self:CreateFontString(nil, "OVERLAY") |
text:SetFontObject(font) |
text:SetFontObject(SystemFont_Shadow_Med1) |
text:SetPoint("TOP", self, "TOP", 0, 16) |
text:SetTextColor(1, 0.82, 0) |
text:SetText("") |
self.header = text |
end |
SlashCmdList.Blessed = function(input) |
local input = string.lower(input) |
if (input == "test") then |
self:SetupIcon(54428, "Test Icon", pguid, pguid) |
self:SetupIcon(54428, "Test Icon", pguid) |
Print("Showing test-timer.") |
elseif (input == "lock") then |
if locked then |
self:EnableMouse(true) |
locked = false |
self.header:SetText("Blessed") |
self:SetBackdropColor(1, 1, 1, 0.25) |
Print("Unlocked. Press down SHIFT and drag the square to move.") |
else |
self:EnableMouse(false) |
locked = true |
self.header:SetText("") |
self:SetBackdropColor(1, 1, 1, 0) |
Print("Locked.") |
end |
elseif (input == "debug") then |
Print("Number of frames in the pool: " .. (#framePool or 0)) |
Print("Current durations:") |
for k, v in pairs(spells) do |
local name, _, _, _, _, _, _, _, _ = GetSpellInfo(k) |
if not name then Print("No value for key: " .. k) end |
Print(name .. ": " .. v) |
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.") |
Print("This addon has no use for any other class than a Paladin, you should consider disabling it for this character.") |
end |
end |
self:UpdateDurations() |
end |
self.PLAYER_ALIVE = self.UpdateDurations |
self:RegisterEvent("CHARACTER_POINTS_CHANGED") |
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") |
end |
-- Talents are only available at this point when you're logging in |
-- so we need to update durations. |
function Blessed:PLAYER_ALIVE() |
self:UpdateDurations() |
self:UnregisterEvent("PLAYER_ALIVE") |
end |
-- Check talents for updates |
function Blessed:UpdateDurations() |
-- Hand of Freedom |
local _, _, _, _, rank, maxRank, _, _ = GetTalentInfo(3, 4) |
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.ACTIVE_TALENT_GROUP_CHANGED = Blessed.UpdateDurations |
-- Handle stuff, plx |
function Blessed:COMBAT_LOG_EVENT_UNFILTERED(timestamp, combatEvent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, ...) |
if sourceGUID and sourceGUID ~= pguid then return end |
function Blessed:COMBAT_LOG_EVENT_UNFILTERED(timestamp, combatEvent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, spellID, ...) |
if sourceGUID ~= pguid or not spells[spellID] then return end |
if (combatEvent == "SPELL_AURA_REMOVED") then |
local spellID, _, _, _ = select(1, ...) |
if spells[spellID] then |
self:RemoveFrame(spellID .. sourceGUID .. destGUID) |
end |
self:RemoveFrame(spellID, false) |
elseif (combatEvent == "SPELL_AURA_APPLIED") then |
local spellID, spellName, _, _ = select(1, ...) |
if (spells[spellID]) then |
-- special handling for Inquisition, sigh |
if spellID == 84963 and spellName then |
local duration, expirationTime = select(6, UnitAura("player", spellName)) |
spells[84963] = duration |
end |
self:SetupIcon(spellID, destName, sourceGUID, destGUID) |
end |
self:SetupIcon(spellID, destName, destGUID) |
elseif (combatEvent == "SPELL_AURA_REFRESH") then |
local spellID, spellName, _, _ = select(1, ...) |
if (spells[spellID]) then |
self:RemoveFrame(spellID .. sourceGUID .. destGUID) |
-- special handling for Inquisition, sigh |
if spellID == 84963 and spellName then |
local duration, expirationTime = select(6, UnitAura("player", spellName)) |
spells[84963] = duration |
end |
self:SetupIcon(spellID, destName, sourceGUID, destGUID) |
end |
self:RemoveFrame(spellID, true) |
self:SetupIcon(spellID, destName, destGUID) |
end |
end |
-- Reanchor frames |
-- If it's frame #1, anchor it to anchorframe (teehee). If it's frame #n (!1) anchor it to the right of frame #n-1. |
function Blessed:UpdateFrames() |
if #frames == 0 then return end |
for i, frame in ipairs(frames) do |
for i, frame in pairs(frames) do |
frame:ClearAllPoints() |
if i > 1 then |
frame:SetPoint("LEFT", frames[i - 1], "RIGHT", 15, 0) |
end |
-- Remove bar |
function Blessed:RemoveFrame(id) |
function Blessed:RemoveFrame(spellID, refresh) |
if #frames == 0 then return end |
for i, frame in pairs(frames) do |
if frame.id == id then |
if frame.id == spellID then |
frame:Hide() |
table.remove(frames, i) |
table.insert(framePool, frame) |
self:UpdateFrames() -- reanchor frames |
self:UpdateFrames() |
end |
end |
end |
-- Update barinfo |
local function update(self, elapsed) |
self.time = GetTime() |
if self.time - self.lastUpdate < 1 then return end |
self.duration = self.duration - elapsed |
self.update = self.update - elapsed |
if self.update > 0 then return end |
self.duration = self.duration - (self.time - self.lastUpdate) |
self.lastUpdate = self.time |
self.timer:SetTextColor(1, 1, 1) |
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 -- indicate that there is equalorless than 5 secs left |
Blessed:RemoveFrame(self.id) |
elseif self.duration <= 5 then |
self.timer:SetTextColor(1, 0, 0) |
end |
end |
end |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:SetHeight(iconSize) |
frame:SetWidth(iconSize) |
frame:SetSize(iconSize, iconSize) |
frame:SetPoint("CENTER", self) |
-- Icon |
frame.icon = frame:CreateTexture(nil, "ARTWORK") |
frame.icon:SetHeight(iconSize) |
frame.icon:SetWidth(iconSize) |
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(font) |
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(fontTimer) |
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:SetHeight(iconSize) |
frame.cd:SetWidth(iconSize) |
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 |
-- Overlay |
frame.overlay = CreateFrame("Frame", nil, frame) |
frame.overlay:SetAllPoints(frame) |
frame.overlay:SetParent(frame) |
-- Border |
frame.border = frame.overlay:CreateTexture(nil, "OVERLAY") |
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) |
end |
-- Setup a timer |
local color = {} |
function Blessed:SetupIcon(spellID, targetName, sourceGUID, targetGUID) |
function Blessed:SetupIcon(spellID, targetName, targetGUID) |
local frame = self:GetFrame() |
local duration = spells[spellID] |
local icon = select(3, GetSpellInfo(spellID)) |
targetName = string.sub(targetName, 0, 3) |
local class = select(2, GetPlayerInfoByGUID(targetGUID)) |
if spellID == 84963 then |
duration = select(6, UnitAura("player", INQUISITION)) |
end |
if targetGUID == pguid then |
targetName = "You!" |
class = "PALADIN" |
end |
local icon = select(3, GetSpellInfo(spellID)) |
local class = select(2, GetPlayerInfoByGUID(targetGUID)) |
frame.icon:SetTexture(icon) |
color = RAID_CLASS_COLORS[class] or { r = 1, g = 1, b =1 } |
frame.target:SetTextColor(color.r, color.g, color.b) |
frame.target:SetText(targetName or "Unknown") |
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)) |
end |
frame.timer:SetTextColor(1, 1, 1) |
-- Nifty stuff |
frame.duration = duration |
frame.id = spellID .. sourceGUID .. targetGUID |
frame.lastUpdate = GetTime() |
frame.id = spellID |
frame.update = 1 |
frame.cd:SetCooldown(GetTime(), duration) |
table.insert(frames, frame) |
frame:SetScript("OnUpdate", update) |
-- when a frame is shown, reanchor all the frames accordingly |
self:UpdateFrames() |
frame:Show() |
end |