1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-15 13:55:11 -05:00

Implement textarea in formspec, a multiline input field

This commit is contained in:
Jeija 2012-12-28 09:52:21 +01:00 committed by PilzAdam
parent 615fd498bc
commit 46d431e7c3
2 changed files with 49 additions and 32 deletions

View File

@ -725,6 +725,9 @@ field[<name>;<label>;<default>]
^ must be used without a size[] element ^ must be used without a size[] element
^ a 'Proceed' button will be added automatically ^ a 'Proceed' button will be added automatically
textarea[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]
^ same as fields above, but with multi-line input
label[<X>,<Y>;<label>] label[<X>,<Y>;<label>]
^ x and y work as per field ^ x and y work as per field
^ label is the text on the label ^ label is the text on the label

View File

@ -318,13 +318,16 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
errorstream<<"WARNING: invalid use of background without a size[] element"<<std::endl; errorstream<<"WARNING: invalid use of background without a size[] element"<<std::endl;
m_backgrounds.push_back(ImageDrawSpec(name, pos, geom)); m_backgrounds.push_back(ImageDrawSpec(name, pos, geom));
} }
else if(type == "field") else if(type == "field" or type == "textarea")
{ {
std::string fname = f.next(";"); std::string fname = f.next(";");
std::string flabel = f.next(";"); std::string flabel = f.next(";");
if(fname.find(",") == std::string::npos && flabel.find(",") == std::string::npos) if(fname.find(",") == std::string::npos && flabel.find(",") == std::string::npos)
{ {
if (type == "textarea")
errorstream<<"WARNING: Textarea connot be unpositioned"<<std::endl;
if(!bp_set) if(!bp_set)
{ {
rect = core::rect<s32>( rect = core::rect<s32>(
@ -339,7 +342,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
bp_set = 1; bp_set = 1;
} }
else if(bp_set == 2) else if(bp_set == 2)
errorstream<<"WARNING: invalid use of unpositioned field in inventory"<<std::endl; errorstream<<"WARNING: invalid use of unpositioned "<<type<<" in inventory"<<std::endl;
v2s32 pos = basepos; v2s32 pos = basepos;
pos.Y = ((m_fields.size()+2)*60); pos.Y = ((m_fields.size()+2)*60);
@ -353,14 +356,26 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
pos.Y = stof(fname.substr(fname.find(",")+1)) * (float)spacing.Y; pos.Y = stof(fname.substr(fname.find(",")+1)) * (float)spacing.Y;
v2s32 geom; v2s32 geom;
geom.X = (stof(flabel.substr(0,flabel.find(","))) * (float)spacing.X)-(spacing.X-imgsize.X); geom.X = (stof(flabel.substr(0,flabel.find(","))) * (float)spacing.X)-(spacing.X-imgsize.X);
if (type == "textarea")
{
geom.Y = (stof(flabel.substr(flabel.find(",")+1)) * (float)imgsize.Y) - (spacing.Y-imgsize.Y);
pos.Y += 15;
}
else
{
pos.Y += (stof(flabel.substr(flabel.find(",")+1)) * (float)imgsize.Y)/2; pos.Y += (stof(flabel.substr(flabel.find(",")+1)) * (float)imgsize.Y)/2;
pos.Y -= 15;
geom.Y = 30;
}
rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
rect = core::rect<s32>(pos.X, pos.Y-15, pos.X+geom.X, pos.Y+15);
fname = f.next(";"); fname = f.next(";");
flabel = f.next(";"); flabel = f.next(";");
if(bp_set != 2) if(bp_set != 2)
errorstream<<"WARNING: invalid use of positioned field without a size[] element"<<std::endl; errorstream<<"WARNING: invalid use of positioned "<<type<<" without a size[] element"<<std::endl;
} }
@ -381,40 +396,39 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
258+m_fields.size() 258+m_fields.size()
); );
// three cases: field and no label, label and no field, label and field // three cases: field name and no label, label and field, label name and no field
if (flabel == "") gui::IGUIEditBox *e;
if (fname == "")
{ {
spec.send = true; // spec field id to 0, this stops submit searching for a value that isn't there
gui::IGUIElement *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
Environment->setFocus(e);
irr::SEvent evt;
evt.EventType = EET_KEY_INPUT_EVENT;
evt.KeyInput.Key = KEY_END;
evt.KeyInput.PressedDown = true;
e->OnEvent(evt);
}
else if (fname == "")
{
// set spec field id to 0, this stops submit searching for a value that isn't there
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid); Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
} }
else else
{ {
spec.send = true; spec.send = true;
gui::IGUIElement *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid); e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
Environment->setFocus(e); Environment->setFocus(e);
rect.UpperLeftCorner.Y -= 15;
rect.LowerRightCorner.Y -= 15;
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
if (type == "textarea")
{
e->setMultiLine(true);
e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
} else {
irr::SEvent evt; irr::SEvent evt;
evt.EventType = EET_KEY_INPUT_EVENT;
evt.KeyInput.Key = KEY_END; evt.KeyInput.Key = KEY_END;
evt.EventType = EET_KEY_INPUT_EVENT;
evt.KeyInput.PressedDown = true; evt.KeyInput.PressedDown = true;
e->OnEvent(evt); e->OnEvent(evt);
} }
if (flabel != "")
{
rect.UpperLeftCorner.Y -= 15;
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 15;
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
}
}
m_fields.push_back(spec); m_fields.push_back(spec);
} }
else if(type == "label") else if(type == "label")