Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Classes/DropDownControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local m_min = math.min
local m_max = math.max
local m_floor = math.floor

local DropDownClass = newClass("DropDownControl", "Control", "ControlHost", "TooltipHost", "SearchHost", function(self, anchor, rect, list, selFunc, tooltipText)
local DropDownClass = newClass("DropDownControl", "Control", "ControlHost", "TooltipHost", "SearchHost", function(self, anchor, rect, list, selFunc, tooltipText, ignoreSearchOrder)
self.Control(anchor, rect)
self.ControlHost()
self.TooltipHost(tooltipText)
Expand All @@ -28,7 +28,8 @@ local DropDownClass = newClass("DropDownControl", "Control", "ControlHost", "Too
end
end
return StripEscapes(listVal)
end
end,
ignoreSearchOrder
)
self.controls.scrollBar = new("ScrollBarControl", {"TOPRIGHT",self,"TOPRIGHT"}, {-1, 0, 18, 0}, (self.height - 4) * 4)
self.controls.scrollBar.height = function()
Expand Down Expand Up @@ -111,13 +112,14 @@ function DropDownClass:DrawSearchHighlights(label, searchInfo, x, y, width, heig
local endX = 0
local last = 0
SetDrawColor(1, 1, 0, 0.2)
local strippedLabel = StripEscapes(label)
for _, range in ipairs(searchInfo.ranges) do
if range.from - last - 1 > 0 then
startX = DrawStringWidth(height, "VAR", label:sub(last + 1, range.from - 1)) + x + endX
startX = DrawStringWidth(height, "VAR", strippedLabel:sub(last + 1, range.from - 1)) + x + endX
else
startX = endX
end
endX = DrawStringWidth(height, "VAR", label:sub(range.from, range.to)) + x + startX
endX = DrawStringWidth(height, "VAR", strippedLabel:sub(range.from, range.to)) + x + startX
last = range.to

DrawImage(nil, startX, y, endX - startX, height)
Expand Down
32 changes: 26 additions & 6 deletions src/Classes/SearchHost.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
-- Search host
--

local SearchHostClass = newClass("SearchHost", function(self, listAccessor, valueAccessor)
local SearchHostClass = newClass("SearchHost", function(self, listAccessor, valueAccessor, ignoreOrder)
self.searchListAccessor = listAccessor
self.valueAccessor = valueAccessor
self.searchTerm = ""
self.searchInfos = {}
self.ignoreOrder = ignoreOrder or false
end)

local function splitWords(s)
Expand All @@ -34,7 +35,7 @@ local function wordsToCaselessPatterns(words)
return patterns
end

local function matchWords(searchWords, entry, valueAccessor)
local function matchWords(searchWords, entry, valueAccessor, ignoreOrder)
local value = valueAccessor and valueAccessor(entry) or entry
local searchInfo = { ranges = {}, matches = true }
local lastMatchEnd = 0
Expand All @@ -43,24 +44,43 @@ local function matchWords(searchWords, entry, valueAccessor)
if (from) then
local range = { from = from, to = to }
table.insert(searchInfo.ranges, range)
lastMatchEnd = to
if not ignoreOrder then
lastMatchEnd = to
end
else
-- at least one search word did not match at least once (respecting order)
searchInfo.matches = false
end
end
if ignoreOrder then
-- sort to be in left to right order
table.sort(searchInfo.ranges, function(a, b)
return a.from < b.from
end)
-- merge overlapping ranges
local i = 1
while searchInfo.ranges[i] do
local this = searchInfo.ranges[i]
local next = searchInfo.ranges[i + 1]
if next and next.from <= this.to then
this.to = next.to
table.remove(searchInfo.ranges, i + 1)
end
i = i + 1
end
end
return searchInfo
end

local function matchTerm(searchTerm, list, valueAccessor)
local function matchTerm(searchTerm, list, valueAccessor, ignoreOrder)
if not searchTerm or searchTerm == "" or not list then
return {}
end

local searchInfos = {}
local searchPatterns = wordsToCaselessPatterns(splitWords(searchTerm))
for idx, entry in ipairs(list) do
searchInfos[idx] = matchWords(searchPatterns, entry, valueAccessor)
searchInfos[idx] = matchWords(searchPatterns, entry, valueAccessor, ignoreOrder)
end
return searchInfos
end
Expand Down Expand Up @@ -110,7 +130,7 @@ end

function SearchHostClass:UpdateSearch()
if self.searchListAccessor then
self.searchInfos = matchTerm(self.searchTerm, self.searchListAccessor(), self.valueAccessor)
self.searchInfos = matchTerm(self.searchTerm, self.searchListAccessor(), self.valueAccessor, self.ignoreOrder)
self:UpdateMatchCount()
end
end
Expand Down
35 changes: 0 additions & 35 deletions src/Classes/TradeHelpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,6 @@ end

local _optionTradeStatMap

-- These option stats are still needed for legacy items, but are no longer
-- included in the trade API's 3.29 stats response.
local legacyOptionTradeStats = {
{
type = "explicit",
id = "explicit.stat_2878779644",
text = "Grants Level 20 Summon Bestial # Skill",
options = {
{ id = 1, text = "rhoa" },
{ id = 2, text = "ursa" },
{ id = 3, text = "snake" },
},
},
{
type = "explicit",
id = "explicit.stat_3642528642",
text = "Only affects Passives in # Ring",
options = {
{ id = 1, text = "small" },
{ id = 2, text = "medium" },
{ id = 3, text = "large" },
{ id = 4, text = "very large" },
{ id = 5, text = "massive" },
},
},
}

---@param tradeStats table table of data from https://www.pathofexile.com/api/trade2/data/stats
---@return table optionTradeStatMap table containing helper data for matching trade option filters
local function getOptionTradeStatMap(tradeStats)
Expand Down Expand Up @@ -139,14 +112,6 @@ local function getOptionTradeStatMap(tradeStats)
end
end
end
for _, entry in ipairs(legacyOptionTradeStats) do
local matchKey = entry.text:gsub("#", "(.*)"):lower()
optionTradeStatMap.patterns[matchKey] = optionTradeStatMap.patterns[matchKey] or {
type = entry.type,
options = entry.options,
tradeId = entry.id,
}
end

_optionTradeStatMap = optionTradeStatMap
return _optionTradeStatMap
Expand Down
22 changes: 21 additions & 1 deletion src/Classes/TradeQueryGenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ local function getStatEntries(modType)
["Rune"] = "rune",
["HeartOfTheWell"] = "explicit",
["AgainstTheDarkness"] = "explicit",
["pseudo"] = "pseudo",
}
if tradeStatCategoryIndices[modType] then
for _, cat in ipairs(tradeStats) do
Expand Down Expand Up @@ -1389,6 +1390,25 @@ Remove: %s will be removed from the search results.]], term, term, term)
end
end
end
local pseudoStats = getStatEntries("pseudo")
-- map stats and such which are clearly not relevant here
local ignoredStats = {
"^pseudo.lake",
"^pseudo.pseudo_lake",
"^pseudo.pseudo_logbook",
"^pseudo.pseudo_temple",
"^pseudo.pseudo_map",
"^pseudo.pseudo_ritual",
}
for _, entry in ipairs(pseudoStats or {}) do
for _, ignored in ipairs(ignoredStats) do
if entry.id:find(ignored) then
goto pseudoContinue
end
end
t_insert(mods, { label = s_format("^7%s (Pseudo)", entry.text), tradeId = entry.id })
::pseudoContinue::
end
return mods
end
-- amount of mod selectors: technically we could have 40, but the more we have the fewer
Expand Down Expand Up @@ -1430,7 +1450,7 @@ Remove: %s will be removed from the search results.]], term, term, term)
selectedMods[i] = copyTable(val)
end
setModSelectors(controls)
end)
end, nil, true)
dropdown.shown = function()
return not not selectedMods[i - 1] or i == 1
end
Expand Down
Loading
Loading