From 24cc33e7046fc4b90bf8e1b2fd2546c699fc6eee Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 24 Mar 2024 17:19:23 +0000 Subject: [PATCH] Add button_url[] and hypertext element to allow mods to open web pages (#13825) Fixes #12500 --- builtin/mainmenu/tab_about.lua | 6 +- doc/lua_api.md | 19 ++ games/devtest/mods/testformspec/formspec.lua | 8 +- src/client/game.cpp | 7 + src/gui/CMakeLists.txt | 1 + src/gui/guiFormSpecMenu.cpp | 23 ++- src/gui/guiFormSpecMenu.h | 1 + src/gui/guiHyperText.cpp | 14 ++ src/gui/guiOpenURL.cpp | 196 +++++++++++++++++++ src/gui/guiOpenURL.h | 50 +++++ src/gui/mainmenumanager.h | 19 +- src/unittest/test_utilities.cpp | 19 ++ src/util/CMakeLists.txt | 1 + src/util/colorize.cpp | 113 +++++++++++ src/util/colorize.h | 34 ++++ src/util/string.cpp | 34 ++++ src/util/string.h | 22 +-- 17 files changed, 530 insertions(+), 37 deletions(-) create mode 100644 src/gui/guiOpenURL.cpp create mode 100644 src/gui/guiOpenURL.h create mode 100644 src/util/colorize.cpp create mode 100644 src/util/colorize.h diff --git a/builtin/mainmenu/tab_about.lua b/builtin/mainmenu/tab_about.lua index 8c5573399..1805acc81 100644 --- a/builtin/mainmenu/tab_about.lua +++ b/builtin/mainmenu/tab_about.lua @@ -158,7 +158,7 @@ return { "style[label_button;border=false]" .. "button[0.1,3.4;5.3,0.5;label_button;" .. core.formspec_escape(version.project .. " " .. version.string) .. "]" .. - "button[1.5,4.1;2.5,0.8;homepage;minetest.net]" .. + "button_url[1.5,4.1;2.5,0.8;homepage;minetest.net;https://www.minetest.net/]" .. "hypertext[5.5,0.25;9.75,6.6;credits;" .. minetest.formspec_escape(hypertext) .. "]" -- Render information @@ -188,10 +188,6 @@ return { end, cbf_button_handler = function(this, fields, name, tabdata) - if fields.homepage then - core.open_url("https://www.minetest.net") - end - if fields.share_debug then local path = core.get_user_path() .. DIR_DELIM .. "debug.txt" core.share_file(path) diff --git a/doc/lua_api.md b/doc/lua_api.md index b0bcdf34e..3a2e1f47d 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -3017,6 +3017,16 @@ Elements centered on `H`. With the new coordinate system, `H` will modify the height. * `label` is the text on the button +### `button_url[,;,;;