Mercurial > wow > kbf
comparison KBF.lua @ 38:0addebdd412f
Do the refactoring that was needed for the consolidated header, works in a pretty clean way now, still need to get it set up for flyouts and in-combat support
| author | Chris Mellon <arkanes@gmail.com> |
|---|---|
| date | Fri, 31 Dec 2010 13:13:54 -0600 |
| parents | 15b9e97ab2d2 |
| children | 0aeebc3f4fe9 |
comparison
equal
deleted
inserted
replaced
| 37:15b9e97ab2d2 | 38:0addebdd412f |
|---|---|
| 5 local kbf = LibStub("AceAddon-3.0"):NewAddon(kbf, "KBF", "AceEvent-3.0", "AceConsole-3.0") | 5 local kbf = LibStub("AceAddon-3.0"):NewAddon(kbf, "KBF", "AceEvent-3.0", "AceConsole-3.0") |
| 6 | 6 |
| 7 | 7 |
| 8 function kbf:OnInitialize() | 8 function kbf:OnInitialize() |
| 9 self.debuffFrames = {} | 9 self.debuffFrames = {} |
| 10 self.anchor = self:CreateAnchorFrame() | |
| 11 self:RegisterEvent("UNIT_AURA") | 10 self:RegisterEvent("UNIT_AURA") |
| 12 self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange") | 11 self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange") |
| 13 self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange") | 12 self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange") |
| 14 -- set up the countdown timer | 13 self:RegisterChatCommand("kbf", "ToggleAnchor") |
| 14 end | |
| 15 | |
| 16 function kbf:OnEnable() | |
| 17 self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy = self:CreateCoreFrames() | |
| 18 -- set up the countdown timer | |
| 15 -- TODO: Fancy enable/disable based on whether you have any timed buffs. | 19 -- TODO: Fancy enable/disable based on whether you have any timed buffs. |
| 16 -- Not a big deal, how often do you care about that | 20 -- Not a big deal, how often do you care about that |
| 17 -- also TODO: Maybe should bucket OnUpdates somehow | 21 -- also TODO: Maybe should bucket OnUpdates somehow |
| 18 -- AceTimer repeating events can only happen at 0.1 seconds, which is probably | 22 -- AceTimer repeating events can only happen at 0.1 seconds, which is probably |
| 19 -- fast enough for updating, but makes the animation look jerky | 23 -- fast enough for updating, but makes the animation look jerky |
| 20 -- need to experiment with using animation groups | 24 -- need to experiment with using animation groups |
| 21 self.update = CreateFrame("FRAME") | 25 self.update = CreateFrame("FRAME") |
| 22 self.update:SetScript("OnUpdate", function() self:OnUpdate() end) | 26 self.update:SetScript("OnUpdate", function() self:OnUpdate() end) |
| 23 self.dirty = true -- force an immediate scan on login | 27 self.dirty = true -- force an immediate scan on login |
| 24 self:HideBlizzardBuffFrames() | 28 self:HideBlizzardBuffFrames() |
| 25 self:RegisterChatCommand("kbf", "ToggleAnchor") | |
| 26 end | 29 end |
| 27 -- naming convention | 30 -- naming convention |
| 28 -- a "frame" is the top-level button (secure button from the header, or one I make myself) | 31 -- a "frame" is the top-level button (secure button from the header, or one I make myself) |
| 29 -- that will contain the UI information about the buff | 32 -- that will contain the UI information about the buff |
| 30 -- a "bar" is a frame that has the icon, status bar, ect associated with it | 33 -- a "bar" is a frame that has the icon, status bar, ect associated with it |
| 59 -- only swap if we're in a "real" vehicle with its own actions | 62 -- only swap if we're in a "real" vehicle with its own actions |
| 60 -- There is possibly a timing issue here where | 63 -- There is possibly a timing issue here where |
| 61 -- we have set the poll flag but the unit is not | 64 -- we have set the poll flag but the unit is not |
| 62 -- actually "in" the vehicle yet. I'm hoping thats | 65 -- actually "in" the vehicle yet. I'm hoping thats |
| 63 -- handled by using exited/entered events instead of exiting/entering | 66 -- handled by using exited/entered events instead of exiting/entering |
| 64 self.secureFrame:SetAttribute("unit", "vehicle") | 67 self.secureHeader:SetAttribute("unit", "vehicle") |
| 65 else | 68 else |
| 66 self.secureFrame:SetAttribute("unit", "player") | 69 self.secureHeader:SetAttribute("unit", "player") |
| 67 end | 70 end |
| 68 self.pollForUnitChange = nil | 71 self.pollForUnitChange = nil |
| 69 end | 72 end |
| 70 local unit = self.secureFrame:GetAttribute("unit") | 73 local unit = self.secureHeader:GetAttribute("unit") |
| 71 local buffCount = 0 | 74 local buffCount = 0 |
| 72 for idx=1,99 do | 75 for idx=1,99 do |
| 73 local frame = self.secureFrame:GetAttribute("child"..idx) | 76 local frame = self.secureHeader:GetAttribute("child"..idx) |
| 74 if not (frame and frame:IsShown()) then break end | 77 if not (frame and frame:IsShown()) then break end |
| 75 buffCount = buffCount + 1 | 78 buffCount = buffCount + 1 |
| 76 if self.dirty then | 79 if self.dirty then |
| 77 if self:BindBarToBuff(frame, unit) then break end | 80 if self:BindBarToBuff(frame, unit) then break end |
| 78 end | 81 end |
| 83 end | 86 end |
| 84 end | 87 end |
| 85 | 88 |
| 86 -- consolidated buffs | 89 -- consolidated buffs |
| 87 if self.consolidateProxy:IsShown() then | 90 if self.consolidateProxy:IsShown() then |
| 88 self.consolidateHeader:Show() -- *** STATE DRIVEN | 91 --self.consolidateHeader:Show() -- *** STATE DRIVEN |
| 89 for idx=1,99 do | 92 for idx=1,99 do |
| 90 local frame = self.consolidateHeader:GetAttribute("child"..idx) | 93 local frame = self.consolidateHeader:GetAttribute("child"..idx) |
| 91 if not (frame and frame:IsShown()) then break end | 94 if not (frame and frame:IsShown()) then break end |
| 92 if self.dirty then | 95 if self.dirty then |
| 93 if self:BindBarToBuff(frame, unit) then break end | 96 if self:BindBarToBuff(frame, unit) then break end |
| 97 if ( GameTooltip:IsOwned(frame) ) then | 100 if ( GameTooltip:IsOwned(frame) ) then |
| 98 self:OnEnter(frame) | 101 self:OnEnter(frame) |
| 99 end | 102 end |
| 100 end | 103 end |
| 101 else | 104 else |
| 102 self.consolidateHeader:Hide() -- *** STATE DRIVEN | 105 --self.consolidateHeader:Hide() -- *** STATE DRIVEN |
| 103 end | 106 end |
| 104 | 107 |
| 105 -- temporary enchants | 108 -- temporary enchants |
| 106 local tempEnchant = self.secureFrame:GetAttribute("tempEnchant1") | 109 local tempEnchant = self.secureHeader:GetAttribute("tempEnchant1") |
| 107 if tempEnchant and tempEnchant:IsShown() then | 110 if tempEnchant and tempEnchant:IsShown() then |
| 108 if self.dirty or true then | 111 if self.dirty or true then |
| 109 self:BindBarToWeaponEnchant(tempEnchant, 16) | 112 self:BindBarToWeaponEnchant(tempEnchant, 16) |
| 110 end | 113 end |
| 111 self:UpdateBarExpirationTime(tempEnchant) | 114 self:UpdateBarExpirationTime(tempEnchant) |
| 112 buffCount = buffCount + 1 | 115 buffCount = buffCount + 1 |
| 113 end | 116 end |
| 114 tempEnchant = self.secureFrame:GetAttribute("tempEnchant2") | 117 tempEnchant = self.secureHeader:GetAttribute("tempEnchant2") |
| 115 if tempEnchant and tempEnchant:IsShown() then | 118 if tempEnchant and tempEnchant:IsShown() then |
| 116 if self.dirty or true then | 119 if self.dirty or true then |
| 117 self:BindBarToWeaponEnchant(tempEnchant, 17) | 120 self:BindBarToWeaponEnchant(tempEnchant, 17) |
| 118 end | 121 end |
| 119 self:UpdateBarExpirationTime(tempEnchant) | 122 self:UpdateBarExpirationTime(tempEnchant) |
| 174 end | 177 end |
| 175 self.dirty = nil | 178 self.dirty = nil |
| 176 end | 179 end |
| 177 | 180 |
| 178 function kbf:UNIT_AURA(event, unit) | 181 function kbf:UNIT_AURA(event, unit) |
| 179 if unit ~= self.secureFrame:GetAttribute("unit") then return end | 182 if unit ~= self.secureHeader:GetAttribute("unit") then return end |
| 180 self.dirty = true | 183 self.dirty = true |
| 181 end | 184 end |
| 182 | 185 |
| 183 function kbf:UpdateBarExpirationTime(frame) | 186 function kbf:UpdateBarExpirationTime(frame) |
| 184 if frame.expirationTime then | 187 if frame.expirationTime then |
| 358 bar.text:SetText("text") | 361 bar.text:SetText("text") |
| 359 bar.text:SetTextColor(textcolor[1], textcolor[2], textcolor[3], textcolor[4]) | 362 bar.text:SetTextColor(textcolor[1], textcolor[2], textcolor[3], textcolor[4]) |
| 360 return bar | 363 return bar |
| 361 end | 364 end |
| 362 | 365 |
| 363 function kbf:CreateAnchorFrame() | 366 function kbf:CreateCoreFrames() |
| 364 -- give it a name so it'll remember its position | 367 -- this is the visible anchor frame that the user interacts with |
| 368 -- to move the buffs around | |
| 365 local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent) | 369 local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent) |
| 366 anchor:SetClampedToScreen(true) | 370 anchor:SetClampedToScreen(true) |
| 367 anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", | 371 anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", |
| 368 edgeFile = "Interface/Tooltips/UI-Tooltip-Border", | 372 edgeFile = "Interface/Tooltips/UI-Tooltip-Border", |
| 369 tile = true, tileSize = 16, edgeSize = 12, | 373 tile = true, tileSize = 16, edgeSize = 12, |
| 384 anchor:SetScript("OnDragStart", anchor.StartMoving) | 388 anchor:SetScript("OnDragStart", anchor.StartMoving) |
| 385 anchor:SetScript("OnDragStop", anchor.StopMovingOrSizing) | 389 anchor:SetScript("OnDragStop", anchor.StopMovingOrSizing) |
| 386 anchor:ClearAllPoints() | 390 anchor:ClearAllPoints() |
| 387 anchor:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0) | 391 anchor:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0) |
| 388 anchor:Hide() | 392 anchor:Hide() |
| 393 -- this is the parent & host for the secure aura buttons. | |
| 389 | 394 |
| 390 self.secureFrame = self:CreateSecureHeaderFrame("KBFBuffFrame", "SecureAuraHeaderTemplate") | 395 local secureHeader = CreateFrame("FRAME", "KBFBuffFrame", UIParent, "SecureAuraHeaderTemplate") |
| 391 self.secureFrame:SetPoint("TOP", anchor, "TOP", 0, 0) | 396 self:SetCommonSecureHeaderAttributes(secureHeader) |
| 392 self.secureFrame:SetAttribute("consolidateTo", 1) | 397 secureHeader:SetAttribute("consolidateTo", 1) |
| 393 -- pre-create the consolidated proxy & headers so I can decide what they look like | 398 secureHeader:SetPoint("TOP", anchor, "TOP", 0, 0) |
| 394 -- lazy - just make it a regular bar for now | 399 |
| 395 self.consolidateProxy = self:ConstructBar() | 400 -- this is the "button" in the aura flow that represents the consolidated buffs. |
| 396 self.secureFrame:SetAttribute("consolidateProxy", self.consolidateProxy) | 401 -- pre-creating it here in order to perform customization |
| 397 self.secureFrame:SetAttribute("frameref-proxy", GetFrameHandle(self.consolidateProxy)) | 402 local consolidateProxy = self:ConstructBar() |
| 398 -- pre-create the consolidated header | 403 secureHeader:SetAttribute("consolidateProxy", consolidateProxy) |
| 399 self.consolidateHeader = self:CreateSecureHeaderFrame("KBFConsolidatedAnchorFrame") | 404 secureHeader:SetAttribute("frameref-proxy", GetFrameHandle(consolidateProxy)) |
| 400 self.secureFrame:SetAttribute("consolidateHeader", self.consolidateHeader) | 405 -- this is the equivilent of the secureHeader for the consolidated buffs |
| 401 self.consolidateHeader:SetPoint("RIGHT", self.consolidateProxy, "LEFT", 0, 0) | 406 -- pre-creating again, so we can customize/size/position it |
| 402 self.consolidateHeader:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", | 407 local consolidateHeader = CreateFrame("FRAME", "KBFConsolidatedAnchorFrame", consolidateProxy) |
| 403 edgeFile = "Interface/Tooltips/UI-Tooltip-Border", | 408 self:SetCommonSecureHeaderAttributes(consolidateHeader) |
| 404 tile = true, tileSize = 16, edgeSize = 12, | 409 secureHeader:SetAttribute("consolidateHeader", consolidateHeader) |
| 405 insets = { left = 4, right = 4, top = 4, bottom = 4 }, | 410 -- position it relative to the proxy, so it can appear where we want it |
| 406 }) | 411 consolidateHeader:SetPoint("TOPRIGHT", consolidateProxy, "TOPLEFT", 0, 0) |
| 407 self.consolidateHeader:SetWidth(200 +16) | 412 consolidateHeader:SetWidth(200 +16) |
| 408 self.consolidateHeader:SetHeight(16) | 413 consolidateHeader:SetHeight(16) |
| 409 self.consolidateHeader:Show() | 414 consolidateHeader:Show() |
| 410 self.consolidateProxy:SetAttribute("header", self.consolidateHeader); | 415 consolidateProxy:SetAttribute("header", consolidateHeader); |
| 411 self.consolidateProxy:SetAttribute("frameref-header", GetFrameHandle(self.consolidateHeader)) | 416 consolidateProxy:SetAttribute("frameref-header", GetFrameHandle(consolidateHeader)) |
| 412 return anchor | 417 return anchor, secureHeader, consolidateHeader, consolidateProxy |
| 413 end | 418 end |
| 414 | 419 |
| 415 function kbf:CreateSecureHeaderFrame(name, template) | 420 --- sets the attributes needed by all the headers |
| 416 local frame = CreateFrame("FRAME", name, UIParent, template) | 421 function kbf:SetCommonSecureHeaderAttributes(frame) |
| 417 frame:SetAttribute("filter", "HELPFUL") | 422 frame:SetAttribute("filter", "HELPFUL") |
| 418 frame:SetAttribute("toggleForVehicle", true) -- this doesn't actually work right now, but maybe it eventually will | 423 frame:SetAttribute("toggleForVehicle", true) -- this doesn't actually work right now, but maybe it eventually will |
| 419 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate") | 424 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate") |
| 420 frame:SetAttribute("point", "TOP") | 425 frame:SetAttribute("point", "TOP") |
| 421 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header | 426 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header |
| 432 frame:Show() -- has to be shown, otherwise the child frames don't show | 437 frame:Show() -- has to be shown, otherwise the child frames don't show |
| 433 return frame | 438 return frame |
| 434 end | 439 end |
| 435 | 440 |
| 436 function kbf:ShowAnchor() | 441 function kbf:ShowAnchor() |
| 437 self.secureFrame:ClearAllPoints() | 442 self.secureHeader:ClearAllPoints() |
| 438 self.secureFrame:SetPoint("TOP", self.anchor, "BOTTOM", 0, 0) | 443 self.secureHeader:SetPoint("TOP", self.anchor, "BOTTOM", 0, 0) |
| 439 self.anchor:Show() | 444 self.anchor:Show() |
| 440 end | 445 end |
| 441 | 446 |
| 442 function kbf:HideAnchor() | 447 function kbf:HideAnchor() |
| 443 self.secureFrame:ClearAllPoints() | 448 self.secureHeader:ClearAllPoints() |
| 444 self.secureFrame:SetPoint("TOP", self.anchor, "TOP", 0, 0) | 449 self.secureHeader:SetPoint("TOP", self.anchor, "TOP", 0, 0) |
| 445 self.anchor:Hide() | 450 self.anchor:Hide() |
| 446 end | 451 end |
| 447 | 452 |
| 448 function kbf:ToggleAnchor() | 453 function kbf:ToggleAnchor() |
| 449 if self.anchor:IsShown() then | 454 if self.anchor:IsShown() then |
