changeset 77:cd36938d2a48

Add a button to put enchants directly on a scroll
author contrebasse
date Sat, 14 May 2011 23:54:02 +0200
parents 9d487333bf10
children 31009ddc7d31
files EnchantOnScroll.lua ReagentMaker.lua ReagentMaker.toc
diffstat 3 files changed, 75 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EnchantOnScroll.lua	Sat May 14 23:54:02 2011 +0200
@@ -0,0 +1,69 @@
+local addonName, A = ...
+
+local SCROLL_ID = 38682
+local ENCHANTING_ID = 7411
+local btn
+
+local EventsFrame = CreateFrame("Frame",nil,TradeSkillFrame) -- It will be hidden with the TradeSkillFrame
+
+local function CheckButtonAvailable(arg1)
+	if not btn then return end
+
+	-- Do not manage guild tradeskill
+	-- Check that we're still with the enchanting tradeskill
+	if IsTradeSkillGuild() or IsTradeSkillLinked() or GetTradeSkillLine() ~= GetSpellInfo(ENCHANTING_ID) then
+		btn:Hide()
+		return
+	end
+
+	-- Check that the selected recipe can be crafted, and the crafted thing is an enchant
+	local index = GetTradeSkillSelectionIndex()
+	if not index then
+		btn:Disable()
+		btn:Show()
+		return
+	end
+	local _, _, numAvailable, _, serviceType = GetTradeSkillInfo(index)
+
+	-- serviceType is localised, but nil if an item is created
+	if not serviceType then
+		btn:Hide()
+		return
+	end
+	if numAvailable==0 or not serviceType then
+		btn:Disable()
+		btn:Show()
+		return
+	end
+
+	-- Check that there's scrolls in the bags
+	local itemCount = GetItemCount(SCROLL_ID)
+	if not itemCount or itemCount==0 then
+		btn:Disable()
+		btn:Show()
+		return
+	end
+	
+	-- It passed the tests
+	btn:Enable()
+	btn:Show()
+end
+EventsFrame:SetScript("OnEvent",CheckButtonAvailable)
+EventsFrame:RegisterEvent("BAG_UPDATE")
+hooksecurefunc("SelectTradeSkill",CheckButtonAvailable)
+
+function A.LoadEnchantOnScroll()
+	btn = CreateFrame("Button", nil, TradeSkillFrame, "UIPanelButtonTemplate")
+	btn:SetSize(168,22)
+	btn:SetPoint("TOPRIGHT",TradeSkillCreateButton,"TOPLEFT",0,0)
+	btn:SetText(A.L["Enchant on a scroll"])
+	btn:Show()
+	
+	btn:SetScript("OnClick",function()
+		-- from http://wowprogramming.com/utils/xmlbrowser/live/AddOns/Blizzard_TradeSkillUI/Blizzard_TradeSkillUI.xml
+		DoTradeSkill(TradeSkillFrame.selectedSkill,1)
+		
+		-- From GnomeWorks/ScrollMaking.lua
+		UseItemByName(SCROLL_ID)
+	end)
+end
--- a/ReagentMaker.lua	Sat May 14 21:30:56 2011 +0200
+++ b/ReagentMaker.lua	Sat May 14 23:54:02 2011 +0200
@@ -96,9 +96,13 @@
 		btn.label = label
 	end -- for
 
+	-- Secondary Tooltip
 	A.tooltipRecipe = CreateFrame("GameTooltip", "ReagentMaker_tooltipRecipe",UIParent, "GameTooltipTemplate")
 	A.tooltipRecipe:SetFrameStrata("TOOLTIP")
 	A.tooltipRecipe:Hide()
+	
+	-- Button for enchanting directy on a scroll
+	A.LoadEnchantOnScroll()
 end -- function
 
 -- Function run after selecting a item in the tradeskill window
--- a/ReagentMaker.toc	Sat May 14 21:30:56 2011 +0200
+++ b/ReagentMaker.toc	Sat May 14 23:54:02 2011 +0200
@@ -13,3 +13,5 @@
 data.lua
 SecureMenu.lua
 ReagentMaker.lua
+
+EnchantOnScroll.lua