mirror of
https://github.com/PastaStomp/OctoAuctionatorPlus.git
synced 2026-11-18 14:54:45 +00:00
The owner-page walk and the cancel walk's page-advance both relied solely on AUCTION_OWNED_LIST_UPDATE to know when a requested page had arrived, but that event doesn't fire when the requested page is already the client's current page - no real fetch happens, so nothing re-confirms it. This left gOwnerScanActive/gOwnerCancelState stuck "busy" forever, which also permanently blocked every retry. Both now fall back to processing whatever data is already there after a short timeout instead of waiting on an event that may never come. Also fixes two related bugs found while testing this: a stray gJustPosted_ItemName reset left over from the cancellation rework could crash a concurrent multi-stack post with "table index is nil", and the active-auctions cache could be left holding a mid-operation snapshot after a cancel or post settled, showing wrong counts until some unrelated event happened to force a rebuild.
5274 lines
151 KiB
Lua
5274 lines
151 KiB
Lua
|
|
AuctionatorVersion = "???"; -- set from toc upon loading
|
|
AuctionatorAuthor = "Zirco";
|
|
|
|
local AuctionatorLoaded = false;
|
|
local AuctionatorInited = false;
|
|
|
|
local addonName, addonTable = "Auctionator", AtrNS;
|
|
local zc = addonTable.zc;
|
|
|
|
gAtrZC = addonTable.zc; -- share with AuctionatorDev
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
local recommendElements = {};
|
|
|
|
-- the per-item buyout price - kept here so stack size changes can recompute the stack total
|
|
-- without a separate field for it, and so the "per item" button has something to show
|
|
local gSellItemPrice = 0;
|
|
|
|
-- whether the Buyout Price input currently represents the per-item price instead of the whole
|
|
-- stack's total; toggled by the "Price per item" checkbox
|
|
local gBuyoutIsPerItem = false;
|
|
|
|
-- Starting Price always needs to track whichever mode Buyout Price is currently in, the same
|
|
-- way Buyout Price itself does, given a per-item starting price
|
|
function Atr_ApplyStartingPrice (itemStartPrice)
|
|
if (gBuyoutIsPerItem) then
|
|
MoneyInputFrame_SetCopper (Atr_StartingPrice, itemStartPrice);
|
|
else
|
|
MoneyInputFrame_SetCopper (Atr_StartingPrice, itemStartPrice * Atr_StackSize());
|
|
end
|
|
end
|
|
|
|
AUCTIONATOR_OPEN_ALL_BAGS = 1;
|
|
AUCTIONATOR_SHOW_TIPS = 1;
|
|
AUCTIONATOR_DEF_DURATION = "N"; -- none
|
|
AUCTIONATOR_V_TIPS = 1;
|
|
AUCTIONATOR_A_TIPS = 1;
|
|
AUCTIONATOR_D_TIPS = 1;
|
|
AUCTIONATOR_SHIFT_TIPS = 1;
|
|
AUCTIONATOR_DE_DETAILS_TIPS = 4; -- off by default
|
|
AUCTIONATOR_DEFTAB = 1;
|
|
|
|
AUCTIONATOR_OPEN_FIRST = 0; -- obsolete - just needed for migration
|
|
AUCTIONATOR_OPEN_BUY = 0; -- obsolete - just needed for migration
|
|
|
|
local SELL_TAB = 1;
|
|
local MORE_TAB = 2;
|
|
local BUY_TAB = 3;
|
|
|
|
local MODE_LIST_ACTIVE = 1;
|
|
local MODE_LIST_ALL = 2;
|
|
|
|
|
|
-- saved variables - amounts to undercut
|
|
|
|
local auctionator_savedvars_defaults =
|
|
{
|
|
["_5000000"] = 10000; -- amount to undercut buyouts over 500 gold
|
|
["_1000000"] = 2500;
|
|
["_200000"] = 1000;
|
|
["_50000"] = 500;
|
|
["_10000"] = 200;
|
|
["_2000"] = 100;
|
|
["_500"] = 5;
|
|
["BIDDING_RATIO"] = 95; -- PERCENT of the buyout price the starting bid defaults to
|
|
};
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
local auctionator_orig_AuctionFrameTab_OnClick;
|
|
local auctionator_orig_ContainerFrameItemButton_OnClick;
|
|
local auctionator_orig_AuctionFrameAuctions_Update;
|
|
local auctionator_orig_CanShowRightUIPanel;
|
|
local auctionator_orig_ChatEdit_InsertLink;
|
|
local auctionator_orig_ChatFrame_OnEvent;
|
|
local auctionator_orig_FriendsFrame_OnEvent;
|
|
|
|
local gForceMsgAreaUpdate = true;
|
|
|
|
local gOpenAllBags = AUCTIONATOR_OPEN_ALL_BAGS;
|
|
local gTimeZero;
|
|
local gTimeTightZero;
|
|
|
|
local cslots = {};
|
|
local gEmptyBScached = nil;
|
|
|
|
local gAutoSingleton = 0;
|
|
|
|
local gJustPosted_ItemName = nil; -- set to the last item posted, even after the posting so that message and icon can be displayed
|
|
local gJustPosted_ItemLink;
|
|
local gJustPosted_BuyoutPrice;
|
|
local gJustPosted_StackSize;
|
|
local gJustPosted_NumInBagsAtStart;
|
|
local gJustPosted_NumStacks;
|
|
local gJustPosted_Deposit; -- per-auction deposit cost, recorded at post time so it can later be shown/reported on cancel
|
|
|
|
local auctionator_pending_message = nil;
|
|
|
|
local kBagIDs = {};
|
|
|
|
local Atr_Confirm_Proc_Yes = nil;
|
|
|
|
local gStartingTime = time();
|
|
local gHentryTryAgain = nil;
|
|
local gCondensedThisSession = {};
|
|
|
|
local ITEM_HIST_NUM_LINES = 10; -- Listings-tab rows per page, at ITEM_HIST_ROW_HEIGHT each
|
|
ITEM_HIST_ROW_HEIGHT = 32; -- global: AuctionatorShop.lua's scroll handler needs this too
|
|
ATR_HLIST_FRAME_COUNT = 13; -- global: total AuctionatorHEntry frames to create - the Buy tab's SLITEMS_NUM_LINES needs more (smaller) rows than the Listings tab
|
|
|
|
local gActiveAuctions = {};
|
|
local gActiveAuctionIcons = {}; -- textures captured straight off the native "owner" auction query - always available instantly, unlike GetItemInfo-by-name
|
|
local gActiveAuctionRarity = {}; -- same deal, for item rarity (quality)
|
|
|
|
-- GetNumAuctionItems("owner")/GetAuctionItemInfo("owner", i) only ever reflect one page (up to 50
|
|
-- entries) at a time, the same as a browse/search query - GetOwnerAuctionItems(page) requests a
|
|
-- specific page, mirroring the native Auctions tab's own page-arrow button. There is only ONE
|
|
-- shared client-side "current owner page" cursor though - every piece of code reading the
|
|
-- "owner" query sees whichever page was most recently requested, not necessarily page 0.
|
|
-- Atr_CancelAuction_ByIndex/Atr_Cancel_Undercuts_OnClick assume it always sits at page 0 (true
|
|
-- before this walk existed, since nothing else ever repointed it) - gOwnerScanActive tracks a
|
|
-- multi-page walk in progress, and gOwnerScanResetting tracks the trailing page-0 request that
|
|
-- restores that assumption once the walk finishes, without re-flushing the aggregate it just built.
|
|
local gOwnerScanActive = false;
|
|
local gOwnerScanPage = 0;
|
|
local gOwnerScanResetting = false;
|
|
local gOwnerScanT = 0; -- GetTime() the current page was requested - if AUCTION_OWNED_LIST_UPDATE
|
|
local gOwnerScanPageHandled = false; -- never arrives (confirmed: happens when the requested page was already
|
|
-- the client's current page, e.g. right after Atr_RefreshOwnedAuctions already
|
|
-- loaded page 0 - no actual fetch happens, so nothing re-fires the event, and
|
|
-- gOwnerScanActive was left stuck true forever with no recovery), Atr_OwnerScanStep
|
|
-- (polled from Atr_OnUpdate) processes whatever's already there after a short wait
|
|
-- instead of blocking on an event that may never come.
|
|
|
|
-- Cancelling has two separate problems beyond simple pagination, both confirmed by direct
|
|
-- testing: (1) the client's own list/index shrinks optimistically the instant CancelAuction() is
|
|
-- issued, well before the server has actually accepted or rejected it - exactly the same false-
|
|
-- positive trap documented for StartAuction/posting elsewhere in this file, just not previously
|
|
-- recognized here. Firing many CancelAuction() calls in one batch and trusting the client's own
|
|
-- shrinking list/counts as proof of success is what let a run of "cancelled" auctions turn out to
|
|
-- still be live on the server. (2) the real server confirmation (CHAT_MSG_SYSTEM's
|
|
-- ERR_AUCTION_REMOVED) is the only trustworthy signal, same as ERR_AUCTION_STARTED is for
|
|
-- posting. So: cancel exactly one match at a time, wait for that confirmation (or a timeout, if
|
|
-- cancelling something that doesn't exist on this server, or something else went wrong) before
|
|
-- counting it and moving on to the next, walking every page as needed in between. Shared by both
|
|
-- Atr_CancelAuction_ByIndex and Atr_Cancel_Undercuts_OnClick; polled every frame by
|
|
-- Atr_OwnerCancelStep (called from Atr_OnUpdate), confirmed via auctionator_ChatFrame_OnEvent,
|
|
-- and advanced to the next page by Atr_OnAuctionOwnedUpdate once a requested page's data arrives.
|
|
local gOwnerCancelState = nil; -- nil (inactive) | "findmatch" | "pageloading" | "cancelwait"
|
|
local gOwnerCancelPage = 0;
|
|
local gOwnerCancelMatchFn = nil; -- function(name, stackSize, buyoutPrice) -> true if this slot should be cancelled
|
|
local gOwnerCancelOnEach = nil; -- function(name, stackSize, buyoutPrice), called once a cancel is actually confirmed
|
|
local gOwnerCancelOnComplete = nil; -- function(), called once no further matches remain on any page
|
|
local gOwnerCancelConfirmed = false;
|
|
local gOwnerCancelFailed = false; -- the most recent cancel timed out without confirmation - don't count it, but don't retry forever either
|
|
local gOwnerCancelT = 0;
|
|
local gOwnerCancelPendingName = nil; -- the slot's own name/stackSize/buyoutPrice at the moment Atr_CancelAuction was called on it -
|
|
local gOwnerCancelPendingStackSize = nil; -- needed again once confirmation arrives, by which point re-reading "owner" index foundIndex
|
|
local gOwnerCancelPendingBuyout = nil; -- may no longer refer to the same (or any) auction
|
|
local gOwnerCancelMaxCount = nil; -- nil = cancel every match; otherwise stop once this many are confirmed
|
|
local gOwnerCancelConfirmedCount = 0;
|
|
|
|
local gHlistNeedsUpdate = false;
|
|
|
|
local gSellPane;
|
|
local gMorePane;
|
|
local gActivePane;
|
|
local gShopPane;
|
|
|
|
local gCurrentPane;
|
|
|
|
local gHistoryItemList = {};
|
|
|
|
local ATR_CACT_NULL = 0;
|
|
local ATR_CACT_READY = 1;
|
|
local ATR_CACT_PROCESSING = 2;
|
|
local ATR_CACT_WAITING_ON_CANCEL_CONFIRM = 3;
|
|
|
|
|
|
local gItemPostingInProgress = false;
|
|
local gQuietWho = 0;
|
|
local gSendZoneMsgs = false;
|
|
|
|
gAtr_ptime = nil; -- a more precise timer but may not be updated very frequently
|
|
|
|
gAtr_ScanDB = nil;
|
|
gAtr_PriceHistDB = nil;
|
|
|
|
-----------------------------------------
|
|
|
|
ATR_SK_GLYPHS = "*_glyphs";
|
|
ATR_SK_GEMS_CUT = "*_gemscut";
|
|
ATR_SK_GEMS_UNCUT = "*_gemsuncut";
|
|
ATR_SK_ITEM_ENH = "*_itemenh";
|
|
ATR_SK_POT_ELIX = "*_potelix";
|
|
ATR_SK_FLASKS = "*_flasks";
|
|
ATR_SK_HERBS = "*_herbs";
|
|
|
|
-----------------------------------------
|
|
|
|
local roundPriceDown, ToTightTime, FromTightTime, monthDay;
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_RegisterEvents(self)
|
|
|
|
self:RegisterEvent("VARIABLES_LOADED");
|
|
self:RegisterEvent("ADDON_LOADED");
|
|
|
|
self:RegisterEvent("AUCTION_ITEM_LIST_UPDATE");
|
|
self:RegisterEvent("AUCTION_OWNED_LIST_UPDATE");
|
|
|
|
self:RegisterEvent("AUCTION_MULTISELL_START");
|
|
self:RegisterEvent("AUCTION_MULTISELL_UPDATE");
|
|
self:RegisterEvent("AUCTION_MULTISELL_FAILURE");
|
|
|
|
self:RegisterEvent("AUCTION_HOUSE_SHOW");
|
|
self:RegisterEvent("AUCTION_HOUSE_CLOSED");
|
|
|
|
self:RegisterEvent("NEW_AUCTION_UPDATE");
|
|
self:RegisterEvent("PLAYER_ENTERING_WORLD");
|
|
|
|
-- fires for both a successful AND a failed right-click sell attempt (e.g. soulbound/quest
|
|
-- items), unlike NEW_AUCTION_UPDATE which only fires on success - used to catch the native
|
|
-- "switch to the Auctions tab" behavior on a failed attempt too, see Atr_OnItemLockChanged
|
|
self:RegisterEvent("ITEM_LOCK_CHANGED");
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_EventHandler()
|
|
|
|
-- zc.md (event);
|
|
|
|
if (event == "VARIABLES_LOADED") then Atr_OnLoad(); end;
|
|
if (event == "ADDON_LOADED") then Atr_OnAddonLoaded(); end;
|
|
if (event == "AUCTION_ITEM_LIST_UPDATE") then Atr_OnAuctionUpdate(); end;
|
|
if (event == "AUCTION_OWNED_LIST_UPDATE") then Atr_OnAuctionOwnedUpdate(); end;
|
|
|
|
if (event == "AUCTION_MULTISELL_START") then Atr_OnAuctionMultiSellStart(); end;
|
|
if (event == "AUCTION_MULTISELL_UPDATE") then Atr_OnAuctionMultiSellUpdate(); end;
|
|
if (event == "AUCTION_MULTISELL_FAILURE") then Atr_OnAuctionMultiSellFailure(); end;
|
|
|
|
if (event == "AUCTION_HOUSE_SHOW") then Atr_OnAuctionHouseShow(); end;
|
|
if (event == "AUCTION_HOUSE_CLOSED") then Atr_OnAuctionHouseClosed(); end;
|
|
if (event == "NEW_AUCTION_UPDATE") then Atr_OnNewAuctionUpdate(); end;
|
|
if (event == "ITEM_LOCK_CHANGED") then Atr_OnItemLockChanged(); end;
|
|
if (event == "CHAT_MSG_ADDON") then Atr_OnChatMsgAddon(); end;
|
|
if (event == "WHO_LIST_UPDATE") then Atr_OnWhoListUpdate(); end;
|
|
if (event == "PLAYER_ENTERING_WORLD") then Atr_OnPlayerEnteringWorld(); end;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetupHookFunctionsEarly ()
|
|
|
|
Atr_Hook_OnTooltipAddMoney ();
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetupHookFunctions ()
|
|
|
|
auctionator_orig_AuctionFrameTab_OnClick = AuctionFrameTab_OnClick;
|
|
AuctionFrameTab_OnClick = Atr_AuctionFrameTab_OnClick;
|
|
|
|
-- 1.12 has no OnModifiedClick: the bag button's OnClick handler gets the button and modifier state instead
|
|
auctionator_orig_ContainerFrameItemButton_OnClick = ContainerFrameItemButton_OnClick;
|
|
ContainerFrameItemButton_OnClick = Atr_ContainerFrameItemButton_OnClick;
|
|
|
|
auctionator_orig_AuctionFrameAuctions_Update = AuctionFrameAuctions_Update;
|
|
AuctionFrameAuctions_Update = Atr_AuctionFrameAuctions_Update;
|
|
|
|
auctionator_orig_ChatFrame_OnEvent = ChatFrame_OnEvent;
|
|
ChatFrame_OnEvent = auctionator_ChatFrame_OnEvent;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local gItemLinkCache = {};
|
|
local gA2IC_prevName = "";
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_AddToItemLinkCache (itemName, itemLink)
|
|
|
|
if (itemName == gA2IC_prevName) then -- for performance reasons only
|
|
return;
|
|
end
|
|
|
|
gA2IC_prevName = itemName;
|
|
|
|
gItemLinkCache[string.lower(itemName)] = itemLink;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_GetItemLink (itemName)
|
|
if (itemName == nil or itemName == "") then
|
|
return nil;
|
|
end
|
|
|
|
local itemLink = gItemLinkCache[string.lower(itemName)];
|
|
|
|
if (itemLink == nil) then
|
|
_, itemLink = Atr_GetItemInfo (itemName);
|
|
if (itemLink) then
|
|
Atr_AddToItemLinkCache (itemName, itemLink);
|
|
end
|
|
end
|
|
|
|
return itemLink;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local checkVerString = nil;
|
|
local versionReminderCalled = false; -- make sure we don't bug user more than once
|
|
|
|
-----------------------------------------
|
|
|
|
local function CheckVersion (verString)
|
|
|
|
if (checkVerString == nil) then
|
|
checkVerString = AuctionatorVersion;
|
|
end
|
|
|
|
local a,b,c = Atr_strsplit (".", verString);
|
|
|
|
if (tonumber(a) == nil or tonumber(b) == nil or tonumber(c) == nil) then
|
|
return false;
|
|
end
|
|
|
|
if (verString > checkVerString) then
|
|
checkVerString = verString;
|
|
return true; -- out of date
|
|
end
|
|
|
|
return false;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_VersionReminder ()
|
|
if (not versionReminderCalled) then
|
|
versionReminderCalled = true;
|
|
|
|
zc.msg_atr (ZT("There is a more recent version of Auctionator: VERSION").." "..checkVerString);
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
local VREQ_sent = 0;
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SendAddon_VREQ (type, target)
|
|
|
|
VREQ_sent = time();
|
|
|
|
SendAddonMessage ("ATR", "VREQ_"..AuctionatorVersion, type, target);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnChatMsgAddon ()
|
|
|
|
local prefix = arg1;
|
|
local msg = arg2;
|
|
local distribution = arg3;
|
|
local sender = arg4;
|
|
|
|
-- local s = string.format ("%s %s |cff88ffff %s |cffffffaa %s|r", prefix, distribution, sender, msg);
|
|
-- zc.md (s);
|
|
|
|
if (arg1 == "ATR") then
|
|
|
|
if (zc.StringStartsWith (msg, "VREQ_")) then
|
|
SendAddonMessage ("ATR", "V_"..AuctionatorVersion, "WHISPER", sender);
|
|
end
|
|
|
|
if (zc.StringStartsWith (msg, "V_") and time() - VREQ_sent < 5) then
|
|
|
|
local herVerString = string.sub (msg, 3);
|
|
zc.md ("version found:", herVerString, " ", sender, " delta", time() - VREQ_sent);
|
|
local outOfDate = CheckVersion (herVerString);
|
|
if (outOfDate) then
|
|
zc.AddDeferredCall (3, "Atr_VersionReminder", nil, nil, "VR");
|
|
end
|
|
end
|
|
end
|
|
|
|
if (Atr_OnChatMsgAddon_Dev) then
|
|
Atr_OnChatMsgAddon_Dev (prefix, msg, distribution, sender);
|
|
end
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
local function Atr_GetAuctionatorMemString(msg)
|
|
|
|
UpdateAddOnMemoryUsage();
|
|
|
|
local mem = GetAddOnMemoryUsage("OctoAuctionator");
|
|
return string.format ("%6i KB", math.floor(mem));
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local function Atr_SlashCmdFunction(msg)
|
|
|
|
local cmd, param1u, param2u, param3u = zc.words (msg);
|
|
|
|
if (cmd == nil or type (cmd) ~= "string") then
|
|
return;
|
|
end
|
|
|
|
cmd = cmd and string.lower(cmd) or nil;
|
|
local param1 = param1u and string.lower(param1u) or nil;
|
|
local param2 = param2u and string.lower(param2u) or nil;
|
|
local param3 = param3u and string.lower(param3u) or nil;
|
|
|
|
if (cmd == "mem") then
|
|
|
|
UpdateAddOnMemoryUsage();
|
|
|
|
for i = 1, GetNumAddOns() do
|
|
local mem = GetAddOnMemoryUsage(i);
|
|
local name = GetAddOnInfo(i);
|
|
if (mem > 0) then
|
|
local s = string.format ("%6i KB %s", math.floor(mem), name);
|
|
zc.msg_yellow (s);
|
|
end
|
|
end
|
|
|
|
elseif (cmd == "locale") then
|
|
Atr_PickLocalizationTable (param1u);
|
|
|
|
elseif (cmd == "clear") then
|
|
|
|
zc.msg_atr ("memory usage: "..Atr_GetAuctionatorMemString());
|
|
|
|
if (param1 == "fullscandb") then
|
|
gAtr_ScanDB = nil;
|
|
AUCTIONATOR_PRICE_DATABASE = nil;
|
|
Atr_InitScanDB();
|
|
zc.msg_atr (ZT("full scan database cleared"));
|
|
|
|
elseif (param1 == "posthistory") then
|
|
AUCTIONATOR_PRICING_HISTORY = {};
|
|
zc.msg_atr (ZT("pricing history cleared"));
|
|
end
|
|
|
|
collectgarbage ("collect");
|
|
|
|
zc.msg_atr ("memory usage: "..Atr_GetAuctionatorMemString());
|
|
|
|
elseif (Atr_HandleDevCommands and Atr_HandleDevCommands (cmd, param1, param2)) then
|
|
-- do nothing
|
|
else
|
|
zc.msg_atr (ZT("unrecognized command"));
|
|
end
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_InitScanDB()
|
|
|
|
local faction = UnitFactionGroup ("player");
|
|
|
|
if (faction == nil or GetRealmName() == nil) then -- 1.12: not known yet at VARIABLES_LOADED
|
|
if (gAtr_ScanDB == nil) then
|
|
gAtr_ScanDB = {};
|
|
end
|
|
gAtr_ScanDB_Pending = true;
|
|
return;
|
|
end
|
|
|
|
local realmKey = GetRealmName();
|
|
local oldRealmFactionKey = realmKey.."_"..faction; -- the per-faction key this used to be stored under
|
|
|
|
if (AUCTIONATOR_PRICE_DATABASE and AUCTIONATOR_PRICE_DATABASE["__dbversion"] == nil) then -- see if we need to migrate
|
|
|
|
local temp = zc.CopyDeep (AUCTIONATOR_PRICE_DATABASE);
|
|
|
|
AUCTIONATOR_PRICE_DATABASE = {};
|
|
AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 2;
|
|
|
|
AUCTIONATOR_PRICE_DATABASE[oldRealmFactionKey] = zc.CopyDeep (temp);
|
|
|
|
temp = {};
|
|
end
|
|
|
|
if (AUCTIONATOR_PRICE_DATABASE == nil) then
|
|
AUCTIONATOR_PRICE_DATABASE = {};
|
|
AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 2;
|
|
end
|
|
|
|
-- this server runs one neutral auction house shared by both factions, not two separate
|
|
-- ones - merge any old per-faction split into a single realm-wide database so characters of
|
|
-- different factions on the same realm actually share scan data
|
|
if (AUCTIONATOR_PRICE_DATABASE["__dbversion"] < 3) then
|
|
|
|
AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 3;
|
|
|
|
if (AUCTIONATOR_PRICE_DATABASE[realmKey] == nil) then
|
|
AUCTIONATOR_PRICE_DATABASE[realmKey] = {};
|
|
end
|
|
|
|
local i, otherFaction;
|
|
for i, otherFaction in ipairs ({"Alliance", "Horde"}) do
|
|
local oldKey = realmKey.."_"..otherFaction;
|
|
if (AUCTIONATOR_PRICE_DATABASE[oldKey]) then
|
|
local a, v;
|
|
for a, v in pairs (AUCTIONATOR_PRICE_DATABASE[oldKey]) do
|
|
AUCTIONATOR_PRICE_DATABASE[realmKey][a] = v;
|
|
end
|
|
AUCTIONATOR_PRICE_DATABASE[oldKey] = nil;
|
|
end
|
|
end
|
|
end
|
|
|
|
if (AUCTIONATOR_PRICE_DATABASE[realmKey] == nil) then
|
|
AUCTIONATOR_PRICE_DATABASE[realmKey] = {};
|
|
end
|
|
|
|
local db = AUCTIONATOR_PRICE_DATABASE[realmKey];
|
|
|
|
if (gAtr_ScanDB_Pending and gAtr_ScanDB and gAtr_ScanDB ~= db) then -- keep prices learned before the realm was known
|
|
for a,v in pairs (gAtr_ScanDB) do
|
|
db[a] = v;
|
|
end
|
|
end
|
|
|
|
gAtr_ScanDB_Pending = nil;
|
|
gAtr_ScanDB = db;
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnLoad()
|
|
|
|
AuctionatorVersion = Atr_GetVersion();
|
|
|
|
gTimeZero = time({year=2000, month=1, day=1, hour=0});
|
|
gTimeTightZero = time({year=2008, month=8, day=1, hour=0});
|
|
|
|
local x;
|
|
for x = 0, NUM_BAG_SLOTS do
|
|
kBagIDs[x+1] = x;
|
|
end
|
|
|
|
kBagIDs[NUM_BAG_SLOTS+2] = KEYRING_CONTAINER;
|
|
|
|
AuctionatorLoaded = true;
|
|
|
|
SlashCmdList["Auctionator"] = Atr_SlashCmdFunction;
|
|
|
|
SLASH_Auctionator1 = "/auctionator";
|
|
SLASH_Auctionator2 = "/atr";
|
|
|
|
Atr_InitScanDB ();
|
|
|
|
if (AUCTIONATOR_PRICING_HISTORY == nil) then -- the old history of postings
|
|
AUCTIONATOR_PRICING_HISTORY = {};
|
|
end
|
|
|
|
if (AUCTIONATOR_DEPOSITS == nil) then -- deposit paid per posting, so it can be shown/reported later (e.g. on cancel)
|
|
AUCTIONATOR_DEPOSITS = {};
|
|
end
|
|
|
|
if (AUCTIONATOR_TOONS == nil) then
|
|
AUCTIONATOR_TOONS = {};
|
|
end
|
|
|
|
if (AUCTIONATOR_STACKING_PREFS == nil) then
|
|
Atr_StackingPrefs_Init();
|
|
end
|
|
|
|
|
|
local playerName = UnitName("player");
|
|
|
|
if (playerName and not AUCTIONATOR_TOONS[playerName]) then
|
|
AUCTIONATOR_TOONS[playerName] = {};
|
|
AUCTIONATOR_TOONS[playerName].firstSeen = time();
|
|
AUCTIONATOR_TOONS[playerName].firstVersion = AuctionatorVersion;
|
|
end
|
|
|
|
-- (no UnitGUID on 1.12)
|
|
|
|
if (AUCTIONATOR_SCAN_MINLEVEL == nil) then
|
|
AUCTIONATOR_SCAN_MINLEVEL = 1; -- poor (all) items
|
|
end
|
|
|
|
if (AUCTIONATOR_SHOW_TIPS == 0) then -- migrate old option to new ones
|
|
AUCTIONATOR_V_TIPS = 0;
|
|
AUCTIONATOR_A_TIPS = 0;
|
|
AUCTIONATOR_D_TIPS = 0;
|
|
|
|
AUCTIONATOR_SHOW_TIPS = 2;
|
|
end
|
|
|
|
if (AUCTIONATOR_OPEN_FIRST < 2) then -- set to 2 to indicate it's been migrated
|
|
if (AUCTIONATOR_OPEN_FIRST == 1) then AUCTIONATOR_DEFTAB = 1;
|
|
elseif (AUCTIONATOR_OPEN_BUY == 1) then AUCTIONATOR_DEFTAB = 2;
|
|
else AUCTIONATOR_DEFTAB = 0; end;
|
|
|
|
AUCTIONATOR_OPEN_FIRST = 2;
|
|
end
|
|
|
|
|
|
Atr_SetupHookFunctionsEarly();
|
|
|
|
------------------
|
|
|
|
CreateFrame( "GameTooltip", "AtrScanningTooltip", nil, "GameTooltipTemplate" );
|
|
AtrScanningTooltip:SetOwner( WorldFrame, "ANCHOR_NONE" );
|
|
|
|
------------------
|
|
|
|
Atr_InitDETable();
|
|
|
|
if ( IsAddOnLoaded("Blizzard_AuctionUI") ) then -- need this for AH_QuickSearch since that mod forces Blizzard_AuctionUI to load at a startup
|
|
Atr_Init();
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local gPrevTime = 0;
|
|
|
|
function Atr_OnAddonLoaded()
|
|
|
|
local addonName = arg1;
|
|
|
|
if (zc.StringSame (addonName, "blizzard_auctionui")) then
|
|
Atr_Init();
|
|
end
|
|
|
|
if (zc.StringSame (addonName, "lilsparkysWorkshop")) then
|
|
|
|
local LSW_version = GetAddOnMetadata("lilsparkysWorkshop", "Version");
|
|
|
|
if (LSW_version and (LSW_version == "0.72" or LSW_version == "0.90" or LSW_version == "0.91")) then
|
|
|
|
if (LSW_itemPrice) then
|
|
zc.msg ("** |cff00ffff"..ZT("Auctionator provided an auction module to LilSparky's Workshop."), 0, 1, 0);
|
|
zc.msg ("** |cff00ffff"..ZT("Ignore any ERROR message to the contrary below."), 0, 1, 0);
|
|
LSW_itemPrice = Atr_LSW_itemPriceGetAuctionBuyout;
|
|
end
|
|
end
|
|
end
|
|
|
|
Atr_Check_For_Conflicts (addonName);
|
|
|
|
local now = time();
|
|
|
|
-- zc.md (addonName.." time: "..now - gStartingTime);
|
|
|
|
gPrevTime = now;
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnPlayerEnteringWorld()
|
|
|
|
if (gAtr_ScanDB_Pending or gAtr_ScanDB == nil) then
|
|
Atr_InitScanDB();
|
|
end
|
|
|
|
Atr_InitOptionsPanels();
|
|
|
|
-- Atr_MakeOptionsFrameOpaque();
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_LSW_itemPriceGetAuctionBuyout(link)
|
|
|
|
sellPrice = Atr_GetAuctionBuyout(link)
|
|
if sellPrice then
|
|
return sellPrice, false
|
|
else
|
|
return 0, true
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Init()
|
|
|
|
if (AuctionatorInited) then
|
|
return;
|
|
end
|
|
|
|
-- zc.msg("Auctionator Initialized");
|
|
|
|
AuctionatorInited = true;
|
|
|
|
-- in case Atr_OnLoad was cut short
|
|
if (AUCTIONATOR_PRICING_HISTORY == nil) then AUCTIONATOR_PRICING_HISTORY = {}; end
|
|
if (AUCTIONATOR_TOONS == nil) then AUCTIONATOR_TOONS = {}; end
|
|
if (AUCTIONATOR_STACKING_PREFS == nil) then Atr_StackingPrefs_Init(); end
|
|
if (AUCTIONATOR_SCAN_MINLEVEL == nil) then AUCTIONATOR_SCAN_MINLEVEL = 1; end
|
|
if (gAtr_ScanDB_Pending or gAtr_ScanDB == nil) then
|
|
Atr_InitScanDB();
|
|
end
|
|
|
|
if (AUCTIONATOR_SAVEDVARS == nil) then
|
|
Atr_ResetSavedVars();
|
|
end
|
|
|
|
|
|
if (AUCTIONATOR_SHOPPING_LISTS == nil) then
|
|
AUCTIONATOR_SHOPPING_LISTS = {};
|
|
Atr_SList.create (ZT("Recent Searches"), true);
|
|
|
|
if (zc.IsEnglishLocale()) then
|
|
local slist = Atr_SList.create ("Sample Shopping List #1");
|
|
slist:AddItem ("Greater Cosmic Essence");
|
|
slist:AddItem ("Infinite Dust");
|
|
slist:AddItem ("Dream Shard");
|
|
slist:AddItem ("Abyss Crystal");
|
|
end
|
|
else
|
|
Atr_ShoppingListsInit();
|
|
end
|
|
|
|
gShopPane = Atr_AddSellTab (ZT("Buy"), BUY_TAB);
|
|
gSellPane = Atr_AddSellTab (ZT("Sell"), SELL_TAB);
|
|
gMorePane = Atr_AddSellTab (ZT("Listings"), MORE_TAB);
|
|
|
|
Atr_AddMainPanel ();
|
|
|
|
Atr_SetupHookFunctions ();
|
|
|
|
recommendElements[1] = getglobal ("Atr_Recommend_Text");
|
|
recommendElements[2] = getglobal ("Atr_RecommendPerItem_Text");
|
|
recommendElements[3] = getglobal ("Atr_RecommendPerItem_Price");
|
|
recommendElements[4] = getglobal ("Atr_RecommendPerStack_Text");
|
|
recommendElements[5] = getglobal ("Atr_RecommendPerStack_Price");
|
|
recommendElements[6] = getglobal ("Atr_RecommendItem_Tex");
|
|
recommendElements[7] = getglobal ("Atr_RecommendDeposit_Text");
|
|
recommendElements[8] = getglobal ("Atr_RecommendDeposit_Price");
|
|
|
|
-- create the lines that appear in the item history scroll pane / Buy-tab shopping lists.
|
|
-- height and position are set per-redraw (see Atr_DisplayHlist / Atr_SList:DisplayX) since
|
|
-- the two lists use different row heights; just create enough frames for the taller of the two.
|
|
|
|
local line, n;
|
|
|
|
for n = 1, ATR_HLIST_FRAME_COUNT do
|
|
line = CreateFrame("BUTTON", "AuctionatorHEntry"..n, Atr_Hlist, "Atr_HEntryTemplate");
|
|
getglobal("AuctionatorHEntry"..n.."_UCOverlay"):SetTexture ("Interface\\Buttons\\WHITE8X8");
|
|
end
|
|
|
|
Atr_LocalizeFrames();
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_GetSellItemInfo ()
|
|
|
|
local auctionItemName, auctionTexture, auctionCount = GetAuctionSellItemInfo();
|
|
|
|
if (auctionItemName == nil) then
|
|
auctionItemName = "";
|
|
auctionCount = 0;
|
|
end
|
|
|
|
local auctionItemLink = nil;
|
|
|
|
if (auctionItemName ~= "") then
|
|
-- this server returns the item link as the 8th value; otherwise fall back to what we have seen
|
|
auctionItemLink = Atr_SellSlotLink();
|
|
|
|
if (auctionItemLink == nil) then
|
|
return "",0,nil;
|
|
else
|
|
Atr_AddToItemLinkCache (auctionItemName, auctionItemLink);
|
|
end
|
|
|
|
end
|
|
|
|
return auctionItemName, auctionCount, auctionItemLink;
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ResetSavedVars ()
|
|
AUCTIONATOR_SAVEDVARS = zc.CopyDeep (auctionator_savedvars_defaults);
|
|
end
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- don't reference these directly; use the function below instead
|
|
|
|
local _AUCTIONATOR_SELL_TAB_INDEX = 0;
|
|
local _AUCTIONATOR_MORE_TAB_INDEX = 0;
|
|
local _AUCTIONATOR_BUY_TAB_INDEX = 0;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function Atr_FindTabIndex (whichTab)
|
|
|
|
if (_AUCTIONATOR_SELL_TAB_INDEX == 0) then
|
|
|
|
local i = 4;
|
|
while (true) do
|
|
local tab = getglobal('AuctionFrameTab'..i);
|
|
if (tab == nil) then
|
|
break;
|
|
end
|
|
|
|
if (tab.auctionatorTab) then
|
|
if (tab.auctionatorTab == SELL_TAB) then _AUCTIONATOR_SELL_TAB_INDEX = i; end;
|
|
if (tab.auctionatorTab == MORE_TAB) then _AUCTIONATOR_MORE_TAB_INDEX = i; end;
|
|
if (tab.auctionatorTab == BUY_TAB) then _AUCTIONATOR_BUY_TAB_INDEX = i; end;
|
|
end
|
|
|
|
i = i + 1;
|
|
end
|
|
end
|
|
|
|
if (whichTab == SELL_TAB) then return _AUCTIONATOR_SELL_TAB_INDEX ; end;
|
|
if (whichTab == MORE_TAB) then return _AUCTIONATOR_MORE_TAB_INDEX; end;
|
|
if (whichTab == BUY_TAB) then return _AUCTIONATOR_BUY_TAB_INDEX; end;
|
|
|
|
return 0;
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
function Atr_AuctionFrameTab_OnClick (index)
|
|
|
|
if ( index == nil or type(index) == "string") then
|
|
index = this:GetID();
|
|
end
|
|
|
|
getglobal("Atr_Main_Panel"):Hide();
|
|
|
|
gBuyState = ATR_BUY_NULL; -- just in case
|
|
gItemPostingInProgress = false; -- just in case
|
|
|
|
auctionator_orig_AuctionFrameTab_OnClick (index);
|
|
|
|
if (not Atr_IsAuctionatorTab(index)) then
|
|
gForceMsgAreaUpdate = true;
|
|
Atr_HideAllDialogs();
|
|
AuctionFrameMoneyFrame:Show();
|
|
|
|
if (AP_Bid_MoneyFrame) then -- for the addon 'Auction Profit'
|
|
if (AP_ShowBid) then AP_ShowHide_Bid_Button(1); end;
|
|
if (AP_ShowBO) then AP_ShowHide_BO_Button(1); end;
|
|
end
|
|
|
|
|
|
elseif (Atr_IsAuctionatorTab(index)) then
|
|
|
|
AuctionFrameAuctions:Hide();
|
|
AuctionFrameBrowse:Hide();
|
|
AuctionFrameBid:Hide();
|
|
PlaySound("igCharacterInfoTab");
|
|
|
|
PanelTemplates_SetTab(AuctionFrame, index);
|
|
|
|
-- AuctionFrameTopLeft:SetTexture ("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-TopLeft");
|
|
AuctionFrameTopLeft:SetTexture ("Interface\\AddOns\\OctoAuctionatorPlus\\Images\\Atr_topleft.tga");
|
|
AuctionFrameBotLeft:SetTexture ("Interface\\AddOns\\OctoAuctionatorPlus\\Images\\Atr_botleft.tga");
|
|
AuctionFrameTop:SetTexture ("Interface\\AddOns\\OctoAuctionatorPlus\\Images\\Atr_top.tga");
|
|
AuctionFrameTopRight:SetTexture ("Interface\\AddOns\\OctoAuctionatorPlus\\Images\\Atr_topright.tga");
|
|
AuctionFrameBot:SetTexture ("Interface\\AddOns\\OctoAuctionatorPlus\\Images\\Atr_bot.tga");
|
|
AuctionFrameBotRight:SetTexture ("Interface\\AddOns\\OctoAuctionatorPlus\\Images\\Atr_botright.tga");
|
|
|
|
if (index == Atr_FindTabIndex(SELL_TAB)) then gCurrentPane = gSellPane; end;
|
|
if (index == Atr_FindTabIndex(BUY_TAB)) then gCurrentPane = gShopPane; end;
|
|
if (index == Atr_FindTabIndex(MORE_TAB)) then gCurrentPane = gMorePane; end;
|
|
|
|
if (index == Atr_FindTabIndex(SELL_TAB)) then AuctionatorTitle:SetText ("Auctionator - "..ZT("Sell")); end;
|
|
if (index == Atr_FindTabIndex(BUY_TAB)) then AuctionatorTitle:SetText ("Auctionator - "..ZT("Buy")); end;
|
|
if (index == Atr_FindTabIndex(MORE_TAB)) then AuctionatorTitle:SetText ("Auctionator - "..ZT("Listings")); end;
|
|
|
|
Atr_ClearHlist();
|
|
Atr_SellControls:Hide();
|
|
Atr_Hlist:Hide();
|
|
Atr_Hlist_ScrollFrame:Hide();
|
|
Atr_Search_Box:Hide();
|
|
Atr_Search_Button:Hide();
|
|
Atr_AddToSListButton:Hide();
|
|
Atr_RemFromSListButton:Hide();
|
|
Atr_NewSListButton:Hide();
|
|
Atr_DelSListButton:Hide();
|
|
Atr_DropDown1:Hide();
|
|
Atr_DropDownSL:Hide();
|
|
Atr_CheckActiveButton:Hide();
|
|
Atr_Back_Button:Hide()
|
|
|
|
AuctionFrameMoneyFrame:Hide();
|
|
|
|
if (index == Atr_FindTabIndex(SELL_TAB)) then
|
|
Atr_SellControls:Show();
|
|
else
|
|
Atr_Hlist:Show();
|
|
Atr_Hlist_ScrollFrame:Show();
|
|
if (gJustPosted_ItemName) then
|
|
gJustPosted_ItemName = nil;
|
|
gSellPane:ClearSearch ();
|
|
end
|
|
end
|
|
|
|
|
|
if (index == Atr_FindTabIndex(MORE_TAB)) then
|
|
-- always start at the top rather than restoring a remembered offset: the Listings and
|
|
-- Buy tabs now use different row heights but share this one scrollbar widget, so an
|
|
-- offset recorded under one row height lands the scrollbar at the wrong pixel position
|
|
-- under the other, leaving it visually stuck at the top while the list itself is
|
|
-- actually scrolled (and, with ≤10 rows and no scrollbar shown, stuck there for good)
|
|
gCurrentPane.hlistScrollOffset = 0;
|
|
FauxScrollFrame_SetOffset (Atr_Hlist_ScrollFrame, 0);
|
|
if (Atr_Hlist_ScrollFrameScrollBar) then
|
|
Atr_Hlist_ScrollFrameScrollBar:SetValue (0); -- FauxScrollFrame_SetOffset alone doesn't visually snap the slider back to the top
|
|
end
|
|
|
|
if (UIDropDownMenu_GetSelectedValue(Atr_DropDown1) == MODE_LIST_ACTIVE) then
|
|
Atr_CheckActiveButton:Show();
|
|
|
|
-- the one-shot trigger at AH-open (Atr_OnAuctionHouseShow) is a blind,
|
|
-- fire-and-forget request for owned-auction data with no confirmation it
|
|
-- actually got a response - if that race loses (the AH connection wasn't fully
|
|
-- settled yet), owned-auction data stays empty for the rest of the session with
|
|
-- nothing else to retry it. Give it another shot every time this view is
|
|
-- actually looked at, same as the vanilla Auctions tab gets a fresh chance
|
|
-- every time the player clicks into it themselves. Skip it if a page-walk
|
|
-- (read or cancel) is already in flight, to avoid racing that instead.
|
|
if (not gOwnerScanActive and gOwnerCancelState == nil) then
|
|
Atr_RefreshOwnedAuctions ();
|
|
end
|
|
end
|
|
|
|
Atr_DisplayHlist();
|
|
Atr_DropDown1:Show();
|
|
end
|
|
|
|
|
|
if (index == Atr_FindTabIndex(BUY_TAB)) then
|
|
-- same reset as the Listings tab above, and for the same reason: this scrollbar is
|
|
-- shared across tabs that use different row heights, so a position left over from
|
|
-- another tab lands at the wrong pixel offset here
|
|
gCurrentPane.hlistScrollOffset = 0;
|
|
FauxScrollFrame_SetOffset (Atr_Hlist_ScrollFrame, 0);
|
|
if (Atr_Hlist_ScrollFrameScrollBar) then
|
|
Atr_Hlist_ScrollFrameScrollBar:SetValue (0);
|
|
end
|
|
Atr_Search_Box:Show();
|
|
Atr_Search_Button:Show();
|
|
AuctionFrameMoneyFrame:Show();
|
|
Atr_BuildGlobalHistoryList(true);
|
|
Atr_AddToSListButton:Show();
|
|
Atr_RemFromSListButton:Show();
|
|
Atr_NewSListButton:Show();
|
|
Atr_DelSListButton:Show();
|
|
Atr_DropDownSL:Show();
|
|
Atr_Hlist:SetHeight (252);
|
|
Atr_Hlist_ScrollFrame:SetHeight (252);
|
|
else
|
|
Atr_Hlist:SetHeight (335);
|
|
Atr_Hlist_ScrollFrame:SetHeight (335);
|
|
end
|
|
|
|
if (index == Atr_FindTabIndex(BUY_TAB) or index == Atr_FindTabIndex(SELL_TAB)) then
|
|
Atr_Buy1_Button:Show();
|
|
Atr_Buy1_Button:Disable();
|
|
end
|
|
|
|
Atr_HideElems (recommendElements);
|
|
|
|
getglobal("Atr_Main_Panel"):Show();
|
|
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
|
|
if (gOpenAllBags == 1) then
|
|
OpenAllBags(true);
|
|
gOpenAllBags = 0;
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_StackSize ()
|
|
return Atr_Batch_Stacksize:GetNumber();
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetStackSize (n)
|
|
return Atr_Batch_Stacksize:SetText(n);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- the biggest stack size you could possibly set right now - capped by both the item's own max
|
|
-- stack size and how many you actually have to sell, whichever is smaller
|
|
function Atr_MaxPossibleStackSize ()
|
|
|
|
local total = gCurrentPane.totalItems or 0;
|
|
local fullStack = gCurrentPane.fullStackSize or 0;
|
|
|
|
if (fullStack <= 0) then
|
|
return total;
|
|
end
|
|
|
|
return math.min (fullStack, total);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- the biggest number of stacks you could possibly set right now, given the current stack size
|
|
function Atr_MaxPossibleNumAuctions ()
|
|
|
|
if (Atr_StackSize() <= 0) then
|
|
return 0;
|
|
end
|
|
|
|
return math.floor ((gCurrentPane.totalItems or 0) / Atr_StackSize());
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_MaxNumAuctions_OnClick ()
|
|
Atr_Batch_NumAuctions:SetText (Atr_MaxPossibleNumAuctions());
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_MaxStacksize_OnClick ()
|
|
Atr_SetStackSize (Atr_MaxPossibleStackSize());
|
|
Atr_MaxNumAuctions_OnClick (); -- re-max the number of stacks too, now that the stack size just changed
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SelectPane (whichTab)
|
|
|
|
local index = Atr_FindTabIndex(whichTab);
|
|
local tab = getglobal('AuctionFrameTab'..index);
|
|
|
|
Atr_AuctionFrameTab_OnClick (index);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_IsModeCreateAuction ()
|
|
return (Atr_IsTabSelected(SELL_TAB));
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_IsModeBuy ()
|
|
return (Atr_IsTabSelected(BUY_TAB));
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_IsModeActiveAuctions ()
|
|
return (Atr_IsTabSelected(MORE_TAB) and UIDropDownMenu_GetSelectedValue(Atr_DropDown1) == MODE_LIST_ACTIVE);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ClickAuctionSellItemButton (self, button)
|
|
|
|
ClickAuctionSellItemButton();
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnDropItem (self, button)
|
|
|
|
if (not CursorHasItem()) then
|
|
return;
|
|
end
|
|
|
|
if (not Atr_IsTabSelected(SELL_TAB)) then
|
|
Atr_SelectPane (SELL_TAB); -- then fall through
|
|
end
|
|
|
|
Atr_ClickAuctionSellItemButton (self, button);
|
|
ClearCursor();
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SellItemButton_OnClick (self, button)
|
|
|
|
Atr_ClickAuctionSellItemButton (self, button);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SellItemButton_OnEvent (self, event)
|
|
|
|
if ( event == "NEW_AUCTION_UPDATE") then
|
|
local name, texture, count, quality, canUse, price = GetAuctionSellItemInfo();
|
|
Atr_SellControls_Tex:SetNormalTexture(texture);
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local function Atr_LoadContainerItemToSellPane()
|
|
|
|
local bagID = this:GetParent():GetID();
|
|
local slotID = this:GetID();
|
|
|
|
if (not Atr_IsTabSelected(SELL_TAB)) then
|
|
Atr_SelectPane (SELL_TAB);
|
|
end
|
|
|
|
if (IsControlKeyDown()) then
|
|
gAutoSingleton = time();
|
|
end
|
|
|
|
PickupContainerItem(bagID, slotID);
|
|
|
|
if (CursorHasItem()) then
|
|
Atr_ClearAll();
|
|
Atr_ClickAuctionSellItemButton ();
|
|
ClearCursor();
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ContainerFrameItemButton_OnClick (button, ignoreModifiers)
|
|
|
|
if (button == "LeftButton" and AuctionFrame and AuctionFrame:IsShown() and IsAltKeyDown() and not CursorHasItem()) then
|
|
|
|
Atr_LoadContainerItemToSellPane();
|
|
return;
|
|
end
|
|
|
|
return auctionator_orig_ContainerFrameItemButton_OnClick (button, ignoreModifiers);
|
|
end
|
|
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CreateAuction_OnClick ()
|
|
|
|
gJustPosted_ItemName = gCurrentPane.activeScan.itemName;
|
|
gJustPosted_ItemLink = gCurrentPane.activeScan.itemLink;
|
|
gJustPosted_StackSize = Atr_StackSize();
|
|
|
|
-- the Buyout Price field holds a per-item value while the "Price per item" checkbox is
|
|
-- checked instead of the whole stack's total - convert it before this goes anywhere that
|
|
-- expects a per-stack price (everything from here on, including the server)
|
|
local stackBuyoutPrice = MoneyInputFrame_GetCopper(Atr_StackPrice);
|
|
if (gBuyoutIsPerItem) then
|
|
stackBuyoutPrice = stackBuyoutPrice * gJustPosted_StackSize;
|
|
end
|
|
|
|
gJustPosted_BuyoutPrice = stackBuyoutPrice;
|
|
gJustPosted_NumInBagsAtStart = Atr_GetNumItemInBags(gJustPosted_ItemName);
|
|
gJustPosted_NumStacks = Atr_Batch_NumAuctions:GetNumber();
|
|
|
|
local duration = UIDropDownMenu_GetSelectedValue(Atr_Duration);
|
|
local stackStartingPrice = math.max (MoneyInputFrame_GetCopper(Atr_StartingPrice), 1); -- the auction house requires a starting price of at least 1c
|
|
|
|
gJustPosted_Deposit = Atr_CalcDeposit (gJustPosted_ItemLink, gJustPosted_ItemName, gJustPosted_StackSize, duration);
|
|
|
|
if (gJustPosted_StackSize == 1 and gCurrentPane.fullStackSize > 1) then
|
|
|
|
local scan = gCurrentPane.activeScan;
|
|
|
|
if (scan and scan.numYourSingletons + gJustPosted_NumStacks > 40) then
|
|
local s = ZT("You may have at most 40 single-stack (x1)\nauctions posted for this item.\n\nYou already have %d such auctions and\nyou are trying to post %d more.");
|
|
Atr_Error_Display (string.format (s, scan.numYourSingletons, gJustPosted_NumStacks));
|
|
return;
|
|
end
|
|
end
|
|
|
|
Atr_Memorize_Stacking_If();
|
|
|
|
Atr_StartAuction (stackStartingPrice, stackBuyoutPrice, duration, gJustPosted_StackSize, gJustPosted_NumStacks);
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
local gMS_stacksPrev;
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnAuctionMultiSellStart()
|
|
|
|
gMS_stacksPrev = 0;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnAuctionMultiSellUpdate()
|
|
local stacksSoFar = arg1;
|
|
local stacksTotal = arg2;
|
|
|
|
local delta = stacksSoFar - gMS_stacksPrev;
|
|
|
|
--zc.md ("stacksSoFar: ", stacksSoFar, "stacksTotal: ", stacksTotal, "delta: ", delta);
|
|
|
|
gMS_stacksPrev = stacksSoFar;
|
|
|
|
Atr_AddToScan (gJustPosted_ItemName, gJustPosted_StackSize, gJustPosted_BuyoutPrice, delta);
|
|
|
|
if (stacksSoFar == stacksTotal) then
|
|
Atr_LogMsg (gJustPosted_ItemLink, gJustPosted_StackSize, gJustPosted_BuyoutPrice, stacksTotal);
|
|
Atr_AddHistoricalPrice (gJustPosted_ItemName, gJustPosted_BuyoutPrice / gJustPosted_StackSize, gJustPosted_StackSize, gJustPosted_ItemLink);
|
|
Atr_RecordDeposit ();
|
|
Atr_InvalidateActiveAuctions ();
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnAuctionMultiSellFailure()
|
|
|
|
-- each stack that actually posted already went through Atr_OnAuctionMultiSellUpdate (which
|
|
-- accounts for it via Atr_AddToScan); only report a success message here if some stacks truly
|
|
-- went through, and only for that many - never claim one more succeeded than we actually saw.
|
|
if (gMS_stacksPrev > 0) then
|
|
Atr_LogMsg (gJustPosted_ItemLink, gJustPosted_StackSize, gJustPosted_BuyoutPrice, gMS_stacksPrev);
|
|
Atr_RecordDeposit ();
|
|
Atr_InvalidateActiveAuctions ();
|
|
end
|
|
|
|
if (gCurrentPane.activeScan) then
|
|
gCurrentPane.activeScan.whenScanned = 0;
|
|
end
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_AuctionFrameAuctions_Update()
|
|
|
|
auctionator_orig_AuctionFrameAuctions_Update();
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_LogMsg (itemlink, itemcount, price, numstacks)
|
|
|
|
itemlink = Atr_BuildDisplayLink (itemlink) or itemlink;
|
|
|
|
local totalDeposit = (gJustPosted_Deposit or 0) * numstacks;
|
|
local stackWord = (numstacks == 1) and ZT("stack of") or ZT("stacks of");
|
|
local coloredCount = "|cff00dddd"..numstacks.." "..stackWord.." "..itemcount.."x|r";
|
|
|
|
local logmsg = string.format (ZT("Auctions created for %s %s - Total deposit paid: %s, Buyout Price per stack: %s"),
|
|
coloredCount, itemlink, zc.priceToString (totalDeposit), zc.priceToString (price));
|
|
|
|
zc.msg_yellow (logmsg);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- the actual per-page work for the owner-scan walk, shared by both Atr_OnAuctionOwnedUpdate (the
|
|
-- event normally arrives once the page we asked for is ready) and Atr_OwnerScanStep's timeout
|
|
-- fallback (the event never arrives if the requested page was already the client's current page -
|
|
-- no real fetch happens, so nothing re-fires AUCTION_OWNED_LIST_UPDATE). gOwnerScanPageHandled
|
|
-- guards against running this twice for the same page if the event fires right after a timeout
|
|
-- already processed it.
|
|
function Atr_OwnerScanProcessPage ()
|
|
|
|
if (gOwnerScanPageHandled) then
|
|
return;
|
|
end
|
|
gOwnerScanPageHandled = true;
|
|
|
|
local numBatch, totalAuctions = GetNumAuctionItems ("owner");
|
|
|
|
local i;
|
|
for i = 1, numBatch do
|
|
local name, texture, count, quality = GetAuctionItemInfo ("owner", i);
|
|
|
|
if (name and count > 0) then
|
|
gActiveAuctions[name] = (gActiveAuctions[name] or 0) + count;
|
|
|
|
if (texture and not gActiveAuctionIcons[name]) then
|
|
gActiveAuctionIcons[name] = texture;
|
|
end
|
|
|
|
if (quality and not gActiveAuctionRarity[name]) then
|
|
gActiveAuctionRarity[name] = quality;
|
|
end
|
|
end
|
|
end
|
|
|
|
if ((gOwnerScanPage + 1) * 50 < (totalAuctions or 0)) then
|
|
gOwnerScanPage = gOwnerScanPage + 1;
|
|
gOwnerScanT = GetTime();
|
|
gOwnerScanPageHandled = false;
|
|
GetOwnerAuctionItems (gOwnerScanPage);
|
|
else
|
|
gOwnerScanActive = false;
|
|
gHlistNeedsUpdate = true; -- the full, now-complete list is ready to redraw
|
|
|
|
-- put the shared owner-page cursor back at page 0 for whatever reads it next, rather
|
|
-- than leaving it wherever this walk happened to end
|
|
if (gOwnerScanPage > 0) then
|
|
gOwnerScanResetting = true;
|
|
GetOwnerAuctionItems (0);
|
|
end
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- polled every frame from Atr_OnUpdate; a no-op unless a walk is active and waiting past its
|
|
-- timeout for a page that the event-driven path (Atr_OnAuctionOwnedUpdate) hasn't picked up yet
|
|
function Atr_OwnerScanStep ()
|
|
|
|
if (gOwnerScanActive and not gOwnerScanPageHandled and (GetTime() - gOwnerScanT > 0.5)) then
|
|
Atr_OwnerScanProcessPage ();
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnAuctionOwnedUpdate ()
|
|
|
|
gItemPostingInProgress = false;
|
|
|
|
-- this single event does multiple duty: it's "something about your owned auctions changed"
|
|
-- AND (if any of the states below are active) the arrival of whichever page we just
|
|
-- explicitly requested via GetOwnerAuctionItems. Handle whichever walk is in progress first,
|
|
-- unconditionally - everything below still runs too (a posting confirmation can overlap with
|
|
-- one of these), it just mustn't flush gActiveAuctions out from under a walk that's still
|
|
-- filling it in, or out from under the trailing page-0 reset right after one finishes.
|
|
local wasScanning = gOwnerScanActive or gOwnerScanResetting;
|
|
|
|
-- Atr_OwnerCancelStep (polled from Atr_OnUpdate) does the actual work for a cancel walk; this
|
|
-- handler's only job for it is to notice once a page it explicitly requested has arrived
|
|
if (gOwnerCancelState == "pageloading") then
|
|
gOwnerCancelState = "findmatch";
|
|
end
|
|
|
|
if (gOwnerScanResetting) then
|
|
|
|
gOwnerScanResetting = false; -- just absorb this one; it only exists to repoint the shared owner-page cursor back to 0
|
|
|
|
elseif (gOwnerScanActive) then
|
|
|
|
Atr_OwnerScanProcessPage ();
|
|
|
|
end
|
|
|
|
if (Atr_IsModeActiveAuctions()) then
|
|
gHlistNeedsUpdate = true;
|
|
end
|
|
|
|
if (not Atr_IsTabSelected()) then
|
|
Atr_ClearScanCache(); -- if not our tab, we have no idea what happened so must flush all caches
|
|
return;
|
|
end;
|
|
|
|
if (not wasScanning) then
|
|
gActiveAuctions = {}; -- flush so the next view of Active Listings starts a fresh scan
|
|
gActiveAuctionIcons = {};
|
|
gActiveAuctionRarity = {};
|
|
end
|
|
|
|
if (gJustPosted_ItemName) then
|
|
|
|
if (gJustPosted_NumStacks == 1) then
|
|
Atr_LogMsg (gJustPosted_ItemLink, gJustPosted_StackSize, gJustPosted_BuyoutPrice, 1);
|
|
Atr_AddHistoricalPrice (gJustPosted_ItemName, gJustPosted_BuyoutPrice / gJustPosted_StackSize, gJustPosted_StackSize, gJustPosted_ItemLink);
|
|
Atr_AddToScan (gJustPosted_ItemName, gJustPosted_StackSize, gJustPosted_BuyoutPrice, 1);
|
|
Atr_RecordDeposit ();
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ResetDuration()
|
|
|
|
-- Duration isn't the only dropdown in this addon (or in the game), and they all share one
|
|
-- global pop-up button pool - SetSelectedValue matches against whichever dropdown's list was
|
|
-- populated into it most recently. Re-Initialize right before selecting so it's always
|
|
-- Duration's own list being matched against, not some other dropdown's stale leftovers
|
|
-- (confirmed bug: seen displaying "Uncommon" - a scan-quality dropdown entry that happens to
|
|
-- share value 3 with Duration's own "72 hours").
|
|
if (AUCTIONATOR_DEF_DURATION == "S") then UIDropDownMenu_Initialize (Atr_Duration, Atr_Duration_Initialize); UIDropDownMenu_SetSelectedValue(Atr_Duration, 1); end;
|
|
if (AUCTIONATOR_DEF_DURATION == "M") then UIDropDownMenu_Initialize (Atr_Duration, Atr_Duration_Initialize); UIDropDownMenu_SetSelectedValue(Atr_Duration, 2); end;
|
|
if (AUCTIONATOR_DEF_DURATION == "L") then UIDropDownMenu_Initialize (Atr_Duration, Atr_Duration_Initialize); UIDropDownMenu_SetSelectedValue(Atr_Duration, 3); end;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_AddToScan (itemName, stackSize, buyoutPrice, numAuctions)
|
|
|
|
local scan = Atr_FindScan (itemName);
|
|
|
|
scan:AddScanItem (itemName, stackSize, buyoutPrice, UnitName("player"), numAuctions);
|
|
|
|
scan:CondenseAndSort ();
|
|
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function AuctionatorSubtractFromScan (itemName, stackSize, buyoutPrice, howMany)
|
|
|
|
if (howMany == nil) then
|
|
howMany = 1;
|
|
end
|
|
|
|
local scan = Atr_FindScan (itemName);
|
|
|
|
local x;
|
|
for x = 1, howMany do
|
|
scan:SubtractScanItem (itemName, stackSize, buyoutPrice);
|
|
end
|
|
|
|
scan:CondenseAndSort ();
|
|
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function auctionator_ChatFrame_OnEvent(event)
|
|
|
|
if (event == "CHAT_MSG_SYSTEM") then
|
|
if (arg1 == ERR_AUCTION_STARTED) then -- absorb the Auction Created message
|
|
return;
|
|
end
|
|
if (arg1 == ERR_AUCTION_REMOVED) then -- absorb the Auction Cancelled message
|
|
if (gOwnerCancelState == "cancelwait") then
|
|
gOwnerCancelConfirmed = true;
|
|
end
|
|
return;
|
|
end
|
|
if (arg1 and string.find (arg1, "Auction deposit")) then -- this server's own per-auction deposit-paid notice - redundant with our "Auctions created for..." summary, and spams once per auction in a batch
|
|
return;
|
|
end
|
|
end
|
|
|
|
return auctionator_orig_ChatFrame_OnEvent (event);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_AddMainPanel ()
|
|
|
|
local frame = CreateFrame("FRAME", "Atr_Main_Panel", AuctionFrame, "Atr_Sell_Template");
|
|
frame:Hide();
|
|
|
|
UIDropDownMenu_SetWidth (150, Atr_DropDownSL);
|
|
UIDropDownMenu_JustifyText ("CENTER", Atr_DropDownSL);
|
|
|
|
UIDropDownMenu_SetWidth (95, Atr_Duration);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_AddSellTab (tabtext, whichTab)
|
|
|
|
local n = AuctionFrame.numTabs+1;
|
|
|
|
local framename = "AuctionFrameTab"..n;
|
|
|
|
local frame = CreateFrame("Button", framename, AuctionFrame, "AuctionTabTemplate");
|
|
|
|
frame:SetID(n);
|
|
frame:SetText(tabtext);
|
|
|
|
local orange = getglobal("AtrFontOrange");
|
|
if (orange and frame.SetTextFontObject) then
|
|
frame:SetTextFontObject(orange);
|
|
end
|
|
|
|
frame.auctionatorTab = whichTab;
|
|
|
|
frame:SetPoint("LEFT", getglobal("AuctionFrameTab"..n-1), "RIGHT", -8, 0);
|
|
|
|
pcall (PanelTemplates_TabResize, 0, frame);
|
|
PanelTemplates_SetNumTabs (AuctionFrame, n);
|
|
PanelTemplates_EnableTab (AuctionFrame, n);
|
|
|
|
return AtrPane.create (whichTab);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_HideElems (tt)
|
|
|
|
if (not tt) then
|
|
return;
|
|
end
|
|
|
|
for i,x in ipairs(tt) do
|
|
x:Hide();
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowElems (tt)
|
|
|
|
for i,x in ipairs(tt) do
|
|
x:Show();
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnAuctionUpdate ()
|
|
|
|
if (gAtr_FullScanState == ATR_FS_STARTED) then
|
|
Atr_FullScanAnalyze();
|
|
return;
|
|
end
|
|
|
|
if (not Atr_IsTabSelected()) then
|
|
Atr_ClearScanCache(); -- if not our tab, we have no idea what happened so must flush all caches
|
|
return;
|
|
end;
|
|
|
|
if (Atr_Buy_OnAuctionUpdate()) then
|
|
return;
|
|
end
|
|
|
|
if (gCurrentPane.activeSearch and gCurrentPane.activeSearch.processing_state == KM_POSTQUERY) then
|
|
|
|
local search = gCurrentPane.activeSearch;
|
|
|
|
if (Atr_PageHasMissingNames()) then -- 1.12: names of items not seen yet arrive a moment later
|
|
if (search.namesWaitStart == nil) then
|
|
search.namesWaitStart = GetTime();
|
|
end
|
|
if (GetTime() - search.namesWaitStart < 2) then
|
|
return;
|
|
end
|
|
end
|
|
|
|
search.namesWaitStart = nil;
|
|
|
|
local isDup = gCurrentPane.activeSearch:CheckForDuplicatePage ();
|
|
|
|
if (not isDup) then
|
|
|
|
local done = gCurrentPane.activeSearch:AnalyzeResultsPage();
|
|
|
|
if (done) then
|
|
gCurrentPane.activeSearch:Finish();
|
|
Atr_OnSearchComplete ();
|
|
else
|
|
gCurrentPane.activeSearch:UpdatePartial();
|
|
Atr_OnSearchPartial ();
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_PickKey (scan, idx)
|
|
|
|
if (scan and idx and scan.sortedData and scan.sortedData[idx]) then
|
|
local d = scan.sortedData[idx];
|
|
return d.stackSize.."_"..d.buyoutPrice.."_"..tostring(d.yours).."_"..tostring(d.type);
|
|
end
|
|
|
|
return nil;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_FindPickKey (scan, key)
|
|
|
|
if (scan and key and scan.sortedData) then
|
|
local i;
|
|
for i = 1, getn(scan.sortedData) do
|
|
if (Atr_PickKey (scan, i) == key) then
|
|
return i;
|
|
end
|
|
end
|
|
end
|
|
|
|
return nil;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnSearchPartial ()
|
|
|
|
local search = gCurrentPane.activeSearch;
|
|
|
|
if (gCurrentPane:IsScanEmpty() and search:NumScans() == 1) then -- the item asked for: show its auctions right away
|
|
local scn = search:GetFirstScan();
|
|
if (scn and zc.StringSame (scn.itemName, search.searchText)) then
|
|
gCurrentPane.activeScan = scn;
|
|
end
|
|
end
|
|
|
|
if (gCurrentPane.pickKey) then
|
|
gCurrentPane.currIndex = Atr_FindPickKey (gCurrentPane.activeScan, gCurrentPane.pickKey);
|
|
if (gCurrentPane.currIndex == nil) then
|
|
gCurrentPane.pickKey = nil;
|
|
end
|
|
end
|
|
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SearchProgressText ()
|
|
|
|
local search = gCurrentPane.activeSearch;
|
|
local page = search.current_page or 0;
|
|
|
|
if (page < 1) then
|
|
page = 1;
|
|
end
|
|
|
|
if (search.totalPages and search.totalPages > 1) then
|
|
if (page > search.totalPages) then
|
|
page = search.totalPages;
|
|
end
|
|
return string.format (ZT("Scanning auctions: page %d"), page).." / "..search.totalPages;
|
|
end
|
|
|
|
return string.format (ZT("Scanning auctions: page %d"), page);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnSearchComplete ()
|
|
|
|
gCurrentPane.sortedHist = nil;
|
|
|
|
local count = gCurrentPane.activeSearch:NumScans();
|
|
if (count == 1) then
|
|
gCurrentPane.activeScan = gCurrentPane.activeSearch:GetFirstScan();
|
|
end
|
|
|
|
if (Atr_IsModeCreateAuction()) then
|
|
|
|
gCurrentPane:SetToShowCurrent();
|
|
|
|
if (getn(gCurrentPane.activeScan.scanData) == 0) then
|
|
gCurrentPane.hints = Atr_BuildHints (gCurrentPane.activeScan.itemName);
|
|
if (getn(gCurrentPane.hints) > 0) then
|
|
gCurrentPane:SetToShowHints();
|
|
gCurrentPane.hintsIndex = 1;
|
|
end
|
|
|
|
end
|
|
|
|
if (gCurrentPane:ShowCurrent()) then
|
|
Atr_FindBestCurrentAuction ();
|
|
end
|
|
|
|
Atr_UpdateRecommendation(true);
|
|
else
|
|
if (Atr_IsModeActiveAuctions()) then
|
|
Atr_DisplayHlist();
|
|
end
|
|
|
|
Atr_FindBestCurrentAuction ();
|
|
end
|
|
|
|
if (Atr_IsModeBuy()) then
|
|
Atr_Shop_OnFinishScan ();
|
|
end
|
|
|
|
Atr_CheckingActive_OnSearchComplete();
|
|
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ClearTop ()
|
|
Atr_HideElems (recommendElements);
|
|
|
|
if (AuctionatorMessageFrame) then
|
|
AuctionatorMessageFrame:Hide();
|
|
AuctionatorMessage2Frame:Hide();
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ClearList ()
|
|
|
|
Atr_Col1_Heading:Hide();
|
|
Atr_Col3_Heading:Hide();
|
|
Atr_Col4_Heading:Hide();
|
|
|
|
Atr_Col1_Heading_Button:Hide();
|
|
Atr_Col3_Heading_Button:Hide();
|
|
|
|
local line; -- 1 through 12 of our window to scroll
|
|
|
|
FauxScrollFrame_Update (AuctionatorScrollFrame, 0, 12, 16);
|
|
|
|
for line = 1,12 do
|
|
local lineEntry = getglobal ("AuctionatorEntry"..line);
|
|
lineEntry:Hide();
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ClearAll ()
|
|
|
|
if (AuctionatorMessageFrame) then -- just to make sure xml has been loaded
|
|
|
|
Atr_ClearTop();
|
|
Atr_ClearList();
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetMessage (msg)
|
|
Atr_HideElems (recommendElements);
|
|
|
|
if (gCurrentPane.activeSearch.searchText) then
|
|
|
|
Atr_ShowItemNameAndTexture (gCurrentPane.activeSearch.searchText);
|
|
|
|
AuctionatorMessage2Frame:SetText (msg);
|
|
AuctionatorMessage2Frame:Show();
|
|
|
|
else
|
|
AuctionatorMessageFrame:SetText (msg);
|
|
AuctionatorMessageFrame:Show();
|
|
AuctionatorMessage2Frame:Hide();
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowItemNameAndTexture(itemName)
|
|
|
|
AuctionatorMessageFrame:Hide();
|
|
AuctionatorMessage2Frame:Hide();
|
|
|
|
local scn = gCurrentPane.activeScan;
|
|
|
|
if (scn and not scn:IsNil()) then
|
|
local color = "|cff"..zc.RGBtoHEX (scn.itemTextColor[1], scn.itemTextColor[2], scn.itemTextColor[3]);
|
|
Atr_Recommend_Text:SetText (color..scn.itemName);
|
|
elseif (Atr_IsModeBuy() and itemName and itemName ~= "") then
|
|
Atr_Recommend_Text:SetText (string.format (ZT("Searching for: \"%s\""), itemName));
|
|
else
|
|
Atr_Recommend_Text:SetText ("");
|
|
end
|
|
|
|
Atr_Recommend_Text:Show ();
|
|
|
|
Atr_SetTextureButton ("Atr_RecommendItem_Tex", 1, gCurrentPane.activeScan.itemLink);
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SortHistoryData (x, y)
|
|
|
|
return x.when > y.when;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function BuildHtag (type, y, m, d)
|
|
|
|
local t = time({year=y, month=m, day=d, hour=0});
|
|
|
|
return tostring (ToTightTime(t))..":"..type;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function ParseHtag (tag)
|
|
local when, type = Atr_strsplit (":", tag);
|
|
|
|
if (type == nil) then
|
|
type = "hx";
|
|
end
|
|
|
|
when = FromTightTime (tonumber (when));
|
|
|
|
return when, type;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function ParseHist (tag, hist)
|
|
|
|
local when, type = ParseHtag(tag);
|
|
|
|
local price, count = Atr_strsplit (":", hist);
|
|
|
|
price = tonumber (price);
|
|
|
|
local stacksize, numauctions;
|
|
|
|
if (type == "hx") then
|
|
stacksize = tonumber (count);
|
|
numauctions = 1;
|
|
else
|
|
stacksize = 0;
|
|
numauctions = tonumber (count);
|
|
end
|
|
|
|
return when, type, price, stacksize, numauctions;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function CalcAbsTimes (when, whent)
|
|
|
|
local absYear = whent.year - 2000;
|
|
local absMonth = (absYear * 12) + whent.month;
|
|
local absDay = floor ((when - gTimeZero) / (60*60*24));
|
|
|
|
return absYear, absMonth, absDay;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Condense_History (itemname)
|
|
|
|
if (AUCTIONATOR_PRICING_HISTORY[itemname] == nil) then
|
|
return;
|
|
end
|
|
|
|
local tempHistory = {};
|
|
|
|
local now = time();
|
|
local nowt = date("*t", now);
|
|
|
|
local absNowYear, absNowMonth, absNowDay = CalcAbsTimes (now, nowt);
|
|
|
|
local n = 1;
|
|
local tag, hist, newtag, stacksize, numauctions;
|
|
for tag, hist in pairs (AUCTIONATOR_PRICING_HISTORY[itemname]) do
|
|
if (tag ~= "is") then
|
|
|
|
local when, type, price, stacksize, numauctions = ParseHist (tag, hist);
|
|
|
|
local whnt = date("*t", when);
|
|
|
|
local absYear, absMonth, absDay = CalcAbsTimes (when, whnt);
|
|
|
|
if (absNowYear - absYear >= 3) then
|
|
newtag = BuildHtag ("hy", whnt.year, 1, 1);
|
|
elseif (absNowMonth - absMonth >= 2) then
|
|
newtag = BuildHtag ("hm", whnt.year, whnt.month, 1);
|
|
elseif (absNowDay - absDay >= 2) then
|
|
newtag = BuildHtag ("hd", whnt.year, whnt.month, whnt.day);
|
|
else
|
|
newtag = tag;
|
|
end
|
|
|
|
tempHistory[n] = {};
|
|
tempHistory[n].price = price;
|
|
tempHistory[n].numauctions = numauctions;
|
|
tempHistory[n].stacksize = stacksize;
|
|
tempHistory[n].when = when;
|
|
tempHistory[n].newtag = newtag;
|
|
n = n + 1;
|
|
end
|
|
end
|
|
|
|
-- clear all the existing history
|
|
|
|
local is = AUCTIONATOR_PRICING_HISTORY[itemname]["is"];
|
|
|
|
AUCTIONATOR_PRICING_HISTORY[itemname] = {};
|
|
AUCTIONATOR_PRICING_HISTORY[itemname]["is"] = is;
|
|
|
|
-- repopulate the history
|
|
|
|
local x;
|
|
|
|
for x = 1,getn(tempHistory) do
|
|
|
|
local thist = tempHistory[x];
|
|
local newtag = thist.newtag;
|
|
|
|
if (AUCTIONATOR_PRICING_HISTORY[itemname][newtag] == nil) then
|
|
|
|
local when, type = ParseHtag (newtag);
|
|
|
|
local count = thist.numauctions;
|
|
if (type == "hx") then
|
|
count = thist.stacksize;
|
|
end
|
|
|
|
AUCTIONATOR_PRICING_HISTORY[itemname][newtag] = tostring(thist.price)..":"..tostring(count);
|
|
|
|
else
|
|
|
|
local hist = AUCTIONATOR_PRICING_HISTORY[itemname][newtag];
|
|
|
|
local when, type, price, stacksize, numauctions = ParseHist (newtag, hist);
|
|
|
|
local newNumAuctions = numauctions + thist.numauctions;
|
|
local newPrice = ((price * numauctions) + (thist.price * thist.numauctions)) / newNumAuctions;
|
|
|
|
AUCTIONATOR_PRICING_HISTORY[itemname][newtag] = tostring(newPrice)..":"..tostring(newNumAuctions);
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Process_Historydata ()
|
|
|
|
-- Condense the data if needed - only once per session for each item
|
|
|
|
if (gCurrentPane:IsScanEmpty()) then
|
|
return;
|
|
end
|
|
|
|
local itemName = gCurrentPane.activeScan.itemName;
|
|
|
|
if (gCondensedThisSession[itemName] == nil) then
|
|
|
|
gCondensedThisSession[itemName] = true;
|
|
|
|
Atr_Condense_History(itemName);
|
|
end
|
|
|
|
-- build the sorted history list
|
|
|
|
gCurrentPane.sortedHist = {};
|
|
|
|
if (AUCTIONATOR_PRICING_HISTORY[itemName]) then
|
|
local n = 1;
|
|
local tag, hist;
|
|
for tag, hist in pairs (AUCTIONATOR_PRICING_HISTORY[itemName]) do
|
|
if (tag ~= "is") then
|
|
local when, type, price, stacksize, numauctions = ParseHist (tag, hist);
|
|
|
|
if (stacksize == 0) then
|
|
stacksize = numauctions;
|
|
end
|
|
|
|
gCurrentPane.sortedHist[n] = {};
|
|
gCurrentPane.sortedHist[n].itemPrice = price;
|
|
gCurrentPane.sortedHist[n].buyoutPrice = price * stacksize;
|
|
gCurrentPane.sortedHist[n].stackSize = stacksize;
|
|
gCurrentPane.sortedHist[n].when = when;
|
|
gCurrentPane.sortedHist[n].yours = true;
|
|
gCurrentPane.sortedHist[n].type = type;
|
|
|
|
n = n + 1;
|
|
end
|
|
end
|
|
end
|
|
|
|
table.sort (gCurrentPane.sortedHist, Atr_SortHistoryData);
|
|
|
|
if (getn(gCurrentPane.sortedHist) > 0) then
|
|
return gCurrentPane.sortedHist[1].itemPrice;
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_GetMostRecentSale (itemName)
|
|
|
|
local recentPrice;
|
|
local recentWhen = 0;
|
|
|
|
if (AUCTIONATOR_PRICING_HISTORY and AUCTIONATOR_PRICING_HISTORY[itemName]) then
|
|
local n = 1;
|
|
local tag, hist;
|
|
for tag, hist in pairs (AUCTIONATOR_PRICING_HISTORY[itemName]) do
|
|
if (tag ~= "is") then
|
|
local when, type, price = ParseHist (tag, hist);
|
|
|
|
if (when > recentWhen) then
|
|
recentPrice = price;
|
|
recentWhen = when;
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return recentPrice;
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowingSearchSummary ()
|
|
|
|
if (gCurrentPane.activeSearch and gCurrentPane.activeSearch.searchText ~= "" and gCurrentPane:IsScanEmpty() and gCurrentPane.activeSearch:NumScans() > 0) then
|
|
return true;
|
|
end
|
|
|
|
return false;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowingCurrentAuctions ()
|
|
if (gCurrentPane) then
|
|
return gCurrentPane:ShowCurrent();
|
|
end
|
|
|
|
return true;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowingHistory ()
|
|
if (gCurrentPane) then
|
|
return gCurrentPane:ShowHistory();
|
|
end
|
|
|
|
return false;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowingHints ()
|
|
if (gCurrentPane) then
|
|
return gCurrentPane:ShowHints();
|
|
end
|
|
|
|
return false;
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_UpdateRecommendation (updatePrices)
|
|
|
|
-- gJustPosted_ItemLink stays set indefinitely after posting (not cleared just because the
|
|
-- slot ends up empty), so gating on it here used to block this function forever once the
|
|
-- sell slot settled empty - not just during the brief transient window right after the last
|
|
-- auction posts, which is all this was ever meant to guard against
|
|
if (gCurrentPane == gSellPane and Atr_PostingInProgress()) then
|
|
return;
|
|
end
|
|
|
|
local basedata;
|
|
|
|
if (Atr_ShowingSearchSummary()) then
|
|
|
|
elseif (Atr_ShowingCurrentAuctions()) then
|
|
|
|
-- while a multi-page scan is still running, sortedData/numMatches can be mid-rebuild, so
|
|
-- skip showing anything new based on them - but if a row's already selected, its basedata
|
|
-- is already known-good and shouldn't keep getting hidden just because the broader scan
|
|
-- (for other items) hasn't finished yet
|
|
if (gCurrentPane:GetProcessingState() ~= KM_NULL_STATE and not gCurrentPane.currIndex) then
|
|
return;
|
|
end
|
|
|
|
if (getn(gCurrentPane.activeScan.sortedData) == 0) then
|
|
Atr_SetMessage (ZT("No current auctions found"));
|
|
return;
|
|
end
|
|
|
|
if (not gCurrentPane.currIndex) then
|
|
if (gCurrentPane.activeScan.numMatches == 0) then
|
|
Atr_SetMessage (ZT("No current auctions found\n\n(related auctions shown)"));
|
|
elseif (gCurrentPane.activeScan.numMatchesWithBuyout == 0) then
|
|
Atr_SetMessage (ZT("No current auctions with buyouts found"));
|
|
else
|
|
Atr_SetMessage ("");
|
|
end
|
|
return;
|
|
end
|
|
|
|
basedata = gCurrentPane.activeScan.sortedData[gCurrentPane.currIndex];
|
|
|
|
elseif (Atr_ShowingHistory()) then
|
|
|
|
basedata = zc.GetArrayElemOrFirst (gCurrentPane.sortedHist, gCurrentPane.histIndex);
|
|
|
|
if (basedata == nil) then
|
|
Atr_SetMessage (ZT("Auctionator has yet to record any auctions for this item"));
|
|
return;
|
|
end
|
|
|
|
else -- hints
|
|
|
|
local data = zc.GetArrayElemOrFirst (gCurrentPane.hints, gCurrentPane.hintsIndex);
|
|
|
|
if (data) then
|
|
basedata = {};
|
|
basedata.itemPrice = data.price;
|
|
basedata.buyoutPrice = data.price;
|
|
basedata.stackSize = 1;
|
|
basedata.sourceText = data.text;
|
|
basedata.yours = true; -- so no discounting
|
|
end
|
|
end
|
|
|
|
local new_Item_BuyoutPrice;
|
|
local recommendStackSize;
|
|
|
|
if (gItemPostingInProgress and gCurrentPane.itemLink == gJustPosted_ItemLink) then -- handle the unusual case where server is still in the process of creating the last auction
|
|
|
|
new_Item_BuyoutPrice = gJustPosted_BuyoutPrice / gJustPosted_StackSize;
|
|
recommendStackSize = gJustPosted_StackSize;
|
|
|
|
elseif (basedata) then -- the normal case
|
|
|
|
new_Item_BuyoutPrice = basedata.itemPrice;
|
|
recommendStackSize = basedata.stackSize;
|
|
|
|
if (not basedata.yours and not basedata.altname) then
|
|
new_Item_BuyoutPrice = Atr_CalcUndercutPrice (new_Item_BuyoutPrice);
|
|
end
|
|
end
|
|
|
|
if (new_Item_BuyoutPrice == nil) then
|
|
return;
|
|
end
|
|
|
|
local new_Item_StartPrice = Atr_CalcStartPrice (new_Item_BuyoutPrice);
|
|
|
|
Atr_ShowElems (recommendElements);
|
|
AuctionatorMessageFrame:Hide();
|
|
AuctionatorMessage2Frame:Hide();
|
|
|
|
local scn = gCurrentPane.activeScan;
|
|
local itemNameColored = scn.itemName;
|
|
if (scn.itemTextColor) then
|
|
itemNameColored = "|cff"..zc.RGBtoHEX (scn.itemTextColor[1], scn.itemTextColor[2], scn.itemTextColor[3])..scn.itemName.."|r";
|
|
end
|
|
|
|
local coloredCount = "|cff55ddff"..recommendStackSize.."x|r";
|
|
Atr_Recommend_Text:SetText (string.format (ZT("Buyout Price for %s %s"), coloredCount, itemNameColored));
|
|
Atr_RecommendPerStack_Text:SetText ("|cff55ddfffor "..recommendStackSize.."|r");
|
|
|
|
if (basedata and basedata.yours and Atr_ShowingCurrentAuctions()) then
|
|
local deposit = Atr_GetRecordedDeposit (scn.itemName, basedata.buyoutPrice, basedata.stackSize);
|
|
if (deposit) then
|
|
-- identical auctions (same stack size and buyout price) condense into one row with a
|
|
-- count, instead of a separate row each - multiply the per-auction deposit by that
|
|
-- count for the true total
|
|
local count = basedata.count or 1;
|
|
local totalDeposit = deposit * count;
|
|
|
|
Atr_RecommendDeposit_Text:SetText (ZT("Total deposit paid")..":");
|
|
|
|
-- shift the money display left when it has fewer denominations, so a short amount
|
|
-- doesn't leave a big empty gap between it and the label
|
|
local depositX = -10;
|
|
if (totalDeposit < 100) then
|
|
depositX = -70; -- copper only
|
|
elseif (totalDeposit < 10000) then
|
|
depositX = -35; -- silver + copper
|
|
end
|
|
Atr_RecommendDeposit_Price:ClearAllPoints ();
|
|
Atr_RecommendDeposit_Price:SetPoint ("TOPRIGHT", depositX, -123);
|
|
|
|
MoneyFrame_Update ("Atr_RecommendDeposit_Price", totalDeposit);
|
|
Atr_RecommendDeposit_Text:Show ();
|
|
Atr_RecommendDeposit_Price:Show ();
|
|
else
|
|
Atr_RecommendDeposit_Text:Hide ();
|
|
Atr_RecommendDeposit_Price:Hide ();
|
|
end
|
|
else
|
|
Atr_RecommendDeposit_Text:Hide ();
|
|
Atr_RecommendDeposit_Price:Hide ();
|
|
end
|
|
|
|
Atr_SetTextureButton ("Atr_RecommendItem_Tex", recommendStackSize, gCurrentPane.activeScan.itemLink);
|
|
|
|
MoneyFrame_Update ("Atr_RecommendPerItem_Price", zc.round(new_Item_BuyoutPrice));
|
|
MoneyFrame_Update ("Atr_RecommendPerStack_Price", zc.round(new_Item_BuyoutPrice * recommendStackSize));
|
|
|
|
Atr_RecommendPerStack_Text:Show ();
|
|
Atr_RecommendPerStack_Price:Show ();
|
|
|
|
-- the per-item price is redundant with the per-stack price when the stack is just one item
|
|
if (recommendStackSize > 1) then
|
|
Atr_RecommendPerItem_Text:Show ();
|
|
Atr_RecommendPerItem_Price:Show ();
|
|
else
|
|
Atr_RecommendPerItem_Text:Hide ();
|
|
Atr_RecommendPerItem_Price:Hide ();
|
|
end
|
|
|
|
-- clicking an auction row only feeds its price into the Sell tab's own input fields while
|
|
-- actually composing there - on the Buy/Listings tabs it's purely informational
|
|
if (updatePrices and Atr_IsModeCreateAuction()) then
|
|
if (gBuyoutIsPerItem) then
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, new_Item_BuyoutPrice);
|
|
else
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, new_Item_BuyoutPrice * Atr_StackSize());
|
|
end
|
|
Atr_ApplyStartingPrice (new_Item_StartPrice);
|
|
gSellItemPrice = new_Item_BuyoutPrice;
|
|
Atr_UpdateItemPriceButton ();
|
|
end
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_StackPriceChangedFunc ()
|
|
|
|
local enteredPrice = MoneyInputFrame_GetCopper (Atr_StackPrice);
|
|
|
|
if (gBuyoutIsPerItem) then
|
|
gSellItemPrice = enteredPrice;
|
|
else
|
|
gSellItemPrice = math.floor (enteredPrice / Atr_StackSize());
|
|
end
|
|
|
|
local new_Item_StartPrice = Atr_CalcStartPrice (gSellItemPrice);
|
|
|
|
Atr_ApplyStartingPrice (new_Item_StartPrice);
|
|
Atr_UpdateItemPriceButton ();
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_StackSizeChangedFunc ()
|
|
|
|
-- clamp down if the player manually typed in more than is actually possible to post
|
|
local maxStackSize = Atr_MaxPossibleStackSize();
|
|
if (maxStackSize > 0 and Atr_StackSize() > maxStackSize) then
|
|
Atr_SetStackSize (maxStackSize); -- re-triggers this handler with the clamped value
|
|
return;
|
|
end
|
|
|
|
local maxAuctions = Atr_MaxPossibleNumAuctions();
|
|
if (maxAuctions > 0 and Atr_Batch_NumAuctions:GetNumber() > maxAuctions) then
|
|
Atr_Batch_NumAuctions:SetText (maxAuctions);
|
|
end
|
|
|
|
local item_BuyoutPrice = gSellItemPrice;
|
|
local new_Item_StartPrice = Atr_CalcStartPrice (item_BuyoutPrice);
|
|
|
|
if (gBuyoutIsPerItem) then
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, item_BuyoutPrice);
|
|
else
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, item_BuyoutPrice * Atr_StackSize());
|
|
end
|
|
Atr_ApplyStartingPrice (new_Item_StartPrice);
|
|
|
|
Atr_UpdateItemPriceButton ();
|
|
|
|
-- Atr_MemorizeButton:Show();
|
|
|
|
gSellPane.UINeedsUpdate = true;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_NumAuctionsChangedFunc (x)
|
|
|
|
-- clamp down if the player manually typed in more than is actually possible to post
|
|
local maxAuctions = Atr_MaxPossibleNumAuctions();
|
|
if (maxAuctions > 0 and Atr_Batch_NumAuctions:GetNumber() > maxAuctions) then
|
|
Atr_Batch_NumAuctions:SetText (maxAuctions); -- re-triggers this handler with the clamped value
|
|
return;
|
|
end
|
|
|
|
-- Atr_MemorizeButton:Show();
|
|
|
|
gSellPane.UINeedsUpdate = true;
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetTextureButton (elementName, count, itemlink)
|
|
|
|
local texture = Atr_GetItemIcon (itemlink);
|
|
|
|
local textureElement = getglobal (elementName);
|
|
|
|
if (texture) then
|
|
textureElement:Show();
|
|
textureElement:SetNormalTexture (texture);
|
|
Atr_SetTextureButtonCount (elementName, count);
|
|
else
|
|
Atr_SetTextureButtonCount (elementName, 0);
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetTextureButtonCount (elementName, count)
|
|
|
|
local countElement = getglobal (elementName.."Count");
|
|
|
|
if (count > 1) then
|
|
countElement:SetText (count);
|
|
countElement:Show();
|
|
else
|
|
countElement:Hide();
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local gRecTooltipAnchor;
|
|
|
|
function Atr_ShowRecTooltip (anchorFrame)
|
|
|
|
-- Atr_Idle re-calls this every 0.2s with no argument to keep the price fresh while the
|
|
-- tooltip is up; remember whichever icon was actually hovered so the refresh doesn't
|
|
-- jump the tooltip back onto Atr_RecommendItem_Tex.
|
|
anchorFrame = anchorFrame or gRecTooltipAnchor or Atr_RecommendItem_Tex;
|
|
gRecTooltipAnchor = anchorFrame;
|
|
|
|
local link = gCurrentPane.activeScan.itemLink;
|
|
local num = Atr_StackSize();
|
|
|
|
if (not link) then
|
|
link = gJustPosted_ItemLink;
|
|
num = gJustPosted_StackSize;
|
|
end
|
|
|
|
link = Atr_NormalizeItemLink (link);
|
|
|
|
if (link) then
|
|
if (num < 1) then num = 1; end;
|
|
|
|
GameTooltip:SetOwner(anchorFrame, "ANCHOR_RIGHT");
|
|
if (not pcall(GameTooltip.SetHyperlink, GameTooltip, link, num)) then -- never break the tooltip over a bad link
|
|
GameTooltip:SetText(link);
|
|
GameTooltip:Show();
|
|
end
|
|
gCurrentPane.tooltipvisible = true;
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_HideRecTooltip ()
|
|
|
|
gCurrentPane.tooltipvisible = nil;
|
|
gRecTooltipAnchor = nil;
|
|
GameTooltip:Hide();
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
-- the stock "Auctions" tab's OnShow is what actually asks the server for the player's owned
|
|
-- auctions at all; our tabs hide that frame instead of showing it, so without triggering this,
|
|
-- GetNumAuctionItems("owner") would stay completely empty. This is a blind, fire-and-forget
|
|
-- request with no confirmation it actually got a response - if the AH connection wasn't fully
|
|
-- settled yet when it's called, it can silently fail, leaving owned-auction data empty for the
|
|
-- rest of the session unless something calls this again later. Safe to call repeatedly (it only
|
|
-- actually does anything while AuctionFrameAuctions is hidden, which is always true while our
|
|
-- own tabs are the ones showing) - just don't call it while a page-walk (read or cancel, see
|
|
-- gOwnerScanActive/gOwnerCancelState) is in flight, since that would race it instead.
|
|
function Atr_RefreshOwnedAuctions ()
|
|
|
|
if (AuctionFrameAuctions and not AuctionFrameAuctions:IsShown()) then
|
|
AuctionFrameAuctions:Show();
|
|
AuctionFrameAuctions:Hide();
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnAuctionHouseShow()
|
|
|
|
gOpenAllBags = AUCTIONATOR_OPEN_ALL_BAGS;
|
|
|
|
Atr_RefreshOwnedAuctions ();
|
|
|
|
if (AUCTIONATOR_DEFTAB == 1) then Atr_SelectPane (SELL_TAB); end
|
|
if (AUCTIONATOR_DEFTAB == 2) then Atr_SelectPane (BUY_TAB); end
|
|
if (AUCTIONATOR_DEFTAB == 3) then Atr_SelectPane (MORE_TAB); end
|
|
|
|
Atr_ResetDuration();
|
|
|
|
gJustPosted_ItemName = nil;
|
|
gSellPane:ClearSearch();
|
|
|
|
if (gCurrentPane) then
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnAuctionHouseClosed()
|
|
|
|
Atr_HideAllDialogs();
|
|
|
|
Atr_CheckingActive_Finish ();
|
|
|
|
Atr_ClearScanCache();
|
|
|
|
gSellPane:ClearSearch();
|
|
gShopPane:ClearSearch();
|
|
gMorePane:ClearSearch();
|
|
|
|
-- if a read or cancel page-walk was still mid-flight, the AUCTION_OWNED_LIST_UPDATE it was
|
|
-- waiting on will never arrive now that this AH session is over - left alone, that stuck
|
|
-- "busy" state would silently block every future attempt at refreshing owned-auction data,
|
|
-- including every retry, for the rest of the game session (confirmed: reproduces exactly
|
|
-- this way, and nothing short of a full reload recovers from it otherwise)
|
|
gOwnerScanActive = false;
|
|
gOwnerScanResetting = false;
|
|
gOwnerCancelState = nil;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_HideAllDialogs()
|
|
|
|
Atr_CheckActives_Frame:Hide();
|
|
Atr_Error_Frame:Hide();
|
|
Atr_Buy_Confirm_Frame:Hide();
|
|
Atr_FullScanFrame:Hide();
|
|
Atr_Mask:Hide();
|
|
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_BasicOptionsUpdate(self, elapsed)
|
|
|
|
self.TimeSinceLastUpdate = (self.TimeSinceLastUpdate or 0) + elapsed;
|
|
|
|
if (self.TimeSinceLastUpdate > 0.25) then
|
|
|
|
self.TimeSinceLastUpdate = 0;
|
|
|
|
if (AuctionatorOption_Def_Duration_CB:GetChecked()) then
|
|
AuctionatorOption_Durations:Show();
|
|
else
|
|
AuctionatorOption_Durations:Hide();
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnWhoListUpdate()
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_PageHasMissingNames ()
|
|
|
|
local n = GetNumAuctionItems ("list");
|
|
local i;
|
|
|
|
for i = 1, n do
|
|
local name = GetAuctionItemInfo ("list", i);
|
|
if (name == nil or name == "") then
|
|
return true;
|
|
end
|
|
end
|
|
|
|
return false;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_QueryPoll ()
|
|
|
|
if (gAtr_FullScanState == ATR_FS_STARTED) then
|
|
Atr_FullScanFrameIdle();
|
|
end
|
|
|
|
if (gCurrentPane == nil or gCurrentPane.activeSearch == nil or not Atr_IsTabSelected()) then
|
|
return;
|
|
end
|
|
|
|
local search = gCurrentPane.activeSearch;
|
|
|
|
if (search.processing_state == KM_PREQUERY) then
|
|
if (not gHentryTryAgain and not Atr_Buy_IsBusy()) then
|
|
search:Continue();
|
|
end
|
|
elseif (search.processing_state == KM_POSTQUERY and search.namesWaitStart) then
|
|
if (not Atr_PageHasMissingNames() or GetTime() - search.namesWaitStart >= 2) then
|
|
Atr_OnAuctionUpdate();
|
|
end
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnUpdate(self, elapsed)
|
|
|
|
-- update the global "precision" timer
|
|
|
|
gAtr_ptime = gAtr_ptime and gAtr_ptime + elapsed or 0;
|
|
|
|
|
|
-- next auction page as soon as possible
|
|
|
|
Atr_QueryPoll ();
|
|
|
|
-- check deferred call queue
|
|
|
|
if (zc.periodic (self, "dcq_lastUpdate", 0.05, elapsed)) then
|
|
zc.CheckDeferredCall();
|
|
end
|
|
|
|
-- make sure all dusts and essences are in the local cache
|
|
|
|
if (gAtr_dustCacheIndex > 0 and zc.periodic (self, "dust_lastUpdate", 0.1, elapsed)) then
|
|
Atr_GetNextDustIntoCache();
|
|
end
|
|
|
|
-- the full-pane drop zone only intercepts the mouse while something's actually being dragged,
|
|
-- so it never blocks the normal buttons/inputs it overlaps the rest of the time
|
|
if (Atr_SellDropZone) then
|
|
Atr_SellDropZone:EnableMouse (CursorHasItem() and true or false);
|
|
end
|
|
|
|
-- drives a confirmed, one-at-a-time cancel walk forward; a no-op instantly whenever none is active
|
|
Atr_OwnerCancelStep ();
|
|
|
|
-- catches an owner-scan page whose AUCTION_OWNED_LIST_UPDATE never arrives (confirmed: happens
|
|
-- when the requested page was already the client's current page); a no-op instantly otherwise
|
|
Atr_OwnerScanStep ();
|
|
|
|
-- the core Idle routine
|
|
|
|
if (zc.periodic (self, "idle_lastUpdate", 0.2, elapsed)) then
|
|
Atr_Idle (self, elapsed);
|
|
end
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
local verCheckMsgState = 0;
|
|
-----------------------------------------
|
|
|
|
function Atr_Idle(self, elapsed)
|
|
|
|
|
|
if (gCurrentPane and gCurrentPane.tooltipvisible) then
|
|
Atr_ShowRecTooltip();
|
|
end
|
|
|
|
|
|
if (gAtr_FullScanState ~= ATR_FS_NULL) then
|
|
Atr_FullScanFrameIdle();
|
|
end
|
|
|
|
|
|
|
|
if (not Atr_IsTabSelected() or AuctionatorMessageFrame == nil) then
|
|
return;
|
|
end
|
|
|
|
if (gHentryTryAgain) then
|
|
Atr_HEntryOnClick();
|
|
return;
|
|
end
|
|
|
|
if (gCurrentPane.activeSearch and gCurrentPane.activeSearch.processing_state == KM_PREQUERY and not Atr_Buy_IsBusy()) then ------- check whether to send a new auction query to get the next page -------
|
|
gCurrentPane.activeSearch:Continue();
|
|
end
|
|
|
|
Atr_UpdateUI ();
|
|
|
|
Atr_CheckingActiveIdle();
|
|
|
|
Atr_Buy_Idle();
|
|
|
|
if (gHideAPFrameCheck == nil) then -- for the addon 'Auction Profit' (flags for efficiency so we only check one time)
|
|
gHideAPFrameCheck = true;
|
|
if (AP_Bid_MoneyFrame) then
|
|
AP_Bid_MoneyFrame:Hide();
|
|
AP_Buy_MoneyFrame:Hide();
|
|
end
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local gPrevSellItemLink;
|
|
|
|
-----------------------------------------
|
|
|
|
-- the "for N"/"for 1" suffix on both the Buyout Price and Starting Price labels, kept in sync
|
|
-- with whichever the checkbox currently says (stack total vs. per item)
|
|
function Atr_UpdatePriceLabels ()
|
|
|
|
local suffix = "";
|
|
if (gBuyoutIsPerItem) then
|
|
suffix = " |cff55ddfffor 1|r";
|
|
elseif (Atr_StackSize() > 1) then
|
|
suffix = " |cff55ddfffor "..Atr_StackSize().."|r";
|
|
end
|
|
|
|
Atr_StackPriceText:SetText (ZT("Buyout Price")..suffix);
|
|
Atr_StartingPriceText:SetText (ZT("Starting Price (Bids)")..suffix);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_UpdateItemPriceButton ()
|
|
|
|
Atr_UpdatePriceLabels ();
|
|
|
|
if (Atr_StackSize() <= 1) then
|
|
Atr_PricePerItemCheck:Hide();
|
|
return;
|
|
end
|
|
|
|
Atr_PricePerItemCheck:SetChecked (gBuyoutIsPerItem);
|
|
Atr_PricePerItemCheck:Show();
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- toggles whether the Buyout Price field is read/written as the per-item price or the whole
|
|
-- stack's total, converting the currently displayed value (and both labels) to match
|
|
function Atr_PricePerItemCheck_OnClick ()
|
|
|
|
gBuyoutIsPerItem = Atr_PricePerItemCheck:GetChecked() and true or false;
|
|
|
|
local itemStartPrice = Atr_CalcStartPrice (gSellItemPrice);
|
|
|
|
if (gBuyoutIsPerItem) then
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, gSellItemPrice);
|
|
else
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, gSellItemPrice * Atr_StackSize());
|
|
end
|
|
Atr_ApplyStartingPrice (itemStartPrice);
|
|
|
|
Atr_UpdateItemPriceButton ();
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_OnNewAuctionUpdate()
|
|
|
|
-- used to only react when one of our own click/drag handlers had just set a flag first -
|
|
-- confirmed (via direct event logging) that NEW_AUCTION_UPDATE fires reliably for a
|
|
-- right-click placement too, same as a drag, with arg1 set to the mouse button used. The
|
|
-- itemLink comparison below already detects a genuine change on its own; no flag needed.
|
|
--
|
|
-- Compat.lua's multi-stack posting driver splits/repicks/redrops the item into the sell slot
|
|
-- between stacks, which fires this same event and can toggle the sell slot's link to nil and
|
|
-- back even though it's still the same item being posted. Reacting to that as if a player had
|
|
-- placed a genuinely new item wiped gJustPosted_ItemName mid-batch (nilling it out right
|
|
-- before the final stack's completion handler needed it), crashing with "table index is nil"
|
|
-- in Atr_AddHistoricalPrice. None of this function's reactions are meaningful while our own
|
|
-- posting is driving the slot, so skip all of it until posting settles.
|
|
if (Atr_PostingInProgress()) then
|
|
return;
|
|
end
|
|
|
|
local auctionItemName, auctionCount, auctionLink = Atr_GetSellItemInfo();
|
|
|
|
-- a right-click (or the vanilla "Auctions" tab's own sell slot) can place an item here without
|
|
-- ever switching to our own Sell tab first - make sure it's actually showing. This must run
|
|
-- regardless of whether the link below counts as "changed": right-clicking a second stack of
|
|
-- the same item leaves auctionLink identical to gPrevSellItemLink, but still needs the tab switch.
|
|
if (auctionLink and not Atr_IsTabSelected(SELL_TAB)) then
|
|
Atr_SelectPane (SELL_TAB);
|
|
end
|
|
|
|
if (gPrevSellItemLink ~= auctionLink) then
|
|
|
|
gPrevSellItemLink = auctionLink;
|
|
gBuyoutIsPerItem = false;
|
|
|
|
if (auctionLink) then
|
|
gJustPosted_ItemName = nil;
|
|
Atr_AddToItemLinkCache (auctionItemName, auctionLink);
|
|
Atr_ClearList(); -- better UE
|
|
gSellPane:SetToShowCurrent();
|
|
end
|
|
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, 0);
|
|
MoneyInputFrame_SetCopper (Atr_StartingPrice, 0);
|
|
Atr_ResetDuration();
|
|
|
|
if (gJustPosted_ItemName == nil) then
|
|
local cacheHit = gSellPane:DoSearch (auctionItemName, true, 20);
|
|
|
|
gSellPane.totalItems = Atr_GetNumItemInBags (auctionItemName);
|
|
gSellPane.fullStackSize = Atr_ItemStackSize (auctionLink);
|
|
|
|
local prefNumStacks, prefStackSize = Atr_GetSellStacking (auctionLink, auctionCount, gSellPane.totalItems);
|
|
|
|
if (time() - gAutoSingleton < 5) then
|
|
Atr_SetInitialStacking (1, 1);
|
|
else
|
|
Atr_SetInitialStacking (prefNumStacks, prefStackSize);
|
|
end
|
|
|
|
if (cacheHit) then
|
|
Atr_OnSearchComplete ();
|
|
end
|
|
|
|
Atr_SetTextureButton ("Atr_SellControls_Tex", Atr_StackSize(), auctionLink);
|
|
Atr_SellControls_TexName:SetText (auctionItemName);
|
|
else
|
|
Atr_SetTextureButton ("Atr_SellControls_Tex", 0, nil);
|
|
Atr_SellControls_TexName:SetText ("");
|
|
end
|
|
|
|
elseif (Atr_StackSize() ~= auctionCount) then
|
|
|
|
local prefNumStacks, prefStackSize = Atr_GetSellStacking (auctionLink, auctionCount, gSellPane.totalItems);
|
|
|
|
Atr_SetInitialStacking (prefNumStacks, prefStackSize);
|
|
|
|
Atr_SetTextureButton ("Atr_SellControls_Tex", Atr_StackSize(), auctionLink);
|
|
|
|
Atr_FindBestCurrentAuction();
|
|
Atr_ResetDuration();
|
|
end
|
|
|
|
gSellPane.UINeedsUpdate = true;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- a right-click sell attempt that fails (soulbound, quest item, etc.) still triggers the native
|
|
-- "switch to the Auctions tab" behavior even though nothing actually landed in the sell slot, so
|
|
-- NEW_AUCTION_UPDATE never fires to catch it - this fires for both outcomes though, so just
|
|
-- switch back to our own Sell tab here too rather than leaving the vanilla one showing
|
|
function Atr_OnItemLockChanged ()
|
|
|
|
if (arg1 == "RightButton" and AuctionFrame and AuctionFrame:IsShown() and not Atr_IsTabSelected(SELL_TAB)) then
|
|
Atr_SelectPane (SELL_TAB);
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- after a multi-stack post finishes, Compat.lua moves whatever's left of the item back into the
|
|
-- sell slot itself rather than leaving it empty - same item, same link, so Atr_OnNewAuctionUpdate's
|
|
-- own change-detection never sees it as a change and the cached bag count (used by the max
|
|
-- buttons and the Create-Auctions button's enabled state) goes stale. Re-sync just that, leaving
|
|
-- whatever price/stacking the player already configured untouched.
|
|
function Atr_OnRefillSettled ()
|
|
|
|
local auctionItemName = GetAuctionSellItemInfo();
|
|
|
|
if (auctionItemName) then
|
|
gSellPane.totalItems = Atr_GetNumItemInBags (auctionItemName);
|
|
end
|
|
|
|
gSellPane.UINeedsUpdate = true;
|
|
end
|
|
|
|
---------------------------------------------------------
|
|
|
|
function Atr_UpdateUI ()
|
|
|
|
local needsUpdate = gCurrentPane.UINeedsUpdate;
|
|
|
|
if (gCurrentPane.UINeedsUpdate) then
|
|
|
|
gCurrentPane.UINeedsUpdate = false;
|
|
|
|
if (Atr_ShowingSearchSummary()) then
|
|
Atr_ShowSearchSummary();
|
|
elseif (gCurrentPane:ShowCurrent()) then
|
|
PanelTemplates_SetTab(Atr_ListTabs, 1);
|
|
Atr_ShowCurrentAuctions();
|
|
elseif (gCurrentPane:ShowHistory()) then
|
|
PanelTemplates_SetTab(Atr_ListTabs, 2);
|
|
Atr_ShowHistory();
|
|
else
|
|
PanelTemplates_SetTab(Atr_ListTabs, 3);
|
|
Atr_ShowHints();
|
|
end
|
|
|
|
if (gCurrentPane:IsScanEmpty()) then
|
|
Atr_ListTabs:Hide();
|
|
else
|
|
Atr_ListTabs:Show();
|
|
end
|
|
|
|
Atr_SetMessage ("");
|
|
local scn = gCurrentPane.activeScan;
|
|
|
|
-- used to only run on the Sell tab, falling back to a bare icon+name everywhere else even
|
|
-- once a specific auction/history/hint row was selected there - the fallback is only
|
|
-- actually appropriate when there's no item scan to show details for at all (e.g. the Buy
|
|
-- tab's multi-item search results list, before drilling into one specific item)
|
|
if (Atr_IsModeCreateAuction() or not scn:IsNil()) then
|
|
|
|
Atr_UpdateRecommendation (false);
|
|
else
|
|
Atr_HideElems (recommendElements);
|
|
|
|
if (scn:IsNil()) then
|
|
Atr_ShowItemNameAndTexture (gCurrentPane.activeSearch.searchText);
|
|
else
|
|
Atr_ShowItemNameAndTexture (gCurrentPane.activeScan.itemName);
|
|
end
|
|
|
|
if (Atr_IsModeBuy()) then
|
|
|
|
if (gCurrentPane.activeSearch.searchText == "") then
|
|
Atr_SetMessage (ZT("Select an item from the list on the left\n or type a search term above to start a scan."));
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
|
|
if (Atr_IsTabSelected(BUY_TAB)) then
|
|
Atr_Shop_UpdateUI();
|
|
end
|
|
|
|
if (gCurrentPane.activeSearch and gCurrentPane.activeSearch:IsActive()) then
|
|
Atr_ScanProgress_Text:SetText (Atr_SearchProgressText ());
|
|
Atr_ScanProgress_Text:Show ();
|
|
else
|
|
Atr_ScanProgress_Text:Hide ();
|
|
end
|
|
|
|
|
|
end
|
|
|
|
-- update the hlist if needed
|
|
|
|
if (gHlistNeedsUpdate and Atr_IsModeActiveAuctions()) then
|
|
gHlistNeedsUpdate = false;
|
|
Atr_DisplayHlist();
|
|
end
|
|
|
|
if (Atr_IsTabSelected(SELL_TAB)) then
|
|
Atr_UpdateUI_SellPane (needsUpdate);
|
|
end
|
|
|
|
end
|
|
|
|
---------------------------------------------------------
|
|
|
|
function Atr_UpdateUI_SellPane (needsUpdate)
|
|
|
|
local auctionItemName, _, auctionItemCount = GetAuctionSellItemInfo();
|
|
|
|
if (needsUpdate) then
|
|
|
|
if (gCurrentPane.activeSearch and gCurrentPane.activeSearch.processing_state ~= KM_NULL_STATE) then
|
|
Atr_CreateAuctionButton:Disable();
|
|
Atr_FullScanButton:Disable();
|
|
Auctionator1Button:Disable();
|
|
MoneyInputFrame_SetCopper (Atr_StartingPrice, 0);
|
|
return;
|
|
else
|
|
Atr_FullScanButton:Enable();
|
|
Auctionator1Button:Enable();
|
|
|
|
|
|
if (Atr_Batch_Stacksize.oldStackSize ~= Atr_StackSize()) then
|
|
Atr_Batch_Stacksize.oldStackSize = Atr_StackSize();
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, gSellItemPrice * Atr_StackSize());
|
|
end
|
|
|
|
if (Atr_Batch_NumAuctions:GetNumber() < 2) then
|
|
Atr_Batch_Stacksize_Text:SetText (ZT("stack of"));
|
|
Atr_CreateAuctionButton:SetText (ZT("Create Auction"));
|
|
else
|
|
Atr_Batch_Stacksize_Text:SetText (ZT("stacks of"));
|
|
Atr_CreateAuctionButton:SetText (string.format (ZT("Create %d Auctions"), Atr_Batch_NumAuctions:GetNumber()));
|
|
end
|
|
|
|
Atr_UpdateItemPriceButton ();
|
|
|
|
Atr_SetTextureButton ("Atr_SellControls_Tex", auctionItemCount or 0, Atr_GetItemLink(auctionItemName));
|
|
Atr_SellControls_TexName:SetText (auctionItemName or "");
|
|
|
|
-- the event-driven clear in Atr_OnNewAuctionUpdate doesn't reliably fire once the sell
|
|
-- slot settles into "still empty" right after the last auction of a batch posts (the
|
|
-- native sell-item-changed event only fires on an actual change) - clear these from the
|
|
-- live slot state here too, same as a manual drag-out already does. Only once posting
|
|
-- has fully settled though - the slot sits briefly empty between stacks mid-batch, and
|
|
-- that must not be mistaken for "actually emptied out".
|
|
if (auctionItemName == nil and not Atr_PostingInProgress()) then
|
|
MoneyInputFrame_SetCopper (Atr_StackPrice, 0);
|
|
MoneyInputFrame_SetCopper (Atr_StartingPrice, 0);
|
|
Atr_SetStackSize (0);
|
|
Atr_Batch_NumAuctions:SetText (0);
|
|
Atr_Batch_Stacksize_Text:SetText (ZT("stack of"));
|
|
Atr_CreateAuctionButton:SetText (ZT("Create Auction"));
|
|
end
|
|
|
|
local maxAuctions = 0;
|
|
if (Atr_StackSize() > 0) then
|
|
maxAuctions = math.floor (gCurrentPane.totalItems / Atr_StackSize());
|
|
end
|
|
|
|
Atr_Batch_MaxAuctions_Text:SetText (ZT("max")..": "..maxAuctions);
|
|
Atr_Batch_MaxStacksize_Text:SetText (ZT("max")..": "..Atr_MaxPossibleStackSize());
|
|
|
|
Atr_SetDepositText();
|
|
end
|
|
|
|
if (gJustPosted_ItemName ~= nil) then
|
|
|
|
-- the recommend header used to get overwritten with "Auction created for X" here,
|
|
-- blowing away whatever it was already showing (and hiding the per-stack/per-item
|
|
-- lines with it) - leave it alone and just highlight the newly created auction below
|
|
gCurrentPane.currIndex = gCurrentPane.activeScan:FindInSortedData (gJustPosted_StackSize, gJustPosted_BuyoutPrice);
|
|
|
|
if (gCurrentPane:ShowCurrent()) then
|
|
Atr_HighlightEntry (gCurrentPane.currIndex); -- highlight the newly created auction(s)
|
|
else
|
|
Atr_HighlightEntry (gCurrentPane.histIndex);
|
|
end
|
|
|
|
elseif (gCurrentPane:IsScanEmpty()) then
|
|
Atr_SetMessage (ZT("Right-click items in your bag or drag them here to sell them"));
|
|
end
|
|
end
|
|
|
|
-- stuff we should do every time (not just when needsUpdate is true)
|
|
|
|
local start = MoneyInputFrame_GetCopper(Atr_StartingPrice);
|
|
local buyout = MoneyInputFrame_GetCopper(Atr_StackPrice);
|
|
|
|
local pricesOK = (start > 0 and (start <= buyout or buyout == 0) and (auctionItemName ~= nil));
|
|
|
|
local numToSell = Atr_Batch_NumAuctions:GetNumber() * Atr_Batch_Stacksize:GetNumber();
|
|
|
|
zc.EnableDisable (Atr_CreateAuctionButton, pricesOK and (numToSell <= gCurrentPane.totalItems));
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- CalculateAuctionDeposit only knows about the stack currently sitting in the sell slot, which
|
|
-- can differ from the stack size we're actually about to post once it's split, and rescaling its
|
|
-- (already-floored) result for a different size loses a copper here and there since deposit
|
|
-- isn't linear in stack size (there's a 5%-per-item surcharge for being short of a full stack).
|
|
-- Compute the formula directly instead, floored exactly once, at the end - confirmed to match
|
|
-- this server's native Auctions tab exactly.
|
|
function Atr_CalcDeposit (itemLink, itemName, stackSize, duration)
|
|
|
|
local minutes = AtrNS.durationMinutes[duration] or 1440;
|
|
|
|
local _, _, _, _, _, _, _, maxStack, _, _, vendorPrice = Atr_GetItemInfo (itemLink or itemName);
|
|
vendorPrice = vendorPrice or 0;
|
|
maxStack = maxStack or stackSize;
|
|
local shortBy = math.max (maxStack - stackSize, 0);
|
|
|
|
return math.floor (vendorPrice * stackSize * (minutes / 120) * (1 + shortBy * 0.05) * 0.025);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- the auction house gives no way to ask an already-posted auction what its own deposit was, so
|
|
-- track it ourselves, keyed the same way Atr_CancelAuction_ByIndex already matches a scanned
|
|
-- "owner" row back to one of our own postings (name + per-stack buyout price + stack size)
|
|
function Atr_DepositKey (itemName, buyoutPrice, stackSize)
|
|
return itemName.."_"..buyoutPrice.."_"..stackSize;
|
|
end
|
|
|
|
function Atr_RecordDeposit ()
|
|
if (gJustPosted_Deposit == nil) then
|
|
return;
|
|
end
|
|
AUCTIONATOR_DEPOSITS[Atr_DepositKey (gJustPosted_ItemName, gJustPosted_BuyoutPrice, gJustPosted_StackSize)] = gJustPosted_Deposit;
|
|
end
|
|
|
|
-- nil if we have no record of posting this particular auction ourselves (e.g. posted before this
|
|
-- tracking existed, or via the default Blizzard UI)
|
|
function Atr_GetRecordedDeposit (itemName, buyoutPrice, stackSize)
|
|
return AUCTIONATOR_DEPOSITS[Atr_DepositKey (itemName, buyoutPrice, stackSize)];
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetDepositText()
|
|
|
|
local auctionItemName, auctionItemCount, auctionItemLink = Atr_GetSellItemInfo();
|
|
auctionCount = auctionItemCount;
|
|
|
|
if (auctionCount > 0) then
|
|
local duration = UIDropDownMenu_GetSelectedValue(Atr_Duration);
|
|
local stackSize = Atr_StackSize();
|
|
|
|
local deposit = Atr_CalcDeposit (auctionItemLink, auctionItemName, stackSize, duration);
|
|
|
|
local numAuctionString = "";
|
|
if (Atr_Batch_NumAuctions:GetNumber() > 1) then
|
|
numAuctionString = " |cffff55ff x"..Atr_Batch_NumAuctions:GetNumber();
|
|
end
|
|
|
|
Atr_Deposit_Text:SetText (ZT("Deposit")..":");
|
|
Atr_ShowDepositMoney (deposit, numAuctionString);
|
|
else
|
|
Atr_Deposit_Text:SetText ("");
|
|
Atr_ShowDepositMoney (nil);
|
|
end
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
-- a stray (not-our-walk) AUCTION_OWNED_LIST_UPDATE flushes gActiveAuctions, but if several arrive
|
|
-- in a burst (confirmed: a cancel walk's per-confirmation pages and a multi-stack post's own
|
|
-- per-stack pings both fire these) the walk that re-fills it can start, and finish, before every
|
|
-- change in that burst has actually happened server-side - caching a mid-operation snapshot that
|
|
-- then just sits there, wrong, since nothing re-triggers another walk once gActiveAuctions is
|
|
-- non-empty again. Call this once a cancel walk or a multi-stack post has fully settled, so the
|
|
-- next render is guaranteed to see it empty and kick off one more walk after the dust has
|
|
-- actually cleared, instead of trusting whichever walk happened to land during the burst.
|
|
function Atr_InvalidateActiveAuctions ()
|
|
|
|
gActiveAuctions = {};
|
|
gActiveAuctionIcons = {};
|
|
gActiveAuctionRarity = {};
|
|
gHlistNeedsUpdate = true;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- GetNumAuctionItems("owner")/GetAuctionItemInfo("owner", i) only ever reflect a single page (up
|
|
-- to 50 entries) of your own auctions at a time - same as a browse/search query. Confirmed via
|
|
-- debug logging: with 73 real active auctions, page 0 alone reported exactly 50, zero gaps, every
|
|
-- one correctly counted - nothing wrong with reading page 0, there just was never a request for
|
|
-- anything past it. GetOwnerAuctionItems(page) requests a specific page (the same native function
|
|
-- the Auctions tab's own page-arrow button uses) - walk every page here instead of just the first.
|
|
-- This kicks off the walk and returns immediately; Atr_OnAuctionOwnedUpdate drives it page by page
|
|
-- as each one's AUCTION_OWNED_LIST_UPDATE arrives, and flags gHlistNeedsUpdate once it's done.
|
|
function Atr_BuildActiveAuctions ()
|
|
|
|
if (gOwnerScanActive or gOwnerCancelState ~= nil) then
|
|
return; -- another owner-page walk is already in progress; let it finish first rather than interleaving with it
|
|
end
|
|
|
|
gActiveAuctions = {};
|
|
gActiveAuctionIcons = {};
|
|
gActiveAuctionRarity = {};
|
|
|
|
gOwnerScanActive = true;
|
|
gOwnerScanPage = 0;
|
|
gOwnerScanT = GetTime();
|
|
gOwnerScanPageHandled = false;
|
|
GetOwnerAuctionItems (gOwnerScanPage);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local ATR_UNKNOWN_ITEM_ICON = "Interface\\Icons\\INV_Misc_QuestionMark";
|
|
|
|
-- prefer the texture straight off the native "owner" auction query (instant, no item-cache wait);
|
|
-- fall back to the usual by-name lookup, then to the standard "unknown item" question mark
|
|
function Atr_GetListingIcon (itemName)
|
|
return gActiveAuctionIcons[itemName] or Atr_GetItemIcon (itemName) or ATR_UNKNOWN_ITEM_ICON;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- "safe" (all your auctions at/below the current best price), "partial" (some but not all are),
|
|
-- "undercut" (even your best is beaten), or nil (no scan data to judge by yet)
|
|
function Atr_GetUCStatus (itemName)
|
|
|
|
local status = nil;
|
|
local undercutFound = false;
|
|
|
|
local scan = Atr_FindScan (itemName);
|
|
if (scan and scan.absoluteBest and scan.whenScanned ~= 0 and scan.yourBestPrice and scan.yourWorstPrice) then
|
|
|
|
local absBestPrice = scan.absoluteBest.itemPrice;
|
|
|
|
if (scan.yourBestPrice <= absBestPrice and scan.yourWorstPrice > absBestPrice) then
|
|
status = "partial";
|
|
undercutFound = true;
|
|
elseif (scan.yourBestPrice <= absBestPrice) then
|
|
status = "safe";
|
|
else
|
|
status = "undercut";
|
|
undercutFound = true;
|
|
end
|
|
end
|
|
|
|
if (gAtr_CheckingActive_State ~= ATR_CACT_NULL and undercutFound) then
|
|
gAtr_CheckingActive_NumUndercuts = gAtr_CheckingActive_NumUndercuts + 1;
|
|
end
|
|
|
|
return status;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_GetUCIcon (itemName)
|
|
|
|
local status = Atr_GetUCStatus (itemName);
|
|
|
|
if (status == "partial") then
|
|
return "|cffffd100[~]|r ";
|
|
elseif (status == "safe") then
|
|
return "|cff40ff40[+]|r ";
|
|
elseif (status == "undercut") then
|
|
return "|cffff4040[-]|r ";
|
|
end
|
|
|
|
return " ";
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- the standard classic item quality colors (poor through legendary), kept local so this doesn't
|
|
-- depend on the global ITEM_QUALITY_COLORS table existing/matching on every client
|
|
local ITEM_RARITY_COLORS = {
|
|
[0] = {0.61, 0.61, 0.61}, -- poor
|
|
[1] = {1.00, 1.00, 1.00}, -- common
|
|
[2] = {0.12, 1.00, 0.00}, -- uncommon
|
|
[3] = {0.00, 0.44, 0.87}, -- rare
|
|
[4] = {0.64, 0.21, 0.93}, -- epic
|
|
[5] = {1.00, 0.50, 0.00}, -- legendary
|
|
};
|
|
local ITEM_RARITY_COLOR_DEFAULT = {1.0, 1.0, 1.0};
|
|
|
|
local UC_ICON_TEXTURES = {
|
|
safe = "Interface\\AddOns\\OctoAuctionatorPlus\\Images\\auction_undercut_no.tga",
|
|
partial = "Interface\\AddOns\\OctoAuctionatorPlus\\Images\\auction_undercut_partial.tga",
|
|
undercut = "Interface\\AddOns\\OctoAuctionatorPlus\\Images\\auction_undercut_yes.tga",
|
|
};
|
|
|
|
-- small custom-icon badge over the bottom-left of the item icon, flagging undercut status. It used
|
|
-- to render inconsistently (sometimes hidden behind the opaque item icon) because it shared
|
|
-- ItemIcon's BACKGROUND draw layer, where sibling order isn't reliably enforced on this client;
|
|
-- it now lives in OVERLAY, a strictly higher named layer guaranteed to draw above BACKGROUND -
|
|
-- see Atr_HEntryTemplate. ucOverlay (a color wash over the icon) is kept around but deliberately
|
|
-- unused - it looked worse than the badge alone when tried.
|
|
function Atr_SetRowUndercutIcon (ucOverlay, ucIcon, itemName)
|
|
|
|
local status = itemName and Atr_GetUCStatus (itemName);
|
|
|
|
ucOverlay:Hide();
|
|
|
|
if status then
|
|
ucIcon:SetTexture (UC_ICON_TEXTURES[status]);
|
|
ucIcon:Show();
|
|
else
|
|
ucIcon:Hide();
|
|
end
|
|
|
|
end
|
|
|
|
-- colors a list row's item name by the item's own rarity (poor/common/uncommon/rare/epic/
|
|
-- legendary) - a fixed property of the item, unlike undercut status, so it never changes once set
|
|
function Atr_SetRowItemRarityColor (lineEntry_text, itemName)
|
|
|
|
local rarity;
|
|
if (itemName) then
|
|
rarity = gActiveAuctionRarity[itemName];
|
|
if (rarity == nil) then
|
|
local _, _, r = Atr_GetItemInfo (itemName);
|
|
rarity = r;
|
|
end
|
|
end
|
|
|
|
local color = (rarity and ITEM_RARITY_COLORS[rarity]) or ITEM_RARITY_COLOR_DEFAULT;
|
|
|
|
lineEntry_text:SetTextColor (color[1], color[2], color[3]);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Hlist_OnVerticalScroll ()
|
|
if (Atr_IsTabSelected (BUY_TAB)) then
|
|
FauxScrollFrame_OnVerticalScroll (SLIST_ROW_HEIGHT, Atr_DisplayHlist);
|
|
else
|
|
FauxScrollFrame_OnVerticalScroll (ITEM_HIST_ROW_HEIGHT, Atr_DisplayHlist);
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_DisplayHlist ()
|
|
|
|
if (Atr_IsTabSelected (BUY_TAB)) then -- done this way because OnScrollFrame always calls Atr_DisplayHlist
|
|
Atr_DisplaySlist();
|
|
return;
|
|
end
|
|
|
|
local doFull = (UIDropDownMenu_GetSelectedValue(Atr_DropDown1) == MODE_LIST_ALL);
|
|
|
|
Atr_BuildGlobalHistoryList (doFull);
|
|
|
|
local numrows = getn(gHistoryItemList);
|
|
|
|
local line; -- 1 through NN of our window to scroll
|
|
local dataOffset; -- an index into our data calculated from the scroll offset
|
|
|
|
FauxScrollFrame_Update (Atr_Hlist_ScrollFrame, numrows, ITEM_HIST_NUM_LINES, ITEM_HIST_ROW_HEIGHT);
|
|
|
|
for line = 1,ATR_HLIST_FRAME_COUNT do
|
|
|
|
local lineEntry = getglobal ("AuctionatorHEntry"..line);
|
|
|
|
if (line > ITEM_HIST_NUM_LINES) then -- beyond this list's page size; the Buy tab's longer, shorter-row list may have left these shown
|
|
|
|
lineEntry:Hide();
|
|
|
|
else
|
|
|
|
gCurrentPane.hlistScrollOffset = FauxScrollFrame_GetOffset (Atr_Hlist_ScrollFrame);
|
|
|
|
dataOffset = line + gCurrentPane.hlistScrollOffset;
|
|
|
|
lineEntry:SetID(dataOffset);
|
|
lineEntry:SetHeight (ITEM_HIST_ROW_HEIGHT);
|
|
lineEntry:SetPoint ("TOPLEFT", 0, -5 - ((line-1)*ITEM_HIST_ROW_HEIGHT));
|
|
|
|
if (dataOffset <= numrows and gHistoryItemList[dataOffset]) then
|
|
|
|
local lineEntry_text = getglobal("AuctionatorHEntry"..line.."_EntryText");
|
|
local lineEntry_icon = getglobal("AuctionatorHEntry"..line.."_ItemIcon");
|
|
local lineEntry_count = getglobal("AuctionatorHEntry"..line.."_ItemCount");
|
|
local lineEntry_uc_overlay = getglobal("AuctionatorHEntry"..line.."_UCOverlay");
|
|
local lineEntry_uc_icon = getglobal("AuctionatorHEntry"..line.."_UCIcon");
|
|
|
|
lineEntry_text:SetHeight (ITEM_HIST_ROW_HEIGHT);
|
|
|
|
local iName = gHistoryItemList[dataOffset];
|
|
|
|
lineEntry_icon:SetTexture (Atr_GetListingIcon (iName));
|
|
lineEntry_icon:Show();
|
|
|
|
Atr_SetRowItemRarityColor (lineEntry_text, iName);
|
|
|
|
if (not doFull) then
|
|
Atr_SetRowUndercutIcon (lineEntry_uc_overlay, lineEntry_uc_icon, iName);
|
|
else
|
|
Atr_SetRowUndercutIcon (lineEntry_uc_overlay, lineEntry_uc_icon, nil);
|
|
end
|
|
|
|
lineEntry_text:SetPoint ("LEFT", lineEntry_icon, "RIGHT", 4, 0);
|
|
lineEntry_text:SetWidth (140);
|
|
lineEntry_text:SetText (Atr_AbbrevItemName (iName));
|
|
|
|
local qty = (not doFull) and gActiveAuctions[iName];
|
|
if (qty and qty > 0) then
|
|
lineEntry_count:SetText (qty);
|
|
lineEntry_count:Show();
|
|
else
|
|
lineEntry_count:Hide();
|
|
end
|
|
|
|
if (iName == gCurrentPane.activeSearch.searchText) then
|
|
Atr_SetRowSelected (lineEntry, true);
|
|
else
|
|
Atr_SetRowSelected (lineEntry, false);
|
|
end
|
|
|
|
lineEntry:Hide(); -- force a real transition - a row left in the "already shown" state from the last redraw
|
|
lineEntry:Show(); -- seems to make this client skip re-compositing its children's visibility changes
|
|
else
|
|
lineEntry:Hide();
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ClearHlist ()
|
|
local line;
|
|
for line = 1,ITEM_HIST_NUM_LINES do
|
|
local lineEntry = getglobal ("AuctionatorHEntry"..line);
|
|
lineEntry:Hide();
|
|
|
|
local lineEntry_text = getglobal("AuctionatorHEntry"..line.."_EntryText");
|
|
lineEntry_text:SetText ("");
|
|
lineEntry_text:SetTextColor (.7,.7,.7);
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_HEntryOnClick(itemName)
|
|
|
|
if (gCurrentPane == gShopPane) then
|
|
Atr_SEntryOnClick();
|
|
return;
|
|
end
|
|
|
|
if (not itemName) then
|
|
local line = this;
|
|
|
|
if (gHentryTryAgain) then
|
|
line = gHentryTryAgain;
|
|
gHentryTryAgain = nil;
|
|
end
|
|
|
|
local _, itemLink;
|
|
local entryIndex = line:GetID();
|
|
|
|
itemName = gHistoryItemList[entryIndex];
|
|
end
|
|
|
|
if (IsAltKeyDown() and Atr_IsModeActiveAuctions()) then
|
|
Atr_Cancel_Undercuts_OnClick (itemName)
|
|
return;
|
|
end
|
|
|
|
if (AUCTIONATOR_PRICING_HISTORY[itemName]) then
|
|
local itemId, suffixId, uniqueId = Atr_strsplit (":", AUCTIONATOR_PRICING_HISTORY[itemName]["is"])
|
|
|
|
local itemId = tonumber(itemId);
|
|
|
|
if (suffixId == nil) then suffixId = 0;
|
|
else suffixId = tonumber(suffixId);
|
|
end
|
|
|
|
if (uniqueId == nil) then uniqueId = 0;
|
|
else uniqueId = tonumber(suffixId);
|
|
end
|
|
|
|
local itemString = "item:"..itemId..":0:"..suffixId..":"..uniqueId;
|
|
|
|
_, itemLink = Atr_GetItemInfo (itemString);
|
|
|
|
if (itemLink == nil) then -- pull it into the cache and go back to the idle loop to wait for it to appear
|
|
AtrScanningTooltip:SetHyperlink(itemString);
|
|
gHentryTryAgain = line;
|
|
zc.md ("pulling "..itemName.." into the local cache");
|
|
return;
|
|
end
|
|
end
|
|
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
|
|
Atr_ClearAll();
|
|
|
|
local cacheHit = gCurrentPane:DoSearch (itemName, true, 20);
|
|
|
|
Atr_Process_Historydata ();
|
|
Atr_FindBestHistoricalAuction ();
|
|
|
|
Atr_DisplayHlist(); -- for the highlight
|
|
|
|
if (cacheHit) then
|
|
Atr_OnSearchComplete();
|
|
end
|
|
|
|
PlaySound ("igMainMenuOptionCheckBoxOn");
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowWhichRB (id)
|
|
|
|
if (gCurrentPane.activeSearch.processing_state ~= KM_NULL_STATE) then -- if we're scanning auctions don't respond
|
|
return;
|
|
end
|
|
|
|
PlaySound("igMainMenuOptionCheckBoxOn");
|
|
|
|
if (id == 1) then
|
|
gCurrentPane:SetToShowCurrent();
|
|
elseif (id == 2) then
|
|
gCurrentPane:SetToShowHistory();
|
|
else
|
|
gCurrentPane:SetToShowHints();
|
|
end
|
|
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_RedisplayAuctions ()
|
|
|
|
if (Atr_ShowingSearchSummary()) then
|
|
Atr_ShowSearchSummary();
|
|
elseif (Atr_ShowingCurrentAuctions()) then
|
|
Atr_ShowCurrentAuctions();
|
|
elseif Atr_ShowingHistory() then
|
|
Atr_ShowHistory();
|
|
else
|
|
Atr_ShowHints();
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_BuildHistItemText(data)
|
|
|
|
local stacktext = "";
|
|
-- if (data.stackSize > 1) then
|
|
-- stacktext = " (stack of "..data.stackSize..")";
|
|
-- end
|
|
|
|
local now = time();
|
|
local nowtime = date ("*t");
|
|
|
|
local when = data.when;
|
|
local whentime = date ("*t", when);
|
|
|
|
local numauctions = data.stackSize;
|
|
|
|
local datestr = "";
|
|
|
|
if (data.type == "hy") then
|
|
return ZT("average of your auctions for").." "..whentime.year;
|
|
elseif (data.type == "hm") then
|
|
if (nowtime.year == whentime.year) then
|
|
return ZT("average of your auctions for").." "..date("%B", when);
|
|
else
|
|
return ZT("average of your auctions for").." "..date("%B %Y", when);
|
|
end
|
|
elseif (data.type == "hd") then
|
|
return ZT("average of your auctions for").." "..monthDay(whentime);
|
|
else
|
|
return ZT("your auction on").." "..monthDay(whentime)..date(" at %I:%M %p", when);
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function monthDay (when)
|
|
|
|
local t = time(when);
|
|
|
|
local s = date("%b ", t);
|
|
|
|
return s..when.day;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowLineTooltip (self)
|
|
|
|
local itemLink = Atr_NormalizeItemLink (self.itemLink);
|
|
|
|
if (itemLink) then
|
|
GameTooltip:SetOwner(self, "ANCHOR_RIGHT", -280);
|
|
if (not pcall(GameTooltip.SetHyperlink, GameTooltip, itemLink, 1)) then -- never break the tooltip over a bad link
|
|
GameTooltip:SetText(itemLink);
|
|
GameTooltip:Show();
|
|
end
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_HideLineTooltip (self)
|
|
GameTooltip:Hide();
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Onclick_Back ()
|
|
|
|
gCurrentPane.activeScan = Atr_FindScan (nil);
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Onclick_Col1 ()
|
|
|
|
if (not Atr_ShowingSearchSummary()) then -- list of auctions: flip cheapest-first / most-expensive-first
|
|
local scn = gCurrentPane.activeScan;
|
|
if (scn and not scn:IsNil()) then
|
|
local key = Atr_PickKey (scn, gCurrentPane.currIndex);
|
|
gAtr_PriceSortDesc = not gAtr_PriceSortDesc;
|
|
scn:CondenseAndSort ();
|
|
gCurrentPane.currIndex = Atr_FindPickKey (scn, key);
|
|
FauxScrollFrame_SetOffset (AuctionatorScrollFrame, 0);
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
PlaySound ("igMainMenuOptionCheckBoxOn");
|
|
end
|
|
return;
|
|
end
|
|
|
|
if (gCurrentPane.activeSearch) then
|
|
gCurrentPane.activeSearch:ClickPriceCol();
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Onclick_Col3 ()
|
|
|
|
if (gCurrentPane.activeSearch) then
|
|
gCurrentPane.activeSearch:ClickNameCol();
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowSearchSummary()
|
|
|
|
Atr_Col1_Heading_Button:SetText (ZT("Lowest Price"));
|
|
Atr_Col1_Heading:Hide();
|
|
Atr_Col3_Heading:Hide();
|
|
Atr_Col1_Heading_Button:Show();
|
|
Atr_Col3_Heading_Button:Show();
|
|
Atr_Col4_Heading:Show();
|
|
|
|
gCurrentPane.activeSearch:UpdateArrows ();
|
|
|
|
local numrows = gCurrentPane.activeSearch:NumScans();
|
|
|
|
if (gCurrentPane.activeScan.hasStack) then
|
|
Atr_Col4_Heading:SetText (ZT("Total Price"));
|
|
else
|
|
Atr_Col4_Heading:SetText ("");
|
|
end
|
|
|
|
local highIndex = 0;
|
|
local line = 0; -- 1 through 12 of our window to scroll
|
|
local dataOffset = FauxScrollFrame_GetOffset (AuctionatorScrollFrame); -- an index into our data calculated from the scroll offset
|
|
|
|
FauxScrollFrame_Update (AuctionatorScrollFrame, numrows, 12, 16);
|
|
|
|
while (line < 12) do
|
|
|
|
dataOffset = dataOffset + 1;
|
|
line = line + 1;
|
|
|
|
local lineEntry = getglobal ("AuctionatorEntry"..line);
|
|
|
|
lineEntry:SetID(dataOffset);
|
|
|
|
local scn;
|
|
|
|
if (gCurrentPane.activeSearch and gCurrentPane.activeSearch:NumSortedScans() > 0) then
|
|
scn = gCurrentPane.activeSearch.sortedScans[dataOffset];
|
|
end
|
|
|
|
if (dataOffset > numrows or not scn) then
|
|
|
|
lineEntry:Hide();
|
|
|
|
else
|
|
local data = scn.absoluteBest;
|
|
|
|
local lineEntry_item_tag = "AuctionatorEntry"..line.."_PerItem_Price";
|
|
|
|
local lineEntry_item = getglobal(lineEntry_item_tag);
|
|
local lineEntry_itemtext = getglobal("AuctionatorEntry"..line.."_PerItem_Text");
|
|
local lineEntry_text = getglobal("AuctionatorEntry"..line.."_EntryText");
|
|
local lineEntry_stack = getglobal("AuctionatorEntry"..line.."_StackPrice");
|
|
|
|
lineEntry_itemtext:SetText ("");
|
|
lineEntry_text:SetText ("");
|
|
lineEntry_stack:SetText ("");
|
|
Atr_ShowRowStackMoney (lineEntry, nil);
|
|
|
|
lineEntry_text:GetParent():SetPoint ("LEFT", 157, 0);
|
|
|
|
Atr_SetMFcolor (lineEntry_item_tag);
|
|
|
|
lineEntry:Show();
|
|
|
|
lineEntry.itemLink = scn.itemLink;
|
|
|
|
local r = scn.itemTextColor[1];
|
|
local g = scn.itemTextColor[2];
|
|
local b = scn.itemTextColor[3];
|
|
|
|
lineEntry_text:SetTextColor (r, g, b);
|
|
lineEntry_stack:SetTextColor (1, 1, 1);
|
|
|
|
local icon = Atr_GetUCIcon (scn.itemName);
|
|
|
|
lineEntry_text:SetText (icon.." "..scn.itemName);
|
|
lineEntry_stack:SetText (scn:GetNumAvailable().." "..ZT("available"));
|
|
|
|
if (data == nil or data.buyoutPrice == 0) then
|
|
lineEntry_item:Hide();
|
|
lineEntry_itemtext:Show();
|
|
lineEntry_itemtext:SetText (ZT("no buyout price"));
|
|
else
|
|
lineEntry_item:Show();
|
|
lineEntry_itemtext:Hide();
|
|
MoneyFrame_Update (lineEntry_item_tag, zc.round(data.buyoutPrice/data.stackSize) );
|
|
end
|
|
|
|
if (zc.StringSame (scn.itemName , gCurrentPane.SS_hilite_itemName)) then
|
|
highIndex = dataOffset;
|
|
end
|
|
|
|
|
|
end
|
|
end
|
|
|
|
Atr_HighlightEntry (highIndex); -- need this for when called from onVerticalScroll
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowCurrentAuctions()
|
|
|
|
Atr_Col1_Heading:Hide();
|
|
Atr_Col3_Heading:Hide();
|
|
Atr_Col4_Heading:Hide();
|
|
Atr_Col1_Heading_Button:Hide();
|
|
Atr_Col3_Heading_Button:Hide();
|
|
|
|
|
|
local numrows = getn(gCurrentPane.activeScan.sortedData);
|
|
|
|
if (numrows > 0) then
|
|
Atr_Col1_Heading_Button:SetText (ZT("Item Price")); -- clickable: flips the price order
|
|
Atr_Col1_Heading_Button:Show();
|
|
Atr_Col1_Heading_ButtonArrow:Show();
|
|
if (gAtr_PriceSortDesc) then
|
|
Atr_Col1_Heading_ButtonArrow:SetTexCoord (0, 0.5625, 1.0, 0);
|
|
else
|
|
Atr_Col1_Heading_ButtonArrow:SetTexCoord (0, 0.5625, 0, 1.0);
|
|
end
|
|
Atr_Col3_Heading:Show();
|
|
Atr_Col4_Heading:Show();
|
|
end
|
|
|
|
Atr_Col1_Heading:SetText (ZT("Item Price"));
|
|
Atr_Col3_Heading:SetText (ZT("Current Auctions"));
|
|
|
|
if (gCurrentPane.activeScan.hasStack) then
|
|
Atr_Col4_Heading:SetText (ZT("Stack Price"));
|
|
else
|
|
Atr_Col4_Heading:SetText ("");
|
|
end
|
|
|
|
local line = 0; -- 1 through 12 of our window to scroll
|
|
local dataOffset = FauxScrollFrame_GetOffset (AuctionatorScrollFrame); -- an index into our data calculated from the scroll offset
|
|
|
|
FauxScrollFrame_Update (AuctionatorScrollFrame, numrows, 12, 16);
|
|
|
|
while (line < 12) do
|
|
|
|
dataOffset = dataOffset + 1;
|
|
line = line + 1;
|
|
|
|
local lineEntry = getglobal ("AuctionatorEntry"..line);
|
|
|
|
lineEntry:SetID(dataOffset);
|
|
|
|
lineEntry.itemLink = nil;
|
|
|
|
if (dataOffset > numrows or not gCurrentPane.activeScan.sortedData[dataOffset]) then
|
|
|
|
lineEntry:Hide();
|
|
|
|
else
|
|
local data = gCurrentPane.activeScan.sortedData[dataOffset];
|
|
|
|
local lineEntry_item_tag = "AuctionatorEntry"..line.."_PerItem_Price";
|
|
|
|
local lineEntry_item = getglobal(lineEntry_item_tag);
|
|
local lineEntry_itemtext = getglobal("AuctionatorEntry"..line.."_PerItem_Text");
|
|
local lineEntry_text = getglobal("AuctionatorEntry"..line.."_EntryText");
|
|
local lineEntry_stack = getglobal("AuctionatorEntry"..line.."_StackPrice");
|
|
|
|
lineEntry_itemtext:SetText ("");
|
|
lineEntry_text:SetText ("");
|
|
lineEntry_stack:SetText ("");
|
|
Atr_ShowRowStackMoney (lineEntry, nil);
|
|
|
|
lineEntry_text:GetParent():SetPoint ("LEFT", 172, 0);
|
|
|
|
Atr_SetMFcolor (lineEntry_item_tag);
|
|
|
|
local entrytext = "";
|
|
|
|
if (data.type == "n") then
|
|
|
|
lineEntry:Show();
|
|
|
|
if (data.count == 1) then
|
|
entrytext = string.format ("%i %s %i", data.count, ZT ("stack of"), data.stackSize);
|
|
else
|
|
entrytext = string.format ("%i %s %i", data.count, ZT ("stacks of"), data.stackSize);
|
|
end
|
|
|
|
lineEntry_text:SetTextColor (0.6, 0.6, 0.6);
|
|
|
|
if ( data.stackSize == Atr_StackSize() or Atr_StackSize() == 0 or gCurrentPane ~= gSellPane) then
|
|
lineEntry_text:SetTextColor (1.0, 1.0, 1.0);
|
|
end
|
|
|
|
if (data.yours) then
|
|
entrytext = entrytext.." ("..ZT("yours")..")";
|
|
elseif (data.altname) then
|
|
entrytext = entrytext.." ("..data.altname..")";
|
|
end
|
|
|
|
-- local ccc = zc.If (data.minpage ~= data.maxpage, "|cffff8888", "");
|
|
-- entrytext = zc.msg_str (entrytext, " ", ccc, data.minpage, " / ", data.maxpage, " ", gCurrentPane.activeScan.searchWasExact);
|
|
|
|
lineEntry_text:SetText (entrytext);
|
|
|
|
if (data.buyoutPrice == 0) then
|
|
lineEntry_item:Hide();
|
|
lineEntry_itemtext:Show();
|
|
lineEntry_itemtext:SetText (ZT("no buyout price"));
|
|
else
|
|
lineEntry_item:Show();
|
|
lineEntry_itemtext:Hide();
|
|
MoneyFrame_Update (lineEntry_item_tag, zc.round(data.buyoutPrice/data.stackSize) );
|
|
|
|
if (data.stackSize > 1) then
|
|
Atr_ShowRowStackMoney (lineEntry, data.buyoutPrice);
|
|
end
|
|
end
|
|
|
|
else
|
|
zc.msg_red ("Unknown datatype:");
|
|
zc.msg_red (data.type);
|
|
end
|
|
end
|
|
end
|
|
|
|
Atr_HighlightEntry (gCurrentPane.currIndex); -- need this for when called from onVerticalScroll
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_ShowHistory ()
|
|
|
|
if (gCurrentPane.sortedHist == nil) then
|
|
Atr_Process_Historydata ();
|
|
Atr_FindBestHistoricalAuction ();
|
|
end
|
|
|
|
Atr_Col1_Heading:Hide();
|
|
Atr_Col1_Heading_Button:Hide();
|
|
Atr_Col3_Heading_Button:Hide();
|
|
Atr_Col3_Heading:Hide();
|
|
Atr_Col4_Heading:Hide();
|
|
|
|
Atr_Col3_Heading:SetText (ZT("History"));
|
|
|
|
local numrows = gCurrentPane.sortedHist and getn(gCurrentPane.sortedHist) or 0;
|
|
|
|
--zc.msg ("gCurrentPane.sortedHist: "..numrows,1,0,0);
|
|
|
|
if (numrows > 0) then
|
|
Atr_Col1_Heading:Show();
|
|
Atr_Col3_Heading:Show();
|
|
end
|
|
|
|
local line; -- 1 through 12 of our window to scroll
|
|
local dataOffset; -- an index into our data calculated from the scroll offset
|
|
|
|
FauxScrollFrame_Update (AuctionatorScrollFrame, numrows, 12, 16);
|
|
|
|
for line = 1,12 do
|
|
|
|
dataOffset = line + FauxScrollFrame_GetOffset (AuctionatorScrollFrame);
|
|
|
|
local lineEntry = getglobal ("AuctionatorEntry"..line);
|
|
|
|
lineEntry:SetID(dataOffset);
|
|
|
|
if (dataOffset <= numrows and gCurrentPane.sortedHist[dataOffset]) then
|
|
|
|
local data = gCurrentPane.sortedHist[dataOffset];
|
|
|
|
local lineEntry_item_tag = "AuctionatorEntry"..line.."_PerItem_Price";
|
|
|
|
local lineEntry_item = getglobal(lineEntry_item_tag);
|
|
local lineEntry_itemtext = getglobal("AuctionatorEntry"..line.."_PerItem_Text");
|
|
local lineEntry_text = getglobal("AuctionatorEntry"..line.."_EntryText");
|
|
local lineEntry_stack = getglobal("AuctionatorEntry"..line.."_StackPrice");
|
|
|
|
lineEntry_item:Show();
|
|
lineEntry_itemtext:Hide();
|
|
lineEntry_stack:SetText ("");
|
|
Atr_ShowRowStackMoney (lineEntry, nil);
|
|
|
|
Atr_SetMFcolor (lineEntry_item_tag);
|
|
|
|
MoneyFrame_Update (lineEntry_item_tag, zc.round(data.itemPrice) );
|
|
|
|
lineEntry_text:SetText (Atr_BuildHistItemText (data));
|
|
lineEntry_text:SetTextColor (0.8, 0.8, 1.0);
|
|
|
|
lineEntry:Show();
|
|
else
|
|
lineEntry:Hide();
|
|
end
|
|
end
|
|
|
|
if (Atr_IsTabSelected (SELL_TAB)) then
|
|
Atr_HighlightEntry (gCurrentPane.histIndex); -- need this for when called from onVerticalScroll
|
|
else
|
|
Atr_HighlightEntry (-1);
|
|
end
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_FindBestCurrentAuction()
|
|
|
|
local scan = gCurrentPane.activeScan;
|
|
|
|
if (gCurrentPane.pickKey) then -- keep the row the user picked while the search was running
|
|
local idx = Atr_FindPickKey (scan, gCurrentPane.pickKey);
|
|
if (idx) then
|
|
gCurrentPane.currIndex = idx;
|
|
return;
|
|
end
|
|
gCurrentPane.pickKey = nil;
|
|
end
|
|
|
|
|
|
if (Atr_IsModeCreateAuction()) then gCurrentPane.currIndex = scan:FindCheapest ();
|
|
elseif (Atr_IsModeBuy()) then gCurrentPane.currIndex = scan:FindCheapest ();
|
|
else gCurrentPane.currIndex = scan:FindMatchByYours ();
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_FindBestHistoricalAuction()
|
|
|
|
gCurrentPane.histIndex = nil;
|
|
|
|
if (gCurrentPane.sortedHist and getn(gCurrentPane.sortedHist) > 0) then
|
|
gCurrentPane.histIndex = 1;
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_HighlightEntry(entryIndex)
|
|
|
|
local line; -- 1 through 12 of our window to scroll
|
|
|
|
for line = 1,12 do
|
|
|
|
local lineEntry = getglobal ("AuctionatorEntry"..line);
|
|
|
|
if (lineEntry:GetID() == entryIndex) then
|
|
Atr_SetRowSelected (lineEntry, true);
|
|
else
|
|
Atr_SetRowSelected (lineEntry, false);
|
|
end
|
|
end
|
|
|
|
local doEnableCancel = false;
|
|
local doEnableBuy = false;
|
|
local data;
|
|
|
|
if (Atr_ShowingCurrentAuctions() and entryIndex ~= nil and entryIndex > 0 and entryIndex <= getn(gCurrentPane.activeScan.sortedData)) then
|
|
data = gCurrentPane.activeScan.sortedData[entryIndex];
|
|
if (data.yours) then
|
|
doEnableCancel = true;
|
|
end
|
|
|
|
if (not data.yours and not data.altname and data.buyoutPrice > 0) then
|
|
doEnableBuy = true;
|
|
end
|
|
end
|
|
|
|
Atr_Buy1_Button:Disable();
|
|
Atr_CancelSelectionButton:Disable();
|
|
|
|
if (doEnableCancel) then
|
|
Atr_CancelSelectionButton:Enable();
|
|
|
|
if (data.count == 1) then
|
|
Atr_CancelSelectionButton:SetText (CANCEL_AUCTION);
|
|
else
|
|
Atr_CancelSelectionButton:SetText (ZT("Cancel Auctions"));
|
|
end
|
|
end
|
|
|
|
if (doEnableBuy) then
|
|
Atr_Buy1_Button:Enable();
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_EntryOnClick()
|
|
|
|
local entryIndex = this:GetID();
|
|
|
|
if (Atr_ShowingSearchSummary()) then
|
|
elseif (Atr_ShowingCurrentAuctions()) then gCurrentPane.currIndex = entryIndex;
|
|
gCurrentPane.pickKey = Atr_PickKey (gCurrentPane.activeScan, entryIndex);
|
|
elseif (Atr_ShowingHistory()) then gCurrentPane.histIndex = entryIndex;
|
|
else gCurrentPane.hintsIndex = entryIndex;
|
|
end
|
|
|
|
if (Atr_ShowingSearchSummary()) then
|
|
local scn = gCurrentPane.activeSearch.sortedScans[entryIndex];
|
|
|
|
FauxScrollFrame_SetOffset (AuctionatorScrollFrame, 0);
|
|
gCurrentPane.activeScan = scn;
|
|
gCurrentPane.pickKey = nil;
|
|
gCurrentPane.currIndex = scn:FindMatchByYours ();
|
|
gCurrentPane.SS_hilite_itemName = scn.itemName;
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
else
|
|
Atr_HighlightEntry (entryIndex);
|
|
Atr_UpdateRecommendation(true);
|
|
end
|
|
|
|
PlaySound ("igMainMenuOptionCheckBoxOn");
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function AuctionatorMoneyFrame_OnLoad()
|
|
|
|
this.small = 1;
|
|
MoneyFrame_SetType("AUCTION");
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_GetNumItemInBags (theItemName)
|
|
|
|
return Atr_CountItemInBags (theItemName);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CancelAuction(x)
|
|
|
|
CancelAuction(x);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- starts a confirmed, one-at-a-time cancel walk (see the gOwnerCancel* state block near the top
|
|
-- of this file for why). matchFn(name, stackSize, buyoutPrice) decides whether a given owner slot
|
|
-- should be cancelled; onEach(name, stackSize, buyoutPrice) fires once a cancel is genuinely
|
|
-- confirmed by the server; onComplete() fires once no further matches remain on any page, or once
|
|
-- maxCount confirmed cancels have happened (whichever comes first) - pass nil for maxCount to
|
|
-- cancel every match. Returns false without starting anything if another owner-page walk (read or
|
|
-- cancel) is already active.
|
|
function Atr_StartOwnerCancelWalk (matchFn, onEach, onComplete, maxCount)
|
|
|
|
if (gOwnerScanActive or gOwnerCancelState ~= nil) then
|
|
return false;
|
|
end
|
|
|
|
gOwnerCancelPage = 0;
|
|
gOwnerCancelMatchFn = matchFn;
|
|
gOwnerCancelOnEach = onEach;
|
|
gOwnerCancelOnComplete = onComplete;
|
|
gOwnerCancelConfirmed = false;
|
|
gOwnerCancelFailed = false;
|
|
gOwnerCancelMaxCount = (maxCount and maxCount > 0) and maxCount or nil;
|
|
gOwnerCancelConfirmedCount = 0;
|
|
|
|
-- explicitly (re-)request page 0 rather than assuming the shared cursor is already sitting
|
|
-- there - it may currently be wherever some other, unrelated owner-page read last left it
|
|
GetOwnerAuctionItems (gOwnerCancelPage);
|
|
gOwnerCancelState = "pageloading";
|
|
gOwnerCancelT = GetTime();
|
|
|
|
return true;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- shared by both the "no match found anywhere" and "reached the requested maxCount" endings
|
|
local function Atr_FinishOwnerCancelWalk ()
|
|
|
|
local page = gOwnerCancelPage;
|
|
local onComplete = gOwnerCancelOnComplete;
|
|
|
|
gOwnerCancelState = nil;
|
|
|
|
Atr_InvalidateActiveAuctions ();
|
|
|
|
if (onComplete) then
|
|
onComplete ();
|
|
end
|
|
|
|
if (page > 0) then
|
|
GetOwnerAuctionItems (0); -- put the shared owner-page cursor back at page 0 for whatever reads it next
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- polled every frame from Atr_OnUpdate; no-ops instantly whenever no walk is active
|
|
function Atr_OwnerCancelStep ()
|
|
|
|
if (gOwnerCancelState == nil) then
|
|
return;
|
|
end
|
|
|
|
local now = GetTime();
|
|
|
|
if (gOwnerCancelState == "pageloading") then
|
|
-- the event this is normally waiting for (Atr_OnAuctionOwnedUpdate advancing this to
|
|
-- "findmatch") can simply never arrive, confirmed by testing: if the page just requested
|
|
-- was already the client's current page, no real fetch happens and nothing re-fires
|
|
-- AUCTION_OWNED_LIST_UPDATE - this walk would otherwise sit here forever (seen stalling an
|
|
-- entire cancel until unrelated posting activity happened to deliver some other page's
|
|
-- update, which this state change doesn't care which page triggered it). Same fallback as
|
|
-- Atr_OwnerScanStep uses for the read-only walk: after a short wait, stop waiting and just
|
|
-- look at whatever's already there.
|
|
if (now - gOwnerCancelT > 0.1) then
|
|
gOwnerCancelState = "findmatch";
|
|
else
|
|
return;
|
|
end
|
|
end
|
|
|
|
if (gOwnerCancelState == "cancelwait") then
|
|
if (gOwnerCancelConfirmed) then
|
|
|
|
-- only ever trust the server's own ERR_AUCTION_REMOVED as proof this actually
|
|
-- happened - the client's own list/count shrinks optimistically well before the
|
|
-- server has accepted or rejected anything, and treating that as success is exactly
|
|
-- what let a cancel claim succeed when it hadn't (confirmed by direct testing)
|
|
if (gOwnerCancelOnEach) then
|
|
gOwnerCancelOnEach (gOwnerCancelPendingName, gOwnerCancelPendingStackSize, gOwnerCancelPendingBuyout);
|
|
end
|
|
AuctionatorSubtractFromScan (gOwnerCancelPendingName, gOwnerCancelPendingStackSize, gOwnerCancelPendingBuyout);
|
|
|
|
gOwnerCancelConfirmedCount = gOwnerCancelConfirmedCount + 1;
|
|
|
|
if (gOwnerCancelMaxCount and gOwnerCancelConfirmedCount >= gOwnerCancelMaxCount) then
|
|
Atr_FinishOwnerCancelWalk ();
|
|
return;
|
|
end
|
|
|
|
-- re-request the current page explicitly rather than trusting GetAuctionItemInfo's
|
|
-- cache is already fully settled the instant ERR_AUCTION_REMOVED fires - confirmed by
|
|
-- testing that scanning immediately can miss a genuinely-still-there match right
|
|
-- after a confirmed cancel (several auctions needed a second manual click to catch),
|
|
-- the same discipline page-advances already use instead of trusting a stale read
|
|
GetOwnerAuctionItems (gOwnerCancelPage);
|
|
gOwnerCancelState = "pageloading";
|
|
gOwnerCancelT = now;
|
|
return;
|
|
|
|
elseif (now - gOwnerCancelT > 5) then
|
|
-- no ERR_AUCTION_REMOVED arrived in time - don't count it as cancelled (it may not
|
|
-- actually have been), but don't retry the exact same slot forever either; move on
|
|
-- to look for the next match, which will naturally re-target this same auction if
|
|
-- it's genuinely still there
|
|
gOwnerCancelFailed = true;
|
|
GetOwnerAuctionItems (gOwnerCancelPage);
|
|
gOwnerCancelState = "pageloading";
|
|
gOwnerCancelT = now;
|
|
return;
|
|
else
|
|
return;
|
|
end
|
|
end
|
|
|
|
-- "findmatch"
|
|
local numBatch, totalAuctions = GetNumAuctionItems ("owner");
|
|
|
|
local i;
|
|
local foundIndex;
|
|
for i = 1, numBatch do
|
|
local name, texture, stackSize, quality, canUse, level,
|
|
minBid, minIncrement, buyoutPrice = GetAuctionItemInfo ("owner", i);
|
|
|
|
if (name and gOwnerCancelMatchFn (name, stackSize, buyoutPrice)) then
|
|
foundIndex = i;
|
|
break;
|
|
end
|
|
end
|
|
|
|
if (foundIndex) then
|
|
|
|
local name, texture, stackSize, quality, canUse, level,
|
|
minBid, minIncrement, buyoutPrice = GetAuctionItemInfo ("owner", foundIndex);
|
|
|
|
gOwnerCancelPendingName = name;
|
|
gOwnerCancelPendingStackSize = stackSize;
|
|
gOwnerCancelPendingBuyout = buyoutPrice;
|
|
|
|
gOwnerCancelConfirmed = false;
|
|
gOwnerCancelFailed = false;
|
|
Atr_CancelAuction (foundIndex);
|
|
gOwnerCancelT = now;
|
|
gOwnerCancelState = "cancelwait";
|
|
|
|
elseif ((gOwnerCancelPage + 1) * 50 < (totalAuctions or 0)) then
|
|
|
|
gOwnerCancelPage = gOwnerCancelPage + 1;
|
|
GetOwnerAuctionItems (gOwnerCancelPage);
|
|
gOwnerCancelState = "pageloading";
|
|
gOwnerCancelT = now;
|
|
|
|
else
|
|
Atr_FinishOwnerCancelWalk ();
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_LogCancelAuction(numCancelled, itemLink, stackSize, depositLost)
|
|
|
|
if (numCancelled < 1) then
|
|
return;
|
|
end
|
|
|
|
itemLink = Atr_BuildDisplayLink (itemLink) or itemLink;
|
|
|
|
local stackWord = (numCancelled == 1) and ZT("stack of") or ZT("stacks of");
|
|
local coloredCount = "|cff00dddd"..numCancelled.." "..stackWord.." "..(stackSize or 1).."x|r";
|
|
|
|
local depositString = "";
|
|
if (depositLost ~= nil) then
|
|
depositString = " - "..ZT("Deposit lost")..": "..zc.priceToString (depositLost);
|
|
end
|
|
|
|
zc.msg_yellow (string.format (ZT("Auctions cancelled for %s %s%s"), coloredCount, itemLink, depositString));
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- remembers which row "Cancel Auctions" was clicked for, so the count-prompt dialog's OK button
|
|
-- (clicked later, possibly after other selections changed) still targets the right auction
|
|
local gCancelPromptItemName;
|
|
local gCancelPromptItemLink;
|
|
local gCancelPromptBuyoutPrice;
|
|
local gCancelPromptStackSize;
|
|
|
|
function Atr_CancelSelection_OnClick()
|
|
|
|
if (not Atr_ShowingCurrentAuctions()) then
|
|
return;
|
|
end
|
|
|
|
local data = gCurrentPane.activeScan.sortedData[gCurrentPane.currIndex];
|
|
|
|
if (not data or not data.yours) then
|
|
return;
|
|
end
|
|
|
|
gCancelPromptItemName = gCurrentPane.activeScan.itemName;
|
|
gCancelPromptItemLink = gCurrentPane.activeScan.itemLink;
|
|
gCancelPromptBuyoutPrice = data.buyoutPrice;
|
|
gCancelPromptStackSize = data.stackSize;
|
|
|
|
Atr_CancelCount_Box:SetText (tostring (data.count or 1));
|
|
|
|
Atr_CancelCountFrame:ClearAllPoints ();
|
|
Atr_CancelCountFrame:SetPoint ("BOTTOMRIGHT", AuctionFrame, "BOTTOMRIGHT", -20, 20);
|
|
|
|
Atr_CancelCountFrame:Show ();
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CancelCount_OnClick ()
|
|
|
|
Atr_CancelCountFrame:Hide ();
|
|
|
|
local maxCount = Atr_CancelCount_Box:GetNumber();
|
|
if (maxCount == nil or maxCount < 1) then
|
|
return; -- nothing sensible was entered - do nothing rather than guess
|
|
end
|
|
|
|
Atr_CancelAuctionsMatching (gCancelPromptItemName, gCancelPromptItemLink, gCancelPromptBuyoutPrice, gCancelPromptStackSize, maxCount);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- starts a confirmed, one-at-a-time cancel walk for every owner auction matching this item/stack
|
|
-- size/buyout price, across every page, stopping once maxCount are confirmed (nil = cancel every
|
|
-- match). Returns immediately; Atr_LogCancelAuction fires once the whole walk completes (see
|
|
-- Atr_StartOwnerCancelWalk/Atr_OwnerCancelStep).
|
|
function Atr_CancelAuctionsMatching (itemName, itemLink, buyoutPrice, stackSize, maxCount)
|
|
|
|
local numCancelled = 0;
|
|
|
|
Atr_StartOwnerCancelWalk (
|
|
|
|
function (name, ss, bp)
|
|
return (name == itemName and bp == buyoutPrice and ss == stackSize);
|
|
end,
|
|
|
|
function (name, ss, bp)
|
|
numCancelled = numCancelled + 1;
|
|
end,
|
|
|
|
function ()
|
|
local deposit = Atr_GetRecordedDeposit (itemName, buyoutPrice, stackSize);
|
|
local depositLost = deposit and (deposit * numCancelled) or nil;
|
|
Atr_LogCancelAuction (numCancelled, itemLink, stackSize, depositLost);
|
|
gHlistNeedsUpdate = true;
|
|
end,
|
|
|
|
maxCount
|
|
);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-- cancels every owner auction matching this row's item/stack size/buyout price, across every
|
|
-- page. Kept as its own entry point (rather than folded into the dialog flow above) since
|
|
-- Atr_CancelUndercuts_CurrentScan already calls this by sortedData index, unprompted, once the
|
|
-- player has confirmed an undercut cancellation.
|
|
function Atr_CancelAuction_ByIndex(index)
|
|
|
|
local data = gCurrentPane.activeScan.sortedData[index];
|
|
|
|
if (not data.yours) then
|
|
return;
|
|
end
|
|
|
|
Atr_CancelAuctionsMatching (gCurrentPane.activeScan.itemName, gCurrentPane.activeScan.itemLink, data.buyoutPrice, data.stackSize, nil);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_StackingPrefs_Init ()
|
|
|
|
AUCTIONATOR_STACKING_PREFS = {};
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Has_StackingPrefs (key)
|
|
|
|
local lkey = string.lower(key);
|
|
|
|
return (AUCTIONATOR_STACKING_PREFS[lkey] ~= nil);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Clear_StackingPrefs (key)
|
|
|
|
local lkey = string.lower(key);
|
|
|
|
AUCTIONATOR_STACKING_PREFS[lkey] = nil;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Get_StackingPrefs (key)
|
|
|
|
local lkey = string.lower(key);
|
|
|
|
if (Atr_Has_StackingPrefs(lkey)) then
|
|
return AUCTIONATOR_STACKING_PREFS[lkey].numstacks, AUCTIONATOR_STACKING_PREFS[lkey].stacksize;
|
|
end
|
|
|
|
return nil, nil;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Set_StackingPrefs_numstacks (key, numstacks)
|
|
|
|
local lkey = string.lower(key);
|
|
|
|
if (not Atr_Has_StackingPrefs(lkey)) then
|
|
AUCTIONATOR_STACKING_PREFS[lkey] = { stacksize = 0 };
|
|
end
|
|
|
|
AUCTIONATOR_STACKING_PREFS[lkey].numstacks = zc.Val (numstacks, 1);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Set_StackingPrefs_stacksize (key, stacksize)
|
|
|
|
local lkey = string.lower(key);
|
|
|
|
if (not Atr_Has_StackingPrefs(lkey)) then
|
|
AUCTIONATOR_STACKING_PREFS[lkey] = { numstacks = 0};
|
|
end
|
|
|
|
AUCTIONATOR_STACKING_PREFS[lkey].stacksize = zc.Val (stacksize, 1);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_GetStackingPrefs_ByItem (itemLink)
|
|
|
|
if (itemLink) then
|
|
|
|
local itemName = Atr_GetItemInfo (itemLink);
|
|
local text, spinfo;
|
|
|
|
for text, spinfo in pairs (AUCTIONATOR_STACKING_PREFS) do
|
|
|
|
if (zc.StringContains (itemName, text)) then
|
|
return spinfo.numstacks, spinfo.stacksize;
|
|
end
|
|
end
|
|
|
|
if (Atr_IsGlyph (itemLink)) then return Atr_Special_SP (ATR_SK_GLYPHS, 0, 1);
|
|
elseif (Atr_IsCutGem (itemLink)) then return Atr_Special_SP (ATR_SK_GEMS_CUT, 0, 1);
|
|
elseif (Atr_IsGem (itemLink)) then return Atr_Special_SP (ATR_SK_GEMS_UNCUT, 1, 0);
|
|
elseif (Atr_IsItemEnhancement (itemLink)) then return Atr_Special_SP (ATR_SK_ITEM_ENH, 0, 1);
|
|
elseif (Atr_IsPotion (itemLink) or Atr_IsElixir (itemLink)) then return Atr_Special_SP (ATR_SK_POT_ELIX, 1, 0);
|
|
elseif (Atr_IsFlask (itemLink)) then return Atr_Special_SP (ATR_SK_FLASKS, 1, 0);
|
|
elseif (Atr_IsHerb (itemLink)) then return Atr_Special_SP (ATR_SK_HERBS, 1, 0);
|
|
end
|
|
end
|
|
|
|
return nil, nil;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Special_SP (key, numstack, stacksize)
|
|
|
|
if (Atr_Has_StackingPrefs (key)) then
|
|
return Atr_Get_StackingPrefs(key);
|
|
end
|
|
|
|
return numstack, stacksize;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_GetSellStacking (itemLink, numDragged, numTotal)
|
|
|
|
-- the number of stacks always defaults to the max possible for however many you actually have
|
|
-- in your bags - only the stack size itself is ever remembered/capped by the item's own limit
|
|
|
|
local prefNumStacks, prefStackSize = Atr_GetStackingPrefs_ByItem (itemLink);
|
|
|
|
local stackSize;
|
|
|
|
if (prefStackSize and prefStackSize > 0) then -- a remembered, fixed stack size
|
|
stackSize = prefStackSize;
|
|
|
|
elseif (prefNumStacks and prefNumStacks > 0) then -- "auto stacksize": derive it from the remembered number of stacks
|
|
stackSize = math.floor (numDragged / prefNumStacks);
|
|
|
|
else -- no remembered preference at all - cap at the item's own max stack size
|
|
local maxStack = Atr_ItemStackSize (itemLink);
|
|
stackSize = numTotal;
|
|
if (maxStack and maxStack > 0) then
|
|
stackSize = math.min (maxStack, numTotal);
|
|
end
|
|
end
|
|
|
|
if (not stackSize or stackSize <= 0) then
|
|
stackSize = numDragged;
|
|
end
|
|
|
|
local numStacks = math.floor (numTotal / stackSize);
|
|
|
|
if (numStacks == 0) then
|
|
numStacks = 1;
|
|
stackSize = numTotal;
|
|
end
|
|
|
|
return numStacks, stackSize;
|
|
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
local gInitial_NumStacks;
|
|
local gInitial_StackSize;
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetInitialStacking (numStacks, stackSize)
|
|
|
|
gInitial_NumStacks = numStacks;
|
|
gInitial_StackSize = stackSize;
|
|
|
|
Atr_Batch_NumAuctions:SetText (numStacks);
|
|
Atr_SetStackSize (stackSize);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Memorize_Stacking_If ()
|
|
|
|
local newNumStacks = Atr_Batch_NumAuctions:GetNumber();
|
|
local newStackSize = Atr_StackSize();
|
|
|
|
local numStacksChanged = (tonumber (gInitial_NumStacks) ~= newNumStacks);
|
|
local stackSizeChanged = (tonumber (gInitial_StackSize) ~= newStackSize);
|
|
|
|
if (stackSizeChanged) then
|
|
|
|
local itemName = string.lower(gCurrentPane.activeScan.itemName);
|
|
|
|
if (itemName) then
|
|
|
|
-- see if user is trying to set it back to default
|
|
|
|
if (newNumStacks == 1) then
|
|
local _, _, auctionCount = GetAuctionSellItemInfo();
|
|
if (auctionCount == newStackSize) then
|
|
Atr_Clear_StackingPrefs (itemName);
|
|
return;
|
|
end
|
|
end
|
|
|
|
-- else remember the new stack size
|
|
|
|
Atr_Set_StackingPrefs_stacksize (itemName, Atr_StackSize());
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Duration_OnLoad(self)
|
|
UIDropDownMenu_Initialize (self, Atr_Duration_Initialize);
|
|
UIDropDownMenu_SetSelectedValue (Atr_Duration, 1);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Duration_OnShow(self)
|
|
UIDropDownMenu_Initialize (self, Atr_Duration_Initialize);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Duration_Initialize()
|
|
|
|
local info = UIDropDownMenu_CreateInfo();
|
|
local i;
|
|
|
|
for i = 1, 3 do
|
|
info.text = AtrNS.durationText[i];
|
|
info.value = i;
|
|
info.checked = nil;
|
|
info.func = Atr_Duration_OnClick;
|
|
UIDropDownMenu_AddButton(info);
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Duration_OnClick()
|
|
|
|
UIDropDownMenu_SetSelectedValue(Atr_Duration, this.value);
|
|
Atr_SetDepositText();
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_DropDown1_OnLoad (self)
|
|
UIDropDownMenu_Initialize(self, Atr_DropDown1_Initialize);
|
|
UIDropDownMenu_SetSelectedValue(Atr_DropDown1, MODE_LIST_ACTIVE);
|
|
Atr_DropDown1:Show();
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_DropDown1_Initialize()
|
|
local info = UIDropDownMenu_CreateInfo();
|
|
|
|
info.text = ZT("Active Listings");
|
|
info.value = MODE_LIST_ACTIVE;
|
|
info.func = Atr_DropDown1_OnClick;
|
|
info.owner = Atr_DropDown1;
|
|
info.checked = nil;
|
|
UIDropDownMenu_AddButton(info);
|
|
|
|
info.text = ZT("History");
|
|
info.value = MODE_LIST_ALL;
|
|
info.func = Atr_DropDown1_OnClick;
|
|
info.owner = Atr_DropDown1;
|
|
info.checked = nil;
|
|
UIDropDownMenu_AddButton(info);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_DropDown1_OnClick()
|
|
|
|
UIDropDownMenu_SetSelectedValue(this.owner, this.value);
|
|
|
|
local mode = this.value;
|
|
|
|
if (mode == MODE_LIST_ALL) then
|
|
Atr_DisplayHlist();
|
|
end
|
|
|
|
if (mode == MODE_LIST_ACTIVE) then
|
|
|
|
-- same reasoning as the MORE_TAB switch above: give the one-shot AH-open trigger
|
|
-- another chance, since it can silently race-fail with nothing else to retry it
|
|
if (not gOwnerScanActive and gOwnerCancelState == nil) then
|
|
Atr_RefreshOwnedAuctions ();
|
|
end
|
|
|
|
Atr_DisplayHlist();
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_AddMenuPick (info, text, value, func)
|
|
|
|
info.text = text;
|
|
info.value = value;
|
|
info.func = func;
|
|
info.checked = nil;
|
|
info.owner = getglobal (UIDROPDOWNMENU_INIT_MENU);
|
|
UIDropDownMenu_AddButton(info);
|
|
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_IsTabSelected(whichTab)
|
|
|
|
if (not AuctionFrame or not AuctionFrame:IsShown()) then
|
|
return false;
|
|
end
|
|
|
|
if (not whichTab) then
|
|
return (Atr_IsTabSelected(SELL_TAB) or Atr_IsTabSelected(MORE_TAB) or Atr_IsTabSelected(BUY_TAB));
|
|
end
|
|
|
|
return (PanelTemplates_GetSelectedTab (AuctionFrame) == Atr_FindTabIndex(whichTab));
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_IsAuctionatorTab (tabIndex)
|
|
|
|
if (tabIndex == Atr_FindTabIndex(SELL_TAB) or tabIndex == Atr_FindTabIndex(MORE_TAB) or tabIndex == Atr_FindTabIndex(BUY_TAB) ) then
|
|
|
|
return true;
|
|
|
|
end
|
|
|
|
return false;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Confirm_Yes()
|
|
|
|
if (Atr_Confirm_Proc_Yes) then
|
|
Atr_Confirm_Proc_Yes();
|
|
Atr_Confirm_Proc_Yes = nil;
|
|
end
|
|
|
|
Atr_Confirm_Frame:Hide();
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Confirm_No()
|
|
|
|
Atr_Confirm_Frame:Hide();
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_AddHistoricalPrice (itemName, price, stacksize, itemLink, testwhen)
|
|
|
|
if (not AUCTIONATOR_PRICING_HISTORY[itemName] ) then
|
|
AUCTIONATOR_PRICING_HISTORY[itemName] = {};
|
|
end
|
|
|
|
local itemId, suffixId, uniqueId = zc.ItemIDfromLink (itemLink);
|
|
|
|
local is = itemId;
|
|
|
|
if (suffixId ~= 0) then
|
|
is = is..":"..suffixId;
|
|
if (tonumber(suffixId) < 0) then
|
|
is = is..":"..uniqueId;
|
|
end
|
|
end
|
|
|
|
AUCTIONATOR_PRICING_HISTORY[itemName]["is"] = is;
|
|
|
|
local hist = tostring (zc.round (price))..":"..stacksize;
|
|
|
|
local roundtime = floor (time() / 60) * 60; -- so multiple auctions close together don't generate too many entries
|
|
|
|
local tag = tostring(ToTightTime(roundtime));
|
|
|
|
if (testwhen) then
|
|
tag = tostring(ToTightTime(testwhen));
|
|
end
|
|
|
|
AUCTIONATOR_PRICING_HISTORY[itemName][tag] = hist;
|
|
|
|
gCurrentPane.sortedHist = nil;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_HasHistoricalData (itemName)
|
|
|
|
if (AUCTIONATOR_PRICING_HISTORY[itemName] ) then
|
|
return true;
|
|
end
|
|
|
|
return false;
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_BuildGlobalHistoryList(full)
|
|
|
|
gHistoryItemList = {};
|
|
|
|
local n = 1;
|
|
|
|
if (full) then
|
|
for name,hist in pairs (AUCTIONATOR_PRICING_HISTORY) do
|
|
gHistoryItemList[n] = name;
|
|
n = n + 1;
|
|
end
|
|
else
|
|
if (zc.tableIsEmpty (gActiveAuctions)) then
|
|
Atr_BuildActiveAuctions();
|
|
end
|
|
|
|
local name;
|
|
for name, count in pairs (gActiveAuctions) do
|
|
if (name and count ~= 0) then
|
|
gHistoryItemList[n] = name;
|
|
n = n + 1;
|
|
end
|
|
end
|
|
end
|
|
|
|
table.sort (gHistoryItemList);
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_FindHListIndexByName (itemName)
|
|
|
|
local x;
|
|
|
|
for x = 1, getn(gHistoryItemList) do
|
|
if (itemName == gHistoryItemList[x]) then
|
|
return x;
|
|
end
|
|
end
|
|
|
|
return 0;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local gAtr_CheckingActive_State = ATR_CACT_NULL;
|
|
local gAtr_CheckingActive_Index;
|
|
local gAtr_CheckingActive_NextItemName;
|
|
local gAtr_CheckingActive_AndCancel = false;
|
|
|
|
gAtr_CheckingActive_NumUndercuts = 0;
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CheckActive_OnClick (andCancel)
|
|
|
|
if (gAtr_CheckingActive_State == ATR_CACT_NULL) then
|
|
|
|
Atr_CheckActiveList (andCancel);
|
|
--[[
|
|
if (andCancel == nil) then
|
|
Atr_CheckActives_Frame:Show();
|
|
else
|
|
Atr_CheckActives_Frame:Hide();
|
|
Atr_CheckActiveList (andCancel);
|
|
end
|
|
]]--
|
|
else -- stop checking
|
|
Atr_CheckingActive_Finish ();
|
|
gCurrentPane.activeSearch:Abort();
|
|
gCurrentPane:ClearSearch();
|
|
Atr_SetMessage(ZT("Checking stopped"));
|
|
end
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CheckActiveList (andCancel)
|
|
|
|
gAtr_CheckingActive_State = ATR_CACT_READY;
|
|
gAtr_CheckingActive_NextItemName = gHistoryItemList[1];
|
|
gAtr_CheckingActive_AndCancel = andCancel;
|
|
gAtr_CheckingActive_NumUndercuts = 0;
|
|
|
|
gCurrentPane:SetToShowCurrent();
|
|
|
|
Atr_CheckingActiveIdle ();
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CheckingActive_Finish()
|
|
|
|
gAtr_CheckingActive_State = ATR_CACT_NULL; -- done
|
|
|
|
Atr_CheckActiveButton:SetText(ZT("Check for Undercuts"));
|
|
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CheckingActiveIdle()
|
|
|
|
if (gAtr_CheckingActive_State == ATR_CACT_READY) then
|
|
|
|
if (gAtr_CheckingActive_NextItemName == nil) then
|
|
|
|
Atr_CheckingActive_Finish ();
|
|
|
|
if (gAtr_CheckingActive_NumUndercuts > 0) then
|
|
Atr_CheckActives_Frame:Show();
|
|
end
|
|
|
|
else
|
|
gAtr_CheckingActive_State = ATR_CACT_PROCESSING;
|
|
|
|
Atr_CheckActiveButton:SetText(ZT("Stop Checking"));
|
|
|
|
local itemName = gAtr_CheckingActive_NextItemName;
|
|
|
|
local x = Atr_FindHListIndexByName (itemName);
|
|
gAtr_CheckingActive_NextItemName = (x > 0 and getn(gHistoryItemList) >= x+1) and gHistoryItemList[x+1] or nil;
|
|
|
|
local cacheHit = gCurrentPane:DoSearch (itemName, true, 15);
|
|
|
|
Atr_Hilight_Hentry (itemName);
|
|
|
|
if (cacheHit) then
|
|
Atr_CheckingActive_OnSearchComplete();
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CheckActive_IsBusy()
|
|
|
|
return (gAtr_CheckingActive_State ~= ATR_CACT_NULL);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CheckingActive_OnSearchComplete()
|
|
|
|
if (gAtr_CheckingActive_State == ATR_CACT_PROCESSING) then
|
|
|
|
if (gAtr_CheckingActive_AndCancel) then
|
|
zc.AddDeferredCall (0.1, "Atr_CheckingActive_CheckCancel"); -- need to defer so UI can update and show auctions about to be canceled
|
|
else
|
|
zc.AddDeferredCall (0.1, "Atr_CheckingActive_Next"); -- need to defer so UI can update
|
|
end
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CheckingActive_CheckCancel()
|
|
|
|
if (gAtr_CheckingActive_State == ATR_CACT_PROCESSING) then
|
|
|
|
Atr_CancelUndercuts_CurrentScan(false);
|
|
|
|
if (gAtr_CheckingActive_State ~= ATR_CACT_WAITING_ON_CANCEL_CONFIRM) then
|
|
zc.AddDeferredCall (0.1, "Atr_CheckingActive_Next"); -- need to defer so UI can update
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CheckingActive_Next ()
|
|
|
|
if (gAtr_CheckingActive_State == ATR_CACT_PROCESSING) then
|
|
gAtr_CheckingActive_State = ATR_CACT_READY;
|
|
end
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CancelUndercut_Confirm (yesCancel)
|
|
gAtr_CheckingActive_State = ATR_CACT_PROCESSING;
|
|
Atr_CancelAuction_Confirm_Frame:Hide();
|
|
if (yesCancel) then
|
|
Atr_CancelUndercuts_CurrentScan(true);
|
|
end
|
|
zc.AddDeferredCall (0.1, "Atr_CheckingActive_Next");
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CancelUndercuts_CurrentScan(confirmed)
|
|
|
|
local scan = gCurrentPane.activeScan;
|
|
|
|
for x = getn(scan.sortedData),1,-1 do
|
|
|
|
local data = scan.sortedData[x];
|
|
|
|
if (data.yours and data.itemPrice > scan.absoluteBest.itemPrice) then
|
|
|
|
if (not confirmed) then
|
|
gAtr_CheckingActive_State = ATR_CACT_WAITING_ON_CANCEL_CONFIRM;
|
|
Atr_CancelAuction_Confirm_Frame_text:SetText (string.format (ZT("Your auction has been undercut:\n%s%s"), "|cffffffff", scan.itemName));
|
|
Atr_CancelAuction_Confirm_Frame:Show ();
|
|
return;
|
|
end
|
|
|
|
Atr_CancelAuction_ByIndex (x);
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
-- starts a confirmed, one-at-a-time cancel walk for every owner auction (optionally filtered to
|
|
-- one item name) that's currently undercut, across every page. Returns immediately.
|
|
function Atr_Cancel_Undercuts_OnClick (nameToCancel)
|
|
|
|
local cancelled = {};
|
|
|
|
Atr_StartOwnerCancelWalk (
|
|
|
|
function (name, stackSize, buyoutPrice)
|
|
|
|
if (nameToCancel ~= nil and not zc.StringSame (name, nameToCancel)) then
|
|
return false;
|
|
end
|
|
|
|
local scan = Atr_FindScan (name);
|
|
if (not (scan and scan.absoluteBest and scan.whenScanned ~= 0 and scan.yourBestPrice and scan.yourWorstPrice)) then
|
|
return false;
|
|
end
|
|
|
|
local itemPrice = math.floor (buyoutPrice / stackSize);
|
|
|
|
return (itemPrice > scan.absoluteBest.itemPrice);
|
|
end,
|
|
|
|
function (name, stackSize, buyoutPrice)
|
|
|
|
local scan = Atr_FindScan (name);
|
|
|
|
if (cancelled[name] == nil) then
|
|
cancelled[name] = {};
|
|
cancelled[name].num = 0;
|
|
cancelled[name].link = scan.itemLink;
|
|
cancelled[name].stackSize = stackSize;
|
|
end
|
|
|
|
cancelled[name].num = cancelled[name].num + 1;
|
|
|
|
if (scan.yourBestPrice > scan.absoluteBest.itemPrice) then
|
|
gActiveAuctions[name] = nil;
|
|
end
|
|
end,
|
|
|
|
function ()
|
|
local nm, cancelInfo;
|
|
for nm, cancelInfo in pairs (cancelled) do
|
|
Atr_LogCancelAuction (cancelInfo.num, cancelInfo.link, cancelInfo.stackSize);
|
|
end
|
|
|
|
Atr_DisplayHlist();
|
|
Atr_CheckActives_Frame:Hide();
|
|
end
|
|
);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Hilight_Hentry(itemName)
|
|
|
|
for line = 1,ITEM_HIST_NUM_LINES do
|
|
|
|
dataOffset = line + FauxScrollFrame_GetOffset (Atr_Hlist_ScrollFrame);
|
|
|
|
local lineEntry = getglobal ("AuctionatorHEntry"..line);
|
|
|
|
if (dataOffset <= getn(gHistoryItemList) and gHistoryItemList[dataOffset]) then
|
|
|
|
if (gHistoryItemList[dataOffset] == itemName) then
|
|
Atr_SetRowSelected (lineEntry, true);
|
|
else
|
|
Atr_SetRowSelected (lineEntry, false);
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Item_Autocomplete(self)
|
|
|
|
local text = self:GetText();
|
|
local textlen = strlen(text);
|
|
local name;
|
|
|
|
-- first search shopping lists
|
|
|
|
local numLists = getn(AUCTIONATOR_SHOPPING_LISTS);
|
|
local n;
|
|
|
|
for n = 1,numLists do
|
|
local slist = AUCTIONATOR_SHOPPING_LISTS[n];
|
|
|
|
local numItems = getn(slist.items);
|
|
|
|
if ( numItems > 0 ) then
|
|
for i=1, numItems do
|
|
name = slist.items[i];
|
|
if ( name and text and (strfind(strupper(name), strupper(text), 1, 1) == 1) ) then
|
|
self:SetText(name);
|
|
self:HighlightText(textlen, -1);
|
|
return;
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
-- next search history list
|
|
|
|
numItems = getn(gHistoryItemList);
|
|
|
|
if ( numItems > 0 ) then
|
|
for i=1, numItems do
|
|
name = gHistoryItemList[i];
|
|
if ( name and text and (strfind(strupper(name), strupper(text), 1, 1) == 1) ) then
|
|
self:SetText(name);
|
|
self:HighlightText(textlen, -1);
|
|
return;
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_GetCurrentPane () -- so other modules can use gCurrentPane
|
|
return gCurrentPane;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_SetUINeedsUpdate () -- so other modules can easily set
|
|
gCurrentPane.UINeedsUpdate = true;
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CalcUndercutPrice (price)
|
|
|
|
if (price > 5000000) then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._5000000); end;
|
|
if (price > 1000000) then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._1000000); end;
|
|
if (price > 200000) then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._200000); end;
|
|
if (price > 50000) then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._50000); end;
|
|
if (price > 10000) then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._10000); end;
|
|
if (price > 2000) then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._2000); end;
|
|
if (price > 500) then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._500); end;
|
|
if (price > 0) then return math.floor (price - 1); end;
|
|
|
|
return 0;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_CalcStartPrice (buyoutPrice)
|
|
|
|
local ratio = AUCTIONATOR_SAVEDVARS.BIDDING_RATIO / 100;
|
|
|
|
if (ratio >= 1) then -- 100% means the starting bid equals the buyout price exactly
|
|
return math.max (buyoutPrice, 1);
|
|
end
|
|
|
|
return math.max (Atr_CalcUndercutPrice (math.floor (buyoutPrice * ratio)), 1); -- the auction house requires a starting price of at least 1c
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
local ATR_MAX_ITEM_NAME_CHARS = 25; -- total length incl. "...", e.g. "Wicked Chain Shield of..." - never any longer than this
|
|
|
|
function Atr_AbbrevItemName (itemName)
|
|
|
|
local name = string.gsub (itemName, "Scroll of Enchant", "SoE");
|
|
|
|
if (string.len(name) > ATR_MAX_ITEM_NAME_CHARS) then
|
|
name = string.sub (name, 1, ATR_MAX_ITEM_NAME_CHARS - 3).."..."; -- hard cut, mid-word if need be, to use all the space available
|
|
end
|
|
|
|
return name;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_IsMyToon (name)
|
|
|
|
if (name and (AUCTIONATOR_TOONS[name] or AUCTIONATOR_TOONS[string.lower(name)])) then
|
|
return true;
|
|
end
|
|
|
|
return false;
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_Error_Display (errmsg)
|
|
if (errmsg) then
|
|
Atr_Error_Text:SetText (errmsg);
|
|
Atr_Error_Frame:Show ();
|
|
return;
|
|
end
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_PollWho_Unused(s)
|
|
|
|
gSendZoneMsgs = true;
|
|
gQuietWho = time();
|
|
|
|
SetWhoToUI(1);
|
|
|
|
zc.md (s);
|
|
|
|
SendWho (s);
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function Atr_FriendsFrame_OnEvent(self, event)
|
|
|
|
end
|
|
|
|
-- roundPriceDown - rounds a price down to the next lowest multiple of a.
|
|
-- - if the result is not at least a/2 lower, rounds down by a/2.
|
|
--
|
|
-- examples: (128790, 500) -> 128500
|
|
-- (128700, 500) -> 128000
|
|
-- (128400, 500) -> 128000
|
|
-----------------------------------------
|
|
|
|
function roundPriceDown (price, a)
|
|
|
|
if (a == 0) then
|
|
return price;
|
|
end
|
|
|
|
local newprice = math.floor((price-1) / a) * a;
|
|
|
|
if ((price - newprice) < a/2) then
|
|
newprice = newprice - (a/2);
|
|
end
|
|
|
|
if (newprice == price) then
|
|
newprice = newprice - 1;
|
|
end
|
|
|
|
return newprice;
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function ToTightHour(t)
|
|
|
|
return floor((t - gTimeTightZero)/3600);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function FromTightHour(tt)
|
|
|
|
return (tt*3600) + gTimeTightZero;
|
|
|
|
end
|
|
|
|
|
|
-----------------------------------------
|
|
|
|
function ToTightTime(t)
|
|
|
|
return floor((t - gTimeTightZero)/60);
|
|
|
|
end
|
|
|
|
-----------------------------------------
|
|
|
|
function FromTightTime(tt)
|
|
|
|
return (tt*60) + gTimeTightZero;
|
|
|
|
end
|
|
|
|
|
|
--[[
|
|
|
|
- right click item in bag
|
|
- reset to 12 hours when switching tabs
|
|
- off by one when cancelling multisell
|
|
- cosmetic issue with the background
|
|
- collapsed multiple cancel messages
|
|
|
|
]]--
|
|
|
|
|
|
|
|
|