3 Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2011 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"
26 const int ID_oldPassword = 256;
27 const int ID_newPassword1 = 257;
28 const int ID_newPassword2 = 258;
29 const int ID_change = 259;
30 const int ID_message = 260;
32 GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
33 gui::IGUIElement* parent, s32 id,
34 IMenuManager *menumgr,
37 GUIModalMenu(env, parent, id, menumgr),
42 GUIPasswordChange::~GUIPasswordChange()
47 void GUIPasswordChange::removeChildren()
50 gui::IGUIElement *e = getElementFromId(ID_oldPassword);
55 gui::IGUIElement *e = getElementFromId(ID_newPassword1);
60 gui::IGUIElement *e = getElementFromId(ID_newPassword2);
65 gui::IGUIElement *e = getElementFromId(ID_change);
71 void GUIPasswordChange::regenerateGui(v2u32 screensize)
79 Calculate new sizes and positions
82 screensize.X/2 - 580/2,
83 screensize.Y/2 - 300/2,
84 screensize.X/2 + 580/2,
85 screensize.Y/2 + 300/2
89 recalculateAbsolutePosition(false);
91 v2s32 size = rect.getSize();
92 v2s32 topleft_client(40, 0);
93 v2s32 size_client = size - v2s32(40, 0);
100 core::rect<s32> rect(0, 0, 110, 20);
101 rect += topleft_client + v2s32(35, ypos+6);
102 Environment->addStaticText(chartowchar_t(gettext("Old Password")), rect, false, true, this, -1);
105 core::rect<s32> rect(0, 0, 230, 30);
106 rect += topleft_client + v2s32(160, ypos);
107 gui::IGUIEditBox *e =
108 Environment->addEditBox(L"", rect, true, this, ID_oldPassword);
109 Environment->setFocus(e);
110 e->setPasswordBox(true);
114 core::rect<s32> rect(0, 0, 110, 20);
115 rect += topleft_client + v2s32(35, ypos+6);
116 Environment->addStaticText(chartowchar_t(gettext("New Password")), rect, false, true, this, -1);
119 core::rect<s32> rect(0, 0, 230, 30);
120 rect += topleft_client + v2s32(160, ypos);
121 gui::IGUIEditBox *e =
122 Environment->addEditBox(L"", rect, true, this, ID_newPassword1);
123 e->setPasswordBox(true);
127 core::rect<s32> rect(0, 0, 110, 20);
128 rect += topleft_client + v2s32(35, ypos+6);
129 Environment->addStaticText(chartowchar_t(gettext("Confirm Password")), rect, false, true, this, -1);
132 core::rect<s32> rect(0, 0, 230, 30);
133 rect += topleft_client + v2s32(160, ypos);
134 gui::IGUIEditBox *e =
135 Environment->addEditBox(L"", rect, true, this, ID_newPassword2);
136 e->setPasswordBox(true);
141 core::rect<s32> rect(0, 0, 140, 30);
142 rect = rect + v2s32(size.X/2-140/2, ypos);
143 Environment->addButton(rect, this, ID_change, chartowchar_t(gettext("Change")));
148 core::rect<s32> rect(0, 0, 300, 20);
149 rect += topleft_client + v2s32(35, ypos);
151 Environment->addStaticText(chartowchar_t(gettext("Passwords do not match!")), rect, false, true, this, ID_message);
152 e->setVisible(false);
157 void GUIPasswordChange::drawMenu()
159 gui::IGUISkin* skin = Environment->getSkin();
162 video::IVideoDriver* driver = Environment->getVideoDriver();
164 video::SColor bgcolor(140,0,0,0);
165 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
167 gui::IGUIElement::draw();
170 bool GUIPasswordChange::acceptInput()
172 std::wstring oldpass;
173 std::wstring newpass;
175 e = getElementFromId(ID_oldPassword);
177 oldpass = e->getText();
178 e = getElementFromId(ID_newPassword1);
180 newpass = e->getText();
181 e = getElementFromId(ID_newPassword2);
182 if(e != NULL && newpass != e->getText())
184 e = getElementFromId(ID_message);
189 m_client->sendChangePassword(oldpass, newpass);
193 bool GUIPasswordChange::OnEvent(const SEvent& event)
195 if(event.EventType==EET_KEY_INPUT_EVENT)
197 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
202 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
209 if(event.EventType==EET_GUI_EVENT)
211 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
214 if(!canTakeFocus(event.GUIEvent.Element))
216 dstream<<"GUIPasswordChange: Not allowing focus change."
218 // Returning true disables focus change
222 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
224 switch(event.GUIEvent.Caller->getID())
232 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
234 switch(event.GUIEvent.Caller->getID())
237 case ID_newPassword1:
238 case ID_newPassword2:
246 return Parent ? Parent->OnEvent(event) : false;