annotate KBF.lua @ 55:9ab2e1401152

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