From 14fa03172d5940d6358c17d3ad962ad822873fce Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 6 Jun 2024 13:45:14 +0200 Subject: [PATCH] Supertip: Make static position argument mandatory --- doc/lua_api.md | 14 ++++++++------ games/devtest/mods/testformspec/formspec.lua | 6 +++--- src/gui/guiFormSpecMenu.cpp | 19 +++++++++---------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 5a51673a0..d28aa5c92 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -2849,13 +2849,15 @@ Elements * `bgcolor` tooltip background color as `ColorString` (optional) * `fontcolor` tooltip font color as `ColorString` (optional) -### `supertip[,;,;,;;;]` +### `supertip[,;,;;;;]` -* Displays a formatted text using `Markup Language` in a tooltip. -* `x`, `y`, `w` and `h` set the mouse hover area that allows the tooltip to pop-up. -* `posX` and `posY` set the static positioning of the tooltip (optional). - If not set, the tooltip is floating (moving with the pointer). -* `width` sets the tooltip width. +* Adds an advanced tooltip for an area. Displays a formatted text using + `Markup Language` in a tooltip. +* `X`, `Y`, `W` and `H` set the cursor hover area that allows the tooltip to pop-up. +* `staticPos` is an optional position of the form `posX,posY` in formspec coordinates. + If specified, the tooltip will always appear at these given formspec coordinates. + If this field is empty, the tooltip will follow the cursor. +* `width` sets the tooltip width (in formspec units). * `name` is the name of the field. * `text` is the formatted text using `Markup Language` described below. diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua index f6450e97a..d31a0cf07 100644 --- a/games/devtest/mods/testformspec/formspec.lua +++ b/games/devtest/mods/testformspec/formspec.lua @@ -483,11 +483,11 @@ mouse control = true] supertip[1,3;1,1;2.5,3.5;5;supertip_static;Simple supertip (static) This one should always appear at the tiny white square.] box[1,5;1,1;#ff000080] - supertip[1,5;1,1;5;supertip_dynamic;Simple supertip (dynamic) + supertip[1,5;1,1;;5;supertip_dynamic;Simple supertip (dynamic) This should appear at the cursor.] box[1,7;1,1;#ff000080] - supertip[1,7;1,1;5;supertip_dynamic_complex;]]..minetest.formspec_escape([[Complex supertip (dynamic) + supertip[1,7;1,1;;5;supertip_dynamic_complex;]]..minetest.formspec_escape([[Complex supertip (dynamic) Left align
Right align
@@ -497,7 +497,7 @@ Item: ]])..[[] box[1,9;1,1;#ff000080] - supertip[1,9;1,1;5;supertip_stone;]]..minetest.formspec_escape([[ + supertip[1,9;1,1;;5;supertip_stone;]]..minetest.formspec_escape([[
Formspec Test Node
The Formspec Test Node is a dummy node to display an item in the testformspec mod. diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 3524821ab..567a8ce59 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -1756,24 +1756,23 @@ void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &elemen void GUIFormSpecMenu::parseSuperTip(parserData *data, const std::string &element) { - constexpr char max_parts = 6; std::vector parts; - if (!precheckElement("supertip", element, 5, max_parts, parts)) + if (!precheckElement("supertip", element, 6, 6, parts)) return; - std::vector v_stpos; std::vector v_pos = split(parts[0], ','); std::vector v_geom = split(parts[1], ','); - bool floating = parts.size() == max_parts - 1; - - if (!floating) + std::vector v_stpos; + bool floating = true; + if(parts[2] != "") { v_stpos = split(parts[2], ','); + floating = false; + } - const char i = max_parts - parts.size(); - s32 width = stof(parts[3-i]) * spacing.Y; - std::string name = parts[4-i]; - std::string text = parts[5-i]; + s32 width = stof(parts[3]) * spacing.Y; + std::string name = parts[4]; + std::string text = parts[5]; MY_CHECKPOS("supertip", 0); MY_CHECKGEOM("supertip", 1);