Add scanning, shopping lists and pricing source

This commit is contained in:
2026-10-07 18:49:59 +00:00
parent ef2f20a53a
commit cd6e5653af
5 changed files with 2221 additions and 0 deletions
+147
View File
@@ -0,0 +1,147 @@
AtrPane = {};
AtrPane.__index = AtrPane;
ATR_SHOW_CURRENT = 1;
ATR_SHOW_HISTORY = 2;
ATR_SHOW_HINTS = 3;
function AtrPane.create ()
local pane = {};
setmetatable (pane,AtrPane);
pane.fullStackSize = 0;
pane.totalItems = 0; -- total in bags for this item
pane.UINeedsUpdate = false;
pane.showWhich = ATR_SHOW_CURRENT;
pane.activeSearch = nil;
pane.sortedHist = nil;
pane.hints = nil;
pane.hlistScrollOffset = 0;
pane:ClearSearch();
return pane;
end
-----------------------------------------
function AtrPane:DoSearch (searchText, exact, rescanThreshold, callback)
self.currIndex = nil;
self.pickKey = nil;
self.histIndex = nil;
self.hintsIndex = nil;
self.sortedHist = nil;
self.hints = nil;
self.SS_hilite_itemName = searchText; -- by name for search summary
Atr_ClearBuyState();
self.activeScan = Atr_FindScan (nil);
Atr_ClearAll(); -- it's fast, might as well just do it now for cleaner UE
self.UINeedsUpdate = false; -- will be set when scan finishes
self.activeSearch = Atr_NewSearch (searchText, exact, rescanThreshold, callback);
if (exact) then
self.activeScan = self.activeSearch:GetFirstScan();
end
local cacheHit = false;
if (searchText ~= "") then
if (self.activeScan.whenScanned == 0) then -- check whenScanned so we don't rescan cache hits
self.activeSearch:Start();
else
self.UINeedsUpdate = true;
cacheHit = true;
end
end
return cacheHit;
end
-----------------------------------------
function AtrPane:ClearSearch ()
self:DoSearch ("", true);
end
-----------------------------------------
function AtrPane:GetProcessingState ()
if (self.activeSearch) then
return self.activeSearch.processing_state;
end
return KM_NULL_STATE;
end
-----------------------------------------
function AtrPane:IsScanEmpty ()
return (self.activeScan == nil or self.activeScan:IsNil());
end
-----------------------------------------
function AtrPane:ShowCurrent ()
return self.showWhich == ATR_SHOW_CURRENT;
end
-----------------------------------------
function AtrPane:ShowHistory ()
return self.showWhich == ATR_SHOW_HISTORY;
end
-----------------------------------------
function AtrPane:ShowHints ()
return self.showWhich == ATR_SHOW_HINTS;
end
-----------------------------------------
function AtrPane:SetToShowCurrent ()
self.showWhich = ATR_SHOW_CURRENT;
end
-----------------------------------------
function AtrPane:SetToShowHistory ()
self.showWhich = ATR_SHOW_HISTORY;
end
-----------------------------------------
function AtrPane:SetToShowHints ()
self.showWhich = ATR_SHOW_HINTS;
end
+117
View File
@@ -0,0 +1,117 @@
-----------------------------------------
AtrQuery = {};
AtrQuery.__index = AtrQuery;
-----------------------------------------
function Atr_NewQuery ()
local query = {};
setmetatable (query, AtrQuery);
query.prevPage = nil;
query.numDupPages = 0;
query.pagenum = -1;
return query;
end
-----------------------------------------
function AtrQuery:CheckForDuplicatePage (pagenum)
local numBatchAuctions = GetNumAuctionItems("list");
local thisPage = {};
thisPage.numOnPage = numBatchAuctions;
thisPage.items = {};
thisPage.pagenum = pagenum;
if (self.prevPage) then
-- zc.msg_atr ("Comparing page ", pagenum, " to pge ", self.prevPage.pagenum);
if (self.prevPage.pagenum == pagenum) then
return false;
end
end
if (numBatchAuctions == 0) then
self.prevPage = thisPage;
return false;
end
local x;
local prevPage = self.prevPage;
local dupPageFound = true;
local numDupItems = 0;
local allItemsIdentical = true;
for x = 1, numBatchAuctions do
local name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner = GetAuctionItemInfo("list", x);
thisPage.items[x] = self:BuildItemIDstr (name, count, minBid, buyoutPrice, bidAmount);
if (prevPage == nil or (thisPage.items[x] ~= prevPage.items[x])) then
dupPageFound = false;
else
numDupItems = numDupItems + 1;
end
if (x > 1 and allItemsIdentical and thisPage.items[x] ~= thisPage.items[x-1]) then -- handle those numnuts who post 200 identical auctions
allItemsIdentical = false;
end
end
if (prevPage ~= nil and prevPage.numOnPage ~= thisPage.numOnPage) then
-- zc.msg_pink ("page is unique - numauctions didn't match");
dupPageFound = false;
elseif (dupPageFound and allItemsIdentical) then
-- zc.msg_red ("Dup page found but all items identical: thisPage.numOnPage: ", thisPage.numOnPage);
dupPageFound = false;
elseif (not dupPageFound) then
-- zc.msg_pink ("page is unique");
end
if (dupPageFound) then
self.numDupPages = self.numDupPages + 1;
-- zc.msg_atr ("DUPLICATE PAGE FOUND: thisPage.numOnPage: ", thisPage.numOnPage, " numDupItems: ", numDupItems);
else
self.prevPage = thisPage;
end
return dupPageFound;
end
-----------------------------------------
function AtrQuery:IsLastPage (pagenum)
local _, totalAuctions = GetNumAuctionItems("list");
return (((pagenum + 1) * 50) >= totalAuctions);
end
-----------------------------------------
function AtrQuery:BuildItemIDstr(name, count, minBid, buyoutPrice, bidAmount)
if (name) then
return name.."_"..count.."_"..minBid.."_"..buyoutPrice.."_"..bidAmount;
end
return "";
end
+1374
View File
File diff suppressed because it is too large Load Diff
+510
View File
@@ -0,0 +1,510 @@
local addonName, addonTable = "Auctionator", AtrNS;
local zc = addonTable.zc;
-----------------------------------------
Atr_SList = {};
Atr_SList.__index = Atr_SList;
local SLITEMS_NUM_LINES = 15;
local gCurrentSList;
-----------------------------------------
function Atr_ShoppingListsInit ()
local num = getn(AUCTIONATOR_SHOPPING_LISTS);
local x;
for x = 1,num do
setmetatable (AUCTIONATOR_SHOPPING_LISTS[x], Atr_SList);
end
end
-----------------------------------------
function Atr_SList.create (name, isRecents)
local slist = {};
setmetatable (slist,Atr_SList);
slist.name = name;
slist.items = {};
if (isRecents) then
slist.isRecents = 1;
end
table.insert (AUCTIONATOR_SHOPPING_LISTS, slist);
table.sort (AUCTIONATOR_SHOPPING_LISTS, Atr_SortSlists);
return slist;
end
-----------------------------------------
function Atr_SortSlists (x, y)
if (x.isRecents) then return true; end;
if (y.isRecents) then return false; end;
return (string.lower(x.name) < string.lower(y.name));
end
-----------------------------------------
function Atr_SList:AddItem (itemName)
if (itemName == "" or itemName == nil) then
return;
end
if (self.isRecents) then
table.insert (self.items, 1, itemName);
while (getn(self.items) > 50) do -- max 50 items on recents list
table.remove (self.items);
end
else
table.insert (self.items, itemName);
self.isSorted = false;
end
end
-----------------------------------------
function Atr_SList:RemoveItem (itemName)
local num = getn(self.items);
local n;
for n = 1,num do
if (zc.StringSame (self.items[n], itemName)) then
table.remove (self.items, n);
return;
end
end
end
-----------------------------------------
function Atr_DisplaySlist ()
if (gCurrentSList) then
gCurrentSList:DisplayX ();
end
end
-----------------------------------------
function sortSlist (x, y)
return (string.lower(x) < string.lower(y));
end
-----------------------------------------
function Atr_SList:DisplayX ()
gCurrentSList = self;
local currentPane = Atr_GetCurrentPane();
if (not (self.isRecents or self.isSorted)) then
self.isSorted = true;
table.sort (self.items, sortSlist);
end
local numrows = getn(self.items);
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, SLITEMS_NUM_LINES, 16);
for line = 1,SLITEMS_NUM_LINES do
currentPane.hlistScrollOffset = FauxScrollFrame_GetOffset (Atr_Hlist_ScrollFrame);
dataOffset = line + currentPane.hlistScrollOffset;
local lineEntry = getglobal ("AuctionatorHEntry"..line);
lineEntry:SetID(dataOffset);
local slItem = self.items[dataOffset];
if (dataOffset <= numrows and slItem) then
local lineEntry_text = getglobal("AuctionatorHEntry"..line.."_EntryText");
lineEntry_text:SetText (Atr_AbbrevItemName (slItem));
lineEntry_text:SetTextColor (.6,.6,.6);
if (currentPane.activeSearch.origSearchText ~= "" and zc.StringSame (slItem , currentPane.activeSearch.origSearchText)) then
Atr_SetRowSelected (lineEntry, true);
elseif (currentPane.activeSearch.searchText == "" and zc.StringSame (slItem , Atr_Search_Box:GetText())) then
Atr_SetRowSelected (lineEntry, true);
else
Atr_SetRowSelected (lineEntry, false);
end
lineEntry:Show();
else
lineEntry:Hide();
end
end
end
-----------------------------------------
function Atr_SList:FindItemIndex (itemName)
local num = getn(self.items);
local n;
for n = 1,num do
if (zc.StringSame (itemName, self.items[n])) then
return n;
end
end
return 0;
end
-----------------------------------------
function Atr_SList:IsItemOnList (itemName)
return (self:FindItemIndex(itemName) > 0);
end
-----------------------------------------
function Atr_Search_Onclick ()
local currentPane = Atr_GetCurrentPane();
local searchText = Atr_Search_Box:GetText();
Atr_Search_Button:Disable();
Atr_Buy1_Button:Disable();
Atr_AddToSListButton:Disable();
Atr_RemFromSListButton:Disable();
Atr_ClearAll();
currentPane:DoSearch (searchText);
Atr_Process_Historydata ();
end
-----------------------------------------
function Atr_Shop_OnFinishScan ()
local currentPane = Atr_GetCurrentPane();
local searchText = currentPane.activeSearch.origSearchText;
Atr_Search_Box:SetText (searchText);
local recentsList = AUCTIONATOR_SHOPPING_LISTS[1];
if (recentsList) then
local isRecentsShown = (gCurrentSList == recentsList);
local n = recentsList:FindItemIndex(searchText);
if (n > 14 or (not isRecentsShown and n > 0)) then
table.remove (recentsList.items, n);
end
n = recentsList:FindItemIndex(searchText);
if (n == 0) then
recentsList:AddItem (searchText);
end
if (isRecentsShown) then
FauxScrollFrame_SetOffset (Atr_Hlist_ScrollFrame, 0);
end
end
if (getn(currentPane.activeScan.sortedData) > 0 and not currentPane.pickKey) then
currentPane.currIndex = 1;
end
currentPane.UINeedsUpdate = true;
Atr_Search_Button:Enable();
end
-----------------------------------------
function Atr_DropDownSL_OnLoad (self)
UIDropDownMenu_Initialize(self, Atr_DropDownSL_Initialize);
UIDropDownMenu_SetSelectedValue(Atr_DropDownSL, 1);
Atr_DropDownSL:Show();
end
-----------------------------------------
function Atr_DropDownSL_Initialize()
local info = UIDropDownMenu_CreateInfo();
local num = getn(AUCTIONATOR_SHOPPING_LISTS);
local x;
for x = 1,num do
local slist = AUCTIONATOR_SHOPPING_LISTS[x];
info.text = slist.name;
info.value = x;
info.func = Atr_DropDownSL_OnClick;
info.checked = nil;
info.owner = Atr_DropDownSL;
-- info.colorCode = nil;
-- if (slist.isRecents) then
-- info.colorCode = "|c00ffddaa";
-- end
UIDropDownMenu_AddButton(info);
end
end
-----------------------------------------
function Atr_DropDownSL_OnClick()
UIDropDownMenu_SetSelectedValue(this.owner, this.value);
gCurrentSList = AUCTIONATOR_SHOPPING_LISTS[this.value];
Atr_SetUINeedsUpdate();
end
-----------------------------------------
function Atr_SEntryOnClick ()
local line = this;
local entryIndex = line:GetID();
local itemName = gCurrentSList.items[entryIndex];
Atr_Search_Box:SetText (itemName);
if (IsAltKeyDown()) then
Atr_GetCurrentPane():ClearSearch();
Atr_RemFromSListOnClick();
else
Atr_Search_Onclick ();
end
Atr_Shop_UpdateUI();
-- gCurrentSList:DisplayX(); -- for the highlight
end
-----------------------------------------
local function FinishCreateNewSList(text)
local slist = Atr_SList.create(text);
local num = getn(AUCTIONATOR_SHOPPING_LISTS);
local n;
for n = 1,num do
if (AUCTIONATOR_SHOPPING_LISTS[n] == slist) then
UIDropDownMenu_SetSelectedValue(Atr_DropDownSL, n);
UIDropDownMenu_SetText (text, Atr_DropDownSL); -- needed to fix bug in UIDropDownMenu
slist:DisplayX();
Atr_SetUINeedsUpdate();
break;
end
end
end
-----------------------------------------
StaticPopupDialogs["ATR_NEW_SHOPPING_LIST"] = {
text = "",
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = 1,
maxLetters = 32,
OnAccept = function()
local text = getglobal(this:GetParent():GetName().."EditBox"):GetText();
FinishCreateNewSList (text);
end,
EditBoxOnEnterPressed = function()
local text = this:GetText();
FinishCreateNewSList (text);
this:GetParent():Hide();
end,
OnShow = function()
getglobal(this:GetName().."EditBox"):SetText("");
getglobal(this:GetName().."EditBox"):SetFocus();
end,
timeout = 0,
exclusive = 1,
whileDead = 1,
hideOnEscape = 1
};
-----------------------------------------
StaticPopupDialogs["ATR_DEL_SHOPPING_LIST"] = {
text = "",
button1 = YES,
button2 = NO,
OnAccept = function()
local x;
for x = 1,getn(AUCTIONATOR_SHOPPING_LISTS) do
if (AUCTIONATOR_SHOPPING_LISTS[x] == gCurrentSList) then
table.remove (AUCTIONATOR_SHOPPING_LISTS, x);
gCurrentSList = AUCTIONATOR_SHOPPING_LISTS[1];
UIDropDownMenu_SetSelectedValue(Atr_DropDownSL, 1);
UIDropDownMenu_SetText (gCurrentSList.name, Atr_DropDownSL);
Atr_SetUINeedsUpdate();
return;
end
end
end,
OnShow = function()
local s = string.format (ZT("Really delete the shopping list %s ?"), ": \n\n"..gCurrentSList.name);
getglobal(this:GetName().."Text"):SetText("\n"..s.."\n\n");
end,
timeout = 0,
exclusive = 1,
whileDead = 1,
hideOnEscape = 1
};
-----------------------------------------
function Atr_NewSlist_OnClick ()
StaticPopupDialogs["ATR_NEW_SHOPPING_LIST"].text = ZT("Name for your new shopping list");
StaticPopup_Show("ATR_NEW_SHOPPING_LIST");
end
-----------------------------------------
function Atr_DelSList_OnClick ()
StaticPopup_Show("ATR_DEL_SHOPPING_LIST");
end
-----------------------------------------
function Atr_AddToSListOnClick ()
local currentPane = Atr_GetCurrentPane();
if (gCurrentSList) then
if (getn(gCurrentSList.items) >= 50) then
Atr_Error_Text:SetText (string.format (ZT("You may have no more than\n\n%d items on a shopping list."), 50));
Atr_Error_Frame.withMask = 1;
Atr_Error_Frame:Show ();
else
gCurrentSList:AddItem (Atr_Search_Box:GetText());
Atr_SetUINeedsUpdate();
end
end
end
-----------------------------------------
function Atr_RemFromSListOnClick ()
local currentPane = Atr_GetCurrentPane();
if (gCurrentSList) then
gCurrentSList:RemoveItem (Atr_Search_Box:GetText());
Atr_SetUINeedsUpdate();
end
end
-----------------------------------------
function Atr_Shop_UpdateUI ()
local currentPane = Atr_GetCurrentPane();
Atr_AddToSListButton:Disable();
Atr_RemFromSListButton:Disable();
Atr_DelSListButton:Disable();
if (gCurrentSList == nil) then
gCurrentSList = AUCTIONATOR_SHOPPING_LISTS[1];
end
if (gCurrentSList) then
gCurrentSList:DisplayX ();
local iName = Atr_Search_Box:GetText();
if (gCurrentSList:IsItemOnList (iName)) then
Atr_RemFromSListButton:Enable();
elseif (iName ~= "" and iName ~= nil and gCurrentSList ~= AUCTIONATOR_SHOPPING_LISTS[1]) then -- hack
Atr_AddToSListButton:Enable();
end
if (gCurrentSList ~= AUCTIONATOR_SHOPPING_LISTS[1]) then
Atr_DelSListButton:Enable();
end
end
if (currentPane.activeSearch:NumScans() > 1 and not currentPane:IsScanEmpty()) then
Atr_Back_Button:Show();
else
Atr_Back_Button:Hide();
end
end
File diff suppressed because one or more lines are too long