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")),
103 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 Environment->addStaticText(chartowchar_t(gettext("New Password")),
118 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 Environment->addStaticText(chartowchar_t(gettext("Confirm Password")),
132 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, chartowchar_t(gettext("Change")));
151 core::rect<s32> rect(0, 0, 300, 20);
152 rect += topleft_client + v2s32(35, ypos);
154 Environment->addStaticText(
155 chartowchar_t(gettext("Passwords do not match!")),
156 rect, false, true, this, ID_message);
157 e->setVisible(false);
162 void GUIPasswordChange::drawMenu()
164 gui::IGUISkin* skin = Environment->getSkin();
167 video::IVideoDriver* driver = Environment->getVideoDriver();
169 video::SColor bgcolor(140,0,0,0);
170 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
172 gui::IGUIElement::draw();
175 bool GUIPasswordChange::acceptInput()
177 std::wstring oldpass;
178 std::wstring newpass;
180 e = getElementFromId(ID_oldPassword);
182 oldpass = e->getText();
183 e = getElementFromId(ID_newPassword1);
185 newpass = e->getText();
186 e = getElementFromId(ID_newPassword2);
187 if(e != NULL && newpass != e->getText())
189 e = getElementFromId(ID_message);
194 m_client->sendChangePassword(oldpass, newpass);
198 bool GUIPasswordChange::OnEvent(const SEvent& event)
200 if(event.EventType==EET_KEY_INPUT_EVENT)
202 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
207 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
214 if(event.EventType==EET_GUI_EVENT)
216 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
219 if(!canTakeFocus(event.GUIEvent.Element))
221 dstream<<"GUIPasswordChange: Not allowing focus change."
223 // Returning true disables focus change
227 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
229 switch(event.GUIEvent.Caller->getID())
237 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
239 switch(event.GUIEvent.Caller->getID())
242 case ID_newPassword1:
243 case ID_newPassword2:
251 return Parent ? Parent->OnEvent(event) : false;