3 Copyright (C) 2018 srifqi, Muhammad Rifqi Priyo Susanto
4 <muhammadrifqipriyosusanto@gmail.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "guiConfirmRegistration.h"
22 #include "client/client.h"
23 #include "guiButton.h"
24 #include <IGUICheckBox.h>
25 #include <IGUIButton.h>
26 #include <IGUIStaticText.h>
28 #include "intlGUIEditBox.h"
33 // Continuing from guiPasswordChange.cpp
34 const int ID_confirmPassword = 262;
35 const int ID_confirm = 263;
36 const int ID_intotext = 264;
37 const int ID_cancel = 265;
38 const int ID_message = 266;
40 GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env,
41 gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, Client *client,
42 const std::string &playername, const std::string &password,
44 GUIModalMenu(env, parent, id, menumgr),
45 m_client(client), m_playername(playername), m_password(password),
49 m_touchscreen_visible = false;
53 GUIConfirmRegistration::~GUIConfirmRegistration()
58 void GUIConfirmRegistration::removeChildren()
60 const core::list<gui::IGUIElement *> &children = getChildren();
61 core::list<gui::IGUIElement *> children_copy;
62 for (gui::IGUIElement *i : children)
63 children_copy.push_back(i);
64 for (gui::IGUIElement *i : children_copy)
68 void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
74 Calculate new sizes and positions
76 const float s = m_gui_scale;
77 DesiredRect = core::rect<s32>(
78 screensize.X / 2 - 600 * s / 2,
79 screensize.Y / 2 - 360 * s / 2,
80 screensize.X / 2 + 600 * s / 2,
81 screensize.Y / 2 + 360 * s / 2
83 recalculateAbsolutePosition(false);
85 v2s32 size = DesiredRect.getSize();
86 v2s32 topleft_client(0, 0);
95 core::rect<s32> rect2(0, 0, 540 * s, 180 * s);
96 rect2 += topleft_client + v2s32(30 * s, ypos);
97 static const std::string info_text_template = strgettext(
98 "You are about to join this server with the name \"%s\" for the "
100 "If you proceed, a new account using your credentials will be "
101 "created on this server.\n"
102 "Please retype your password and click 'Register and Join' to "
103 "confirm account creation, or click 'Cancel' to abort.");
104 char info_text_buf[1024];
105 porting::mt_snprintf(info_text_buf, sizeof(info_text_buf),
106 info_text_template.c_str(), m_playername.c_str());
108 wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf);
109 gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true,
110 Environment, this, ID_intotext, rect2, false, true);
111 delete[] info_text_buf_wide;
113 e->setMultiLine(true);
114 e->setWordWrap(true);
115 e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
120 core::rect<s32> rect2(0, 0, 540 * s, 30 * s);
121 rect2 += topleft_client + v2s32(30 * s, ypos);
122 gui::IGUIEditBox *e = Environment->addEditBox(m_pass_confirm.c_str(),
123 rect2, true, this, ID_confirmPassword);
124 e->setPasswordBox(true);
125 Environment->setFocus(e);
130 core::rect<s32> rect2(0, 0, 230 * s, 35 * s);
131 rect2 = rect2 + v2s32(size.X / 2 - 220 * s, ypos);
132 text = wgettext("Register and Join");
133 GUIButton::addButton(Environment, rect2, this, ID_confirm, text);
137 core::rect<s32> rect2(0, 0, 120 * s, 35 * s);
138 rect2 = rect2 + v2s32(size.X / 2 + 70 * s, ypos);
139 text = wgettext("Cancel");
140 GUIButton::addButton(Environment, rect2, this, ID_cancel, text);
144 core::rect<s32> rect2(0, 0, 500 * s, 40 * s);
145 rect2 += topleft_client + v2s32(30 * s, ypos + 40 * s);
146 text = wgettext("Passwords do not match!");
147 IGUIElement *e = Environment->addStaticText(
148 text, rect2, false, true, this, ID_message);
149 e->setVisible(false);
154 void GUIConfirmRegistration::drawMenu()
156 gui::IGUISkin *skin = Environment->getSkin();
159 video::IVideoDriver *driver = Environment->getVideoDriver();
161 video::SColor bgcolor(140, 0, 0, 0);
162 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
164 gui::IGUIElement::draw();
170 void GUIConfirmRegistration::closeMenu(bool goNext)
173 m_client->confirmRegistration();
176 infostream << "Connect aborted [Escape]" << std::endl;
181 void GUIConfirmRegistration::acceptInput()
184 e = getElementFromId(ID_confirmPassword);
186 m_pass_confirm = e->getText();
189 bool GUIConfirmRegistration::processInput()
191 std::wstring m_password_ws = narrow_to_wide(m_password);
192 if (m_password_ws != m_pass_confirm) {
193 gui::IGUIElement *e = getElementFromId(ID_message);
201 bool GUIConfirmRegistration::OnEvent(const SEvent &event)
203 if (event.EventType == EET_KEY_INPUT_EVENT) {
205 if ((event.KeyInput.Key == KEY_ESCAPE ||
206 event.KeyInput.Key == KEY_CANCEL) &&
207 event.KeyInput.PressedDown) {
212 if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
220 if (event.EventType != EET_GUI_EVENT)
221 return Parent ? Parent->OnEvent(event) : false;
223 if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
224 if (!canTakeFocus(event.GUIEvent.Element)) {
225 dstream << "GUIConfirmRegistration: Not allowing focus change."
227 // Returning true disables focus change
230 } else if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
231 switch (event.GUIEvent.Caller->getID()) {
241 } else if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
242 switch (event.GUIEvent.Caller->getID()) {
243 case ID_confirmPassword:
255 bool GUIConfirmRegistration::getAndroidUIInput()
257 if (!hasAndroidUIInput() || m_jni_field_name != "password")
260 std::string text = porting::getInputDialogValue();
261 gui::IGUIElement *e = getElementFromId(ID_confirmPassword);
263 e->setText(utf8_to_wide(text).c_str());
265 m_jni_field_name.clear();