comparison SecureMenu.lua @ 111:af23986010ef v1.1beta0

Rewrote the main part to clarify things, should have removed some hidden nasty bugs.
author contrebasse
date Thu, 02 Jun 2011 23:07:23 +0200
parents d60d6b4cab0c
children 5a3fb8fea026
comparison
equal deleted inserted replaced
110:d60d6b4cab0c 111:af23986010ef
1 local addonName, A = ... 1 local addonName, A = ...
2
3 -- Lua functions
4 local ipairs = ipairs
5 local type = type
6
7 -- Wow variables
2 8
3 -- Create the menu frame 9 -- Create the menu frame
4 local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent) 10 local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent)
5 MenuFrame:Hide() 11 MenuFrame:Hide()
6 MenuFrame:SetSize(192,256) 12 MenuFrame:SetSize(192,256)
54 end) 60 end)
55 61
56 -- Hide frame when selecting a recipe which doesn't need this reagent 62 -- Hide frame when selecting a recipe which doesn't need this reagent
57 hooksecurefunc("SelectTradeSkill",function() 63 hooksecurefunc("SelectTradeSkill",function()
58 local selectedIndex = GetTradeSkillSelectionIndex() 64 local selectedIndex = GetTradeSkillSelectionIndex()
59 for reagentRecipeIndex = 1,GetTradeSkillNumReagents(selectedIndex) do 65 for reagentIndexInRecipe = 1,GetTradeSkillNumReagents(selectedIndex) do
60 local reagentID = A.link2ID(GetTradeSkillReagentItemLink(selectedIndex, reagentRecipeIndex)) 66 local reagentID = A.link2ID(GetTradeSkillReagentItemLink(selectedIndex, reagentIndexInRecipe))
61 if reagentID == MenuFrame.itemID or (MenuFrame.superItemID and reagentID == MenuFrame.superItemID) then 67 if reagentID == MenuFrame.itemID or (MenuFrame.superItemID and reagentID == MenuFrame.superItemID) then
62 return 68 return
63 end 69 end
64 end 70 end
65 MenuFrame:Hide() 71 MenuFrame:Hide()
202 A.Error(A.L["You do not have enough [%s] to craft [%s]"]:format(btn.itemNameString,TitleText:GetText())) 208 A.Error(A.L["You do not have enough [%s] to craft [%s]"]:format(btn.itemNameString,TitleText:GetText()))
203 end 209 end
204 end 210 end
205 211
206 local function CraftFromExternal(btn) 212 local function CraftFromExternal(btn)
207 local chooseNumber = IsShiftKeyDown() 213 local chooseNumberToCraft = IsShiftKeyDown()
208 local numReagentMakable = A.numRecipeMakable(btn.reagentID,btn.reagentsForOneRecipe) 214
209 local reagentIndex = A.findExactSkillIndex(btn.itemID,btn.itemNameString) 215 A.CraftItemWithRecipe( GetTradeSkillSelectionIndex(),
210 216 btn.itemID,
211 -- to define 217 btn.reagent,
212 local numToMake = 1 218 MenuFrame.reagentIndexInRecipe,
213 219 IsShiftKeyDown(),
214 -- Choose number or craft directly 220 btn)
215 if chooseNumber then
216 -- Store info to be able to run the function later
217 btn.ReagentMaker_reagentIndex = reagentIndex
218
219 -- Open dialog
220 OpenStackSplitFrame(numReagentMakable, btn, "BOTTOMRIGHT", "TOP")
221
222 -- Fill in the number to make
223 numToMake = tostring(numToMake)
224 for i = 1,numToMake:len() do
225 StackSplitFrame_OnChar(StackSplitFrame,numToMake:gsub(i,i))
226 end
227 StackSplitFrame.typing = 0 -- reinit the frame so that the entered value will be erased on text entry
228 else
229 DoTradeSkill(reagentIndex,numToMake)
230 end -- if
231 end 221 end
232 222
233 -- Update counts and button actions 223 -- Update counts and button actions
234 function MenuFrame.updateCounts() 224 function MenuFrame.updateCounts()
235 local anyMakable 225 local anyMakable
344 end 334 end
345 end 335 end
346 336
347 -- Save params 337 -- Save params
348 btn.itemID = itemID 338 btn.itemID = itemID
339 btn.reagent = reagent
349 btn.reagentID = reagent[1] 340 btn.reagentID = reagent[1]
350 btn.reagentLink = link 341 btn.reagentLink = link
351 btn.reagentsForOneRecipe = reagent[2] 342 btn.reagentsForOneRecipe = reagent[2]
352 btn.spellLink = reagent.spellLink 343 btn.spellLink = reagent.spellLink
353 btn.action = action 344 btn.action = action
366 local function reopen() 357 local function reopen()
367 -- Release OnUpdate frame (could conflict with BAG_UPDATE) 358 -- Release OnUpdate frame (could conflict with BAG_UPDATE)
368 MenuFrame:SetScript("OnUpdate",nil) 359 MenuFrame:SetScript("OnUpdate",nil)
369 360
370 -- reopen 361 -- reopen
371 A.externalCraftWindow(MenuFrame.itemID,MenuFrame.superItemID) 362 A.externalCraftWindow(MenuFrame.itemID,MenuFrame.reagentIndexInRecipe,MenuFrame.superItemID)
372 end 363 end
373 364
374 -- Fill the window and open it 365 -- Fill the window and open it
375 function A.externalCraftWindow(itemID,superItemID) 366 function A.externalCraftWindow(itemID,reagentIndexInRecipe,superItemID)
376 -- Do not open during combat 367 -- Do not open during combat
377 if InCombatLockdown() then 368 if InCombatLockdown() then
378 A.Error(SPELL_FAILED_AFFECTING_COMBAT) 369 A.Error(SPELL_FAILED_AFFECTING_COMBAT)
379 return 370 return
380 end 371 end
398 389
399 -- Save vars to show the tooltip later 390 -- Save vars to show the tooltip later
400 MenuFrame.reagentLink = link 391 MenuFrame.reagentLink = link
401 MenuFrame.spellLink = A.isRecipeUnique(A.data[itemID]) and A.data[itemID][1].spellLink 392 MenuFrame.spellLink = A.isRecipeUnique(A.data[itemID]) and A.data[itemID][1].spellLink
402 MenuFrame.itemID = itemID 393 MenuFrame.itemID = itemID
394 MenuFrame.reagentIndexInRecipe = reagentIndexInRecipe
403 MenuFrame.superItemID = superItemID -- optional, will be nil if not set 395 MenuFrame.superItemID = superItemID -- optional, will be nil if not set
404 396
405 -- Loop over the available recipes 397 -- Loop over the available recipes
406 local noSkipped = true -- check if we have to reload the external frame to get all the data 398 local noSkipped = true -- check if we have to reload the external frame to get all the data
407 local existsValidEntries -- check if the menu contains at least one item (cross-tradeskill problem) 399 local existsValidEntries -- check if the menu contains at least one item (cross-tradeskill problem)