WoWInterface SVN Blessed

[/] [Blessed.lua] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Ailae-78500
--[[
2 Ailae-78500
        Blessed
3 Ailae-78500
        by Ailae of Emeriss-EU
4 Ailae-78500
 
5 Ailae-78500
        Credits to zork (of Roth UI) for texture.
6 Ailae-78500
]]
7 Ailae-78500
 
8 Ailae-78500
local ADDON, ns = ...
9 Ailae-78500
local pguid
10 Ailae-78500
local locked = true
11 Ailae-78500
 
12 Ailae-78500
-- default position
13 Ailae-78500
local defaults = {
14 Ailae-78500
        framePoint = "CENTER",
15 Ailae-78500
        xOfs = 0,
16 Ailae-78500
        yOfs = -150,
17 Ailae-78500
}
18 Ailae-78500
local db
19 Ailae-78500
 
20 Ailae-78500
-- cosmetics
21 Ailae-78500
local font = SystemFont_Shadow_Med1
22 Ailae-78500
local fontTimer = SystemFont_Shadow_Large
23 Ailae-78500
local iconSize = 36
24 Ailae-78500
 
25 Ailae-78500
local Blessed = CreateFrame("Frame", "Blessed_Anchor", UIParent)
26 Ailae-78500
Blessed:RegisterEvent("ADDON_LOADED")
27 Ailae-78500
 
28 Ailae-78500
Blessed:SetScript("OnEvent", function(self, event, ...)
29 Ailae-78500
    self[event](self, ...)
30 Ailae-78500
end)
31 Ailae-78500
 
32 Ailae-78500
-- Add a prefix
33 Ailae-78500
local function Print(output)
34 Ailae-78500
        print("|cff00aaffBlessed:|r " .. output)
35 Ailae-78500
end
36 Ailae-78500
 
37 Ailae-78500
-- Format: [spell] = (duration)
38 Ailae-78500
local spells = {
39 Ailae-78500
        [1044] = 6, -- Hand of Freedom
40 Ailae-78500
        [1022] = 10, -- Hand of Protection
41 Ailae-78500
        [6940] = 12, -- Hand of Sacrifice
42 Ailae-78500
        [1038] = 10, -- Hand of Salvation
43 Ailae-78500
        [53563] = 300, -- Light's Beacon
44 Ailae-78500
        [54428] = 15, -- Divine Plea
45 Ailae-78500
        [53657] = 60, -- Judgement of the Pure (Rank 3, but who hasn't got 3/3 in this?)
46 Ailae-78500
        [87342] = 20, -- Holy Shield
47 Ailae-78500
        [84963] = 12, -- Inquisition
48 Ailae-78500
        [82327] = 10, -- Holy Radiance
49 Ailae-78500
        -- [88819] = 12, -- Daybreak
50 Ailae-78500
        [85433] = 15, -- Sacred Duty
51 Ailae-78500
        [94686] = 15, -- Crusader
52 Ailae-78500
        [54149] = 15, -- Infusion of Light
53 Ailae-78500
}
54 Ailae-78500
 
55 Ailae-78500
-- Empty tables for our frames
56 Ailae-78500
local frames = {}
57 Ailae-78500
local framePool = {}
58 Ailae-78500
 
59 Ailae-78500
function Blessed:Init()
60 Ailae-78500
        self:SetBackdrop({
61 Ailae-78500
                bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=],
62 Ailae-78500
                insets = {top = 0, left = 0, bottom = 0, right = 0},
63 Ailae-78500
        })
64 Ailae-78500
        self:SetBackdropColor(1, 1, 1, 0)
65 Ailae-78500
 
66 Ailae-78500
        self:SetWidth(iconSize)
67 Ailae-78500
        self:SetHeight(iconSize)
68 Ailae-78500
        self:SetPoint(db.framePoint, db.xOfs, db.yOfs)
69 Ailae-78500
 
70 Ailae-78500
        self:SetMovable(true)
71 Ailae-78500
 
72 Ailae-78500
        -- yeh bebe, move it!
73 Ailae-78500
        self:SetScript("OnMouseDown", function()
74 Ailae-78500
                if(IsShiftKeyDown() and not locked) then
75 Ailae-78500
                        self:ClearAllPoints()
76 Ailae-78500
                        self:StartMoving()
77 Ailae-78500
                end
78 Ailae-78500
        end)
79 Ailae-78500
 
