Mercurial > wow > reagentmaker
changeset 110:d60d6b4cab0c
Tradeskill in external window should now be functional
author | contrebasse |
---|---|
date | Thu, 02 Jun 2011 18:23:42 +0200 |
parents | b5fd4a61ee64 |
children | af23986010ef |
files | ReagentMaker.lua SecureMenu.lua data.lua utils.lua |
diffstat | 4 files changed, 103 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/ReagentMaker.lua Thu Jun 02 14:12:49 2011 +0200 +++ b/ReagentMaker.lua Thu Jun 02 18:23:42 2011 +0200 @@ -92,6 +92,7 @@ local textureHighlight = btn:CreateTexture() textureHighlight:Hide() textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight") + --textureHighlight:SetTexture("Interface\\BUTTONS\\ButtonHilight-Square") textureHighlight:SetBlendMode("ADD") textureHighlight:SetAllPoints("TradeSkillReagent"..i.."IconTexture") btn.textureHighlight = textureHighlight @@ -140,7 +141,7 @@ -- If only one recipe is known for the reagent, use it if #(A.data[reagentID]) == 1 and not A.data[reagentID][1].macro then - if A.data[reagentID][1].spellName and A.data[reagentID][1].spellName ~= GetTradeSkillLine() then + if A.data[reagentID][1].tradeskillName and A.data[reagentID][1].tradeskillName ~= GetTradeSkillLine() then A.Error(A.L["The recipe to make this reagent is in another tradeskill. Currently ReagentMaker can not manage such a case, sorry."]) return end @@ -227,7 +228,7 @@ for i = 1,numToMake:len() do StackSplitFrame_OnChar(StackSplitFrame,numToMake:gsub(i,i)) end - StackSplitFrame.typing = 0 -- reinit the frame so tha the entered value will be erased on text entry + StackSplitFrame.typing = 0 -- reinit the frame so that the entered value will be erased on text entry else DoTradeSkill(reagentIndex,numToMake) end -- if
--- a/SecureMenu.lua Thu Jun 02 14:12:49 2011 +0200 +++ b/SecureMenu.lua Thu Jun 02 18:23:42 2011 +0200 @@ -4,9 +4,10 @@ local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent) MenuFrame:Hide() MenuFrame:SetSize(192,256) -MenuFrame:SetFrameStrata("DIALOG") +--MenuFrame:SetFrameStrata("DIALOG") MenuFrame:EnableMouse(true) MenuFrame:SetPoint("CENTER") +MenuFrame:SetToplevel(true) -- raised if clicked tinsert(UISpecialFrames,"ReagentMaker_ExternalFrame") -- make it closable with escape local SCAN_DELAY = 0.2 @@ -137,7 +138,7 @@ btn:Hide() btn:SetSize(MENU_ENTRY_WIDTH,MENU_ENTRY_HEIGHT) - btn:SetFrameStrata("DIALOG") + --btn:SetFrameStrata("DIALOG") -- Set its position if #menuEntries>1 then @@ -167,6 +168,7 @@ local textureHighlight = btn:CreateTexture(nil,"BORDER") textureHighlight:Hide() textureHighlight:SetTexture("Interface\\BUTTONS\\CheckButtonHilight") + --textureHighlight:SetTexture("Interface\\BUTTONS\\ButtonHilight-Square") textureHighlight:SetBlendMode("ADD") textureHighlight:SetAllPoints(icon) btn.textureHighlight = textureHighlight @@ -184,6 +186,9 @@ resultNumber:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE") btn.resultNumber = resultNumber + -- Used to choose the number of items to make + btn.SplitStack = A.SplitStack + btn:SetScript("OnEnter", btnEntered) btn:SetScript("OnLeave", btnLeft) @@ -198,15 +203,60 @@ end end +local function CraftFromExternal(btn) + local chooseNumber = IsShiftKeyDown() + local numReagentMakable = A.numRecipeMakable(btn.reagentID,btn.reagentsForOneRecipe) + local reagentIndex = A.findExactSkillIndex(btn.itemID,btn.itemNameString) + + -- to define + local numToMake = 1 + + -- Choose number or craft directly + if chooseNumber then + -- Store info to be able to run the function later + btn.ReagentMaker_reagentIndex = reagentIndex + + -- Open dialog + OpenStackSplitFrame(numReagentMakable, btn, "BOTTOMRIGHT", "TOP") + + -- Fill in the number to make + numToMake = tostring(numToMake) + for i = 1,numToMake:len() do + StackSplitFrame_OnChar(StackSplitFrame,numToMake:gsub(i,i)) + end + StackSplitFrame.typing = 0 -- reinit the frame so that the entered value will be erased on text entry + else + DoTradeSkill(reagentIndex,numToMake) + end -- if +end + -- Update counts and button actions function MenuFrame.updateCounts() local anyMakable for i=1,numActiveEntries do - btn = menuEntries[i] + local btn = menuEntries[i] local itemCount = GetItemCount(btn.reagentID) - local numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1)) - btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1)) + local numMakable + if btn.reagentID then + numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1)) + btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1)) + else + for _,reagent in pairs(btn.reagentsForOneRecipe) do + itemCount = GetItemCount(reagent[1]) + if not itemCount then + numMakable = 0 + break + end + if not numMakable then + numMakable = math.floor(itemCount/reagent[2]) + else + numMakable = math.min(numMakable,math.floor(itemCount/reagent[2])) + end + if numMakable==0 then break end + end + btn.countDetail:SetText(numMakable) + end if numMakable>0 then -- Set action @@ -362,9 +412,9 @@ noSkipped = menuAddItem(reagent.macro,itemID,reagent) and noSkipped else -- Standard tradeskill spell - if not reagent.spellName or reagent.spellName == A.currentTradeSkill then + if not reagent.tradeskillName or reagent.tradeskillName == A.currentTradeSkill then existsValidEntries = true - noSkipped = menuAddItem(A.craft,itemID,reagent) and noSkipped + noSkipped = menuAddItem(CraftFromExternal,itemID,reagent) and noSkipped end end -- if end -- for
--- a/data.lua Thu Jun 02 14:12:49 2011 +0200 +++ b/data.lua Thu Jun 02 18:23:42 2011 +0200 @@ -121,16 +121,12 @@ -- Cache the data if addSpell then local spell = {reagentID,reagentCount,minMade,maxMade} - spell.spellName = tradeskillName + spell.skillName = skillName + spell.tradeskillName = tradeskillName spell.spellLink = recipeLink spell.header = lastHeader tinsert(A.data[itemID],spell) end - - --else -- Zap incomplete recipes, they will be scanned later - --@debug@ - --print("Erreur de scan :",itemID,reagentID,reagentCount,minMade,maxMade,recipeLink) - --@end-debug@ end -- if end -- if end -- for
--- a/utils.lua Thu Jun 02 14:12:49 2011 +0200 +++ b/utils.lua Thu Jun 02 18:23:42 2011 +0200 @@ -42,18 +42,28 @@ local GetNumTradeSkills = GetNumTradeSkills local GetTradeSkillItemLink = GetTradeSkillItemLink + function A.numRecipeMakable(reagentIDIfUnique,reagents) + if reagentIDIfUnique then -- only one reagent + itemCount = GetItemCount(reagentIDIfUnique) + if not itemCount then return end + return math.floor(itemCount/reagents) + else -- many reagents + local m + for _,reagent in pairs(reagents) do + itemCount = GetItemCount(reagent[1]) + if not itemCount then return end + if not m then + m = math.floor(itemCount/reagent[2]) + else + m = math.min(m,math.floor(itemCount/reagent[2])) + end + if m==0 then break end + end + return m + end -- if + end + -- Gives the number of craftable objects - --[[ - function A.numMakable(reagentID) - -- Look for the recipe to make the item - local reagentIndex = A.findSkillIndex(reagentID) - if not reagentIndex then return end - - -- Check how many items we can craft - local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) - return numReagentMakable, reagentIndex - end - --]] function A.numMakable(reagentID) -- No recipe if not A.data[reagentID] then return 0 end @@ -62,46 +72,35 @@ local n = 0 local itemCount for _,recipe in pairs(A.data[reagentID]) do - if recipe[1] then -- only one reagent - itemCount = GetItemCount(recipe[1]) - if not itemCount then return end - n = n + math.floor(itemCount/recipe[2]) - else -- many reagents - local m - for _,reagent in pairs(recipe[2]) do - itemCount = GetItemCount(reagent[1]) - if not itemCount then return end - if not m then - m = math.floor(itemCount/reagent[2]) - else - m = math.min(m,math.floor(itemCount/reagent[2])) - end - if m==0 then break end - end - n = n + m - end -- if + n = n + A.numRecipeMakable(recipe[1],recipe[2]) end -- for return n end -- function -- Find the first tradeskill index of the recipe to make an item function A.findSkillIndex(itemID) + if not itemID then return end for i = 1,GetNumTradeSkills() do - local _, skillType = GetTradeSkillInfo(i) - if skillType == "header" then - else - local ID = A.link2ID(GetTradeSkillItemLink(i)) - if ID and ID == itemID then - return i - end -- if + if select(2,GetTradeSkillInfo(i)) ~= "header" and A.link2ID(GetTradeSkillItemLink(i)) == itemID then + return i + end -- if + end -- for + end -- function + + -- Find the exact tradeskill index of the recipe to make an item + function A.findExactSkillIndex(itemID,recipeName) + if not itemID or not recipeName then return end + for i = 1,GetNumTradeSkills() do + local skillName, skillType = GetTradeSkillInfo(i) + if skillType ~= "header" and skillName==recipeName and A.link2ID(GetTradeSkillItemLink(i)) == itemID then + return i end -- if end -- for end -- function end -- do --- Taken from Datastore_Crafts --- *** Scanning functions *** +-- Bypass filters and collpsed headers do local selectedTradeSkillIndex local stateSaved @@ -211,18 +210,18 @@ --[[ function A.isTradeskillUnique(itemData) - local spellName = itemData[1].spellName + local tradeskillName = itemData[1].tradeskillName -- Check if the item is made by only one recipe. If not, return if #itemData>1 then for _,v in ipairs(itemData) do - if v.spellName ~= spellName then - spellName = nil + if v.tradeskillName ~= tradeskillName then + tradeskillName = nil break end end end - return spellName + return tradeskillName end --]]