GnomishVendorShrinker/GnomishVendorShrinker.lua

272 lines
8.1 KiB
Lua
Raw Normal View History

2010-05-02 22:20:55 +00:00
local myname, ns = ...
2014-12-15 09:49:28 +00:00
2010-05-02 22:20:55 +00:00
local ItemSearch = LibStub('LibItemSearch-1.0')
2009-08-14 05:09:03 +00:00
local NUMROWS, ICONSIZE, GAP, SCROLLSTEP = 14, 17, 4, 5
for _,f in pairs{MerchantNextPageButton, MerchantPrevPageButton, MerchantPageText} do
f:Hide()
f.Show = f.Hide
end
local GVS = CreateFrame("frame", nil, MerchantFrame)
GVS:SetWidth(315)
GVS:SetHeight(294)
2012-08-29 21:38:28 +00:00
GVS:SetPoint("TOPLEFT", 8, -67)
2009-08-14 05:09:03 +00:00
GVS:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
GVS:Hide()
local function OnClick(self, button)
if IsAltKeyDown() and not self.AltCurrency:IsShown() then self:BuyItem(true)
2009-08-14 05:09:03 +00:00
elseif IsModifiedClick() then HandleModifiedItemClick(GetMerchantItemLink(self:GetID()))
elseif self.AltCurrency:IsShown() then
2009-08-14 05:09:03 +00:00
local id = self:GetID()
local link = GetMerchantItemLink(id)
self.link, self.texture = GetMerchantItemLink(id), self.icon:GetTexture()
MerchantFrame_ConfirmExtendedItemCost(self)
else self:BuyItem() end
end
local function PopoutOnClick(self, button)
local id = self:GetParent():GetID()
2009-08-14 05:09:03 +00:00
local link = GetMerchantItemLink(id)
if not link then return end
local _, _, _, vendorStackSize, numAvailable = GetMerchantItemInfo(id)
local maxPurchase = GetMerchantItemMaxStack(id)
local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link)
local size = numAvailable > 0 and numAvailable or itemStackSize
OpenStackSplitFrame(250, self, "LEFT", "RIGHT")
end
local function Purchase(id, quantity)
local _, _, _, vendorStackSize, numAvailable = GetMerchantItemInfo(id)
local maxPurchase = GetMerchantItemMaxStack(id)
2009-08-14 05:09:03 +00:00
if numAvailable > 0 and numAvailable < quantity then quantity = numAvailable end
local purchased = 0
while purchased < quantity do
local buyamount = math.min(maxPurchase, quantity - purchased)
purchased = purchased + buyamount
BuyMerchantItem(id, buyamount)
end
end
local function BuyItem(self, fullstack)
local id = self:GetID()
local link = GetMerchantItemLink(id)
if not link then return end
2010-10-15 05:09:52 +00:00
local _, _, _, vendorStackSize = GetMerchantItemInfo(id)
local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link)
Purchase(id, fullstack and itemStackSize or vendorStackSize or 1)
end
local function PopoutSplitStack(self, qty)
Purchase(self:GetParent():GetID(), qty)
end
local ROWHEIGHT = 21
2009-08-14 05:09:03 +00:00
local rows = {}
for i=1,NUMROWS do
local row = CreateFrame('Button', nil, GVS) -- base frame
row:SetHeight(ROWHEIGHT)
2011-03-08 01:30:52 +00:00
row:SetPoint("TOP", i == 1 and GVS or rows[i-1], i == 1 and "TOP" or "BOTTOM")
2009-08-14 05:09:03 +00:00
row:SetPoint("LEFT")
row:SetPoint("RIGHT", -19, 0)
row.BuyItem = BuyItem
row:SetHighlightTexture("Interface\\HelpFrame\\HelpFrameButton-Highlight")
row:GetHighlightTexture():SetTexCoord(0, 1, 0, 0.578125)
row:RegisterForClicks("AnyUp")
2009-08-14 05:09:03 +00:00
row:SetScript('OnClick', OnClick)
2010-10-15 05:10:47 +00:00
row:RegisterForDrag("LeftButton")
2009-08-14 05:09:03 +00:00
row:SetScript('OnDragStart', function(self, button)
MerchantFrame.extendedCost = nil
PickupMerchantItem(self:GetID())
if self.extendedCost then MerchantFrame.extendedCost = self end
end)
local backdrop = row:CreateTexture(nil, "BACKGROUND")
backdrop:SetAllPoints()
backdrop:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background")
row.backdrop = backdrop
2009-08-14 05:09:03 +00:00
local icon = CreateFrame('Frame', nil, row)
icon:SetHeight(ICONSIZE)
icon:SetWidth(ICONSIZE)
icon:SetPoint('LEFT', 2, 0)
row.icon = icon:CreateTexture(nil, "BORDER")
row.icon:SetAllPoints()
local popout = CreateFrame("Button", nil, row)
popout:SetPoint("RIGHT")
popout:SetWidth(ROWHEIGHT/2) popout:SetHeight(ROWHEIGHT)
popout:SetNormalTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton")
popout:SetHighlightTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton")
popout:GetNormalTexture():SetTexCoord(0.15625, 0.5, 0.84375, 0.5, 0.15625, 0, 0.84375, 0)
popout:GetHighlightTexture():SetTexCoord(0.15625, 1, 0.84375, 1, 0.15625, 0.5, 0.84375, 0.5)
popout:SetScript("OnClick", PopoutOnClick)
popout.SplitStack = PopoutSplitStack
row.popout = popout
2010-05-02 22:20:55 +00:00
local ItemPrice = row:CreateFontString(nil, nil, "NumberFontNormal")
ItemPrice:SetPoint('RIGHT', popout, "LEFT", -2, 0)
2009-08-14 05:09:03 +00:00
row.ItemPrice = ItemPrice
local AltCurrency = ns.NewAltCurrencyFrame(row)
AltCurrency:SetPoint("RIGHT", ItemPrice, "LEFT")
row.AltCurrency = AltCurrency
local ItemName = row:CreateFontString(nil, nil, "GameFontNormalSmall")
ItemName:SetPoint("LEFT", icon, "RIGHT", GAP, 0)
ItemName:SetPoint("RIGHT", AltCurrency, "LEFT", -GAP, 0)
ItemName:SetJustifyH("LEFT")
row.ItemName = ItemName
2009-08-14 05:09:03 +00:00
row:SetScript('OnEnter', function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetMerchantItem(self:GetID())
GameTooltip_ShowCompareItem()
MerchantFrame.itemHover = self:GetID()
if IsModifiedClick("DRESSUP") then ShowInspectCursor() else ResetCursor() end
end)
row:SetScript('OnLeave', function()
GameTooltip:Hide()
ResetCursor()
MerchantFrame.itemHover = nil
end)
rows[i] = row
end
local function ShowMerchantItem(row, i)
row:SetID(i)
row:Show()
local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(i)
local link = GetMerchantItemLink(i)
2015-01-26 09:26:17 +00:00
local gradient, shown = ns.GetRowGradient(i)
row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(gradient))
row.backdrop:SetShown(shown)
2009-08-14 05:09:03 +00:00
row.icon:SetTexture(itemTexture)
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 ""))
2009-08-14 05:09:03 +00:00
row.AltCurrency:SetValue(i)
if extendedCost then
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.extendedCost = nil
end
row.icon:SetVertexColor(ns.GetRowVertexColor(i))
end
2009-08-14 05:09:03 +00:00
local scrollbar = LibStub("tekKonfig-Scroll").new(GVS, 0, SCROLLSTEP)
local offset = 0
local function Refresh()
local n = GetMerchantNumItems()
local row, n_searchmatch = 1, 0
for i=1,n do
local link = GetMerchantItemLink(i)
2016-09-09 08:09:57 +00:00
if ItemSearch:Find(link, GVS.searchstring) then
if n_searchmatch >= offset and n_searchmatch < offset + NUMROWS then
ShowMerchantItem(rows[row], i)
row = row + 1
end
n_searchmatch = n_searchmatch + 1
2009-08-14 05:09:03 +00:00
end
end
scrollbar:SetMinMaxValues(0, math.max(0, n_searchmatch - NUMROWS))
for i=row,NUMROWS do
rows[i]:Hide()
end
2009-08-14 05:09:03 +00:00
end
GVS.CURRENCY_DISPLAY_UPDATE = Refresh
GVS.BAG_UPDATE = Refresh
GVS.MERCHANT_UPDATE = Refresh
2009-08-14 05:09:03 +00:00
2016-09-09 08:09:57 +00:00
ns.MakeSearchField(GVS, Refresh)
2009-08-16 01:43:17 +00:00
2009-08-14 05:09:03 +00:00
local f = scrollbar:GetScript("OnValueChanged")
scrollbar:SetScript("OnValueChanged", function(self, value, ...)
offset = math.floor(value)
Refresh()
return f(self, value, ...)
end)
local offset = 0
GVS:EnableMouseWheel(true)
GVS:SetScript("OnMouseWheel", function(self, value) scrollbar:SetValue(scrollbar:GetValue() - value * SCROLLSTEP) end)
2009-12-21 01:16:08 +00:00
GVS:SetScript("OnShow", function(self, noreset)
local max = math.max(0, GetMerchantNumItems() - NUMROWS)
scrollbar:SetMinMaxValues(0, max)
scrollbar:SetValue(noreset and math.min(scrollbar:GetValue(), max) or 0)
2009-08-14 05:09:03 +00:00
Refresh()
GVS:RegisterEvent("BAG_UPDATE")
GVS:RegisterEvent("MERCHANT_UPDATE")
GVS:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
end)
GVS:SetScript("OnHide", function()
GVS:UnregisterEvent("BAG_UPDATE")
GVS:UnregisterEvent("MERCHANT_UPDATE")
GVS:UnregisterEvent("CURRENCY_DISPLAY_UPDATE")
if StackSplitFrame:IsVisible() then StackSplitFrame:Hide() end
2009-08-14 05:09:03 +00:00
end)
-- Reanchor the buyback button, it acts weird when switching tabs otherwise...
MerchantBuyBackItem:ClearAllPoints()
2012-08-29 21:38:28 +00:00
MerchantBuyBackItem:SetPoint("BOTTOMRIGHT", -7, 33)
2009-08-14 05:09:03 +00:00
local function Show()
for i=1,12 do _G["MerchantItem"..i]:Hide() end
2009-12-21 01:16:08 +00:00
if GVS:IsShown() then GVS:GetScript("OnShow")(GVS, true) else GVS:Show() end
2009-08-14 05:09:03 +00:00
end
hooksecurefunc("MerchantFrame_UpdateMerchantInfo", Show)
hooksecurefunc("MerchantFrame_UpdateBuybackInfo", function()
GVS:Hide()
for i=1,12 do _G["MerchantItem"..i]:Show() end
end)
if MerchantFrame:IsVisible() and MerchantFrame.selectedTab == 1 then Show() end