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

Android: Add field_enter_after_edit[] formspec element (#13836)

This commit is contained in:
Gregor Parzefall 2023-10-01 11:20:50 +02:00 committed by GitHub
parent 94eba15c34
commit 56965bc814
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 56 additions and 8 deletions

View file

@ -1379,6 +1379,15 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element
}
}
void GUIFormSpecMenu::parseFieldEnterAfterEdit(parserData *data, const std::string &element)
{
std::vector<std::string> parts;
if (!precheckElement("field_enter_after_edit", element, 2, 2, parts))
return;
field_enter_after_edit[parts[0]] = is_yes(parts[1]);
}
void GUIFormSpecMenu::parseFieldCloseOnEnter(parserData *data, const std::string &element)
{
std::vector<std::string> parts;
@ -2903,6 +2912,11 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
return;
}
if (type == "field_enter_after_edit") {
parseFieldEnterAfterEdit(data, description);
return;
}
if (type == "field_close_on_enter") {
parseFieldCloseOnEnter(data, description);
return;
@ -3082,6 +3096,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
theme_by_name.clear();
theme_by_type.clear();
m_clickthrough_elements.clear();
field_enter_after_edit.clear();
field_close_on_enter.clear();
m_dropdown_index_event.clear();
@ -3480,8 +3495,23 @@ bool GUIFormSpecMenu::getAndroidUIInput()
if (!element || element->getType() != irr::gui::EGUIET_EDIT_BOX)
return false;
gui::IGUIEditBox *editbox = (gui::IGUIEditBox *)element;
std::string text = porting::getInputDialogValue();
((gui::IGUIEditBox *)element)->setText(utf8_to_wide(text).c_str());
editbox->setText(utf8_to_wide(text).c_str());
bool enter_after_edit = false;
auto iter = field_enter_after_edit.find(fieldname);
if (iter != field_enter_after_edit.end()) {
enter_after_edit = iter->second;
}
if (enter_after_edit && editbox->getParent()) {
SEvent enter;
enter.EventType = EET_GUI_EVENT;
enter.GUIEvent.Caller = editbox;
enter.GUIEvent.Element = nullptr;
enter.GUIEvent.EventType = gui::EGET_EDITBOX_ENTER;
editbox->getParent()->OnEvent(enter);
}
}
return false;
}

View file

@ -331,6 +331,7 @@ protected:
std::vector<GUIInventoryList *> m_inventorylists;
std::vector<ListRingSpec> m_inventory_rings;
std::unordered_map<std::string, bool> field_enter_after_edit;
std::unordered_map<std::string, bool> field_close_on_enter;
std::unordered_map<std::string, bool> m_dropdown_index_event;
std::vector<FieldSpec> m_fields;
@ -448,6 +449,7 @@ private:
void parseTable(parserData* data, const std::string &element);
void parseTextList(parserData* data, const std::string &element);
void parseDropDown(parserData* data, const std::string &element);
void parseFieldEnterAfterEdit(parserData *data, const std::string &element);
void parseFieldCloseOnEnter(parserData *data, const std::string &element);
void parsePwdField(parserData* data, const std::string &element);
void parseField(parserData* data, const std::string &element, const std::string &type);

View file

@ -241,7 +241,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// base64-encoded SHA-1 (27+\0).
// See also formspec [Version History] in doc/lua_api.md
#define FORMSPEC_API_VERSION 6
#define FORMSPEC_API_VERSION 7
#define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"