comparison Main.lua @ 464:6e78d7849ea3

Rewrote TradeSkill handling for new Legion APIs.
author Caleb Atherton <catherton@curse.com>
date Sat, 07 May 2016 21:07:38 -0400
parents 1136b1bc88a1
children efdbef365ec0
comparison
equal deleted inserted replaced
463:1136b1bc88a1 464:6e78d7849ea3
249 249
250 function TradeSkillExecutePer(iter_func) 250 function TradeSkillExecutePer(iter_func)
251 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then 251 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then
252 return 252 return
253 end 253 end
254 -- Clear the search box focus so the scan will have correct results. 254
255 local search_box = _G.TradeSkillFrameSearchBox 255 if (private.isLegion) then
256 search_box:SetText("") 256 local recipes = _G.C_TradeSkillUI.GetAllRecipeIDs()
257 257
258 _G.TradeSkillSearch_OnTextChanged(search_box) 258 if recipes and (#recipes > 0) then
259 search_box:ClearFocus() 259 for i = 1, #recipes do
260 search_box:GetScript("OnEditFocusLost")(search_box) 260 if iter_func(_G.C_TradeSkillUI.GetRecipeInfo(recipes[i]).name, recipes[i]) then
261 261 break
262 table.wipe(header_list) 262 end
263 263 end
264 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it. 264 end
265 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials 265 else
266 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp 266 -- Clear the search box focus so the scan will have correct results.
267 267 local search_box = _G.TradeSkillFrameSearchBox
268 if have_materials then 268 search_box:SetText("")
269 _G.TradeSkillFrame.filterTbl.hasMaterials = false 269
270 _G.TradeSkillOnlyShowMakeable(false) 270 _G.TradeSkillSearch_OnTextChanged(search_box)
271 end 271 search_box:ClearFocus()
272 272 search_box:GetScript("OnEditFocusLost")(search_box)
273 if have_skillup then 273
274 _G.TradeSkillFrame.filterTbl.hasSkillUp = false 274 table.wipe(header_list)
275 _G.TradeSkillOnlyShowSkillUps(false) 275
276 end 276 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
277 _G.SetTradeSkillInvSlotFilter(0, true, true) 277 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
278 _G.TradeSkillUpdateFilterBar() 278 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
279 _G.TradeSkillFrame_Update() 279
280 280 if have_materials then
281 -- Expand all headers so we can see all the recipes there are 281 _G.TradeSkillFrame.filterTbl.hasMaterials = false
282 for tradeskill_index = 1, _G.GetNumTradeSkills() do 282 _G.TradeSkillOnlyShowMakeable(false)
283 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index) 283 end
284 284
285 if tradeskill_type == "header" or tradeskill_type == "subheader" then 285 if have_skillup then
286 if not is_expanded then 286 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
287 header_list[name] = true 287 _G.TradeSkillOnlyShowSkillUps(false)
288 _G.ExpandTradeSkillSubClass(tradeskill_index) 288 end
289 end 289 _G.SetTradeSkillInvSlotFilter(0, true, true)
290 elseif iter_func(name, tradeskill_index) then 290 _G.TradeSkillUpdateFilterBar()
291 break 291 _G.TradeSkillFrame_Update()
292 end 292
293 end 293 -- Expand all headers so we can see all the recipes there are
294 294 for tradeskill_index = 1, _G.GetNumTradeSkills() do
295 -- Restore the state of the things we changed. 295 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
296 for tradeskill_index = 1, _G.GetNumTradeSkills() do 296
297 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index) 297 if tradeskill_type == "header" or tradeskill_type == "subheader" then
298 298 if not is_expanded then
299 if header_list[name] then 299 header_list[name] = true
300 _G.CollapseTradeSkillSubClass(tradeskill_index) 300 _G.ExpandTradeSkillSubClass(tradeskill_index)
301 end 301 end
302 end 302 elseif iter_func(name, tradeskill_index) then
303 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials 303 break
304 _G.TradeSkillOnlyShowMakeable(have_materials) 304 end
305 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup 305 end
306 _G.TradeSkillOnlyShowSkillUps(have_skillup) 306
307 307 -- Restore the state of the things we changed.
308 _G.TradeSkillUpdateFilterBar() 308 for tradeskill_index = 1, _G.GetNumTradeSkills() do
309 _G.TradeSkillFrame_Update() 309 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
310
311 if header_list[name] then
312 _G.CollapseTradeSkillSubClass(tradeskill_index)
313 end
314 end
315 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
316 _G.TradeSkillOnlyShowMakeable(have_materials)
317 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
318 _G.TradeSkillOnlyShowSkillUps(have_skillup)
319
320 _G.TradeSkillUpdateFilterBar()
321 _G.TradeSkillFrame_Update()
322 end
310 end 323 end
311 end -- do-block 324 end -- do-block
312 325
313 326
314 local ActualCopperCost 327 local ActualCopperCost
1652 local RECIPE_MATCH = _G.ERR_LEARN_RECIPE_S:gsub("%%s", "(.*)") 1665 local RECIPE_MATCH = _G.ERR_LEARN_RECIPE_S:gsub("%%s", "(.*)")
1653 1666
1654 1667
1655 local function RecordDiscovery(tradeskill_name, tradeskill_index) 1668 local function RecordDiscovery(tradeskill_name, tradeskill_index)
1656 if tradeskill_name == private.discovered_recipe_name then 1669 if tradeskill_name == private.discovered_recipe_name then
1657 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) 1670 if (private.isLegion) then
1671 DBEntry("spells", tonumber(_G.C_TradeSkillUI.GetRecipeLink(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)
1672 else
1673 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)
1674 end
1658 1675
1659 private.discovered_recipe_name = nil 1676 private.discovered_recipe_name = nil
1660 private.profession_level = nil 1677 private.profession_level = nil
1661 private.previous_spell_id = nil 1678 private.previous_spell_id = nil
1662 1679
1681 if not item_id then 1698 if not item_id then
1682 if not private.trainer_shown then 1699 if not private.trainer_shown then
1683 local recipe_name = message:match(RECIPE_MATCH) 1700 local recipe_name = message:match(RECIPE_MATCH)
1684 1701
1685 if recipe_name and private.previous_spell_id then 1702 if recipe_name and private.previous_spell_id then
1686 local profession_name, prof_level = _G.GetTradeSkillLine() 1703 local profession_name, prof_level
1704 if private.isLegion then
1705 profession_name, prof_level= _G.C_TradeSkillUI.GetTradeSkillLine()
1706 else
1707 profession_name, prof_level= _G.GetTradeSkillLine()
1708 end
1687 1709
1688 if profession_name == _G.UNKNOWN then 1710 if profession_name == _G.UNKNOWN then
1689 return 1711 return
1690 end 1712 end
1691 private.discovered_recipe_name = recipe_name 1713 private.discovered_recipe_name = recipe_name
2228 2250
2229 for loot_slot = 1, _G.GetNumLootItems() do 2251 for loot_slot = 1, _G.GetNumLootItems() do
2230 local texturefiledataID, item_text, slot_quantity, quality, locked = _G.GetLootSlotInfo(loot_slot) 2252 local texturefiledataID, item_text, slot_quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
2231 local slot_type = _G.GetLootSlotType(loot_slot) 2253 local slot_type = _G.GetLootSlotType(loot_slot)
2232 local loot_info = { _G.GetLootSourceInfo(loot_slot) } 2254 local loot_info = { _G.GetLootSourceInfo(loot_slot) }
2233 local loot_link = _G.GetLootSlotLink(loot_slot) 2255 local loot_link = _G.GetLootSlotLink(loot_slot)
2234 2256
2235 -- Odd index is GUID, even is count. 2257 -- Odd index is GUID, even is count.
2236 for loot_index = 1, #loot_info, 2 do 2258 for loot_index = 1, #loot_info, 2 do
2237 local source_guid = loot_info[loot_index] 2259 local source_guid = loot_info[loot_index]
2238 2260
2246 end 2268 end
2247 local source_type, source_id = ParseGUID(source_guid) 2269 local source_type, source_id = ParseGUID(source_guid)
2248 local source_key = ("%s:%d"):format(source_type, source_id) 2270 local source_key = ("%s:%d"):format(source_type, source_id)
2249 2271
2250 if slot_type == LOOT_SLOT_ITEM then 2272 if slot_type == LOOT_SLOT_ITEM then
2251 if loot_link then 2273 if loot_link then
2252 local item_id = ItemLinkToID(loot_link) 2274 local item_id = ItemLinkToID(loot_link)
2253 Debug("GUID: %s - Type:ID: %s - ItemID: %d - Amount: %d (%d)", loot_info[loot_index], source_key, item_id, loot_info[loot_index + 1], slot_quantity) 2275 Debug("GUID: %s - Type:ID: %s - ItemID: %d - Amount: %d (%d)", loot_info[loot_index], source_key, item_id, loot_info[loot_index + 1], slot_quantity)
2254 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} 2276 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
2255 current_loot.sources[source_guid][item_id] = (current_loot.sources[source_guid][item_id] or 0) + loot_quantity 2277 current_loot.sources[source_guid][item_id] = (current_loot.sources[source_guid][item_id] or 0) + loot_quantity
2256 guids_used[source_guid] = true 2278 guids_used[source_guid] = true
2257 else 2279 else
2258 Debug("%s: Loot link is nil for loot slot %d of the entity with GUID %s and Type:ID: %s.", event_name, loot_slot, loot_info[loot_index], source_key) 2280 Debug("%s: Loot link is nil for loot slot %d of the entity with GUID %s and Type:ID: %s.", event_name, loot_slot, loot_info[loot_index], source_key)
2259 end 2281 end
2260 elseif slot_type == LOOT_SLOT_MONEY then 2282 elseif slot_type == LOOT_SLOT_MONEY then
2261 Debug("GUID: %s - Type:ID: %s - Money - Amount: %d (%d)", loot_info[loot_index], source_key, loot_info[loot_index + 1], slot_quantity) 2283 Debug("GUID: %s - Type:ID: %s - Money - Amount: %d (%d)", loot_info[loot_index], source_key, loot_info[loot_index + 1], slot_quantity)
2267 guids_used[source_guid] = true 2289 guids_used[source_guid] = true
2268 end 2290 end
2269 elseif slot_type == LOOT_SLOT_CURRENCY then 2291 elseif slot_type == LOOT_SLOT_CURRENCY then
2270 -- Same bug with GetLootSlotInfo() will screw up currency when it happens, so we won't process this slot's loot. 2292 -- Same bug with GetLootSlotInfo() will screw up currency when it happens, so we won't process this slot's loot.
2271 if loot_link then 2293 if loot_link then
2272 local icon_texture = CurrencyLinkToTexture(loot_link) 2294 local icon_texture = CurrencyLinkToTexture(loot_link)
2273 Debug("GUID: %s - Type:ID: %s - Currency: %s - Amount: %d (%d)", loot_info[loot_index], source_key, icon_texture, loot_info[loot_index + 1], slot_quantity) 2295 Debug("GUID: %s - Type:ID: %s - Currency: %s - Amount: %d (%d)", loot_info[loot_index], source_key, icon_texture, loot_info[loot_index + 1], slot_quantity)
2274 if current_loot.target_type == AF.ZONE then 2296 if current_loot.target_type == AF.ZONE then
2275 table.insert(current_loot.list, ("currency:%d:%s"):format(loot_quantity, icon_texture)) 2297 table.insert(current_loot.list, ("currency:%d:%s"):format(loot_quantity, icon_texture))
2276 else 2298 else
2277 local currency_token = ("currency:%s"):format(icon_texture) 2299 local currency_token = ("currency:%s"):format(icon_texture)
2629 Forge = forge_spell_ids, 2651 Forge = forge_spell_ids,
2630 } 2652 }
2631 2653
2632 2654
2633 local function RegisterTools(tradeskill_name, tradeskill_index) 2655 local function RegisterTools(tradeskill_name, tradeskill_index)
2634 local link = _G.GetTradeSkillRecipeLink(tradeskill_index) 2656 local link
2657 if (private.isLegion) then
2658 link = _G.C_TradeSkillUI.GetRecipeLink(tradeskill_index)
2659 else
2660 link = _G.GetTradeSkillRecipeLink(tradeskill_index)
2661 end
2662
2635 if link then 2663 if link then
2636 local spell_id = tonumber(link:match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)")) 2664 local spell_id = tonumber(link:match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))
2637 local required_tool = _G.GetTradeSkillTools(tradeskill_index) 2665 local required_tool
2666 if (private.isLegion) then
2667 required_tool = _G.C_TradeSkillUI.GetRecipeTools(tradeskill_index)
2668 else
2669 required_tool = _G.GetTradeSkillTools(tradeskill_index)
2670 end
2638 2671
2639 if required_tool then 2672 if required_tool then
2640 for tool_name, registry in pairs(TRADESKILL_TOOLS) do 2673 for tool_name, registry in pairs(TRADESKILL_TOOLS) do
2641 if required_tool:find(tool_name) then 2674 if required_tool:find(tool_name) then
2642 registry[spell_id] = true 2675 registry[spell_id] = true
2646 end 2679 end
2647 end 2680 end
2648 2681
2649 2682
2650 function WDP:TRADE_SKILL_SHOW(event_name) 2683 function WDP:TRADE_SKILL_SHOW(event_name)
2651 local profession_name, prof_level = _G.GetTradeSkillLine() 2684 local profession_name, prof_level
2685 if private.isLegion then
2686 profession_name, prof_level= _G.C_TradeSkillUI.GetTradeSkillLine()
2687 else
2688 profession_name, prof_level= _G.GetTradeSkillLine()
2689 end
2652 2690
2653 if profession_name == _G.UNKNOWN then 2691 if profession_name == _G.UNKNOWN then
2654 return 2692 return
2655 end 2693 end
2656 TradeSkillExecutePer(RegisterTools) 2694 TradeSkillExecutePer(RegisterTools)