Mercurial > wow > reagentmaker
comparison ReagentMaker.lua @ 0:eba26c900e99
Initial commit, save state before using secure menus
| author | contrebasse |
|---|---|
| date | Mon, 28 Mar 2011 22:32:26 +0200 |
| parents | |
| children | 5fc29ed07094 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:eba26c900e99 |
|---|---|
| 1 local addonName, A = ... | |
| 2 | |
| 3 -- @todo clean the A table | |
| 4 -- @todo check local copy of globals functions | |
| 5 -- @todo add support for sub-recipes (like ink plus milling) | |
| 6 -- @todo show a tooltip | |
| 7 -- @todo show number of craftable items | |
| 8 -- @todo show owned items | |
| 9 -- @todo add support for dez ? | |
| 10 -- @todo add support for cross tradeskill, like mining + forge/ingé | |
| 11 -- @todo icon on reagent's button | |
| 12 | |
| 13 --------------------------------------------------- | |
| 14 -- Variables | |
| 15 --------------------------------------------------- | |
| 16 -- Used by findglobals | |
| 17 -- GLOBALS: _G, CreateFrame, DEFAULT_CHAT_FRAME | |
| 18 | |
| 19 -- Lua functions | |
| 20 | |
| 21 -- Wow functions | |
| 22 | |
| 23 -- constant vars | |
| 24 | |
| 25 --------------------------------------------------- | |
| 26 -- Manage events | |
| 27 --------------------------------------------------- | |
| 28 A.EventsFrame = CreateFrame("Frame") | |
| 29 | |
| 30 A.EventsFrame:SetScript("OnEvent", function(self, event) | |
| 31 if event == "TRADE_SKILL_SHOW" then | |
| 32 A:Initialize() | |
| 33 end -- if | |
| 34 end); -- function | |
| 35 A.EventsFrame:RegisterEvent("TRADE_SKILL_SHOW") | |
| 36 | |
| 37 | |
| 38 --------------------------------------------------- | |
| 39 -- Initialize | |
| 40 --------------------------------------------------- | |
| 41 function A:Initialize() | |
| 42 -- This part is done the first time only | |
| 43 if not self.MenuFrame 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 | |
| 51 -- Register clics on reagent's buttons | |
| 52 for i=1,7 do | |
| 53 local button = _G["TradeSkillReagent"..i]; | |
| 54 button:HookScript("OnClick", function() self:ToggleMenu(button, i) end); | |
| 55 --button:HookScript("OnEnter", function() self:Entered(button, i) end) | |
| 56 --button:HookScript("OnLeave", function() self:Left(button, i) end) | |
| 57 end -- for | |
| 58 end -- if | |
| 59 | |
| 60 -- Scan availabe recipes | |
| 61 A:ScanSimpleRecipes() | |
| 62 end -- function | |
| 63 | |
| 64 | |
| 65 --------------------------------------------------- | |
| 66 -- Craft items | |
| 67 --------------------------------------------------- | |
| 68 do | |
| 69 -- WoW functions | |
| 70 local GetNumTradeSkills = GetNumTradeSkills | |
| 71 local GetTradeSkillInfo = GetTradeSkillInfo | |
| 72 local GetTradeSkillItemLink = GetTradeSkillItemLink | |
| 73 | |
| 74 | |
| 75 function A.findSkillIndex(itemID) | |
| 76 for i = 1,GetNumTradeSkills() do | |
| 77 local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i) | |
| 78 if skillType == "header" then | |
| 79 else | |
| 80 if skillName then | |
| 81 local ID = A.link2ID(GetTradeSkillItemLink(i)) | |
| 82 if ID and ID == itemID then | |
| 83 return i | |
| 84 end -- if | |
| 85 end -- if | |
| 86 end -- if | |
| 87 end -- for | |
| 88 A.DEBUG("Tradeskill not found") | |
| 89 end -- function | |
| 90 end -- do | |
| 91 | |
| 92 | |
| 93 -- http://www.wowwiki.com/RunSlashCmd | |
| 94 local _G = _G | |
| 95 function RunSlashCmd(cmd) | |
| 96 local slash, rest = cmd:match("^(%S+)%s*(.-)$") | |
| 97 for name, func in pairs(SlashCmdList) do | |
| 98 local i, slashCmd = 1 | |
| 99 repeat | |
| 100 slashCmd, i = _G["SLASH_"..name..i], i + 1 | |
| 101 if slashCmd == slash then | |
| 102 A.DEBUG("Spell found !") | |
| 103 return true, func(rest) | |
| 104 end | |
| 105 until not slashCmd | |
| 106 end | |
| 107 A.DEBUG("Spell not found :(") | |
| 108 end | |
| 109 | |
| 110 do | |
| 111 -- WoW functions | |
| 112 local DoTradeSkill = DoTradeSkill | |
| 113 | |
| 114 local function SplitStack(owner,split) | |
| 115 DoTradeSkill(owner.ReagentMakerIndex,tonumber(split)) | |
| 116 end | |
| 117 | |
| 118 function A.craft(self,itemID, spell) | |
| 119 -- self is the menu entry | |
| 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 | |
| 128 local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index) | |
| 129 if IsShiftKeyDown() and numAvailable>1 and not spell then | |
| 130 if not self.SplitStack then | |
| 131 self.SplitStack = SplitStack | |
| 132 end | |
| 133 self.ReagentMakerIndex = index | |
| 134 | |
| 135 OpenStackSplitFrame(numAvailable, self, "TOPLEFT", "TOPRIGHT") | |
| 136 else | |
| 137 DoTradeSkill(index,1) | |
| 138 end | |
| 139 end | |
| 140 end -- function | |
| 141 end -- do | |
| 142 | |
| 143 | |
| 144 --------------------------------------------------- | |
| 145 -- Manage the popup menu | |
| 146 --------------------------------------------------- | |
| 147 do | |
| 148 -- Lua functions | |
| 149 local tonumber = tonumber | |
| 150 | |
| 151 -- WoW functions | |
| 152 local IsModifierKeyDown = IsModifierKeyDown | |
| 153 local GetTradeSkillReagentItemLink = GetTradeSkillReagentItemLink | |
| 154 local GetTradeSkillSelectionIndex = GetTradeSkillSelectionIndex | |
| 155 local ToggleDropDownMenu = ToggleDropDownMenu | |
| 156 | |
| 157 -- Toggles the reagent's menu | |
| 158 function A:ToggleMenu(button, index) | |
| 159 -- We want no modifiers | |
| 160 if IsModifierKeyDown() then return end | |
| 161 | |
| 162 local itemID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), index)) | |
| 163 if itemID and A.data[itemID] then | |
| 164 self.MenuFrame.ReagentMakerItemID = itemID | |
| 165 ToggleDropDownMenu(1, nil, A.MenuFrame, button,-4,0) | |
| 166 end -- if | |
| 167 end -- function | |
| 168 end -- do | |
| 169 | |
| 170 do | |
| 171 -- Lua functions | |
| 172 local type = type | |
| 173 | |
| 174 -- Wow functions | |
| 175 local GetItemInfo = GetItemInfo | |
| 176 local UIDropDownMenu_AddButton = UIDropDownMenu_AddButton | |
| 177 | |
| 178 -- persistent vars | |
| 179 local Minfo = {notCheckable = true, func = A.craft} | |
| 180 local Tinfo = {notCheckable = true, isTitle = true} | |
| 181 | |
| 182 -- function to define the menu items | |
| 183 function A.FillMenu(self, level) | |
| 184 -- Title | |
| 185 local itemName, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(self.ReagentMakerItemID) | |
| 186 Tinfo.text = "Make "..link.." with:" | |
| 187 UIDropDownMenu_AddButton(Tinfo,level) | |
| 188 | |
| 189 -- Loop over the availible reciepes | |
| 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") | |
| 192 -- Right now, manage only sub-recipes with only one reagent | |
| 193 if type(reagents[1]) == "number" then | |
| 194 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagents[1]) | |
| 195 | |
| 196 if link then | |
| 197 Minfo.text = "|T"..texture..":0|t "..link | |
| 198 if #reagents>1 and reagents[2] > 1 then | |
| 199 Minfo.text = reagents[2].."x "..Minfo.text | |
| 200 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 | |
| 213 A.DEBUG("Erreur, objet inconnu :"..reagents[1]) | |
| 214 end -- if | |
| 215 end -- if | |
| 216 end -- for | |
| 217 end -- function | |
| 218 end -- do | |
| 219 | |
| 220 | |
| 221 --------------------------------------------------- | |
| 222 -- Manage the tradeskill window state | |
| 223 --------------------------------------------------- | |
| 224 function A:SaveState() | |
| 225 end | |
| 226 | |
| 227 function A:SetState(state) | |
| 228 end | |
| 229 | |
| 230 function A:ExpandAll() | |
| 231 end |
