2011-03-08 01:20:01 +00:00
|
|
|
|
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
|
|
|
|
2011-11-20 23:34:19 +00:00
|
|
|
local ItemSearch = LibStub('LibItemSearch-1.0')
|
|
|
|
|
2016-09-09 10:11:16 +00:00
|
|
|
local NUMROWS, SCROLLSTEP = 14, 5
|
2009-08-14 05:09:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
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 rows = {}
|
|
|
|
for i=1,NUMROWS do
|
2016-09-09 10:11:16 +00:00
|
|
|
local row = ns.NewMerchantItemFrame(GVS)
|
2016-09-09 06:52:50 +00:00
|
|
|
|
2016-09-09 10:11:16 +00:00
|
|
|
if i == 1 then
|
|
|
|
row:SetPoint("TOPLEFT")
|
|
|
|
row:SetPoint("RIGHT", -19, 0)
|
2011-03-06 16:37:27 +00:00
|
|
|
else
|
2016-09-09 10:11:16 +00:00
|
|
|
row:SetPoint("TOPLEFT", rows[i-1], "BOTTOMLEFT")
|
|
|
|
row:SetPoint("RIGHT", rows[i-1])
|
2011-03-06 16:37:27 +00:00
|
|
|
end
|
|
|
|
|
2016-09-09 10:11:16 +00:00
|
|
|
rows[i] = row
|
2011-03-06 16:37:27 +00:00
|
|
|
end
|
2009-08-14 05:09:03 +00:00
|
|
|
|
2011-03-08 01:20:01 +00:00
|
|
|
|
2011-03-06 16:37:27 +00:00
|
|
|
local scrollbar = LibStub("tekKonfig-Scroll").new(GVS, 0, SCROLLSTEP)
|
|
|
|
local offset = 0
|
|
|
|
local function Refresh()
|
|
|
|
local n = GetMerchantNumItems()
|
2011-03-08 01:20:01 +00:00
|
|
|
local row, n_searchmatch = 1, 0
|
2011-03-06 16:37:27 +00:00
|
|
|
for i=1,n do
|
|
|
|
local link = GetMerchantItemLink(i)
|
2016-09-09 08:09:57 +00:00
|
|
|
if ItemSearch:Find(link, GVS.searchstring) then
|
2011-03-08 01:20:01 +00:00
|
|
|
if n_searchmatch >= offset and n_searchmatch < offset + NUMROWS then
|
2016-09-09 10:11:16 +00:00
|
|
|
rows[row]:SetValue(i)
|
2011-03-08 01:20:01 +00:00
|
|
|
row = row + 1
|
2011-03-06 16:37:27 +00:00
|
|
|
end
|
2011-03-08 01:20:01 +00:00
|
|
|
n_searchmatch = n_searchmatch + 1
|
2009-08-14 05:09:03 +00:00
|
|
|
end
|
|
|
|
end
|
2011-03-08 01:20:01 +00:00
|
|
|
scrollbar:SetMinMaxValues(0, math.max(0, n_searchmatch - NUMROWS))
|
|
|
|
for i=row,NUMROWS do
|
2011-03-06 16:37:27 +00:00
|
|
|
rows[i]:Hide()
|
|
|
|
end
|
2009-08-14 05:09:03 +00:00
|
|
|
end
|
2015-03-09 09:30:32 +00:00
|
|
|
GVS.CURRENCY_DISPLAY_UPDATE = Refresh
|
|
|
|
GVS.BAG_UPDATE = Refresh
|
|
|
|
GVS.MERCHANT_UPDATE = Refresh
|
2009-08-14 05:09:03 +00:00
|
|
|
|
2011-03-08 01:20:01 +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()
|
2015-03-09 09:30:32 +00:00
|
|
|
|
|
|
|
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
|