Split row color logic out into its own file

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ 2016-09-08 18:05:26 -06:00
parent 8d2d5629cb
commit 9c853b301e
3 changed files with 104 additions and 61 deletions

View File

@ -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 "<Loading item data>").. (itemStackCount > 1 and ("|r x"..itemStackCount) or ""))
local textcolor = ns.GetRowTextColor(i)
row.ItemName:SetText((numAvailable > -1 and ("["..numAvailable.."] ") or "").. textcolor.. (name or "<Loading item data>").. (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

View File

@ -17,5 +17,6 @@ tekFunks\gsc.lua
tekKonfig\tekKonfig.xml
LibItemSearch-1.0.lua
RowShader.lua
KnownScanner.lua
GnomishVendorShrinker.lua

95
RowShader.lua Normal file
View File

@ -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