mirror of
https://github.com/minetest/minetest.git
synced 2025-07-04 00:40:24 +02:00
Android: Add selection dialog (drop down/combo box) (#13814)
- The handling of IGUIComboBox uses the new setAndSendSelected() method. - getDialogState() is now getInputDialogState() and returns the state of the input dialog. - getLastDialogType() is added and returns current/last shown dialog's type. - getInputDialogState() now returns an enum instead of int. - getAndroidUIInput() now returns void instead of bool. - New data types (enum) are added: (1) GameActivity.DialogType (Java) and porting::AndroidDialogType (C++) (2) GameActivity.DialogState (Java) and porting::AndroidDialogState (C++) - When showing a text input dialog, there is no custom accept button text any more. - showDialog()/showDialogUI() for text input is now showTextInputDialog()/showTextInputDialogUI(). - showInputDialog()/showDialogUI() for text input is now showTextInputDialog()/showTextInputDialogUI(). - getDialogValue()/getInputDialogValue() is now getDialogMessage()/getInputDialogMessage(). Co-authored-by: Gregor Parzefall <82708541+grorp@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
bd42cc2c77
commit
171f911237
@ -3497,46 +3497,58 @@ void GUIFormSpecMenu::legacySortElements(std::list<IGUIElement *>::iterator from
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
bool GUIFormSpecMenu::getAndroidUIInput()
|
||||
void GUIFormSpecMenu::getAndroidUIInput()
|
||||
{
|
||||
if (!hasAndroidUIInput())
|
||||
return false;
|
||||
porting::AndroidDialogState dialogState = getAndroidUIInputState();
|
||||
if (dialogState == porting::DIALOG_SHOWN) {
|
||||
return;
|
||||
} else if (dialogState == porting::DIALOG_CANCELED) {
|
||||
m_jni_field_name.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// still waiting
|
||||
if (porting::getInputDialogState() == -1)
|
||||
return true;
|
||||
porting::AndroidDialogType dialog_type = porting::getLastInputDialogType();
|
||||
|
||||
std::string fieldname = m_jni_field_name;
|
||||
m_jni_field_name.clear();
|
||||
|
||||
for (const FieldSpec &field : m_fields) {
|
||||
if (field.fname != fieldname)
|
||||
continue;
|
||||
continue; // Iterate until found
|
||||
|
||||
IGUIElement *element = getElementFromId(field.fid, true);
|
||||
|
||||
if (!element || element->getType() != irr::gui::EGUIET_EDIT_BOX)
|
||||
return false;
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
gui::IGUIEditBox *editbox = (gui::IGUIEditBox *)element;
|
||||
std::string text = porting::getInputDialogValue();
|
||||
editbox->setText(utf8_to_wide(text).c_str());
|
||||
auto element_type = element->getType();
|
||||
if (dialog_type == porting::TEXT_INPUT && element_type == irr::gui::EGUIET_EDIT_BOX) {
|
||||
gui::IGUIEditBox *editbox = (gui::IGUIEditBox *)element;
|
||||
std::string text = porting::getInputDialogMessage();
|
||||
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);
|
||||
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);
|
||||
}
|
||||
} else if (dialog_type == porting::SELECTION_INPUT &&
|
||||
element_type == irr::gui::EGUIET_COMBO_BOX) {
|
||||
auto dropdown = (gui::IGUIComboBox *) element;
|
||||
int selected = porting::getInputDialogSelection();
|
||||
dropdown->setAndSendSelected(selected);
|
||||
}
|
||||
|
||||
return; // Early-return after found
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -286,7 +286,7 @@ public:
|
||||
core::rect<s32> getAbsoluteRect();
|
||||
|
||||
#ifdef __ANDROID__
|
||||
bool getAndroidUIInput();
|
||||
void getAndroidUIInput();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
@ -264,14 +264,19 @@ std::string GUIPasswordChange::getNameByID(s32 id)
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
bool GUIPasswordChange::getAndroidUIInput()
|
||||
void GUIPasswordChange::getAndroidUIInput()
|
||||
{
|
||||
if (!hasAndroidUIInput())
|
||||
return false;
|
||||
porting::AndroidDialogState dialogState = getAndroidUIInputState();
|
||||
if (dialogState == porting::DIALOG_SHOWN) {
|
||||
return;
|
||||
} else if (dialogState == porting::DIALOG_CANCELED) {
|
||||
m_jni_field_name.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// still waiting
|
||||
if (porting::getInputDialogState() == -1)
|
||||
return true;
|
||||
// It has to be a text input
|
||||
if (porting::getLastInputDialogType() != porting::TEXT_INPUT)
|
||||
return;
|
||||
|
||||
gui::IGUIElement *e = nullptr;
|
||||
if (m_jni_field_name == "old_password")
|
||||
@ -283,10 +288,10 @@ bool GUIPasswordChange::getAndroidUIInput()
|
||||
m_jni_field_name.clear();
|
||||
|
||||
if (!e || e->getType() != irr::gui::EGUIET_EDIT_BOX)
|
||||
return false;
|
||||
return;
|
||||
|
||||
std::string text = porting::getInputDialogValue();
|
||||
std::string text = porting::getInputDialogMessage();
|
||||
e->setText(utf8_to_wide(text).c_str());
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
|
||||
bool OnEvent(const SEvent &event);
|
||||
#ifdef __ANDROID__
|
||||
bool getAndroidUIInput();
|
||||
void getAndroidUIInput();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
@ -268,11 +268,34 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
|
||||
if (((gui::IGUIEditBox *)hovered)->isPasswordBox())
|
||||
type = 3;
|
||||
|
||||
porting::showInputDialog(gettext("OK"), "",
|
||||
wide_to_utf8(((gui::IGUIEditBox *)hovered)->getText()), type);
|
||||
porting::showTextInputDialog("",
|
||||
wide_to_utf8(((gui::IGUIEditBox *) hovered)->getText()), type);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.EventType == EET_GUI_EVENT) {
|
||||
if (event.GUIEvent.EventType == gui::EGET_LISTBOX_OPENED) {
|
||||
gui::IGUIComboBox *dropdown = (gui::IGUIComboBox *) event.GUIEvent.Caller;
|
||||
|
||||
std::string field_name = getNameByID(dropdown->getID());
|
||||
if (field_name.empty())
|
||||
return false;
|
||||
|
||||
m_jni_field_name = field_name;
|
||||
|
||||
s32 selected_idx = dropdown->getSelected();
|
||||
s32 option_size = dropdown->getItemCount();
|
||||
std::string list_of_options[option_size];
|
||||
|
||||
for (s32 i = 0; i < option_size; i++) {
|
||||
list_of_options[i] = wide_to_utf8(dropdown->getItem(i));
|
||||
}
|
||||
|
||||
porting::showComboBoxDialog(list_of_options, option_size, selected_idx);
|
||||
return true; // Prevent the Irrlicht dropdown from opening.
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Convert touch events into mouse events.
|
||||
@ -347,22 +370,12 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
bool GUIModalMenu::hasAndroidUIInput()
|
||||
porting::AndroidDialogState GUIModalMenu::getAndroidUIInputState()
|
||||
{
|
||||
// no dialog shown
|
||||
// No dialog is shown
|
||||
if (m_jni_field_name.empty())
|
||||
return false;
|
||||
return porting::DIALOG_CANCELED;
|
||||
|
||||
// still waiting
|
||||
if (porting::getInputDialogState() == -1)
|
||||
return true;
|
||||
|
||||
// no value abort dialog processing
|
||||
if (porting::getInputDialogState() != 0) {
|
||||
m_jni_field_name.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return porting::getInputDialogState();
|
||||
}
|
||||
#endif
|
||||
|
@ -22,6 +22,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "irrlichttypes_extrabloated.h"
|
||||
#include "irr_ptr.h"
|
||||
#include "util/string.h"
|
||||
#ifdef __ANDROID__
|
||||
#include <porting_android.h>
|
||||
#endif
|
||||
|
||||
enum class PointerType {
|
||||
Mouse,
|
||||
@ -59,8 +62,8 @@ public:
|
||||
virtual bool OnEvent(const SEvent &event) { return false; };
|
||||
virtual bool pausesGame() { return false; } // Used for pause menu
|
||||
#ifdef __ANDROID__
|
||||
virtual bool getAndroidUIInput() { return false; }
|
||||
bool hasAndroidUIInput();
|
||||
virtual void getAndroidUIInput() {};
|
||||
porting::AndroidDialogState getAndroidUIInputState();
|
||||
#endif
|
||||
|
||||
PointerType getPointerType() { return m_pointer_type; };
|
||||
|
Reference in New Issue
Block a user