2018-01-13 12:07:16 +01:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2018 srifqi, Muhammad Rifqi Priyo Susanto
|
|
|
|
<muhammadrifqipriyosusanto@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "guiConfirmRegistration.h"
|
2018-11-28 20:01:49 +01:00
|
|
|
#include "client/client.h"
|
2019-10-12 18:44:23 +02:00
|
|
|
#include "guiButton.h"
|
2018-01-13 12:07:16 +01:00
|
|
|
#include <IGUICheckBox.h>
|
|
|
|
#include <IGUIButton.h>
|
|
|
|
#include <IGUIStaticText.h>
|
|
|
|
#include <IGUIFont.h>
|
2018-03-11 17:45:58 +01:00
|
|
|
#include "intlGUIEditBox.h"
|
2018-07-22 21:56:06 +02:00
|
|
|
#include "porting.h"
|
2018-01-13 12:07:16 +01:00
|
|
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
// Continuing from guiPasswordChange.cpp
|
|
|
|
const int ID_confirmPassword = 262;
|
|
|
|
const int ID_confirm = 263;
|
2019-12-09 20:01:16 +01:00
|
|
|
const int ID_intotext = 264;
|
2018-01-13 12:07:16 +01:00
|
|
|
const int ID_cancel = 265;
|
2019-12-09 20:01:16 +01:00
|
|
|
const int ID_message = 266;
|
2018-01-13 12:07:16 +01:00
|
|
|
|
|
|
|
GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env,
|
|
|
|
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, Client *client,
|
|
|
|
const std::string &playername, const std::string &password,
|
2020-04-11 22:39:30 +02:00
|
|
|
bool *aborted, ISimpleTextureSource *tsrc) :
|
2018-01-13 12:07:16 +01:00
|
|
|
GUIModalMenu(env, parent, id, menumgr),
|
|
|
|
m_client(client), m_playername(playername), m_password(password),
|
2020-04-11 22:39:30 +02:00
|
|
|
m_aborted(aborted), m_tsrc(tsrc)
|
2018-01-13 12:07:16 +01:00
|
|
|
{
|
2018-06-24 21:50:57 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
m_touchscreen_visible = false;
|
|
|
|
#endif
|
2018-01-13 12:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GUIConfirmRegistration::~GUIConfirmRegistration()
|
|
|
|
{
|
|
|
|
removeChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIConfirmRegistration::removeChildren()
|
|
|
|
{
|
|
|
|
const core::list<gui::IGUIElement *> &children = getChildren();
|
|
|
|
core::list<gui::IGUIElement *> children_copy;
|
|
|
|
for (gui::IGUIElement *i : children)
|
|
|
|
children_copy.push_back(i);
|
|
|
|
for (gui::IGUIElement *i : children_copy)
|
|
|
|
i->remove();
|
|
|
|
}
|
2019-08-07 19:15:46 +02:00
|
|
|
|
2018-01-13 12:07:16 +01:00
|
|
|
void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
|
|
|
|
{
|
|
|
|
acceptInput();
|
|
|
|
removeChildren();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Calculate new sizes and positions
|
|
|
|
*/
|
2018-11-26 22:55:24 +01:00
|
|
|
const float s = m_gui_scale;
|
|
|
|
DesiredRect = core::rect<s32>(
|
|
|
|
screensize.X / 2 - 600 * s / 2,
|
|
|
|
screensize.Y / 2 - 360 * s / 2,
|
|
|
|
screensize.X / 2 + 600 * s / 2,
|
|
|
|
screensize.Y / 2 + 360 * s / 2
|
|
|
|
);
|
2018-01-13 12:07:16 +01:00
|
|
|
recalculateAbsolutePosition(false);
|
|
|
|
|
2018-11-26 22:55:24 +01:00
|
|
|
v2s32 size = DesiredRect.getSize();
|
2018-01-13 12:07:16 +01:00
|
|
|
v2s32 topleft_client(0, 0);
|
|
|
|
|
|
|
|
const wchar_t *text;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Add stuff
|
|
|
|
*/
|
2018-11-26 22:55:24 +01:00
|
|
|
s32 ypos = 30 * s;
|
2018-01-13 12:07:16 +01:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect2(0, 0, 540 * s, 180 * s);
|
|
|
|
rect2 += topleft_client + v2s32(30 * s, ypos);
|
2018-01-13 12:07:16 +01:00
|
|
|
static const std::string info_text_template = strgettext(
|
2019-03-10 02:49:03 +01:00
|
|
|
"You are about to join this server with the name \"%s\" for the "
|
|
|
|
"first time.\n"
|
|
|
|
"If you proceed, a new account using your credentials will be "
|
|
|
|
"created on this server.\n"
|
|
|
|
"Please retype your password and click 'Register and Join' to "
|
|
|
|
"confirm account creation, or click 'Cancel' to abort.");
|
2018-01-13 12:07:16 +01:00
|
|
|
char info_text_buf[1024];
|
2018-07-22 21:56:06 +02:00
|
|
|
porting::mt_snprintf(info_text_buf, sizeof(info_text_buf),
|
2019-03-10 02:49:03 +01:00
|
|
|
info_text_template.c_str(), m_playername.c_str());
|
2018-02-23 17:01:05 +01:00
|
|
|
|
2018-06-27 18:09:45 +02:00
|
|
|
wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf);
|
|
|
|
gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true,
|
2019-12-09 20:01:16 +01:00
|
|
|
Environment, this, ID_intotext, rect2, false, true);
|
2018-06-27 18:09:45 +02:00
|
|
|
delete[] info_text_buf_wide;
|
2018-02-23 17:01:05 +01:00
|
|
|
e->drop();
|
|
|
|
e->setMultiLine(true);
|
|
|
|
e->setWordWrap(true);
|
|
|
|
e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
|
2018-01-13 12:07:16 +01:00
|
|
|
}
|
|
|
|
|
2019-12-09 20:01:16 +01:00
|
|
|
ypos += 200 * s;
|
2018-01-13 12:07:16 +01:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect2(0, 0, 540 * s, 30 * s);
|
|
|
|
rect2 += topleft_client + v2s32(30 * s, ypos);
|
2018-01-13 12:07:16 +01:00
|
|
|
gui::IGUIEditBox *e = Environment->addEditBox(m_pass_confirm.c_str(),
|
2018-03-16 08:41:33 +01:00
|
|
|
rect2, true, this, ID_confirmPassword);
|
2018-01-13 12:07:16 +01:00
|
|
|
e->setPasswordBox(true);
|
2019-08-07 19:15:46 +02:00
|
|
|
Environment->setFocus(e);
|
2018-01-13 12:07:16 +01:00
|
|
|
}
|
|
|
|
|
2019-12-09 20:01:16 +01:00
|
|
|
ypos += 50 * s;
|
2018-01-13 12:07:16 +01:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect2(0, 0, 230 * s, 35 * s);
|
|
|
|
rect2 = rect2 + v2s32(size.X / 2 - 220 * s, ypos);
|
2018-01-13 12:07:16 +01:00
|
|
|
text = wgettext("Register and Join");
|
2020-04-11 22:39:30 +02:00
|
|
|
GUIButton::addButton(Environment, rect2, m_tsrc, this, ID_confirm, text);
|
2018-01-13 12:07:16 +01:00
|
|
|
delete[] text;
|
|
|
|
}
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect2(0, 0, 120 * s, 35 * s);
|
|
|
|
rect2 = rect2 + v2s32(size.X / 2 + 70 * s, ypos);
|
2018-01-13 12:07:16 +01:00
|
|
|
text = wgettext("Cancel");
|
2020-04-11 22:39:30 +02:00
|
|
|
GUIButton::addButton(Environment, rect2, m_tsrc, this, ID_cancel, text);
|
2018-01-13 12:07:16 +01:00
|
|
|
delete[] text;
|
|
|
|
}
|
|
|
|
{
|
2019-12-09 20:01:16 +01:00
|
|
|
core::rect<s32> rect2(0, 0, 500 * s, 40 * s);
|
|
|
|
rect2 += topleft_client + v2s32(30 * s, ypos + 40 * s);
|
2018-01-13 12:07:16 +01:00
|
|
|
text = wgettext("Passwords do not match!");
|
|
|
|
IGUIElement *e = Environment->addStaticText(
|
2018-03-11 17:45:58 +01:00
|
|
|
text, rect2, false, true, this, ID_message);
|
2018-01-13 12:07:16 +01:00
|
|
|
e->setVisible(false);
|
|
|
|
delete[] text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIConfirmRegistration::drawMenu()
|
|
|
|
{
|
|
|
|
gui::IGUISkin *skin = Environment->getSkin();
|
|
|
|
if (!skin)
|
|
|
|
return;
|
|
|
|
video::IVideoDriver *driver = Environment->getVideoDriver();
|
|
|
|
|
|
|
|
video::SColor bgcolor(140, 0, 0, 0);
|
|
|
|
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
|
|
|
|
|
|
|
|
gui::IGUIElement::draw();
|
2018-06-24 21:50:57 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
getAndroidUIInput();
|
|
|
|
#endif
|
2018-01-13 12:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIConfirmRegistration::closeMenu(bool goNext)
|
|
|
|
{
|
|
|
|
if (goNext) {
|
|
|
|
m_client->confirmRegistration();
|
|
|
|
} else {
|
|
|
|
*m_aborted = true;
|
|
|
|
infostream << "Connect aborted [Escape]" << std::endl;
|
|
|
|
}
|
2018-05-10 13:50:06 +02:00
|
|
|
quitMenu();
|
2018-01-13 12:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIConfirmRegistration::acceptInput()
|
|
|
|
{
|
|
|
|
gui::IGUIElement *e;
|
|
|
|
e = getElementFromId(ID_confirmPassword);
|
|
|
|
if (e)
|
|
|
|
m_pass_confirm = e->getText();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GUIConfirmRegistration::processInput()
|
|
|
|
{
|
|
|
|
std::wstring m_password_ws = narrow_to_wide(m_password);
|
|
|
|
if (m_password_ws != m_pass_confirm) {
|
|
|
|
gui::IGUIElement *e = getElementFromId(ID_message);
|
|
|
|
if (e)
|
|
|
|
e->setVisible(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GUIConfirmRegistration::OnEvent(const SEvent &event)
|
|
|
|
{
|
|
|
|
if (event.EventType == EET_KEY_INPUT_EVENT) {
|
2018-06-24 21:50:57 +02:00
|
|
|
// clang-format off
|
|
|
|
if ((event.KeyInput.Key == KEY_ESCAPE ||
|
|
|
|
event.KeyInput.Key == KEY_CANCEL) &&
|
|
|
|
event.KeyInput.PressedDown) {
|
2018-01-13 12:07:16 +01:00
|
|
|
closeMenu(false);
|
|
|
|
return true;
|
|
|
|
}
|
2018-06-24 21:50:57 +02:00
|
|
|
// clang-format on
|
2018-01-13 12:07:16 +01:00
|
|
|
if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
|
|
|
|
acceptInput();
|
|
|
|
if (processInput())
|
|
|
|
closeMenu(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.EventType != EET_GUI_EVENT)
|
|
|
|
return Parent ? Parent->OnEvent(event) : false;
|
|
|
|
|
|
|
|
if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
|
|
|
|
if (!canTakeFocus(event.GUIEvent.Element)) {
|
2019-08-07 19:15:46 +02:00
|
|
|
dstream << "GUIConfirmRegistration: Not allowing focus change."
|
2018-01-13 12:07:16 +01:00
|
|
|
<< std::endl;
|
|
|
|
// Returning true disables focus change
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
|
|
|
|
switch (event.GUIEvent.Caller->getID()) {
|
|
|
|
case ID_confirm:
|
|
|
|
acceptInput();
|
|
|
|
if (processInput())
|
|
|
|
closeMenu(true);
|
|
|
|
return true;
|
|
|
|
case ID_cancel:
|
|
|
|
closeMenu(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
|
|
|
|
switch (event.GUIEvent.Caller->getID()) {
|
|
|
|
case ID_confirmPassword:
|
|
|
|
acceptInput();
|
|
|
|
if (processInput())
|
|
|
|
closeMenu(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-24 21:50:57 +02:00
|
|
|
|
|
|
|
#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
|