comparison utils.lua @ 108:618163a6d970 v1.0beta13

Always show counts and bypass all filtering and searches
author contrebasse
date Thu, 02 Jun 2011 14:12:06 +0200
parents d64a19e5a47d
children d60d6b4cab0c
comparison
equal deleted inserted replaced
107:d64a19e5a47d 108:618163a6d970
41 local GetTradeSkillInfo = GetTradeSkillInfo 41 local GetTradeSkillInfo = GetTradeSkillInfo
42 local GetNumTradeSkills = GetNumTradeSkills 42 local GetNumTradeSkills = GetNumTradeSkills
43 local GetTradeSkillItemLink = GetTradeSkillItemLink 43 local GetTradeSkillItemLink = GetTradeSkillItemLink
44 44
45 -- Gives the number of craftable objects 45 -- Gives the number of craftable objects
46 --[[
46 function A.numMakable(reagentID) 47 function A.numMakable(reagentID)
47 -- Look for the recipe to make the item 48 -- Look for the recipe to make the item
48 local reagentIndex = A.findSkillIndex(reagentID) 49 local reagentIndex = A.findSkillIndex(reagentID)
49 if not reagentIndex then return end 50 if not reagentIndex then return end
50 51
51 -- Check how many items we can craft 52 -- Check how many items we can craft
52 local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) 53 local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex)
53 return numReagentMakable, reagentIndex 54 return numReagentMakable, reagentIndex
54 end 55 end
56 --]]
57 function A.numMakable(reagentID)
58 -- No recipe
59 if not A.data[reagentID] then return 0 end
60
61 -- Many recipes
62 local n = 0
63 local itemCount
64 for _,recipe in pairs(A.data[reagentID]) do
65 if recipe[1] then -- only one reagent
66 itemCount = GetItemCount(recipe[1])
67 if not itemCount then return end
68 n = n + math.floor(itemCount/recipe[2])
69 else -- many reagents
70 local m
71 for _,reagent in pairs(recipe[2]) do
72 itemCount = GetItemCount(reagent[1])
73 if not itemCount then return end
74 if not m then
75 m = math.floor(itemCount/reagent[2])
76 else
77 m = math.min(m,math.floor(itemCount/reagent[2]))
78 end
79 if m==0 then break end
80 end
81 n = n + m
82 end -- if
83 end -- for
84 return n
85 end -- function
55 86
56 -- Find the first tradeskill index of the recipe to make an item 87 -- Find the first tradeskill index of the recipe to make an item
57 function A.findSkillIndex(itemID) 88 function A.findSkillIndex(itemID)
58 for i = 1,GetNumTradeSkills() do 89 for i = 1,GetNumTradeSkills() do
59 local _, skillType = GetTradeSkillInfo(i) 90 local _, skillType = GetTradeSkillInfo(i)
75 local selectedTradeSkillIndex 106 local selectedTradeSkillIndex
76 local stateSaved 107 local stateSaved
77 local filtersState = {} 108 local filtersState = {}
78 local headersState = {} 109 local headersState = {}
79 110
80 local function GetSubClassID()
81 -- The purpose of this function is to get the subClassID in a UI independant way
82 -- ie: without relying on UIDropDownMenu_GetSelectedID(TradeSkillSubClassDropDown), which uses a hardcoded frame name.
83
84 if GetTradeSkillSubClassFilter(0) then -- if "All Subclasses" is selected, GetTradeSkillSubClassFilter() will return 1 for all indexes, including 0
85 return 1 -- thus return 1 as selected id (as would be returned by UIDropDownMenu_GetSelectedID(TradeSkillSubClassDropDown))
86 end
87
88 local filter
89 for i = 1, #subClasses do
90 filter = GetTradeSkillSubClassFilter(i)
91 if filter then
92 return i+1 -- ex: 3rd element of the subClasses array, but 4th in the dropdown due to "All Subclasses", so return i+1
93 end
94 end
95 end
96
97 local function GetInvSlotID()
98 -- The purpose of this function is to get the invSlotID in a UI independant way (same as GetSubClassID)
99 -- ie: without relying on UIDropDownMenu_GetSelectedID(TradeSkillInvSlotDropDown), which uses a hardcoded frame name.
100
101 if GetTradeSkillInvSlotFilter(0) then -- if "All Slots" is selected, GetTradeSkillInvSlotFilter() will return 1 for all indexes, including 0
102 return 1 -- thus return 1 as selected id (as would be returned by UIDropDownMenu_GetSelectedID(TradeSkillInvSlotDropDown))
103 end
104
105 local filter
106 for i = 1, #invSlots do
107 filter = GetTradeSkillInvSlotFilter(i)
108 if filter then
109 return i+1 -- ex: 3rd element of the invSlots array, but 4th in the dropdown due to "All Slots", so return i+1
110 end
111 end
112 end
113
114 local function ApplyFilters() 111 local function ApplyFilters()
115 TradeSkillOnlyShowSkillUps(TradeSkillFrame.filterTbl.hasSkillUp); 112 TradeSkillOnlyShowSkillUps(TradeSkillFrame.filterTbl.hasSkillUp);
116 TradeSkillOnlyShowMakeable(TradeSkillFrame.filterTbl.hasMaterials); 113 TradeSkillOnlyShowMakeable(TradeSkillFrame.filterTbl.hasMaterials);
117 SetTradeSkillSubClassFilter(TradeSkillFrame.filterTbl.subClassValue, 1, 1); 114 SetTradeSkillSubClassFilter(TradeSkillFrame.filterTbl.subClassValue, 1, 1);
118 SetTradeSkillInvSlotFilter(TradeSkillFrame.filterTbl.slotValue, 1, 1); 115 SetTradeSkillInvSlotFilter(TradeSkillFrame.filterTbl.slotValue, 1, 1);
122 119
123 function A.SaveActiveFilters(headerName) 120 function A.SaveActiveFilters(headerName)
124 A.blockScan = true 121 A.blockScan = true
125 122
126 -- Save filters 123 -- Save filters
124 filtersState.text = GetTradeSkillItemNameFilter()
125 filtersState.minLevel, filtersState.maxLevel = GetTradeSkillItemLevelFilter()
127 filtersState.hasMaterials = TradeSkillFrame.filterTbl.hasMaterials 126 filtersState.hasMaterials = TradeSkillFrame.filterTbl.hasMaterials
128 filtersState.hasSkillUp = TradeSkillFrame.filterTbl.hasSkillUp 127 filtersState.hasSkillUp = TradeSkillFrame.filterTbl.hasSkillUp
129 filtersState.subClassValue = TradeSkillFrame.filterTbl.subClassValue 128 filtersState.subClassValue = TradeSkillFrame.filterTbl.subClassValue
130 filtersState.slotValue = TradeSkillFrame.filterTbl.slotValue 129 filtersState.slotValue = TradeSkillFrame.filterTbl.slotValue
131 130
132 -- Remove all filters 131 -- Remove all filters
132 SetTradeSkillItemNameFilter(nil)
133 SetTradeSkillItemLevelFilter(0, 0)
133 TradeSkillFrame.filterTbl.hasMaterials = false 134 TradeSkillFrame.filterTbl.hasMaterials = false
134 TradeSkillFrame.filterTbl.hasSkillUp = false 135 TradeSkillFrame.filterTbl.hasSkillUp = false
135 TradeSkillFrame.filterTbl.subClassValue = -1 136 TradeSkillFrame.filterTbl.subClassValue = -1
136 TradeSkillFrame.filterTbl.slotValue = -1 137 TradeSkillFrame.filterTbl.slotValue = -1
137 ApplyFilters() 138 ApplyFilters()
138 139
139 -- Headers 140 -- Headers
140 --local headerCount = 0 -- use a counter to avoid being bound to header names, which might not be unique.
141 headersState.headerName = headerName 141 headersState.headerName = headerName
142 for i = GetNumTradeSkills(), 1, -1 do -- 1st pass, expand all categories 142 for i = GetNumTradeSkills(), 1, -1 do -- 1st pass, expand all categories
143 local skillName, skillType, _, isExpanded = GetTradeSkillInfo(i) 143 local skillName, skillType, _, isExpanded = GetTradeSkillInfo(i)
144 if (skillType == "header") and skillName==headerName then 144 if (skillType == "header") and skillName==headerName then
145 if not isExpanded then 145 if not isExpanded then
146 ExpandTradeSkillSubClass(i) 146 ExpandTradeSkillSubClass(i)
147 table.insert(headersState,true) 147 table.insert(headersState,true)
148 else 148 else
149 table.insert(headersState,false) 149 table.insert(headersState,false)
150 end
151 end 150 end
152 end 151 end
152 end
153
154 stateSaved = true
155 A.blockScan = nil
153 156
154 --@todo Scroll down to the selected recipe 157 --@todo Scroll down to the selected recipe
155 -- with TradeSkillSkillXX:Show() ? 158 -- with TradeSkillSkillXX:Show() ?
156
157 stateSaved = true
158
159 A.blockScan = nil
160 end 159 end
161 160
162 function A.RestoreActiveFilters() 161 function A.RestoreActiveFilters()
163 if not stateSaved then return end 162 if not stateSaved then return end
164
165 A.blockScan = true 163 A.blockScan = true
166 164
167 -- restore headers 165 -- restore headers
168 for i = GetNumTradeSkills(), 1, -1 do 166 for i = GetNumTradeSkills(), 1, -1 do
169 local skillName, skillType = GetTradeSkillInfo(i) 167 local skillName, skillType = GetTradeSkillInfo(i)
172 end 170 end
173 end 171 end
174 wipe(headersState) 172 wipe(headersState)
175 173
176 -- restore filters 174 -- restore filters
175 SetTradeSkillItemNameFilter(filtersState.text)
176 SetTradeSkillItemLevelFilter(filtersState.minLevel, filtersState.maxLevel)
177 TradeSkillFrame.filterTbl.hasMaterials = filtersState.hasMaterials 177 TradeSkillFrame.filterTbl.hasMaterials = filtersState.hasMaterials
178 TradeSkillFrame.filterTbl.hasSkillUp = filtersState.hasSkillUp 178 TradeSkillFrame.filterTbl.hasSkillUp = filtersState.hasSkillUp
179 TradeSkillFrame.filterTbl.subClassValue = filtersState.subClassValue 179 TradeSkillFrame.filterTbl.subClassValue = filtersState.subClassValue
180 TradeSkillFrame.filterTbl.slotValue = filtersState.slotValue 180 TradeSkillFrame.filterTbl.slotValue = filtersState.slotValue
181 ApplyFilters() 181 ApplyFilters()
182 182
183
184 --print("restored")
185
186 stateSaved = nil 183 stateSaved = nil
187
188 A.blockScan = nil 184 A.blockScan = nil
185
186 --@todo Scroll down to the selected recipe
187 -- with TradeSkillSkillXX:Show() ?
189 end 188 end
190 end 189 end
191 190
192 function A.isRecipeUnique(itemData) 191 function A.isRecipeUnique(itemData)
193 local unique = true 192 local unique = true