annotate KBF.lua @ 46:04d0d145a676

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