Supertip: Make static position argument mandatory

This commit is contained in:
Wuzzy 2024-06-06 13:45:14 +02:00
parent b3c06bb9e5
commit 14fa03172d
3 changed files with 20 additions and 19 deletions

@ -2849,13 +2849,15 @@ Elements
* `bgcolor` tooltip background color as `ColorString` (optional)
* `fontcolor` tooltip font color as `ColorString` (optional)
### `supertip[<X>,<Y>;<W>,<H>;<posX>,<posY>;<width>;<name>;<text>]`
### `supertip[<X>,<Y>;<W>,<H>;<staticPos>;<width>;<name>;<text>]`
* 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.

@ -483,11 +483,11 @@ mouse control = true]
supertip[1,3;1,1;2.5,3.5;5;supertip_static;<big>Simple supertip (<i>static</i>)</big>
This one should always appear at the tiny white square.]
box[1,5;1,1;#ff000080]
supertip[1,5;1,1;5;supertip_dynamic;<big>Simple supertip (<i>dynamic</i>)</big>
supertip[1,5;1,1;;5;supertip_dynamic;<big>Simple supertip (<i>dynamic</i>)</big>
This should appear at the cursor.]
box[1,7;1,1;#ff000080]
supertip[1,7;1,1;5;supertip_dynamic_complex;]]..minetest.formspec_escape([[<big>Complex supertip (<i>dynamic</i>)</big>
supertip[1,7;1,1;;5;supertip_dynamic_complex;]]..minetest.formspec_escape([[<big>Complex supertip (<i>dynamic</i>)</big>
<img name=testformspec_node.png float=right width=64 height=64>
<left>Left align</left>
<center>Right align</center>
@ -497,7 +497,7 @@ Item:
<item name=testformspec:node>]])..[[]
box[1,9;1,1;#ff000080]
supertip[1,9;1,1;5;supertip_stone;]]..minetest.formspec_escape([[<global color=#333 background=#aaa margin=20>
supertip[1,9;1,1;;5;supertip_stone;]]..minetest.formspec_escape([[<global color=#333 background=#aaa margin=20>
<item name=testformspec:node float=left width=64 height=64>
<big><b><center>Formspec Test Node</center></b></big>
The <b>Formspec Test Node</b> is a dummy node to display an item in the <mono>testformspec</mono> mod.

@ -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<std::string> parts;
if (!precheckElement("supertip", element, 5, max_parts, parts))
if (!precheckElement("supertip", element, 6, 6, parts))
return;
std::vector<std::string> v_stpos;
std::vector<std::string> v_pos = split(parts[0], ',');
std::vector<std::string> v_geom = split(parts[1], ',');
bool floating = parts.size() == max_parts - 1;
if (!floating)
std::vector<std::string> 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);