annotate KBF.lua @ 38:0addebdd412f

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