From 9f51065d9ba066bdda0edbcd69ebf8d7d7910683 Mon Sep 17 00:00:00 2001 From: Caio Rodrigues Date: Wed, 28 Nov 2018 23:38:35 -0300 Subject: [PATCH] Fix searching and filtering on the Lua Packlist --- .../ScreenPackDownloader underlay.lua | 2 -- .../BGAnimations/packlistDisplay.lua | 3 +- Themes/_fallback/Scripts/09 PackList.lua | 33 +++++++++++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Themes/Til Death/BGAnimations/ScreenPackDownloader underlay.lua b/Themes/Til Death/BGAnimations/ScreenPackDownloader underlay.lua index 62fda7f542..8e58e09a0e 100644 --- a/Themes/Til Death/BGAnimations/ScreenPackDownloader underlay.lua +++ b/Themes/Til Death/BGAnimations/ScreenPackDownloader underlay.lua @@ -3,7 +3,6 @@ local filters = {"", "0", "0", "0", "0", "0", "0"} local curInput = "" local inputting = 0 --1=name 2=lowerdiff 3=upperdiff 4=lowersize 5=uppersize 0=none -local packlist local function getFilter(index) return filters[index] @@ -165,7 +164,6 @@ local o = InitCommand = function(self) self:xy(0, 0):halign(0.5):valign(0) self:GetChild("PacklistDisplay"):xy(SCREEN_WIDTH / 2.5 - offx, offy * 2 + 14) - packlist = DLMAN:GetPacklist() self:SetUpdateFunction(highlight) end, BeginCommand = function(self) diff --git a/Themes/Til Death/BGAnimations/packlistDisplay.lua b/Themes/Til Death/BGAnimations/packlistDisplay.lua index cc7850f7df..3f8488d1f0 100644 --- a/Themes/Til Death/BGAnimations/packlistDisplay.lua +++ b/Themes/Til Death/BGAnimations/packlistDisplay.lua @@ -31,7 +31,7 @@ local function highlightIfOver(self) end end -local packlist +packlist = {} local packtable local o = Def.ActorFrame { @@ -42,7 +42,6 @@ local o = BeginCommand = function(self) self:SetUpdateFunction(highlight) packlist = PackList:new() - packlist:SetFromAll() self:queuecommand("PackTableRefresh") end, PackTableRefreshCommand = function(self) diff --git a/Themes/_fallback/Scripts/09 PackList.lua b/Themes/_fallback/Scripts/09 PackList.lua index d4e45ba61b..4e00133c2a 100644 --- a/Themes/_fallback/Scripts/09 PackList.lua +++ b/Themes/_fallback/Scripts/09 PackList.lua @@ -53,20 +53,39 @@ function PackList:SortBySize() return self:SortByProp(getSizePropName) end function PackList:FilterAndSearch(name, avgMin, avgMax, sizeMin, sizeMax) - self.packs = + self.packs = filter( function(x) - local d = x[getAvgDiffPropName]:x() - local n = x[getNamePropName]:x() - local s = x[getSizePropName]:x() - return n == name and ((d > avgMin and d < avgMax) or d <= 0) and ((s > sizeMin and d < sizeMax) or s <= 0) + local d = x[getAvgDiffPropName](x) + local n = x[getNamePropName](x) + local s = x[getSizePropName](x) + local valid = string.lower(n):sub(1, #name) == string.lower(name) + if d > 0 then + if avgMin > 0 then + valid = valid and d > avgMin + end + if avgMax > 0 then + valid = valid and d < avgMax + end + end + if s > 0 then + if sizeMin > 0 then + valid = valid and s > sizeMin + end + if sizeMax > 0 then + valid = valid and s < sizeMax + end + end + return valid end, - self.packs + self.allPacks ) return self end function PackList:SetFromAll() - self.packs = DLMAN:GetAllPacks() + local allPacks = DLMAN:GetAllPacks() + self.allPacks = allPacks + self.packs = DeepCopy(allPacks) return self end function PackList:new()