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