arkanes@0
|
1 local _, kbf = ...
|
arkanes@0
|
2
|
arkanes@0
|
3 KBF = kbf -- make global for debugging
|
arkanes@0
|
4
|
arkanes@0
|
5 local kbf = LibStub("AceAddon-3.0"):NewAddon(kbf, "KBF", "AceEvent-3.0", "AceConsole-3.0")
|
arkanes@0
|
6
|
arkanes@0
|
7
|
arkanes@0
|
8 function kbf:OnInitialize()
|
arkanes@10
|
9 self.debuffFrames = {}
|
arkanes@0
|
10 self.anchor = self:CreateAnchorFrame()
|
arkanes@0
|
11 self.anchor:Show()
|
arkanes@0
|
12 self:RegisterEvent("UNIT_AURA")
|
arkanes@4
|
13 -- set up the countdown timer
|
arkanes@4
|
14 -- TODO: Fancy enable/disable based on whether you have any timed buffs.
|
arkanes@4
|
15 -- Not a big deal, how often do you care about that
|
arkanes@8
|
16 -- also TODO: Maybe should bucket OnUpdates somehow
|
arkanes@4
|
17 self.anchor:SetScript("OnUpdate", function() self:OnUpdate() end)
|
arkanes@7
|
18 self.dirty = true -- force an immediate scan on login
|
arkanes@8
|
19 --self:HideBlizzardBuffFrames()
|
arkanes@0
|
20 end
|
arkanes@1
|
21 -- naming convention
|
arkanes@1
|
22 -- "frame" is the secure aura button created by the group handler
|
arkanes@1
|
23 -- "bar" is the set of icon + status bars that we create to show the buff time
|
arkanes@0
|
24
|
arkanes@8
|
25 function kbf:HideBlizzardBuffFrames()
|
arkanes@8
|
26 local function HideBlizFrame(frame)
|
arkanes@8
|
27 if not frame then return end
|
arkanes@8
|
28 frame:UnregisterAllEvents()
|
arkanes@8
|
29 frame:SetScript("OnUpdate", nil)
|
arkanes@8
|
30 frame:Hide()
|
arkanes@8
|
31 frame.Show = function() end
|
arkanes@8
|
32 end
|
arkanes@8
|
33 HideBlizFrame(BuffFrame)
|
arkanes@8
|
34 HideBlizFrame(ConsolidatedBuffs)
|
arkanes@8
|
35 HideBlizFrame(TemporaryEnchantFrame)
|
arkanes@8
|
36
|
arkanes@8
|
37 end
|
arkanes@8
|
38
|
arkanes@4
|
39 function kbf:OnUpdate()
|
arkanes@10
|
40 local unit = self.secureFrame:GetAttribute("unit")
|
arkanes@10
|
41 local buffCount = 0
|
arkanes@4
|
42 for idx=1,99 do
|
arkanes@4
|
43 local frame = self.secureFrame:GetAttribute("child"..idx)
|
arkanes@10
|
44 if not (frame and frame:IsShown()) then break end
|
arkanes@10
|
45 buffCount = buffCount + 1
|
arkanes@6
|
46 if self.dirty then
|
arkanes@10
|
47 if self:BindBarToBuff(frame, unit) then break end
|
arkanes@9
|
48 end
|
arkanes@10
|
49 self:UpdateBarExpirationTime(frame)
|
arkanes@12
|
50 -- Don't forget to refresh shown tooltips
|
arkanes@12
|
51 if ( GameTooltip:IsOwned(frame) ) then
|
arkanes@12
|
52 GameTooltip:SetUnitAura(unit, idx, filter);
|
arkanes@12
|
53 end
|
arkanes@10
|
54 end
|
arkanes@10
|
55 -- temporary enchants
|
arkanes@10
|
56 -- TODO: The blizz secure aura header binds both temp enchants
|
arkanes@10
|
57 -- to the main hand. No support for cancelling weapon enchants
|
arkanes@10
|
58 -- until this gets fixed up
|
arkanes@10
|
59
|
arkanes@10
|
60 -- debuffs
|
arkanes@11
|
61 -- Since debuffs aren't cancellable, don't need to use the secure header
|
arkanes@11
|
62 -- for them. This could be rewritten to support useful features like
|
arkanes@11
|
63 -- sorting & scaling and stuff. Honestly, should at least be alphabetical.
|
arkanes@10
|
64 for idx=1,99 do
|
arkanes@10
|
65 local frame = self.debuffFrames[idx]
|
arkanes@10
|
66 if self.dirty then
|
arkanes@10
|
67 local name, rank, icon, stacks, debuffType, duration, expirationTime = UnitAura(unit, idx, "HARMFUL")
|
arkanes@10
|
68 if not name then
|
arkanes@10
|
69 -- out of debuffs, hide all the rest of them
|
arkanes@10
|
70 for jdx = idx, 99 do
|
arkanes@10
|
71 local bar = self.debuffFrames[jdx]
|
arkanes@10
|
72 if bar then bar:Hide() else break end
|
arkanes@10
|
73 end
|
arkanes@10
|
74 break
|
arkanes@10
|
75 end
|
arkanes@10
|
76 if not frame then
|
arkanes@10
|
77 frame = self:ConstructBar(nil, 1, 0, 0)
|
arkanes@10
|
78 self.debuffFrames[idx] = frame
|
arkanes@10
|
79 end
|
arkanes@10
|
80 self:SetBarAppearance(frame, name, icon, stacks, duration, expirationTime)
|
arkanes@10
|
81 frame:ClearAllPoints()
|
arkanes@10
|
82 -- position it under all the buffs, with a half-bar spacing
|
arkanes@10
|
83 frame:SetPoint("TOP", self.anchor, "BOTTOM", 0, (buffCount * -16) - 8)
|
arkanes@10
|
84 frame:Show()
|
arkanes@13
|
85 frame:SetID(idx)
|
arkanes@13
|
86 frame.filter = "HARMFUL"
|
arkanes@13
|
87 frame.unit = unit
|
arkanes@13
|
88 frame:SetScript("OnEnter", function() kbf:OnEnter(frame) end)
|
arkanes@13
|
89 frame:SetScript("OnLeave", function() GameTooltip:Hide() end)
|
arkanes@10
|
90 buffCount = buffCount + 1
|
arkanes@10
|
91 else
|
arkanes@10
|
92 -- not dirty, so no frame means we're done
|
arkanes@10
|
93 if not frame then break end
|
arkanes@6
|
94 end
|
arkanes@10
|
95 self:UpdateBarExpirationTime(frame)
|
arkanes@13
|
96 if ( GameTooltip:IsOwned(frame) ) then
|
arkanes@13
|
97 GameTooltip:SetUnitAura(unit, idx, "HARMFUL");
|
arkanes@13
|
98 end
|
arkanes@4
|
99 end
|
arkanes@6
|
100 self.dirty = nil
|
arkanes@4
|
101 end
|
arkanes@4
|
102
|
arkanes@0
|
103 function kbf:UNIT_AURA(event, unit)
|
arkanes@2
|
104 if unit ~= self.secureFrame:GetAttribute("unit") then return end
|
arkanes@6
|
105 self.dirty = true
|
arkanes@0
|
106 end
|
arkanes@0
|
107
|
arkanes@10
|
108 function kbf:UpdateBarExpirationTime(frame)
|
arkanes@10
|
109 if frame.expirationTime then
|
arkanes@10
|
110 local remaining = frame.expirationTime - GetTime()
|
arkanes@10
|
111 remaining = math.max(0, remaining)
|
arkanes@10
|
112 local perc = remaining / frame.duration
|
arkanes@10
|
113 frame.timertext:SetText(self:FormatTimeText(remaining))
|
arkanes@10
|
114 frame.statusbar:SetValue(remaining)
|
arkanes@10
|
115 end
|
arkanes@10
|
116 end
|
arkanes@10
|
117
|
arkanes@3
|
118 function kbf:BindBarToBuff(parentFrame, unit)
|
arkanes@3
|
119 local index = parentFrame:GetAttribute("index")
|
arkanes@3
|
120 local filter = parentFrame:GetAttribute("filter")
|
arkanes@10
|
121 local name, rank, icon, stacks, debuffType, duration, expirationTime,
|
arkanes@3
|
122 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, index, filter)
|
arkanes@10
|
123 if not name then return end
|
arkanes@2
|
124 if not parentFrame.icon then
|
arkanes@2
|
125 self:ConstructBar(parentFrame)
|
arkanes@0
|
126 end
|
arkanes@10
|
127 self:SetBarAppearance(parentFrame, name, icon, stacks, duration, expirationTime)
|
arkanes@10
|
128 end
|
arkanes@10
|
129
|
arkanes@10
|
130 function kbf:SetBarAppearance(parentFrame, name, icon, stacks, duration, expirationTime)
|
arkanes@2
|
131 parentFrame.icon:SetNormalTexture(icon)
|
arkanes@0
|
132 if stacks and stacks > 0 then
|
arkanes@2
|
133 parentFrame.text:SetText(string.format("%s(%d)", name, stacks))
|
arkanes@0
|
134 else
|
arkanes@2
|
135 parentFrame.text:SetText(name)
|
arkanes@0
|
136 end
|
arkanes@4
|
137 parentFrame.timertext:SetText(self:FormatTimeText(duration))
|
arkanes@4
|
138 -- store duration information
|
arkanes@6
|
139 if duration and duration > 0 then
|
arkanes@4
|
140 parentFrame.expirationTime = expirationTime
|
arkanes@4
|
141 parentFrame.duration = duration
|
arkanes@4
|
142 parentFrame.statusbar:SetMinMaxValues(0, duration)
|
arkanes@4
|
143 else
|
arkanes@4
|
144 parentFrame.expirationTime = nil
|
arkanes@4
|
145 parentFrame.duration = 0
|
arkanes@4
|
146 parentFrame.statusbar:SetMinMaxValues(0,1)
|
arkanes@4
|
147 parentFrame.statusbar:SetValue(1)
|
arkanes@4
|
148 end
|
arkanes@4
|
149 end
|
arkanes@4
|
150
|
arkanes@4
|
151 function kbf:FormatTimeText(time)
|
arkanes@4
|
152 if not time or time == 0 then return "" end
|
arkanes@4
|
153 local timetext
|
arkanes@4
|
154 local h = floor(time/3600)
|
arkanes@4
|
155 local m = time - (h*3600)
|
arkanes@4
|
156 m = floor(m/60)
|
arkanes@4
|
157 local s = time - ((h*3600) + (m*60))
|
arkanes@4
|
158 if h > 0 then
|
arkanes@4
|
159 timetext = ("%d:%02d"):format(h, m)
|
arkanes@4
|
160 elseif m > 0 then
|
arkanes@4
|
161 timetext = string.format("%d:%02d", m, floor(s))
|
arkanes@4
|
162 elseif s < 10 then
|
arkanes@4
|
163 timetext = string.format("%1.1f", s)
|
arkanes@4
|
164 else
|
arkanes@4
|
165 timetext = string.format("%.0f", floor(s))
|
arkanes@4
|
166 end
|
arkanes@4
|
167 return timetext
|
arkanes@0
|
168 end
|
arkanes@0
|
169
|
arkanes@12
|
170 function KBF:OnEnter(button, motion)
|
arkanes@12
|
171 -- this is for the secure buttons, so use the attributes
|
arkanes@12
|
172 -- I'd like a better place to position this but it's funky for right now, handle it later
|
arkanes@13
|
173 local unit = button.unit or button:GetAttribute("unit")
|
arkanes@13
|
174 local filter = button.filter or button:GetAttribute("filter")
|
arkanes@12
|
175 GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT");
|
arkanes@13
|
176 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
|
arkanes@13
|
177 GameTooltip:SetUnitAura(unit, button:GetID(), filter);
|
arkanes@12
|
178 end
|
arkanes@12
|
179
|
arkanes@1
|
180 -- creates a icon + statusbar bar
|
arkanes@10
|
181 function kbf:ConstructBar(frame, r, g, b)
|
arkanes@0
|
182 local texture = "Interface\\TargetingFrame\\UI-StatusBar"
|
arkanes@1
|
183 -- Because of secureframe suckiness, these height & width numbers
|
arkanes@1
|
184 -- have to be consistent with the stuff in KBF.xml
|
arkanes@0
|
185 local height = 16
|
arkanes@1
|
186 local width = 200 -- this is the width *without* the icon
|
arkanes@0
|
187 local font, _ style = GameFontHighlight:GetFont()
|
arkanes@10
|
188 local r = r or 0
|
arkanes@10
|
189 local g = g or 1
|
arkanes@10
|
190 local b = b or 0
|
arkanes@10
|
191 local bgcolor = {r, g, b, 0.5}
|
arkanes@10
|
192 local color = {r, g, b, 1}
|
arkanes@0
|
193 local fontsize = 11
|
arkanes@0
|
194 local timertextwidth = fontsize * 3.6
|
arkanes@0
|
195 local textcolor = {1, 1, 1, 1}
|
arkanes@0
|
196 local timertextcolor = {1, 1, 1, 1}
|
arkanes@10
|
197 if not frame then
|
arkanes@10
|
198 frame = CreateFrame("Button", nil, UIParent) -- the "top level" frame that represents the bar as a whole
|
arkanes@10
|
199 frame:SetHeight(16)
|
arkanes@10
|
200 frame:SetWidth(200 + 16)
|
arkanes@10
|
201 end
|
arkanes@1
|
202 local bar = frame
|
arkanes@0
|
203 bar.icon = CreateFrame("Button", nil, bar) -- the icon
|
arkanes@0
|
204 bar.statusbarbg = CreateFrame("StatusBar", nil, bar) -- the bars background
|
arkanes@0
|
205 bar.statusbar = CreateFrame("StatusBar", nil, bar) -- and the bars foreground
|
arkanes@0
|
206 bar.text = bar.statusbar:CreateFontString(nil, "OVERLAY") -- the label text
|
arkanes@0
|
207 bar.timertext = bar.statusbar:CreateFontString(nil, "OVERLAY") -- and the timer text
|
arkanes@0
|
208
|
arkanes@0
|
209 -- the icon
|
arkanes@0
|
210 bar.icon:ClearAllPoints()
|
arkanes@0
|
211 bar.icon:SetPoint("LEFT", bar, "LEFT", 0, 0)
|
arkanes@0
|
212 -- icons are square
|
arkanes@0
|
213 bar.icon:SetWidth(height)
|
arkanes@0
|
214 bar.icon:SetHeight(height)
|
arkanes@2
|
215 --bar.icon:EnableMouse(false)
|
arkanes@0
|
216 -- the status bar background & foreground
|
arkanes@0
|
217 local function setupStatusBar(sb, color)
|
arkanes@0
|
218 sb:ClearAllPoints()
|
arkanes@0
|
219 sb:SetHeight(height)
|
arkanes@0
|
220 sb:SetWidth(width)
|
arkanes@0
|
221 -- offset the height of the frame on the x-axis for the icon.
|
arkanes@0
|
222 sb:SetPoint("TOPLEFT", bar, "TOPLEFT", height, 0)
|
arkanes@0
|
223 sb:SetStatusBarTexture(texture)
|
arkanes@0
|
224 sb:GetStatusBarTexture():SetVertTile(false)
|
arkanes@0
|
225 sb:GetStatusBarTexture():SetHorizTile(false)
|
arkanes@0
|
226 sb:SetStatusBarColor(unpack(color))
|
arkanes@0
|
227 sb:SetMinMaxValues(0,1)
|
arkanes@0
|
228 sb:SetValue(1)
|
arkanes@0
|
229 end
|
arkanes@0
|
230 setupStatusBar(bar.statusbarbg, bgcolor)
|
arkanes@0
|
231 setupStatusBar(bar.statusbar, color)
|
arkanes@0
|
232 bar.statusbarbg:SetFrameLevel(bar.statusbarbg:GetFrameLevel()-1) -- make sure the bg frame stays in the back
|
arkanes@0
|
233 -- timer text
|
arkanes@0
|
234 bar.timertext:SetFontObject(GameFontHighlight)
|
arkanes@0
|
235 bar.timertext:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
236 bar.timertext:SetHeight(height)
|
arkanes@0
|
237 bar.timertext:SetWidth(timertextwidth)
|
arkanes@0
|
238 bar.timertext:SetPoint("LEFT", bar.statusbar, "LEFT", 0, 0)
|
arkanes@0
|
239 bar.timertext:SetJustifyH("RIGHT")
|
arkanes@0
|
240 bar.timertext:SetText("time")
|
arkanes@0
|
241 bar.timertext:SetTextColor(timertextcolor[1], timertextcolor[2], timertextcolor[3], timertextcolor[4])
|
arkanes@0
|
242
|
arkanes@0
|
243 -- and the label text
|
arkanes@0
|
244 bar.text:SetFontObject(GameFontHighlight)
|
arkanes@0
|
245 bar.text:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
246 bar.text:SetHeight(height)
|
arkanes@0
|
247 bar.text:SetWidth((width - timertextwidth) *.9)
|
arkanes@0
|
248 bar.text:SetPoint("RIGHT", bar.statusbar, "RIGHT", 0, 0)
|
arkanes@0
|
249 bar.text:SetJustifyH("LEFT")
|
arkanes@0
|
250 bar.text:SetText("text")
|
arkanes@0
|
251 bar.text:SetTextColor(textcolor[1], textcolor[2], textcolor[3], textcolor[4])
|
arkanes@0
|
252
|
arkanes@0
|
253 bar:EnableMouse(true)
|
arkanes@0
|
254 return bar
|
arkanes@0
|
255 end
|
arkanes@0
|
256
|
arkanes@0
|
257 function kbf:CreateAnchorFrame()
|
arkanes@0
|
258 -- give it a name so it'll remember its position
|
arkanes@0
|
259 local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent)
|
arkanes@0
|
260 anchor:SetClampedToScreen(true)
|
arkanes@0
|
261 anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
arkanes@0
|
262 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
|
arkanes@0
|
263 tile = true, tileSize = 16, edgeSize = 16,
|
arkanes@0
|
264 insets = { left = 4, right = 4, top = 4, bottom = 4 },
|
arkanes@0
|
265 })
|
arkanes@0
|
266 local text = anchor:CreateFontString(nil, "OVERLAY") -- the label text
|
arkanes@0
|
267 text:SetFontObject(GameFontHighlight)
|
arkanes@0
|
268 text:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
269 text:SetPoint("TOPLEFT", anchor, "TOPLEFT", 0, 0)
|
arkanes@0
|
270 text:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 0, 0)
|
arkanes@0
|
271 text:SetText("KBF ANCHOR")
|
arkanes@10
|
272 anchor:SetWidth(200 + 16 + 8)
|
arkanes@10
|
273 anchor:SetHeight(16 + 8)
|
arkanes@0
|
274 -- movability
|
arkanes@0
|
275 anchor:EnableMouse(true)
|
arkanes@0
|
276 anchor:SetMovable(true)
|
arkanes@0
|
277 anchor:RegisterForDrag("LeftButton")
|
arkanes@0
|
278 anchor:SetScript("OnDragStart", anchor.StartMoving)
|
arkanes@0
|
279 anchor:SetScript("OnDragStop", anchor.StopMovingOrSizing)
|
arkanes@0
|
280 anchor:ClearAllPoints()
|
arkanes@0
|
281 anchor:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
|
arkanes@0
|
282 anchor:Hide()
|
arkanes@0
|
283
|
arkanes@0
|
284 local frame = CreateFrame("FRAME", "KBFBuffFrame", anchor, "SecureAuraHeaderTemplate")
|
arkanes@0
|
285 --local frame = anchor
|
arkanes@0
|
286 frame:SetAttribute("filter", "HELPFUL")
|
arkanes@0
|
287 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate")
|
arkanes@3
|
288 frame:SetAttribute("point", "TOP")
|
arkanes@0
|
289 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header
|
arkanes@0
|
290 frame:SetAttribute("consolidateTo", nil)
|
arkanes@2
|
291 frame:SetAttribute("xOffset", 0)
|
arkanes@3
|
292 frame:SetAttribute("yOffset", -16)
|
arkanes@3
|
293 frame:SetAttribute("minWidth", 216)
|
arkanes@3
|
294 frame:SetAttribute("minHeight", 16)
|
arkanes@2
|
295 frame:SetAttribute("unit", "player") -- TODO: figure out the vehicle swapping stuff
|
arkanes@3
|
296 frame:SetAttribute("sortMethod", "NAME")
|
arkanes@3
|
297 frame:SetAttribute("sortOrder", "-")
|
arkanes@10
|
298 -- TODO: SecureAuraHeader doesn't correcltly implement the temp enchants
|
arkanes@10
|
299 --frame:SetAttribute("weaponTemplate", "KBFSecureUnitAuraTemplate")
|
arkanes@10
|
300 --frame:SetAttribute("includeWeapons", 1)
|
arkanes@3
|
301 frame:SetPoint("TOP", anchor, "BOTTOM", 0, 0)
|
arkanes@5
|
302 frame:Show() -- has to be shown, otherwise the child frames don't show
|
arkanes@0
|
303 self.secureFrame = frame
|
arkanes@0
|
304 return anchor
|
arkanes@0
|
305 end
|