big refactoring
This commit is contained in:
+50
-61
@@ -1,61 +1,58 @@
|
||||
aux.module 'bids_tab'
|
||||
aux.tab(4, 'Bids')
|
||||
g.aux.tab(4, 'Bids')
|
||||
|
||||
auction_records = nil
|
||||
|
||||
function m.LOAD()
|
||||
m.create_frames()
|
||||
function LOAD()
|
||||
create_frames()
|
||||
end
|
||||
|
||||
function m.OPEN()
|
||||
m.frame:Show()
|
||||
m.scan_bids()
|
||||
function OPEN()
|
||||
frame:Show()
|
||||
scan_bids()
|
||||
end
|
||||
|
||||
function m.CLOSE()
|
||||
m.frame:Hide()
|
||||
function CLOSE()
|
||||
frame:Hide()
|
||||
end
|
||||
|
||||
function update_listing()
|
||||
if not m:ACTIVE() then
|
||||
return
|
||||
end
|
||||
|
||||
m.listing:SetDatabase(m.auction_records)
|
||||
if not ACTIVE then return end
|
||||
listing:SetDatabase(auction_records)
|
||||
end
|
||||
|
||||
function public.scan_bids()
|
||||
|
||||
m.status_bar:update_status(0,0)
|
||||
m.status_bar:set_text('Scanning auctions...')
|
||||
status_bar:update_status(0,0)
|
||||
status_bar:set_text('Scanning auctions...')
|
||||
|
||||
m.auction_records = {}
|
||||
m.update_listing()
|
||||
aux.scan.start{
|
||||
auction_records = {}
|
||||
update_listing()
|
||||
scan.start{
|
||||
type = 'bidder',
|
||||
queries = {{ blizzard_query = {} }},
|
||||
on_page_loaded = function(page, total_pages)
|
||||
m.status_bar:update_status(100 * (page - 1) / total_pages, 0)
|
||||
m.status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages))
|
||||
status_bar:update_status(100 * (page - 1) / total_pages, 0)
|
||||
status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages))
|
||||
end,
|
||||
on_auction = function(auction_record)
|
||||
tinsert(m.auction_records, auction_record)
|
||||
tinsert(auction_records, auction_record)
|
||||
end,
|
||||
on_complete = function()
|
||||
m.status_bar:update_status(100, 100)
|
||||
m.status_bar:set_text('Scan complete')
|
||||
m.update_listing()
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Scan complete')
|
||||
update_listing()
|
||||
end,
|
||||
on_abort = function()
|
||||
m.status_bar:update_status(100, 100)
|
||||
m.status_bar:set_text('Scan aborted')
|
||||
status_bar:update_status(100, 100)
|
||||
status_bar:set_text('Scan aborted')
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
function test(record)
|
||||
return function(index)
|
||||
local auction_info = aux.info.auction(index, 'bidder')
|
||||
local auction_info = info.auction(index, 'bidder')
|
||||
return auction_info and auction_info.search_signature == record.search_signature
|
||||
end
|
||||
end
|
||||
@@ -67,45 +64,41 @@ do
|
||||
local found_index
|
||||
|
||||
function find_auction(record)
|
||||
if not m.listing:ContainsRecord(record) then
|
||||
return
|
||||
end
|
||||
if not listing:ContainsRecord(record) then return end
|
||||
|
||||
aux.scan.abort(scan_id)
|
||||
scan.abort(scan_id)
|
||||
state = SEARCHING
|
||||
scan_id = aux.scan_util.find(
|
||||
scan_id = scan_util.find(
|
||||
record,
|
||||
m.status_bar,
|
||||
status_bar,
|
||||
function() state = IDLE end,
|
||||
function()
|
||||
state = IDLE
|
||||
end,
|
||||
function()
|
||||
state = IDLE
|
||||
m.listing:RemoveAuctionRecord(record)
|
||||
listing:RemoveAuctionRecord(record)
|
||||
end,
|
||||
function(index)
|
||||
state = FOUND
|
||||
found_index = index
|
||||
|
||||
if not record.high_bidder then
|
||||
m.bid_button:SetScript('OnClick', function()
|
||||
if m.test(record)(index) and m.listing:ContainsRecord(record) then
|
||||
aux.place_bid('bidder', index, record.bid_price, record.bid_price < record.buyout_price and function()
|
||||
aux.info.bid_update(record)
|
||||
m.listing:SetDatabase()
|
||||
end or L(m.listing.RemoveAuctionRecord, m.listing, record))
|
||||
bid_button:SetScript('OnClick', function()
|
||||
if test(record)(index) and listing:ContainsRecord(record) then
|
||||
place_bid('bidder', index, record.bid_price, record.bid_price < record.buyout_price and function()
|
||||
info.bid_update(record)
|
||||
listing:SetDatabase()
|
||||
end or L(listing.RemoveAuctionRecord, listing, record))
|
||||
end
|
||||
end)
|
||||
m.bid_button:Enable()
|
||||
bid_button:Enable()
|
||||
end
|
||||
|
||||
if record.buyout_price > 0 then
|
||||
m.buyout_button:SetScript('OnClick', function()
|
||||
if m.test(record)(index) and m.listing:ContainsRecord(record) then
|
||||
aux.place_bid('bidder', index, record.buyout_price, L(m.listing.RemoveAuctionRecord, m.listing, record))
|
||||
buyout_button:SetScript('OnClick', function()
|
||||
if test(record)(index) and listing:ContainsRecord(record) then
|
||||
place_bid('bidder', index, record.buyout_price, L(listing.RemoveAuctionRecord, listing, record))
|
||||
end
|
||||
end)
|
||||
m.buyout_button:Enable()
|
||||
buyout_button:Enable()
|
||||
end
|
||||
end
|
||||
)
|
||||
@@ -113,25 +106,21 @@ do
|
||||
|
||||
function on_update()
|
||||
if state == IDLE or state == SEARCHING then
|
||||
m.buyout_button:Disable()
|
||||
m.bid_button:Disable()
|
||||
buyout_button:Disable()
|
||||
bid_button:Disable()
|
||||
end
|
||||
|
||||
if state == SEARCHING then
|
||||
return
|
||||
end
|
||||
if state == SEARCHING then return end
|
||||
|
||||
local selection = m.listing:GetSelection()
|
||||
local selection = listing:GetSelection()
|
||||
if not selection then
|
||||
state = IDLE
|
||||
elseif selection and state == IDLE then
|
||||
m.find_auction(selection.record)
|
||||
elseif state == FOUND and not m.test(selection.record)(found_index) then
|
||||
m.buyout_button:Disable()
|
||||
m.bid_button:Disable()
|
||||
if not aux.bid_in_progress() then
|
||||
state = IDLE
|
||||
end
|
||||
find_auction(selection.record)
|
||||
elseif state == FOUND and not test(selection.record)(found_index) then
|
||||
buyout_button:Disable()
|
||||
bid_button:Disable()
|
||||
if not bid_in_progress() then state = IDLE end
|
||||
end
|
||||
end
|
||||
end
|
||||
+11
-11
@@ -1,17 +1,17 @@
|
||||
aux.module 'bids_tab'
|
||||
|
||||
function create_frames()
|
||||
frame = CreateFrame('Frame', nil, aux.frame)
|
||||
frame = CreateFrame('Frame', nil, frame)
|
||||
frame:SetAllPoints()
|
||||
frame:SetScript('OnUpdate', on_update)
|
||||
frame:Hide()
|
||||
|
||||
frame.listing = aux.gui.panel(frame)
|
||||
frame.listing:SetPoint('TOP', aux.frame, 'TOP', 0, -8)
|
||||
frame.listing:SetPoint('BOTTOMLEFT', aux.frame.content, 'BOTTOMLEFT', 0, 0)
|
||||
frame.listing:SetPoint('BOTTOMRIGHT', aux.frame.content, 'BOTTOMRIGHT', 0, 0)
|
||||
frame.listing = gui.panel(frame)
|
||||
frame.listing:SetPoint('TOP', frame, 'TOP', 0, -8)
|
||||
frame.listing:SetPoint('BOTTOMLEFT', frame.content, 'BOTTOMLEFT', 0, 0)
|
||||
frame.listing:SetPoint('BOTTOMRIGHT', frame.content, 'BOTTOMRIGHT', 0, 0)
|
||||
|
||||
listing = aux.auction_listing.CreateAuctionResultsTable(frame.listing, aux.auction_listing.bids_config)
|
||||
listing = auction_listing.CreateAuctionResultsTable(frame.listing, auction_listing.bids_config)
|
||||
listing:SetSort(1,2,3,4,5,6,7,8)
|
||||
listing:Reset()
|
||||
listing:SetHandler('OnCellClick', function(cell, button)
|
||||
@@ -29,15 +29,15 @@ function create_frames()
|
||||
end)
|
||||
|
||||
do
|
||||
status_bar = aux.gui.status_bar(frame)
|
||||
status_bar = gui.status_bar(frame)
|
||||
status_bar:SetWidth(265)
|
||||
status_bar:SetHeight(25)
|
||||
status_bar:SetPoint('TOPLEFT', aux.frame.content, 'BOTTOMLEFT', 0, -6)
|
||||
status_bar:SetPoint('TOPLEFT', frame.content, 'BOTTOMLEFT', 0, -6)
|
||||
status_bar:update_status(100, 0)
|
||||
status_bar:set_text('')
|
||||
end
|
||||
do
|
||||
local btn = aux.gui.button(frame, 16)
|
||||
local btn = gui.button(frame, 16)
|
||||
btn:SetPoint('TOPLEFT', status_bar, 'TOPRIGHT', 5, 0)
|
||||
btn:SetWidth(80)
|
||||
btn:SetHeight(24)
|
||||
@@ -46,7 +46,7 @@ function create_frames()
|
||||
bid_button = btn
|
||||
end
|
||||
do
|
||||
local btn = aux.gui.button(frame, 16)
|
||||
local btn = gui.button(frame, 16)
|
||||
btn:SetPoint('TOPLEFT', bid_button, 'TOPRIGHT', 5, 0)
|
||||
btn:SetWidth(80)
|
||||
btn:SetHeight(24)
|
||||
@@ -55,7 +55,7 @@ function create_frames()
|
||||
buyout_button = btn
|
||||
end
|
||||
do
|
||||
local btn = aux.gui.button(frame, 16)
|
||||
local btn = gui.button(frame, 16)
|
||||
btn:SetPoint('TOPLEFT', buyout_button, 'TOPRIGHT', 5, 0)
|
||||
btn:SetWidth(80)
|
||||
btn:SetHeight(24)
|
||||
|
||||
Reference in New Issue
Block a user