WoWInterface SVN fernir_UI

[/] [oUF/] [elements/] [aura.lua] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Wildbreath-135052
--[[
2 Wildbreath-135052
        Elements handled: .Auras, .Buffs, .Debuffs
3 Wildbreath-135052
 
4 Wildbreath-135052
        Shared:
5 Wildbreath-135052
         - spacing: Padding between aura icons. (Default: 0)
6 Wildbreath-135052
         - size: Size of the aura icons. (Default: 16)
7 Wildbreath-135052
         - initialAnchor: Initial anchor in the aura frame. (Default: "BOTTOMLEFT")
8 Wildbreath-135052
         - onlyShowPlayer: Only display icons casted by the player. (Default: nil)
9 Wildbreath-135052
         - growth-x: Growth direction, affected by initialAnchor. (Default: "UP")
10 Wildbreath-135052
         - growth-y: Growth direction, affected by initialAnchor. (Default: "RIGHT")
11 Wildbreath-135052
         - disableCooldown: Disable the Cooldown Spiral on the Aura Icons. (Default: nil)
12 Wildbreath-135052
         - filter: Expects a string with filter. See the UnitAura[1] documentation for
13 Wildbreath-135052
                more information.
14 Wildbreath-135052
 
15 Wildbreath-135052
        .Auras only:
16 Wildbreath-135052
         - gap: Adds a empty icon to separate buffs and debuffs. (Default: nil)
17 Wildbreath-135052
         - numBuffs: The maximum number of buffs that should be shown. (Default: 32)
18 Wildbreath-135052
         - numDebuffs: The maximum number of debuffs that should be shown. (Default: 40)
19 Wildbreath-135052
         - buffFilter: See filter on Shared. (Default: "HELPFUL")
20 Wildbreath-135052
         - debuffFilter: See filter on Shared. (Default: "HARMFUL")
21 Wildbreath-135052
         - Variables set by .Auras:
22 Wildbreath-135052
                 - visibleBuffs: Number of currently visible buff icons.
23 Wildbreath-135052
                 - visibleDebuffs: Number of currently visible debuff icons.
24 Wildbreath-135052
                 - visibleAuras: Total number of currently visible buffs + debuffs.
25 Wildbreath-135052
 
26 Wildbreath-135052
        .Buffs only:
27 Wildbreath-135052
         - num: The maximum number of buffs that should be shown. (Default: 32)
28 Wildbreath-135052
         - Variables set by .Buffs:
29 Wildbreath-135052
                 - visibleBuffs: Number of currently visible buff icons.
30 Wildbreath-135052
 
31 Wildbreath-135052
        .Debuffs only:
32 Wildbreath-135052
         - num: The maximum number of debuffs that should be shown. (Default: 40)
33 Wildbreath-135052
         - Variables set by .Debuffs:
34 Wildbreath-135052
                 - visibleDebuffs: Number of currently visible debuff icons.
35 Wildbreath-135052
 
36 Wildbreath-135052
        Functions that can be overridden from within a layout:
37 Wildbreath-135052
         - :PostCreateAuraIcon(icon, icons, index, isDebuff)
38 Wildbreath-135052
         - :CreateAuraIcon(icons, index, isDebuff)
39 Wildbreath-135052
         - :PostUpdateAuraIcon(icons, unit, icon, index, offset, filter, isDebuff)
40 Wildbreath-135052
         - :PreUpdateAura(event, unit)
41 Wildbreath-135052
         - :PreAuraSetPosition(auras, max)
42 Wildbreath-135052
         - :SetAuraPosition(auras, max)
43 Wildbreath-135052
         - :PostUpdateAura(event, unit)
44 Wildbreath-135052
 
45 Wildbreath-135052
        [1] http://www.wowwiki.com/API_UnitAura
46 Wildbreath-135052
--]]
47 Wildbreath-135052
local parent, ns = ...
48 Wildbreath-135052
local oUF = ns.oUF
49 Wildbreath-135052
 
50 Wildbreath-135052
local OnEnter = function(self)
51 Wildbreath-135052
        if(not self:IsVisible()) then return end
52 Wildbreath-135052
 
53 Wildbreath-135052
        GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
54 Wildbreath-135052
        GameTooltip:SetUnitAura(self.frame.unit, self:GetID(), self.filter)
