diff SecureMenu.lua @ 20:4ea38bae4174

Lots of display arrangements (tooltips and counts) Corrected an id in data
author contrebasse
date Sun, 10 Apr 2011 19:26:33 +0200
parents f7b23db7bcc6
children 15123d11fc64
line wrap: on
line diff
--- a/SecureMenu.lua	Fri Apr 08 19:58:08 2011 +0200
+++ b/SecureMenu.lua	Sun Apr 10 19:26:33 2011 +0200
@@ -9,16 +9,40 @@
 MenuFrame:SetPoint("CENTER")
 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)
+
+		-- Update counts
+		MenuFrame.updateCounts()
+	end
+end
 MenuFrame:SetScript("OnEvent",function(self,event,...)
-	if event == "TRADE_SKILL_UPDATE" then
-		MenuFrame.updateCounts()
+	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("TRADE_SKILL_UPDATE")
+MenuFrame:RegisterEvent("BAG_UPDATE")
+MenuFrame:SetScript("OnEnter",function(self)
+	if self.reagentLink then
+		GameTooltip:SetOwner(self)
+		GameTooltip:SetHyperlink(self.reagentLink)
+		GameTooltip:Show()
+		GameTooltip:ClearAllPoints()
+		GameTooltip:SetPoint("TOPRIGHT",self,"TOPLEFT",10,0)
+	end
+end)
+MenuFrame:SetScript("OnLeave",function()
+	GameTooltip:Hide()
+end)
 A.MenuFrame = MenuFrame
 
 -- Background adaptable vertically
@@ -62,30 +86,23 @@
 
 -- Button hovering
 local function btnEntered(btn)
-	--[[
-	-- Index of the reagent in the recipe, taken from the button name
-	local reagentRecipeIndex = A.buttonNumber(btn)
-
-	-- ID of the reagent we want to craft
-	local reagentID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), reagentRecipeIndex))
-
-	-- Continue only if the reagent is known
-	if not reagentID or not A.data[reagentID] then return end
-	--]]
-
-	if btn.numMakable>0 then
+	if btn.numMakable and btn.numMakable>0 then
 		btn.textureHighlight:Show()
 	end
 
-	GameTooltip:SetOwner(btn,"ANCHOR_TOPLEFT")
+	GameTooltip:SetOwner(btn,"ANCHOR_LEFT")
 	GameTooltip:SetHyperlink(btn.reagentLink)
 	GameTooltip:Show()
-	local link, tradeLink = GetSpellLink(btn.spellID)
-	A.tooltipRecipe:SetOwner(GameTooltip)
-	A.tooltipRecipe:SetHyperlink(link)
-	A.tooltipRecipe:Show()
-	A.tooltipRecipe:ClearAllPoints()
-	A.tooltipRecipe:SetPoint("BOTTOMLEFT",GameTooltip,"BOTTOMRIGHT")
+	if btn.spellID then
+		local link = GetSpellLink(btn.spellID)
+		if link then
+			A.tooltipRecipe:SetOwner(GameTooltip)
+			A.tooltipRecipe:SetHyperlink(link)
+			A.tooltipRecipe:Show()
+			A.tooltipRecipe:ClearAllPoints()
+			A.tooltipRecipe:SetPoint("TOPRIGHT",GameTooltip,"BOTTOMRIGHT")
+		end
+	end
 end
 local function btnLeft(btn)
 	btn.textureHighlight:Hide()
@@ -145,13 +162,12 @@
 	resultNumber:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
 	btn.resultNumber = resultNumber
 
-	btn:HookScript("OnEnter", btnEntered)
-	btn:HookScript("OnLeave", btnLeft)
+	btn:SetScript("OnEnter", btnEntered)
+	btn:SetScript("OnLeave", btnLeft)
 
 	return btn
 end
 
-
 local function menuCraftItem()
 	action(itemID,reagentIndex,IsShiftKeyDown())
 end
@@ -272,6 +288,9 @@
 	local color = ITEM_QUALITY_COLORS[quality]
 	TitleText:SetTextColor(color.r, color.g, color.b)
 
+	-- Save vars to show the tooltip later
+	MenuFrame.reagentLink = link
+	
 	-- Loop over the available recipes
 	for _,reagent in ipairs(A.data[itemID]) do
 			if A.data[itemID].spell then