1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Allow fields to choose whether they close on enter press

This commit is contained in:
rubenwardy 2016-08-07 16:22:50 +01:00
parent 4330c63ea4
commit e10fee0001
3 changed files with 45 additions and 13 deletions

View file

@ -894,8 +894,8 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';');
if ((parts.size() == 4) ||
((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION)))
if ((parts.size() == 4) || (parts.size() == 5) ||
((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
{
std::vector<std::string> v_pos = split(parts[0],',');
std::vector<std::string> v_geom = split(parts[1],',');
@ -952,6 +952,11 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element)
evt.KeyInput.Shift = 0;
evt.KeyInput.PressedDown = true;
e->OnEvent(evt);
if (parts.size() >= 5 && !is_yes(parts[4])) {
spec.close_on_enter = false;
}
m_fields.push_back(spec);
return;
}
@ -1033,6 +1038,10 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
}
}
if (parts.size() >= 4 && !is_yes(parts[3])) {
spec.close_on_enter = false;
}
m_fields.push_back(spec);
}
@ -1137,6 +1146,11 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,
addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
}
}
if (parts.size() >= 6 && !is_yes(parts[5])) {
spec.close_on_enter = false;
}
m_fields.push_back(spec);
}
@ -1150,8 +1164,8 @@ void GUIFormSpecMenu::parseField(parserData* data,std::string element,
return;
}
if ((parts.size() == 5) ||
((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
if ((parts.size() == 5) || (parts.size() == 6) ||
((parts.size() > 6) && (m_formspec_version > FORMSPEC_API_VERSION)))
{
parseTextArea(data,parts,type);
return;
@ -2698,6 +2712,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
if (!current_field_enter_pending.empty()) {
fields["key_enter_field"] = current_field_enter_pending;
current_field_enter_pending = "";
}
if (current_keys_pending.key_escape) {
@ -3630,15 +3645,18 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
if (event.GUIEvent.Caller->getID() > 257) {
bool close_on_enter = true;
for (u32 i = 0; i < m_fields.size(); i++) {
FieldSpec &s = m_fields[i];
if (s.ftype == f_Unknown &&
s.fid == event.GUIEvent.Caller->getID()) {
current_field_enter_pending = s.fname;
close_on_enter = s.close_on_enter;
break;
}
}
if (m_allowclose) {
if (m_allowclose && close_on_enter) {
current_keys_pending.key_enter = true;
acceptInput(quit_mode_accept);
quitMenu();

View file

@ -202,20 +202,22 @@ class GUIFormSpecMenu : public GUIModalMenu
FieldSpec(const std::string &name, const std::wstring &label,
const std::wstring &default_text, int id) :
fname(name),
fid(id)
flabel(label),
fid(id),
send(false),
close_on_enter(false),
ftype(f_Unknown),
is_exit(false)
{
//flabel = unescape_enriched(label);
flabel = label;
fdefault = unescape_enriched(default_text);
send = false;
ftype = f_Unknown;
is_exit = false;
}
std::string fname;
std::wstring flabel;
std::wstring fdefault;
int fid;
bool send;
bool close_on_enter; // used by text fields
FormspecFieldType ftype;
bool is_exit;
core::rect<s32> rect;