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 wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf);
103 gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true,
104 Environment, this, ID_message, rect2, false, true);
105 delete[] info_text_buf_wide;
107 e->setMultiLine(true);
108 e->setWordWrap(true);
109 e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
114 core::rect<s32> rect2(0, 0, 540, 30);
115 rect2 += topleft_client + v2s32(30, ypos);
116 gui::IGUIEditBox *e = Environment->addEditBox(m_pass_confirm.c_str(),
117 rect2, true, this, ID_confirmPassword);
118 e->setPasswordBox(true);
123 core::rect<s32> rect2(0, 0, 230, 35);
124 rect2 = rect2 + v2s32(size.X / 2 - 220, ypos);
125 text = wgettext("Register and Join");
126 Environment->addButton(rect2, this, ID_confirm, text);
130 core::rect<s32> rect2(0, 0, 120, 35);
131 rect2 = rect2 + v2s32(size.X / 2 + 70, ypos);
132 text = wgettext("Cancel");
133 Environment->addButton(rect2, this, ID_cancel, text);
137 core::rect<s32> rect2(0, 0, 200, 20);
138 rect2 += topleft_client + v2s32(30, ypos - 40);
139 text = wgettext("Passwords do not match!");
140 IGUIElement *e = Environment->addStaticText(
141 text, rect2, false, true, this, ID_message);
142 e->setVisible(false);
147 void GUIConfirmRegistration::drawMenu()
149 gui::IGUISkin *skin = Environment->getSkin();
152 video::IVideoDriver *driver = Environment->getVideoDriver();
154 video::SColor bgcolor(140, 0, 0, 0);
155 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
157 gui::IGUIElement::draw();
160 void GUIConfirmRegistration::closeMenu(bool goNext)
163 m_client->confirmRegistration();
166 infostream << "Connect aborted [Escape]" << std::endl;
171 void GUIConfirmRegistration::acceptInput()
174 e = getElementFromId(ID_confirmPassword);
176 m_pass_confirm = e->getText();
179 bool GUIConfirmRegistration::processInput()
181 std::wstring m_password_ws = narrow_to_wide(m_password);
182 if (m_password_ws != m_pass_confirm) {
183 gui::IGUIElement *e = getElementFromId(ID_message);
191 bool GUIConfirmRegistration::OnEvent(const SEvent &event)
193 if (event.EventType == EET_KEY_INPUT_EVENT) {
194 if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) {
198 if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
206 if (event.EventType != EET_GUI_EVENT)
207 return Parent ? Parent->OnEvent(event) : false;
209 if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
210 if (!canTakeFocus(event.GUIEvent.Element)) {
211 dstream << "GUIConfirmRegistration: Not allowing focus "
214 // Returning true disables focus change
217 } else if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
218 switch (event.GUIEvent.Caller->getID()) {
228 } else if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
229 switch (event.GUIEvent.Caller->getID()) {
230 case ID_confirmPassword: