comparison Main.lua @ 169:5f6d5a1a62e1 1.0.20

Make sure the TradeSkillFrame exists and is visible before attempting to do anything with it. Re-use the headers table. Added the ability to break out of the loop in functions called by TradeSkillExecutePer.
author James D. Callahan III <jcallahan@curse.com>
date Tue, 16 Oct 2012 03:38:35 -0500
parents 0820f3ab783e
children 40624eb09591
comparison
equal deleted inserted replaced
168:10ad2d900502 169:5f6d5a1a62e1
166 end 166 end
167 _G.print(...) 167 _G.print(...)
168 end 168 end
169 169
170 170
171 local function TradeSkillExecutePer(iter_func) 171 local TradeSkillExecutePer
172 if _G.TradeSkillFrame and _G.TradeSkillFrame:IsVisible() then 172 do
173 local header_list = {}
174
175 -- iter_func returns true to indicate that the loop should be broken
176 function TradeSkillExecutePer(iter_func)
177 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then
178 return
179 end
173 -- Clear the search box focus so the scan will have correct results. 180 -- Clear the search box focus so the scan will have correct results.
174 local search_box = _G.TradeSkillFrameSearchBox 181 local search_box = _G.TradeSkillFrameSearchBox
175 search_box:SetText("") 182 search_box:SetText("")
183
176 _G.TradeSkillSearch_OnTextChanged(search_box) 184 _G.TradeSkillSearch_OnTextChanged(search_box)
177 search_box:ClearFocus() 185 search_box:ClearFocus()
178 search_box:GetScript("OnEditFocusLost")(search_box) 186 search_box:GetScript("OnEditFocusLost")(search_box)
179 end 187
180 local header_list = {} 188 table.wipe(header_list)
181 189
182 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it. 190 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
183 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials 191 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
184 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp 192 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
185 193
186 if have_materials then 194 if have_materials then
187 _G.TradeSkillFrame.filterTbl.hasMaterials = false 195 _G.TradeSkillFrame.filterTbl.hasMaterials = false
188 _G.TradeSkillOnlyShowMakeable(false) 196 _G.TradeSkillOnlyShowMakeable(false)
189 end 197 end
190 198
191 if have_skillup then 199 if have_skillup then
192 _G.TradeSkillFrame.filterTbl.hasSkillUp = false 200 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
193 _G.TradeSkillOnlyShowSkillUps(false) 201 _G.TradeSkillOnlyShowSkillUps(false)
194 end 202 end
195 _G.SetTradeSkillInvSlotFilter(0, 1, 1) 203 _G.SetTradeSkillInvSlotFilter(0, 1, 1)
196 _G.TradeSkillUpdateFilterBar() 204 _G.TradeSkillUpdateFilterBar()
197 _G.TradeSkillFrame_Update() 205 _G.TradeSkillFrame_Update()
198 206
199 -- Expand all headers so we can see all the recipes there are 207 -- Expand all headers so we can see all the recipes there are
200 for tradeskill_index = 1, _G.GetNumTradeSkills() do 208 for tradeskill_index = 1, _G.GetNumTradeSkills() do
201 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index) 209 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
202 210
203 if tradeskill_type == "header" or tradeskill_type == "subheader" then 211 if tradeskill_type == "header" or tradeskill_type == "subheader" then
204 if not is_expanded then 212 if not is_expanded then
205 header_list[name] = true 213 header_list[name] = true
206 _G.ExpandTradeSkillSubClass(tradeskill_index) 214 _G.ExpandTradeSkillSubClass(tradeskill_index)
207 end 215 end
208 else 216 elseif iter_func(name, tradeskill_index) then
209 iter_func(name, tradeskill_index) 217 break
210 end 218 end
211 end 219 end
212 220
213 -- Restore the state of the things we changed. 221 -- Restore the state of the things we changed.
214 for tradeskill_index = 1, _G.GetNumTradeSkills() do 222 for tradeskill_index = 1, _G.GetNumTradeSkills() do
215 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index) 223 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
216 224
217 if header_list[name] then 225 if header_list[name] then
218 _G.CollapseTradeSkillSubClass(tradeskill_index) 226 _G.CollapseTradeSkillSubClass(tradeskill_index)
219 end 227 end
220 end 228 end
221 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials 229 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
222 _G.TradeSkillOnlyShowMakeable(have_materials) 230 _G.TradeSkillOnlyShowMakeable(have_materials)
223 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup 231 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
224 _G.TradeSkillOnlyShowSkillUps(have_skillup) 232 _G.TradeSkillOnlyShowSkillUps(have_skillup)
225 233
226 _G.TradeSkillUpdateFilterBar() 234 _G.TradeSkillUpdateFilterBar()
227 _G.TradeSkillFrame_Update() 235 _G.TradeSkillFrame_Update()
228 end 236 end
237 end -- do-block
229 238
230 239
231 local ActualCopperCost 240 local ActualCopperCost
232 do 241 do
233 local BARTERING_SPELL_ID = 83964 242 local BARTERING_SPELL_ID = 83964
1027 DBEntry("spells", tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level) 1036 DBEntry("spells", tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level)
1028 1037
1029 private.discovered_recipe_name = nil 1038 private.discovered_recipe_name = nil
1030 private.profession_level = nil 1039 private.profession_level = nil
1031 private.previous_spell_id = nil 1040 private.previous_spell_id = nil
1041
1042 return true
1032 end 1043 end
1033 end 1044 end
1034 1045
1035 1046
1036 local function IterativeRecordDiscovery() 1047 local function IterativeRecordDiscovery()