From 12e8a2045bce6eed1ab951f0308d65fd021d5d25 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sun, 24 Apr 2016 05:33:17 +0200 Subject: [PATCH] improvement for buying/cancelling mechanism --- auctions_frame.lua | 29 +---------------------------- core.lua | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/auctions_frame.lua b/auctions_frame.lua index 7c82a43..7bb475c 100644 --- a/auctions_frame.lua +++ b/auctions_frame.lua @@ -105,32 +105,6 @@ function private.record_remover(record) end end -do - local found_index - - function private.find_auction(record) - if not Aux.util.index_of(record, auction_records) then - return - end - - found_index = nil - - Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index) - - found_index = index - - private.cancel_button:SetScript('OnClick', function() - if private.test(record)(index) and Aux.util.index_of(record, auction_records) then - CancelAuction(index) - private.record_remover(record)() - end - end) - private.cancel_button:Enable() - - end) - end -end - do local scan_id local IDLE, SEARCHING, FOUND = {}, {}, {} @@ -160,8 +134,7 @@ do private.cancel_button:SetScript('OnClick', function() if private.test(record)(index) and private.listing:ContainsRecord(record) then - CancelAuction(index) - private.record_remover(record)() + Aux.cancel_auction(index, private.record_remover(record)) end end) private.cancel_button:Enable() diff --git a/core.lua b/core.lua index 2518afe..4b21bb6 100644 --- a/core.lua +++ b/core.lua @@ -1,5 +1,5 @@ Aux = { - version = '2.11.2', + version = '2.11.3', blizzard_ui_shown = false, orig = {}, } @@ -167,17 +167,48 @@ do end local money = GetMoney() + PlaceAuctionBid(type, index, amount) if money >= amount then locked = true - local t0 = GetTime() - Aux.control.as_soon_as(function() return GetMoney() < money or GetTime() - t0 > 10 end, function() - if GetMoney() < money then + + local listener = Aux.control.event_listener('CHAT_MSG_SYSTEM') + listener:set_action(function() + if arg1 == ERR_AUCTION_BID_PLACED then on_success() + locked = false + listener:stop() end - locked = false end) + listener:start() end - PlaceAuctionBid(type, index, amount) + end +end + +do + local locked + + function Aux.cancel_in_progress() + return locked + end + + function Aux.cancel_auction(index, on_success) + + if locked then + return + end + + locked = true + + CancelAuction(index) + local listener = Aux.control.event_listener('CHAT_MSG_SYSTEM') + listener:set_action(function() + if arg1 == ERR_AUCTION_REMOVED then + on_success() + locked = false + listener:stop() + end + end) + listener:start() end end