changeset 67:673fd9893f1e

set consolidation so that infinite (duration = 0) buffs will be consoliated
author Chris Mellon <arkanes@gmail.com>
date Sat, 30 Jun 2012 15:44:10 -0500
parents 6f1457157688
children f5bd73181349
files KBF.lua
diffstat 1 files changed, 139 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/KBF.lua	Tue Feb 28 13:44:48 2012 -0600
+++ b/KBF.lua	Sat Jun 30 15:44:10 2012 -0500
@@ -6,12 +6,12 @@
 
 
 function kbf:OnInitialize()
-	self.oocQueue = {}
-	-- config settings - account wide shared profile by default
-	self.db = LibStub("AceDB-3.0"):New("KBFSavedVars", self.defaultConfig, true)
-	-- create frames here so that they will be correctly stored in location cache by 
-	-- the UI.
-	self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy = self:CreateCoreFrames()
+    self.oocQueue = {}
+    -- config settings - account wide shared profile by default
+    self.db = LibStub("AceDB-3.0"):New("KBFSavedVars", self.defaultConfig, true)
+    -- create frames here so that they will be correctly stored in location cache by 
+    -- the UI.
+    self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy = self:CreateCoreFrames()
     self.debuffFrames = {}
     self:RegisterEvent("UNIT_AURA")
     self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange")
@@ -24,7 +24,7 @@
 end
 
 function kbf:OnEnable()
-	-- set up the countdown timer
+    -- 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
@@ -47,12 +47,12 @@
     if unit ~= "player" then return end
     self.dirty = true
     local function performSwap()
-    	if UnitHasVehicleUI("player") then
-			-- only swap if we're in a "real" vehicle with its own actions
-        	-- There is possibly a timing issue here where
-        	-- 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
+        if UnitHasVehicleUI("player") then
+            -- only swap if we're in a "real" vehicle with its own actions
+            -- There is possibly a timing issue here where
+            -- 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.secureHeader:SetAttribute("unit", "vehicle")
         else
             self.secureHeader:SetAttribute("unit", "player")
@@ -80,18 +80,18 @@
 -- if called when OOC, the function will be called immediately, unless the alwaysQueue parameter is true, 
 -- in which case it will be appended normally
 function kbf:QueueForOOC(func, alwaysQueue)
-	if InCombatLockdown() or alwaysQueue then
-		tinsert(self.oocQueue, func)
-	else
-		func()
-	end
+    if InCombatLockdown() or alwaysQueue then
+        tinsert(self.oocQueue, func)
+    else
+        func()
+    end
 end
 
 function kbf:OnUpdate()   
     -- TODO: only start this polling when we leave combat?
     while #self.oocQueue > 0  and not InCombatLockdown() do
-		local func = table.remove(self.oocQueue)
-		func()
+        local func = table.remove(self.oocQueue)
+        func()
     end
     
     local unit = self.secureHeader:GetAttribute("unit")
@@ -101,30 +101,30 @@
         if not (frame and frame:IsShown()) then break end
         local boundIndex = frame:GetAttribute("index")
         if not boundIndex then
-			break
+            break
         end
         if self.dirty then
-			local hasbuff = UnitAura(unit, boundIndex)
-			--self:Print(hasbuff, idx, boundIndex)
-			if not hasbuff then
-				if frame.icon then frame.icon:Hide() end
-				if frame.statusbar then frame.statusbar:Hide() end
-				if frame.statusbarbg then frame.statusbarbg:Hide() end
-				if frame.text then frame.text:Hide() end
-				if frame.timertext then frame.timertext:Hide() end
-				break 
-			end
-			buffCount = buffCount + 1
-			
-			if self.dirty then 
-				if self:BindBarToBuff(frame, unit) then break end
-			end
-			frame.icon:Show()
-			frame.statusbar:Show()
-			frame.statusbarbg:Show()
-			frame.text:Show()
-			frame.timertext:Show()
-		end
+            local hasbuff = UnitAura(unit, boundIndex)
+            --self:Print(hasbuff, idx, boundIndex)
+            if not hasbuff then
+                if frame.icon then frame.icon:Hide() end
+                if frame.statusbar then frame.statusbar:Hide() end
+                if frame.statusbarbg then frame.statusbarbg:Hide() end
+                if frame.text then frame.text:Hide() end
+                if frame.timertext then frame.timertext:Hide() end
+                break 
+            end
+            buffCount = buffCount + 1
+            
+            if self.dirty then 
+                if self:BindBarToBuff(frame, unit) then break end
+            end
+            frame.icon:Show()
+            frame.statusbar:Show()
+            frame.statusbarbg:Show()
+            frame.text:Show()
+            frame.timertext:Show()
+        end
         self:UpdateBarExpirationTime(frame)
         -- Don't forget to refresh shown tooltips
         if (GameTooltip:IsOwned(frame)) then
