annotate KBF.lua @ 40:5def7d061738

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