From 5240f4f084ebe16d547e719fa89045237c9aff48 Mon Sep 17 00:00:00 2001 From: "James D. Callahan III" Date: Fri, 28 May 2010 08:26:45 -0400 Subject: [PATCH] Split code from ListFrame:Initialize() into AcquisitionTab:Initialize() and LocationTab:Initialize(). --- Frame.lua | 166 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 93 insertions(+), 73 deletions(-) diff --git a/Frame.lua b/Frame.lua index 5fa3370..dd6aee0 100644 --- a/Frame.lua +++ b/Frame.lua @@ -1097,6 +1097,95 @@ do MainPanel:Hide() end -- do-block +-- Used for Location and Acquisition sort - since many recipes have multiple locations/acquire types it is +-- necessary to ensure each is counted only once. +local recipe_registry = {} + +function AcquisitionTab:Initialize(expand_mode) + local sorted_acquires = addon.sorted_acquires + local current_prof = Player.current_prof + local search_box = MainPanel.search_editbox + + local recipe_count = 0 + local insert_index = 1 + + twipe(recipe_registry) + SortAcquireList() + + for index = 1, #sorted_acquires do + local acquire_type = sorted_acquires[index] + local count = 0 + + -- Check to see if any recipes for this acquire type will be shown - otherwise, don't show the type in the list. + for spell_id, affiliation in pairs(private.acquire_list[acquire_type].recipes) do + local recipe = private.recipe_list[spell_id] + + if recipe:HasState("VISIBLE") and search_box:MatchesRecipe(recipe) then + count = count + 1 + + if not recipe_registry[recipe] then + recipe_registry[recipe] = true + recipe_count = recipe_count + 1 + end + end + end + + if count > 0 then + local t = AcquireTable() + + local acquire_str = string.gsub(private.acquire_strings[acquire_type]:lower(), "_", "") + local color_code = private.category_colors[acquire_str] or "ffffff" + + t.text = string.format("%s (%d)", SetTextColor(color_code, private.acquire_names[acquire_type]), count) + t.acquire_id = acquire_type + + insert_index = ListFrame:InsertEntry(t, nil, insert_index, "header", expand_mode, expand_mode) + end + end + return recipe_count +end + +function LocationTab:Initialize(expand_mode) + local sorted_locations = addon.sorted_locations + local current_prof = Player.current_prof + local search_box = MainPanel.search_editbox + + local recipe_count = 0 + local insert_index = 1 + + twipe(recipe_registry) + SortLocationList() + + for index = 1, #sorted_locations do + local loc_name = sorted_locations[index] + local count = 0 + + -- Check to see if any recipes for this location will be shown - otherwise, don't show the location in the list. + for spell_id, affiliation in pairs(private.location_list[loc_name].recipes) do + local recipe = private.recipe_list[spell_id] + + if recipe:HasState("VISIBLE") and search_box:MatchesRecipe(recipe) then + count = count + 1 + + if not recipe_registry[recipe] then + recipe_registry[recipe] = true + recipe_count = recipe_count + 1 + end + end + end + + if count > 0 then + local t = AcquireTable() + + t.text = string.format("%s (%d)", SetTextColor(private.category_colors["location"], loc_name), count) + t.location_id = loc_name + + insert_index = ListFrame:InsertEntry(t, nil, insert_index, "header", expand_mode, expand_mode) + end + end + return recipe_count +end + ------------------------------------------------------------------------------- -- MainPanel scripts/functions. ------------------------------------------------------------------------------- @@ -3069,14 +3158,11 @@ do return insert_index end - -- Used for Location and Acquisition sort - since many recipes have multiple locations/acquire types it is - -- necessary to ensure each is counted only once. - local recipe_registry = {} - function ListFrame:Initialize(expand_mode) local recipe_list = private.recipe_list local sort_type = addon.db.profile.sorting local current_tab = addon.db.profile.current_tab + local search_box = MainPanel.search_editbox local recipe_count = 0 local insert_index = 1 @@ -3085,7 +3171,6 @@ do ReleaseTable(self.entries[i]) end twipe(self.entries) - twipe(recipe_registry) addon:UpdateFilters(MainPanel.is_linked) Player:MarkExclusions() @@ -3093,74 +3178,9 @@ do ExpandButton:Contract() if current_tab == VIEW_TABS["Acquisition"] then - local sorted_acquires = addon.sorted_acquires - local current_prof = Player.current_prof - - SortAcquireList() - - for index = 1, #sorted_acquires do - local acquire_type = sorted_acquires[index] - local count = 0 - - -- Check to see if any recipes for this acquire type will be shown - otherwise, don't show the type in the list. - for spell_id, affiliation in pairs(private.acquire_list[acquire_type].recipes) do - local recipe = private.recipe_list[spell_id] - - if recipe:HasState("VISIBLE") and RecipeMatchesSearch(recipe) then - count = count + 1 - - if not recipe_registry[recipe] then - recipe_registry[recipe] = true - recipe_count = recipe_count + 1 - end - end - end - - if count > 0 then - local t = AcquireTable() - - local acquire_str = string.gsub(private.acquire_strings[acquire_type]:lower(), "_", "") - local color_code = private.category_colors[acquire_str] or "ffffff" - - t.text = string.format("%s (%d)", SetTextColor(color_code, private.acquire_names[acquire_type]), count) - t.acquire_id = acquire_type - - insert_index = self:InsertEntry(t, nil, insert_index, "header", expand_mode, expand_mode) - end - end + recipe_count = AcquisitionTab:Initialize(expand_mode) elseif current_tab == VIEW_TABS["Location"] then - local sorted_locations = addon.sorted_locations - local current_prof = Player.current_prof - - SortLocationList() - - for index = 1, #sorted_locations do - local loc_name = sorted_locations[index] - local count = 0 - - -- Check to see if any recipes for this location will be shown - otherwise, don't show the location in the list. - for spell_id, affiliation in pairs(private.location_list[loc_name].recipes) do - local recipe = private.recipe_list[spell_id] - - if recipe:HasState("VISIBLE") and RecipeMatchesSearch(recipe) then - count = count + 1 - - if not recipe_registry[recipe] then - recipe_registry[recipe] = true - recipe_count = recipe_count + 1 - end - end - end - - if count > 0 then - local t = AcquireTable() - - t.text = string.format("%s (%d)", SetTextColor(private.category_colors["location"], loc_name), count) - t.location_id = loc_name - - insert_index = self:InsertEntry(t, nil, insert_index, "header", expand_mode, expand_mode) - end - end + recipe_count = LocationTab:Initialize(expand_mode) else local sorted_recipes = addon.sorted_recipes @@ -3170,7 +3190,7 @@ do local recipe_index = sorted_recipes[i] local recipe = recipe_list[recipe_index] - if recipe:HasState("VISIBLE") and RecipeMatchesSearch(recipe) then + if recipe:HasState("VISIBLE") and search_box:MatchesRecipe(recipe) then local t = AcquireTable() t.text = FormatRecipeText(recipe) -- 1.7.9.5