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
|
|
|
|
2016-09-11 10:10:05 +00:00
|
|
|
local ItemSearch = ns.LibItemSearch
|
|
|
|
ns.LibItemSearch = nil
|
|
|
|
|
2011-11-20 23:34:19 +00:00
|
|
|
|
2016-09-12 00:28:04 +00:00
|
|
|
local NUMROWS = 14
|
2009-08-14 05:09:03 +00:00
|
|
|
|
|
|
|
|
2016-09-12 00:28:04 +00:00
|
|
|
function ns.NewMainFrame()
|
2016-09-12 02:21:48 +00:00
|
|
|
local GVS = CreateFrame("frame", nil, MerchantBuyBackItem)
|
2011-03-06 16:37:27 +00:00
|
|
|
|
2016-09-12 01:45:02 +00:00
|
|
|
local search = ns.MakeSearchField(GVS)
|
2016-09-12 01:28:47 +00:00
|
|
|
|
2016-09-11 01:02:40 +00:00
|
|
|
local rows = {}
|
|
|
|
for i=1,NUMROWS do
|
|
|
|
local row = ns.NewMerchantItemFrame(GVS)
|
|
|
|
|
|
|
|
if i == 1 then
|
|
|
|
row:SetPoint("TOPLEFT")
|
|
|
|
row:SetPoint("RIGHT", -19, 0)
|
|
|
|
else
|
|
|
|
row:SetPoint("TOPLEFT", rows[i-1], "BOTTOMLEFT")
|
|
|
|
row:SetPoint("RIGHT", rows[i-1])
|
|
|
|
end
|
|
|
|
|
|
|
|
rows[i] = row
|
|
|
|
end
|
2009-08-14 05:09:03 +00:00
|
|
|
|
2016-09-12 00:28:04 +00:00
|
|
|
local scrollbar = ns.NewScrollBar(GVS, 0, 5)
|
2016-09-12 01:45:02 +00:00
|
|
|
local function Refresh()
|
2016-09-11 10:12:42 +00:00
|
|
|
local offset = scrollbar:GetValue()
|
2016-09-12 01:28:47 +00:00
|
|
|
local searchstring = search:GetText()
|
2016-09-11 01:02:40 +00:00
|
|
|
local n = GetMerchantNumItems()
|
|
|
|
local row, n_searchmatch = 1, 0
|
|
|
|
for i=1,n do
|
|
|
|
local link = GetMerchantItemLink(i)
|
2016-09-12 01:28:47 +00:00
|
|
|
if ItemSearch:Find(link, searchstring) then
|
2016-09-11 01:02:40 +00:00
|
|
|
if n_searchmatch >= offset and n_searchmatch < offset + NUMROWS then
|
|
|
|
rows[row]:SetValue(i)
|
|
|
|
row = row + 1
|
|
|
|
end
|
|
|
|
n_searchmatch = n_searchmatch + 1
|
2011-03-06 16:37:27 +00:00
|
|
|
end
|
2016-09-11 01:02:40 +00:00
|
|
|
end
|
|
|
|
scrollbar:SetMinMaxValues(0, math.max(0, n_searchmatch - NUMROWS))
|
2016-09-12 00:28:04 +00:00
|
|
|
for i=row,NUMROWS do rows[i]:Hide() end
|
2009-08-14 05:09:03 +00:00
|
|
|
end
|
2016-09-12 01:45:02 +00:00
|
|
|
scrollbar:SetScript("OnValueChanged", Refresh)
|
|
|
|
|
2009-08-14 05:09:03 +00:00
|
|
|
|
2016-09-12 01:28:47 +00:00
|
|
|
search:SetScript("OnTextChanged", Refresh)
|
2009-08-14 05:09:03 +00:00
|
|
|
|
2016-09-11 01:02:40 +00:00
|
|
|
GVS:EnableMouseWheel(true)
|
|
|
|
GVS:SetScript("OnMouseWheel", function(self, value)
|
2016-09-11 10:12:42 +00:00
|
|
|
if value > 0 then
|
|
|
|
scrollbar:Decrement()
|
|
|
|
else
|
|
|
|
scrollbar:Increment()
|
|
|
|
end
|
2016-09-11 01:02:40 +00:00
|
|
|
end)
|
2016-09-12 01:45:02 +00:00
|
|
|
GVS:SetScript("OnEvent", Refresh)
|
2016-09-12 02:21:48 +00:00
|
|
|
GVS:SetScript("OnShow", function(self)
|
|
|
|
for i=1,12 do _G["MerchantItem"..i]:Hide() end
|
|
|
|
|
2016-09-11 01:02:40 +00:00
|
|
|
local max = math.max(0, GetMerchantNumItems() - NUMROWS)
|
|
|
|
scrollbar:SetMinMaxValues(0, max)
|
2016-09-12 02:21:48 +00:00
|
|
|
scrollbar:SetValue(0)
|
2016-09-12 01:45:02 +00:00
|
|
|
Refresh()
|
2015-03-09 09:30:32 +00:00
|
|
|
|
2016-09-11 01:02:40 +00:00
|
|
|
GVS:RegisterEvent("BAG_UPDATE")
|
|
|
|
GVS:RegisterEvent("MERCHANT_UPDATE")
|
|
|
|
GVS:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
|
|
|
|
end)
|
2016-09-12 02:21:48 +00:00
|
|
|
GVS:SetScript("OnHide", function(self)
|
|
|
|
for i=1,12 do _G["MerchantItem"..i]:Show() end
|
|
|
|
self:UnregisterAllEvents()
|
|
|
|
end)
|
2009-08-14 05:09:03 +00:00
|
|
|
|
2016-09-12 00:28:04 +00:00
|
|
|
return GVS
|
2016-09-11 01:02:40 +00:00
|
|
|
end
|