@@ -133,36 +133,36 @@
     end
     -- consolidated buffs
     if self.consolidateProxy:IsShown() then
-		for idx=1,99 do
-			local frame = self.consolidateHeader:GetAttribute("child"..idx)
-			if not (frame and frame:IsShown()) then break end
-			if self.dirty then 
-				if self:BindBarToBuff(frame, unit) then break end
-			end
-			self:UpdateBarExpirationTime(frame)
-			-- Don't forget to refresh shown tooltips
-			if ( GameTooltip:IsOwned(frame) ) then
-				self:OnEnter(frame)
-			end
-		end
-		buffCount = buffCount+1
-	end
-	-- SAH correctly binds the weapon enchant templates now, but when temp enchants
-	-- are present and used, it seems that it doesn't correctly hide un-bound 
-	-- buff frames, which breaks all the layout and so forth.
-	for weapon=3,1,-1 do
-		local tempEnchant = self.secureHeader:GetAttribute("tempEnchant"..weapon)
-		if tempEnchant and tempEnchant:IsShown() then
-			self:BindBarToWeaponEnchant(tempEnchant)
-			self:UpdateBarExpirationTime(tempEnchant)
-			buffCount = buffCount + 1
-		end
-	end
-	
-	-- debuffs
-	-- Since debuffs aren't cancellable, don't need to use the secure header
-	-- for them. This could be rewritten to support useful features like
-	-- sorting & scaling and stuff. Honestly, should at least be alphabetical.
+        for idx=1,99 do
+            local frame = self.consolidateHeader:GetAttribute("child"..idx)
+            if not (frame and frame:IsShown()) then break end
+            if self.dirty then 
+                if self:BindBarToBuff(frame, unit) then break end
+            end
+            self:UpdateBarExpirationTime(frame)
+            -- Don't forget to refresh shown tooltips
+            if ( GameTooltip:IsOwned(frame) ) then
+                self:OnEnter(frame)
+            end
+        end
+        buffCount = buffCount+1
+    end
+    -- SAH correctly binds the weapon enchant templates now, but when temp enchants
+    -- are present and used, it seems that it doesn't correctly hide un-bound 
+    -- buff frames, which breaks all the layout and so forth.
+    for weapon=3,1,-1 do
+        local tempEnchant = self.secureHeader:GetAttribute("tempEnchant"..weapon)
+        if tempEnchant and tempEnchant:IsShown() then
+            self:BindBarToWeaponEnchant(tempEnchant)
+            self:UpdateBarExpirationTime(tempEnchant)
+            buffCount = buffCount + 1
+        end
+    end
+    
+    -- debuffs
+    -- Since debuffs aren't cancellable, don't need to use the secure header
+    -- for them. This could be rewritten to support useful features like
+    -- sorting & scaling and stuff. Honestly, should at least be alphabetical.
     for idx=1,99 do
         local frame = self.debuffFrames[idx]
         if self.dirty then
@@ -233,11 +233,11 @@
     local icon = GetInventoryItemTexture("player", slot)
     local maxDuration
     if select(2, UnitClass("player")) == "ROGUE" then
-    	-- Rogues are probably using poisons, which are an hour
-    	maxDuration = 60 * 60
+        -- Rogues are probably using poisons, which are an hour
+        maxDuration = 60 * 60
     else
-    	-- everyone else is probably using something thats a half hour
-    	maxDuration = 30 * 60
+        -- everyone else is probably using something thats a half hour
+        maxDuration = 30 * 60
     end
     local duration = max(maxDuration, remaining)
     local expirationTime = GetTime() + remaining
