mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-30 19:22:14 +00:00
add "default" field to pwdfield formspec
This commit is contained in:
parent
fcbf05fc30
commit
825b3011b3
3 changed files with 15 additions and 5 deletions
|
@ -3108,7 +3108,7 @@ Elements
|
|||
(`x` and `y` are used as offset values, `w` and `h` are ignored)
|
||||
* Available since formspec version 2
|
||||
|
||||
### `pwdfield[<X>,<Y>;<W>,<H>;<name>;<label>]`
|
||||
### `pwdfield[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
|
||||
|
||||
* Textual password style field; will be sent to server when a button is clicked
|
||||
* When enter is pressed in field, `fields.key_enter_field` will be sent with the
|
||||
|
@ -3118,6 +3118,10 @@ Elements
|
|||
* `name` is the name of the field as returned in fields to `on_receive_fields`
|
||||
* `label`, if not blank, will be text printed on the top left above the field
|
||||
* See `field_close_on_enter` to stop enter closing the formspec
|
||||
* `default` (optional) is the default value of the password
|
||||
* `default` may contain variable references such as `${text}` which
|
||||
will fill the value from the metadata value `text`
|
||||
* **Note**: no extra text or more than a single variable is supported ATM.
|
||||
|
||||
### `field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ local scroll_fs =
|
|||
"button[0,1;1,1;lorem;Lorem]"..
|
||||
"animated_image[0,1;4.5,1;clip_animated_image;testformspec_animation.png;4;100]" ..
|
||||
"button[0,10;1,1;ipsum;Ipsum]"..
|
||||
"pwdfield[2,2;1,1;lorem2;Lorem]"..
|
||||
"pwdfield[2,2;1,1;lorem2;Lorem;password]"..
|
||||
"list[current_player;main;4,4;1,5;]"..
|
||||
"box[2,5;3,2;#ffff00]"..
|
||||
"image[1,10;3,2;testformspec_item.png]"..
|
||||
|
@ -349,7 +349,7 @@ local pages = {
|
|||
item_image_button[0,6;1,1;testformspec:node;rc_item_image_button_1x1;1x1]
|
||||
item_image_button[1,6;2,2;testformspec:node;rc_item_image_button_2x2;2x2]
|
||||
field[3,.5;3,.5;rc_field;Field;text]
|
||||
pwdfield[6,.5;3,1;rc_pwdfield;Password Field]
|
||||
pwdfield[6,.5;3,1;rc_pwdfield;Password Field;password]
|
||||
field[3,1;3,1;;Read-Only Field;text]
|
||||
textarea[3,2;3,.5;rc_textarea_small;Textarea;text]
|
||||
textarea[6,2;3,2;rc_textarea_big;Textarea;text\nmore text]
|
||||
|
|
|
@ -1441,13 +1441,16 @@ void GUIFormSpecMenu::parseFieldCloseOnEnter(parserData *data, const std::string
|
|||
void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element)
|
||||
{
|
||||
std::vector<std::string> parts;
|
||||
if (!precheckElement("pwdfield", element, 4, 4, parts))
|
||||
if (!precheckElement("pwdfield", element, 4, 5, parts))
|
||||
return;
|
||||
|
||||
std::vector<std::string> v_pos = split(parts[0],',');
|
||||
std::vector<std::string> v_geom = split(parts[1],',');
|
||||
std::string name = parts[2];
|
||||
std::string label = parts[3];
|
||||
std::string default_val = "";
|
||||
if(parts.size() == 5) // If the field has a default value (for backwards compatibility)
|
||||
default_val = parts[4];
|
||||
|
||||
MY_CHECKPOS("pwdfield",0);
|
||||
MY_CHECKGEOM("pwdfield",1);
|
||||
|
@ -1469,6 +1472,9 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element
|
|||
geom.Y = m_btn_height*2;
|
||||
}
|
||||
|
||||
if(m_form_src)
|
||||
default_val = m_form_src->resolveText(default_val);
|
||||
|
||||
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
||||
|
||||
std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label)));
|
||||
|
@ -1483,7 +1489,7 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element
|
|||
);
|
||||
|
||||
spec.send = true;
|
||||
gui::IGUIEditBox *e = Environment->addEditBox(0, rect, true,
|
||||
gui::IGUIEditBox *e = Environment->addEditBox(utf8_to_wide(unescape_string(default_val)).c_str(), rect, true,
|
||||
data->current_parent, spec.fid);
|
||||
|
||||
if (spec.fname == m_focused_element) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue