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