From 9c853b301e35f1f62ff2a30cafba80fbe4739172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tekkub=20=CA=95=20=C2=B4=E1=B4=A5=60=20=CA=94?= Date: Thu, 8 Sep 2016 18:05:26 -0600 Subject: [PATCH] Split row color logic out into its own file --- GnomishVendorShrinker.lua | 69 ++++------------------------ GnomishVendorShrinker.toc | 1 + RowShader.lua | 95 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 61 deletions(-) create mode 100644 RowShader.lua diff --git a/GnomishVendorShrinker.lua b/GnomishVendorShrinker.lua index 5dd2419..d2293a8 100644 --- a/GnomishVendorShrinker.lua +++ b/GnomishVendorShrinker.lua @@ -43,7 +43,6 @@ local function PopoutOnClick(self, button) local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link) local size = numAvailable > 0 and numAvailable or itemStackSize - -- OpenStackSplitFrame(size, self, "LEFT", "RIGHT") OpenStackSplitFrame(250, self, "LEFT", "RIGHT") end @@ -227,71 +226,18 @@ for i=1,NUMROWS do end -local RECIPE = GetItemClassInfo(LE_ITEM_CLASS_RECIPE) -local MISC = GetItemClassInfo(LE_ITEM_CLASS_MISCELLANEOUS) -local GARRISON_ICON = {[1001489] = true, [1001490] = true, [1001491] = true} -local function Knowable(link) - local name, link2, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(link) - local id = ns.ids[link] - - if C_Heirloom.IsItemHeirloom(id) then return true end - if class == MISC and select(2, C_ToyBox.GetToyInfo(id)) then return true end - if class == RECIPE or GARRISON_ICON[texture] then return true end -end - - -local function RecipeNeedsRank(link) - local _, _, _, _, _, class = GetItemInfo(link) - if class ~= RECIPE then return end - return ns.unmet_requirements[link] -end - - -local default_grad = {0,1,0,0.75, 0,1,0,0} -- green -local grads = setmetatable({ - red = {1,0,0,0.75, 1,0,0,0}, - [1] = {1,1,1,0.75, 1,1,1,0}, -- white - [2] = default_grad, -- green - [3] = {0.5,0.5,1,1, 0,0,1,0}, -- blue - [4] = {1,0,1,0.75, 1,0,1,0}, -- purple - [7] = {1,.75,.5,0.75, 1,.75,.5,0}, -- heirloom -}, {__index = function(t,i) t[i] = default_grad return default_grad end}) -local quality_colors = setmetatable({}, {__index = function() return "|cffffffff" end}) -for i=0,7 do quality_colors[i] = "|c".. select(4, GetItemQualityColor(i)) end - local function ShowMerchantItem(row, i) local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(i) local link = GetMerchantItemLink(i) - local color = quality_colors.default - row.backdrop:Hide() - if not isUsable then - row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads.red)) - row.backdrop:Show() - end - - if link then - local name, link2, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(link) - local id = ns.ids[link] - local is_heirloom = C_Heirloom.IsItemHeirloom(id) - color = quality_colors[quality] - - if Knowable(link) then - if ns.knowns[link] then - color = quality_colors[0] - row.backdrop:Hide() - elseif RecipeNeedsRank(link) then - row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads.red)) - row.backdrop:Show() - else - row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads[quality])) - row.backdrop:Show() - end - end - end + local gradient, shown = ns.GetRowGradient(i) + row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(gradient)) + row.backdrop:SetShown(shown) row.icon:SetTexture(itemTexture) - row.ItemName:SetText((numAvailable > -1 and ("["..numAvailable.."] ") or "").. color.. (name or "").. (itemStackCount > 1 and ("|r x"..itemStackCount) or "")) + + local textcolor = ns.GetRowTextColor(i) + row.ItemName:SetText((numAvailable > -1 and ("["..numAvailable.."] ") or "").. textcolor.. (name or "").. (itemStackCount > 1 and ("|r x"..itemStackCount) or "")) for i,v in pairs(row.altframes) do v:Hide() end row.altcurrency = extendedCost @@ -313,7 +259,8 @@ local function ShowMerchantItem(row, i) row.extendedCost = nil end - if isUsable then row.icon:SetVertexColor(1, 1, 1) else row.icon:SetVertexColor(.9, 0, 0) end + row.icon:SetVertexColor(ns.GetRowVertexColor(i)) + row:SetID(i) row:Show() end diff --git a/GnomishVendorShrinker.toc b/GnomishVendorShrinker.toc index 9dd8720..6338a21 100644 --- a/GnomishVendorShrinker.toc +++ b/GnomishVendorShrinker.toc @@ -17,5 +17,6 @@ tekFunks\gsc.lua tekKonfig\tekKonfig.xml LibItemSearch-1.0.lua +RowShader.lua KnownScanner.lua GnomishVendorShrinker.lua diff --git a/RowShader.lua b/RowShader.lua new file mode 100644 index 0000000..090e178 --- /dev/null +++ b/RowShader.lua @@ -0,0 +1,95 @@ + +local myname, ns = ... + + + +local RECIPE = GetItemClassInfo(LE_ITEM_CLASS_RECIPE) +local MISC = GetItemClassInfo(LE_ITEM_CLASS_MISCELLANEOUS) +local GARRISON_ICONS = {[1001489] = true, [1001490] = true, [1001491] = true} + + +local function Knowable(link) + local id = ns.ids[link] + if C_Heirloom.IsItemHeirloom(id) then return true end + + local _, _, _, _, _, class, _, _, _, texture = GetItemInfo(link) + if class == MISC and select(2, C_ToyBox.GetToyInfo(id)) then return true end + if class == RECIPE or GARRISON_ICONS[texture] then return true end +end + + +local function RecipeNeedsRank(link) + local _, _, _, _, _, class = GetItemInfo(link) + if class ~= RECIPE then return end + return ns.unmet_requirements[link] +end + + +local DEFAULT_GRAD = {0,1,0,0.75, 0,1,0,0} -- green +local GRADS = { + red = {1,0,0,0.75, 1,0,0,0}, + [1] = {1,1,1,0.75, 1,1,1,0}, -- white + [2] = DEFAULT_GRAD, -- green + [3] = {0.5,0.5,1,1, 0,0,1,0}, -- blue + [4] = {1,0,1,0.75, 1,0,1,0}, -- purple + [7] = {1,.75,.5,0.75, 1,.75,.5,0}, -- heirloom +} +GRADS = setmetatable(GRADS, { + __index = function(t,i) + t[i] = DEFAULT_GRAD + return DEFAULT_GRAD + end +}) + + +function ns.GetRowGradient(index) + local gradient = DEFAULT_GRAD + local shown = false + + local _, _, _, _, _, isUsable = GetMerchantItemInfo(index) + if not isUsable then + gradient = GRADS.red + shown = true + end + + local link = GetMerchantItemLink(index) + if not (link and Knowable(link)) then return gradient, shown end + + if ns.knowns[link] then + return gradient, false + elseif RecipeNeedsRank(link) then + return GRADS.red, true + else + return GRADS[quality], true + end +end + + +local QUALITY_COLORS = setmetatable({}, { + __index = function(t,i) + -- GetItemQualityColor only takes numbers, so fall back to white + local _, _, _, hex = GetItemQualityColor(tonumber(i) or 1) + t[i] = "|c".. hex + return "|c".. hex + end +}) + + +function ns.GetRowTextColor(index) + local link = GetMerchantItemLink(index) + if not link then return QUALITY_COLORS.default end + + -- Grey out if already known + if Knowable(link) and ns.knowns[link] then return QUALITY_COLORS[0] end + + local _, _, quality = GetItemInfo(link) + return QUALITY_COLORS[quality] +end + + +function ns.GetRowVertexColor(index) + local _, _, _, _, _, isUsable = GetMerchantItemInfo(index) + if isUsable then return 1.0, 1.0, 1.0 + else return 0.9, 0.0, 0.0 + end +end