55 Wildbreath-135052
end
56 Wildbreath-135052
 
57 Wildbreath-135052
local OnLeave = function()
58 Wildbreath-135052
        GameTooltip:Hide()
59 Wildbreath-135052
end
60 Wildbreath-135052
 
61 Wildbreath-135052
-- We don't really need to validate much here as the filter should prevent us
62 Wildbreath-135052
-- from doing something we shouldn't.
63 Wildbreath-135052
local OnClick = function(self)
64 Wildbreath-135052
        CancelUnitBuff(self.frame.unit, self:GetID(), self.filter)
65 Wildbreath-135052
end
66 Wildbreath-135052
 
67 Wildbreath-135052
local createAuraIcon = function(self, icons, index, debuff)
68 Wildbreath-135052
        local button = CreateFrame("Button", nil, icons)
69 Wildbreath-135052
        button:EnableMouse(true)
70 Wildbreath-135052
        button:RegisterForClicks'RightButtonUp'
71 Wildbreath-135052
 
72 Wildbreath-135052
        button:SetWidth(icons.size or 16)
73 Wildbreath-135052
        button:SetHeight(icons.size or 16)
74 Wildbreath-135052
 
75 Wildbreath-135052
        local cd = CreateFrame("Cooldown", nil, button)
76 Wildbreath-135052
        cd:SetAllPoints(button)
77 Wildbreath-135052
 
78 Wildbreath-135052
        local icon = button:CreateTexture(nil, "BACKGROUND")
79 Wildbreath-135052
        icon:SetAllPoints(button)
80 Wildbreath-135052
 
81 Wildbreath-135052
        local count = button:CreateFontString(nil, "OVERLAY")
82 Wildbreath-135052
        count:SetFontObject(NumberFontNormal)
83 Wildbreath-135052
        count:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -1, 0)
84 Wildbreath-135052
 
85 Wildbreath-135052
        local overlay = button:CreateTexture(nil, "OVERLAY")
86 Wildbreath-135052
        overlay:SetTexture"Interface\\Buttons\\UI-Debuff-Overlays"
87 Wildbreath-135052
        overlay:SetAllPoints(button)
88 Wildbreath-135052
        overlay:SetTexCoord(.296875, .5703125, 0, .515625)
89 Wildbreath-135052
        button.overlay = overlay
90 Wildbreath-135052
 
91 Wildbreath-135052
        button:SetScript("OnEnter", OnEnter)
92 Wildbreath-135052
        button:SetScript("OnLeave", OnLeave)
93 Wildbreath-135052
 
94 Wildbreath-135052
        if(self.unit == 'player') then
95 Wildbreath-135052
                button:SetScript('OnClick', OnClick)
96 Wildbreath-135052
        end
97 Wildbreath-135052
 
98 Wildbreath-135052
        table.insert(icons, button)
99 Wildbreath-135052
 
100 Wildbreath-135052
        button.parent = icons
101 Wildbreath-135052
        button.frame = self
102 Wildbreath-135052
        button.debuff = debuff
103 Wildbreath-135052
 
104 Wildbreath-135052
        button.icon = icon
105 Wildbreath-135052
        button.count = count
106 Wildbreath-135052
        button.cd = cd
107 Wildbreath-135052
 
108 Wildbreath-135052
        if(self.PostCreateAuraIcon) then self:PostCreateAuraIcon(button, icons, index, debuff) end
109 Wildbreath-135052
 
110 Wildbreath-135052
        return button
111 Wildbreath-135052
end
112 Wildbreath-135052
 
113 Wildbreath-135052
local customFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
114 Wildbreath-135052
        local isPlayer
115 Wildbreath-135052
 
116 Wildbreath-135052
        if(caster == 'player' or caster == 'vehicle') then
117 Wildbreath-135052
                isPlayer = true
118 Wildbreath-135052
        end
119 Wildbreath-135052
 
120 Wildbreath-135052
        if((icons.onlyShowPlayer and isPlayer) or (not icons.onlyShowPlayer and name)) then
121 Wildbreath-135052
                icon.isPlayer = isPlayer
122 Wildbreath-135052
                icon.owner = caster
123 Wildbreath-135052
                return true
124 Wildbreath-135052
        end
