3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013 Ciaran Gultnieks <ciaran@ciarang.com>
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include "guiPasswordChange.h"
21 #include <IGUICheckBox.h>
22 #include <IGUIEditBox.h>
23 #include <IGUIButton.h>
24 #include <IGUIStaticText.h>
29 const int ID_oldPassword = 256;
30 const int ID_newPassword1 = 257;
31 const int ID_newPassword2 = 258;
32 const int ID_change = 259;
33 const int ID_message = 260;
34 const int ID_cancel = 261;
36 GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
37 gui::IGUIElement* parent, s32 id,
38 IMenuManager *menumgr,
41 GUIModalMenu(env, parent, id, menumgr),
46 GUIPasswordChange::~GUIPasswordChange()
51 void GUIPasswordChange::removeChildren()
53 const core::list<gui::IGUIElement *> &children = getChildren();
54 core::list<gui::IGUIElement *> children_copy;
55 for (core::list<gui::IGUIElement *>::ConstIterator i = children.begin();
56 i != children.end(); i++) {
57 children_copy.push_back(*i);
59 for (core::list<gui::IGUIElement *>::Iterator i = children_copy.begin();
60 i != children_copy.end(); i++) {
64 void GUIPasswordChange::regenerateGui(v2u32 screensize)
77 Calculate new sizes and positions
80 screensize.X/2 - 580/2,
81 screensize.Y/2 - 300/2,
82 screensize.X/2 + 580/2,
83 screensize.Y/2 + 300/2
87 recalculateAbsolutePosition(false);
89 v2s32 size = rect.getSize();
90 v2s32 topleft_client(40, 0);
99 core::rect<s32> rect(0, 0, 150, 20);
100 rect += topleft_client + v2s32(25, ypos + 6);
101 text = wgettext("Old Password");
102 Environment->addStaticText(text, rect, false, true, this, -1);
106 core::rect<s32> rect(0, 0, 230, 30);
107 rect += topleft_client + v2s32(160, ypos);
108 gui::IGUIEditBox *e = Environment->addEditBox(
109 m_oldpass.c_str(), rect, true, this, ID_oldPassword);
110 Environment->setFocus(e);
111 e->setPasswordBox(true);
115 core::rect<s32> rect(0, 0, 150, 20);
116 rect += topleft_client + v2s32(25, ypos + 6);
117 text = wgettext("New Password");
118 Environment->addStaticText(text, rect, false, true, this, -1);
122 core::rect<s32> rect(0, 0, 230, 30);
123 rect += topleft_client + v2s32(160, ypos);
124 gui::IGUIEditBox *e = Environment->addEditBox(
125 m_newpass.c_str(), rect, true, this, ID_newPassword1);
126 e->setPasswordBox(true);
130 core::rect<s32> rect(0, 0, 150, 20);
131 rect += topleft_client + v2s32(25, ypos + 6);
132 text = wgettext("Confirm Password");
133 Environment->addStaticText(text, rect, false, true, this, -1);
137 core::rect<s32> rect(0, 0, 230, 30);
138 rect += topleft_client + v2s32(160, ypos);
139 gui::IGUIEditBox *e = Environment->addEditBox(
140 m_newpass_confirm.c_str(), rect, true, this, ID_newPassword2);
141 e->setPasswordBox(true);
146 core::rect<s32> rect(0, 0, 100, 30);
147 rect = rect + v2s32(size.X / 4 + 56, ypos);
148 text = wgettext("Change");
149 Environment->addButton(rect, this, ID_change, text);
153 core::rect<s32> rect(0, 0, 100, 30);
154 rect = rect + v2s32(size.X / 4 + 185, ypos);
155 text = wgettext("Cancel");
156 Environment->addButton(rect, this, ID_cancel, text);
162 core::rect<s32> rect(0, 0, 300, 20);
163 rect += topleft_client + v2s32(35, ypos);
164 text = wgettext("Passwords do not match!");
166 Environment->addStaticText(
167 text, rect, false, true, this, ID_message);
168 e->setVisible(false);
173 void GUIPasswordChange::drawMenu()
175 gui::IGUISkin *skin = Environment->getSkin();
178 video::IVideoDriver *driver = Environment->getVideoDriver();
180 video::SColor bgcolor(140, 0, 0, 0);
181 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
183 gui::IGUIElement::draw();
186 void GUIPasswordChange::acceptInput()
189 e = getElementFromId(ID_oldPassword);
191 m_oldpass = e->getText();
192 e = getElementFromId(ID_newPassword1);
194 m_newpass = e->getText();
195 e = getElementFromId(ID_newPassword2);
197 m_newpass_confirm = e->getText();
200 bool GUIPasswordChange::processInput()
202 if (m_newpass != m_newpass_confirm) {
203 gui::IGUIElement *e = getElementFromId(ID_message);
208 m_client->sendChangePassword(wide_to_utf8(m_oldpass), wide_to_utf8(m_newpass));
212 bool GUIPasswordChange::OnEvent(const SEvent &event)
214 if (event.EventType == EET_KEY_INPUT_EVENT) {
215 if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) {
219 if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
226 if (event.EventType == EET_GUI_EVENT) {
227 if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST &&
229 if (!canTakeFocus(event.GUIEvent.Element)) {
230 dstream << "GUIPasswordChange: Not allowing focus change."
232 // Returning true disables focus change
236 if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
237 switch (event.GUIEvent.Caller->getID()) {
248 if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
249 switch (event.GUIEvent.Caller->getID()) {
251 case ID_newPassword1:
252 case ID_newPassword2:
261 return Parent ? Parent->OnEvent(event) : false;