annotate KBF.lua @ 41:15a0ceebbd83

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