Mercurial > wow > reagentmaker
comparison utils.lua @ 107:d64a19e5a47d
Bypass the filtering. Not fully tested, but mostly works.
| author | contrebasse |
|---|---|
| date | Thu, 02 Jun 2011 00:57:17 +0200 |
| parents | 8dd86b6b76d8 |
| children | 618163a6d970 |
comparison
equal
deleted
inserted
replaced
| 106:f857e01b067e | 107:d64a19e5a47d |
|---|---|
| 71 | 71 |
| 72 -- Taken from Datastore_Crafts | 72 -- Taken from Datastore_Crafts |
| 73 -- *** Scanning functions *** | 73 -- *** Scanning functions *** |
| 74 do | 74 do |
| 75 local selectedTradeSkillIndex | 75 local selectedTradeSkillIndex |
| 76 local subClasses, subClassID | 76 local stateSaved |
| 77 local invSlots, invSlotID | 77 local filtersState = {} |
| 78 local haveMats | |
| 79 local headersState = {} | 78 local headersState = {} |
| 80 | 79 |
| 81 local function GetSubClassID() | 80 local function GetSubClassID() |
| 82 -- The purpose of this function is to get the subClassID in a UI independant way | 81 -- The purpose of this function is to get the subClassID in a UI independant way |
| 83 -- ie: without relying on UIDropDownMenu_GetSelectedID(TradeSkillSubClassDropDown), which uses a hardcoded frame name. | 82 -- ie: without relying on UIDropDownMenu_GetSelectedID(TradeSkillSubClassDropDown), which uses a hardcoded frame name. |
| 110 return i+1 -- ex: 3rd element of the invSlots array, but 4th in the dropdown due to "All Slots", so return i+1 | 109 return i+1 -- ex: 3rd element of the invSlots array, but 4th in the dropdown due to "All Slots", so return i+1 |
| 111 end | 110 end |
| 112 end | 111 end |
| 113 end | 112 end |
| 114 | 113 |
| 114 local function ApplyFilters() | |
| 115 TradeSkillOnlyShowSkillUps(TradeSkillFrame.filterTbl.hasSkillUp); | |
| 116 TradeSkillOnlyShowMakeable(TradeSkillFrame.filterTbl.hasMaterials); | |
| 117 SetTradeSkillSubClassFilter(TradeSkillFrame.filterTbl.subClassValue, 1, 1); | |
| 118 SetTradeSkillInvSlotFilter(TradeSkillFrame.filterTbl.slotValue, 1, 1); | |
| 119 TradeSkillUpdateFilterBar(); | |
| 120 CloseDropDownMenus(); | |
| 121 end | |
| 122 | |
| 115 function A.SaveActiveFilters(headerName) | 123 function A.SaveActiveFilters(headerName) |
| 116 A.blockScan = true | 124 A.blockScan = true |
| 117 | 125 |
| 118 --[[ | 126 -- Save filters |
| 119 print("save") | 127 filtersState.hasMaterials = TradeSkillFrame.filterTbl.hasMaterials |
| 120 print(GetNumTradeSkills()) | 128 filtersState.hasSkillUp = TradeSkillFrame.filterTbl.hasSkillUp |
| 121 selectedTradeSkillIndex = GetTradeSkillSelectionIndex() | 129 filtersState.subClassValue = TradeSkillFrame.filterTbl.subClassValue |
| 122 | 130 filtersState.slotValue = TradeSkillFrame.filterTbl.slotValue |
| 123 subClasses = { GetTradeSkillSubClasses() } | 131 |
| 124 invSlots = { GetTradeSkillInvSlots() } | 132 -- Remove all filters |
| 125 subClassID = GetSubClassID() | 133 TradeSkillFrame.filterTbl.hasMaterials = false |
| 126 invSlotID = GetInvSlotID() | 134 TradeSkillFrame.filterTbl.hasSkillUp = false |
| 127 | 135 TradeSkillFrame.filterTbl.subClassValue = -1 |
| 128 -- Subclasses | 136 TradeSkillFrame.filterTbl.slotValue = -1 |
| 129 SetTradeSkillSubClassFilter(0, 1, 1) -- this checks "All subclasses" | 137 ApplyFilters() |
| 130 if TradeSkillSubClassDropDown then | |
| 131 UIDropDownMenu_SetSelectedID(TradeSkillSubClassDropDown, 1) | |
| 132 end | |
| 133 print(GetNumTradeSkills()) | |
| 134 | |
| 135 -- Inventory slots | |
| 136 SetTradeSkillInvSlotFilter(0, 1, 1) -- this checks "All slots" | |
| 137 if TradeSkillInvSlotDropDown then | |
| 138 UIDropDownMenu_SetSelectedID(TradeSkillInvSlotDropDown, 1) | |
| 139 end | |
| 140 print(GetNumTradeSkills()) | |
| 141 | |
| 142 -- Have Materials | |
| 143 if TradeSkillFrameAvailableFilterCheckButton then | |
| 144 haveMats = TradeSkillFrameAvailableFilterCheckButton:GetChecked() -- nil or true | |
| 145 TradeSkillFrameAvailableFilterCheckButton:SetChecked(false) | |
| 146 end | |
| 147 TradeSkillOnlyShowMakeable(false) | |
| 148 print(GetNumTradeSkills()) | |
| 149 --]] | |
| 150 | 138 |
| 151 -- Headers | 139 -- Headers |
| 152 --local headerCount = 0 -- use a counter to avoid being bound to header names, which might not be unique. | 140 --local headerCount = 0 -- use a counter to avoid being bound to header names, which might not be unique. |
| 141 headersState.headerName = headerName | |
| 153 for i = GetNumTradeSkills(), 1, -1 do -- 1st pass, expand all categories | 142 for i = GetNumTradeSkills(), 1, -1 do -- 1st pass, expand all categories |
| 154 local skillName, skillType, _, isExpanded = GetTradeSkillInfo(i) | 143 local skillName, skillType, _, isExpanded = GetTradeSkillInfo(i) |
| 155 if (skillType == "header") then | 144 if (skillType == "header") and skillName==headerName then |
| 156 --headerCount = headerCount + 1 | 145 if not isExpanded then |
| 157 if not isExpanded and skillName==headerName then | 146 ExpandTradeSkillSubClass(i) |
| 158 ExpandTradeSkillSubClass(i) | 147 table.insert(headersState,true) |
| 159 --print(GetNumTradeSkills()) | 148 else |
| 160 --headersState[headerCount] = true | 149 table.insert(headersState,false) |
| 150 end | |
| 161 end | 151 end |
| 162 end | 152 end |
| 163 end | 153 |
| 164 | 154 --@todo Scroll down to the selected recipe |
| 165 --print("saved") | 155 -- with TradeSkillSkillXX:Show() ? |
| 156 | |
| 157 stateSaved = true | |
| 166 | 158 |
| 167 A.blockScan = nil | 159 A.blockScan = nil |
| 168 end | 160 end |
| 169 | 161 |
| 170 function A.RestoreActiveFilters() | 162 function A.RestoreActiveFilters() |
| 163 if not stateSaved then return end | |
| 164 | |
| 171 A.blockScan = true | 165 A.blockScan = true |
| 172 | 166 |
| 173 print("restore") | 167 -- restore headers |
| 174 -- Subclasses | |
| 175 SetTradeSkillSubClassFilter(subClassID-1, 1, 1) -- this checks the previously checked value | |
| 176 | |
| 177 local frame = TradeSkillSubClassDropDown | |
| 178 if frame then -- other addons might nil this frame (delayed load, etc..), so secure DDM calls | |
| 179 local text = (subClassID == 1) and ALL_SUBCLASSES or subClasses[subClassID-1] | |
| 180 UIDropDownMenu_SetSelectedID(frame, subClassID) | |
| 181 UIDropDownMenu_SetText(frame, text); | |
| 182 end | |
| 183 | |
| 184 subClassID = nil | |
| 185 wipe(subClasses) | |
| 186 subClasses = nil | |
| 187 | |
| 188 -- Inventory slots | |
| 189 invSlotID = invSlotID or 1 | |
| 190 SetTradeSkillInvSlotFilter(invSlotID-1, 1, 1) -- this checks the previously checked value | |
| 191 | |
| 192 frame = TradeSkillInvSlotDropDown | |
| 193 if frame then | |
| 194 local text = (invSlotID == 1) and ALL_INVENTORY_SLOTS or invSlots[invSlotID-1] | |
| 195 UIDropDownMenu_SetSelectedID(frame, invSlotID) | |
| 196 UIDropDownMenu_SetText(frame, text); | |
| 197 end | |
| 198 | |
| 199 invSlotID = nil | |
| 200 wipe(invSlots) | |
| 201 invSlots = nil | |
| 202 | |
| 203 -- Have Materials | |
| 204 if TradeSkillFrameAvailableFilterCheckButton then | |
| 205 TradeSkillFrameAvailableFilterCheckButton:SetChecked(haveMats or false) | |
| 206 end | |
| 207 TradeSkillOnlyShowMakeable(haveMats or false) | |
| 208 haveMats = nil | |
| 209 | |
| 210 SelectTradeSkill(selectedTradeSkillIndex) | |
| 211 selectedTradeSkillIndex = nil | |
| 212 | |
| 213 -- Headers | |
| 214 local headerCount = 0 | |
| 215 for i = GetNumTradeSkills(), 1, -1 do | 168 for i = GetNumTradeSkills(), 1, -1 do |
| 216 local _, skillType = GetTradeSkillInfo(i) | 169 local skillName, skillType = GetTradeSkillInfo(i) |
| 217 if (skillType == "header") then | 170 if (skillType == "header") and skillName==headersState.headerName and table.remove(headersState,1) then |
| 218 headerCount = headerCount + 1 | |
| 219 if headersState[headerCount] then | |
| 220 CollapseTradeSkillSubClass(i) | 171 CollapseTradeSkillSubClass(i) |
| 221 end | |
| 222 end | 172 end |
| 223 end | 173 end |
| 224 wipe(headersState) | 174 wipe(headersState) |
| 225 end | 175 |
| 226 print("restored") | 176 -- restore filters |
| 227 | 177 TradeSkillFrame.filterTbl.hasMaterials = filtersState.hasMaterials |
| 228 A.blockScan = nil | 178 TradeSkillFrame.filterTbl.hasSkillUp = filtersState.hasSkillUp |
| 179 TradeSkillFrame.filterTbl.subClassValue = filtersState.subClassValue | |
| 180 TradeSkillFrame.filterTbl.slotValue = filtersState.slotValue | |
| 181 ApplyFilters() | |
| 182 | |
| 183 | |
| 184 --print("restored") | |
| 185 | |
| 186 stateSaved = nil | |
| 187 | |
| 188 A.blockScan = nil | |
| 189 end | |
| 229 end | 190 end |
| 230 | 191 |
| 231 function A.isRecipeUnique(itemData) | 192 function A.isRecipeUnique(itemData) |
| 232 local unique = true | 193 local unique = true |
| 233 | 194 |
| 234 -- Check if the item is made by only one recipe. If not, return | 195 -- Check if the item is made by only one recipe. If not, return |
| 235 if #itemData>1 then | 196 if #itemData>1 then |
| 236 local spellLink | 197 local spellLink |
| 237 for _,v in ipairs(itemData) do | 198 for _,v in ipairs(itemData) do |
| 238 if not spellLink then | 199 if not spellLink then |
| 243 break | 204 break |
| 244 end | 205 end |
| 245 end | 206 end |
| 246 end | 207 end |
| 247 end | 208 end |
| 248 | 209 |
| 249 return unique | 210 return unique |
| 250 end | 211 end |
| 251 | 212 |
| 252 --[[ | 213 --[[ |
| 253 function A.isTradeskillUnique(itemData) | 214 function A.isTradeskillUnique(itemData) |
| 254 local spellName = itemData[1].spellName | 215 local spellName = itemData[1].spellName |
| 255 | 216 |
| 256 -- Check if the item is made by only one recipe. If not, return | 217 -- Check if the item is made by only one recipe. If not, return |
| 257 if #itemData>1 then | 218 if #itemData>1 then |
| 258 for _,v in ipairs(itemData) do | 219 for _,v in ipairs(itemData) do |
| 259 if v.spellName ~= spellName then | 220 if v.spellName ~= spellName then |
| 260 spellName = nil | 221 spellName = nil |
