changeset 115:5a3fb8fea026

Throttle count display
author contrebasse
date Wed, 15 Jun 2011 00:05:35 +0200
parents c770f969ffa2
children 7ce304c296b0
files ReagentMaker.lua SecureMenu.lua
diffstat 2 files changed, 38 insertions(+), 24 deletions(-) [+]
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)
--- a/SecureMenu.lua	Fri Jun 03 12:24:26 2011 +0200
+++ b/SecureMenu.lua	Wed Jun 15 00:05:35 2011 +0200
@@ -16,28 +16,11 @@
 MenuFrame:SetToplevel(true) -- raised if clicked
 tinsert(UISpecialFrames,"ReagentMaker_ExternalFrame") -- make it closable with escape
 
-local SCAN_DELAY = 0.2
-local t_throttle = SCAN_DELAY
-function MenuFrame.throttleUpdateCounts(self, t_elapsed)
-	t_throttle = t_throttle - t_elapsed
-	if t_throttle<0 then
-		self:SetScript("OnUpdate", nil)
+-- Throttling is made in ReagentMaker.lua
+MenuFrame:SetScript("OnEvent",function() MenuFrame:Hide() end)
+MenuFrame:RegisterEvent("TRADE_SKILL_CLOSE")
+MenuFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
 
-		-- Update counts
-		MenuFrame.updateCounts()
-	end
-end
-MenuFrame:SetScript("OnEvent",function(self,event,...)
-	if event == "BAG_UPDATE" then
-		t_throttle = SCAN_DELAY
-		self:SetScript("OnUpdate", MenuFrame.throttleUpdateCounts)
-	elseif event == "TRADE_SKILL_CLOSE" or event == "PLAYER_REGEN_DISABLED" then
-		MenuFrame:Hide()
-	end
-end)
-MenuFrame:RegisterEvent("TRADE_SKILL_CLOSE")
-MenuFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
-MenuFrame:RegisterEvent("BAG_UPDATE")
 MenuFrame:SetScript("OnEnter",function(self)
 	if self.reagentLink then
 		GameTooltip:SetOwner(self)