new gui colors, multiplayer menu modified

This commit is contained in:
Looki2000 2023-04-25 23:24:58 +02:00
parent 25ecab3ad8
commit 19fa51c570
2 changed files with 158 additions and 111 deletions

View File

@ -16,41 +16,54 @@
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
local function get_sorted_servers()
--local servers = {
-- fav = {},
-- public = {},
-- incompatible = {}
--}
main_serv = {
address = "test.test.test.test",
port = 30000,
name = "The official SussyCraft server"
}
local servers = {
fav = {},
public = {},
fav = serverlistmgr.get_favorites(),
public = {main_serv},
incompatible = {}
}
local favs = serverlistmgr.get_favorites()
local taken_favs = {}
local result = menudata.search_result or serverlistmgr.servers
for _, server in ipairs(result) do
server.is_favorite = false
for index, fav in ipairs(favs) do
if server.address == fav.address and server.port == fav.port then
taken_favs[index] = true
server.is_favorite = true
break
end
end
server.is_compatible = is_server_protocol_compat(server.proto_min, server.proto_max)
if server.is_favorite then
table.insert(servers.fav, server)
elseif server.is_compatible then
table.insert(servers.public, server)
else
table.insert(servers.incompatible, server)
end
end
if not menudata.search_result then
for index, fav in ipairs(favs) do
if not taken_favs[index] then
table.insert(servers.fav, fav)
end
end
end
--local favs = serverlistmgr.get_favorites()
--local taken_favs = {}
--local result = menudata.search_result or serverlistmgr.servers
--for _, server in ipairs(result) do
-- server.is_favorite = false
-- for index, fav in ipairs(favs) do
-- if server.address == fav.address and server.port == fav.port then
-- taken_favs[index] = true
-- server.is_favorite = true
-- break
-- end
-- end
-- server.is_compatible = is_server_protocol_compat(server.proto_min, server.proto_max)
-- if server.is_favorite then
-- table.insert(servers.fav, server)
-- elseif server.is_compatible then
-- table.insert(servers.public, server)
-- else
-- table.insert(servers.incompatible, server)
-- end
--end
--
--if not menudata.search_result then
-- for index, fav in ipairs(favs) do
-- if not taken_favs[index] then
-- table.insert(servers.fav, fav)
-- end
-- end
--end
return servers
end
@ -80,11 +93,11 @@ local function get_formspec(tabview, name, tabdata)
"box[0,0;5.75,7;#666666]" ..
-- Address / Port
"label[0.25,0.35;" .. fgettext("Address") .. "]" ..
"label[4.25,0.35;" .. fgettext("Port") .. "]" ..
"field[0.25,0.5;4,0.75;te_address;;" ..
"label[0.25,0.30;" .. fgettext("Address") .. "]" ..
"label[4,0.30;" .. fgettext("Port") .. "]" ..
"field[0.25,0.5;3.75,0.75;te_address;;" ..
core.formspec_escape(core.settings:get("address")) .. "]" ..
"field[4.25,0.5;1.25,0.75;te_port;;" ..
"field[4,0.5;1.5,0.75;te_port;;" ..
core.formspec_escape(core.settings:get("remote_port")) .. "]" ..
-- Description Background
@ -186,60 +199,60 @@ end
--------------------------------------------------------------------------------
local function search_server_list(input)
menudata.search_result = nil
if #serverlistmgr.servers < 2 then
return
end
-- setup the keyword list
local keywords = {}
for word in input:gmatch("%S+") do
word = word:gsub("(%W)", "%%%1")
table.insert(keywords, word)
end
if #keywords == 0 then
return
end
menudata.search_result = {}
-- Search the serverlist
local search_result = {}
for i = 1, #serverlistmgr.servers do
local server = serverlistmgr.servers[i]
local found = 0
for k = 1, #keywords do
local keyword = keywords[k]
if server.name then
local sername = server.name:lower()
local _, count = sername:gsub(keyword, keyword)
found = found + count * 4
end
if server.description then
local desc = server.description:lower()
local _, count = desc:gsub(keyword, keyword)
found = found + count * 2
end
end
if found > 0 then
local points = (#serverlistmgr.servers - i) / 5 + found
server.points = points
table.insert(search_result, server)
end
end
if #search_result == 0 then
return
end
table.sort(search_result, function(a, b)
return a.points > b.points
end)
menudata.search_result = search_result
end
--local function search_server_list(input)
-- menudata.search_result = nil
-- if #serverlistmgr.servers < 2 then
-- return
-- end
--
-- -- setup the keyword list
-- local keywords = {}
-- for word in input:gmatch("%S+") do
-- word = word:gsub("(%W)", "%%%1")
-- table.insert(keywords, word)
-- end
--
-- if #keywords == 0 then
-- return
-- end
--
-- menudata.search_result = {}
--
-- -- Search the serverlist
-- local search_result = {}
-- for i = 1, #serverlistmgr.servers do
-- local server = serverlistmgr.servers[i]
-- local found = 0
-- for k = 1, #keywords do
-- local keyword = keywords[k]
-- if server.name then
-- local sername = server.name:lower()
-- local _, count = sername:gsub(keyword, keyword)
-- found = found + count * 4
-- end
--
-- if server.description then
-- local desc = server.description:lower()
-- local _, count = desc:gsub(keyword, keyword)
-- found = found + count * 2
-- end
-- end
-- if found > 0 then
-- local points = (#serverlistmgr.servers - i) / 5 + found
-- server.points = points
-- table.insert(search_result, server)
-- end
-- end
--
-- if #search_result == 0 then
-- return
-- end
--
-- table.sort(search_result, function(a, b)
-- return a.points > b.points
-- end)
-- menudata.search_result = search_result
--end
local function set_selected_server(tabdata, idx, server)
-- reset selection
@ -325,22 +338,22 @@ local function main_button_handler(tabview, fields, name, tabdata)
return true
end
if fields.btn_mp_clear then
tabdata.search_for = ""
menudata.search_result = nil
return true
end
--if fields.btn_mp_clear then
-- tabdata.search_for = ""
-- menudata.search_result = nil
-- return true
--end
if fields.btn_mp_search or fields.key_enter_field == "te_search" then
tabdata.search_for = fields.te_search
search_server_list(fields.te_search:lower())
if menudata.search_result then
-- first server in row 2 due to header
set_selected_server(tabdata, 2, menudata.search_result[1])
end
--if fields.btn_mp_search or fields.key_enter_field == "te_search" then
-- tabdata.search_for = fields.te_search
-- search_server_list(fields.te_search:lower())
-- if menudata.search_result then
-- -- first server in row 2 due to header
-- set_selected_server(tabdata, 2, menudata.search_result[1])
-- end
return true
end
-- return true
--end
--if fields.btn_mp_refresh then
-- serverlistmgr.sync()
@ -365,8 +378,11 @@ local function main_button_handler(tabview, fields, name, tabdata)
if server and server.address == gamedata.address and
server.port == gamedata.port then
serverlistmgr.add_favorite(server)
-- add only if not main_serv
if server.address ~= main_serv.address and server.port ~= main_serv.port then
serverlistmgr.add_favorite(server)
end
gamedata.servername = server.name
gamedata.serverdescription = server.description
@ -414,10 +430,10 @@ local function main_button_handler(tabview, fields, name, tabdata)
return false
end
local function on_change(type, old_tab, new_tab)
if type == "LEAVE" then return end
serverlistmgr.sync()
end
--local function on_change(type, old_tab, new_tab)
-- if type == "LEAVE" then return end
-- serverlistmgr.sync()
--end
return {
name = "online",

View File

@ -142,7 +142,27 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0));
skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30));
skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0));
skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 120, 50));
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distrib(0, 1);
// random gui color
bool gui_color = static_cast<bool>(distrib(gen));
// sus list highlight color
//skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 120, 50)); // minetest green
//skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 120, 50, 50)); // dark sussy red
//skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 50, 50, 120)); // evening sky blue
if (gui_color)
skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 120, 50, 50)); // dark sussy red
else
skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 50, 50, 120)); // evening sky blue
skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255));
#ifdef HAVE_TOUCHSCREENGUI
float density = RenderingEngine::getDisplayDensity();
@ -173,7 +193,18 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
// Irrlicht 1.8 input colours
skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128));
skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 96, 134, 49));
// sus field selected color
//skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 96, 134, 49)); // minetest green
//skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 135, 50, 50)); // dark sussy red
//skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 50, 50, 135)); // evening sky blue
if (gui_color)
skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 135, 50, 50)); // dark sussy red
else
skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 50, 50, 135)); // evening sky blue
// Create the menu clouds
if (!g_menucloudsmgr)