From 14df3d043688c699175009524cd104c53ca37a16 Mon Sep 17 00:00:00 2001 From: DarkGod <darkgod@net-core.org> Date: Wed, 23 Oct 2019 00:38:21 +0200 Subject: [PATCH] Show known lore menu now has a search bar (search by lore id, name and category) --- game/modules/tome/dialogs/ShimmerOther.lua | 39 ++++++++++++++++------ game/modules/tome/dialogs/ShowLore.lua | 27 ++++++++++++--- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/game/modules/tome/dialogs/ShimmerOther.lua b/game/modules/tome/dialogs/ShimmerOther.lua index 1f00c02ff2..f0cea9deba 100644 --- a/game/modules/tome/dialogs/ShimmerOther.lua +++ b/game/modules/tome/dialogs/ShimmerOther.lua @@ -21,7 +21,8 @@ require "engine.class" local Dialog = require "engine.ui.Dialog" local Textzone = require "engine.ui.Textzone" local ActorFrame = require "engine.ui.ActorFrame" -local List = require "engine.ui.List" +local Textbox = require "engine.ui.Textbox" +local ListColumns = require "engine.ui.ListColumns" module(..., package.seeall, class.inherit(Dialog)) @@ -36,14 +37,17 @@ function _M:init(player, slot) self:generateList() - self.c_list = List.new{scrollbar=true, width=300, height=self.ih - 5, list=self.list, fct=function(item) self:use(item) end, select=function(item) self:select(item) end} + self.c_search = Textbox.new{title="Search: ", text="", chars=20, max_len=60, fct=function() end, on_change=function(text) self:search(text) end} + + self.c_list = ListColumns.new{columns={{name="Name", width=100, display_prop="name", sort="sortname"}}, hide_columns=true, scrollbar=true, width=300, height=self.ih - 5 - self.c_search.h, list=self.list, fct=function(item) self:use(item) end, select=function(item) self:select(item) end} local donatortext = "" if not profile:isDonator(1) then donatortext = "\n#{italic}##CRIMSON#This cosmetic feature is only available to donators/buyers. You can only preview.#WHITE##{normal}#" end local help = Textzone.new{width=math.floor(self.iw - self.c_list.w - 20), height=self.ih, no_color_bleed=true, auto_height=true, text="You can alter your look.\n#{bold}#This is a purely cosmetic change.#{normal}#"..donatortext} local actorframe = ActorFrame.new{actor=self.actor, w=128, h=128} self:loadUI{ - {left=0, top=0, ui=self.c_list}, + {left=0, top=0, ui=self.c_search}, + {left=0, top=self.c_search, ui=self.c_list}, {right=0, top=0, ui=help}, {right=(help.w - actorframe.w) / 2, vcenter=0, ui=actorframe}, } @@ -113,6 +117,18 @@ function _M:select(item) self.actor:updateModdableTile() end +function _M:search(text) + if text == "" then self.search_filter = nil + else self.search_filter = text end + + self:generateList() +end + +function _M:matchSearch(name) + if not self.search_filter then return true end + return name:lower():find(self.search_filter:lower(), 1, 1) +end + function _M:generateList() local unlocked = world.unlocked_shimmers and world.unlocked_shimmers[self.slot] or {} local list = {} @@ -124,15 +140,18 @@ function _M:generateList() } for name, data in pairs(unlocked) do - local d = { - moddables = table.clone(data.moddables, true), - name = name, - sortname = name:removeColorCodes(), - } - d.moddables.name = name - list[#list+1] = d + if self:matchSearch(name:removeColorCodes()) then + local d = { + moddables = table.clone(data.moddables, true), + name = name, + sortname = name:removeColorCodes(), + } + d.moddables.name = name + list[#list+1] = d + end end table.sort(list, "sortname") self.list = list + if self.c_list then self.c_list:setList(list) end end diff --git a/game/modules/tome/dialogs/ShowLore.lua b/game/modules/tome/dialogs/ShowLore.lua index d5cdb112e8..ea36ad61b5 100644 --- a/game/modules/tome/dialogs/ShowLore.lua +++ b/game/modules/tome/dialogs/ShowLore.lua @@ -20,6 +20,7 @@ require "engine.class" local Dialog = require "engine.ui.Dialog" local ListColumns = require "engine.ui.ListColumns" +local Textbox = require "engine.ui.Textbox" local TextzoneList = require "engine.ui.TextzoneList" local Separator = require "engine.ui.Separator" local Image = require "engine.ui.Image" @@ -40,14 +41,17 @@ function _M:init(title, actor) self:generateList() - self.c_list = ListColumns.new{width=math.floor(self.iw / 2 - vsep.w / 2), height=self.ih - 10, scrollbar=true, sortable=true, columns={ + self.c_search = Textbox.new{title="Search: ", text="", chars=20, max_len=60, fct=function() end, on_change=function(text) self:search(text) end} + + self.c_list = ListColumns.new{width=math.floor(self.iw / 2 - vsep.w / 2), height=self.ih - 10 - self.c_search.h, scrollbar=true, sortable=true, columns={ {name="", width={40,"fixed"}, display_prop="order", sort="order"}, {name="Lore", width=60, display_prop="name", sort="name"}, {name="Category", width=40, display_prop="cat", sort="cat"}, }, list=self.list, fct=function(item) self:popup(item) end, select=function(item, sel) self:select(item) end} self:loadUI{ - {left=0, top=0, ui=self.c_list}, + {left=0, top=0, ui=self.c_search}, + {left=0, top=self.c_search, ui=self.c_list}, {right=0, top=0, ui=self.c_desc}, {hcenter=0, top=5, ui=vsep}, } @@ -60,18 +64,31 @@ function _M:init(title, actor) } end +function _M:search(text) + if text == "" then self.search_filter = nil + else self.search_filter = text end + + self:generateList() +end + +function _M:matchSearch(name) + if not self.search_filter then return true end + return name:lower():find(self.search_filter:lower(), 1, 1) +end + function _M:generateList() -- Makes up the list local list = {} - local i = 0 for id, _ in pairs(self.actor.lore_known) do local l = self.actor:getLore(id) - list[#list+1] = { name=l.name, desc=util.getval(l.lore), cat=l.category, order=l.order, image=l.image, lore=l } - i = i + 1 + if self:matchSearch(id) or self:matchSearch(l.name) or self:matchSearch(l.category) then + list[#list+1] = { name=l.name, desc=util.getval(l.lore), cat=l.category, order=l.order, image=l.image, lore=l } + end end -- Add known artifacts table.sort(list, function(a, b) return a.order < b.order end) self.list = list + if self.c_list then self.c_list:setList(list) end end function _M:popup(item) -- GitLab