Mercurial > wow > reagentmaker
comparison ReagentMaker.lua @ 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 |
comparison
equal
deleted
inserted
replaced
0:eba26c900e99 | 1:5fc29ed07094 |
---|---|
36 | 36 |
37 | 37 |
38 --------------------------------------------------- | 38 --------------------------------------------------- |
39 -- Initialize | 39 -- Initialize |
40 --------------------------------------------------- | 40 --------------------------------------------------- |
41 local toInitialize = true | |
41 function A:Initialize() | 42 function A:Initialize() |
42 -- This part is done the first time only | 43 -- This part is done the first time only |
43 if not self.MenuFrame then | 44 if toInitialize then |
44 -- Prepare the menu | |
45 self.MenuFrame = CreateFrame("Frame", "ReagentMakerDropDownMenu"); -- Needs a global name | |
46 self.MenuFrame.displayMode = "MENU"; | |
47 self.MenuFrame.initialize = self.FillMenu; | |
48 self.MenuFrame.point = "TOPLEFT"; | |
49 self.MenuFrame.relativePoint = "TOPRIGHT"; | |
50 | 45 |
51 -- Register clics on reagent's buttons | 46 -- Register clics on reagent's buttons |
52 for i=1,7 do | 47 for i=1,7 do |
53 local button = _G["TradeSkillReagent"..i]; | 48 local button = _G["TradeSkillReagent"..i]; |
54 button:HookScript("OnClick", function() self:ToggleMenu(button, i) end); | 49 button:HookScript("OnClick", function() self:ToggleMenu(button, i) end); |
55 --button:HookScript("OnEnter", function() self:Entered(button, i) end) | 50 --button:HookScript("OnEnter", function() self:Entered(button, i) end) |
56 --button:HookScript("OnLeave", function() self:Left(button, i) end) | 51 --button:HookScript("OnLeave", function() self:Left(button, i) end) |
57 end -- for | 52 end -- for |
53 | |
54 toInitialize = nil | |
58 end -- if | 55 end -- if |
59 | 56 |
60 -- Scan availabe recipes | 57 -- Scan availabe recipes |
61 A:ScanSimpleRecipes() | 58 A:ScanSimpleRecipes() |
62 end -- function | 59 end -- function |
113 | 110 |
114 local function SplitStack(owner,split) | 111 local function SplitStack(owner,split) |
115 DoTradeSkill(owner.ReagentMakerIndex,tonumber(split)) | 112 DoTradeSkill(owner.ReagentMakerIndex,tonumber(split)) |
116 end | 113 end |
117 | 114 |
118 function A.craft(self,itemID, spell) | 115 function A.craft(btn,...) |
119 -- self is the menu entry | 116 local index = A.findSkillIndex(btn:GetAttribute(target-item)) |
120 if spell then | |
121 CastSpellByName("Mouture") | |
122 RunSlashCmd(spell) --CastSpellByName(spell) | |
123 --RunSlashCmd("/use "..itemID) --CastSpellByName("/use "..itemID) | |
124 return | |
125 end | |
126 local index = A.findSkillIndex(itemID) | |
127 if index then | 117 if index then |
128 local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index) | 118 local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index) |
129 if IsShiftKeyDown() and numAvailable>1 and not spell then | 119 if IsShiftKeyDown() and numAvailable>1 and not spell then |
130 if not self.SplitStack then | 120 if not btn.SplitStack then |
131 self.SplitStack = SplitStack | 121 btn.SplitStack = SplitStack |
132 end | 122 end |
133 self.ReagentMakerIndex = index | 123 btn.ReagentMakerIndex = index |
134 | 124 |
135 OpenStackSplitFrame(numAvailable, self, "TOPLEFT", "TOPRIGHT") | 125 OpenStackSplitFrame(numAvailable, btn, "TOPLEFT", "TOPRIGHT") |
136 else | 126 else |
137 DoTradeSkill(index,1) | 127 DoTradeSkill(index,1) |
138 end | 128 end |
139 end | 129 end |
140 end -- function | 130 end -- function |
159 -- We want no modifiers | 149 -- We want no modifiers |
160 if IsModifierKeyDown() then return end | 150 if IsModifierKeyDown() then return end |
161 | 151 |
162 local itemID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), index)) | 152 local itemID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), index)) |
163 if itemID and A.data[itemID] then | 153 if itemID and A.data[itemID] then |
164 self.MenuFrame.ReagentMakerItemID = itemID | 154 A.FillMenu(itemID) |
165 ToggleDropDownMenu(1, nil, A.MenuFrame, button,-4,0) | 155 A.menuOpen(button) |
166 end -- if | 156 end -- if |
167 end -- function | 157 end -- function |
168 end -- do | 158 end -- do |
169 | 159 |
170 do | 160 do |
171 -- Lua functions | 161 -- Lua functions |
172 local type = type | 162 local type = type |
173 | 163 |
174 -- Wow functions | 164 -- Wow functions |
175 local GetItemInfo = GetItemInfo | 165 local GetItemInfo = GetItemInfo |
176 local UIDropDownMenu_AddButton = UIDropDownMenu_AddButton | |
177 | 166 |
178 -- persistent vars | 167 -- persistent vars |
179 local Minfo = {notCheckable = true, func = A.craft} | 168 local Minfo = {notCheckable = true, func = A.craft} |
180 local Tinfo = {notCheckable = true, isTitle = true} | |
181 | 169 |
182 -- function to define the menu items | 170 -- function to define the menu items |
183 function A.FillMenu(self, level) | 171 function A.FillMenu(itemID) |
184 -- Title | 172 -- Title |
185 local itemName, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(self.ReagentMakerItemID) | 173 --local itemName, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) |
186 Tinfo.text = "Make "..link.." with:" | 174 --Tinfo.text = "Make "..link.." with:" |
187 UIDropDownMenu_AddButton(Tinfo,level) | 175 |
188 | 176 -- Loop over the available reciepes |
189 -- Loop over the availible reciepes | 177 for spellID,reagents in pairs(A.data[itemID]) do |
190 for spellID,reagents in pairs(A.data[self.ReagentMakerItemID]) do | |
191 --name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) or GetItemInfo("itemName") or GetItemInfo("itemLink") | 178 --name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) or GetItemInfo("itemName") or GetItemInfo("itemLink") |
192 -- Right now, manage only sub-recipes with only one reagent | 179 -- Right now, manage only sub-recipes with only one reagent |
193 if type(reagents[1]) == "number" then | 180 if type(reagents[1]) == "number" then |
194 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagents[1]) | 181 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagents[1]) |
195 | 182 |
196 if link then | 183 if link then |
197 Minfo.text = "|T"..texture..":0|t "..link | 184 local text = reagents[2].."x |T"..texture..":0|t "..link |
198 if #reagents>1 and reagents[2] > 1 then | 185 |
199 Minfo.text = reagents[2].."x "..Minfo.text | 186 if reagents.spell then |
187 -- Special spell | |
188 -- Minfo.func = RunMacroText | |
189 -- Minfo.arg1 = reagents.spell..itemName | |
190 -- Minfo.arg2 = nil | |
191 A.menuAddItem(text,action,itemID) | |
192 else | |
193 -- Standard tradeskill spell | |
194 A.menuAddItem(text,A.craft,itemID) | |
200 end -- if | 195 end -- if |
201 | |
202 --if reagents.spell then | |
203 -- Minfo.func = RunMacroText | |
204 -- Minfo.arg1 = reagents.spell..itemName | |
205 -- Minfo.arg2 = nil | |
206 --else | |
207 Minfo.func = A.craft | |
208 Minfo.arg1 = self.ReagentMakerItemID | |
209 Minfo.arg2 = reagents.spell | |
210 --end -- if | |
211 UIDropDownMenu_AddButton(Minfo,level) | |
212 else | 196 else |
213 A.DEBUG("Erreur, objet inconnu :"..reagents[1]) | 197 A.DEBUG("Erreur, objet inconnu :"..reagents[1]) |
214 end -- if | 198 end -- if |
215 end -- if | 199 end -- if |
216 end -- for | 200 end -- for |