some refactoring in the search frame code
This commit is contained in:
+37
-37
@@ -508,31 +508,31 @@ local methods = {
|
||||
end
|
||||
end,
|
||||
|
||||
RemoveAuctionRecord = function(rt, record)
|
||||
local index = Aux.util.index_of(record, rt.records)
|
||||
RemoveAuctionRecord = function(self, record)
|
||||
local index = Aux.util.index_of(record, self.records)
|
||||
if index then
|
||||
tremove(rt.records, index)
|
||||
tremove(self.records, index)
|
||||
end
|
||||
rt:SetDatabase()
|
||||
self:SetDatabase()
|
||||
end,
|
||||
|
||||
RemoveSelectedRecord = function(rt, count)
|
||||
RemoveSelectedRecord = function(self, count)
|
||||
count = count or 1
|
||||
for i=1, count do
|
||||
local index = Aux.util.index_of(rt.selected, rt.records)
|
||||
local index = Aux.util.index_of(self.selected, self.records)
|
||||
if index then
|
||||
tremove(rt.records, index)
|
||||
tremove(self.records, index)
|
||||
end
|
||||
end
|
||||
rt:SetDatabase()
|
||||
self:SetDatabase()
|
||||
end,
|
||||
|
||||
InsertAuctionRecord = function(rt, record, count)
|
||||
InsertAuctionRecord = function(self, record, count)
|
||||
count = count or 1
|
||||
for i=1, count do
|
||||
tinsert(rt.records, record)
|
||||
tinsert(self.records, record)
|
||||
end
|
||||
rt:SetDatabase()
|
||||
self:SetDatabase()
|
||||
end,
|
||||
|
||||
ContainsRecord = function(rt, record)
|
||||
@@ -541,7 +541,7 @@ local methods = {
|
||||
end
|
||||
end,
|
||||
|
||||
SetSort = function(rt, sortIndex)
|
||||
SetSort = function(self, sortIndex)
|
||||
local sortIndexLookup
|
||||
if aux_price_per_unit then
|
||||
sortIndexLookup = {'name', 'level', 'numAuctions', 'aux_quantity', 'duration', 'owner', 'unit_bid_price', 'unit_buyout_price', 'percent'}
|
||||
@@ -549,45 +549,45 @@ local methods = {
|
||||
sortIndexLookup = {'name', 'level', 'numAuctions', 'aux_quantity', 'duration', 'owner', 'bid_price', 'buyout_price', 'percent'}
|
||||
end
|
||||
if sortIndex then
|
||||
if sortIndex == rt.sortInfo.index then return end
|
||||
rt.sortInfo.descending = sortIndex < 0
|
||||
rt.sortInfo.columnIndex = abs(sortIndex)
|
||||
if sortIndex == self.sortInfo.index then return end
|
||||
self.sortInfo.descending = sortIndex < 0
|
||||
self.sortInfo.columnIndex = abs(sortIndex)
|
||||
end
|
||||
-- TSMAPI:Assert(rt.sortInfo.columnIndex > 0 and rt.sortInfo.columnIndex <= getn(rt.headCells))
|
||||
rt.sortInfo.sortKey = sortIndexLookup[rt.sortInfo.columnIndex]
|
||||
rt.sortInfo.isSorted = nil
|
||||
rt.sortInfo.index = sortIndex
|
||||
rt:UpdateRows()
|
||||
-- TSMAPI:Assert(self.sortInfo.columnIndex > 0 and self.sortInfo.columnIndex <= getn(self.headCells))
|
||||
self.sortInfo.sortKey = sortIndexLookup[self.sortInfo.columnIndex]
|
||||
self.sortInfo.isSorted = nil
|
||||
self.sortInfo.index = sortIndex
|
||||
self:UpdateRows()
|
||||
end,
|
||||
|
||||
SetScrollDisabled = function(rt, disabled)
|
||||
rt.scrollDisabled = disabled
|
||||
SetScrollDisabled = function(self, disabled)
|
||||
self.scrollDisabled = disabled
|
||||
end,
|
||||
|
||||
SetHandler = function(rt, event, handler)
|
||||
rt.handlers[event] = handler
|
||||
SetHandler = function(self, event, handler)
|
||||
self.handlers[event] = handler
|
||||
end,
|
||||
|
||||
SetDisabled = function(rt, disabled)
|
||||
rt.disabled = disabled
|
||||
SetDisabled = function(self, disabled)
|
||||
self.disabled = disabled
|
||||
if not disabled then
|
||||
-- if there's only one item in the result, expand it
|
||||
if getn(rt.rowInfo) == 1 and rt.expanded[rt.rowInfo[1].expandKey] == nil then
|
||||
rt.expanded[rt.rowInfo[1].expandKey] = true
|
||||
rt.rowInfo.numDisplayRows = getn(rt.rowInfo[1].children)
|
||||
if getn(self.rowInfo) == 1 and self.expanded[self.rowInfo[1].expandKey] == nil then
|
||||
self.expanded[self.rowInfo[1].expandKey] = true
|
||||
self.rowInfo.numDisplayRows = getn(self.rowInfo[1].children)
|
||||
end
|
||||
rt:UpdateRows()
|
||||
self:UpdateRows()
|
||||
-- select the first row
|
||||
rt:SetSelectedRecord(getn(rt.rowInfo) > 0 and rt.rowInfo[1].children[1].record)
|
||||
self:SetSelectedRecord(getn(self.rowInfo) > 0 and self.rowInfo[1].children[1].record)
|
||||
end
|
||||
end,
|
||||
|
||||
GetSelection = function(rt)
|
||||
if not rt.selected then return end
|
||||
GetSelection = function(self)
|
||||
if not self.selected then return end
|
||||
local selectedData
|
||||
for _, info in ipairs(rt.rowInfo) do
|
||||
for _, info in ipairs(self.rowInfo) do
|
||||
for _, childInfo in ipairs(info.children) do
|
||||
if childInfo.record.search_signature == rt.selected.search_signature then
|
||||
if childInfo.record.search_signature == self.selected.search_signature then
|
||||
selectedData = childInfo
|
||||
break
|
||||
end
|
||||
@@ -596,9 +596,9 @@ local methods = {
|
||||
return selectedData
|
||||
end,
|
||||
|
||||
GetTotalAuctions = function(rt)
|
||||
GetTotalAuctions = function(self)
|
||||
local numResults = 0
|
||||
for _, info in ipairs(rt.rowInfo) do
|
||||
for _, info in ipairs(self.rowInfo) do
|
||||
for _, childInfo in ipairs(info.children) do
|
||||
numResults = numResults + childInfo.numAuctions
|
||||
end
|
||||
|
||||
+2
-2
@@ -144,7 +144,7 @@ function private.find_auction_and_cancel(record)
|
||||
return
|
||||
end
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
if Aux.util.index_of(record, auction_records) then
|
||||
CancelAuction(index)
|
||||
private.record_remover(record)()
|
||||
@@ -162,7 +162,7 @@ do
|
||||
|
||||
found_index = nil
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
|
||||
found_index = index
|
||||
|
||||
|
||||
+2
-2
@@ -164,7 +164,7 @@ function private.find_auction_and_bid(record, buyout_mode)
|
||||
return
|
||||
end
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
if Aux.util.index_of(record, auction_records) then
|
||||
Aux.place_bid('bidder', index, buyout_mode and record.buyout_price or record.bid_price, private.record_remover(record))
|
||||
end
|
||||
@@ -181,7 +181,7 @@ do
|
||||
|
||||
found_index = nil
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, private.record_remover(record), function(index)
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
|
||||
found_index = index
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
AuxVersion = '2.4.22'
|
||||
AuxVersion = '2.4.23'
|
||||
AuxAuthors = 'shirsig; Zerf; Zirco (Auctionator); Nimeral (Auctionator backport)'
|
||||
|
||||
Aux = {
|
||||
|
||||
+3
-2
@@ -1,7 +1,7 @@
|
||||
local m = {}
|
||||
Aux.scan_util = m
|
||||
|
||||
function m.find(test, query, page, status_bar, on_failure, on_success)
|
||||
function m.find(test, query, page, status_bar, on_abort, on_failure, on_success)
|
||||
|
||||
Aux.scan.abort(function()
|
||||
|
||||
@@ -40,12 +40,13 @@ function m.find(test, query, page, status_bar, on_failure, on_success)
|
||||
if not found then
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Auction not found')
|
||||
return on_abort()
|
||||
end
|
||||
end,
|
||||
on_complete = function()
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Auction not found')
|
||||
on_failure()
|
||||
return on_failure()
|
||||
end,
|
||||
}
|
||||
end)
|
||||
|
||||
+46
-35
@@ -694,10 +694,6 @@ end
|
||||
private.results_listing:SetHandler('OnCellAltClick', function(cell, button)
|
||||
private.find_auction_and_bid(cell.row.data.record, button == 'LeftButton')
|
||||
end)
|
||||
private.results_listing:SetHandler('OnSelectionChanged', function(rt, datum)
|
||||
if not datum then return end
|
||||
private.find_auction(datum.record)
|
||||
end)
|
||||
|
||||
local handlers = {
|
||||
OnClick = function(st, data, _, button)
|
||||
@@ -878,7 +874,9 @@ function private.find_auction_and_bid(record, buyout_mode)
|
||||
return
|
||||
end
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, private.record_remover(record), function(index)
|
||||
private.results_listing:SetSelectedRecord(nil)
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
|
||||
if private.results_listing:ContainsRecord(record) then
|
||||
Aux.place_bid('list', index, buyout_mode and record.buyout_price or record.bid_price, private.record_remover(record))
|
||||
end
|
||||
@@ -886,6 +884,8 @@ function private.find_auction_and_bid(record, buyout_mode)
|
||||
end
|
||||
|
||||
do
|
||||
local IDLE, SEARCHING, FOUND = {}, {}, {}
|
||||
local state = IDLE
|
||||
local found_index
|
||||
|
||||
function private.find_auction(record)
|
||||
@@ -893,30 +893,41 @@ do
|
||||
return
|
||||
end
|
||||
|
||||
found_index = nil
|
||||
Aux.scan_util.find(
|
||||
private.test(record),
|
||||
record.query,
|
||||
record.page,
|
||||
private.status_bar,
|
||||
function()
|
||||
state = IDLE
|
||||
end,
|
||||
function()
|
||||
state = IDLE
|
||||
private.record_remover(record)()
|
||||
end,
|
||||
function(index)
|
||||
state = FOUND
|
||||
found_index = index
|
||||
|
||||
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, private.record_remover(record), function(index)
|
||||
if not record.high_bidder then
|
||||
private.bid_button:SetScript('OnClick', function()
|
||||
if private.test(record)(index) and private.results_listing:ContainsRecord(record) then
|
||||
Aux.place_bid('list', index, record.bid_price, private.record_remover(record))
|
||||
end
|
||||
end)
|
||||
private.bid_button:Enable()
|
||||
end
|
||||
|
||||
found_index = index
|
||||
|
||||
if not record.high_bidder then
|
||||
private.bid_button:SetScript('OnClick', function()
|
||||
if private.test(record)(index) and private.results_listing:ContainsRecord(record) then
|
||||
Aux.place_bid('list', index, record.bid_price, private.record_remover(record))
|
||||
end
|
||||
end)
|
||||
private.bid_button:Enable()
|
||||
if record.buyout_price > 0 then
|
||||
private.buyout_button:SetScript('OnClick', function()
|
||||
if private.test(record)(index) and private.results_listing:ContainsRecord(record) then
|
||||
Aux.place_bid('list', index, record.buyout_price, private.record_remover(record))
|
||||
end
|
||||
end)
|
||||
private.buyout_button:Enable()
|
||||
end
|
||||
end
|
||||
|
||||
if record.buyout_price > 0 then
|
||||
private.buyout_button:SetScript('OnClick', function()
|
||||
if private.test(record)(index) and private.results_listing:ContainsRecord(record) then
|
||||
Aux.place_bid('list', index, record.buyout_price, private.record_remover(record))
|
||||
end
|
||||
end)
|
||||
private.buyout_button:Enable()
|
||||
end
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
function public.on_update()
|
||||
@@ -924,23 +935,23 @@ do
|
||||
return
|
||||
end
|
||||
|
||||
if not found_index then
|
||||
if state == IDLE or state == SEARCHING then
|
||||
private.buyout_button:Disable()
|
||||
private.bid_button:Disable()
|
||||
end
|
||||
|
||||
if state == SEARCHING then
|
||||
return
|
||||
end
|
||||
|
||||
local selection = private.results_listing:GetSelection()
|
||||
if not selection then
|
||||
private.buyout_button:Disable()
|
||||
private.bid_button:Disable()
|
||||
return
|
||||
end
|
||||
|
||||
if found_index and not private.test(selection.record)(found_index) then
|
||||
private.buyout_button:Disable()
|
||||
private.bid_button:Disable()
|
||||
state = IDLE
|
||||
elseif selection and state == IDLE then
|
||||
state = SEARCHING
|
||||
private.find_auction(selection.record)
|
||||
elseif state == FOUND and not private.test(selection.record)(found_index) then
|
||||
state = IDLE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user