125 Wildbreath-135052
end
126 Wildbreath-135052
 
127 Wildbreath-135052
local updateIcon = function(self, unit, icons, index, offset, filter, isDebuff, max)
128 Wildbreath-135052
        if(index == 0) then index = max end
129 Wildbreath-135052
 
130 Wildbreath-135052
        local name, rank, texture, count, dtype, duration, timeLeft, caster, isStealable, shouldConsolidate, spellID = UnitAura(unit, index, filter)
131 Wildbreath-135052
        if(name) then
132 Wildbreath-135052
                local icon = icons[index + offset]
133 Wildbreath-135052
                if(not icon) then
134 Wildbreath-135052
                        icon = (self.CreateAuraIcon or createAuraIcon) (self, icons, index, isDebuff)
135 Wildbreath-135052
                end
136 Wildbreath-135052
 
137 Wildbreath-135052
                local show = (self.CustomAuraFilter or customFilter) (icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster, isStealable, shouldConsolidate, spellID)
138 Wildbreath-135052
                if(show) then
139 Wildbreath-135052
                        -- We might want to consider delaying the creation of an actual cooldown
140 Wildbreath-135052
                        -- object to this point, but I think that will just make things needlessly
141 Wildbreath-135052
                        -- complicated.
142 Wildbreath-135052
                        local cd = icon.cd
143 Wildbreath-135052
                        if(cd and not icons.disableCooldown) then
144 Wildbreath-135052
                                if(duration and duration > 0) then
145 Wildbreath-135052
                                        cd:SetCooldown(timeLeft - duration, duration)
146 Wildbreath-135052
                                        cd:Show()
147 Wildbreath-135052
                                else
148 Wildbreath-135052
                                        cd:Hide()
149 Wildbreath-135052
                                end
150 Wildbreath-135052
                        end
151 Wildbreath-135052
 
152 Wildbreath-135052
                        if((isDebuff and icons.showDebuffType) or (not isDebuff and icons.showBuffType) or icons.showType) then
153 Wildbreath-135052
                                local color = DebuffTypeColor[dtype] or DebuffTypeColor.none
154 Wildbreath-135052
 
155 Wildbreath-135052
                                icon.overlay:SetVertexColor(color.r, color.g, color.b)
156 Wildbreath-135052
                                icon.overlay:Show()
157 Wildbreath-135052
                        else
158 Wildbreath-135052
                                icon.overlay:Hide()
159 Wildbreath-135052
                        end
160 Wildbreath-135052
 
161 Wildbreath-135052
                        icon.icon:SetTexture(texture)
162 Wildbreath-135052
                        icon.count:SetText((count > 1 and count))
163 Wildbreath-135052
 
164 Wildbreath-135052
                        icon.filter = filter
165 Wildbreath-135052
                        icon.debuff = isDebuff
166 Wildbreath-135052
 
167 Wildbreath-135052
                        icon:SetID(index)
168 Wildbreath-135052
                        icon:Show()
169 Wildbreath-135052
 
170 Wildbreath-135052
                        if(self.PostUpdateAuraIcon) then
171 Wildbreath-135052
                                self:PostUpdateAuraIcon(icons, unit, icon, index, offset, filter, isDebuff)
172 Wildbreath-135052
                        end
173 Wildbreath-135052
                else
174 Wildbreath-135052
                        -- Hide the icon in-case we are in the middle of the stack.
175 Wildbreath-135052
                        icon:Hide()
176 Wildbreath-135052
                end
177 Wildbreath-135052
 
178 Wildbreath-135052
                return true
179 Wildbreath-135052
        end
180 Wildbreath-135052
end
181 Wildbreath-135052
 
182 Wildbreath-135052
local SetAuraPosition = function(self, icons, x)
183 Wildbreath-135052
        if(icons and x > 0) then
184 Wildbreath-135052
                local col = 0
185 Wildbreath-135052
                local row = 0
186 Wildbreath-135052
                local spacing = icons.spacing or 0
187 Wildbreath-135052
                local gap = icons.gap
188 Wildbreath-135052
                local size = (icons.size or 16) + spacing
189 Wildbreath-135052
                local anchor = icons.initialAnchor or "BOTTOMLEFT"
190 Wildbreath-135052
                local growthx = (icons["growth-x"] == "LEFT" and -1) or 1
