From ddfcb20040719e50f3b7b6cbc2b0bab9f4ea34b5 Mon Sep 17 00:00:00 2001 From: "James D. Callahan III" Date: Fri, 9 Jul 2010 18:41:14 -0400 Subject: [PATCH] Re-designated FormatRecipeText() as a recipe entry's GetDisplayName() method. --- Frame.lua | 53 +++-------------------------------------------------- core.lua | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/Frame.lua b/Frame.lua index f28a509..511ef32 100644 --- a/Frame.lua +++ b/Frame.lua @@ -187,53 +187,6 @@ function addon:ClosePopups() end ------------------------------------------------------------------------------- -local FormatRecipeText -do - local SKILL_LEVEL_FORMAT = "[%d]" - local SPELL_ENCHANTING = GetSpellInfo(51313) - - function FormatRecipeText(recipe_entry) - local _, _, _, quality_color = GetItemQualityColor(recipe_entry.quality) - local recipe_name = recipe_entry.name - - if ORDERED_PROFESSIONS[addon.Frame.profession] == SPELL_ENCHANTING then - recipe_name = string.gsub(recipe_name, _G.ENSCRIBE.." ", "") - end - local recipe_string = string.format("%s%s|r", quality_color, recipe_name) - - local skill_level = Player["ProfessionLevel"] - local recipe_level = recipe_entry.skill_level - local rep_data = recipe_entry.acquire_data[A.REPUTATION] - local has_faction = Player:HasProperRepLevel(rep_data) - local level_text - local difficulty = private.difficulty_colors - - if not has_faction or recipe_level > skill_level then - level_text = string.format(SetTextColor(difficulty["impossible"], SKILL_LEVEL_FORMAT), recipe_level) - elseif skill_level >= recipe_entry.trivial_level then - level_text = string.format(SetTextColor(difficulty["trivial"], SKILL_LEVEL_FORMAT), recipe_level) - elseif skill_level >= recipe_entry.easy_level then - level_text = string.format(SetTextColor(difficulty["easy"], SKILL_LEVEL_FORMAT), recipe_level) - elseif skill_level >= recipe_entry.medium_level then - level_text = string.format(SetTextColor(difficulty["medium"], SKILL_LEVEL_FORMAT), recipe_level) - elseif skill_level >= recipe_entry.optimal_level then - level_text = string.format(SetTextColor(difficulty["optimal"], SKILL_LEVEL_FORMAT), recipe_level) - else - addon:Debug("Skill level color fallback: %s.", recipe_string) - level_text = string.format(SetTextColor(difficulty["trivial"], SKILL_LEVEL_FORMAT), recipe_level) - end - local skill_view = addon.db.profile.skill_view - - recipe_string = skill_view and string.format("%s - %s", level_text, recipe_string) or string.format("%s - %s", recipe_string, level_text) - - if addon.db.profile.exclusionlist[recipe_entry.spell_id] then - recipe_string = string.format("** %s **", recipe_string) - end - return recipe_string - end -end -- do block - -------------------------------------------------------------------------------- -- Sets show and hide scripts as well as text for a tooltip for the given frame. ------------------------------------------------------------------------------- local SetTooltipScripts @@ -1324,7 +1277,7 @@ do local is_expanded = self[prof_name.." expanded"][recipe_index] - t.text = FormatRecipeText(recipe) + t.text = recipe:GetDisplayName() t.recipe_id = recipe_index recipe_count = recipe_count + 1 @@ -3078,7 +3031,7 @@ do end local is_expanded = current_tab[prof_name.." expanded"][spell_id] and current_tab[prof_name.." expanded"][private.acquire_names[acquire_id]] - t.text = FormatRecipeText(recipe_entry) + t.text = recipe_entry:GetDisplayName() t.recipe_id = spell_id t.acquire_id = acquire_id @@ -3121,7 +3074,7 @@ do end local is_expanded = current_tab[prof_name.." expanded"][spell_id] and current_tab[prof_name.." expanded"][location_id] - t.text = FormatRecipeText(recipe_entry) + t.text = recipe_entry:GetDisplayName() t.recipe_id = spell_id t.location_id = location_id diff --git a/core.lua b/core.lua index 24011b9..35ec778 100644 --- a/core.lua +++ b/core.lua @@ -831,7 +831,7 @@ do local SF = private.recipe_state_flags ------------------------------------------------------------------------------- - -- Recipe member functions for bit flags. + -- Recipe methods. ------------------------------------------------------------------------------- local function Recipe_HasState(self, state_name) return self.state and (bit.band(self.state, SF[state_name]) == SF[state_name]) or false @@ -879,6 +879,53 @@ do return bitfield and (bit.band(bitfield, value) == value) or false end + local Recipe_GetDisplayName + do + local SKILL_LEVEL_FORMAT = "[%d]" + local SPELL_ENCHANTING = GetSpellInfo(51313) + + function Recipe_GetDisplayName(recipe_entry) + local _, _, _, quality_color = GetItemQualityColor(recipe_entry.quality) + local recipe_name = recipe_entry.name + + if private.ordered_professions[addon.Frame.profession] == SPELL_ENCHANTING then + recipe_name = string.gsub(recipe_name, _G.ENSCRIBE.." ", "") + end + local recipe_string = string.format("%s%s|r", quality_color, recipe_name) + local skill_level = Player["ProfessionLevel"] + local recipe_level = recipe_entry.skill_level + local has_faction = Player:HasProperRepLevel(recipe_entry.acquire_data[A.REPUTATION]) + + local diff_color + + if not has_faction or recipe_level > skill_level then + diff_color = "impossible" + elseif skill_level >= recipe_entry.trivial_level then + diff_color = "trivial" + elseif skill_level >= recipe_entry.easy_level then + diff_color = "easy" + elseif skill_level >= recipe_entry.medium_level then + diff_color = "medium" + elseif skill_level >= recipe_entry.optimal_level then + diff_color = "optimal" + else + addon:Debug("Skill level color fallback: %s.", recipe_string) + diff_color = "trivial" + end + local level_text = string.format(private.SetTextColor(private.difficulty_colors[diff_color], SKILL_LEVEL_FORMAT), recipe_level) + + local skill_view = addon.db.profile.skill_view + + recipe_string = skill_view and string.format("%s - %s", level_text, recipe_string) or string.format("%s - %s", recipe_string, level_text) + + if addon.db.profile.exclusionlist[recipe_entry.spell_id] then + recipe_string = string.format("** %s **", recipe_string) + end + return recipe_string + end + end -- do block + + --- Adds a tradeskill recipe into the specified recipe database -- @name AckisRecipeList:AddRecipe -- @usage AckisRecipeList:AddRecipe(28927, 305, 23109, Q.UNCOMMON, V.TBC, 305, 305, 325, 345) @@ -925,6 +972,7 @@ do ["AddState"] = Recipe_AddState, ["RemoveState"] = Recipe_RemoveState, ["IsFlagged"] = Recipe_IsFlagged, + ["GetDisplayName"] = Recipe_GetDisplayName, } if not recipe.name then -- 1.7.9.5