Skip to content

Commit 688f277

Browse files
committed
add button to find exact search result for trade tool
1 parent 07429bf commit 688f277

3 files changed

Lines changed: 54 additions & 18 deletions

File tree

src/Classes/TradeQuery.lua

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ on trade site to work on other leagues and realms)]]
283283
"Instant buyout and in person",
284284
"In person (online in league)",
285285
"In person (online)",
286-
"Any",
287286
}
288287

289288
self.controls.tradeTypeSelection = new("DropDownControl", { "TOPLEFT", self.controls.poesessidButton, "BOTTOMLEFT" },
@@ -942,6 +941,7 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
942941
return
943942
end
944943
context.controls["priceButton"..context.row_idx].label = "Searching..."
944+
self.lastQuery = query
945945
self.tradeQueryRequests:SearchWithQueryWeightAdjusted(self.pbRealm, self.pbLeague, query,
946946
function(items, errMsg)
947947
if errMsg then
@@ -1105,8 +1105,6 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
11051105
local firstValidSlot = self:findValidSlotForWatchersEye()
11061106
local currentItem = firstValidSlot.selItemId ~= 0 and self.itemsTab.items[firstValidSlot.selItemId]
11071107
local eyeEquipped = currentItem and currentItem.name:find("Watcher's Eye")
1108-
-- for watcher's eye we can compare to an already existing one, or
1109-
-- default to comparing with all active sockets
11101108
self.itemsTab:AddItemTooltip(tooltip, item, eyeEquipped and firstValidSlot or nil, true)
11111109
else
11121110
self.itemsTab:AddItemTooltip(tooltip, item, slotTbl, true)
@@ -1118,23 +1116,53 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
11181116
return self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]].item_string ~= nil
11191117
end
11201118
-- Whisper so we can copy to clipboard
1121-
controls["whisperButton"..row_idx] = new("ButtonControl", { "TOPLEFT", controls["importButton"..row_idx], "TOPRIGHT"}, {8, 0, 185, row_height}, function()
1122-
return self.totalPrice[row_idx] and "Whisper for " .. self.totalPrice[row_idx].amount .. " " .. self.totalPrice[row_idx].currency or "Whisper"
1123-
end, function()
1124-
Copy(self.resultTbl[row_idx][self.itemIndexTbl[row_idx]].whisper)
1125-
end)
1126-
controls["whisperButton"..row_idx].enabled = function()
1127-
return self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]].whisper ~= nil
1128-
end
1129-
controls["whisperButton"..row_idx].tooltipFunc = function(tooltip)
1119+
controls["whisperButton" .. row_idx] = new("ButtonControl",
1120+
{ "TOPLEFT", controls["importButton" .. row_idx], "TOPRIGHT" }, { 8, 0, 185, row_height }, function()
1121+
local itemResult = self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]]
1122+
1123+
if not itemResult then return "" end
1124+
1125+
local price = self.totalPrice[row_idx] and
1126+
self.totalPrice[row_idx].amount .. " " .. self.totalPrice[row_idx].currency
1127+
1128+
if itemResult.whisper then
1129+
return price and "Whisper for " .. price or "Whisper"
1130+
else
1131+
return price and "Search for selected item"
1132+
end
1133+
1134+
end, function()
1135+
local itemResult = self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]]
1136+
if itemResult.whisper then
1137+
Copy(itemResult.whisper)
1138+
else
1139+
local exactQuery = dkjson.decode(self.lastQuery)
1140+
-- use trade sum to get the specific item. we could also add the
1141+
-- trader name as it is contained in the fetch responses, but
1142+
-- this alone doesn't seem to really result in multiple results.
1143+
-- trade weight min is exclusive while max is inclusive (makes no sense to me)
1144+
exactQuery.query.stats[1].value = { min = tonumber(itemResult.weight) - 0.1, max = tonumber(itemResult.weight) }
1145+
1146+
local exactQueryStr = dkjson.encode(exactQuery)
1147+
1148+
self.tradeQueryRequests:SearchWithQuery(self.pbRealm, self.pbLeague, exactQueryStr, function(_, _)
1149+
end, {callbackQueryId = function(queryId)
1150+
local url = self.hostName.."trade/search/"..self.pbLeague.."/"..queryId
1151+
Copy(url)
1152+
OpenURL(url)
1153+
end})
1154+
end
1155+
end)
1156+
1157+
controls["whisperButton" .. row_idx].tooltipFunc = function(tooltip)
11301158
tooltip:Clear()
1131-
if self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]].item_string then
1132-
tooltip.center = true
1133-
tooltip:AddLine(16, "Copies the item purchase whisper to the clipboard")
1134-
end
1159+
tooltip.center = true
1160+
local itemResult = self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]]
1161+
local text = itemResult.whisper and "Copies the item purchase whisper to the clipboard" or
1162+
"Opens the search page to show the item"
1163+
tooltip:AddLine(16, text)
11351164
end
11361165
end
1137-
11381166
-- Method to update the Total Price string sum of all items
11391167
function TradeQueryClass:GetTotalPriceString()
11401168
local text = ""

src/Classes/TradeQueryGenerator.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,6 @@ function TradeQueryGeneratorClass:FinishQuery()
10101010
"available",
10111011
"onlineleague",
10121012
"online",
1013-
"any",
10141013
}
10151014
local selectedTradeType = self.tradeTypes[self.tradeTypeIndex]
10161015
-- Generate trade query str and open in browser
@@ -1113,6 +1112,10 @@ function TradeQueryGeneratorClass:FinishQuery()
11131112
}
11141113
end
11151114

1115+
if options.account then
1116+
queryTable.query.filters.trade_filters.filters.account = {input = options.account}
1117+
end
1118+
11161119
if options.maxLevel and options.maxLevel > 0 then
11171120
queryTable.query.filters.req_filters = {
11181121
disabled = false,

src/Classes/TradeQueryRequests.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ function TradeQueryRequestsClass:FetchResultBlock(url, callback)
285285
table.insert(items, {
286286
amount = trade_entry.listing.price.amount,
287287
currency = trade_entry.listing.price.currency,
288+
-- note: using these to travel to the hideout or for a
289+
-- direct whisper is not allowed, even if they are provided
290+
-- right here
291+
-- hideout_token = trade_entry.listing.hideout_token,
292+
-- whisper_token = trade_entry.listing.whisper_token,
288293
item_string = common.base64.decode(trade_entry.item.extended.text),
289294
whisper = trade_entry.listing.whisper,
290295
weight = trade_entry.item.pseudoMods and trade_entry.item.pseudoMods[1]:match("Sum: (.+)") or "0",

0 commit comments

Comments
 (0)