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@40
|
10 local defaultSettings = {
|
arkanes@40
|
11 -- global bar settings
|
arkanes@40
|
12 -- overrides for buffs
|
arkanes@40
|
13 -- overrides for debuffs
|
arkanes@40
|
14 }
|
arkanes@0
|
15 self:RegisterEvent("UNIT_AURA")
|
arkanes@27
|
16 self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange")
|
arkanes@27
|
17 self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange")
|
arkanes@38
|
18 self:RegisterChatCommand("kbf", "ToggleAnchor")
|
arkanes@38
|
19 end
|
arkanes@38
|
20
|
arkanes@38
|
21 function kbf:OnEnable()
|
arkanes@38
|
22 self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy = self:CreateCoreFrames()
|
arkanes@38
|
23 -- set up the countdown timer
|
arkanes@4
|
24 -- TODO: Fancy enable/disable based on whether you have any timed buffs.
|
arkanes@4
|
25 -- Not a big deal, how often do you care about that
|
arkanes@8
|
26 -- also TODO: Maybe should bucket OnUpdates somehow
|
arkanes@18
|
27 -- AceTimer repeating events can only happen at 0.1 seconds, which is probably
|
arkanes@18
|
28 -- fast enough for updating, but makes the animation look jerky
|
arkanes@27
|
29 -- need to experiment with using animation groups
|
arkanes@18
|
30 self.update = CreateFrame("FRAME")
|
arkanes@18
|
31 self.update:SetScript("OnUpdate", function() self:OnUpdate() end)
|
arkanes@7
|
32 self.dirty = true -- force an immediate scan on login
|
arkanes@14
|
33 self:HideBlizzardBuffFrames()
|
arkanes@0
|
34 end
|
arkanes@1
|
35 -- naming convention
|
arkanes@17
|
36 -- a "frame" is the top-level button (secure button from the header, or one I make myself)
|
arkanes@17
|
37 -- that will contain the UI information about the buff
|
arkanes@17
|
38 -- a "bar" is a frame that has the icon, status bar, ect associated with it
|
arkanes@0
|
39
|
arkanes@20
|
40 -- Secure aura header doesn't self-bind to vehicle,
|
arkanes@27
|
41 -- so this only works out of combat. But thats better than nothing...
|
arkanes@27
|
42 function kbf:PollForVehicleChange(event, unit)
|
arkanes@20
|
43 if unit ~= "player" then return end
|
arkanes@20
|
44 self.dirty = true
|
arkanes@20
|
45 -- hax until SAH supports vehicles - do the swap after we come out of combat
|
arkanes@27
|
46 -- always poll instead of insta-swapping OOC in order to simplify the UnitHasVehicleUI logic
|
arkanes@27
|
47 self.pollForUnitChange = true
|
arkanes@20
|
48 end
|
arkanes@20
|
49
|
arkanes@8
|
50 function kbf:HideBlizzardBuffFrames()
|
arkanes@8
|
51 local function HideBlizFrame(frame)
|
arkanes@8
|
52 if not frame then return end
|
arkanes@8
|
53 frame:UnregisterAllEvents()
|
arkanes@8
|
54 frame:SetScript("OnUpdate", nil)
|
arkanes@8
|
55 frame:Hide()
|
arkanes@8
|
56 frame.Show = function() end
|
arkanes@8
|
57 end
|
arkanes@8
|
58 HideBlizFrame(BuffFrame)
|
arkanes@8
|
59 HideBlizFrame(ConsolidatedBuffs)
|
arkanes@18
|
60 HideBlizFrame(TemporaryEnchantFrame)
|
arkanes@8
|
61
|
arkanes@8
|
62 end
|
arkanes@8
|
63
|
arkanes@4
|
64 function kbf:OnUpdate()
|
arkanes@20
|
65 if self.pollForUnitChange and not InCombatLockdown() then
|
arkanes@20
|
66 if UnitHasVehicleUI("player") then
|
arkanes@27
|
67 -- only swap if we're in a "real" vehicle with its own actions
|
arkanes@27
|
68 -- There is possibly a timing issue here where
|
arkanes@27
|
69 -- we have set the poll flag but the unit is not
|
arkanes@27
|
70 -- actually "in" the vehicle yet. I'm hoping thats
|
arkanes@27
|
71 -- handled by using exited/entered events instead of exiting/entering
|
arkanes@38
|
72 self.secureHeader:SetAttribute("unit", "vehicle")
|
arkanes@20
|
73 else
|
arkanes@38
|
74 self.secureHeader:SetAttribute("unit", "player")
|
arkanes@20
|
75 end
|
arkanes@20
|
76 self.pollForUnitChange = nil
|
arkanes@20
|
77 end
|
arkanes@38
|
78 local unit = self.secureHeader:GetAttribute("unit")
|
arkanes@10
|
79 local buffCount = 0
|
arkanes@4
|
80 for idx=1,99 do
|
arkanes@38
|
81 local frame = self.secureHeader:GetAttribute("child"..idx)
|
arkanes@10
|
82 if not (frame and frame:IsShown()) then break end
|
arkanes@10
|
83 buffCount = buffCount + 1
|
arkanes@6
|
84 if self.dirty then
|
arkanes@10
|
85 if self:BindBarToBuff(frame, unit) then break end
|
arkanes@9
|
86 end
|
arkanes@10
|
87 self:UpdateBarExpirationTime(frame)
|
arkanes@12
|
88 -- Don't forget to refresh shown tooltips
|
arkanes@12
|
89 if ( GameTooltip:IsOwned(frame) ) then
|
arkanes@15
|
90 self:OnEnter(frame)
|
arkanes@12
|
91 end
|
arkanes@10
|
92 end
|
arkanes@37
|
93
|
arkanes@37
|
94 -- consolidated buffs
|
arkanes@37
|
95 if self.consolidateProxy:IsShown() then
|
arkanes@37
|
96 for idx=1,99 do
|
arkanes@37
|
97 local frame = self.consolidateHeader:GetAttribute("child"..idx)
|
arkanes@37
|
98 if not (frame and frame:IsShown()) then break end
|
arkanes@37
|
99 if self.dirty then
|
arkanes@37
|
100 if self:BindBarToBuff(frame, unit) then break end
|
arkanes@37
|
101 end
|
arkanes@37
|
102 self:UpdateBarExpirationTime(frame)
|
arkanes@37
|
103 -- Don't forget to refresh shown tooltips
|
arkanes@37
|
104 if ( GameTooltip:IsOwned(frame) ) then
|
arkanes@37
|
105 self:OnEnter(frame)
|
arkanes@37
|
106 end
|
arkanes@37
|
107 end
|
arkanes@41
|
108 buffCount = buffCount+1
|
arkanes@37
|
109 end
|
arkanes@37
|
110
|
arkanes@10
|
111 -- temporary enchants
|
arkanes@42
|
112 -- TODO: So much copy/paste here. I really need to clean this up.
|
arkanes@38
|
113 local tempEnchant = self.secureHeader:GetAttribute("tempEnchant1")
|
arkanes@17
|
114 if tempEnchant and tempEnchant:IsShown() then
|
arkanes@41
|
115 self:BindBarToWeaponEnchant(tempEnchant, 16)
|
arkanes@17
|
116 self:UpdateBarExpirationTime(tempEnchant)
|
arkanes@19
|
117 buffCount = buffCount + 1
|
arkanes@17
|
118 end
|
arkanes@42
|
119 if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
|
arkanes@42
|
120 self:OnEnter(tempEnchant)
|
arkanes@42
|
121 end
|
arkanes@38
|
122 tempEnchant = self.secureHeader:GetAttribute("tempEnchant2")
|
arkanes@17
|
123 if tempEnchant and tempEnchant:IsShown() then
|
arkanes@41
|
124 self:BindBarToWeaponEnchant(tempEnchant, 17)
|
arkanes@17
|
125 self:UpdateBarExpirationTime(tempEnchant)
|
arkanes@19
|
126 buffCount = buffCount + 1
|
arkanes@28
|
127 -- SAH binds the offhand enchant to the main hand for removal purposes.
|
arkanes@28
|
128 -- fix it up if we're out of combat
|
arkanes@28
|
129 -- TODO: maybe this should only happen if we're dirty
|
arkanes@28
|
130 if not InCombatLockdown() then
|
arkanes@28
|
131 tempEnchant:SetAttribute('target-slot', 17)
|
arkanes@28
|
132 end
|
arkanes@17
|
133 end
|
arkanes@42
|
134 if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
|
arkanes@42
|
135 self:OnEnter(tempEnchant)
|
arkanes@42
|
136 end
|
arkanes@41
|
137 -- make a fake third buff bar. It can't be used to cancel the buff, but
|
arkanes@41
|
138 -- at least you can see it.
|
arkanes@41
|
139 local thirdWeaponInfo = select(7, GetWeaponEnchantInfo())
|
arkanes@41
|
140 if thirdWeaponInfo then
|
arkanes@41
|
141 if not self.tempEnchant3 then
|
arkanes@41
|
142 -- largely copy/pasted code from SAH to bind to third weapon
|
arkanes@41
|
143 self.tempEnchant3 = CreateFrame("Button", nil, self.secureHeader);
|
arkanes@41
|
144 self.tempEnchant3:SetWidth(200+16)
|
arkanes@41
|
145 self.tempEnchant3:SetHeight(16)
|
arkanes@41
|
146 self.tempEnchant3:Show()
|
arkanes@44
|
147 self.tempEnchant3:SetScript("OnEnter", function() kbf:OnEnter(self.tempEnchant3) end)
|
arkanes@44
|
148 self.tempEnchant3:SetScript("OnLeave", function() GameTooltip:Hide() end)
|
arkanes@44
|
149 self.tempEnchant3:EnableMouse(true)
|
arkanes@44
|
150 --TODO: queue up for setting when leaving combat
|
arkanes@44
|
151 self.tempEnchant3:SetAttribute('target-slot', 18)
|
arkanes@44
|
152 -- set up the tooltip
|
arkanes@41
|
153 end
|
arkanes@44
|
154 -- TODO: If we're out of combat and theres an OH enchant,
|
arkanes@44
|
155 -- create a secure action button & position it relative
|
arkanes@44
|
156 -- to that. What happens when the OH weapon enchant frame
|
arkanes@44
|
157 -- is hidden by SAH?
|
arkanes@44
|
158 -- most likely: it stays visible but stops moving.
|
arkanes@44
|
159 -- in this case, maybe parent it to the OH enchant also
|
arkanes@44
|
160 -- so it vanishes and gets out of the way.
|
arkanes@44
|
161
|
arkanes@41
|
162 self.tempEnchant3:Show()
|
arkanes@41
|
163 end
|
arkanes@41
|
164 if self.tempEnchant3 and not thirdWeaponInfo then
|
arkanes@41
|
165 self.tempEnchant3:Hide()
|
arkanes@41
|
166 end
|
arkanes@41
|
167 tempEnchant = self.tempEnchant3
|
arkanes@41
|
168 if tempEnchant and tempEnchant:IsShown() then
|
arkanes@41
|
169 self.tempEnchant3:ClearAllPoints()
|
arkanes@41
|
170 self.tempEnchant3:SetPoint("TOP", self.secureHeader, "TOP", 0, (buffCount * -16))
|
arkanes@41
|
171 self:BindBarToWeaponEnchant(tempEnchant, 18)
|
arkanes@41
|
172 self:UpdateBarExpirationTime(tempEnchant)
|
arkanes@41
|
173 buffCount = buffCount + 1
|
arkanes@41
|
174 end
|
arkanes@42
|
175 if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
|
arkanes@42
|
176 self:OnEnter(tempEnchant)
|
arkanes@42
|
177 end
|
arkanes@10
|
178 -- debuffs
|
arkanes@11
|
179 -- Since debuffs aren't cancellable, don't need to use the secure header
|
arkanes@11
|
180 -- for them. This could be rewritten to support useful features like
|
arkanes@11
|
181 -- sorting & scaling and stuff. Honestly, should at least be alphabetical.
|
arkanes@10
|
182 for idx=1,99 do
|
arkanes@10
|
183 local frame = self.debuffFrames[idx]
|
arkanes@10
|
184 if self.dirty then
|
arkanes@10
|
185 local name, rank, icon, stacks, debuffType, duration, expirationTime = UnitAura(unit, idx, "HARMFUL")
|
arkanes@10
|
186 if not name then
|
arkanes@10
|
187 -- out of debuffs, hide all the rest of them
|
arkanes@10
|
188 for jdx = idx, 99 do
|
arkanes@10
|
189 local bar = self.debuffFrames[jdx]
|
arkanes@10
|
190 if bar then bar:Hide() else break end
|
arkanes@10
|
191 end
|
arkanes@10
|
192 break
|
arkanes@10
|
193 end
|
arkanes@10
|
194 if not frame then
|
arkanes@10
|
195 frame = self:ConstructBar(nil, 1, 0, 0)
|
arkanes@10
|
196 self.debuffFrames[idx] = frame
|
arkanes@10
|
197 end
|
arkanes@10
|
198 self:SetBarAppearance(frame, name, icon, stacks, duration, expirationTime)
|
arkanes@10
|
199 frame:ClearAllPoints()
|
arkanes@10
|
200 -- position it under all the buffs, with a half-bar spacing
|
arkanes@41
|
201 frame:SetPoint("TOP", self.secureHeader, "TOP", 0, (buffCount * -16) - 8)
|
arkanes@10
|
202 frame:Show()
|
arkanes@13
|
203 frame.filter = "HARMFUL"
|
arkanes@13
|
204 frame.unit = unit
|
arkanes@16
|
205 frame.index = idx
|
arkanes@13
|
206 frame:SetScript("OnEnter", function() kbf:OnEnter(frame) end)
|
arkanes@13
|
207 frame:SetScript("OnLeave", function() GameTooltip:Hide() end)
|
arkanes@23
|
208 frame:EnableMouse(true)
|
arkanes@10
|
209 buffCount = buffCount + 1
|
arkanes@10
|
210 else
|
arkanes@10
|
211 -- not dirty, so no frame means we're done
|
arkanes@10
|
212 if not frame then break end
|
arkanes@6
|
213 end
|
arkanes@10
|
214 self:UpdateBarExpirationTime(frame)
|
arkanes@13
|
215 if ( GameTooltip:IsOwned(frame) ) then
|
arkanes@15
|
216 self:OnEnter(frame)
|
arkanes@13
|
217 end
|
arkanes@4
|
218 end
|
arkanes@6
|
219 self.dirty = nil
|
arkanes@4
|
220 end
|
arkanes@4
|
221
|
arkanes@0
|
222 function kbf:UNIT_AURA(event, unit)
|
arkanes@38
|
223 if unit ~= self.secureHeader:GetAttribute("unit") then return end
|
arkanes@6
|
224 self.dirty = true
|
arkanes@0
|
225 end
|
arkanes@0
|
226
|
arkanes@10
|
227 function kbf:UpdateBarExpirationTime(frame)
|
arkanes@10
|
228 if frame.expirationTime then
|
arkanes@10
|
229 local remaining = frame.expirationTime - GetTime()
|
arkanes@10
|
230 remaining = math.max(0, remaining)
|
arkanes@10
|
231 local perc = remaining / frame.duration
|
arkanes@10
|
232 frame.timertext:SetText(self:FormatTimeText(remaining))
|
arkanes@10
|
233 frame.statusbar:SetValue(remaining)
|
arkanes@10
|
234 end
|
arkanes@10
|
235 end
|
arkanes@10
|
236
|
arkanes@42
|
237 local gratt = LibStub:GetLibrary("LibGratuity-3.0")
|
arkanes@42
|
238
|
arkanes@17
|
239 function kbf:BindBarToWeaponEnchant(parentFrame, slotOverride)
|
arkanes@17
|
240 -- allow passing of explicit slot in order to work around aura header bug
|
arkanes@17
|
241 local slot = slotOverride or parentFrame:GetAttribute("target-slot")
|
arkanes@17
|
242 local itemIndex = slot - 15 -- 1MH, 2OF
|
arkanes@17
|
243 local RETURNS_PER_ITEM = 3
|
arkanes@17
|
244 local hasEnchant, remaining, enchantCharges = select(RETURNS_PER_ITEM * (itemIndex - 1) + 1, GetWeaponEnchantInfo())
|
arkanes@17
|
245 -- remaining time is in milliseconds
|
arkanes@26
|
246 if not hasEnchant then return end -- this should never happen
|
arkanes@17
|
247 local remaining = remaining / 1000
|
arkanes@42
|
248
|
arkanes@17
|
249 local icon = GetInventoryItemTexture("player", slot)
|
arkanes@42
|
250 local maxDuration
|
arkanes@42
|
251 if select(2, UnitClass("player")) == "ROGUE" then
|
arkanes@42
|
252 -- Rogues are probably using poisons, which are an hour
|
arkanes@42
|
253 maxDuration = 60 * 60
|
arkanes@42
|
254 else
|
arkanes@42
|
255 -- everyone else is probably using something thats a half hour
|
arkanes@42
|
256 maxDuration = 30 * 60
|
arkanes@42
|
257 end
|
arkanes@42
|
258 local duration = max(maxDuration, remaining)
|
arkanes@17
|
259 local expirationTime = GetTime() + remaining
|
arkanes@17
|
260 local name = GetItemInfo(GetInventoryItemID("player", slot))
|
arkanes@42
|
261 -- try to figure out what the weapon enchant is
|
arkanes@42
|
262 -- tooltip string -> {spellid, duration}
|
arkanes@42
|
263 local knownEnchants = {
|
arkanes@42
|
264 ["Flametongue"] = {8024, 30*60},
|
arkanes@42
|
265 ["Frostbrand"] = {8033, 30*60},
|
arkanes@44
|
266 ["Instant Poison"] = {8680, 60*60},
|
arkanes@44
|
267 ["Wound Poison"] = {13218, 60*60},
|
arkanes@44
|
268 ["Deadly Poison"] = {2823, 60*60},
|
arkanes@42
|
269
|
arkanes@42
|
270 }
|
arkanes@42
|
271 local spellId = nil
|
arkanes@42
|
272 if gratt then
|
arkanes@42
|
273 gratt:SetInventoryItem("player", slot)
|
arkanes@42
|
274 for tag, info in pairs(knownEnchants) do
|
arkanes@42
|
275 if gratt:Find(tag) then
|
arkanes@42
|
276 spellId, duration = unpack(info)
|
arkanes@42
|
277 -- TODO: Maybe want to leave it as the weapon icon?
|
arkanes@42
|
278 -- I don't think theres enough room to add both the name of the weapon & the buff in there
|
arkanes@42
|
279 -- maybe use the tag?
|
arkanes@42
|
280 -- Or maybe use the slot name, ie Flametongue / Main Hand
|
arkanes@42
|
281 name, _, _ = GetSpellInfo(spellId)
|
arkanes@42
|
282 break
|
arkanes@42
|
283 end
|
arkanes@42
|
284 end
|
arkanes@42
|
285 end
|
arkanes@42
|
286 parentFrame.spellId = spellId
|
arkanes@17
|
287 if not parentFrame.icon then
|
arkanes@17
|
288 self:ConstructBar(parentFrame, 1, 0, 1)
|
arkanes@17
|
289 end
|
arkanes@17
|
290 self:SetBarAppearance(parentFrame, name, icon, enchantCharges, duration, expirationTime)
|
arkanes@17
|
291 end
|
arkanes@17
|
292
|
arkanes@3
|
293 function kbf:BindBarToBuff(parentFrame, unit)
|
arkanes@3
|
294 local index = parentFrame:GetAttribute("index")
|
arkanes@3
|
295 local filter = parentFrame:GetAttribute("filter")
|
arkanes@10
|
296 local name, rank, icon, stacks, debuffType, duration, expirationTime,
|
arkanes@3
|
297 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, index, filter)
|
arkanes@10
|
298 if not name then return end
|
arkanes@2
|
299 if not parentFrame.icon then
|
arkanes@2
|
300 self:ConstructBar(parentFrame)
|
arkanes@0
|
301 end
|
arkanes@10
|
302 self:SetBarAppearance(parentFrame, name, icon, stacks, duration, expirationTime)
|
arkanes@10
|
303 end
|
arkanes@10
|
304
|
arkanes@10
|
305 function kbf:SetBarAppearance(parentFrame, name, icon, stacks, duration, expirationTime)
|
arkanes@2
|
306 parentFrame.icon:SetNormalTexture(icon)
|
arkanes@0
|
307 if stacks and stacks > 0 then
|
arkanes@2
|
308 parentFrame.text:SetText(string.format("%s(%d)", name, stacks))
|
arkanes@0
|
309 else
|
arkanes@2
|
310 parentFrame.text:SetText(name)
|
arkanes@0
|
311 end
|
arkanes@4
|
312 parentFrame.timertext:SetText(self:FormatTimeText(duration))
|
arkanes@4
|
313 -- store duration information
|
arkanes@6
|
314 if duration and duration > 0 then
|
arkanes@4
|
315 parentFrame.expirationTime = expirationTime
|
arkanes@4
|
316 parentFrame.duration = duration
|
arkanes@4
|
317 parentFrame.statusbar:SetMinMaxValues(0, duration)
|
arkanes@4
|
318 else
|
arkanes@4
|
319 parentFrame.expirationTime = nil
|
arkanes@4
|
320 parentFrame.duration = 0
|
arkanes@4
|
321 parentFrame.statusbar:SetMinMaxValues(0,1)
|
arkanes@4
|
322 parentFrame.statusbar:SetValue(1)
|
arkanes@4
|
323 end
|
arkanes@4
|
324 end
|
arkanes@4
|
325
|
arkanes@17
|
326 -- expects time seconds
|
arkanes@4
|
327 function kbf:FormatTimeText(time)
|
arkanes@4
|
328 if not time or time == 0 then return "" end
|
arkanes@4
|
329 local timetext
|
arkanes@4
|
330 local h = floor(time/3600)
|
arkanes@4
|
331 local m = time - (h*3600)
|
arkanes@4
|
332 m = floor(m/60)
|
arkanes@4
|
333 local s = time - ((h*3600) + (m*60))
|
arkanes@4
|
334 if h > 0 then
|
arkanes@4
|
335 timetext = ("%d:%02d"):format(h, m)
|
arkanes@4
|
336 elseif m > 0 then
|
arkanes@4
|
337 timetext = string.format("%d:%02d", m, floor(s))
|
arkanes@4
|
338 elseif s < 10 then
|
arkanes@4
|
339 timetext = string.format("%1.1f", s)
|
arkanes@4
|
340 else
|
arkanes@4
|
341 timetext = string.format("%.0f", floor(s))
|
arkanes@4
|
342 end
|
arkanes@4
|
343 return timetext
|
arkanes@0
|
344 end
|
arkanes@0
|
345
|
arkanes@12
|
346 function KBF:OnEnter(button, motion)
|
arkanes@12
|
347 -- this is for the secure buttons, so use the attributes
|
arkanes@26
|
348 local unit = SecureButton_GetModifiedUnit(button) or button.unit -- will perform vehicle toggle
|
arkanes@21
|
349 local filter = button:GetAttribute("filter") or button.filter
|
arkanes@15
|
350 local index = button:GetAttribute("index") or button.index
|
arkanes@17
|
351 if unit and filter and index then
|
arkanes@21
|
352 -- I'd like a better place to position this but it's funky for right now, handle it later
|
arkanes@17
|
353 GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT");
|
arkanes@17
|
354 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
|
arkanes@17
|
355 GameTooltip:SetUnitAura(unit, index, filter);
|
arkanes@17
|
356 return
|
arkanes@17
|
357 end
|
arkanes@17
|
358 local slot = button:GetAttribute("target-slot") -- temp enchant
|
arkanes@42
|
359 if slot then
|
arkanes@42
|
360 GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT");
|
arkanes@42
|
361 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
|
arkanes@42
|
362 if button.spellId then
|
arkanes@42
|
363 -- TODO: This might be too big of a tooltip to care about that much.
|
arkanes@42
|
364 -- Maybe I should just have a single line with the weapon name
|
arkanes@42
|
365 --GameTooltip:SetInventoryItem(unit, slot)
|
arkanes@42
|
366 local name = GetItemInfo(GetInventoryItemID("player", slot))
|
arkanes@42
|
367 local r, g, b = GetItemQualityColor(GetInventoryItemQuality("player", slot))
|
arkanes@42
|
368 GameTooltip:SetText(name, r, g, b)
|
arkanes@42
|
369 GameTooltip:AddLine(" ")
|
arkanes@42
|
370 GameTooltip:AddSpellByID(button.spellId)
|
arkanes@42
|
371 else
|
arkanes@42
|
372 GameTooltip:SetInventoryItem(unit, slot)
|
arkanes@42
|
373 end
|
arkanes@42
|
374 end
|
arkanes@12
|
375 end
|
arkanes@12
|
376
|
arkanes@1
|
377 -- creates a icon + statusbar bar
|
arkanes@10
|
378 function kbf:ConstructBar(frame, r, g, b)
|
arkanes@0
|
379 local texture = "Interface\\TargetingFrame\\UI-StatusBar"
|
arkanes@1
|
380 -- Because of secureframe suckiness, these height & width numbers
|
arkanes@1
|
381 -- have to be consistent with the stuff in KBF.xml
|
arkanes@0
|
382 local height = 16
|
arkanes@1
|
383 local width = 200 -- this is the width *without* the icon
|
arkanes@22
|
384 local font, _, style = GameFontHighlight:GetFont()
|
arkanes@10
|
385 local r = r or 0
|
arkanes@10
|
386 local g = g or 1
|
arkanes@10
|
387 local b = b or 0
|
arkanes@10
|
388 local bgcolor = {r, g, b, 0.5}
|
arkanes@10
|
389 local color = {r, g, b, 1}
|
arkanes@0
|
390 local fontsize = 11
|
arkanes@0
|
391 local timertextwidth = fontsize * 3.6
|
arkanes@0
|
392 local textcolor = {1, 1, 1, 1}
|
arkanes@0
|
393 local timertextcolor = {1, 1, 1, 1}
|
arkanes@10
|
394 if not frame then
|
arkanes@10
|
395 frame = CreateFrame("Button", nil, UIParent) -- the "top level" frame that represents the bar as a whole
|
arkanes@10
|
396 frame:SetHeight(16)
|
arkanes@23
|
397 frame:SetWidth(200 + 16)
|
arkanes@10
|
398 end
|
arkanes@1
|
399 local bar = frame
|
arkanes@0
|
400 bar.icon = CreateFrame("Button", nil, bar) -- the icon
|
arkanes@0
|
401 bar.statusbarbg = CreateFrame("StatusBar", nil, bar) -- the bars background
|
arkanes@0
|
402 bar.statusbar = CreateFrame("StatusBar", nil, bar) -- and the bars foreground
|
arkanes@0
|
403 bar.text = bar.statusbar:CreateFontString(nil, "OVERLAY") -- the label text
|
arkanes@0
|
404 bar.timertext = bar.statusbar:CreateFontString(nil, "OVERLAY") -- and the timer text
|
arkanes@0
|
405
|
arkanes@0
|
406 -- the icon
|
arkanes@0
|
407 bar.icon:ClearAllPoints()
|
arkanes@0
|
408 bar.icon:SetPoint("LEFT", bar, "LEFT", 0, 0)
|
arkanes@0
|
409 -- icons are square
|
arkanes@0
|
410 bar.icon:SetWidth(height)
|
arkanes@0
|
411 bar.icon:SetHeight(height)
|
arkanes@2
|
412 --bar.icon:EnableMouse(false)
|
arkanes@0
|
413 -- the status bar background & foreground
|
arkanes@0
|
414 local function setupStatusBar(sb, color)
|
arkanes@0
|
415 sb:ClearAllPoints()
|
arkanes@0
|
416 sb:SetHeight(height)
|
arkanes@0
|
417 sb:SetWidth(width)
|
arkanes@0
|
418 -- offset the height of the frame on the x-axis for the icon.
|
arkanes@0
|
419 sb:SetPoint("TOPLEFT", bar, "TOPLEFT", height, 0)
|
arkanes@0
|
420 sb:SetStatusBarTexture(texture)
|
arkanes@0
|
421 sb:GetStatusBarTexture():SetVertTile(false)
|
arkanes@0
|
422 sb:GetStatusBarTexture():SetHorizTile(false)
|
arkanes@0
|
423 sb:SetStatusBarColor(unpack(color))
|
arkanes@0
|
424 sb:SetMinMaxValues(0,1)
|
arkanes@0
|
425 sb:SetValue(1)
|
arkanes@0
|
426 end
|
arkanes@0
|
427 setupStatusBar(bar.statusbarbg, bgcolor)
|
arkanes@0
|
428 setupStatusBar(bar.statusbar, color)
|
arkanes@0
|
429 bar.statusbarbg:SetFrameLevel(bar.statusbarbg:GetFrameLevel()-1) -- make sure the bg frame stays in the back
|
arkanes@0
|
430 -- timer text
|
arkanes@0
|
431 bar.timertext:SetFontObject(GameFontHighlight)
|
arkanes@0
|
432 bar.timertext:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
433 bar.timertext:SetHeight(height)
|
arkanes@0
|
434 bar.timertext:SetWidth(timertextwidth)
|
arkanes@24
|
435 bar.timertext:SetPoint("LEFT", bar.statusbar, "LEFT", 2, 0)
|
arkanes@24
|
436 bar.timertext:SetJustifyH("LEFT")
|
arkanes@0
|
437 bar.timertext:SetText("time")
|
arkanes@0
|
438 bar.timertext:SetTextColor(timertextcolor[1], timertextcolor[2], timertextcolor[3], timertextcolor[4])
|
arkanes@0
|
439
|
arkanes@0
|
440 -- and the label text
|
arkanes@0
|
441 bar.text:SetFontObject(GameFontHighlight)
|
arkanes@0
|
442 bar.text:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
443 bar.text:SetHeight(height)
|
arkanes@24
|
444 bar.text:SetPoint("LEFT", bar.timertext, "RIGHT", 0, 0)
|
arkanes@0
|
445 bar.text:SetPoint("RIGHT", bar.statusbar, "RIGHT", 0, 0)
|
arkanes@0
|
446 bar.text:SetJustifyH("LEFT")
|
arkanes@0
|
447 bar.text:SetText("text")
|
arkanes@0
|
448 bar.text:SetTextColor(textcolor[1], textcolor[2], textcolor[3], textcolor[4])
|
arkanes@0
|
449 return bar
|
arkanes@0
|
450 end
|
arkanes@0
|
451
|
arkanes@38
|
452 function kbf:CreateCoreFrames()
|
arkanes@38
|
453 -- this is the visible anchor frame that the user interacts with
|
arkanes@38
|
454 -- to move the buffs around
|
arkanes@0
|
455 local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent)
|
arkanes@0
|
456 anchor:SetClampedToScreen(true)
|
arkanes@0
|
457 anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
arkanes@0
|
458 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
|
arkanes@18
|
459 tile = true, tileSize = 16, edgeSize = 12,
|
arkanes@0
|
460 insets = { left = 4, right = 4, top = 4, bottom = 4 },
|
arkanes@0
|
461 })
|
arkanes@0
|
462 local text = anchor:CreateFontString(nil, "OVERLAY") -- the label text
|
arkanes@0
|
463 text:SetFontObject(GameFontHighlight)
|
arkanes@0
|
464 text:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
465 text:SetPoint("TOPLEFT", anchor, "TOPLEFT", 0, 0)
|
arkanes@0
|
466 text:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 0, 0)
|
arkanes@0
|
467 text:SetText("KBF ANCHOR")
|
arkanes@18
|
468 anchor:SetWidth(200 +16)
|
arkanes@18
|
469 anchor:SetHeight(16)
|
arkanes@0
|
470 -- movability
|
arkanes@0
|
471 anchor:EnableMouse(true)
|
arkanes@0
|
472 anchor:SetMovable(true)
|
arkanes@0
|
473 anchor:RegisterForDrag("LeftButton")
|
arkanes@0
|
474 anchor:SetScript("OnDragStart", anchor.StartMoving)
|
arkanes@0
|
475 anchor:SetScript("OnDragStop", anchor.StopMovingOrSizing)
|
arkanes@0
|
476 anchor:ClearAllPoints()
|
arkanes@22
|
477 anchor:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0)
|
arkanes@0
|
478 anchor:Hide()
|
arkanes@38
|
479 -- this is the parent & host for the secure aura buttons.
|
arkanes@0
|
480
|
arkanes@38
|
481 local secureHeader = CreateFrame("FRAME", "KBFBuffFrame", UIParent, "SecureAuraHeaderTemplate")
|
arkanes@38
|
482 self:SetCommonSecureHeaderAttributes(secureHeader)
|
arkanes@40
|
483 secureHeader:SetAttribute("consolidateTo", 99)
|
arkanes@38
|
484 secureHeader:SetPoint("TOP", anchor, "TOP", 0, 0)
|
arkanes@38
|
485
|
arkanes@38
|
486 -- this is the "button" in the aura flow that represents the consolidated buffs.
|
arkanes@38
|
487 -- pre-creating it here in order to perform customization
|
arkanes@40
|
488 local consolidateProxy = CreateFrame("BUTTON", nil, UIParent, "SecureHandlerClickTemplate")
|
arkanes@39
|
489 consolidateProxy:SetNormalTexture("Interface\\TargetingFrame\\UI-StatusBar")
|
arkanes@39
|
490 consolidateProxy:SetWidth(200 +16)
|
arkanes@39
|
491 consolidateProxy:SetHeight(16)
|
arkanes@38
|
492 secureHeader:SetAttribute("consolidateProxy", consolidateProxy)
|
arkanes@40
|
493 --secureHeader:SetFrameRef("proxy", consolidateProxy)
|
arkanes@40
|
494
|
arkanes@40
|
495
|
arkanes@38
|
496 -- this is the equivilent of the secureHeader for the consolidated buffs
|
arkanes@38
|
497 -- pre-creating again, so we can customize/size/position it
|
arkanes@38
|
498 local consolidateHeader = CreateFrame("FRAME", "KBFConsolidatedAnchorFrame", consolidateProxy)
|
arkanes@38
|
499 self:SetCommonSecureHeaderAttributes(consolidateHeader)
|
arkanes@38
|
500 secureHeader:SetAttribute("consolidateHeader", consolidateHeader)
|
arkanes@39
|
501 consolidateProxy:SetAttribute("header", consolidateHeader);
|
arkanes@40
|
502 consolidateProxy:SetFrameRef("header", consolidateHeader)
|
arkanes@40
|
503
|
arkanes@40
|
504 consolidateProxy:SetAttribute("_onclick", [[
|
arkanes@40
|
505 local frame = self:GetFrameRef("header")
|
arkanes@40
|
506 if frame:IsShown() then frame:Hide() else frame:Show() end
|
arkanes@40
|
507 ]])
|
arkanes@40
|
508 consolidateProxy:EnableMouse(true)
|
arkanes@40
|
509 consolidateProxy:RegisterForClicks("AnyUp")
|
arkanes@39
|
510
|
arkanes@39
|
511 -- position it relative to the proxy, so it can appear where we want it
|
arkanes@40
|
512 consolidateHeader:SetPoint("TOPRIGHT", anchor, "TOPLEFT", 0, 0)
|
arkanes@38
|
513 consolidateHeader:SetWidth(200 +16)
|
arkanes@38
|
514 consolidateHeader:SetHeight(16)
|
arkanes@38
|
515 consolidateHeader:Show()
|
arkanes@39
|
516
|
arkanes@38
|
517 return anchor, secureHeader, consolidateHeader, consolidateProxy
|
arkanes@37
|
518 end
|
arkanes@37
|
519
|
arkanes@38
|
520 --- sets the attributes needed by all the headers
|
arkanes@38
|
521 function kbf:SetCommonSecureHeaderAttributes(frame)
|
arkanes@0
|
522 frame:SetAttribute("filter", "HELPFUL")
|
arkanes@20
|
523 frame:SetAttribute("toggleForVehicle", true) -- this doesn't actually work right now, but maybe it eventually will
|
arkanes@0
|
524 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate")
|
arkanes@3
|
525 frame:SetAttribute("point", "TOP")
|
arkanes@0
|
526 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header
|
arkanes@2
|
527 frame:SetAttribute("xOffset", 0)
|
arkanes@3
|
528 frame:SetAttribute("yOffset", -16)
|
arkanes@3
|
529 frame:SetAttribute("minWidth", 216)
|
arkanes@3
|
530 frame:SetAttribute("minHeight", 16)
|
arkanes@25
|
531 frame:SetAttribute("unit", "player")
|
arkanes@3
|
532 frame:SetAttribute("sortMethod", "NAME")
|
arkanes@3
|
533 frame:SetAttribute("sortOrder", "-")
|
arkanes@41
|
534 -- TODO: SecureAuraHeader doesn't correctly implement the temp enchants
|
arkanes@17
|
535 frame:SetAttribute("weaponTemplate", "KBFSecureUnitAuraTemplate")
|
arkanes@41
|
536 frame:SetAttribute("includeWeapons", 100)
|
arkanes@5
|
537 frame:Show() -- has to be shown, otherwise the child frames don't show
|
arkanes@37
|
538 return frame
|
arkanes@0
|
539 end
|
arkanes@18
|
540
|
arkanes@18
|
541 function kbf:ShowAnchor()
|
arkanes@38
|
542 self.secureHeader:ClearAllPoints()
|
arkanes@38
|
543 self.secureHeader:SetPoint("TOP", self.anchor, "BOTTOM", 0, 0)
|
arkanes@18
|
544 self.anchor:Show()
|
arkanes@18
|
545 end
|
arkanes@18
|
546
|
arkanes@18
|
547 function kbf:HideAnchor()
|
arkanes@38
|
548 self.secureHeader:ClearAllPoints()
|
arkanes@38
|
549 self.secureHeader:SetPoint("TOP", self.anchor, "TOP", 0, 0)
|
arkanes@18
|
550 self.anchor:Hide()
|
arkanes@18
|
551 end
|
arkanes@18
|
552
|
arkanes@18
|
553 function kbf:ToggleAnchor()
|
arkanes@18
|
554 if self.anchor:IsShown() then
|
arkanes@18
|
555 self:HideAnchor()
|
arkanes@18
|
556 else
|
arkanes@18
|
557 self:ShowAnchor()
|
arkanes@18
|
558 end
|
arkanes@18
|
559 end
|