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"
24 const int ID_oldPassword = 256;
25 const int ID_newPassword1 = 257;
26 const int ID_newPassword2 = 258;
27 const int ID_change = 259;
28 const int ID_message = 260;
30 GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
31 gui::IGUIElement* parent, s32 id,
32 IMenuManager *menumgr,
35 GUIModalMenu(env, parent, id, menumgr),
40 GUIPasswordChange::~GUIPasswordChange()
45 void GUIPasswordChange::removeChildren()
48 gui::IGUIElement *e = getElementFromId(ID_oldPassword);
53 gui::IGUIElement *e = getElementFromId(ID_newPassword1);
58 gui::IGUIElement *e = getElementFromId(ID_newPassword2);
63 gui::IGUIElement *e = getElementFromId(ID_change);
69 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);
91 v2s32 size_client = size - v2s32(40, 0);
98 core::rect<s32> rect(0, 0, 110, 20);
99 rect += topleft_client + v2s32(35, ypos+6);
100 const wchar_t *text = L"Old Password";
101 Environment->addStaticText(text, rect, false, true, this, -1);
104 core::rect<s32> rect(0, 0, 230, 30);
105 rect += topleft_client + v2s32(160, ypos);
106 gui::IGUIEditBox *e =
107 Environment->addEditBox(L"", rect, true, this, ID_oldPassword);
108 Environment->setFocus(e);
109 e->setPasswordBox(true);
113 core::rect<s32> rect(0, 0, 110, 20);
114 rect += topleft_client + v2s32(35, ypos+6);
115 const wchar_t *text = L"New Password";
116 Environment->addStaticText(text, 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 const wchar_t *text = L"Confirm Password";
130 Environment->addStaticText(text, rect, false, true, this, -1);
133 core::rect<s32> rect(0, 0, 230, 30);
134 rect += topleft_client + v2s32(160, ypos);
135 gui::IGUIEditBox *e =
136 Environment->addEditBox(L"", rect, true, this, ID_newPassword2);
137 e->setPasswordBox(true);
142 core::rect<s32> rect(0, 0, 140, 30);
143 rect = rect + v2s32(size.X/2-140/2, ypos);
144 Environment->addButton(rect, this, ID_change, L"Change");
149 core::rect<s32> rect(0, 0, 300, 20);
150 rect += topleft_client + v2s32(35, ypos);
151 const wchar_t *text = L"Passwords do not match!";
153 Environment->addStaticText(text, rect, false, true, this, ID_message);
154 e->setVisible(false);
159 void GUIPasswordChange::drawMenu()
161 gui::IGUISkin* skin = Environment->getSkin();
164 video::IVideoDriver* driver = Environment->getVideoDriver();
166 video::SColor bgcolor(140,0,0,0);
167 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
169 gui::IGUIElement::draw();
172 bool GUIPasswordChange::acceptInput()
174 std::wstring oldpass;
175 std::wstring newpass;
177 e = getElementFromId(ID_oldPassword);
179 oldpass = e->getText();
180 e = getElementFromId(ID_newPassword1);
182 newpass = e->getText();
183 e = getElementFromId(ID_newPassword2);
184 if(e != NULL && newpass != e->getText())
186 e = getElementFromId(ID_message);
191 m_client->sendChangePassword(oldpass, newpass);
195 bool GUIPasswordChange::OnEvent(const SEvent& event)
197 if(event.EventType==EET_KEY_INPUT_EVENT)
199 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
204 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
211 if(event.EventType==EET_GUI_EVENT)
213 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
216 if(!canTakeFocus(event.GUIEvent.Element))
218 dstream<<"GUIPasswordChange: Not allowing focus change."
220 // Returning true disables focus change
224 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
226 switch(event.GUIEvent.Caller->getID())
234 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
236 switch(event.GUIEvent.Caller->getID())
239 case ID_newPassword1:
240 case ID_newPassword2:
248 return Parent ? Parent->OnEvent(event) : false;