191 Wildbreath-135052
                local growthy = (icons["growth-y"] == "DOWN" and -1) or 1
192 Wildbreath-135052
                local cols = math.floor(icons:GetWidth() / size + .5)
193 Wildbreath-135052
                local rows = math.floor(icons:GetHeight() / size + .5)
194 Wildbreath-135052
 
195 Wildbreath-135052
                for i = 1, #icons do
196 Wildbreath-135052
                        local button = icons[i]
197 Wildbreath-135052
                        if(button and button:IsShown()) then
198 Wildbreath-135052
                                if(gap and button.debuff) then
199 Wildbreath-135052
                                        if(col > 0) then
200 Wildbreath-135052
                                                col = col + 1
201 Wildbreath-135052
                                        end
202 Wildbreath-135052
 
203 Wildbreath-135052
                                        gap = false
204 Wildbreath-135052
                                end
205 Wildbreath-135052
 
206 Wildbreath-135052
                                if(col >= cols) then
207 Wildbreath-135052
                                        col = 0
208 Wildbreath-135052
                                        row = row + 1
209 Wildbreath-135052
                                end
210 Wildbreath-135052
                                button:ClearAllPoints()
211 Wildbreath-135052
                                button:SetPoint(anchor, icons, anchor, col * size * growthx, row * size * growthy)
212 Wildbreath-135052
 
213 Wildbreath-135052
                                col = col + 1
214 Wildbreath-135052
                        elseif(not button) then
215 Wildbreath-135052
                                break
216 Wildbreath-135052
                        end
217 Wildbreath-135052
                end
218 Wildbreath-135052
        end
219 Wildbreath-135052
end
220 Wildbreath-135052
 
221 Wildbreath-135052
local Update = function(self, event, unit)
222 Wildbreath-135052
        if(self.unit ~= unit) then return end
223 Wildbreath-135052
        if(self.PreUpdateAura) then self:PreUpdateAura(event, unit) end
224 Wildbreath-135052
 
225 Wildbreath-135052
        local auras, buffs, debuffs = self.Auras, self.Buffs, self.Debuffs
226 Wildbreath-135052
 
227 Wildbreath-135052
        if(auras) then
228 Wildbreath-135052
                local buffs = auras.numBuffs or 32
229 Wildbreath-135052
                local debuffs = auras.numDebuffs or 40
230 Wildbreath-135052
                local max = debuffs + buffs
231 Wildbreath-135052
 
232 Wildbreath-135052
                local visibleBuffs, visibleDebuffs = 0, 0
233 Wildbreath-135052
                for index = 1, max do
234 Wildbreath-135052
                        if(index > buffs) then
235 Wildbreath-135052
                                if(updateIcon(self, unit, auras, index % debuffs, visibleBuffs, auras.debuffFilter or auras.filter or 'HARMFUL', true, debuffs)) then
236 Wildbreath-135052
                                        visibleDebuffs = visibleDebuffs + 1
237 Wildbreath-135052
                                end
238 Wildbreath-135052
                        else
239 Wildbreath-135052
                                if(updateIcon(self, unit, auras, index, 0, auras.buffFilter or  auras.filter or 'HELPFUL')) then
240 Wildbreath-135052
                                        visibleBuffs = visibleBuffs + 1
241 Wildbreath-135052
                                end
242 Wildbreath-135052
                        end
243 Wildbreath-135052
                end
244 Wildbreath-135052
 
245 Wildbreath-135052
                local index = visibleBuffs + visibleDebuffs + 1
246 Wildbreath-135052
                while(auras[index]) do
247 Wildbreath-135052
                        auras[index]:Hide()
248 Wildbreath-135052
                        index = index + 1
249 Wildbreath-135052
                end
250 Wildbreath-135052
 
251 Wildbreath-135052
                auras.visibleBuffs = visibleBuffs
252 Wildbreath-135052
                auras.visibleDebuffs = visibleDebuffs
253 Wildbreath-135052
                auras.visibleAuras = visibleBuffs + visibleDebuffs
254 Wildbreath-135052
 
255 Wildbreath-135052
                if(self.PreAuraSetPosition) then self:PreAuraSetPosition(auras, max) end
256 Wildbreath-135052
                self:SetAuraPosition(auras, max)
