diff --git a/spec/System/TestTradeQueryGenerator_spec.lua b/spec/System/TestTradeQueryGenerator_spec.lua index 4f3c035b5eb..f1bb2f2308a 100644 --- a/spec/System/TestTradeQueryGenerator_spec.lua +++ b/spec/System/TestTradeQueryGenerator_spec.lua @@ -58,6 +58,38 @@ describe("TradeQueryGenerator", function() end) end) + describe("Query options", function() + it("uses remembered links in the next filter for the same slot", function() + local queryGen = new("TradeQueryGenerator"):TradeQueryGenerator({ itemsTab = { items = { } } }) + + local function runQuery(slotName, links) + local requestedOptions + queryGen.StartQuery = function(_, _, options) + requestedOptions = options + end + local context = { + slotTbl = { slotName = slotName, alreadyCorrupted = false }, + controls = { tradeTypeSelection = { selIndex = 1 } }, + } + queryGen:RequestQuery({ slotName = slotName }, context, { }, function() end) + if links ~= nil then + main.popups[1].controls.links:SetText(links) + end + main.popups[1].controls.generateQuery:Click() + return requestedOptions.links + end + + assert.are.equal(6, runQuery("Body Armour", "6")) + assert.are.equal(6, runQuery("Body Armour")) + assert.is_nil(runQuery("Helmet")) + assert.is_nil(runQuery("Body Armour", "")) + assert.is_nil(runQuery("Body Armour")) + assert.are.equal(6, runQuery("Body Armour", "6")) + assert.are.equal(0, runQuery("Body Armour", "0")) + assert.is_nil(runQuery("Body Armour")) + end) + end) + describe("WeightedRatioOutputs", function() local maxStatIncrease diff --git a/src/Classes/TradeQueryGenerator.lua b/src/Classes/TradeQueryGenerator.lua index 097a2e7f948..29c6a3afea6 100644 --- a/src/Classes/TradeQueryGenerator.lua +++ b/src/Classes/TradeQueryGenerator.lua @@ -158,6 +158,7 @@ function TradeQueryGeneratorClass:TradeQueryGenerator(queryTab) self.lastMaxPrice = nil self.lastMaxPriceTypeIndex = nil self.lastMaxLevel = nil + self.lastLinksBySlot = { } return self end @@ -1329,6 +1330,8 @@ Remove: %s will be removed from the search results.]], term, term, term) if not slot.slotName:find("Belt") and not slot.slotName:find("Ring") and not slot.slotName:find("Amulet") then controls.links = new("EditControl"):EditControl({"TOPLEFT",lastItemAnchor,"BOTTOMLEFT"}, {0, 5, 70, 18}, nil, nil, "%D") + local lastLinks = self.lastLinksBySlot[slot.slotName] + controls.links.buf = lastLinks and tostring(lastLinks) or "" controls.linksLabel = new("LabelControl"):LabelControl({"RIGHT",controls.links,"LEFT"}, {-5, 0, 0, 16}, "^7# of Links:") updateLastAnchor(controls.links) end @@ -1407,8 +1410,9 @@ Remove: %s will be removed from the search results.]], term, term, term) options.sockets = tonumber(controls.sockets.buf) self.lastSockets = options.sockets end - if controls.links and controls.links.buf then + if controls.links then options.links = tonumber(controls.links.buf) + self.lastLinksBySlot[slot.slotName] = options.links and options.links > 0 and options.links or nil end if controls.includeAllWEMods then options.includeAllWEMods = controls.includeAllWEMods.state