80 Ailae-78500
        self:SetScript("OnMouseUp", function()
81 Ailae-78500
                self:StopMovingOrSizing()
82 Ailae-78500
                db.framePoint, _, _, db.xOfs, db.yOfs = self:GetPoint()
83 Ailae-78500
        end)
84 Ailae-78500
 
85 Ailae-78500
        local text = self:CreateFontString(nil, "OVERLAY")
86 Ailae-78500
        text:SetFontObject(font)
87 Ailae-78500
        text:SetPoint("TOP", self, "TOP", 0, 16)
88 Ailae-78500
        text:SetTextColor(1, 0.82, 0)
89 Ailae-78500
        text:SetText("")
90 Ailae-78500
        self.header = text
91 Ailae-78500
end
92 Ailae-78500
 
93 Ailae-78500
function Blessed:ADDON_LOADED(name)
94 Ailae-78500
        if name ~= "Blessed" then return end
95 Ailae-78500
        self:UnregisterEvent("ADDON_LOADED")
96 Ailae-78500
 
97 Ailae-78500
        BlessedDB = BlessedDB or defaults
98 Ailae-78500
        db = BlessedDB
99 Ailae-78500
 
100 Ailae-78500
        local class = select(2, UnitClass("player"))
101 Ailae-78500
        if class == "PALADIN" then -- only do stuff if player is a paladin
102 Ailae-78500
                self:RegisterEvent("PLAYER_ENTERING_WORLD")
103 Ailae-78500
                self:Init()
104 Ailae-78500
 
105 Ailae-78500
                SLASH_Blessed1 = "/blessed"
106 Ailae-78500
                SlashCmdList.Blessed = function(input)
107 Ailae-78500
                        local input = string.lower(input)
108 Ailae-78500
                        if (input == "test") then
109 Ailae-78500
                                self:SetupIcon(54428, "Test Icon", pguid, pguid)
110 Ailae-78500
                                Print("Showing test-timer.")
111 Ailae-78500
                        elseif (input == "lock") then
112 Ailae-78500
                                if locked then
113 Ailae-78500
                                        self:EnableMouse(true)
114 Ailae-78500
                                        locked = false
115 Ailae-78500
                                        self.header:SetText("Blessed")
116 Ailae-78500
                                        self:SetBackdropColor(1, 1, 1, 0.25)
117 Ailae-78500
                                        Print("Unlocked. Press down SHIFT and drag the square to move.")
118 Ailae-78500
                                else
119 Ailae-78500
                                        self:EnableMouse(false)
120 Ailae-78500
                                        locked = true
121 Ailae-78500
                                        self.header:SetText("")
122 Ailae-78500
                                        self:SetBackdropColor(1, 1, 1, 0)
123 Ailae-78500
                                        Print("Locked.")
124 Ailae-78500
                                end
125 Ailae-78500
                        elseif (input == "debug") then
