X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fgui%2FguiConfirmRegistration.cpp;h=9a374b405e6782628677ec82c53c25360d0b2974;hb=2ae794ac4548b13e80f16455980522d8d39da07d;hp=3e6fd96c27d5e8df8fb765923e0fb6dbf5c60319;hpb=57418111a8352f2d6dabf1d3e43c1719f4b118c0;p=minetest.git diff --git a/src/gui/guiConfirmRegistration.cpp b/src/gui/guiConfirmRegistration.cpp index 3e6fd96c2..9a374b405 100644 --- a/src/gui/guiConfirmRegistration.cpp +++ b/src/gui/guiConfirmRegistration.cpp @@ -19,13 +19,13 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "guiConfirmRegistration.h" -#include "client.h" -#include "intlGUIEditBox.h" +#include "client/client.h" #include -#include #include #include #include +#include "intlGUIEditBox.h" +#include "porting.h" #include "gettext.h" @@ -43,6 +43,9 @@ GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env, m_client(client), m_playername(playername), m_password(password), m_address(address), m_aborted(aborted) { +#ifdef __ANDROID__ + m_touchscreen_visible = false; +#endif } GUIConfirmRegistration::~GUIConfirmRegistration() @@ -67,13 +70,16 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize) /* Calculate new sizes and positions */ - core::rect rect(screensize.X / 2 - 600 / 2, screensize.Y / 2 - 360 / 2, - screensize.X / 2 + 600 / 2, screensize.Y / 2 + 360 / 2); - - DesiredRect = rect; + const float s = m_gui_scale; + DesiredRect = core::rect( + screensize.X / 2 - 600 * s / 2, + screensize.Y / 2 - 360 * s / 2, + screensize.X / 2 + 600 * s / 2, + screensize.Y / 2 + 360 * s / 2 + ); recalculateAbsolutePosition(false); - v2s32 size = rect.getSize(); + v2s32 size = DesiredRect.getSize(); v2s32 topleft_client(0, 0); const wchar_t *text; @@ -81,13 +87,13 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize) /* Add stuff */ - s32 ypos = 30; + s32 ypos = 30 * s; { std::string address = m_address; if (address.empty()) address = "localhost"; - core::rect rect(0, 0, 540, 180); - rect += topleft_client + v2s32(30, ypos); + core::rect rect2(0, 0, 540 * s, 180 * s); + rect2 += topleft_client + v2s32(30 * s, ypos); static const std::string info_text_template = strgettext( "You are about to join the server at %1$s with the " "name \"%2$s\" for the first time. If you proceed, a " @@ -97,48 +103,50 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize) "Join to confirm account creation or click Cancel to " "abort."); char info_text_buf[1024]; - snprintf(info_text_buf, sizeof(info_text_buf), info_text_template.c_str(), - address.c_str(), m_playername.c_str()); + porting::mt_snprintf(info_text_buf, sizeof(info_text_buf), + info_text_template.c_str(), address.c_str(), + m_playername.c_str()); - gui::intlGUIEditBox *e = new gui::intlGUIEditBox( - utf8_to_wide_c(info_text_buf), true, Environment, this, - ID_message, rect, false, true); + wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf); + gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true, + Environment, this, ID_message, rect2, false, true); + delete[] info_text_buf_wide; e->drop(); e->setMultiLine(true); e->setWordWrap(true); e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER); } - ypos += 210; + ypos += 210 * s; { - core::rect rect(0, 0, 540, 30); - rect += topleft_client + v2s32(30, ypos); + core::rect rect2(0, 0, 540 * s, 30 * s); + rect2 += topleft_client + v2s32(30 * s, ypos); gui::IGUIEditBox *e = Environment->addEditBox(m_pass_confirm.c_str(), - rect, true, this, ID_confirmPassword); + rect2, true, this, ID_confirmPassword); e->setPasswordBox(true); } - ypos += 60; + ypos += 60 * s; { - core::rect rect(0, 0, 230, 35); - rect = rect + v2s32(size.X / 2 - 220, ypos); + core::rect rect2(0, 0, 230 * s, 35 * s); + rect2 = rect2 + v2s32(size.X / 2 - 220 * s, ypos); text = wgettext("Register and Join"); - Environment->addButton(rect, this, ID_confirm, text); + Environment->addButton(rect2, this, ID_confirm, text); delete[] text; } { - core::rect rect(0, 0, 120, 35); - rect = rect + v2s32(size.X / 2 + 70, ypos); + core::rect rect2(0, 0, 120 * s, 35 * s); + rect2 = rect2 + v2s32(size.X / 2 + 70 * s, ypos); text = wgettext("Cancel"); - Environment->addButton(rect, this, ID_cancel, text); + Environment->addButton(rect2, this, ID_cancel, text); delete[] text; } { - core::rect rect(0, 0, 200, 20); - rect += topleft_client + v2s32(30, ypos - 40); + core::rect rect2(0, 0, 200 * s, 20 * s); + rect2 += topleft_client + v2s32(30 * s, ypos - 40 * s); text = wgettext("Passwords do not match!"); IGUIElement *e = Environment->addStaticText( - text, rect, false, true, this, ID_message); + text, rect2, false, true, this, ID_message); e->setVisible(false); delete[] text; } @@ -155,17 +163,20 @@ void GUIConfirmRegistration::drawMenu() driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); gui::IGUIElement::draw(); +#ifdef __ANDROID__ + getAndroidUIInput(); +#endif } void GUIConfirmRegistration::closeMenu(bool goNext) { - quitMenu(); if (goNext) { m_client->confirmRegistration(); } else { *m_aborted = true; infostream << "Connect aborted [Escape]" << std::endl; } + quitMenu(); } void GUIConfirmRegistration::acceptInput() @@ -191,10 +202,14 @@ bool GUIConfirmRegistration::processInput() bool GUIConfirmRegistration::OnEvent(const SEvent &event) { if (event.EventType == EET_KEY_INPUT_EVENT) { - if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) { + // clang-format off + if ((event.KeyInput.Key == KEY_ESCAPE || + event.KeyInput.Key == KEY_CANCEL) && + event.KeyInput.PressedDown) { closeMenu(false); return true; } + // clang-format on if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) { acceptInput(); if (processInput()) @@ -237,3 +252,19 @@ bool GUIConfirmRegistration::OnEvent(const SEvent &event) return false; } + +#ifdef __ANDROID__ +bool GUIConfirmRegistration::getAndroidUIInput() +{ + if (!hasAndroidUIInput() || m_jni_field_name != "password") + return false; + + std::string text = porting::getInputDialogValue(); + gui::IGUIElement *e = getElementFromId(ID_confirmPassword); + if (e) + e->setText(utf8_to_wide(text).c_str()); + + m_jni_field_name.clear(); + return false; +} +#endif