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);
101 core::rect<s32> rect(0, 0, 110, 20);
102 rect += topleft_client + v2s32(35, ypos+6);
103 Environment->addStaticText(wgettext("Old Password"),
104 rect, false, true, this, -1);
108 core::rect<s32> rect(0, 0, 230, 30);
109 rect += topleft_client + v2s32(160, ypos);
110 gui::IGUIEditBox *e =
111 Environment->addEditBox(L"", rect, true, this, ID_oldPassword);
112 Environment->setFocus(e);
113 e->setPasswordBox(true);
118 core::rect<s32> rect(0, 0, 110, 20);
119 rect += topleft_client + v2s32(35, ypos+6);
120 Environment->addStaticText(wgettext("New Password"),
121 rect, false, true, this, -1);
125 core::rect<s32> rect(0, 0, 230, 30);
126 rect += topleft_client + v2s32(160, ypos);
127 gui::IGUIEditBox *e =
128 Environment->addEditBox(L"", rect, true, this, ID_newPassword1);
129 e->setPasswordBox(true);
134 core::rect<s32> rect(0, 0, 110, 20);
135 rect += topleft_client + v2s32(35, ypos+6);
136 Environment->addStaticText(wgettext("Confirm Password"),
137 rect, false, true, this, -1);
141 core::rect<s32> rect(0, 0, 230, 30);
142 rect += topleft_client + v2s32(160, ypos);
143 gui::IGUIEditBox *e =
144 Environment->addEditBox(L"", rect, true, this, ID_newPassword2);
145 e->setPasswordBox(true);
151 core::rect<s32> rect(0, 0, 140, 30);
152 rect = rect + v2s32(size.X/2-140/2, ypos);
153 Environment->addButton(rect, this, ID_change, wgettext("Change"));
158 core::rect<s32> rect(0, 0, 300, 20);
159 rect += topleft_client + v2s32(35, ypos);
161 Environment->addStaticText(
162 wgettext("Passwords do not match!"),
163 rect, false, true, this, ID_message);
164 e->setVisible(false);
170 void GUIPasswordChange::drawMenu()
172 gui::IGUISkin* skin = Environment->getSkin();
175 video::IVideoDriver* driver = Environment->getVideoDriver();
177 video::SColor bgcolor(140,0,0,0);
178 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
180 gui::IGUIElement::draw();
183 bool GUIPasswordChange::acceptInput()
185 std::wstring oldpass;
186 std::wstring newpass;
188 e = getElementFromId(ID_oldPassword);
190 oldpass = e->getText();
191 e = getElementFromId(ID_newPassword1);
193 newpass = e->getText();
194 e = getElementFromId(ID_newPassword2);
195 if(e != NULL && newpass != e->getText())
197 e = getElementFromId(ID_message);
202 m_client->sendChangePassword(oldpass, newpass);
206 bool GUIPasswordChange::OnEvent(const SEvent& event)
208 if(event.EventType==EET_KEY_INPUT_EVENT)
210 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
215 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
222 if(event.EventType==EET_GUI_EVENT)
224 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
227 if(!canTakeFocus(event.GUIEvent.Element))
229 dstream<<"GUIPasswordChange: Not allowing focus change."
231 // Returning true disables focus change
235 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
237 switch(event.GUIEvent.Caller->getID())
245 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
247 switch(event.GUIEvent.Caller->getID())
250 case ID_newPassword1:
251 case ID_newPassword2:
259 return Parent ? Parent->OnEvent(event) : false;