changeset 1:5fc29ed07094

First atempt at using secure menus, it doesn't open yet...
author contrebasse
date Mon, 28 Mar 2011 22:59:20 +0200
parents eba26c900e99
children 04c5b817eead
files ReagentMaker.lua ReagentMaker.toc SecureMenu.lua
diffstat 3 files changed, 45 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/ReagentMaker.lua	Mon Mar 28 22:32:26 2011 +0200
+++ b/ReagentMaker.lua	Mon Mar 28 22:59:20 2011 +0200
@@ -38,15 +38,10 @@
 ---------------------------------------------------
 -- Initialize
 ---------------------------------------------------
+local toInitialize = true
 function A:Initialize()
 	-- This part is done the first time only
-	if not self.MenuFrame then
-	-- Prepare the menu
-		self.MenuFrame = CreateFrame("Frame", "ReagentMakerDropDownMenu"); -- Needs a global name
-		self.MenuFrame.displayMode = "MENU";
-		self.MenuFrame.initialize = self.FillMenu;
-		self.MenuFrame.point = "TOPLEFT";
-		self.MenuFrame.relativePoint = "TOPRIGHT";
+	if toInitialize then
 
 		-- Register clics on reagent's buttons
 		for i=1,7 do
@@ -55,6 +50,8 @@
 			--button:HookScript("OnEnter", function() self:Entered(button, i) end)
 			--button:HookScript("OnLeave", function() self:Left(button, i) end)
 		end -- for
+
+		toInitialize = nil
 	end -- if
 
 	-- Scan availabe recipes
@@ -115,24 +112,17 @@
 		DoTradeSkill(owner.ReagentMakerIndex,tonumber(split))
 	end
 
-	function A.craft(self,itemID, spell)
-		-- self is the menu entry
-		if spell then
-			CastSpellByName("Mouture")
-			RunSlashCmd(spell) --CastSpellByName(spell)
-			--RunSlashCmd("/use "..itemID) --CastSpellByName("/use "..itemID)
-			return
-		end
-		local index = A.findSkillIndex(itemID)
+	function A.craft(btn,...)
+		local index = A.findSkillIndex(btn:GetAttribute(target-item))
 		if index then
 			local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index)
 			if IsShiftKeyDown() and numAvailable>1 and not spell then
-				if not self.SplitStack then
-					self.SplitStack = SplitStack
+				if not btn.SplitStack then
+					btn.SplitStack = SplitStack
 				end
-				self.ReagentMakerIndex = index
+				btn.ReagentMakerIndex = index
 
-				OpenStackSplitFrame(numAvailable, self, "TOPLEFT", "TOPRIGHT")
+				OpenStackSplitFrame(numAvailable, btn, "TOPLEFT", "TOPRIGHT")
 			else
 				DoTradeSkill(index,1)
 			end
@@ -161,8 +151,8 @@
 
 		local itemID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), index))
 		if itemID and A.data[itemID] then
-			self.MenuFrame.ReagentMakerItemID = itemID
-			ToggleDropDownMenu(1, nil, A.MenuFrame, button,-4,0)
+			A.FillMenu(itemID)
+			A.menuOpen(button)
 		end -- if
 	end -- function
 end -- do
@@ -173,42 +163,36 @@
 
 	-- Wow functions
 	local GetItemInfo = GetItemInfo
-	local UIDropDownMenu_AddButton = UIDropDownMenu_AddButton
 
 	-- persistent vars
 	local Minfo = {notCheckable = true, func = A.craft}
-	local Tinfo = {notCheckable = true, isTitle = true}
 
 	-- function to define the menu items
-	function A.FillMenu(self, level)
+	function A.FillMenu(itemID)
 		-- Title
-		local itemName, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(self.ReagentMakerItemID)
-		Tinfo.text = "Make "..link.." with:"
-		UIDropDownMenu_AddButton(Tinfo,level)
+		--local itemName, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID)
+		--Tinfo.text = "Make "..link.." with:"
 