@@ -245,29 +245,29 @@
     -- try to figure out what the weapon enchant is
     -- tooltip string -> {spellid, duration}
     local knownEnchants = {
-    	["Flametongue"] = {8024, 30*60},
-    	["Frostbrand"] = {8033, 30*60},
-    	["Earthliving"] = {51730, 30*60},
-		["Windfury"] = {8232, 30*60},
-    	["Instant Poison"] = {8680, 60*60},
-    	["Wound Poison"] = {13218, 60*60},
-    	["Deadly Poison"] = {2823, 60*60},
-    	["Crippling Poison"] = {3408, 60*60}
+        ["Flametongue"] = {8024, 30*60},
+        ["Frostbrand"] = {8033, 30*60},
+        ["Earthliving"] = {51730, 30*60},
+        ["Windfury"] = {8232, 30*60},
+        ["Instant Poison"] = {8680, 60*60},
+        ["Wound Poison"] = {13218, 60*60},
+        ["Deadly Poison"] = {2823, 60*60},
+        ["Crippling Poison"] = {3408, 60*60}
     
     }
     local spellId = nil
-	if gratt then
-		gratt:SetInventoryItem("player", slot)
-		for tag, info in pairs(knownEnchants) do
-			if gratt:Find(tag) then 
-				spellId, duration = unpack(info)
-				name, _, _ = GetSpellInfo(spellId)
-				local slots = {[16] = "Main Hand", [17] = "Off Hand", [18] = "Thrown"}
-				name = tag .. " (" .. slots[slot] .. ")"
-				break
-			end
-		end
-	end
+    if gratt then
+        gratt:SetInventoryItem("player", slot)
+        for tag, info in pairs(knownEnchants) do
+            if gratt:Find(tag) then 
+                spellId, duration = unpack(info)
+                name, _, _ = GetSpellInfo(spellId)
+                local slots = {[16] = "Main Hand", [17] = "Off Hand", [18] = "Thrown"}
+                name = tag .. " (" .. slots[slot] .. ")"
+                break
+            end
+        end
+    end
     parentFrame.spellId = spellId
     if not parentFrame.icon then
         self:ConstructBar(parentFrame, 1, 0, 1)
@@ -342,23 +342,23 @@
     end
     local slot = button:GetAttribute("target-slot") -- temp enchant
     if slot then
-		GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT");
-		GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
-    	if button.spellId then
-    		-- TODO: This might be too big of a tooltip to care about that much.
-    		-- Maybe I should just have a single line with the weapon name
-    		--GameTooltip:SetInventoryItem(unit, slot)
-    		local name = GetItemInfo(GetInventoryItemID("player", slot))
-    		local r, g, b = GetItemQualityColor(GetInventoryItemQuality("player", slot))
-    		GameTooltip:SetText(name, r, g, b)
-			local slots = {[16] = "Main Hand", [17] = "Off Hand", [18] = "Thrown"}
-			GameTooltip:AddLine(slots[slot])
-    		GameTooltip:AddLine(" ")
-    		GameTooltip:AddSpellByID(button.spellId)
-    	else
-    		GameTooltip:SetInventoryItem(unit, slot)
-    	end
-	end
+        GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT");
+        GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
+        if button.spellId then
+            -- TODO: This might be too big of a tooltip to care about that much.
+            -- Maybe I should just have a single line with the weapon name
+            --GameTooltip:SetInventoryItem(unit, slot)
+            local name = GetItemInfo(GetInventoryItemID("player", slot))
+            local r, g, b = GetItemQualityColor(GetInventoryItemQuality("player", slot))
+            GameTooltip:SetText(name, r, g, b)
+            local slots = {[16] = "Main Hand", [17] = "Off Hand", [18] = "Thrown"}
+            GameTooltip:AddLine(slots[slot])
+            GameTooltip:AddLine(" ")
+            GameTooltip:AddSpellByID(button.spellId)
+        else
+            GameTooltip:SetInventoryItem(unit, slot)
+        end
+    end
 end
 
 -- creates a icon + statusbar bar
@@ -389,7 +389,7 @@
     bar.statusbar = CreateFrame("StatusBar", "ABC-status", bar) -- and the bars foreground
     bar.text = bar.statusbar:CreateFontString(nil, "OVERLAY") -- the label text
     bar.timertext = bar.statusbar:CreateFontString(nil, "OVERLAY") -- and the timer text
-	
+    
 
     -- the icon
     bar.icon:ClearAllPoints()
@@ -438,9 +438,9 @@
 end
 
 function kbf:CreateCoreFrames()
-	-- this is the visible anchor frame that the user interacts with 
-	-- to move the buffs around
-	local height = self.staticConfig.BAR_HEIGHT
+    -- this is the visible anchor frame that the user interacts with 
+    -- to move the buffs around
+    local height = self.staticConfig.BAR_HEIGHT
     local width = self.staticConfig.BAR_WIDTH -- this is the width *without* the icon
     local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent)
     anchor:SetClampedToScreen(true)