257 Wildbreath-135052
        end
258 Wildbreath-135052
 
259 Wildbreath-135052
        if(buffs) then
260 Wildbreath-135052
                local filter = buffs.filter or 'HELPFUL'
261 Wildbreath-135052
                local max = buffs.num or 32
262 Wildbreath-135052
                local visibleBuffs = 0
263 Wildbreath-135052
                for index = 1, max do
264 Wildbreath-135052
                        if(not updateIcon(self, unit, buffs, index, 0, filter)) then
265 Wildbreath-135052
                                max = index - 1
266 Wildbreath-135052
 
267 Wildbreath-135052
                                while(buffs[index]) do
268 Wildbreath-135052
                                        buffs[index]:Hide()
269 Wildbreath-135052
                                        index = index + 1
270 Wildbreath-135052
                                end
271 Wildbreath-135052
                                break
272 Wildbreath-135052
                        end
273 Wildbreath-135052
 
274 Wildbreath-135052
                        visibleBuffs = visibleBuffs + 1
275 Wildbreath-135052
                end
276 Wildbreath-135052
 
277 Wildbreath-135052
                buffs.visibleBuffs = visibleBuffs
278 Wildbreath-135052
 
279 Wildbreath-135052
                if(self.PreAuraSetPosition) then self:PreAuraSetPosition(buffs, max) end
280 Wildbreath-135052
                self:SetAuraPosition(buffs, max)
281 Wildbreath-135052
        end
282 Wildbreath-135052
 
283 Wildbreath-135052
        if(debuffs) then
284 Wildbreath-135052
                local filter = debuffs.filter or 'HARMFUL'
285 Wildbreath-135052
                local max = debuffs.num or 40
286 Wildbreath-135052
                local visibleDebuffs = 0
287 Wildbreath-135052
                for index = 1, max do
288 Wildbreath-135052
                        if(not updateIcon(self, unit, debuffs, index, 0, filter, true)) then
289 Wildbreath-135052
                                max = index - 1
290 Wildbreath-135052
 
291 Wildbreath-135052
                                while(debuffs[index]) do
292 Wildbreath-135052
                                        debuffs[index]:Hide()
293 Wildbreath-135052
                                        index = index + 1
294 Wildbreath-135052
                                end
295 Wildbreath-135052
                                break
296 Wildbreath-135052
                        end
297 Wildbreath-135052
 
298 Wildbreath-135052
                        visibleDebuffs = visibleDebuffs + 1
299 Wildbreath-135052
                end
300 Wildbreath-135052
                debuffs.visibleDebuffs = visibleDebuffs
301 Wildbreath-135052
 
302 Wildbreath-135052
                if(self.PreAuraSetPosition) then self:PreAuraSetPosition(debuffs, max) end
303 Wildbreath-135052
                self:SetAuraPosition(debuffs, max)
304 Wildbreath-135052
        end
305 Wildbreath-135052
 
306 Wildbreath-135052
        if(self.PostUpdateAura) then
307 Wildbreath-135052
                return self:PostUpdateAura(event, unit)
308 Wildbreath-135052
        end
309 Wildbreath-135052
end
310 Wildbreath-135052
 
311 Wildbreath-135052
local Enable = function(self)
312 Wildbreath-135052
        if(self.Buffs or self.Debuffs or self.Auras) then
313 Wildbreath-135052
                if(not self.SetAuraPosition) then
314 Wildbreath-135052
                        self.SetAuraPosition = SetAuraPosition
315 Wildbreath-135052
                end
316 Wildbreath-135052
                self:RegisterEvent("UNIT_AURA", Update)
317 Wildbreath-135052
 
318 Wildbreath-135052
                return true
319 Wildbreath-135052
        end
320 Wildbreath-135052
end
321 Wildbreath-135052
 
322 Wildbreath-135052
local Disable = function(self)
323 Wildbreath-135052
        if(self.Buffs or self.Debuffs or self.Auras) then
324 Wildbreath-135052
                self:UnregisterEvent("UNIT_AURA", Update)
325 Wildbreath-135052
        end
326 Wildbreath-135052
end
327 Wildbreath-135052
 
328 Wildbreath-135052
oUF:AddElement('Aura', Update, Enable, Disable)