changeset 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 25b9f98f9bba
files ReagentMaker.lua SecureMenu.lua data.lua
diffstat 3 files changed, 90 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/ReagentMaker.lua	Fri Apr 08 19:58:08 2011 +0200
+++ b/ReagentMaker.lua	Sun Apr 10 19:26:33 2011 +0200
@@ -42,6 +42,9 @@
 
 		-- Scan availabe recipes
 		A:ScanSimpleRecipes()
+		
+		-- Show makables reagents
+		A.updateCounts(GetTradeSkillSelectionIndex())
 	end
 end
 A.EventsFrame:SetScript("OnEvent", function(self, event)
@@ -64,8 +67,8 @@
 
 	-- Register clics on reagent's buttons
 	for i=1,7 do
-		local btn = _G["TradeSkillReagent"..i];
-		btn:HookScript("OnDoubleClick", A.ProcessReagent);
+		local btn = _G["TradeSkillReagent"..i]
+		btn:HookScript("OnDoubleClick", A.ProcessReagent)
 		btn:HookScript("OnEnter", A.btnEntered)
 		btn:HookScript("OnLeave", A.btnLeft)
 		btn.SplitStack = A.SplitStack
@@ -74,8 +77,6 @@
 		textureHighlight:Hide()
 		textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight")
 		textureHighlight:SetBlendMode("ADD")
-		--textureHighlight:SetPoint("TOPLEFT")
-		--textureHighlight:SetSize(btn:GetHeight(),btn:GetHeight())
 		textureHighlight:SetAllPoints("TradeSkillReagent"..i.."IconTexture")
 		btn.textureHighlight = textureHighlight
 
@@ -196,17 +197,6 @@
 
 	btn.textureHighlight:Show()
 
-	if #(A.data[reagentID]) == 1 and not A.data[reagentID].spell then
-		local numMakable = A.numMakable(reagentID)
-		btn.label:SetText(numMakable)
-		if numMakable==0 then
-			btn.label:SetTextColor(1, 0, 0, 1)
-		else
-			btn.label:SetTextColor(0, 5, 0, 1)
-		end
-		btn.label:Show()
-	end
-
 	-- Tooltips
 	local link
 	if A.data[reagentID].spell then
@@ -219,25 +209,51 @@
 		A.tooltipRecipe:SetHyperlink(link)
 		A.tooltipRecipe:Show()
 		A.tooltipRecipe:ClearAllPoints()
-		--A.tooltipRecipe:SetPoint("TOPLEFT",btn,"TOPRIGHT")
 		A.tooltipRecipe:SetPoint("BOTTOMLEFT",GameTooltip,"BOTTOMRIGHT")
-
-		--[[
-		if #(A.data[reagentID]) == 1 then
-			A.tooltipReagent:SetOwner(A.tooltipRecipe)
-			local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(A.data[reagentID][1][1])
-			A.tooltipReagent:SetHyperlink(link)
-			A.tooltipReagent:Show()
-			A.tooltipReagent:ClearAllPoints()
-			A.tooltipReagent:SetPoint("BOTTOMLEFT",A.tooltipRecipe,"BOTTOMRIGHT")
-		end
-		--]]
 	end
 end
 
 function A.btnLeft(btn)
 	btn.textureHighlight:Hide()
-	btn.label:Hide()
 	A.tooltipRecipe:Hide()
 	--A.tooltipReagent:Hide()
-end
+end -- function
+
+function A.updateCounts(recipeIndex)
+	-- Needs an argument
+	if not recipeIndex then return end
+
+	-- Do not manage guild tradeskill
+	if IsTradeSkillGuild() or IsTradeSkillLinked() then
+		for reagentRecipeIndex = 1,GetTradeSkillNumReagents(recipeIndex) do
+			_G["TradeSkillReagent"..reagentRecipeIndex].label:Hide()
+		end
+		return
+	end
+
+	-- Count makable items and show it
+	for reagentRecipeIndex = 1,GetTradeSkillNumReagents(recipeIndex) do
+		-- ID of the reagent we want to craft
+		local reagentLink = GetTradeSkillReagentItemLink(recipeIndex, reagentRecipeIndex)
+		local reagentID = A.link2ID(reagentLink)
+
+		local label = _G["TradeSkillReagent"..reagentRecipeIndex].label
+		if not label then return end
+
+		-- Continue only if the reagent is known
+		if not reagentID or not A.data[reagentID] or #(A.data[reagentID]) ~= 1 or A.data[reagentID].spell then
+			label:Hide()
+		else
+			-- Count and show
+			local numMakable = A.numMakable(reagentID)
+			label:SetText(numMakable)
+			if numMakable==0 then
+				label:SetTextColor(1, 0, 0, 1)
+			else
+				label:SetTextColor(0, 5, 0, 1)
+			end -- if
+			label:Show()
+		end -- if
+	end -- for
+end -- function
+hooksecurefunc("SelectTradeSkill",A.updateCounts)
--- 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
--- a/data.lua	Fri Apr 08 19:58:08 2011 +0200
+++ b/data.lua	Sun Apr 10 19:26:33 2011 +0200
@@ -13,7 +13,7 @@
 		{2447,5,2,3}, -- Peacebloom
 		{ 765,5,2,3},  -- Silverleaf
 		{2449,5,2,4}}, -- Earthroot
-	[39224] = { -- Dusky Pigment
+	[39334] = { -- Dusky Pigment
 		spell = macroMill,
 		spellID = MillID,
 		{ 785,5,2,3}, -- Mageroyal