Skip to content

Commit 1ff5ee0

Browse files
red-001nerzhul
authored andcommittedMay 20, 2017
Improve password change menu (#5757)
- Fix the GUI getting messed up when resizing - Save the input when resizing
1 parent 605599b commit 1ff5ee0

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed
 

Diff for: ‎src/guiPasswordChange.cpp

+38-39
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
4141
Client* client
4242
):
4343
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"")
4548
{
4649
}
4750

@@ -52,35 +55,24 @@ GUIPasswordChange::~GUIPasswordChange()
5255

5356
void GUIPasswordChange::removeChildren()
5457
{
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);
5963
}
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();
7967
}
8068
}
81-
8269
void GUIPasswordChange::regenerateGui(v2u32 screensize)
8370
{
71+
/*
72+
save current input
73+
*/
74+
acceptInput();
75+
8476
/*
8577
Remove stuff
8678
*/
@@ -119,7 +111,7 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
119111
core::rect<s32> rect(0, 0, 230, 30);
120112
rect += topleft_client + v2s32(160, ypos);
121113
gui::IGUIEditBox *e = Environment->addEditBox(
122-
L"", rect, true, this, ID_oldPassword);
114+
m_oldpass.c_str(), rect, true, this, ID_oldPassword);
123115
Environment->setFocus(e);
124116
e->setPasswordBox(true);
125117
}
@@ -135,7 +127,7 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
135127
core::rect<s32> rect(0, 0, 230, 30);
136128
rect += topleft_client + v2s32(160, ypos);
137129
gui::IGUIEditBox *e = Environment->addEditBox(
138-
L"", rect, true, this, ID_newPassword1);
130+
m_newpass.c_str(), rect, true, this, ID_newPassword1);
139131
e->setPasswordBox(true);
140132
}
141133
ypos += 50;
@@ -150,7 +142,7 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
150142
core::rect<s32> rect(0, 0, 230, 30);
151143
rect += topleft_client + v2s32(160, ypos);
152144
gui::IGUIEditBox *e = Environment->addEditBox(
153-
L"", rect, true, this, ID_newPassword2);
145+
m_newpass_confirm.c_str(), rect, true, this, ID_newPassword2);
154146
e->setPasswordBox(true);
155147
}
156148

@@ -196,25 +188,29 @@ void GUIPasswordChange::drawMenu()
196188
gui::IGUIElement::draw();
197189
}
198190

199-
bool GUIPasswordChange::acceptInput()
191+
void GUIPasswordChange::acceptInput()
200192
{
201-
std::wstring oldpass;
202-
std::wstring newpass;
203193
gui::IGUIElement *e;
204194
e = getElementFromId(ID_oldPassword);
205195
if (e != NULL)
206-
oldpass = e->getText();
196+
m_oldpass = e->getText();
207197
e = getElementFromId(ID_newPassword1);
208198
if (e != NULL)
209-
newpass = e->getText();
199+
m_newpass = e->getText();
210200
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);
213209
if (e != NULL)
214210
e->setVisible(true);
215211
return false;
216212
}
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));
218214
return true;
219215
}
220216

@@ -226,7 +222,8 @@ bool GUIPasswordChange::OnEvent(const SEvent &event)
226222
return true;
227223
}
228224
if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
229-
if (acceptInput())
225+
acceptInput();
226+
if (processInput())
230227
quitMenu();
231228
return true;
232229
}
@@ -244,7 +241,8 @@ bool GUIPasswordChange::OnEvent(const SEvent &event)
244241
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
245242
switch (event.GUIEvent.Caller->getID()) {
246243
case ID_change:
247-
if (acceptInput())
244+
acceptInput();
245+
if (processInput())
248246
quitMenu();
249247
return true;
250248
case ID_cancel:
@@ -257,7 +255,8 @@ bool GUIPasswordChange::OnEvent(const SEvent &event)
257255
case ID_oldPassword:
258256
case ID_newPassword1:
259257
case ID_newPassword2:
260-
if (acceptInput())
258+
acceptInput();
259+
if (processInput())
261260
quitMenu();
262261
return true;
263262
}

Diff for: ‎src/guiPasswordChange.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ class GUIPasswordChange : public GUIModalMenu
3939

4040
void drawMenu();
4141

42-
bool acceptInput();
42+
void acceptInput();
43+
44+
bool processInput();
4345

4446
bool OnEvent(const SEvent &event);
4547

4648
private:
4749
Client *m_client;
50+
std::wstring m_oldpass;
51+
std::wstring m_newpass;
52+
std::wstring m_newpass_confirm;
4853
};
4954

5055
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.