diff KBF.lua @ 45:ca720b4b5435

fix location not being stored, add a framework for doing stuff when OOC
author Chris Mellon <arkanes@gmail.com>
date Sat, 19 Feb 2011 07:23:26 -0600
parents 81cade22f2f9
children 04d0d145a676
line wrap: on
line diff
--- a/KBF.lua	Sun Feb 13 08:55:58 2011 -0600
+++ b/KBF.lua	Sat Feb 19 07:23:26 2011 -0600
@@ -6,6 +6,9 @@
 
 
 function kbf:OnInitialize()
+	-- 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 = {}
    	local defaultSettings = {
 		-- global bar settings
@@ -16,10 +19,11 @@
     self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange")
     self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange")
     self:RegisterChatCommand("kbf", "ToggleAnchor")
+    
+    self.oocQueue = {}
 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
@@ -61,6 +65,18 @@
     
 end
 
+-- enqueues a callable that will be run once in-combat lockdown is past
+-- all callables will be executed in a single run, in the order they were enqueued
+-- 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
+end
+
 function kbf:OnUpdate()
     if self.pollForUnitChange and not InCombatLockdown() then
         if UnitHasVehicleUI("player") then
@@ -75,6 +91,12 @@
         end
         self.pollForUnitChange = nil
     end
+    
+    while #self.oocQueue > 0 do
+		func = table.remove(self.oocQueue)
+		func()
+    end
+    
     local unit = self.secureHeader:GetAttribute("unit")
     local buffCount = 0
     for idx=1,99 do
@@ -86,7 +108,7 @@
         end
         self:UpdateBarExpirationTime(frame)
         -- Don't forget to refresh shown tooltips
-        if ( GameTooltip:IsOwned(frame) ) then
+        if (GameTooltip:IsOwned(frame)) then
             self:OnEnter(frame)
         end
     end
@@ -127,9 +149,7 @@
         -- SAH binds the offhand enchant to the main hand for removal purposes.
         -- fix it up if we're out of combat
         -- TODO: maybe this should only happen if we're dirty
-        if not InCombatLockdown() then
-        	tempEnchant:SetAttribute('target-slot', 17)
-       	end
+        QueueForOOC(function() tempEnchant:SetAttribute('target-slot', 17) end)
     end
     if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
 		self:OnEnter(tempEnchant)
@@ -148,7 +168,7 @@
             self.tempEnchant3:SetScript("OnLeave", function() GameTooltip:Hide() end)
             self.tempEnchant3:EnableMouse(true)
             --TODO: queue up for setting when leaving combat
-            self.tempEnchant3:SetAttribute('target-slot', 18)
+            QueueForOOC(function() self.tempEnchant3:SetAttribute('target-slot', 18) end)
 			-- set up the tooltip
 		end
 		-- TODO: If we're out of combat and theres an OH enchant,