diff ReagentMaker.lua @ 115:5a3fb8fea026

Throttle count display
author contrebasse
date Wed, 15 Jun 2011 00:05:35 +0200
parents c79ab5443ee5
children 7ce304c296b0
line wrap: on
line diff
--- a/ReagentMaker.lua	Fri Jun 03 12:24:26 2011 +0200
+++ b/ReagentMaker.lua	Wed Jun 15 00:05:35 2011 +0200
@@ -55,10 +55,11 @@
 		end
 
 		-- Show makables reagents
-		A.updateCounts(GetTradeSkillSelectionIndex())
+		A.updateCount_throttle()
 	end
 end
 A.EventsFrame:SetScript("OnEvent", function(self, event)
+	--print("Throttle Scan :",event)
 	if event == "TRADE_SKILL_UPDATE" then
 		t_throttle = SCAN_DELAY
 		self:SetScript("OnUpdate", throttleScan)
@@ -165,7 +166,10 @@
 end -- function
 
 -- Show counts on buttons
-function A.updateCounts(recipeIndex)
+local CountThrottleFrame = CreateFrame("Frame")
+local COUNT_DELAY = 0.1
+local t_throttleCount = SCAN_DELAY
+function UpdateCounts(recipeIndex)
 	-- Needs an argument
 	if not recipeIndex then return end
 
@@ -210,4 +214,31 @@
 		end -- if
 	end -- for
 end -- function
-hooksecurefunc("SelectTradeSkill",A.updateCounts)
+local function throttleCount(self, t_elapsed)
+	t_throttle = t_throttle - t_elapsed
+	if t_throttle<0 then
+		self:SetScript("OnUpdate", nil)
+
+		-- Show makables reagents
+		UpdateCounts(GetTradeSkillSelectionIndex())
+	end
+end
+function A.updateCount_throttle(self,event)
+	if not TradeSkillFrame or not TradeSkillFrame:IsVisible() or event=="TRADE_SKILL_CLOSE" then
+		CountThrottleFrame:UnregisterEvent("BAG_UPDATE")
+		t_throttleCount = 0
+		CountThrottleFrame:SetScript("OnUpdate", nil)
+		return
+	else
+		CountThrottleFrame:RegisterEvent("BAG_UPDATE")
+	end
+	t_throttleCount = SCAN_DELAY
+	CountThrottleFrame:SetScript("OnUpdate", throttleCount)
+	
+	A.MenuFrame.updateCounts()
+end
+CountThrottleFrame:SetScript("OnEvent", A.updateCount_throttle)
+CountThrottleFrame:RegisterEvent("TRADE_SKILL_SHOW")
+CountThrottleFrame:RegisterEvent("TRADE_SKILL_UPDATE")
+CountThrottleFrame:RegisterEvent("TRADE_SKILL_CLOSE")
+hooksecurefunc("SelectTradeSkill",A.updateCount_throttle)