3 Copyright (C) 2010-11 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2011 Ciaran Gultnieks <ciaran@ciarang.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "guiPasswordChange.h"
23 #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 const wchar_t *text = L"Old Password";
103 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 =
109 Environment->addEditBox(L"", rect, true, this, ID_oldPassword);
110 Environment->setFocus(e);
111 e->setPasswordBox(true);
115 core::rect<s32> rect(0, 0, 110, 20);
116 rect += topleft_client + v2s32(35, ypos+6);
117 const wchar_t *text = L"New Password";
118 Environment->addStaticText(text, rect, false, true, this, -1);
121 core::rect<s32> rect(0, 0, 230, 30);
122 rect += topleft_client + v2s32(160, ypos);
123 gui::IGUIEditBox *e =
124 Environment->addEditBox(L"", rect, true, this, ID_newPassword1);
125 e->setPasswordBox(true);
129 core::rect<s32> rect(0, 0, 110, 20);
130 rect += topleft_client + v2s32(35, ypos+6);
131 const wchar_t *text = L"Confirm Password";
132 Environment->addStaticText(text, rect, false, true, this, -1);
135 core::rect<s32> rect(0, 0, 230, 30);
136 rect += topleft_client + v2s32(160, ypos);
137 gui::IGUIEditBox *e =
138 Environment->addEditBox(L"", rect, true, this, ID_newPassword2);
139 e->setPasswordBox(true);
144 core::rect<s32> rect(0, 0, 140, 30);
145 rect = rect + v2s32(size.X/2-140/2, ypos);
146 Environment->addButton(rect, this, ID_change, L"Change");
151 core::rect<s32> rect(0, 0, 300, 20);
152 rect += topleft_client + v2s32(35, ypos);
153 const wchar_t *text = L"Passwords do not match!";
155 Environment->addStaticText(text, rect, false, true, this, ID_message);
156 e->setVisible(false);
161 void GUIPasswordChange::drawMenu()
163 gui::IGUISkin* skin = Environment->getSkin();
166 video::IVideoDriver* driver = Environment->getVideoDriver();
168 video::SColor bgcolor(140,0,0,0);
169 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
171 gui::IGUIElement::draw();
174 bool GUIPasswordChange::acceptInput()
176 std::wstring oldpass;
177 std::wstring newpass;
179 e = getElementFromId(ID_oldPassword);
181 oldpass = e->getText();
182 e = getElementFromId(ID_newPassword1);
184 newpass = e->getText();
185 e = getElementFromId(ID_newPassword2);
186 if(e != NULL && newpass != e->getText())
188 e = getElementFromId(ID_message);
193 m_client->sendChangePassword(oldpass, newpass);
197 bool GUIPasswordChange::OnEvent(const SEvent& event)
199 if(event.EventType==EET_KEY_INPUT_EVENT)
201 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
206 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
213 if(event.EventType==EET_GUI_EVENT)
215 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
218 if(!canTakeFocus(event.GUIEvent.Element))
220 dstream<<"GUIPasswordChange: Not allowing focus change."
222 // Returning true disables focus change
226 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
228 switch(event.GUIEvent.Caller->getID())
236 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
238 switch(event.GUIEvent.Caller->getID())
241 case ID_newPassword1:
242 case ID_newPassword2:
250 return Parent ? Parent->OnEvent(event) : false;