@@ -468,11 +468,12 @@
     anchor:Hide()
     -- this is the parent & host for the secure aura buttons. 
     
-	local secureHeader = CreateFrame("FRAME", "KBFBuffFrame", UIParent, "SecureAuraHeaderTemplate")
-	self:SetCommonSecureHeaderAttributes(secureHeader)
-	if self.db.profile.consolidateBuffs then
-	    secureHeader:SetAttribute("consolidateTo", 99)
-	end
+    local secureHeader = CreateFrame("FRAME", "KBFBuffFrame", UIParent, "SecureAuraHeaderTemplate")
+    self:SetCommonSecureHeaderAttributes(secureHeader)
+    if self.db.profile.consolidateBuffs then
+        secureHeader:SetAttribute("consolidateTo", 99)
+        secureHeader:SetAttribute("consolidateDuration", -1) -- put 0 duration buffs into consolidation
+    end
     secureHeader:SetPoint("TOP", anchor, "TOP", 0, 0)
     
     -- this is the "button" in the aura flow that represents the consolidated buffs.
@@ -481,7 +482,7 @@
     consolidateProxy:SetFrameStrata("HIGH")
     consolidateProxy:SetNormalTexture("Interface\\TargetingFrame\\UI-StatusBar")
     consolidateProxy:SetWidth(200 +16)
-	consolidateProxy:SetHeight(16)
+    consolidateProxy:SetHeight(16)
     secureHeader:SetAttribute("consolidateProxy", consolidateProxy)
     --secureHeader:SetFrameRef("proxy", consolidateProxy)
 
@@ -491,22 +492,22 @@
     local consolidateHeader = CreateFrame("FRAME", "KBFConsolidatedAnchorFrame", consolidateProxy)
     self:SetCommonSecureHeaderAttributes(consolidateHeader)
     secureHeader:SetAttribute("consolidateHeader", consolidateHeader)
-	consolidateProxy:SetAttribute("header", consolidateHeader);
-	consolidateProxy:SetFrameRef("header", consolidateHeader)
-	
-	consolidateProxy:SetAttribute("_onclick", [[
-    	local frame = self:GetFrameRef("header")
-    	if frame:IsShown() then frame:Hide() else frame:Show() end
+    consolidateProxy:SetAttribute("header", consolidateHeader);
+    consolidateProxy:SetFrameRef("header", consolidateHeader)
+    
+    consolidateProxy:SetAttribute("_onclick", [[
+        local frame = self:GetFrameRef("header")
+        if frame:IsShown() then frame:Hide() else frame:Show() end
     ]])
     consolidateProxy:EnableMouse(true)
     consolidateProxy:RegisterForClicks("AnyUp")
-	
-	-- position it relative to the proxy, so it can appear where we want it
+    
+    -- position it relative to the proxy, so it can appear where we want it
     consolidateHeader:SetPoint("TOPRIGHT", anchor, "TOPLEFT", 0, 0)
-	consolidateHeader:SetWidth(height + width)
-	consolidateHeader:SetHeight(height)
-	consolidateHeader:Show()
-	
+    consolidateHeader:SetWidth(height + width)
+    consolidateHeader:SetHeight(height)
+    consolidateHeader:Show()
+    
     return anchor, secureHeader, consolidateHeader, consolidateProxy
 end
 
@@ -524,9 +525,9 @@
     frame:SetAttribute("sortMethod", "NAME")
     frame:SetAttribute("sortOrder", "-")
     frame:SetAttribute("weaponTemplate", "KBFSecureWeaponEnchantTemplate")
-	-- TODO: 4.3 SAH has a bug that messes up buff binding when a consolidate proxy
-	-- and/or weapon enchants are present, don't use them. Set up a standalone enchant window to be managed 
-	-- independently
+    -- TODO: 4.3 SAH has a bug that messes up buff binding when a consolidate proxy
+    -- and/or weapon enchants are present, don't use them. Set up a standalone enchant window to be managed 
+    -- independently
     frame:SetAttribute("includeWeapons", 100)
     frame:Show() -- has to be shown, otherwise the child frames don't show
     return frame
@@ -551,4 +552,3 @@
         self:ShowAnchor()
     end
 end
-