126 Ailae-78500
                                Print("Number of frames in the pool: " .. (#framePool or 0))
127 Ailae-78500
                                Print("Current durations:")
128 Ailae-78500
                                for k, v in pairs(spells) do
129 Ailae-78500
                                        local name, _, _, _, _, _, _, _, _ = GetSpellInfo(k)
130 Ailae-78500
                                        if not name then Print("No value for key: " .. k) end
131 Ailae-78500
                                        Print(name .. ": " .. v)
132 Ailae-78500
                                end
133 Ailae-78500
                        else
134 Ailae-78500
                                Print("Incorrect or no command given. Please use '/blessed test' (display a test-timer) or '/blessed lock' (to toggle lock).")
135 Ailae-78500
                        end
136 Ailae-78500
                end
137 Ailae-78500
        else
138 Ailae-78500
                print("This addon has no use for any other class than a Paladin, you should consider disabling it for this character.")
139 Ailae-78500
        end
140 Ailae-78500
end
141 Ailae-78500
 
142 Ailae-78500
-- Only activate buff-tracking if the player is a paladin
143 Ailae-78500
function Blessed:PLAYER_ENTERING_WORLD()
144 Ailae-78500
        self:UnregisterEvent("PLAYER_ENTERING_WORLD")
145 Ailae-78500
        self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
146 Ailae-78500
 
147 Ailae-78500
        pguid = UnitGUID("player")
148 Ailae-78500
 
149 Ailae-78500
        -- this is to make sure talents are loaded or if we need
150 Ailae-78500
        -- to delay the check
151 Ailae-78500
        if (GetNumTalentTabs() == 0) then
152 Ailae-78500
                self:RegisterEvent("PLAYER_ALIVE")
153 Ailae-78500
        else
154 Ailae-78500
                self:UpdateDurations()
155 Ailae-78500
        end
156 Ailae-78500
 
157 Ailae-78500
        self:RegisterEvent("CHARACTER_POINTS_CHANGED")
158 Ailae-78500
        self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
159 Ailae-78500
end
160 Ailae-78500
 
161 Ailae-78500
-- Talents are only available at this point when you're logging in
162 Ailae-78500
-- so we need to update durations.
163 Ailae-78500
function Blessed:PLAYER_ALIVE()
164 Ailae-78500
        self:UpdateDurations()
165 Ailae-78500
        self:UnregisterEvent("PLAYER_ALIVE")
166 Ailae-78500
end
167 Ailae-78500
 
168 Ailae-78500
-- Check talents for updates
169 Ailae-78500
function Blessed:UpdateDurations()
170 Ailae-78500
        -- Hand of Freedom
171 Ailae-78500
        local _, _, _, _, rank, maxRank, _, _ = GetTalentInfo(3, 4)
172 Ailae-78500
        if rank == maxRank then
173 Ailae-78500
                spells[1044] = 10
174 Ailae-78500
        else
175 Ailae-78500
                spells[1044] = 6
176 Ailae-78500
        end
177 Ailae-78500
end
178 Ailae-78500
 
179 Ailae-78500
-- Perform checks for all these events
180 Ailae-78500
Blessed.CHARACTER_POINTS_CHANGED = Blessed.UpdateDurations
181 Ailae-78500
Blessed.ACTIVE_TALENT_GROUP_CHANGED = Blessed.UpdateDurations
182 Ailae-78500
 
183 Ailae-78500
-- Handle stuff, plx
184 Ailae-78500
function Blessed:COMBAT_LOG_EVENT_UNFILTERED(timestamp, combatEvent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, ...)
185 Ailae-78500
        if sourceGUID and sourceGUID ~= pguid then return end
186 Ailae-78500
 
187 Ailae-78500
        if (combatEvent == "SPELL_AURA_REMOVED") then
188 Ailae-78500
                local spellID, _, _, _ = select(1, ...)
189 Ailae-78500
                if spells[spellID] then
190 Ailae-78500
                        self:RemoveFrame(spellID .. sourceGUID .. destGUID)
191 Ailae-78500
                end
192 Ailae-78500
        elseif (combatEvent == "SPELL_AURA_APPLIED") then
193 Ailae-78500
                local spellID, spellName, _, _ = select(1, ...)
194 Ailae-78500
                if (spells[spellID]) then
195 Ailae-78500
                        -- special handling for Inquisition, sigh
196 Ailae-78500
                        if spellID == 84963 and spellName then
197 Ailae-78500
                                local duration, expirationTime = select(6, UnitAura("player", spellName))
198 Ailae-78500
                                spells[84963] = duration
199 Ailae-78500
                        end
200 Ailae-78500
                        self:SetupIcon(spellID, destName, sourceGUID, destGUID)
201 Ailae-78500
                end
202 Ailae-78500
        elseif (combatEvent == "SPELL_AURA_REFRESH") then
203 Ailae-78500
                local spellID, spellName, _, _ = select(1, ...)
204 Ailae-78500
                if (spells[spellID]) then
205 Ailae-78500
                        self:RemoveFrame(spellID .. sourceGUID .. destGUID)
206 Ailae-78500
                        -- special handling for Inquisition, sigh
207 Ailae-78500
                        if spellID == 84963 and spellName then
208 Ailae-78500
                                local duration, expirationTime = select(6, UnitAura("player", spellName))
209 Ailae-78500
                                spells[84963] = duration
210 Ailae-78500
                        end
211 Ailae-78500
                        self:SetupIcon(spellID, destName, sourceGUID, destGUID)
212 Ailae-78500
                end
213 Ailae-78500
        end
214 Ailae-78500
end
215 Ailae-78500
 
216 Ailae-78500
-- Reanchor frames
217 Ailae-78500
-- 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.
218 Ailae-78500
function Blessed:UpdateFrames()
219 Ailae-78500
        if #frames == 0 then return end
220 Ailae-78500
 
221 Ailae-78500
        for i, frame in ipairs(frames) do
222 Ailae-78500
                frame:ClearAllPoints()
223 Ailae-78500
                if i > 1 then
224 Ailae-78500
                        frame:SetPoint("LEFT", frames[i - 1], "RIGHT", 15, 0)
225 Ailae-78500
                else
226 Ailae-78500
                        frame:SetPoint("CENTER", self, "CENTER")
227 Ailae-78500
                end
228 Ailae-78500
        end
229 Ailae-78500
end
230 Ailae-78500
 
231 Ailae-78500
-- Remove bar
232 Ailae-78500
function Blessed:RemoveFrame(id)
233 Ailae-78500
        if #frames == 0 then return end
234 Ailae-78500
 
235 Ailae-78500
        for i, frame in pairs(frames) do
236 Ailae-78500
                if frame.id == id then
237 Ailae-78500
                        frame:Hide()
238 Ailae-78500
                        table.remove(frames, i)
239 Ailae-78500
                        table.insert(framePool, frame)
240 Ailae-78500
                        self:UpdateFrames() -- reanchor frames
241 Ailae-78500
                end
242 Ailae-78500
        end
243 Ailae-78500
end
244 Ailae-78500
 
245 Ailae-78500
-- Update barinfo
246 Ailae-78500
local function update(self, elapsed)
247 Ailae-78500
        self.time = GetTime()
248 Ailae-78500
        if self.time - self.lastUpdate < 1 then return end
249 Ailae-78500
 
250 Ailae-78500
        self.duration = self.duration - (self.time - self.lastUpdate)
251 Ailae-78500
        self.lastUpdate = self.time
252 Ailae-78500
        self.timer:SetTextColor(1, 1, 1)
253 Ailae-78500
        if self.duration > 60 then
254 Ailae-78500
                self.timer:SetFormattedText("%.0fm", ceil(self.duration/60))
255 Ailae-78500
        else
256 Ailae-78500
                self.timer:SetFormattedText("%.0f", floor(self.duration))
257 Ailae-78500
        end
258 Ailae-78500
 
259 Ailae-78500
 
260 Ailae-78500
        if self.duration <= 0 then
261 Ailae-78500
                Blessed:RemoveFrame(self.id)
262 Ailae-78500
        elseif self.duration <= 5 then -- indicate that there is equalorless than 5 secs left
263 Ailae-78500
                self.timer:SetTextColor(1, 0, 0)
264 Ailae-78500
        end
265 Ailae-78500
end
266 Ailae-78500
 
267 Ailae-78500
-- Framemananger, return a new frame if there's no old frame available
268 Ailae-78500
function Blessed:GetFrame()
269 Ailae-78500
        if (#framePool > 0) then
270 Ailae-78500
                return table.remove(framePool, 1)
271 Ailae-78500
        end
272 Ailae-78500
 
273 Ailae-78500
        local frame = CreateFrame("Frame", nil, UIParent)
274 Ailae-78500
        frame:SetHeight(iconSize)
275 Ailae-78500
        frame:SetWidth(iconSize)
276 Ailae-78500
        frame:SetPoint("CENTER", self)
277 Ailae-78500
 
278 Ailae-78500
        -- Icon
279 Ailae-78500
        frame.icon = frame:CreateTexture(nil, "ARTWORK")
280 Ailae-78500
        frame.icon:SetHeight(iconSize)
281 Ailae-78500
        frame.icon:SetWidth(iconSize)
282 Ailae-78500
        frame.icon:SetTexCoord(0.03, 0.97, 0.02, 0.97)
283 Ailae-78500
        frame.icon:SetAllPoints(frame)
284 Ailae-78500
 
285 Ailae-78500
        -- Targettext
286 Ailae-78500
        frame.target = frame:CreateFontString(nil, "OVERLAY")
287 Ailae-78500
        frame.target:SetFontObject(font)
288 Ailae-78500
        frame.target:SetPoint("BOTTOM", frame, "TOP", 0, 5)
289 Ailae-78500
        frame.target:SetTextColor(1, 1, 1)
290 Ailae-78500
        frame.target:SetShadowOffset(1, -1)
291 Ailae-78500
 
292 Ailae-78500
        -- Timertext
293 Ailae-78500
        frame.timer = frame:CreateFontString(nil, "OVERLAY")
294 Ailae-78500
        frame.timer:SetFontObject(fontTimer)
295 Ailae-78500
        frame.timer:SetPoint("TOP", frame, "BOTTOM", 0, -5)
296 Ailae-78500
        frame.timer:SetTextColor(1, 1, 1)
297 Ailae-78500
        frame.timer:SetShadowOffset(1, -1)
298 Ailae-78500
 
299 Ailae-78500
        -- Cooldown-model (beta)
300 Ailae-78500
        frame.cd = CreateFrame("Cooldown", nil, frame, "CooldownFrameTemplate")
301 Ailae-78500
        frame.cd:SetHeight(iconSize)
302 Ailae-78500
        frame.cd:SetWidth(iconSize)
303 Ailae-78500
        frame.cd:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2)
304 Ailae-78500
        frame.cd:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)
305 Ailae-78500
        frame.cd.noCooldownCount = true -- prevent OmniCC if present
306 Ailae-78500
 
307 Ailae-78500
        -- Overlay
308 Ailae-78500
        frame.overlay = CreateFrame("Frame", nil, frame)
309 Ailae-78500
        frame.overlay:SetAllPoints(frame)
310 Ailae-78500
        frame.overlay:SetParent(frame)
311 Ailae-78500
 
312 Ailae-78500
        -- Border
313 Ailae-78500
        frame.border = frame.overlay:CreateTexture(nil, "OVERLAY")
314 Ailae-78500
        frame.border:SetParent(frame)
315 Ailae-78500
        frame.border:SetTexture('Interface\\AddOns\\Blessed\\simplesquare_roth')
316 Ailae-78500
        frame.border:SetPoint('TOPRIGHT', frame, 2, 2)
317 Ailae-78500
        frame.border:SetPoint('BOTTOMLEFT', frame, -2, -2)
318 Ailae-78500
        frame.border:SetVertexColor(0.3, 0.3, 0.3)
319 Ailae-78500
 
320 Ailae-78500
        return frame
321 Ailae-78500
end
322 Ailae-78500
 
323 Ailae-78500
-- Setup a timer
324 Ailae-78500
local color = {}
325 Ailae-78500
function Blessed:SetupIcon(spellID, targetName, sourceGUID, targetGUID)
326 Ailae-78500
        local frame = self:GetFrame()
327 Ailae-78500
        local duration = spells[spellID]
328 Ailae-78500
        local icon = select(3, GetSpellInfo(spellID))
329 Ailae-78500
 
330 Ailae-78500
        targetName = string.sub(targetName, 0, 3)
331 Ailae-78500
        local class = select(2, GetPlayerInfoByGUID(targetGUID))
332 Ailae-78500
 
333 Ailae-78500
        if targetGUID == pguid then
334 Ailae-78500
                targetName = "You!"
335 Ailae-78500
                class = "PALADIN"
336 Ailae-78500
        end
337 Ailae-78500
 
338 Ailae-78500
        frame.icon:SetTexture(icon)
339 Ailae-78500
 
340 Ailae-78500
        color = RAID_CLASS_COLORS[class] or { r = 1, g = 1, b =1 }
341 Ailae-78500
        frame.target:SetTextColor(color.r, color.g, color.b)
342 Ailae-78500
        frame.target:SetText(targetName or "Unknown")
343 Ailae-78500
 
344 Ailae-78500
        if duration > 60 then
345 Ailae-78500
                frame.timer:SetFormattedText("%.0fm", ceil(duration/60))
346 Ailae-78500
        else
347 Ailae-78500
                frame.timer:SetFormattedText("%.0f", floor(duration))
348 Ailae-78500
        end
349 Ailae-78500
        frame.timer:SetTextColor(1, 1, 1)
350 Ailae-78500
 
351 Ailae-78500
        -- Nifty stuff
352 Ailae-78500
        frame.duration = duration
353 Ailae-78500
        frame.id = spellID .. sourceGUID .. targetGUID
354 Ailae-78500
        frame.lastUpdate = GetTime()
355 Ailae-78500
        frame.cd:SetCooldown(GetTime(), duration)
356 Ailae-78500
        table.insert(frames, frame)
357 Ailae-78500
 
358 Ailae-78500
        frame:SetScript("OnUpdate", update)
359 Ailae-78500
 
360 Ailae-78500
        -- when a frame is shown, reanchor all the frames accordingly
361 Ailae-78500
        self:UpdateFrames()
362 Ailae-78500
 
363 Ailae-78500
        frame:Show()
364 Ailae-78500
end