improvement in buying mechanism

This commit is contained in:
Manuel Simon Hirsig
2016-01-24 08:41:11 +01:00
parent 3258e60214
commit 0f66a4d1fe
5 changed files with 142 additions and 178 deletions
+1
View File
@@ -12,6 +12,7 @@ persistence.lua
util.lua util.lua
scan.lua scan.lua
scan_util.lua
stack.lua stack.lua
post.lua post.lua
sheet.lua sheet.lua
+45 -83
View File
@@ -7,7 +7,6 @@ local create_auction_record, show_dialog, find_auction, hide_sheet, update_sheet
local auctions local auctions
local search_query local search_query
local tooltip_patterns = {} local tooltip_patterns = {}
local current_page
local refresh local refresh
function auction_alpha_setter(cell, auction) function auction_alpha_setter(cell, auction)
@@ -520,7 +519,6 @@ function public.on_close()
if AuxFilterSearchFrameResultsConfirmation:IsVisible() then if AuxFilterSearchFrameResultsConfirmation:IsVisible() then
public.dialog_cancel() public.dialog_cancel()
end end
current_page = nil
end end
function public.on_open() function public.on_open()
@@ -642,6 +640,8 @@ function public.start_search()
usable = AuxFilterSearchFrameFiltersUsableCheckButton:GetChecked() usable = AuxFilterSearchFrameFiltersUsableCheckButton:GetChecked()
} }
local current_page
Aux.log('Scanning auctions ...') Aux.log('Scanning auctions ...')
Aux.scan.start{ Aux.scan.start{
query = search_query, query = search_query,
@@ -720,12 +720,12 @@ end
function find_auction(entry, buyout_mode, express_mode) function find_auction(entry, buyout_mode, express_mode)
if entry.gone then if entry.gone then
Aux.log('Auction not available.') -- Aux.log('Auction not available.')
return return
end end
if buyout_mode and not entry.buyout_price then if buyout_mode and not entry.buyout_price then
Aux.log('Auction has no buyout price.') -- Aux.log('Auction has no buyout price.')
return return
end end
@@ -736,88 +736,50 @@ function find_auction(entry, buyout_mode, express_mode)
amount = entry.bid amount = entry.bid
end end
Aux.log('Searching auction ...')
AuxFilterSearchFrameFiltersSearchButton:Disable()
if not express_mode then
show_dialog(buyout_mode, entry, amount)
end
PlaySound('igMainMenuOptionCheckBoxOn') PlaySound('igMainMenuOptionCheckBoxOn')
local found
Aux.scan.start{
query = search_query,
page = entry.page ~= current_page and entry.page,
on_submit_query = function()
current_page = nil
end,
on_page_loaded = function(page)
current_page = page
end,
on_read_auction = function(auction_info, ctrl)
local auction_record = create_auction_record(auction_info) local function test(index)
return create_auction_record(Aux.info.auction(index)).signature == entry.signature
if entry.signature == auction_record.signature then end
ctrl.suspend()
found = true
Aux.log('Matching auction found.')
if express_mode then Aux.scan_util.find_auction(test, search_query, entry.page, private.status_bar, function(index)
if GetMoney() >= amount then if not index then
PlaceAuctionBid('list', auction_info.index, amount) entry.gone = true
Aux.log((buyout_mode and 'Purchased ' or 'Bid on ')..auction_record.hyperlink..' ('..auction_record.aux_quantity..').') private.selected = nil
entry.gone = true refresh = true
refresh = true return
else end
Aux.log((buyout_mode and 'Purchase' or 'Bid')..' failed: Not enough money.')
end if not test(index) then
Aux.scan.abort() return find_auction(entry, buyout_mode, express_mode) -- try again
else end
public.dialog_action = function()
if create_auction_record(Aux.info.auction(auction_info.index)).signature == entry.signature then if express_mode then
if GetMoney() >= amount then if GetMoney() >= amount then
PlaceAuctionBid('list', auction_info.index, buyout_mode and amount or MoneyInputFrame_GetCopper(AuxFilterSearchFrameResultsConfirmationContentBid)) entry.gone = true
Aux.log((buyout_mode and 'Purchased ' or 'Bid on ')..auction_record.hyperlink..' ('..auction_record.aux_quantity..').') end
entry.gone = true PlaceAuctionBid('list', index, amount)
refresh = true private.selected = nil
else refresh = true
Aux.log('Not enough money.') else
end private.buyout_button:SetScript('OnClick', function()
Aux.scan.abort() if not test(index) then
AuxFilterSearchFrameFiltersSearchButton:Enable() private.buyout_button:Disable()
AuxFilterSearchFrameResultsConfirmation:Hide() return find_auction(entry, buyout_mode, express_mode) -- try again
update_sheet() end
end
end if GetMoney() >= amount then
AuxFilterSearchFrameResultsConfirmationContentActionButton:Enable() entry.gone = true
end end
end PlaceAuctionBid('list', index, amount)
end,
on_complete = function() private.buyout_button:Disable()
if not found then private.selected = nil
Aux.log('No matching auction found. Removing entry from the cache.') refresh = true
entry.gone = true end)
refresh = true private.buyout_button:Enable()
public.dialog_cancel() end
end end)
if express_mode then
AuxFilterSearchFrameFiltersSearchButton:Enable()
end
end,
on_abort = function()
if express_mode then
AuxFilterSearchFrameFiltersSearchButton:Enable()
end
end,
next_page = function(page, total_pages)
if not page or page == entry.page then
return entry.page - 1
end
end,
}
end end
function private.on_row_click(entry) function private.on_row_click(entry)
+52 -91
View File
@@ -3,10 +3,9 @@ Aux.item_search_frame = public
aux_recently_searched = {} aux_recently_searched = {}
local create_auction_record, show_dialog, find_auction, hide_sheet, update_listing, auction_alpha_setter, group_alpha_setter, create_auction_record local create_auction_record, find_auction, hide_sheet, update_listing, auction_alpha_setter, group_alpha_setter, create_auction_record
local auctions local auctions
local search_query local search_query
local current_page
local refresh local refresh
function auction_alpha_setter(cell, auction) function auction_alpha_setter(cell, auction)
@@ -464,7 +463,8 @@ public.views = {
} }
function public.on_close() function public.on_close()
current_page = nil private.selected = nil
private.buyout_button:Disable()
end end
function public.on_open() function public.on_open()
@@ -659,14 +659,13 @@ function public.start_search()
AuxItemSearchFrameItemStopButton:Show() AuxItemSearchFrameItemStopButton:Show()
auctions = nil auctions = nil
refresh = true refresh = true
local item_id = private.item_id local item_id = private.item_id
local item_info = Aux.static.item_info(item_id) local item_info = Aux.static.item_info(item_id)
-- local class_index = Aux.item_class_index(item_info.class) -- local class_index = Aux.item_class_index(item_info.class)
-- local subclass_index = class_index and Aux.item_subclass_index(class_index, item_info.subclass) -- local subclass_index = class_index and Aux.item_subclass_index(class_index, item_info.subclass) -- TODO test if needed
search_query = { search_query = {
name = item_info.name, name = item_info.name,
@@ -679,13 +678,11 @@ function public.start_search()
usable = item_info.usable, usable = item_info.usable,
} }
-- Aux.log('Scanning auctions ...') local current_page
Aux.scan.start{ Aux.scan.start{
query = search_query, query = search_query,
page = AuxItemSearchFrameItemAllPagesCheckButton:GetChecked() and 0 or AuxItemSearchFrameItemPageEditBox:GetNumber(), page = AuxItemSearchFrameItemAllPagesCheckButton:GetChecked() and 0 or AuxItemSearchFrameItemPageEditBox:GetNumber(),
on_submit_query = function()
current_page = nil
end,
on_page_loaded = function(page, total_pages) on_page_loaded = function(page, total_pages)
private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages) -- TODO private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages) -- TODO
private.status_bar:set_text(string.format('Scanning (Page %d / %d)', page + 1, total_pages)) private.status_bar:set_text(string.format('Scanning (Page %d / %d)', page + 1, total_pages))
@@ -729,15 +726,15 @@ function public.start_search()
end) end)
end end
function find_auction(entry, buyout_mode, express_mode) function find_auction(entry, express_mode, buyout_mode)
if entry.gone then if entry.gone then
Aux.log('Auction not available.') -- Aux.log('Auction not available.')
return return
end end
if buyout_mode and not entry.buyout_price then if buyout_mode and not entry.buyout_price then
Aux.log('Auction has no buyout price.') -- Aux.log('Auction has no buyout price.')
return return
end end
@@ -748,86 +745,50 @@ function find_auction(entry, buyout_mode, express_mode)
amount = entry.bid amount = entry.bid
end end
private.status_bar:update_status(0, 0) PlaySound('igMainMenuOptionCheckBoxOn')
private.status_bar:set_text('Searching auction...')
-- if not express_mode then
-- show_dialog(buyout_mode, entry, amount)
-- end
PlaySound('igMainMenuOptionCheckBoxOn') local function test(index)
return create_auction_record(Aux.info.auction(index)).signature == entry.signature
local found end
Aux.scan.start{
query = search_query,
page = entry.page ~= current_page and entry.page,
on_submit_query = function()
current_page = nil
end,
on_page_loaded = function(page)
current_page = page
end,
on_read_auction = function(auction_info, ctrl)
local auction_record = create_auction_record(auction_info)
if entry.signature == auction_record.signature then
ctrl.suspend()
found = true
private.status_bar:update_status(100, 100)
private.status_bar:set_text('Auction found')
if express_mode then Aux.scan_util.find_auction(test, search_query, entry.page, private.status_bar, function(index)
if GetMoney() >= amount then if not index then
PlaceAuctionBid('list', auction_info.index, amount) entry.gone = true
Aux.log((buyout_mode and 'Purchased ' or 'Bid on ')..auction_record.hyperlink..' ('..auction_record.aux_quantity..').') private.selected = nil
entry.gone = true refresh = true
refresh = true return
else end
Aux.log((buyout_mode and 'Purchase' or 'Bid')..' failed: Not enough money.')
end if not test(index) then
Aux.scan.abort() return find_auction(entry, buyout_mode, express_mode) -- try again
else end
private.buyout_button:SetScript('OnClick', function()
if create_auction_record(Aux.info.auction(auction_info.index)).signature == entry.signature then if express_mode then
if GetMoney() >= amount then if GetMoney() >= amount then
PlaceAuctionBid('list', auction_info.index, amount) entry.gone = true
Aux.log((buyout_mode and 'Purchased ' or 'Bid on ')..auction_record.hyperlink..' ('..auction_record.aux_quantity..').') end
entry.gone = true PlaceAuctionBid('list', index, amount)
refresh = true private.selected = nil
else refresh = true
Aux.log('Not enough money.') else
end private.buyout_button:SetScript('OnClick', function()
Aux.scan.abort() if not test(index) then
update_listing() private.buyout_button:Disable()
end return find_auction(entry, buyout_mode, express_mode) -- try again
private.buyout_button:Disable() end
end)
private.buyout_button:Enable() if GetMoney() >= amount then
end entry.gone = true
end end
end, PlaceAuctionBid('list', index, amount)
on_complete = function()
if not found then private.buyout_button:Disable()
Aux.log('No matching auction found. Removing entry from the cache.') private.selected = nil
entry.gone = true refresh = true
refresh = true end)
public.dialog_cancel() private.buyout_button:Enable()
end end
if express_mode then end)
AuxItemSearchFrameItemRefreshButton:Enable()
end
end,
on_abort = function()
if express_mode then
AuxItemSearchFrameItemRefreshButton:Enable()
end
end,
next_page = function(page, total_pages)
if not page or page == entry.page then
return entry.page - 1
end
end,
}
end end
function public.on_row_click(entry) function public.on_row_click(entry)
@@ -845,7 +806,7 @@ function public.on_row_click(entry)
ChatFrameEditBox:Insert(entry.hyperlink) ChatFrameEditBox:Insert(entry.hyperlink)
end end
else else
find_auction(entry, buyout_mode, express_mode) find_auction(entry, express_mode, buyout_mode)
end end
end end
+40
View File
@@ -0,0 +1,40 @@
local m = {}
Aux.scan_util = m
function m.find_auction(test, search_query, page, status_bar, callback)
Aux.scan.abort(function()
status_bar:update_status(0, 0)
status_bar:set_text('Searching auction...')
local pages = page > 0 and { page, page - 1 } or { page }
Aux.scan.start{
query = search_query,
on_read_auction = function(auction_info, ctrl)
if test(auction_info.index) then
ctrl.suspend()
status_bar:update_status(100, 100)
status_bar:set_text('Auction found')
Aux.scan.abort(function()
callback(auction_info.index)
end)
end
end,
on_complete = function()
status_bar:update_status(100, 100)
status_bar:set_text('Auction not found')
callback()
end,
next_page = function()
if getn(pages) == 1 then
status_bar:update_status(50, 50)
end
local page = pages[1]
tremove(pages, 1)
return page
end,
}
end)
end
+4 -4
View File
@@ -80,8 +80,8 @@ function public.create(params)
local scroll_frame = CreateFrame('ScrollFrame', name..'ScrollFrame', params.frame, 'FauxScrollFrameTemplate') local scroll_frame = CreateFrame('ScrollFrame', name..'ScrollFrame', params.frame, 'FauxScrollFrameTemplate')
local scrollbar = getglobal(scroll_frame:GetName()..'ScrollBar') local scrollbar = getglobal(scroll_frame:GetName()..'ScrollBar')
scrollbar:SetPoint('TOPLEFT', scroll_frame, 'TOPRIGHT', 6, -4) scrollbar:SetPoint('TOPLEFT', scroll_frame, 'TOPRIGHT', 6, 0)
scrollbar:SetPoint('BOTTOMLEFT', scroll_frame, 'BOTTOMRIGHT', 6, 4) scrollbar:SetPoint('BOTTOMLEFT', scroll_frame, 'BOTTOMRIGHT', 6, 0)
scrollbar:SetWidth(12) scrollbar:SetWidth(12)
local thumbTex = scrollbar:GetThumbTexture() local thumbTex = scrollbar:GetThumbTexture()
thumbTex:SetPoint('CENTER', 0, 0) thumbTex:SetPoint('CENTER', 0, 0)
@@ -91,8 +91,8 @@ function public.create(params)
local scrollbg = scrollbar:CreateTexture(nil, 'BACKGROUND') local scrollbg = scrollbar:CreateTexture(nil, 'BACKGROUND')
scrollbg:SetAllPoints(scrollbar) scrollbg:SetAllPoints(scrollbar)
scrollbg:SetTexture(24/255, 24/255, 24/255, 1) scrollbg:SetTexture(24/255, 24/255, 24/255, 1)
local scrollbar = getglobal(scroll_frame:GetName()..'ScrollBarScrollUpButton'):Hide() getglobal(scroll_frame:GetName()..'ScrollBarScrollUpButton'):Hide()
local scrollbar = getglobal(scroll_frame:GetName()..'ScrollBarScrollDownButton'):Hide() getglobal(scroll_frame:GetName()..'ScrollBarScrollDownButton'):Hide()
scroll_frame:SetScript('OnVerticalScroll', function() scroll_frame:SetScript('OnVerticalScroll', function()
FauxScrollFrame_OnVerticalScroll(16, function() public.render(this.sheet) end) FauxScrollFrame_OnVerticalScroll(16, function() public.render(this.sheet) end)