Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset button (Incomplete, work needed) #8589

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 46 additions & 11 deletions src/gui/guiKeyChangeMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern MainGameCallback *g_gamecallback;
enum
{
GUI_ID_BACK_BUTTON = 101, GUI_ID_ABORT_BUTTON, GUI_ID_SCROLL_BAR,
GUI_ID_RESET_BUTTON,
// buttons
GUI_ID_KEY_FORWARD_BUTTON,
GUI_ID_KEY_BACKWARD_BUTTON,
Expand Down Expand Up @@ -129,17 +130,6 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
v2s32 size = DesiredRect.getSize();
v2s32 topleft(0, 0);

{
core::rect<s32> rect(0, 0, 600 * s, 40 * s);
rect += topleft + v2s32(25 * s, 3 * s);
//gui::IGUIStaticText *t =
const wchar_t *text = wgettext("Keybindings. (If this menu screws up, remove stuff from minetest.conf)");
Environment->addStaticText(text,
rect, false, true, this, -1);
delete[] text;
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}

// Build buttons

v2s32 offset(25 * s, 60 * s);
Expand Down Expand Up @@ -229,6 +219,15 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
text);
delete[] text;
}

{
core::rect<s32> rect(0, 0, 100 * s, 30 * s);
rect += topleft + v2s32(10 * s, size.Y - 40 * s);
const wchar_t *text = wgettext("Reset keys");
Environment->addButton(rect, this, GUI_ID_RESET_BUTTON,
text);
delete[] text;
}
}

void GUIKeyChangeMenu::drawMenu()
Expand Down Expand Up @@ -273,6 +272,35 @@ bool GUIKeyChangeMenu::acceptInput()
return true;
}

bool GUIKeyChangeMenu::resetInput()
{
for (key_setting *k : key_settings) {
g_settings->remove(k->setting_name);
}

{
gui::IGUIElement *e = getElementFromId(GUI_ID_CB_AUX1_DESCENDS);
if(e && e->getType() == gui::EGUIET_CHECK_BOX)
g_settings->setBool("aux1_descends", ((gui::IGUICheckBox*)e)->isChecked());
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_CB_DOUBLETAP_JUMP);
if(e && e->getType() == gui::EGUIET_CHECK_BOX)
g_settings->setBool("doubletap_jump", ((gui::IGUICheckBox*)e)->isChecked());
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_CB_AUTOJUMP);
if(e && e->getType() == gui::EGUIET_CHECK_BOX)
g_settings->setBool("autojump", ((gui::IGUICheckBox*)e)->isChecked());
}

clearKeyCache();

g_gamecallback->signalKeyConfigChange();

return true;
}

bool GUIKeyChangeMenu::resetMenu()
{
if (activeKey >= 0)
Expand Down Expand Up @@ -377,6 +405,13 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
case GUI_ID_ABORT_BUTTON: //abort
quitMenu();
return true;
case GUI_ID_RESET_BUTTON: //reset
resetInput();
regenerateGui(m_screensize_old);
key_settings.clear();
init_keys();
//quitMenu();
return true;
default:
key_setting *k = NULL;

Expand Down
2 changes: 2 additions & 0 deletions src/gui/guiKeyChangeMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class GUIKeyChangeMenu : public GUIModalMenu

bool acceptInput();

bool resetInput();

bool OnEvent(const SEvent &event);

bool pausesGame() { return true; }
Expand Down