@@ -41,7 +41,10 @@ GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
41
41
Client* client
42
42
):
43
43
GUIModalMenu(env, parent, id, menumgr),
44
- m_client(client)
44
+ m_client(client),
45
+ m_oldpass(L" " ),
46
+ m_newpass(L" " ),
47
+ m_newpass_confirm(L" " )
45
48
{
46
49
}
47
50
@@ -52,35 +55,24 @@ GUIPasswordChange::~GUIPasswordChange()
52
55
53
56
void GUIPasswordChange::removeChildren ()
54
57
{
55
- {
56
- gui::IGUIElement *e = getElementFromId (ID_oldPassword);
57
- if (e != NULL )
58
- e->remove ();
58
+ const core::list<gui::IGUIElement *> &children = getChildren ();
59
+ core::list<gui::IGUIElement *> children_copy;
60
+ for (core::list<gui::IGUIElement *>::ConstIterator i = children.begin ();
61
+ i != children.end (); i++) {
62
+ children_copy.push_back (*i);
59
63
}
60
- {
61
- gui::IGUIElement *e = getElementFromId (ID_newPassword1);
62
- if (e != NULL )
63
- e->remove ();
64
- }
65
- {
66
- gui::IGUIElement *e = getElementFromId (ID_newPassword2);
67
- if (e != NULL )
68
- e->remove ();
69
- }
70
- {
71
- gui::IGUIElement *e = getElementFromId (ID_change);
72
- if (e != NULL )
73
- e->remove ();
74
- }
75
- {
76
- gui::IGUIElement *e = getElementFromId (ID_cancel);
77
- if (e != NULL )
78
- e->remove ();
64
+ for (core::list<gui::IGUIElement *>::Iterator i = children_copy.begin ();
65
+ i != children_copy.end (); i++) {
66
+ (*i)->remove ();
79
67
}
80
68
}
81
-
82
69
void GUIPasswordChange::regenerateGui (v2u32 screensize)
83
70
{
71
+ /*
72
+ save current input
73
+ */
74
+ acceptInput ();
75
+
84
76
/*
85
77
Remove stuff
86
78
*/
@@ -119,7 +111,7 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
119
111
core::rect<s32> rect (0 , 0 , 230 , 30 );
120
112
rect += topleft_client + v2s32 (160 , ypos);
121
113
gui::IGUIEditBox *e = Environment->addEditBox (
122
- L" " , rect, true , this , ID_oldPassword);
114
+ m_oldpass. c_str () , rect, true , this , ID_oldPassword);
123
115
Environment->setFocus (e);
124
116
e->setPasswordBox (true );
125
117
}
@@ -135,7 +127,7 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
135
127
core::rect<s32> rect (0 , 0 , 230 , 30 );
136
128
rect += topleft_client + v2s32 (160 , ypos);
137
129
gui::IGUIEditBox *e = Environment->addEditBox (
138
- L" " , rect, true , this , ID_newPassword1);
130
+ m_newpass. c_str () , rect, true , this , ID_newPassword1);
139
131
e->setPasswordBox (true );
140
132
}
141
133
ypos += 50 ;
@@ -150,7 +142,7 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
150
142
core::rect<s32> rect (0 , 0 , 230 , 30 );
151
143
rect += topleft_client + v2s32 (160 , ypos);
152
144
gui::IGUIEditBox *e = Environment->addEditBox (
153
- L" " , rect, true , this , ID_newPassword2);
145
+ m_newpass_confirm. c_str () , rect, true , this , ID_newPassword2);
154
146
e->setPasswordBox (true );
155
147
}
156
148
@@ -196,25 +188,29 @@ void GUIPasswordChange::drawMenu()
196
188
gui::IGUIElement::draw ();
197
189
}
198
190
199
- bool GUIPasswordChange::acceptInput ()
191
+ void GUIPasswordChange::acceptInput ()
200
192
{
201
- std::wstring oldpass;
202
- std::wstring newpass;
203
193
gui::IGUIElement *e;
204
194
e = getElementFromId (ID_oldPassword);
205
195
if (e != NULL )
206
- oldpass = e->getText ();
196
+ m_oldpass = e->getText ();
207
197
e = getElementFromId (ID_newPassword1);
208
198
if (e != NULL )
209
- newpass = e->getText ();
199
+ m_newpass = e->getText ();
210
200
e = getElementFromId (ID_newPassword2);
211
- if (e != NULL && newpass != e->getText ()) {
212
- e = getElementFromId (ID_message);
201
+ if (e != NULL )
202
+ m_newpass_confirm = e->getText ();
203
+ }
204
+
205
+ bool GUIPasswordChange::processInput ()
206
+ {
207
+ if (m_newpass != m_newpass_confirm) {
208
+ gui::IGUIElement *e = getElementFromId (ID_message);
213
209
if (e != NULL )
214
210
e->setVisible (true );
215
211
return false ;
216
212
}
217
- m_client->sendChangePassword (wide_to_utf8 (oldpass ), wide_to_utf8 (newpass ));
213
+ m_client->sendChangePassword (wide_to_utf8 (m_oldpass ), wide_to_utf8 (m_newpass ));
218
214
return true ;
219
215
}
220
216
@@ -226,7 +222,8 @@ bool GUIPasswordChange::OnEvent(const SEvent &event)
226
222
return true ;
227
223
}
228
224
if (event.KeyInput .Key == KEY_RETURN && event.KeyInput .PressedDown ) {
229
- if (acceptInput ())
225
+ acceptInput ();
226
+ if (processInput ())
230
227
quitMenu ();
231
228
return true ;
232
229
}
@@ -244,7 +241,8 @@ bool GUIPasswordChange::OnEvent(const SEvent &event)
244
241
if (event.GUIEvent .EventType == gui::EGET_BUTTON_CLICKED) {
245
242
switch (event.GUIEvent .Caller ->getID ()) {
246
243
case ID_change:
247
- if (acceptInput ())
244
+ acceptInput ();
245
+ if (processInput ())
248
246
quitMenu ();
249
247
return true ;
250
248
case ID_cancel:
@@ -257,7 +255,8 @@ bool GUIPasswordChange::OnEvent(const SEvent &event)
257
255
case ID_oldPassword:
258
256
case ID_newPassword1:
259
257
case ID_newPassword2:
260
- if (acceptInput ())
258
+ acceptInput ();
259
+ if (processInput ())
261
260
quitMenu ();
262
261
return true ;
263
262
}
0 commit comments