-		-- Loop over the availible reciepes
-		for spellID,reagents in pairs(A.data[self.ReagentMakerItemID]) do
+		-- Loop over the available reciepes
+		for spellID,reagents in pairs(A.data[itemID]) do
 			--name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) or GetItemInfo("itemName") or GetItemInfo("itemLink")
 			-- Right now, manage only sub-recipes with only one reagent
 			if type(reagents[1]) == "number" then
 				local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagents[1])
 
 				if link then
-					Minfo.text = "|T"..texture..":0|t "..link
-					if #reagents>1 and reagents[2] > 1 then
-						Minfo.text = reagents[2].."x "..Minfo.text
+					local text = reagents[2].."x |T"..texture..":0|t "..link
+
+					if reagents.spell then
+						-- Special spell
+						--	Minfo.func = RunMacroText
+						--	Minfo.arg1 = reagents.spell..itemName
+						--	Minfo.arg2 = nil
+						A.menuAddItem(text,action,itemID)
+					else
+						-- Standard tradeskill spell
+						A.menuAddItem(text,A.craft,itemID)
 					end -- if
-
-					--if reagents.spell then
-					--	Minfo.func = RunMacroText
-					--	Minfo.arg1 = reagents.spell..itemName
-					--	Minfo.arg2 = nil
-					--else
-						Minfo.func = A.craft
-						Minfo.arg1 = self.ReagentMakerItemID
-						Minfo.arg2 = reagents.spell
-					--end -- if
-					UIDropDownMenu_AddButton(Minfo,level)
 				else
 					A.DEBUG("Erreur, objet inconnu :"..reagents[1])
 				end -- if
--- a/ReagentMaker.toc	Mon Mar 28 22:32:26 2011 +0200
+++ b/ReagentMaker.toc	Mon Mar 28 22:59:20 2011 +0200
@@ -6,4 +6,5 @@
 
 utils.lua
 data.lua
+SecureMenu.lua
 ReagentMaker.lua
--- a/SecureMenu.lua	Mon Mar 28 22:32:26 2011 +0200
+++ b/SecureMenu.lua	Mon Mar 28 22:59:20 2011 +0200
@@ -16,13 +16,21 @@
 		bottom = 11
 	}
 })
+MenuFrame:SetWidth(70)
 local numActiveEntries = 0
 local menuEntries = {}
 
-function A.menuOpen()
-	if not InCombatLockDown() and numActiveEntries>0 then
+function A.menuOpen(parent)
+	A.DEBUG("menuOpen")
+	--if not InCombatLockDown() and numActiveEntries>0 then
+		MenuFrame:ClearAllPoints()
+		MenuFrame:SetPoint("TOPLEFT",parent,"TOPRIGHT",0,0)
+
+		MenuFrame:SetSize(50,50)
+		MenuFrame:SetParent(UIParent)
+
 		MenuFrame:Show()
-	end
+	--end
 end
 function A.menuClose()
 	MenuFrame:Hide()
@@ -34,6 +42,7 @@
 end
 
 function A.menuAddItem(text,action,itemID)
+	A.DEBUG("menuAddItem "..text)
 	local btn
 	-- Create a button only if necessary
 	if numActiveEntries >= #menuEntries then
@@ -41,6 +50,7 @@
 		table.insert(menuEntries,btn)
 
 		btn:SetHeight(12)
+		btn:SetWidth(70)
 
 		-- Set its position
 		if #menuEntries==1 then
@@ -60,7 +70,7 @@
 		btn:SetScript("OnClick",action)
 		btn:SetAttribute("type", nil)
 		btn:SetAttribute("spell", nil)
-		btn:SetAttribute("target-item",nil)
+		btn:SetAttribute("target-item",itemID)
 	elseif type(action)=="string" then
 		btn:SetScript("OnClick",nil)
 		btn:SetAttribute("type", "spell")
@@ -69,7 +79,8 @@
 	end -- if
 
 	-- Reposition MenuFrame
-	MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0)
+	--MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0)
+	MenuFrame:SetHeight((numActiveEntries+1)*12)
 
 	-- Increase she entry number
 	numActiveEntries = numActiveEntries + 1