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"
23 #include <IGUICheckBox.h>
24 #include <IGUIButton.h>
25 #include <IGUIStaticText.h>
27 #include "intlGUIEditBox.h"
32 // Continuing from guiPasswordChange.cpp
33 const int ID_confirmPassword = 262;
34 const int ID_confirm = 263;
35 const int ID_message = 264;
36 const int ID_cancel = 265;
38 GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env,
39 gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, Client *client,
40 const std::string &playername, const std::string &password,
41 const std::string &address, bool *aborted) :
42 GUIModalMenu(env, parent, id, menumgr),
43 m_client(client), m_playername(playername), m_password(password),
44 m_address(address), m_aborted(aborted)
47 m_touchscreen_visible = false;
51 GUIConfirmRegistration::~GUIConfirmRegistration()
56 void GUIConfirmRegistration::removeChildren()
58 const core::list<gui::IGUIElement *> &children = getChildren();
59 core::list<gui::IGUIElement *> children_copy;
60 for (gui::IGUIElement *i : children)
61 children_copy.push_back(i);
62 for (gui::IGUIElement *i : children_copy)
65 void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
71 Calculate new sizes and positions
73 core::rect<s32> rect(screensize.X / 2 - 600 / 2, screensize.Y / 2 - 360 / 2,
74 screensize.X / 2 + 600 / 2, screensize.Y / 2 + 360 / 2);
77 recalculateAbsolutePosition(false);
79 v2s32 size = rect.getSize();
80 v2s32 topleft_client(0, 0);
89 std::string address = m_address;
91 address = "localhost";
92 core::rect<s32> rect2(0, 0, 540, 180);
93 rect2 += topleft_client + v2s32(30, ypos);
94 static const std::string info_text_template = strgettext(
95 "You are about to join the server at %1$s with the "
96 "name \"%2$s\" for the first time. If you proceed, a "
97 "new account using your credentials will be created "
99 "Please retype your password and click Register and "
100 "Join to confirm account creation or click Cancel to "
102 char info_text_buf[1024];
103 porting::mt_snprintf(info_text_buf, sizeof(info_text_buf),
104 info_text_template.c_str(), address.c_str(),
105 m_playername.c_str());
107 wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf);
108 gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true,
109 Environment, this, ID_message, rect2, false, true);
110 delete[] info_text_buf_wide;
112 e->setMultiLine(true);
113 e->setWordWrap(true);
114 e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
119 core::rect<s32> rect2(0, 0, 540, 30);
120 rect2 += topleft_client + v2s32(30, ypos);
121 gui::IGUIEditBox *e = Environment->addEditBox(m_pass_confirm.c_str(),
122 rect2, true, this, ID_confirmPassword);
123 e->setPasswordBox(true);
128 core::rect<s32> rect2(0, 0, 230, 35);
129 rect2 = rect2 + v2s32(size.X / 2 - 220, ypos);
130 text = wgettext("Register and Join");
131 Environment->addButton(rect2, this, ID_confirm, text);
135 core::rect<s32> rect2(0, 0, 120, 35);
136 rect2 = rect2 + v2s32(size.X / 2 + 70, ypos);
137 text = wgettext("Cancel");
138 Environment->addButton(rect2, this, ID_cancel, text);
142 core::rect<s32> rect2(0, 0, 200, 20);
143 rect2 += topleft_client + v2s32(30, ypos - 40);
144 text = wgettext("Passwords do not match!");
145 IGUIElement *e = Environment->addStaticText(
146 text, rect2, false, true, this, ID_message);
147 e->setVisible(false);
152 void GUIConfirmRegistration::drawMenu()
154 gui::IGUISkin *skin = Environment->getSkin();
157 video::IVideoDriver *driver = Environment->getVideoDriver();
159 video::SColor bgcolor(140, 0, 0, 0);
160 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
162 gui::IGUIElement::draw();
168 void GUIConfirmRegistration::closeMenu(bool goNext)
171 m_client->confirmRegistration();
174 infostream << "Connect aborted [Escape]" << std::endl;
179 void GUIConfirmRegistration::acceptInput()
182 e = getElementFromId(ID_confirmPassword);
184 m_pass_confirm = e->getText();
187 bool GUIConfirmRegistration::processInput()
189 std::wstring m_password_ws = narrow_to_wide(m_password);
190 if (m_password_ws != m_pass_confirm) {
191 gui::IGUIElement *e = getElementFromId(ID_message);
199 bool GUIConfirmRegistration::OnEvent(const SEvent &event)
201 if (event.EventType == EET_KEY_INPUT_EVENT) {
203 if ((event.KeyInput.Key == KEY_ESCAPE ||
204 event.KeyInput.Key == KEY_CANCEL) &&
205 event.KeyInput.PressedDown) {
210 if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
218 if (event.EventType != EET_GUI_EVENT)
219 return Parent ? Parent->OnEvent(event) : false;
221 if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
222 if (!canTakeFocus(event.GUIEvent.Element)) {
223 dstream << "GUIConfirmRegistration: Not allowing focus "
226 // Returning true disables focus change
229 } else if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
230 switch (event.GUIEvent.Caller->getID()) {
240 } else if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
241 switch (event.GUIEvent.Caller->getID()) {
242 case ID_confirmPassword:
254 bool GUIConfirmRegistration::getAndroidUIInput()
256 if (!hasAndroidUIInput() || m_jni_field_name != "password")
259 std::string text = porting::getInputDialogValue();
260 gui::IGUIElement *e = getElementFromId(ID_confirmPassword);
262 e->setText(utf8_to_wide(text).c_str());
264 m_jni_field_name.clear();