Mercurial > wow > reagentmaker
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 110:d60d6b4cab0c | 111:af23986010ef |
|---|---|
| 1 local addonName, A = ... | 1 local addonName, A = ... |
| 2 | |
| 3 -- GLOBALS: UIErrorsFrame, UIErrorsFrame_OnEvent | |
| 2 | 4 |
| 3 -- Lua functions | 5 -- Lua functions |
| 4 local tonumber = tonumber | 6 local tonumber = tonumber |
| 5 local select = select | 7 local select = select |
| 6 local sfind = string.find | 8 local sfind = string.find |
| 9 local min = math.min | |
| 10 local floor = math.floor | |
| 11 local pairs = pairs | |
| 12 local ipairs = ipairs | |
| 13 local wipe = wipe | |
| 14 local tinsert = tinsert | |
| 15 local tremove = tremove | |
| 7 | 16 |
| 8 -- Wow functions | 17 -- Wow functions |
| 9 | 18 local GetItemCount = GetItemCount |
| 10 -- DEBUG Print | |
| 11 function A.DEBUG(msg) | |
| 12 -- GLOBALS: DEFAULT_CHAT_FRAME | |
| 13 DEFAULT_CHAT_FRAME:AddMessage(msg or "nil",1,0,0) | |
| 14 end -- function | |
| 15 | 19 |
| 16 -- Messages to the user | 20 -- Messages to the user |
| 17 function A.Warn(msg) | 21 function A.Warn(msg) |
| 18 if not msg then return end | 22 if not msg then return end |
| 19 local event = "UI_INFO_MESSAGE" | 23 local event = "UI_INFO_MESSAGE" |
| 39 do | 43 do |
| 40 -- Wow functions | 44 -- Wow functions |
| 41 local GetTradeSkillInfo = GetTradeSkillInfo | 45 local GetTradeSkillInfo = GetTradeSkillInfo |
| 42 local GetNumTradeSkills = GetNumTradeSkills | 46 local GetNumTradeSkills = GetNumTradeSkills |
| 43 local GetTradeSkillItemLink = GetTradeSkillItemLink | 47 local GetTradeSkillItemLink = GetTradeSkillItemLink |
| 48 local GetTradeSkillRecipeLink = GetTradeSkillRecipeLink | |
| 44 | 49 |
| 45 function A.numRecipeMakable(reagentIDIfUnique,reagents) | 50 function A.numRecipeMakable(reagentIDIfUnique,reagents) |
| 51 local itemCount | |
| 46 if reagentIDIfUnique then -- only one reagent | 52 if reagentIDIfUnique then -- only one reagent |
| 47 itemCount = GetItemCount(reagentIDIfUnique) | 53 itemCount = GetItemCount(reagentIDIfUnique) |
| 48 if not itemCount then return end | 54 if not itemCount then return end |
| 49 return math.floor(itemCount/reagents) | 55 return floor(itemCount/reagents) |
| 50 else -- many reagents | 56 else -- many reagents |
| 51 local m | 57 local m |
| 52 for _,reagent in pairs(reagents) do | 58 for _,reagent in pairs(reagents) do |
| 53 itemCount = GetItemCount(reagent[1]) | 59 itemCount = GetItemCount(reagent[1]) |
| 54 if not itemCount then return end | 60 if not itemCount then return end |
| 55 if not m then | 61 if not m then |
| 56 m = math.floor(itemCount/reagent[2]) | 62 m = floor(itemCount/reagent[2]) |
| 57 else | 63 else |
| 58 m = math.min(m,math.floor(itemCount/reagent[2])) | 64 m = min(m,floor(itemCount/reagent[2])) |
| 59 end | 65 end |
| 60 if m==0 then break end | 66 if m==0 then break end |
| 61 end | 67 end |
| 62 return m | 68 return m |
| 63 end -- if | 69 end -- if |
| 64 end | 70 end |
| 65 | 71 |
| 66 -- Gives the number of craftable objects | 72 -- Gives the total number of craftable objects |
| 67 function A.numMakable(reagentID) | 73 function A.numMakable(reagentID) |
| 68 -- No recipe | 74 -- No recipe |
| 69 if not A.data[reagentID] then return 0 end | 75 if not A.data[reagentID] then return 0 end |
| 70 | 76 |
| 71 -- Many recipes | 77 -- Many recipes |
| 86 end -- if | 92 end -- if |
| 87 end -- for | 93 end -- for |
| 88 end -- function | 94 end -- function |
| 89 | 95 |
| 90 -- Find the exact tradeskill index of the recipe to make an item | 96 -- Find the exact tradeskill index of the recipe to make an item |
| 91 function A.findExactSkillIndex(itemID,recipeName) | 97 function A.findExactSkillIndex(itemID,recipeLink) |
| 92 if not itemID or not recipeName then return end | 98 if not itemID or not recipeLink then return end |
| 93 for i = 1,GetNumTradeSkills() do | 99 for i = 1,GetNumTradeSkills() do |
| 94 local skillName, skillType = GetTradeSkillInfo(i) | 100 if select(2,GetTradeSkillInfo(i)) ~= "header" and GetTradeSkillRecipeLink(i)==recipeLink and A.link2ID(GetTradeSkillItemLink(i)) == itemID then |
| 95 if skillType ~= "header" and skillName==recipeName and A.link2ID(GetTradeSkillItemLink(i)) == itemID then | |
| 96 return i | 101 return i |
| 97 end -- if | 102 end -- if |
| 98 end -- for | 103 end -- for |
| 99 end -- function | 104 end -- function |
| 100 end -- do | 105 end -- do |
| 116 CloseDropDownMenus(); | 121 CloseDropDownMenus(); |
| 117 end | 122 end |
| 118 | 123 |
| 119 function A.SaveActiveFilters(headerName) | 124 function A.SaveActiveFilters(headerName) |
| 120 A.blockScan = true | 125 A.blockScan = true |
| 126 | |
| 127 -- Save position | |
| 128 filtersState.positionOffset = FauxScrollFrame_GetOffset(TradeSkillListScrollFrame) | |
| 129 filtersState.positionValue = TradeSkillListScrollFrameScrollBar:GetValue() | |
| 121 | 130 |
| 122 -- Save filters | 131 -- Save filters |
| 123 filtersState.text = GetTradeSkillItemNameFilter() | 132 filtersState.text = GetTradeSkillItemNameFilter() |
| 124 filtersState.minLevel, filtersState.maxLevel = GetTradeSkillItemLevelFilter() | 133 filtersState.minLevel, filtersState.maxLevel = GetTradeSkillItemLevelFilter() |
| 125 filtersState.hasMaterials = TradeSkillFrame.filterTbl.hasMaterials | 134 filtersState.hasMaterials = TradeSkillFrame.filterTbl.hasMaterials |
| 141 for i = GetNumTradeSkills(), 1, -1 do -- 1st pass, expand all categories | 150 for i = GetNumTradeSkills(), 1, -1 do -- 1st pass, expand all categories |
| 142 local skillName, skillType, _, isExpanded = GetTradeSkillInfo(i) | 151 local skillName, skillType, _, isExpanded = GetTradeSkillInfo(i) |
| 143 if (skillType == "header") and skillName==headerName then | 152 if (skillType == "header") and skillName==headerName then |
| 144 if not isExpanded then | 153 if not isExpanded then |
| 145 ExpandTradeSkillSubClass(i) | 154 ExpandTradeSkillSubClass(i) |
| 146 table.insert(headersState,true) | 155 tinsert(headersState,true) |
| 147 else | 156 else |
| 148 table.insert(headersState,false) | 157 tinsert(headersState,false) |
| 149 end | 158 end |
| 150 end | 159 end |
| 151 end | 160 end |
| 152 | 161 |
| 153 stateSaved = true | 162 stateSaved = true |
| 162 A.blockScan = true | 171 A.blockScan = true |
| 163 | 172 |
| 164 -- restore headers | 173 -- restore headers |
| 165 for i = GetNumTradeSkills(), 1, -1 do | 174 for i = GetNumTradeSkills(), 1, -1 do |
| 166 local skillName, skillType = GetTradeSkillInfo(i) | 175 local skillName, skillType = GetTradeSkillInfo(i) |
| 167 if (skillType == "header") and skillName==headersState.headerName and table.remove(headersState,1) then | 176 if (skillType == "header") and skillName==headersState.headerName and tremove(headersState,1) then |
| 168 CollapseTradeSkillSubClass(i) | 177 CollapseTradeSkillSubClass(i) |
| 169 end | 178 end |
| 170 end | 179 end |
| 171 wipe(headersState) | 180 wipe(headersState) |
| 172 | 181 |
| 176 TradeSkillFrame.filterTbl.hasMaterials = filtersState.hasMaterials | 185 TradeSkillFrame.filterTbl.hasMaterials = filtersState.hasMaterials |
| 177 TradeSkillFrame.filterTbl.hasSkillUp = filtersState.hasSkillUp | 186 TradeSkillFrame.filterTbl.hasSkillUp = filtersState.hasSkillUp |
| 178 TradeSkillFrame.filterTbl.subClassValue = filtersState.subClassValue | 187 TradeSkillFrame.filterTbl.subClassValue = filtersState.subClassValue |
| 179 TradeSkillFrame.filterTbl.slotValue = filtersState.slotValue | 188 TradeSkillFrame.filterTbl.slotValue = filtersState.slotValue |
| 180 ApplyFilters() | 189 ApplyFilters() |
| 190 | |
| 191 -- Re set position | |
| 192 FauxScrollFrame_SetOffset(TradeSkillListScrollFrame,filtersState.positionOffset) | |
| 193 TradeSkillListScrollFrameScrollBar:SetValue(filtersState.positionValue) | |
| 181 | 194 |
| 182 stateSaved = nil | 195 stateSaved = nil |
| 183 A.blockScan = nil | 196 A.blockScan = nil |
| 184 | 197 |
| 185 --@todo Scroll down to the selected recipe | 198 --@todo Scroll down to the selected recipe |
