diff --git a/spec/System/TestTradeHelpers_spec.lua b/spec/System/TestTradeHelpers_spec.lua index 3120b01f18..f77b46ffab 100644 --- a/spec/System/TestTradeHelpers_spec.lua +++ b/spec/System/TestTradeHelpers_spec.lua @@ -109,4 +109,21 @@ describe("TradeHelpers trade hash matching", function() assert.equal(7, value) end) end) + describe("findTradeIdOption", function() + it("matches a '#'-valued option and returns its value", function() + local tradeId, value = tradeHelpers.findTradeIdOption("+2 to Level of all Arc Skills", "explicit") + assert.equal("explicit.stat_448592698|98", tradeId) + assert.equal(2, value) + end) + + it("matches an exact-text option and returns no value", function() + local tradeId, value = tradeHelpers.findTradeIdOption("Allocates Abasement", "enchant") + assert.equal("enchant.stat_2954116742|7338", tradeId) + assert.is_nil(value) + end) + + it("returns nil for an unmatchable line", function() + assert.is_nil(tradeHelpers.findTradeIdOption("+100 to IQ", "explicit")) + end) + end) end) diff --git a/src/Classes/CompareBuySimilar.lua b/src/Classes/CompareBuySimilar.lua index dc89d428d9..cc854dbad3 100644 --- a/src/Classes/CompareBuySimilar.lua +++ b/src/Classes/CompareBuySimilar.lua @@ -333,6 +333,7 @@ function M.openPopup(item, slotName, primaryBuild) -- Helper to fetch and populate leagues for a given realm API id local function fetchLeaguesForRealm(realmApiId) + local lastIdx = M.lastLeagueIdx controls.leagueDrop:SetList({"Loading..."}) controls.leagueDrop.selIndex = 1 tradeQueryRequests:FetchLeagues(realmApiId, function(leagues, errMsg) @@ -362,39 +363,51 @@ function M.openPopup(item, slotName, primaryBuild) break end end + if lastIdx then + controls.leagueDrop:SetSel(lastIdx) + end end) end + local function rebuildUrl() + local result = buildURL(item, slotName, controls, modEntries, defenceEntries, isUnique) + uri = result + end -- Realm dropdown controls.realmLabel = new("LabelControl", {"TOPLEFT", nil, "TOPLEFT"}, {leftMargin, ctrlY, 0, 16}, "^7Realm:") controls.realmDrop = new("DropDownControl", {"LEFT", controls.realmLabel, "RIGHT"}, {4, 0, 80, 20}, {"PoE2"}, function(index, value) local realmApiId = REALM_API_IDS[value] or "poe2" fetchLeaguesForRealm(realmApiId) + rebuildUrl() + M.lastLeagueIdx = index end) + if M.lastRealmIdx then + controls.realmDrop:SetSel(M.lastRealmIdx, true) + end controls.realmDrop.disabled = true -- League dropdown controls.leagueLabel = new("LabelControl", {"LEFT", controls.realmDrop, "RIGHT"}, {12, 0, 0, 16}, "^7League:") controls.leagueDrop = new("DropDownControl", {"LEFT", controls.leagueLabel, "RIGHT"}, {4, 0, 160, 20}, {"Loading..."}, function(index, value) -- League selection stored in the dropdown itself + M.lastLeagueIdx = index end) controls.leagueDrop.enabled = function() return #controls.leagueDrop.list > 0 and controls.leagueDrop.list[1] ~= "Loading..." end -- Listed status dropdown controls.listedDrop = new("DropDownControl", {"TOPRIGHT", nil, "TOPRIGHT"}, {-leftMargin, ctrlY, 242, 20}, LISTED_STATUS_LABELS, function(index, value) -- Listed status selection stored in the dropdown itself + M.lastListedIndex = index end) + if M.lastListedIndex then + controls.listedDrop:SetSel(M.lastListedIndex, true) + end controls.listedLabel = new("LabelControl", {"RIGHT", controls.listedDrop, "LEFT"}, {-4, 0, 0, 16}, "^7Listed:") -- Fetch initial leagues for default realm fetchLeaguesForRealm("poe2") ctrlY = ctrlY + rowHeight + 4 - local function rebuildUrl() - local result = buildURL(item, slotName, controls, modEntries, defenceEntries, isUnique) - uri = result - end - if isUnique then -- Unique item name label @@ -483,8 +496,8 @@ function M.openPopup(item, slotName, primaryBuild) -- when the trade site has a dropdown for the value, we opt to disable -- the inputs as they are numeric if not (entry.isOption or entry.needsExactValue) and entry.value then - controls[prefix .. "Min"] = tradeHelpers.newPlainNumericEdit(nil, { minFieldX - popupWidth / 2, controlYPos, fieldW, fieldH }, entry.value ~= 0 and tostring(entry.value) or "", "Min", 8, rebuildUrl) - controls[prefix .. "Max"] = tradeHelpers.newPlainNumericEdit(nil, { maxFieldX - popupWidth / 2, controlYPos, fieldW, fieldH }, "", "Max", 8, rebuildUrl) + controls[prefix .. "Min"] = tradeHelpers.newPlainNumericEdit(nil, { minFieldX - popupWidth / 2, controlYPos, fieldW, fieldH }, entry.value ~= 0 and tostring(entry.value) or "", "Min", 8, nil, rebuildUrl) + controls[prefix .. "Max"] = tradeHelpers.newPlainNumericEdit(nil, { maxFieldX - popupWidth / 2, controlYPos, fieldW, fieldH }, "", "Max", 8, nil, rebuildUrl) if not canSearch then controls[prefix .. "Min"].enabled = function() return false end controls[prefix .. "Max"].enabled = function() return false end diff --git a/src/Modules/ItemSlotHelper.lua b/src/Modules/ItemSlotHelper.lua index c93d779904..4d9524c9ea 100644 --- a/src/Modules/ItemSlotHelper.lua +++ b/src/Modules/ItemSlotHelper.lua @@ -8,6 +8,8 @@ local M = {} ---@param w integer ---@param h integer function M.DrawViewer(itemsTab, nodeId, x, y, w, h) + local node = itemsTab.build.spec.nodes[nodeId] + if not node then return end SetDrawLayer(nil, 15) SetDrawColor(1, 1, 1) @@ -15,8 +17,6 @@ function M.DrawViewer(itemsTab, nodeId, x, y, w, h) DrawImage(nil, x, y, w + 2 * borderWidth, h + 2 * borderWidth) local viewer = itemsTab.socketViewer - local node = itemsTab.build.spec.nodes[nodeId] - viewer.zoom = 17 local viewPortSize = math.min(w, h)