comparison KBF.lua @ 10:7309cc67cac0

Hooray support for debuffs
author Chris Mellon <arkanes@gmai.com>
date Wed, 13 Oct 2010 09:27:34 -0500
parents ede17cc71b66
children 76650e326a57
comparison
equal deleted inserted replaced
9:ede17cc71b66 10:7309cc67cac0
4 4
5 local kbf = LibStub("AceAddon-3.0"):NewAddon(kbf, "KBF", "AceEvent-3.0", "AceConsole-3.0") 5 local kbf = LibStub("AceAddon-3.0"):NewAddon(kbf, "KBF", "AceEvent-3.0", "AceConsole-3.0")
6 6
7 7
8 function kbf:OnInitialize() 8 function kbf:OnInitialize()
9 self.options = { 9 self.debuffFrames = {}
10 barWidth = 200 + 16 + 8,
11 barHeight = 16 + 8
12 }
13 self.anchor = self:CreateAnchorFrame() 10 self.anchor = self:CreateAnchorFrame()
14 self.buffBars = {}
15 self.anchor:Show() 11 self.anchor:Show()
16 self:RegisterEvent("UNIT_AURA") 12 self:RegisterEvent("UNIT_AURA")
17 -- set up the countdown timer 13 -- set up the countdown timer
18 -- TODO: Fancy enable/disable based on whether you have any timed buffs. 14 -- TODO: Fancy enable/disable based on whether you have any timed buffs.
19 -- Not a big deal, how often do you care about that 15 -- Not a big deal, how often do you care about that
39 HideBlizFrame(TemporaryEnchantFrame) 35 HideBlizFrame(TemporaryEnchantFrame)
40 36
41 end 37 end
42 38
43 function kbf:OnUpdate() 39 function kbf:OnUpdate()
40 local unit = self.secureFrame:GetAttribute("unit")
41 local buffCount = 0
44 for idx=1,99 do 42 for idx=1,99 do
45 local frame = self.secureFrame:GetAttribute("child"..idx) 43 local frame = self.secureFrame:GetAttribute("child"..idx)
46 if not frame then break end 44 if not (frame and frame:IsShown()) then break end
45 buffCount = buffCount + 1
47 if self.dirty then 46 if self.dirty then
48 local unit = self.secureFrame:GetAttribute("unit") 47 if self:BindBarToBuff(frame, unit) then break end
49 self:BindBarToBuff(frame, unit)
50 end 48 end
51 if frame.expirationTime then 49 self:UpdateBarExpirationTime(frame)
52 local remaining = frame.expirationTime - GetTime() 50 end
53 remaining = math.max(0, remaining) 51 -- temporary enchants
54 local perc = remaining / frame.duration 52 -- TODO: The blizz secure aura header binds both temp enchants
55 frame.timertext:SetText(self:FormatTimeText(remaining)) 53 -- to the main hand. No support for cancelling weapon enchants
56 frame.statusbar:SetValue(remaining) 54 -- until this gets fixed up
55
56 -- debuffs
57 for idx=1,99 do
58 local frame = self.debuffFrames[idx]
59 if self.dirty then
60 local name, rank, icon, stacks, debuffType, duration, expirationTime = UnitAura(unit, idx, "HARMFUL")
61 if not name then
62 -- out of debuffs, hide all the rest of them
63 for jdx = idx, 99 do
64 local bar = self.debuffFrames[jdx]
65 if bar then bar:Hide() else break end
66 end
67 break
68 end
69 if not frame then
70 frame = self:ConstructBar(nil, 1, 0, 0)
71 self.debuffFrames[idx] = frame
72 end
73 self:SetBarAppearance(frame, name, icon, stacks, duration, expirationTime)
74 frame:ClearAllPoints()
75 -- position it under all the buffs, with a half-bar spacing
76 frame:SetPoint("TOP", self.anchor, "BOTTOM", 0, (buffCount * -16) - 8)
77 frame:Show()
78 buffCount = buffCount + 1
79 else
80 -- not dirty, so no frame means we're done
81 if not frame then break end
57 end 82 end
83 self:UpdateBarExpirationTime(frame)
58 end 84 end
59 self.dirty = nil 85 self.dirty = nil
60 end 86 end
61 87
62 function kbf:UNIT_AURA(event, unit) 88 function kbf:UNIT_AURA(event, unit)
63 if unit ~= self.secureFrame:GetAttribute("unit") then return end 89 if unit ~= self.secureFrame:GetAttribute("unit") then return end
64 self.dirty = true 90 self.dirty = true
65 end 91 end
66 92
93 function kbf:UpdateBarExpirationTime(frame)
94 if frame.expirationTime then
95 local remaining = frame.expirationTime - GetTime()
96 remaining = math.max(0, remaining)
97 local perc = remaining / frame.duration
98 frame.timertext:SetText(self:FormatTimeText(remaining))
99 frame.statusbar:SetValue(remaining)
100 end
101 end
102
67 function kbf:BindBarToBuff(parentFrame, unit) 103 function kbf:BindBarToBuff(parentFrame, unit)
68 local index = parentFrame:GetAttribute("index") 104 local index = parentFrame:GetAttribute("index")
69 local filter = parentFrame:GetAttribute("filter") 105 local filter = parentFrame:GetAttribute("filter")
70 local name, rank, icon, count, debuffType, duration, expirationTime, 106 local name, rank, icon, stacks, debuffType, duration, expirationTime,
71 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, index, filter) 107 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, index, filter)
108 if not name then return end
72 if not parentFrame.icon then 109 if not parentFrame.icon then
73 self:ConstructBar(parentFrame) 110 self:ConstructBar(parentFrame)
74 end 111 end
112 self:SetBarAppearance(parentFrame, name, icon, stacks, duration, expirationTime)
113 end
114
115 function kbf:SetBarAppearance(parentFrame, name, icon, stacks, duration, expirationTime)
75 parentFrame.icon:SetNormalTexture(icon) 116 parentFrame.icon:SetNormalTexture(icon)
76 if stacks and stacks > 0 then 117 if stacks and stacks > 0 then
77 parentFrame.text:SetText(string.format("%s(%d)", name, stacks)) 118 parentFrame.text:SetText(string.format("%s(%d)", name, stacks))
78 else 119 else
79 parentFrame.text:SetText(name) 120 parentFrame.text:SetText(name)
110 end 151 end
111 return timetext 152 return timetext
112 end 153 end
113 154
114 -- creates a icon + statusbar bar 155 -- creates a icon + statusbar bar
115 function kbf:ConstructBar(frame) 156 function kbf:ConstructBar(frame, r, g, b)
116 local texture = "Interface\\TargetingFrame\\UI-StatusBar" 157 local texture = "Interface\\TargetingFrame\\UI-StatusBar"
117 -- Because of secureframe suckiness, these height & width numbers 158 -- Because of secureframe suckiness, these height & width numbers
118 -- have to be consistent with the stuff in KBF.xml 159 -- have to be consistent with the stuff in KBF.xml
119 local height = 16 160 local height = 16
120 local width = 200 -- this is the width *without* the icon 161 local width = 200 -- this is the width *without* the icon
121 local font, _ style = GameFontHighlight:GetFont() 162 local font, _ style = GameFontHighlight:GetFont()
122 local bgcolor = {1, 0, 0, 0.5} 163 local r = r or 0
123 local color = {0, 1, 0, 1} 164 local g = g or 1
165 local b = b or 0
166 local bgcolor = {r, g, b, 0.5}
167 local color = {r, g, b, 1}
124 local fontsize = 11 168 local fontsize = 11
125 local timertextwidth = fontsize * 3.6 169 local timertextwidth = fontsize * 3.6
126 local textcolor = {1, 1, 1, 1} 170 local textcolor = {1, 1, 1, 1}
127 local timertextcolor = {1, 1, 1, 1} 171 local timertextcolor = {1, 1, 1, 1}
128 --local bar = CreateFrame("Button", nil, UIParent) -- the "top level" frame that represents the bar as a whole 172 if not frame then
173 frame = CreateFrame("Button", nil, UIParent) -- the "top level" frame that represents the bar as a whole
174 frame:SetHeight(16)
175 frame:SetWidth(200 + 16)
176 end
129 local bar = frame 177 local bar = frame
130 bar.icon = CreateFrame("Button", nil, bar) -- the icon 178 bar.icon = CreateFrame("Button", nil, bar) -- the icon
131 bar.statusbarbg = CreateFrame("StatusBar", nil, bar) -- the bars background 179 bar.statusbarbg = CreateFrame("StatusBar", nil, bar) -- the bars background
132 bar.statusbar = CreateFrame("StatusBar", nil, bar) -- and the bars foreground 180 bar.statusbar = CreateFrame("StatusBar", nil, bar) -- and the bars foreground
133 bar.text = bar.statusbar:CreateFontString(nil, "OVERLAY") -- the label text 181 bar.text = bar.statusbar:CreateFontString(nil, "OVERLAY") -- the label text
194 text:SetFontObject(GameFontHighlight) 242 text:SetFontObject(GameFontHighlight)
195 text:SetFont(GameFontHighlight:GetFont()) 243 text:SetFont(GameFontHighlight:GetFont())
196 text:SetPoint("TOPLEFT", anchor, "TOPLEFT", 0, 0) 244 text:SetPoint("TOPLEFT", anchor, "TOPLEFT", 0, 0)
197 text:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 0, 0) 245 text:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 0, 0)
198 text:SetText("KBF ANCHOR") 246 text:SetText("KBF ANCHOR")
199 anchor:SetWidth(self.options.barWidth) 247 anchor:SetWidth(200 + 16 + 8)
200 anchor:SetHeight(self.options.barHeight) 248 anchor:SetHeight(16 + 8)
201 -- movability 249 -- movability
202 anchor:EnableMouse(true) 250 anchor:EnableMouse(true)
203 anchor:SetMovable(true) 251 anchor:SetMovable(true)
204 anchor:RegisterForDrag("LeftButton") 252 anchor:RegisterForDrag("LeftButton")
205 anchor:SetScript("OnDragStart", anchor.StartMoving) 253 anchor:SetScript("OnDragStart", anchor.StartMoving)
213 frame:SetAttribute("filter", "HELPFUL") 261 frame:SetAttribute("filter", "HELPFUL")
214 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate") 262 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate")
215 frame:SetAttribute("point", "TOP") 263 frame:SetAttribute("point", "TOP")
216 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header 264 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header
217 frame:SetAttribute("consolidateTo", nil) 265 frame:SetAttribute("consolidateTo", nil)
218 --frame:SetAttribute("wrapXOffset", 0)
219 --frame:SetAttribute("wrapYOffset", -34)
220 frame:SetAttribute("xOffset", 0) 266 frame:SetAttribute("xOffset", 0)
221 frame:SetAttribute("yOffset", -16) 267 frame:SetAttribute("yOffset", -16)
222 frame:SetAttribute("minWidth", 216) 268 frame:SetAttribute("minWidth", 216)
223 frame:SetAttribute("minHeight", 16) 269 frame:SetAttribute("minHeight", 16)
224 frame:SetAttribute("unit", "player") -- TODO: figure out the vehicle swapping stuff 270 frame:SetAttribute("unit", "player") -- TODO: figure out the vehicle swapping stuff
225 frame:SetAttribute("sortMethod", "NAME") 271 frame:SetAttribute("sortMethod", "NAME")
226 frame:SetAttribute("sortOrder", "-") 272 frame:SetAttribute("sortOrder", "-")
227 frame:SetAttribute("includeWeapons", 1) 273 -- TODO: SecureAuraHeader doesn't correcltly implement the temp enchants
274 --frame:SetAttribute("weaponTemplate", "KBFSecureUnitAuraTemplate")
275 --frame:SetAttribute("includeWeapons", 1)
228 frame:SetPoint("TOP", anchor, "BOTTOM", 0, 0) 276 frame:SetPoint("TOP", anchor, "BOTTOM", 0, 0)
229 -- frame:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
230 -- edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
231 -- tile = true, tileSize = 16, edgeSize = 16,
232 -- insets = { left = 4, right = 4, top = 4, bottom = 4 },
233 -- })
234 frame:Show() -- has to be shown, otherwise the child frames don't show 277 frame:Show() -- has to be shown, otherwise the child frames don't show
235 self.secureFrame = frame 278 self.secureFrame = frame
236 return anchor 279 return anchor
237 end 280 end