Skip to content

Commit d9106d3

Browse files
author
David Medgyesy
committed
Only offer Show All when it would reveal matching Spectres
The button was shown for any empty search, including searches that Show All could not satisfy because of Corpse Only, a monster type filter or a name that matches nothing. Check the search against the list Show All would produce, and pick the test Spectres from the data instead of relying on a fixed name.
1 parent a50a3a8 commit d9106d3

3 files changed

Lines changed: 124 additions & 28 deletions

File tree

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,124 @@
11
describe("Spectre Library", function()
2-
local controls
3-
local frostbearer = "Metadata/Monsters/LeagueCrucible/Cold/Pyromaniac"
2+
local controls, searchText, showAll, showAllCheckbox, corpseOnly
3+
4+
-- Picks a Spectre that only Show All reveals, with a name that no recommended Spectre matches
5+
local function findHiddenSpectre(itemisedCorpse)
6+
local minions = build.data.minions
7+
local recommendedNames = { }
8+
for id in pairs(build.data.spectres) do
9+
if minions[id].extraFlags and minions[id].extraFlags.recommendedSpectre then
10+
table.insert(recommendedNames, minions[id].name:lower())
11+
end
12+
end
13+
local candidates = { }
14+
for id in pairs(build.data.spectres) do
15+
local minion = minions[id]
16+
local name = minion.name:lower()
17+
if not (minion.extraFlags and minion.extraFlags.recommendedSpectre)
18+
and (minion.itemisedCorpse ~= nil) == itemisedCorpse and name:match("^[%a ]+$") then
19+
local hidden = true
20+
for _, recommendedName in ipairs(recommendedNames) do
21+
if recommendedName:find(name, 1, true) then
22+
hidden = false
23+
break
24+
end
25+
end
26+
-- Keep the name distinct from skill names so that it only matches in the name search modes
27+
for _, skill in pairs(build.data.skills) do
28+
if skill.name and skill.name:lower():find(name, 1, true) then
29+
hidden = false
30+
break
31+
end
32+
end
33+
if hidden then
34+
table.insert(candidates, id)
35+
end
36+
end
37+
end
38+
table.sort(candidates)
39+
assert.is_truthy(candidates[1], "Expected a Spectre that is only listed with Show All")
40+
return candidates[1], minions[candidates[1]].name
41+
end
42+
43+
local function setCorpseOnly(state)
44+
corpseOnly.state = state
45+
corpseOnly.changeFunc(state)
46+
end
447

548
before_each(function()
649
newBuild()
750
build:OpenSpectreLibrary()
851
controls = main.popups[1].controls
52+
searchText = controls.source.controls.searchText
53+
showAll = controls.source.controls.showAllForSearch
54+
showAllCheckbox = controls.sortMonsterCheckboxShowAll
55+
corpseOnly = controls.sortMonsterCheckboxFilterCorpse
956
end)
1057

1158
after_each(function()
1259
main:ClosePopup()
1360
end)
1461

1562
it("offers to enable Show All when a spectre search has no recommended matches", function()
16-
local searchText = controls.source.controls.searchText
17-
local showAll = controls.source.controls.showAllForSearch
18-
searchText:SetText("forge", true)
63+
local id, name = findHiddenSpectre(false)
64+
searchText:SetText(name, true)
1965
assert.are.equal(0, #controls.source.list)
2066
assert.is_truthy(showAll and showAll:IsShown(),
2167
"An empty recommended search should offer Show All")
2268

2369
searchText:SetText("", true)
2470
assert.is_false(showAll:IsShown())
25-
searchText:SetText("forge", true)
71+
searchText:SetText(name, true)
2672
showAll.onClick()
2773

28-
assert.is_true(controls.sortMonsterCheckboxShowAll.state)
29-
assert.are.equal("forge", searchText.buf)
30-
assert.is_truthy(isValueInArray(controls.source.list, frostbearer))
74+
assert.is_true(showAllCheckbox.state)
75+
assert.are.equal(name, searchText.buf)
76+
assert.is_truthy(isValueInArray(controls.source.list, id))
3177
assert.is_false(showAll:IsShown())
78+
end)
3279

80+
it("does not offer Show All when it would not find anything either", function()
3381
searchText:SetText("no such spectre", true)
3482
assert.are.equal(0, #controls.source.list)
3583
assert.is_false(showAll:IsShown())
84+
85+
-- Hidden by the monster type filter, which Show All does not change
86+
local id, name = findHiddenSpectre(false)
87+
local typeCheckbox = controls["sortMonsterCheckbox" .. build.data.minions[id].monsterCategory]
88+
searchText:SetText(name, true)
89+
assert.is_true(showAll:IsShown())
90+
typeCheckbox.state = false
91+
typeCheckbox.changeFunc(false)
92+
assert.are.equal(0, #controls.source.list)
93+
assert.is_false(showAll:IsShown())
94+
typeCheckbox.state = true
95+
typeCheckbox.changeFunc(true)
96+
assert.is_true(showAll:IsShown())
97+
98+
-- No Spectre has a skill with this name
99+
controls.source.controls.searchModeDropDown:SetSel(2)
100+
assert.are.equal(0, #controls.source.list)
101+
assert.is_false(showAll:IsShown())
36102
end)
37103

38104
it("keeps Corpse Only enabled when expanding an empty search", function()
39-
local corpseOnly = controls.sortMonsterCheckboxFilterCorpse
40-
corpseOnly.state = true
41-
corpseOnly.changeFunc(true)
42-
controls.source.controls.searchText:SetText("forge", true)
105+
local plainId, plainName = findHiddenSpectre(false)
106+
local corpseId, corpseName = findHiddenSpectre(true)
107+
setCorpseOnly(true)
43108

44-
local showAll = controls.source.controls.showAllForSearch
45-
assert.is_truthy(showAll and showAll:IsShown())
109+
-- Show All would still hide a Spectre that has no itemised corpse
110+
searchText:SetText(plainName, true)
111+
assert.are.equal(0, #controls.source.list)
112+
assert.is_false(showAll:IsShown())
113+
114+
searchText:SetText(corpseName, true)
115+
assert.are.equal(0, #controls.source.list)
116+
assert.is_true(showAll:IsShown())
46117
showAll.onClick()
47118

48119
assert.is_true(corpseOnly.state)
49-
assert.are.equal(0, #controls.source.list)
120+
assert.is_true(showAllCheckbox.state)
121+
assert.is_truthy(isValueInArray(controls.source.list, corpseId))
122+
assert.is_nil(isValueInArray(controls.source.list, plainId))
50123
end)
51124
end)

‎src/Classes/MinionSearchListControl.lua‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,24 @@ function MinionSearchListClass:DoesEntryMatchFilters(searchStr, minionId, filter
122122
return false
123123
end
124124

125-
function MinionSearchListClass:ListFilterChanged(buf, filterMode)
125+
-- Returns the entries of the given list that match the search, or nil if the search is blank
126+
function MinionSearchListClass:FilterList(list, buf, filterMode)
126127
local searchStr = buf:lower():gsub("[%-%.%+%[%]%$%^%%%?%*]", "%%%0")
127-
if searchStr:match("%S") then
128-
local filteredList = { }
129-
for _, minionId in pairs(self.unfilteredList) do
130-
if self:DoesEntryMatchFilters(searchStr, minionId, filterMode) then
131-
t_insert(filteredList, minionId)
132-
end
128+
if not searchStr:match("%S") then
129+
return
130+
end
131+
local filteredList = { }
132+
for _, minionId in pairs(list) do
133+
if self:DoesEntryMatchFilters(searchStr, minionId, filterMode) then
134+
t_insert(filteredList, minionId)
133135
end
136+
end
137+
return filteredList
138+
end
139+
140+
function MinionSearchListClass:ListFilterChanged(buf, filterMode)
141+
local filteredList = self:FilterList(self.unfilteredList, buf, filterMode)
142+
if filteredList then
134143
self.list = filteredList
135144
self:SelectIndex(1)
136145
else

‎src/Modules/Build.lua‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ function buildMode:OpenSpectreLibrary()
17351735
Corpse = true,
17361736
}
17371737

1738-
local function buildSourceList(sourceList)
1738+
local function buildSourceList(sourceList, showAll)
17391739
wipeTable(sourceList)
17401740
local monsterCategories = {
17411741
{ key = "Beast", list = beastList },
@@ -1753,7 +1753,7 @@ function buildMode:OpenSpectreLibrary()
17531753
end
17541754
end
17551755
-- Apply 'recommended' filter if checkbox is off
1756-
if not monsterTypeSort.recommendedList then
1756+
if not monsterTypeSort.recommendedList and not showAll then
17571757
local allowed = {}
17581758
for _, id in ipairs(recommendedSpectreList) do
17591759
allowed[id] = true
@@ -1842,9 +1842,11 @@ function buildMode:OpenSpectreLibrary()
18421842
controls.source.OnSelect = function()
18431843
UpdateMinionDisplay(controls.source.selValue)
18441844
end
1845+
local filterRevision = 0
18451846
local function monsterTypeCheckboxChange(name)
18461847
return function(state)
18471848
monsterTypeSort[name] = state
1849+
filterRevision = filterRevision + 1
18481850
buildSourceList(sourceList)
18491851
controls.source.unfilteredList = copyTable(sourceList)
18501852
controls.source:ListFilterChanged(controls.source.controls.searchText.buf, controls.source.controls.searchModeDropDown.selIndex)
@@ -1871,10 +1873,22 @@ function buildMode:OpenSpectreLibrary()
18711873
controls.sortMonsterCheckboxFilterCorpse = new("CheckBoxControl"):CheckBoxControl({"TOPLEFT", controls.source, "BOTTOMLEFT"}, {89, 2, 26, 26}, "", monsterTypeCheckboxChange("corpseList"), "Hide Spectres found in Acts or Maps and only show\nItemised Corpses obtainable through trade or Rituals.", false)
18721874
controls.showOnlyCorpseLabel =new("LabelControl"):LabelControl({"RIGHT",controls.sortMonsterCheckboxFilterCorpse,"LEFT"}, {-5, 0, 0, 16}, "Corpse Only:")
18731875
controls.showAllLabel =new("LabelControl"):LabelControl({"RIGHT",controls.sortMonsterCheckboxShowAll,"LEFT"}, {-5, 0, 0, 16}, "Show All:")
1876+
-- Whether the search would find Spectres that only the recommended filter is hiding
1877+
local hiddenMatches = { }
18741878
local function canExpandSearch()
1875-
return not controls.sortMonsterCheckboxShowAll.state
1876-
and #controls.source.list == 0
1877-
and controls.source.controls.searchText.buf:find("%S") ~= nil
1879+
local source = controls.source
1880+
if controls.sortMonsterCheckboxShowAll.state or #source.list > 0 then
1881+
return false
1882+
end
1883+
local buf = source.controls.searchText.buf
1884+
local filterMode = source.controls.searchModeDropDown.selIndex
1885+
if hiddenMatches.buf ~= buf or hiddenMatches.filterMode ~= filterMode or hiddenMatches.revision ~= filterRevision then
1886+
local showAllList = { }
1887+
buildSourceList(showAllList, true)
1888+
local matches = source:FilterList(showAllList, buf, filterMode)
1889+
hiddenMatches = { buf = buf, filterMode = filterMode, revision = filterRevision, found = matches ~= nil and #matches > 0 }
1890+
end
1891+
return hiddenMatches.found
18781892
end
18791893
local noRecommendedMatches = new("LabelControl"):LabelControl({"TOP", controls.source, "TOP"}, {-8, 16, 0, 14},
18801894
"No recommended matches")

0 commit comments

Comments
 (0)