From 90e4a205fb7808dd21a291857a809f0a70846fe6 Mon Sep 17 00:00:00 2001 From: cx384 Date: Sun, 15 Dec 2024 13:29:27 +0100 Subject: [PATCH 1/7] Main menu server tab mods button --- LICENSE.txt | 8 +++ builtin/mainmenu/dlg_server_list_mods.lua | 47 ++++++++++++++++++ builtin/mainmenu/init.lua | 1 + builtin/mainmenu/tab_online.lua | 35 ++++++++++++- textures/base/pack/server_view_clients.png | Bin 218 -> 146 bytes .../pack/server_view_clients_unavailable.png | Bin 0 -> 145 bytes textures/base/pack/server_view_mods.png | Bin 0 -> 210 bytes .../pack/server_view_mods_unavailable.png | Bin 0 -> 198 bytes 8 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 builtin/mainmenu/dlg_server_list_mods.lua create mode 100644 textures/base/pack/server_view_clients_unavailable.png create mode 100644 textures/base/pack/server_view_mods.png create mode 100644 textures/base/pack/server_view_mods_unavailable.png diff --git a/LICENSE.txt b/LICENSE.txt index f7930f528..7db690ef2 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -14,6 +14,9 @@ https://www.apache.org/licenses/LICENSE-2.0.html Textures by Zughy are under CC BY-SA 4.0 https://creativecommons.org/licenses/by-sa/4.0/ +Textures by cx384 are under CC BY-SA 4.0 +https://creativecommons.org/licenses/by-sa/4.0/ + Media files by DS are under CC BY-SA 4.0 https://creativecommons.org/licenses/by-sa/4.0/ @@ -65,6 +68,11 @@ Zughy: textures/base/pack/settings_reset.png textures/base/pack/server_url.png textures/base/pack/server_view_clients.png + textures/base/pack/server_view_clients_unavailable.png + +cx384: + textures/base/pack/server_view_mods.png + textures/base/pack/server_view_mods_unavailable.png appgurueu: textures/base/pack/server_incompatible.png diff --git a/builtin/mainmenu/dlg_server_list_mods.lua b/builtin/mainmenu/dlg_server_list_mods.lua new file mode 100644 index 000000000..e5a7c8fa4 --- /dev/null +++ b/builtin/mainmenu/dlg_server_list_mods.lua @@ -0,0 +1,47 @@ +-- Luanti +-- Copyright (C) 2024 cx384 +-- SPDX-License-Identifier: LGPL-2.1-or-later + +local function get_formspec(dialogdata) + local TOUCH_GUI = core.settings:get_bool("touch_gui") + local server = dialogdata.server + + -- A wrongly behaving server may send ill formed mod names + local mods = {} + table.sort(server.mods) + for i, m in ipairs(server.mods) do + mods[i] = core.formspec_escape(m) + end + mods = table.concat(mods, ",") + + local formspec = { + "formspec_version[8]", + "size[6,9.5]", + TOUCH_GUI and "padding[0.01,0.01]" or "", + "hypertext[0,0;6,1.5;;", + fgettext("The $1 server uses " .. (server.gameid and "a game called $2 and " or "") .. + "the following mods:", + "" .. core.hypertext_escape(server.name) .. "", + "") .. "]", + "textlist[0.5,1.5;5,6.8;;" .. mods .. "]", + "button[1.5,8.5;3,0.8;quit;OK]" + } + return table.concat(formspec, "") +end + +local function buttonhandler(this, fields) + if fields.quit then + this:delete() + return true + end + return false +end + +function create_server_list_mods_dialog(server) + local retval = dialog_create("dlg_server_list_mods", + get_formspec, + buttonhandler, + nil) + retval.data.server = server + return retval +end diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 4e1c201cd..9eceb41a8 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -56,6 +56,7 @@ dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua") dofile(menupath .. DIR_DELIM .. "dlg_version_info.lua") dofile(menupath .. DIR_DELIM .. "dlg_reinstall_mtg.lua") dofile(menupath .. DIR_DELIM .. "dlg_clients_list.lua") +dofile(menupath .. DIR_DELIM .. "dlg_server_list_mods.lua") local tabs = { content = dofile(menupath .. DIR_DELIM .. "tab_content.lua"), diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index 12192715f..3f64da344 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -160,6 +160,26 @@ local function get_formspec(tabview, name, tabdata) core.formspec_escape(gamedata.serverdescription) .. "]" end + -- Mods button + local mods = selected_server.mods + if mods and #mods > 0 then + local tooltip = "" + if selected_server.gameid then + tooltip = "Game: " .. selected_server.gameid .. "\n" + end + tooltip = tooltip .. "Number of mods: " .. #mods + + retval = retval .. + "tooltip[btn_view_mods;" .. core.formspec_escape(tooltip) .. "]" .. + "style[btn_view_mods;padding=6]" .. + "image_button[4,1.3;0.5,0.5;" .. core.formspec_escape(defaulttexturedir .. + "server_view_mods.png") .. ";btn_view_mods;]" + else + retval = retval .. "image[4.1,1.4;0.3,0.3;" .. core.formspec_escape(defaulttexturedir .. + "server_view_mods_unavailable.png") .. "]" + end + + -- Clients list button local clients_list = selected_server.clients_list local can_view_clients_list = clients_list and #clients_list > 0 if can_view_clients_list then @@ -177,15 +197,20 @@ local function get_formspec(tabview, name, tabdata) retval = retval .. "style[btn_view_clients;padding=6]" retval = retval .. "image_button[4.5,1.3;0.5,0.5;" .. core.formspec_escape(defaulttexturedir .. "server_view_clients.png") .. ";btn_view_clients;]" + else + retval = retval .. "image[4.6,1.4;0.3,0.3;" .. core.formspec_escape(defaulttexturedir .. + "server_view_clients_unavailable.png") .. "]" end + -- URL button if selected_server.url then retval = retval .. "tooltip[btn_server_url;" .. fgettext("Open server website") .. "]" retval = retval .. "style[btn_server_url;padding=6]" - retval = retval .. "image_button[" .. (can_view_clients_list and "4" or "4.5") .. ",1.3;0.5,0.5;" .. + retval = retval .. "image_button[3.5,1.3;0.5,0.5;" .. core.formspec_escape(defaulttexturedir .. "server_url.png") .. ";btn_server_url;]" end + -- Favorites toggle button if is_selected_fav() then retval = retval .. "tooltip[btn_delete_favorite;" .. fgettext("Remove favorite") .. "]" retval = retval .. "style[btn_delete_favorite;padding=6]" @@ -387,6 +412,14 @@ local function main_button_handler(tabview, fields, name, tabdata) return true end + if fields.btn_view_mods then + local dlg = create_server_list_mods_dialog(find_selected_server()) + dlg:set_parent(tabview) + tabview:hide() + dlg:show() + return true + end + if fields.btn_mp_clear then tabdata.search_for = "" menudata.search_result = nil diff --git a/textures/base/pack/server_view_clients.png b/textures/base/pack/server_view_clients.png index 87b569f93129e5add2d820f3c47d987a99ac2db1..1200670744bbc1fe161d28325b2cf65c5c35e5fa 100644 GIT binary patch delta 117 zcmV-*0E++G0g?fbByL$rL_t(IjbmWI0t|HY{$s<~)MC}#_4*@LOwbT~nu#(5*#LZO z`WQgA7Yr92#;F-3M^r#!GlVG3_`E{DbU;xUP-Fm1GYn(X48vFrK{o&&rkw$#V3Rj%+VIbB~17fVq>ENoCXjJa2kN@6@1>pFkt!iOE?u{lf#G>10B8pjAc_9 zB0cpmH2?3)#)wJ`17L=rI~zUp@wxz)pRpN&5(Y5m;{uFjQ#UbEDaFwUcMiJk*a8s- skOLDVFJRMv4^Zp{6c_yO$|l(W092MpD4HARQ2+n{07*qoM6N<$f~oON#Q*>R diff --git a/textures/base/pack/server_view_clients_unavailable.png b/textures/base/pack/server_view_clients_unavailable.png new file mode 100644 index 0000000000000000000000000000000000000000..964efcde1ef8c96de5981bf1df059b117cbf1a76 GIT binary patch literal 145 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`5uPrNAr`%RCpmI4C~&a+oy~vi z{*Sv>oPx6>gAO{hr#X1G$b{zde4BPE&F!X}lBK95^TogZ52{!gyd@p-ChAO@v^enJ s-{wnvUX0Ua)vQg7*p=?F`W38amXb{W_c-SiC(sTCPgg&ebxsLQ0N5ffk^lez literal 0 HcmV?d00001 diff --git a/textures/base/pack/server_view_mods.png b/textures/base/pack/server_view_mods.png new file mode 100644 index 0000000000000000000000000000000000000000..a2611d92d261fea9b835f16a76f58b9033f8e5b6 GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Gd*1#Lo9lGCmC`z7znU@7ONLr z^QNX@t^5XI?LZdq__Zz(H)4vWbH_}+Eh*;9acpMN_hlQ6)OMWvD8JpK>AdN`;=I4r zI?Z|?8*Yf_R&cIhTa~-yCbN++!_tGPt9d`od~mPWb1iR?XB#_agSRF>+rWLr#U|<-v)|0Vqy5!OR|6f%;OXk; Jvd$@?2>^wxPrCpB literal 0 HcmV?d00001 diff --git a/textures/base/pack/server_view_mods_unavailable.png b/textures/base/pack/server_view_mods_unavailable.png new file mode 100644 index 0000000000000000000000000000000000000000..4238bb786a3f288b2e9ff4dd164f57a82dca3ab7 GIT binary patch literal 198 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`y`C`rU| literal 0 HcmV?d00001 From b1e3001042c0e99544fae6333b2bd75dc9555d41 Mon Sep 17 00:00:00 2001 From: cx384 Date: Sun, 15 Dec 2024 17:51:09 +0100 Subject: [PATCH 2/7] Add group by underscore prefix feature --- builtin/mainmenu/dlg_server_list_mods.lua | 57 +++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/builtin/mainmenu/dlg_server_list_mods.lua b/builtin/mainmenu/dlg_server_list_mods.lua index e5a7c8fa4..4957ec7d9 100644 --- a/builtin/mainmenu/dlg_server_list_mods.lua +++ b/builtin/mainmenu/dlg_server_list_mods.lua @@ -5,15 +5,42 @@ local function get_formspec(dialogdata) local TOUCH_GUI = core.settings:get_bool("touch_gui") local server = dialogdata.server + local filter_prefix = dialogdata.filter_prefix -- A wrongly behaving server may send ill formed mod names local mods = {} table.sort(server.mods) - for i, m in ipairs(server.mods) do - mods[i] = core.formspec_escape(m) + + if filter_prefix then + for _, mod in ipairs(server.mods) do + if mod:sub(0, #filter_prefix) == filter_prefix then + table.insert(mods, core.formspec_escape(mod)) + end + end + else + local last_prefix + for i, mod in ipairs(server.mods) do + local prefix = mod:match("([^_]*_)") + if prefix and last_prefix == prefix then + mods[#mods] = "#BBBBBB".. core.formspec_escape(prefix) .. "*" + else + table.insert(mods, core.formspec_escape(mod)) + last_prefix = prefix + end + end end + dialogdata.mods = mods mods = table.concat(mods, ",") + local prefix_button_label + if not filter_prefix then + prefix_button_label = "Expand all prefixes" + elseif filter_prefix == "" then + prefix_button_label = "Group by prefix" + else + prefix_button_label = "Show all mods" + end + local formspec = { "formspec_version[8]", "size[6,9.5]", @@ -23,8 +50,9 @@ local function get_formspec(dialogdata) "the following mods:", "" .. core.hypertext_escape(server.name) .. "", "") .. "]", - "textlist[0.5,1.5;5,6.8;;" .. mods .. "]", - "button[1.5,8.5;3,0.8;quit;OK]" + "textlist[0.5,1.5;5,6.8;mods;" .. mods .. "]", + "button[0.5,8.5;3,0.8;prefix;" .. prefix_button_label .. "]", + "button[3.5,8.5;2,0.8;quit;Back]" } return table.concat(formspec, "") end @@ -34,6 +62,27 @@ local function buttonhandler(this, fields) this:delete() return true end + + if fields.mods then + local exploded = core.explode_textlist_event(fields.mods) + if exploded.type == "DCL" then + local match = this.data.mods[exploded.index]:match("#BBBBBB([^_]*_)%*") + if match then + this.data.filter_prefix = match + return true + end + end + end + + if fields.prefix then + if this.data.filter_prefix then + this.data.filter_prefix = nil + else + this.data.filter_prefix = "" + end + return true + end + return false end From 4e74157abde1f882e9584c6238ffecd0c98e561b Mon Sep 17 00:00:00 2001 From: cx384 Date: Sat, 21 Dec 2024 17:05:17 +0100 Subject: [PATCH 3/7] Add > prefix and replace Back by OK --- builtin/mainmenu/dlg_server_list_mods.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/mainmenu/dlg_server_list_mods.lua b/builtin/mainmenu/dlg_server_list_mods.lua index 4957ec7d9..8199cbe20 100644 --- a/builtin/mainmenu/dlg_server_list_mods.lua +++ b/builtin/mainmenu/dlg_server_list_mods.lua @@ -22,7 +22,7 @@ local function get_formspec(dialogdata) for i, mod in ipairs(server.mods) do local prefix = mod:match("([^_]*_)") if prefix and last_prefix == prefix then - mods[#mods] = "#BBBBBB".. core.formspec_escape(prefix) .. "*" + mods[#mods] = "#BBBBBB> ".. core.formspec_escape(prefix) .. "*" else table.insert(mods, core.formspec_escape(mod)) last_prefix = prefix @@ -52,7 +52,7 @@ local function get_formspec(dialogdata) "") .. "]", "textlist[0.5,1.5;5,6.8;mods;" .. mods .. "]", "button[0.5,8.5;3,0.8;prefix;" .. prefix_button_label .. "]", - "button[3.5,8.5;2,0.8;quit;Back]" + "button[3.5,8.5;2,0.8;quit;OK]" } return table.concat(formspec, "") end @@ -66,7 +66,7 @@ local function buttonhandler(this, fields) if fields.mods then local exploded = core.explode_textlist_event(fields.mods) if exploded.type == "DCL" then - local match = this.data.mods[exploded.index]:match("#BBBBBB([^_]*_)%*") + local match = this.data.mods[exploded.index]:match("#BBBBBB> ([^_]*_)%*") if match then this.data.filter_prefix = match return true From 5fed56d6b1a59a6eef47ee6b8b4c6cb9ee30c992 Mon Sep 17 00:00:00 2001 From: cx384 Date: Sat, 21 Dec 2024 17:10:22 +0100 Subject: [PATCH 4/7] =?UTF-8?q?Replace=20>=20by=20=E2=96=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builtin/mainmenu/dlg_server_list_mods.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/mainmenu/dlg_server_list_mods.lua b/builtin/mainmenu/dlg_server_list_mods.lua index 8199cbe20..4d0efdac6 100644 --- a/builtin/mainmenu/dlg_server_list_mods.lua +++ b/builtin/mainmenu/dlg_server_list_mods.lua @@ -22,7 +22,7 @@ local function get_formspec(dialogdata) for i, mod in ipairs(server.mods) do local prefix = mod:match("([^_]*_)") if prefix and last_prefix == prefix then - mods[#mods] = "#BBBBBB> ".. core.formspec_escape(prefix) .. "*" + mods[#mods] = "#BBBBBB▶ ".. core.formspec_escape(prefix) .. "*" else table.insert(mods, core.formspec_escape(mod)) last_prefix = prefix @@ -66,7 +66,7 @@ local function buttonhandler(this, fields) if fields.mods then local exploded = core.explode_textlist_event(fields.mods) if exploded.type == "DCL" then - local match = this.data.mods[exploded.index]:match("#BBBBBB> ([^_]*_)%*") + local match = this.data.mods[exploded.index]:match("#BBBBBB▶ ([^_]*_)%*") if match then this.data.filter_prefix = match return true From 0768becc1f1d6f45b876825c8d17cd5934085f1b Mon Sep 17 00:00:00 2001 From: cx384 Date: Tue, 31 Dec 2024 18:29:35 +0100 Subject: [PATCH 5/7] Add grayed out URL icon --- LICENSE.txt | 1 + builtin/mainmenu/tab_online.lua | 3 +++ textures/base/pack/server_url_unavailable.png | Bin 0 -> 297 bytes 3 files changed, 4 insertions(+) create mode 100644 textures/base/pack/server_url_unavailable.png diff --git a/LICENSE.txt b/LICENSE.txt index 7db690ef2..503dd62d2 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -67,6 +67,7 @@ Zughy: textures/base/pack/settings_info.png textures/base/pack/settings_reset.png textures/base/pack/server_url.png + textures/base/pack/server_url_unavailable.png textures/base/pack/server_view_clients.png textures/base/pack/server_view_clients_unavailable.png diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index 3f64da344..37a469c1e 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -208,6 +208,9 @@ local function get_formspec(tabview, name, tabdata) retval = retval .. "style[btn_server_url;padding=6]" retval = retval .. "image_button[3.5,1.3;0.5,0.5;" .. core.formspec_escape(defaulttexturedir .. "server_url.png") .. ";btn_server_url;]" + else + retval = retval .. "image[3.6,1.4;0.3,0.3;" .. core.formspec_escape(defaulttexturedir .. + "server_url_unavailable.png") .. "]" end -- Favorites toggle button diff --git a/textures/base/pack/server_url_unavailable.png b/textures/base/pack/server_url_unavailable.png new file mode 100644 index 0000000000000000000000000000000000000000..8010ad46941facce593dda42e92298c318757dad GIT binary patch literal 297 zcmeAS@N?(olHy`uVBq!ia0vp^3qY8K8Aw(>tdav#iUB?$u0YyAM=v!#COjx0)X&ey z)eXo63f}+r_586N3nusRGPM7=%Iw#3*i;In|IfLj&@UXRI>qRWVo(_qM+VEWC&4L=Y%C?r%`3|%-8y9^psMiT zyhEyHK@=-caPrh$LA8t6mT+;rU~3bN*82N$#oFm{bt@Yh_9gV_G<{^@c)|D1MAHEb z_9ZYfPIoX}&%G+Mp0Kt>CY1T5d0aK49>4^>bP0l+XkKHk)Un literal 0 HcmV?d00001 From 7eb08cc2eabf5b32eba2d1155edb039ced819a6f Mon Sep 17 00:00:00 2001 From: cx384 Date: Tue, 31 Dec 2024 19:08:00 +0100 Subject: [PATCH 6/7] Group mod with name to corresponding underscore prefix --- builtin/mainmenu/dlg_server_list_mods.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/builtin/mainmenu/dlg_server_list_mods.lua b/builtin/mainmenu/dlg_server_list_mods.lua index 4d0efdac6..78acc07c0 100644 --- a/builtin/mainmenu/dlg_server_list_mods.lua +++ b/builtin/mainmenu/dlg_server_list_mods.lua @@ -11,18 +11,20 @@ local function get_formspec(dialogdata) local mods = {} table.sort(server.mods) - if filter_prefix then + if filter_prefix == true then -- All prefixes + mods = server.mods + elseif filter_prefix then for _, mod in ipairs(server.mods) do - if mod:sub(0, #filter_prefix) == filter_prefix then + if mod == filter_prefix or mod:sub(0, #filter_prefix + 1) == filter_prefix .."_" then table.insert(mods, core.formspec_escape(mod)) end end else local last_prefix for i, mod in ipairs(server.mods) do - local prefix = mod:match("([^_]*_)") + local prefix = mod:match("([^_]*)_") or mod if prefix and last_prefix == prefix then - mods[#mods] = "#BBBBBB▶ ".. core.formspec_escape(prefix) .. "*" + mods[#mods] = "#BBBBBB▶ ".. core.formspec_escape(prefix) else table.insert(mods, core.formspec_escape(mod)) last_prefix = prefix @@ -35,7 +37,7 @@ local function get_formspec(dialogdata) local prefix_button_label if not filter_prefix then prefix_button_label = "Expand all prefixes" - elseif filter_prefix == "" then + elseif filter_prefix == true then prefix_button_label = "Group by prefix" else prefix_button_label = "Show all mods" @@ -66,7 +68,7 @@ local function buttonhandler(this, fields) if fields.mods then local exploded = core.explode_textlist_event(fields.mods) if exploded.type == "DCL" then - local match = this.data.mods[exploded.index]:match("#BBBBBB▶ ([^_]*_)%*") + local match = this.data.mods[exploded.index]:match("#BBBBBB▶ ([^_]*)") if match then this.data.filter_prefix = match return true @@ -78,7 +80,7 @@ local function buttonhandler(this, fields) if this.data.filter_prefix then this.data.filter_prefix = nil else - this.data.filter_prefix = "" + this.data.filter_prefix = true end return true end From 69de96c3e22217ae07aaab9d2bdd7bb665f36437 Mon Sep 17 00:00:00 2001 From: cx384 Date: Tue, 31 Dec 2024 19:17:16 +0100 Subject: [PATCH 7/7] Fix fgettext --- builtin/mainmenu/dlg_server_list_mods.lua | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/builtin/mainmenu/dlg_server_list_mods.lua b/builtin/mainmenu/dlg_server_list_mods.lua index 78acc07c0..f4b4f23c1 100644 --- a/builtin/mainmenu/dlg_server_list_mods.lua +++ b/builtin/mainmenu/dlg_server_list_mods.lua @@ -36,22 +36,28 @@ local function get_formspec(dialogdata) local prefix_button_label if not filter_prefix then - prefix_button_label = "Expand all prefixes" + prefix_button_label = fgettext("Expand all prefixes") elseif filter_prefix == true then - prefix_button_label = "Group by prefix" + prefix_button_label = fgettext("Group by prefix") else - prefix_button_label = "Show all mods" + prefix_button_label = fgettext("Show all mods") + end + + local heading + if server.gameid then + heading = fgettext("The $1 server uses a game called $2 and the following mods:", + "" .. core.hypertext_escape(server.name) .. "", + "") + else + heading = fgettext("The $1 server uses the following mods:", + "" .. core.hypertext_escape(server.name) .. "") end local formspec = { "formspec_version[8]", "size[6,9.5]", TOUCH_GUI and "padding[0.01,0.01]" or "", - "hypertext[0,0;6,1.5;;", - fgettext("The $1 server uses " .. (server.gameid and "a game called $2 and " or "") .. - "the following mods:", - "" .. core.hypertext_escape(server.name) .. "", - "") .. "]", + "hypertext[0,0;6,1.5;;".. heading .. "]", "textlist[0.5,1.5;5,6.8;mods;" .. mods .. "]", "button[0.5,8.5;3,0.8;prefix;" .. prefix_button_label .. "]", "button[3.5,8.5;2,0.8;quit;OK]"