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