Skip to content
Snippets Groups Projects
Commit fff4b2e8 authored by DarkGod's avatar DarkGod
Browse files

Shimmer mirror now has a search box

parent 8c1d1ed4
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -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))
......@@ -32,20 +33,24 @@ function _M:init(player, slot)
self.actor.x, self.actor.y = nil, nil
self.actor:removeAllMOs()
self.object = self.actor:getInven(slot)[1]
self.search_filter = nil
local oname = self.object:getName{do_color=true, no_add_name=true}
Dialog.init(self, "Shimmer object: "..oname, 680, 500)
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 "..oname.." to look like another item of the same type/slot.\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},
}
......@@ -78,19 +83,33 @@ 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.object.slot] or {}
local list = {}
list[#list+1] = {
moddables = {},
name = "#GREY#[Invisible]",
sortname = "--",
}
if self:matchSearch("invisible") then
list[#list+1] = {
moddables = {},
name = "#GREY#[Invisible]",
sortname = "--",
}
end
for name, data in pairs(unlocked) do
-- if self.object.type == data.type and self.object.subtype == data.subtype then
if self.object.type == data.type then
if self.object.type == data.type and self:matchSearch(name:removeColorCodes()) then
local d = {
moddables = table.clone(data.moddables, true),
name = name,
......@@ -103,4 +122,5 @@ function _M:generateList()
table.sort(list, "sortname")
self.list = list
if self.c_list then self.c_list:setList(list) end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment