From 7057ec36a9ebb01af6a00b1d2779381680b5a452 Mon Sep 17 00:00:00 2001 From: wormingdead Date: Mon, 27 Jan 2020 13:36:12 -0800 Subject: [PATCH 1/9] Update search cache after search completes instead of before --- Classes/PassiveTreeView.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index 70347a39a..a1da23107 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -344,10 +344,10 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents) -- Update cached node data if self.searchStrCached ~= self.searchStr then - self.searchStrCached = self.searchStr for nodeId, node in pairs(spec.nodes) do self.searchStrResults[nodeId] = #self.searchStr > 0 and self:DoesNodeMatchSearchStr(node) end + self.searchStrCached = self.searchStr end -- Draw the nodes From b7a58084a5f285082993d27c826c0ff6444b03ff Mon Sep 17 00:00:00 2001 From: wormingdead Date: Mon, 27 Jan 2020 15:28:36 -0800 Subject: [PATCH 2/9] Add search result colormap, search term limit, and search term sentinal character to class --- Classes/PassiveTreeView.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index a1da23107..b74486874 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -28,6 +28,20 @@ local PassiveTreeViewClass = newClass("PassiveTreeView", function(self) self.searchStr = "" self.searchStrCached = "" self.searchStrResults = {} + self.searchResultColormap = { + -- Color list generated from Google's FOSS colormap, 'Turbo': + {r = 0.941, g = 0.356, b = 0.070}, + {r = 0.996, g = 0.643, b = 0.192}, + {r = 0.883, g = 0.866, b = 0.217}, + {r = 0.644, g = 0.990, b = 0.234}, + {r = 0.276, g = 0.971, b = 0.517}, + {r = 0.098, g = 0.837, b = 0.803}, + {r = 0.244, g = 0.609, b = 0.997}, + {r = 0.270, g = 0.349, b = 0.796}, + } + self.searchTermsLimit = #self.searchResultColormap + self.searchTermSentinal = "|" + self.showStatDifferences = true end) From f5b5c80d4a8d8d1584878c027e8a9e57eb9a06e5 Mon Sep 17 00:00:00 2001 From: wormingdead Date: Mon, 27 Jan 2020 15:29:32 -0800 Subject: [PATCH 3/9] Reword comment --- Classes/PassiveTreeView.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index b74486874..2b2c7fa19 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -356,7 +356,7 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents) build.calcsTab:BuildPower() end - -- Update cached node data + -- Update cached node search data if self.searchStrCached ~= self.searchStr then for nodeId, node in pairs(spec.nodes) do self.searchStrResults[nodeId] = #self.searchStr > 0 and self:DoesNodeMatchSearchStr(node) From c00723f9a83e558729bc23d7691dff7775232d8c Mon Sep 17 00:00:00 2001 From: wormingdead Date: Mon, 27 Jan 2020 15:47:39 -0800 Subject: [PATCH 4/9] Move search cache updating to a function --- Classes/PassiveTreeView.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index 2b2c7fa19..e28ed88f9 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -358,9 +358,7 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents) -- Update cached node search data if self.searchStrCached ~= self.searchStr then - for nodeId, node in pairs(spec.nodes) do - self.searchStrResults[nodeId] = #self.searchStr > 0 and self:DoesNodeMatchSearchStr(node) - end + self:UpdateSearchCache(spec.nodes) self.searchStrCached = self.searchStr end @@ -560,6 +558,13 @@ function PassiveTreeViewClass:Zoom(level, viewPort) self.zoomY = relY + (self.zoomY - relY) * factor end +-- Parse searchStr and update searchStrResults cache +function PassiveTreeViewClass:UpdateSearchCache(nodes) + for nodeId, node in pairs(nodes) do + self.searchStrResults[nodeId] = #self.searchStr > 0 and self:DoesNodeMatchSearchStr(node) + end +end + function PassiveTreeViewClass:DoesNodeMatchSearchStr(node) if node.type == "ClassStart" or node.type == "Mastery" then return From 83b3c3113c56ed2a318383dd3902c5e1fecbd0c1 Mon Sep 17 00:00:00 2001 From: wormingdead Date: Mon, 27 Jan 2020 15:56:04 -0800 Subject: [PATCH 5/9] Fix search term being case-sensitive --- Classes/PassiveTreeView.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index e28ed88f9..7604af892 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -586,7 +586,7 @@ function PassiveTreeViewClass:DoesNodeMatchSearchStr(node) if not match and node.mods[index].list then -- Then check modifiers for _, mod in ipairs(node.mods[index].list) do - errMsg, match = PCall(string.match, mod.name, self.searchStr) + errMsg, match = PCall(string.match, mod.name:lower(), self.searchStr:lower()) if match then return true end From a1a8949cf901bf9e8f77c80a838f61bb4ba54202 Mon Sep 17 00:00:00 2001 From: wormingdead Date: Mon, 27 Jan 2020 15:59:26 -0800 Subject: [PATCH 6/9] Refactor DoesNodeMatchSearchStr() to take a search term --- Classes/PassiveTreeView.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index 7604af892..5cc61f2b9 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -565,13 +565,13 @@ function PassiveTreeViewClass:UpdateSearchCache(nodes) end end -function PassiveTreeViewClass:DoesNodeMatchSearchStr(node) +function PassiveTreeViewClass:DoesNodeMatchSearchStr(searchTerm, node) if node.type == "ClassStart" or node.type == "Mastery" then return end -- Check node name - local errMsg, match = PCall(string.match, node.dn:lower(), self.searchStr:lower()) + local errMsg, match = PCall(string.match, node.dn:lower(), searchTerm:lower()) if match then return true end @@ -579,14 +579,14 @@ function PassiveTreeViewClass:DoesNodeMatchSearchStr(node) -- Check node description for index, line in ipairs(node.sd) do -- Check display text first - errMsg, match = PCall(string.match, line:lower(), self.searchStr:lower()) + errMsg, match = PCall(string.match, line:lower(), searchTerm:lower()) if match then return true end if not match and node.mods[index].list then -- Then check modifiers for _, mod in ipairs(node.mods[index].list) do - errMsg, match = PCall(string.match, mod.name:lower(), self.searchStr:lower()) + errMsg, match = PCall(string.match, mod.name:lower(), searchTerm:lower()) if match then return true end @@ -595,7 +595,7 @@ function PassiveTreeViewClass:DoesNodeMatchSearchStr(node) end -- Check node type - local errMsg, match = PCall(string.match, node.type:lower(), self.searchStr:lower()) + local errMsg, match = PCall(string.match, node.type:lower(), searchTerm:lower()) if match then return true end From f544b46f82f42eec5a511c1359da97b1095d6df1 Mon Sep 17 00:00:00 2001 From: wormingdead Date: Tue, 28 Jan 2020 14:53:53 -0800 Subject: [PATCH 7/9] Allow searching for multiple terms Split searchStr on searchTermSentinal. Change searchStrResults to a bitmap table. Draw a circle for each successful search term. Color highlight circles with searchResultColormap. Require luabit for access to bitwise functions --- Classes/PassiveTreeView.lua | 43 +++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index 5cc61f2b9..31d069db1 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -4,6 +4,9 @@ -- Passive skill tree viewer. -- Draws the passive skill tree, and also maintains the current view settings (zoom level, position, etc) -- + +local bit = require("bit") + local pairs = pairs local ipairs = ipairs local t_insert = table.insert @@ -477,13 +480,22 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents) self:DrawAsset(tree.assets[overlay], scrX, scrY, scale) SetDrawColor(1, 1, 1) end - if self.searchStrResults[nodeId] then - -- Node matches the search string, show the highlight circle - SetDrawLayer(nil, 30) - SetDrawColor(1, 0, 0) - local size = 175 * scale / self.zoom ^ 0.4 - DrawImage(self.highlightRing, scrX - size, scrY - size, size * 2, size * 2) + if self.searchStrResults[nodeId] and self.searchStrResults[nodeId] ~= 0 then + for searchIndex=1,self.searchTermsLimit do + -- minus one to convert from one-based counting to zero-based + if bit.band(self.searchStrResults[nodeId], (2 ^ (searchIndex - 1))) ~= 0 then + SetDrawLayer(nil, 30 + searchIndex) + SetDrawColor( + self.searchResultColormap[searchIndex].r, + self.searchResultColormap[searchIndex].g, + self.searchResultColormap[searchIndex].b + ) + local size = (175 + 5 * (searchIndex - 1)) * scale / self.zoom ^ 0.4 + DrawImage(self.highlightRing, scrX - size, scrY - size, size * 2, size * 2) + end + end end + if node == hoverNode and (node.type ~= "Socket" or not IsKeyDown("SHIFT")) and not main.popups[1] then -- Draw tooltip SetDrawLayer(nil, 100) @@ -560,8 +572,25 @@ end -- Parse searchStr and update searchStrResults cache function PassiveTreeViewClass:UpdateSearchCache(nodes) + local searchTerms = {} + -- split searchStr on searchTermSentinal + local i = 1 + for term in string.gmatch(self.searchStr, "[^"..self.searchTermSentinal.."]+") do + searchTerms[i] = term + i = i + 1 + end + for nodeId, node in pairs(nodes) do - self.searchStrResults[nodeId] = #self.searchStr > 0 and self:DoesNodeMatchSearchStr(node) + local resultBitmap = 0 + + for termIndex=1,self.searchTermsLimit do + if searchTerms[termIndex] and self:DoesNodeMatchSearchStr(searchTerms[termIndex], node) then + -- minus one to convert from one-based counting to zero-based + resultBitmap = bit.bor(resultBitmap, (2 ^ (termIndex - 1))) + end + end + + self.searchStrResults[nodeId] = resultBitmap end end From 8cceebf51b64c3b6a20745d8dd9c8195cb9a20bd Mon Sep 17 00:00:00 2001 From: wormingdead Date: Thu, 30 Jan 2020 12:37:44 -0800 Subject: [PATCH 8/9] Prevent overlapping circles from hiding those beneath --- Classes/PassiveTreeView.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index 31d069db1..a2f2e4adc 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -484,13 +484,13 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents) for searchIndex=1,self.searchTermsLimit do -- minus one to convert from one-based counting to zero-based if bit.band(self.searchStrResults[nodeId], (2 ^ (searchIndex - 1))) ~= 0 then - SetDrawLayer(nil, 30 + searchIndex) + SetDrawLayer(nil, 35 - searchIndex) SetDrawColor( self.searchResultColormap[searchIndex].r, self.searchResultColormap[searchIndex].g, self.searchResultColormap[searchIndex].b ) - local size = (175 + 5 * (searchIndex - 1)) * scale / self.zoom ^ 0.4 + local size = (175 + 25 * (searchIndex - 1)) * scale / self.zoom ^ 0.4 DrawImage(self.highlightRing, scrX - size, scrY - size, size * 2, size * 2) end end From d86907428902fa7bfa290ce39df4d5f678e5647f Mon Sep 17 00:00:00 2001 From: wormingdead Date: Thu, 30 Jan 2020 12:41:32 -0800 Subject: [PATCH 9/9] Increase highlight circle size based on number of matching search terms Instead of total search terms --- Classes/PassiveTreeView.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Classes/PassiveTreeView.lua b/Classes/PassiveTreeView.lua index a2f2e4adc..3dbca7755 100644 --- a/Classes/PassiveTreeView.lua +++ b/Classes/PassiveTreeView.lua @@ -481,17 +481,19 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents) SetDrawColor(1, 1, 1) end if self.searchStrResults[nodeId] and self.searchStrResults[nodeId] ~= 0 then + local searchResultsCounter = 0 for searchIndex=1,self.searchTermsLimit do -- minus one to convert from one-based counting to zero-based if bit.band(self.searchStrResults[nodeId], (2 ^ (searchIndex - 1))) ~= 0 then - SetDrawLayer(nil, 35 - searchIndex) + SetDrawLayer(nil, 35 - searchResultsCounter) SetDrawColor( self.searchResultColormap[searchIndex].r, self.searchResultColormap[searchIndex].g, self.searchResultColormap[searchIndex].b ) - local size = (175 + 25 * (searchIndex - 1)) * scale / self.zoom ^ 0.4 + local size = (175 + 25 * (searchResultsCounter)) * scale / self.zoom ^ 0.4 DrawImage(self.highlightRing, scrX - size, scrY - size, size * 2, size * 2) + searchResultsCounter = searchResultsCounter + 1 end end end