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"
31 // Continuing from guiPasswordChange.cpp
32 const int ID_confirmPassword = 262;
33 const int ID_confirm = 263;
34 const int ID_message = 264;
35 const int ID_cancel = 265;
37 GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env,
38 gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, Client *client,
39 const std::string &playername, const std::string &password,
40 const std::string &address, bool *aborted) :
41 GUIModalMenu(env, parent, id, menumgr),
42 m_client(client), m_playername(playername), m_password(password),
43 m_address(address), m_aborted(aborted)
47 GUIConfirmRegistration::~GUIConfirmRegistration()
52 void GUIConfirmRegistration::removeChildren()
54 const core::list<gui::IGUIElement *> &children = getChildren();
55 core::list<gui::IGUIElement *> children_copy;
56 for (gui::IGUIElement *i : children)
57 children_copy.push_back(i);
58 for (gui::IGUIElement *i : children_copy)
61 void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
67 Calculate new sizes and positions
69 core::rect<s32> rect(screensize.X / 2 - 600 / 2, screensize.Y / 2 - 360 / 2,
70 screensize.X / 2 + 600 / 2, screensize.Y / 2 + 360 / 2);
73 recalculateAbsolutePosition(false);
75 v2s32 size = rect.getSize();
76 v2s32 topleft_client(0, 0);
85 std::string address = m_address;
87 address = "localhost";
88 core::rect<s32> rect2(0, 0, 540, 180);
89 rect2 += topleft_client + v2s32(30, ypos);
90 static const std::string info_text_template = strgettext(
91 "You are about to join the server at %1$s with the "
92 "name \"%2$s\" for the first time. If you proceed, a "
93 "new account using your credentials will be created "
95 "Please retype your password and click Register and "
96 "Join to confirm account creation or click Cancel to "
98 char info_text_buf[1024];
99 snprintf(info_text_buf, sizeof(info_text_buf), info_text_template.c_str(),
100 address.c_str(), m_playername.c_str());
102 gui::IGUIEditBox *e = new gui::intlGUIEditBox(
103 utf8_to_wide_c(info_text_buf), true, Environment, this,
104 ID_message, rect2, false, true);
106 e->setMultiLine(true);
107 e->setWordWrap(true);
108 e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
113 core::rect<s32> rect2(0, 0, 540, 30);
114 rect2 += topleft_client + v2s32(30, ypos);
115 gui::IGUIEditBox *e = Environment->addEditBox(m_pass_confirm.c_str(),
116 rect2, true, this, ID_confirmPassword);
117 e->setPasswordBox(true);
122 core::rect<s32> rect2(0, 0, 230, 35);
123 rect2 = rect2 + v2s32(size.X / 2 - 220, ypos);
124 text = wgettext("Register and Join");
125 Environment->addButton(rect2, this, ID_confirm, text);
129 core::rect<s32> rect2(0, 0, 120, 35);
130 rect2 = rect2 + v2s32(size.X / 2 + 70, ypos);
131 text = wgettext("Cancel");
132 Environment->addButton(rect2, this, ID_cancel, text);
136 core::rect<s32> rect2(0, 0, 200, 20);
137 rect2 += topleft_client + v2s32(30, ypos - 40);
138 text = wgettext("Passwords do not match!");
139 IGUIElement *e = Environment->addStaticText(
140 text, rect2, false, true, this, ID_message);
141 e->setVisible(false);
146 void GUIConfirmRegistration::drawMenu()
148 gui::IGUISkin *skin = Environment->getSkin();
151 video::IVideoDriver *driver = Environment->getVideoDriver();
153 video::SColor bgcolor(140, 0, 0, 0);
154 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
156 gui::IGUIElement::draw();
159 void GUIConfirmRegistration::closeMenu(bool goNext)
163 m_client->confirmRegistration();
166 infostream << "Connect aborted [Escape]" << std::endl;
170 void GUIConfirmRegistration::acceptInput()
173 e = getElementFromId(ID_confirmPassword);
175 m_pass_confirm = e->getText();
178 bool GUIConfirmRegistration::processInput()
180 std::wstring m_password_ws = narrow_to_wide(m_password);
181 if (m_password_ws != m_pass_confirm) {
182 gui::IGUIElement *e = getElementFromId(ID_message);
190 bool GUIConfirmRegistration::OnEvent(const SEvent &event)
192 if (event.EventType == EET_KEY_INPUT_EVENT) {
193 if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) {
197 if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
205 if (event.EventType != EET_GUI_EVENT)
206 return Parent ? Parent->OnEvent(event) : false;
208 if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
209 if (!canTakeFocus(event.GUIEvent.Element)) {
210 dstream << "GUIConfirmRegistration: Not allowing focus "
213 // Returning true disables focus change
216 } else if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
217 switch (event.GUIEvent.Caller->getID()) {
227 } else if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
228 switch (event.GUIEvent.Caller->getID()) {
229 case ID_confirmPassword: