-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCancelAuctions.lua
More file actions
110 lines (93 loc) · 2.83 KB
/
CancelAuctions.lua
File metadata and controls
110 lines (93 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
-------------------------------------------------------------------------------
-- CancelAuctions.lua
--
-- Cancel a group of auctions.
-------------------------------------------------------------------------------
local L = LibStub("AceLocale-3.0"):GetLocale("AuctionLite", false)
-- Static popup advertising AL's fast scan.
StaticPopupDialogs["AL_CANCEL_CONFIRM"] = {
text = L["CANCEL_CONFIRM_TEXT"],
button1 = L["Cancel All"],
button3 = L["Cancel Unbid"],
button2 = L["Do Nothing"],
OnAccept = function(self)
AuctionLite:FinishCancel(self.data, true);
end,
OnAlt = function(self)
AuctionLite:FinishCancel(self.data, false);
end,
OnCancel = function(self)
-- Do nothing.
end,
showAlert = 1,
timeout = 0,
exclusive = 1,
hideOnEscape = 1
};
-- Cancel all auctions for "name" listed in "targets".
function AuctionLite:CancelAuctions(targets)
local batch = GetNumAuctionItems("owner");
local cancel = {};
local bidsDetected = false;
-- Find all the auctions to cancel.
local i;
for i = 1, batch do
local listing = self:GetListing("owner", i);
for _, target in ipairs(targets) do
if not target.found and
self:MatchListing(target.name, target, listing) then
target.found = true;
local item = { index = i,
target = target,
hasBid = (listing.bidAmount > 0) };
table.insert(cancel, item);
if item.hasBid then
bidsDetected = true;
end
break;
end
end
end
-- Clear all our marks.
for _, target in ipairs(targets) do
target.found = nil;
end
-- If we found any bids, show our confirmation dialog.
-- Otherwise, just cancel the auctions.
if bidsDetected then
local dialog = StaticPopup_Show("AL_CANCEL_CONFIRM");
if dialog ~= nil then
dialog.data = cancel;
end
else
self:FinishCancel(cancel, false);
end
end
-- Actually cancel the selected auctions.
function AuctionLite:FinishCancel(cancel, cancelBid)
-- Sort them from highest to lowest so that we can cancel the higher
-- ones without throwing off the indices of the remaining ones.
table.sort(cancel, function(a, b) return a.index > b.index end);
-- Cancel them!
local summary = {};
for _, item in ipairs(cancel) do
if cancelBid or not item.hasBid then
item.target.cancelled = true;
CancelAuction(item.index);
self:IgnoreMessage(ERR_AUCTION_REMOVED);
local name = item.target.name;
if summary[name] ~= nil then
summary[name] = summary[name] + 1;
else
summary[name] = 1;
end
end
end
-- Print a summary.
for name, listingsCancelled in pairs(summary) do
self:Print(L["Cancelled %d |4listing:listings; of %s."]:
format(listingsCancelled, name));
end
-- Notify the "Buy" frame.
self:CancelComplete();
end