Mercurial > wow > reagentmaker
diff utils.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 | 7ce304c296b0 |
line wrap: on
line diff
--- a/utils.lua Thu Jun 02 18:23:42 2011 +0200 +++ b/utils.lua Thu Jun 02 23:07:23 2011 +0200 @@ -1,17 +1,21 @@ local addonName, A = ... +-- GLOBALS: UIErrorsFrame, UIErrorsFrame_OnEvent + -- Lua functions local tonumber = tonumber local select = select local sfind = string.find +local min = math.min +local floor = math.floor +local pairs = pairs +local ipairs = ipairs +local wipe = wipe +local tinsert = tinsert +local tremove = tremove -- Wow functions - --- DEBUG Print -function A.DEBUG(msg) - -- GLOBALS: DEFAULT_CHAT_FRAME - DEFAULT_CHAT_FRAME:AddMessage(msg or "nil",1,0,0) -end -- function +local GetItemCount = GetItemCount -- Messages to the user function A.Warn(msg) @@ -41,21 +45,23 @@ local GetTradeSkillInfo = GetTradeSkillInfo local GetNumTradeSkills = GetNumTradeSkills local GetTradeSkillItemLink = GetTradeSkillItemLink + local GetTradeSkillRecipeLink = GetTradeSkillRecipeLink function A.numRecipeMakable(reagentIDIfUnique,reagents) + local itemCount if reagentIDIfUnique then -- only one reagent itemCount = GetItemCount(reagentIDIfUnique) if not itemCount then return end - return math.floor(itemCount/reagents) + return 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]) + m = floor(itemCount/reagent[2]) else - m = math.min(m,math.floor(itemCount/reagent[2])) + m = min(m,floor(itemCount/reagent[2])) end if m==0 then break end end @@ -63,7 +69,7 @@ end -- if end - -- Gives the number of craftable objects + -- Gives the total number of craftable objects function A.numMakable(reagentID) -- No recipe if not A.data[reagentID] then return 0 end @@ -88,11 +94,10 @@ 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 + function A.findExactSkillIndex(itemID,recipeLink) + if not itemID or not recipeLink 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 + if select(2,GetTradeSkillInfo(i)) ~= "header" and GetTradeSkillRecipeLink(i)==recipeLink and A.link2ID(GetTradeSkillItemLink(i)) == itemID then return i end -- if end -- for @@ -119,6 +124,10 @@ function A.SaveActiveFilters(headerName) A.blockScan = true + -- Save position + filtersState.positionOffset = FauxScrollFrame_GetOffset(TradeSkillListScrollFrame) + filtersState.positionValue = TradeSkillListScrollFrameScrollBar:GetValue() + -- Save filters filtersState.text = GetTradeSkillItemNameFilter() filtersState.minLevel, filtersState.maxLevel = GetTradeSkillItemLevelFilter() @@ -143,9 +152,9 @@ if (skillType == "header") and skillName==headerName then if not isExpanded then ExpandTradeSkillSubClass(i) - table.insert(headersState,true) + tinsert(headersState,true) else - table.insert(headersState,false) + tinsert(headersState,false) end end end @@ -164,7 +173,7 @@ -- restore headers for i = GetNumTradeSkills(), 1, -1 do local skillName, skillType = GetTradeSkillInfo(i) - if (skillType == "header") and skillName==headersState.headerName and table.remove(headersState,1) then + if (skillType == "header") and skillName==headersState.headerName and tremove(headersState,1) then CollapseTradeSkillSubClass(i) end end @@ -179,6 +188,10 @@ TradeSkillFrame.filterTbl.slotValue = filtersState.slotValue ApplyFilters() + -- Re set position + FauxScrollFrame_SetOffset(TradeSkillListScrollFrame,filtersState.positionOffset) + TradeSkillListScrollFrameScrollBar:SetValue(filtersState.positionValue) + stateSaved = nil A.blockScan = nil