# HG changeset patch # User Chris Mellon # Date 1293822834 21600 # Node ID 0addebdd412f118a83d963e65000420617e28f1d # Parent 15b9e97ab2d268256e351e836a783919de5b831e 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 diff -r 15b9e97ab2d2 -r 0addebdd412f KBF.lua --- a/KBF.lua Fri Dec 31 08:36:30 2010 -0600 +++ b/KBF.lua Fri Dec 31 13:13:54 2010 -0600 @@ -7,11 +7,15 @@ function kbf:OnInitialize() self.debuffFrames = {} - self.anchor = self:CreateAnchorFrame() self:RegisterEvent("UNIT_AURA") self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange") self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange") - -- set up the countdown timer + self:RegisterChatCommand("kbf", "ToggleAnchor") +end + +function kbf:OnEnable() + self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy = self:CreateCoreFrames() + -- set up the countdown timer -- TODO: Fancy enable/disable based on whether you have any timed buffs. -- Not a big deal, how often do you care about that -- also TODO: Maybe should bucket OnUpdates somehow @@ -22,7 +26,6 @@ self.update:SetScript("OnUpdate", function() self:OnUpdate() end) self.dirty = true -- force an immediate scan on login self:HideBlizzardBuffFrames() - self:RegisterChatCommand("kbf", "ToggleAnchor") end -- naming convention -- a "frame" is the top-level button (secure button from the header, or one I make myself) @@ -61,16 +64,16 @@ -- we have set the poll flag but the unit is not -- actually "in" the vehicle yet. I'm hoping thats -- handled by using exited/entered events instead of exiting/entering - self.secureFrame:SetAttribute("unit", "vehicle") + self.secureHeader:SetAttribute("unit", "vehicle") else - self.secureFrame:SetAttribute("unit", "player") + self.secureHeader:SetAttribute("unit", "player") end self.pollForUnitChange = nil end - local unit = self.secureFrame:GetAttribute("unit") + local unit = self.secureHeader:GetAttribute("unit") local buffCount = 0 for idx=1,99 do - local frame = self.secureFrame:GetAttribute("child"..idx) + local frame = self.secureHeader:GetAttribute("child"..idx) if not (frame and frame:IsShown()) then break end buffCount = buffCount + 1 if self.dirty then @@ -85,7 +88,7 @@ -- consolidated buffs if self.consolidateProxy:IsShown() then - self.consolidateHeader:Show() -- *** STATE DRIVEN + --self.consolidateHeader:Show() -- *** STATE DRIVEN for idx=1,99 do local frame = self.consolidateHeader:GetAttribute("child"..idx) if not (frame and frame:IsShown()) then break end @@ -99,11 +102,11 @@ end end else - self.consolidateHeader:Hide() -- *** STATE DRIVEN + --self.consolidateHeader:Hide() -- *** STATE DRIVEN end -- temporary enchants - local tempEnchant = self.secureFrame:GetAttribute("tempEnchant1") + local tempEnchant = self.secureHeader:GetAttribute("tempEnchant1") if tempEnchant and tempEnchant:IsShown() then if self.dirty or true then self:BindBarToWeaponEnchant(tempEnchant, 16) @@ -111,7 +114,7 @@ self:UpdateBarExpirationTime(tempEnchant) buffCount = buffCount + 1 end - tempEnchant = self.secureFrame:GetAttribute("tempEnchant2") + tempEnchant = self.secureHeader:GetAttribute("tempEnchant2") if tempEnchant and tempEnchant:IsShown() then if self.dirty or true then self:BindBarToWeaponEnchant(tempEnchant, 17) @@ -176,7 +179,7 @@ end function kbf:UNIT_AURA(event, unit) - if unit ~= self.secureFrame:GetAttribute("unit") then return end + if unit ~= self.secureHeader:GetAttribute("unit") then return end self.dirty = true end @@ -360,8 +363,9 @@ return bar end -function kbf:CreateAnchorFrame() - -- give it a name so it'll remember its position +function kbf:CreateCoreFrames() + -- this is the visible anchor frame that the user interacts with + -- to move the buffs around local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent) anchor:SetClampedToScreen(true) anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", @@ -386,34 +390,35 @@ anchor:ClearAllPoints() anchor:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0) anchor:Hide() + -- this is the parent & host for the secure aura buttons. - self.secureFrame = self:CreateSecureHeaderFrame("KBFBuffFrame", "SecureAuraHeaderTemplate") - self.secureFrame:SetPoint("TOP", anchor, "TOP", 0, 0) - self.secureFrame:SetAttribute("consolidateTo", 1) - -- pre-create the consolidated proxy & headers so I can decide what they look like - -- lazy - just make it a regular bar for now - self.consolidateProxy = self:ConstructBar() - self.secureFrame:SetAttribute("consolidateProxy", self.consolidateProxy) - self.secureFrame:SetAttribute("frameref-proxy", GetFrameHandle(self.consolidateProxy)) - -- pre-create the consolidated header - self.consolidateHeader = self:CreateSecureHeaderFrame("KBFConsolidatedAnchorFrame") - self.secureFrame:SetAttribute("consolidateHeader", self.consolidateHeader) - self.consolidateHeader:SetPoint("RIGHT", self.consolidateProxy, "LEFT", 0, 0) - self.consolidateHeader:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", - edgeFile = "Interface/Tooltips/UI-Tooltip-Border", - tile = true, tileSize = 16, edgeSize = 12, - insets = { left = 4, right = 4, top = 4, bottom = 4 }, - }) - self.consolidateHeader:SetWidth(200 +16) - self.consolidateHeader:SetHeight(16) - self.consolidateHeader:Show() - self.consolidateProxy:SetAttribute("header", self.consolidateHeader); - self.consolidateProxy:SetAttribute("frameref-header", GetFrameHandle(self.consolidateHeader)) - return anchor + local secureHeader = CreateFrame("FRAME", "KBFBuffFrame", UIParent, "SecureAuraHeaderTemplate") + self:SetCommonSecureHeaderAttributes(secureHeader) + secureHeader:SetAttribute("consolidateTo", 1) + secureHeader:SetPoint("TOP", anchor, "TOP", 0, 0) + + -- this is the "button" in the aura flow that represents the consolidated buffs. + -- pre-creating it here in order to perform customization + local consolidateProxy = self:ConstructBar() + secureHeader:SetAttribute("consolidateProxy", consolidateProxy) + secureHeader:SetAttribute("frameref-proxy", GetFrameHandle(consolidateProxy)) + -- this is the equivilent of the secureHeader for the consolidated buffs + -- pre-creating again, so we can customize/size/position it + local consolidateHeader = CreateFrame("FRAME", "KBFConsolidatedAnchorFrame", consolidateProxy) + self:SetCommonSecureHeaderAttributes(consolidateHeader) + secureHeader:SetAttribute("consolidateHeader", consolidateHeader) + -- position it relative to the proxy, so it can appear where we want it + consolidateHeader:SetPoint("TOPRIGHT", consolidateProxy, "TOPLEFT", 0, 0) + consolidateHeader:SetWidth(200 +16) + consolidateHeader:SetHeight(16) + consolidateHeader:Show() + consolidateProxy:SetAttribute("header", consolidateHeader); + consolidateProxy:SetAttribute("frameref-header", GetFrameHandle(consolidateHeader)) + return anchor, secureHeader, consolidateHeader, consolidateProxy end -function kbf:CreateSecureHeaderFrame(name, template) - local frame = CreateFrame("FRAME", name, UIParent, template) +--- sets the attributes needed by all the headers +function kbf:SetCommonSecureHeaderAttributes(frame) frame:SetAttribute("filter", "HELPFUL") frame:SetAttribute("toggleForVehicle", true) -- this doesn't actually work right now, but maybe it eventually will frame:SetAttribute("template", "KBFSecureUnitAuraTemplate") @@ -434,14 +439,14 @@ end function kbf:ShowAnchor() - self.secureFrame:ClearAllPoints() - self.secureFrame:SetPoint("TOP", self.anchor, "BOTTOM", 0, 0) + self.secureHeader:ClearAllPoints() + self.secureHeader:SetPoint("TOP", self.anchor, "BOTTOM", 0, 0) self.anchor:Show() end function kbf:HideAnchor() - self.secureFrame:ClearAllPoints() - self.secureFrame:SetPoint("TOP", self.anchor, "TOP", 0, 0) + self.secureHeader:ClearAllPoints() + self.secureHeader:SetPoint("TOP", self.anchor, "TOP", 0, 0) self.anchor:Hide() end