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