comparison utils.lua @ 24:5f3a5b88fb19

First attempt to unfilter, failed badly... I'm not even sure it'll be possible at all.
author contrebasse
date Wed, 27 Apr 2011 23:46:20 +0200
parents 250d01156e21
children 578b9c9479c9
comparison
equal deleted inserted replaced
23:8acb6dc1ff9e 24:5f3a5b88fb19
56 end -- if 56 end -- if
57 end -- for 57 end -- for
58 A.DEBUG("Tradeskill not found for "..itemID) 58 A.DEBUG("Tradeskill not found for "..itemID)
59 end -- function 59 end -- function
60 end -- do 60 end -- do
61
62
63 -- Taken from Datastore_Crafts
64 -- *** Scanning functions ***
65 do
66 local selectedTradeSkillIndex
67 local subClasses, subClassID
68 local invSlots, invSlotID
69 local haveMats
70 local headersState = {}
71
72 local function GetSubClassID()
73 -- The purpose of this function is to get the subClassID in a UI independant way
74 -- ie: without relying on UIDropDownMenu_GetSelectedID(TradeSkillSubClassDropDown), which uses a hardcoded frame name.
75
76 if GetTradeSkillSubClassFilter(0) then -- if "All Subclasses" is selected, GetTradeSkillSubClassFilter() will return 1 for all indexes, including 0
77 return 1 -- thus return 1 as selected id (as would be returned by UIDropDownMenu_GetSelectedID(TradeSkillSubClassDropDown))
78 end
79
80 local filter
81 for i = 1, #subClasses do
82 filter = GetTradeSkillSubClassFilter(i)
83 if filter then
84 return i+1 -- ex: 3rd element of the subClasses array, but 4th in the dropdown due to "All Subclasses", so return i+1
85 end
86 end
87 end
88
89 local function GetInvSlotID()
90 -- The purpose of this function is to get the invSlotID in a UI independant way (same as GetSubClassID)
91 -- ie: without relying on UIDropDownMenu_GetSelectedID(TradeSkillInvSlotDropDown), which uses a hardcoded frame name.
92
93 if GetTradeSkillInvSlotFilter(0) then -- if "All Slots" is selected, GetTradeSkillInvSlotFilter() will return 1 for all indexes, including 0
94 return 1 -- thus return 1 as selected id (as would be returned by UIDropDownMenu_GetSelectedID(TradeSkillInvSlotDropDown))
95 end
96
97 local filter
98 for i = 1, #invSlots do
99 filter = GetTradeSkillInvSlotFilter(i)
100 if filter then
101 return i+1 -- ex: 3rd element of the invSlots array, but 4th in the dropdown due to "All Slots", so return i+1
102 end
103 end
104 end
105
106 function A.SaveActiveFilters()
107 print("save")
108 selectedTradeSkillIndex = GetTradeSkillSelectionIndex()
109
110 subClasses = { GetTradeSkillSubClasses() }
111 invSlots = { GetTradeSkillInvSlots() }
112 subClassID = GetSubClassID()
113 invSlotID = GetInvSlotID()
114
115 -- Subclasses
116 SetTradeSkillSubClassFilter(0, 1, 1) -- this checks "All subclasses"
117 if TradeSkillSubClassDropDown then
118 UIDropDownMenu_SetSelectedID(TradeSkillSubClassDropDown, 1)
119 end
120
121 -- Inventory slots
122 SetTradeSkillInvSlotFilter(0, 1, 1) -- this checks "All slots"
123 if TradeSkillInvSlotDropDown then
124 UIDropDownMenu_SetSelectedID(TradeSkillInvSlotDropDown, 1)
125 end
126
127 -- Have Materials
128 if TradeSkillFrameAvailableFilterCheckButton then
129 haveMats = TradeSkillFrameAvailableFilterCheckButton:GetChecked() -- nil or true
130 TradeSkillFrameAvailableFilterCheckButton:SetChecked(false)
131 end
132 TradeSkillOnlyShowMakeable(false)
133
134 -- Headers
135 local headerCount = 0 -- use a counter to avoid being bound to header names, which might not be unique.
136
137 for i = GetNumTradeSkills(), 1, -1 do -- 1st pass, expand all categories
138 local _, skillType, _, isExpanded = GetTradeSkillInfo(i)
139 if (skillType == "header") then
140 headerCount = headerCount + 1
141 if not isExpanded then
142 ExpandTradeSkillSubClass(i)
143 headersState[headerCount] = true
144 end
145 end
146 end
147
148 print("saved")
149 end
150
151 function A.RestoreActiveFilters()
152 print("restore")
153 -- Subclasses
154 SetTradeSkillSubClassFilter(subClassID-1, 1, 1) -- this checks the previously checked value
155
156 local frame = TradeSkillSubClassDropDown
157 if frame then -- other addons might nil this frame (delayed load, etc..), so secure DDM calls
158 local text = (subClassID == 1) and ALL_SUBCLASSES or subClasses[subClassID-1]
159 UIDropDownMenu_SetSelectedID(frame, subClassID)
160 UIDropDownMenu_SetText(frame, text);
161 end
162
163 subClassID = nil
164 wipe(subClasses)
165 subClasses = nil
166
167 -- Inventory slots
168 invSlotID = invSlotID or 1
169 SetTradeSkillInvSlotFilter(invSlotID-1, 1, 1) -- this checks the previously checked value
170
171 frame = TradeSkillInvSlotDropDown
172 if frame then
173 local text = (invSlotID == 1) and ALL_INVENTORY_SLOTS or invSlots[invSlotID-1]
174 UIDropDownMenu_SetSelectedID(frame, invSlotID)
175 UIDropDownMenu_SetText(frame, text);
176 end
177
178 invSlotID = nil
179 wipe(invSlots)
180 invSlots = nil
181
182 -- Have Materials
183 if TradeSkillFrameAvailableFilterCheckButton then
184 TradeSkillFrameAvailableFilterCheckButton:SetChecked(haveMats or false)
185 end
186 TradeSkillOnlyShowMakeable(haveMats or false)
187 haveMats = nil
188
189 SelectTradeSkill(selectedTradeSkillIndex)
190 selectedTradeSkillIndex = nil
191
192 -- Headers
193 local headerCount = 0
194 for i = GetNumTradeSkills(), 1, -1 do
195 local _, skillType = GetTradeSkillInfo(i)
196 if (skillType == "header") then
197 headerCount = headerCount + 1
198 if headersState[headerCount] then
199 CollapseTradeSkillSubClass(i)
200 end
201 end
202 end
203 wipe(headersState)
204 end
205 print("restored")
206 end