From 461a1bee39c35b1c8f742bc45a08869551704abb Mon Sep 17 00:00:00 2001 From: torhal Date: Sun, 14 Feb 2010 07:19:24 +0000 Subject: [PATCH] Re-wrote addon:hexcolor() to use a table, with its values prepended by "|cff", instead of a large if-else chain. In ttAdd(): Removed "|cff" since it's now automatically included in the color codes which are passed to it. In GenerateTooltipContent() and MainPanel.scroll_frame:Update() - in the WORLD_DROP acquire type section - replaced colorizing by the acquire ID with colorizing by the recipe's quality. The acquire ID in this case was also the rarity, and should be replaced by something more useful. This also fixes an inconsistency between how the two functions handled the colorizing. --- Colour.lua | 89 +++++++++++++++++++++++++++++++++--------------------------- Frame.lua | 25 ++++++----------- 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/Colour.lua b/Colour.lua index 9412334..52e3ffe 100644 --- a/Colour.lua +++ b/Colour.lua @@ -259,44 +259,53 @@ function addon:Normal(text) return self:Colourize(NORMAL, text) end --- used for tooltip rgb stuff -function addon:hexcolor(colorstring) - if (colorstring == "NEUTRAL") then return NEUTRAL - elseif (colorstring == "FRIENDLY") then return FRIENDLY - elseif (colorstring == "HONORED") then return HONORED - elseif (colorstring == "REVERED") then return REVERED - elseif (colorstring == "EXALTED") then return EXALTED - - elseif (colorstring == "TRAINER") then return TRAINER - elseif (colorstring == "VENDOR") then return VENDOR - elseif (colorstring == "QUEST") then return QUEST - elseif (colorstring == "REP") then return REP - elseif (colorstring == "SEASON") then return SEASON - elseif (colorstring == "MOBDROP") then return MOBDROP - - elseif (colorstring == "POOR") then return POOR - elseif (colorstring == "COMMON") then return COMMON - elseif (colorstring == "UNCOMMON") then return UNCOMMON - elseif (colorstring == "RARE") then return RARE - elseif (colorstring == "EPIC") then return EPIC - elseif (colorstring == "LEGENDARY") then return LEGENDARY - elseif (colorstring == "ARTIFACT") then return ARTIFACT - - elseif (colorstring == "HORDE") then return HORDE - elseif (colorstring == "ALLIANCE") then return ALLIANCE - - elseif (colorstring == "BLACK") then return BLACK - elseif (colorstring == "ORANGE") then return ORANGE - elseif (colorstring == "GREEN") then return GREEN - elseif (colorstring == "YELLOW") then return YELLOW - elseif (colorstring == "GREY") then return GREY - elseif (colorstring == "MIDGREY") then return MIDGREY - elseif (colorstring == "RED") then return RED - - elseif (colorstring == "HIGH") then return HIGH --- elseif (colorstring == "NORMAL") then return NORMAL - else - return NORMAL +------------------------------------------------------------------------------- +-- Colorize a string based off of a name entry. +------------------------------------------------------------------------------- +do + local COLOR_NAMES = { + ["NEUTRAL"] = "|cff"..NEUTRAL, + ["FRIENDLY"] = "|cff"..FRIENDLY, + ["HONORED"] = "|cff"..HONORED, + ["REVERED"] = "|cff"..REVERED, + ["EXALTED"] = "|cff"..EXALTED, + + ["TRAINER"] = "|cff"..TRAINER, + ["VENDOR"] = "|cff"..VENDOR, + ["QUEST"] = "|cff"..QUEST, + ["REP"] = "|cff"..REP, + ["SEASON"] = "|cff"..SEASON, + ["MOBDROP"] = "|cff"..MOBDROP, + + ["POOR"] = "|cff"..POOR, + ["COMMON"] = "|cff"..COMMON, + ["UNCOMMON"] = "|cff"..UNCOMMON, + ["RARE"] = "|cff"..RARE, + ["EPIC"] = "|cff"..EPIC, + ["LEGENDARY"] = "|cff"..LEGENDARY, + ["ARTIFACT"] = "|cff"..ARTIFACT, + + ["HORDE"] = "|cff"..HORDE, + ["ALLIANCE"] = "|cff"..ALLIANCE, + + ["BLACK"] = "|cff"..BLACK, + ["ORANGE"] = "|cff"..ORANGE, + ["GREEN"] = "|cff"..GREEN, + ["YELLOW"] = "|cff"..YELLOW, + ["GREY"] = "|cff"..GREY, + ["MIDGREY"] = "|cff"..MIDGREY, + ["RED"] = "|cff"..RED, + + ["HIGH"] = "|cff"..HIGH, + } + + function addon:hexcolor(colorstring) + local color = COLOR_NAMES[colorstring] + + if not color then + return "|cff"..NORMAL + end + + return color end ----------------------------------------------------------------------- -end +end -- do diff --git a/Frame.lua b/Frame.lua index 715bfcf..b10ce66 100644 --- a/Frame.lua +++ b/Frame.lua @@ -521,14 +521,14 @@ do if str2 then local lineNum = acquire_tip:AddLine() - acquire_tip:SetCell(lineNum, 1, "|cff"..hexcolor1..leftStr.."|r") - acquire_tip:SetCell(lineNum, 2, "|cff"..hexcolor2..str2.."|r", "RIGHT") + acquire_tip:SetCell(lineNum, 1, hexcolor1..leftStr.."|r") + acquire_tip:SetCell(lineNum, 2, hexcolor2..str2.."|r", "RIGHT") else -- Text spans both columns - set maximum width to match fontSize to maintain uniform tooltip size. -Torhal local width = math.ceil(fontSize * 37.5) local lineNum = acquire_tip:AddLine() - acquire_tip:SetCell(lineNum, 1, "|cff"..hexcolor1..leftStr.."|r", nil, "LEFT", 2, nil, 0, 0, width, width) + acquire_tip:SetCell(lineNum, 1, hexcolor1..leftStr.."|r", nil, "LEFT", 2, nil, 0, 0, width, width) end end @@ -634,7 +634,7 @@ do acquire_tip:Clear() acquire_tip:SetScale(addon.db.profile.frameopts.tooltipscale) acquire_tip:AddHeader() - acquire_tip:SetCell(1, 1, "|cff"..addon:hexcolor("HIGH")..recipe_entry.name, "CENTER", 2) + acquire_tip:SetCell(1, 1, addon:hexcolor("HIGH")..recipe_entry.name, "CENTER", 2) -- check if the recipe is excluded local exclude = addon.db.profile.exclusionlist @@ -816,17 +816,8 @@ do elseif acquire_type == A.WORLD_DROP then local acquire_id = acquire.ID - if acquire_id == 1 then - color_1 = addon:hexcolor("COMMON") - elseif acquire_id == 2 then - color_1 = addon:hexcolor("UNCOMMON") - elseif acquire_id == 3 then - color_1 = addon:hexcolor("RARE") - elseif acquire_id == 4 then - color_1 = addon:hexcolor("EPIC") - else - color_1 = addon:hexcolor("NORMAL") - end + color_1 = select(4, GetItemQualityColor(recipe_entry.quality)) + ttAdd(0, -1, false, L["World Drop"], color_1) elseif acquire_type == A.CUSTOM then ttAdd(0, -1, false, private.custom_list[acquire.ID].name, addon:hexcolor("NORMAL")) @@ -2520,7 +2511,9 @@ do entry_index = entry_index + 1 end elseif acquire_type == A.WORLD_DROP and obtain_filters.worlddrop then - t.text = pad .. addon:RarityColor(acquire.ID + 1, L["World Drop"]) + local hex_color = select(4, GetItemQualityColor(private.recipe_list[recipe_id].quality)) + + t.text = pad..hex_color..L["World Drop"].."|r" tinsert(self.entries, entry_index, t) entry_index = entry_index + 1 elseif acquire_type == A.CUSTOM then -- 1.7.9.5