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 "serialization.h"
23 #include <IGUICheckBox.h>
24 #include <IGUIEditBox.h>
25 #include <IGUIButton.h>
26 #include <IGUIStaticText.h>
31 const int ID_oldPassword = 256;
32 const int ID_newPassword1 = 257;
33 const int ID_newPassword2 = 258;
34 const int ID_change = 259;
35 const int ID_message = 260;
37 GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
38 gui::IGUIElement* parent, s32 id,
39 IMenuManager *menumgr,
42 GUIModalMenu(env, parent, id, menumgr),
47 GUIPasswordChange::~GUIPasswordChange()
52 void GUIPasswordChange::removeChildren()
55 gui::IGUIElement *e = getElementFromId(ID_oldPassword);
60 gui::IGUIElement *e = getElementFromId(ID_newPassword1);
65 gui::IGUIElement *e = getElementFromId(ID_newPassword2);
70 gui::IGUIElement *e = getElementFromId(ID_change);
76 void GUIPasswordChange::regenerateGui(v2u32 screensize)
84 Calculate new sizes and positions
87 screensize.X/2 - 580/2,
88 screensize.Y/2 - 300/2,
89 screensize.X/2 + 580/2,
90 screensize.Y/2 + 300/2
94 recalculateAbsolutePosition(false);
96 v2s32 size = rect.getSize();
97 v2s32 topleft_client(40, 0);
105 core::rect<s32> rect(0, 0, 110, 20);
106 rect += topleft_client + v2s32(35, ypos+6);
107 wchar_t* text = wgettext("Old Password");
108 Environment->addStaticText(text, rect, false, true, this, -1);
113 core::rect<s32> rect(0, 0, 230, 30);
114 rect += topleft_client + v2s32(160, ypos);
115 gui::IGUIEditBox *e =
116 Environment->addEditBox(L"", rect, true, this, ID_oldPassword);
117 Environment->setFocus(e);
118 e->setPasswordBox(true);
123 core::rect<s32> rect(0, 0, 110, 20);
124 rect += topleft_client + v2s32(35, ypos+6);
125 wchar_t* text = wgettext("New Password");
126 Environment->addStaticText(text, rect, false, true, this, -1);
131 core::rect<s32> rect(0, 0, 230, 30);
132 rect += topleft_client + v2s32(160, ypos);
133 gui::IGUIEditBox *e =
134 Environment->addEditBox(L"", rect, true, this, ID_newPassword1);
135 e->setPasswordBox(true);
140 core::rect<s32> rect(0, 0, 110, 20);
141 rect += topleft_client + v2s32(35, ypos+6);
142 wchar_t* text = wgettext("Confirm Password");
143 Environment->addStaticText(text, rect, false, true, this, -1);
148 core::rect<s32> rect(0, 0, 230, 30);
149 rect += topleft_client + v2s32(160, ypos);
150 gui::IGUIEditBox *e =
151 Environment->addEditBox(L"", rect, true, this, ID_newPassword2);
152 e->setPasswordBox(true);
158 core::rect<s32> rect(0, 0, 140, 30);
159 rect = rect + v2s32(size.X/2-140/2, ypos);
160 wchar_t* text = wgettext("Change");
161 Environment->addButton(rect, this, ID_change, text);
167 core::rect<s32> rect(0, 0, 300, 20);
168 rect += topleft_client + v2s32(35, ypos);
169 wchar_t* text = wgettext("Passwords do not match!");
171 Environment->addStaticText(
173 rect, false, true, this, ID_message);
174 e->setVisible(false);
181 void GUIPasswordChange::drawMenu()
183 gui::IGUISkin* skin = Environment->getSkin();
186 video::IVideoDriver* driver = Environment->getVideoDriver();
188 video::SColor bgcolor(140,0,0,0);
189 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
191 gui::IGUIElement::draw();
194 bool GUIPasswordChange::acceptInput()
196 std::wstring oldpass;
197 std::wstring newpass;
199 e = getElementFromId(ID_oldPassword);
201 oldpass = e->getText();
202 e = getElementFromId(ID_newPassword1);
204 newpass = e->getText();
205 e = getElementFromId(ID_newPassword2);
206 if(e != NULL && newpass != e->getText())
208 e = getElementFromId(ID_message);
213 m_client->sendChangePassword(oldpass, newpass);
217 bool GUIPasswordChange::OnEvent(const SEvent& event)
219 if(event.EventType==EET_KEY_INPUT_EVENT)
221 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
226 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
233 if(event.EventType==EET_GUI_EVENT)
235 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
238 if(!canTakeFocus(event.GUIEvent.Element))
240 dstream<<"GUIPasswordChange: Not allowing focus change."
242 // Returning true disables focus change
246 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
248 switch(event.GUIEvent.Caller->getID())
256 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
258 switch(event.GUIEvent.Caller->getID())
261 case ID_newPassword1:
262 case ID_newPassword2:
270 return Parent ? Parent->OnEvent(event) : false;