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)
48 GUIConfirmRegistration::~GUIConfirmRegistration()
53 void GUIConfirmRegistration::removeChildren()
55 const core::list<gui::IGUIElement *> &children = getChildren();
56 core::list<gui::IGUIElement *> children_copy;
57 for (gui::IGUIElement *i : children)
58 children_copy.push_back(i);
59 for (gui::IGUIElement *i : children_copy)
62 void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
68 Calculate new sizes and positions
70 core::rect<s32> rect(screensize.X / 2 - 600 / 2, screensize.Y / 2 - 360 / 2,
71 screensize.X / 2 + 600 / 2, screensize.Y / 2 + 360 / 2);
74 recalculateAbsolutePosition(false);
76 v2s32 size = rect.getSize();
77 v2s32 topleft_client(0, 0);
86 std::string address = m_address;
88 address = "localhost";
89 core::rect<s32> rect2(0, 0, 540, 180);
90 rect2 += topleft_client + v2s32(30, ypos);
91 static const std::string info_text_template = strgettext(
92 "You are about to join the server at %1$s with the "
93 "name \"%2$s\" for the first time. If you proceed, a "
94 "new account using your credentials will be created "
96 "Please retype your password and click Register and "
97 "Join to confirm account creation or click Cancel to "
99 char info_text_buf[1024];
100 porting::mt_snprintf(info_text_buf, sizeof(info_text_buf),
101 info_text_template.c_str(), address.c_str(),
102 m_playername.c_str());
104 wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf);
105 gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true,
106 Environment, this, ID_message, rect2, false, true);
107 delete[] info_text_buf_wide;
109 e->setMultiLine(true);
110 e->setWordWrap(true);
111 e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
116 core::rect<s32> rect2(0, 0, 540, 30);
117 rect2 += topleft_client + v2s32(30, ypos);
118 gui::IGUIEditBox *e = Environment->addEditBox(m_pass_confirm.c_str(),
119 rect2, true, this, ID_confirmPassword);
120 e->setPasswordBox(true);
125 core::rect<s32> rect2(0, 0, 230, 35);
126 rect2 = rect2 + v2s32(size.X / 2 - 220, ypos);
127 text = wgettext("Register and Join");
128 Environment->addButton(rect2, this, ID_confirm, text);
132 core::rect<s32> rect2(0, 0, 120, 35);
133 rect2 = rect2 + v2s32(size.X / 2 + 70, ypos);
134 text = wgettext("Cancel");
135 Environment->addButton(rect2, this, ID_cancel, text);
139 core::rect<s32> rect2(0, 0, 200, 20);
140 rect2 += topleft_client + v2s32(30, ypos - 40);
141 text = wgettext("Passwords do not match!");
142 IGUIElement *e = Environment->addStaticText(
143 text, rect2, false, true, this, ID_message);
144 e->setVisible(false);
149 void GUIConfirmRegistration::drawMenu()
151 gui::IGUISkin *skin = Environment->getSkin();
154 video::IVideoDriver *driver = Environment->getVideoDriver();
156 video::SColor bgcolor(140, 0, 0, 0);
157 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
159 gui::IGUIElement::draw();
162 void GUIConfirmRegistration::closeMenu(bool goNext)
165 m_client->confirmRegistration();
168 infostream << "Connect aborted [Escape]" << std::endl;
173 void GUIConfirmRegistration::acceptInput()
176 e = getElementFromId(ID_confirmPassword);
178 m_pass_confirm = e->getText();
181 bool GUIConfirmRegistration::processInput()
183 std::wstring m_password_ws = narrow_to_wide(m_password);
184 if (m_password_ws != m_pass_confirm) {
185 gui::IGUIElement *e = getElementFromId(ID_message);
193 bool GUIConfirmRegistration::OnEvent(const SEvent &event)
195 if (event.EventType == EET_KEY_INPUT_EVENT) {
196 if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) {
200 if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
208 if (event.EventType != EET_GUI_EVENT)
209 return Parent ? Parent->OnEvent(event) : false;
211 if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
212 if (!canTakeFocus(event.GUIEvent.Element)) {
213 dstream << "GUIConfirmRegistration: Not allowing focus "
216 // Returning true disables focus change
219 } else if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
220 switch (event.GUIEvent.Caller->getID()) {
230 } else if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
231 switch (event.GUIEvent.Caller->getID()) {
232 case ID_confirmPassword: