From 687717f3250b0f556ac7ffdd5fe4b208e33b1023 Mon Sep 17 00:00:00 2001 From: Harm Geerts Date: Sun, 6 Mar 2011 17:37:27 +0100 Subject: [PATCH 1/3] integrate LibItemSearch into GnomishVendorShrinker and hide items which do not match the search --- .gitmodules | 6 ++ GnomishVendorShrinker.lua | 124 ++++++++++++++++++++------------------ embeds.xml | 4 ++ libs/LibItemSearch-1.0 | 1 + libs/LibStub | 1 + 5 files changed, 79 insertions(+), 57 deletions(-) create mode 100644 .gitmodules create mode 100644 embeds.xml create mode 160000 libs/LibItemSearch-1.0 create mode 160000 libs/LibStub diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b0b6358 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "libs/LibItemSearch-1.0"] + path = libs/LibItemSearch-1.0 + url = git@github.com:Tuller/LibItemSearch-1.0.git +[submodule "libs/LibStub"] + path = libs/LibStub + url = git://github.com/p3lim/LibStub.git diff --git a/GnomishVendorShrinker.lua b/GnomishVendorShrinker.lua index 7936476..c76340f 100644 --- a/GnomishVendorShrinker.lua +++ b/GnomishVendorShrinker.lua @@ -1,4 +1,4 @@ - +local ItemSearch = LibStub('LibItemSearch-1.0') local myname, ns = ... ns.IHASCAT = select(4, GetBuildInfo()) >= 40000 @@ -167,7 +167,6 @@ local rows = {} for i=1,NUMROWS do local row = CreateFrame('Button', nil, GVS) -- base frame row:SetHeight(ROWHEIGHT) - row:SetPoint("TOP", i == 1 and GVS or rows[i-1], i == 1 and "TOP" or "BOTTOM") row:SetPoint("LEFT") row:SetPoint("RIGHT", -19, 0) @@ -247,71 +246,83 @@ local grads = setmetatable({ [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 _, _, _, _, _, _, RECIPE = GetAuctionItemClasses() +local RECIPE = select(7, GetAuctionItemClasses()) local quality_colors = setmetatable({}, {__index = function() return "|cffffffff" end}) for i=1,7 do quality_colors[i] = select(4, GetItemQualityColor(i)) end + +local ShowMerchantItem = function (r, i) + local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(i) + local link = GetMerchantItemLink(i) + local color = quality_colors.default + local row = rows[r] + row.backdrop:Hide() + if link then + local name, link2, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(link) + color = quality_colors[quality] + + if class == RECIPE and not ns.knowns[link] then + row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads[quality])) + row.backdrop:Show() + end + end + + if not isUsable then + row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads.red)) + row.backdrop:Show() + end + + row.icon:SetTexture(itemTexture) + row.ItemName:SetText((numAvailable > -1 and ("["..numAvailable.."] ") or "").. color.. (name or "").. (itemStackCount > 1 and ("|r x"..itemStackCount) or "")) + + for i,v in pairs(row.altframes) do v:Hide() end + row.altcurrency = extendedCost + if extendedCost then + row:AddAltCurrency(i) + row.link, row.texture, row.extendedCost = link, itemTexture, true + end + if itemPrice > 0 then + row.ItemPrice:SetText(ns.GSC(itemPrice)) + row.Price = itemPrice + end + if extendedCost and (itemPrice <= 0) then + row.ItemPrice:SetText() + row.Price = 0 + elseif extendedCost and (itemPrice > 0) then + row.ItemPrice:SetText(ns.GSC(itemPrice)) + else + row.ItemName:SetPoint("RIGHT", row.ItemPrice, "LEFT", -GAP, 0) + row.extendedCost = nil + end + + if isUsable then row.icon:SetVertexColor(1, 1, 1) else row.icon:SetVertexColor(.9, 0, 0) end + row:SetID(i) + row:Show() + row:SetPoint("TOP", r == 1 and GVS or rows[r-1], r == 1 and "TOP" or "BOTTOM") +end + +local scrollbar = LibStub("tekKonfig-Scroll").new(GVS, 0, SCROLLSTEP) local offset = 0 local searchstring local function Refresh() local n = GetMerchantNumItems() - for i,row in pairs(rows) do - local j = i + offset - if j > n then - row:Hide() - else - row.backdrop:Hide() - - local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(j) - local link = GetMerchantItemLink(j) - local color = quality_colors.default - if link then - local name, link2, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(link) - color = quality_colors[quality] - - if class == RECIPE and not ns.knowns[link] then - row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads[quality])) - row.backdrop:Show() - end + local r = 1 + local v = 0 + for i=1,n do + local link = GetMerchantItemLink(i) + if ItemSearch:Find(link, searchstring) then + if v >= offset and v < offset + NUMROWS then + ShowMerchantItem(r, i) + r = r + 1 end - - if not isUsable then - row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads.red)) - row.backdrop:Show() - end - - row:SetAlpha(searchstring and name and not name:lower():match(searchstring) and 0.5 or 1) - - row.icon:SetTexture(itemTexture) - row.ItemName:SetText((numAvailable > -1 and ("["..numAvailable.."] ") or "").. color.. (name or "").. (itemStackCount > 1 and ("|r x"..itemStackCount) or "")) - - for i,v in pairs(row.altframes) do v:Hide() end - row.altcurrency = extendedCost - if extendedCost then - row:AddAltCurrency(j) - row.link, row.texture, row.extendedCost = link, itemTexture, true - end - if itemPrice > 0 then - row.ItemPrice:SetText(ns.GSC(itemPrice)) - row.Price = itemPrice - end - if extendedCost and (itemPrice <= 0) then - row.ItemPrice:SetText() - row.Price = 0 - elseif extendedCost and (itemPrice > 0) then - row.ItemPrice:SetText(ns.GSC(itemPrice)) - else - row.ItemName:SetPoint("RIGHT", row.ItemPrice, "LEFT", -GAP, 0) - row.extendedCost = nil - end - - if isUsable then row.icon:SetVertexColor(1, 1, 1) else row.icon:SetVertexColor(.9, 0, 0) end - row:SetID(j) - row:Show() + v = v + 1 end end + scrollbar:SetMinMaxValues(0, math.max(0, v - NUMROWS)) + for i=r,NUMROWS do + rows[i]:Hide() + end end - local editbox = CreateFrame('EditBox', nil, GVS) editbox:SetAutoFocus(false) editbox:SetPoint("TOPLEFT", GVS, "BOTTOMLEFT", 0, -51) @@ -362,7 +373,6 @@ editbox:SetScript("OnShow", function(self) self:SetTextColor(0.75, 0.75, 0.75, 1) end) -local scrollbar = LibStub("tekKonfig-Scroll").new(GVS, 0, SCROLLSTEP) local f = scrollbar:GetScript("OnValueChanged") scrollbar:SetScript("OnValueChanged", function(self, value, ...) offset = math.floor(value) diff --git a/embeds.xml b/embeds.xml new file mode 100644 index 0000000..01090f6 --- /dev/null +++ b/embeds.xml @@ -0,0 +1,4 @@ + +