X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgui%2FguiKeyChangeMenu.cpp;h=94fe0074a343ec82c564705bc8d6dbe300b38f1e;hb=8e9e76a5076db0042773c6b925698f018a208b29;hp=1d4f351cc9d71e4cc33120cd8671bd1bf7425ea0;hpb=69a2099c04527404f2d0942f2088b3d22dd75b5a;p=dragonfireclient.git diff --git a/src/gui/guiKeyChangeMenu.cpp b/src/gui/guiKeyChangeMenu.cpp index 1d4f351cc..94fe0074a 100644 --- a/src/gui/guiKeyChangeMenu.cpp +++ b/src/gui/guiKeyChangeMenu.cpp @@ -59,6 +59,7 @@ enum GUI_ID_KEY_SNEAK_BUTTON, GUI_ID_KEY_DROP_BUTTON, GUI_ID_KEY_INVENTORY_BUTTON, + GUI_ID_KEY_ENDERCHEST_BUTTON, GUI_ID_KEY_HOTBAR_PREV_BUTTON, GUI_ID_KEY_HOTBAR_NEXT_BUTTON, GUI_ID_KEY_MUTE_BUTTON, @@ -72,9 +73,19 @@ enum GUI_ID_KEY_CHATLOG_BUTTON, GUI_ID_KEY_HUD_BUTTON, GUI_ID_KEY_FOG_BUTTON, + GUI_ID_KEY_CHEAT_MENU_BUTTON, GUI_ID_KEY_DEC_RANGE_BUTTON, GUI_ID_KEY_INC_RANGE_BUTTON, GUI_ID_KEY_AUTOFWD_BUTTON, + GUI_ID_KEY_KILLAURA_BUTTON, + GUI_ID_KEY_FREECAM_BUTTON, + GUI_ID_KEY_SCAFFOLD_BUTTON, + GUI_ID_KEY_NEXT_ITEM_BUTTON, + GUI_ID_KEY_SELECT_UP_BUTTON, + GUI_ID_KEY_SELECT_DOWN_BUTTON, + GUI_ID_KEY_SELECT_LEFT_BUTTON, + GUI_ID_KEY_SELECT_RIGHT_BUTTON, + GUI_ID_KEY_SELECT_CONFIRM_BUTTON, // other GUI_ID_CB_AUX1_DESCENDS, GUI_ID_CB_DOUBLETAP_JUMP, @@ -82,12 +93,12 @@ enum }; GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) : -GUIModalMenu(env, parent, id, menumgr) + gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, + ISimpleTextureSource *tsrc) : + GUIModalMenu(env, parent, id, menumgr), + m_tsrc(tsrc) { init_keys(); - for (key_setting *ks : key_settings) - key_used.push_back(ks->key); } GUIKeyChangeMenu::~GUIKeyChangeMenu() @@ -112,6 +123,7 @@ void GUIKeyChangeMenu::removeChildren() for (gui::IGUIElement *i : children_copy) { i->remove(); } + key_used_text = nullptr; } void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) @@ -120,9 +132,9 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) const float s = m_gui_scale; DesiredRect = core::rect( - screensize.X / 2 - 835 * s / 2, + screensize.X / 2 - 1113 * s / 2, screensize.Y / 2 - 430 * s / 2, - screensize.X / 2 + 835 * s / 2, + screensize.X / 2 + 1113 * s / 2, screensize.Y / 2 + 430 * s / 2 ); recalculateAbsolutePosition(false); @@ -158,7 +170,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(offset.X + 150 * s, offset.Y - 5 * s); const wchar_t *text = wgettext(k->key.name()); - k->button = GUIButton::addButton(Environment, rect, this, k->id, text); + k->button = GUIButton::addButton(Environment, rect, m_tsrc, this, k->id, text); delete[] text; } if ((i + 1) % KMaxButtonPerColumns == 0) { @@ -218,14 +230,14 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(size.X / 2 - 105 * s, size.Y - 40 * s); const wchar_t *text = wgettext("Save"); - GUIButton::addButton(Environment, rect, this, GUI_ID_BACK_BUTTON, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_BACK_BUTTON, text); delete[] text; } { core::rect rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(size.X / 2 + 5 * s, size.Y - 40 * s); const wchar_t *text = wgettext("Cancel"); - GUIButton::addButton(Environment, rect, this, GUI_ID_ABORT_BUTTON, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_ABORT_BUTTON, text); delete[] text; } } @@ -246,7 +258,13 @@ void GUIKeyChangeMenu::drawMenu() bool GUIKeyChangeMenu::acceptInput() { for (key_setting *k : key_settings) { - g_settings->set(k->setting_name, k->key.sym()); + std::string default_key; + g_settings->getDefaultNoEx(k->setting_name, default_key); + + if (k->key.sym() != default_key) + g_settings->set(k->setting_name, k->key.sym()); + else + g_settings->remove(k->setting_name); } { @@ -274,29 +292,28 @@ bool GUIKeyChangeMenu::acceptInput() bool GUIKeyChangeMenu::resetMenu() { - if (activeKey >= 0) - { - for (key_setting *k : key_settings) { - if (k->id == activeKey) { - const wchar_t *text = wgettext(k->key.name()); - k->button->setText(text); - delete[] text; - break; - } - } - activeKey = -1; + if (active_key) { + const wchar_t *text = wgettext(active_key->key.name()); + active_key->button->setText(text); + delete[] text; + active_key = nullptr; return false; } return true; } bool GUIKeyChangeMenu::OnEvent(const SEvent& event) { - if (event.EventType == EET_KEY_INPUT_EVENT && activeKey >= 0 + if (event.EventType == EET_KEY_INPUT_EVENT && active_key && event.KeyInput.PressedDown) { bool prefer_character = shift_down; KeyPress kp(event.KeyInput, prefer_character); + if (event.KeyInput.Key == irr::KEY_DELETE) + kp = KeyPress(""); // To erase key settings + else if (event.KeyInput.Key == irr::KEY_ESCAPE) + kp = active_key->key; // Cancel + bool shift_went_down = false; if(!shift_down && (event.KeyInput.Key == irr::KEY_SHIFT || @@ -304,51 +321,46 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) event.KeyInput.Key == irr::KEY_RSHIFT)) shift_went_down = true; - // Remove Key already in use message - if(this->key_used_text) - { - this->key_used_text->remove(); - this->key_used_text = NULL; - } // Display Key already in use message - if (std::find(this->key_used.begin(), this->key_used.end(), kp) != this->key_used.end()) - { - core::rect < s32 > rect(0, 0, 600, 40); + bool key_in_use = false; + if (strcmp(kp.sym(), "") != 0) { + for (key_setting *ks : key_settings) { + if (ks != active_key && ks->key == kp) { + key_in_use = true; + break; + } + } + } + + if (key_in_use && !this->key_used_text) { + core::rect rect(0, 0, 600, 40); rect += v2s32(0, 0) + v2s32(25, 30); const wchar_t *text = wgettext("Key already in use"); this->key_used_text = Environment->addStaticText(text, rect, false, true, this, -1); delete[] text; - //infostream << "Key already in use" << std::endl; + } else if (!key_in_use && this->key_used_text) { + this->key_used_text->remove(); + this->key_used_text = nullptr; } // But go on { - key_setting *k = NULL; - for (key_setting *ks : key_settings) { - if (ks->id == activeKey) { - k = ks; - break; - } - } - FATAL_ERROR_IF(k == NULL, "Key setting not found"); - k->key = kp; - const wchar_t *text = wgettext(k->key.name()); - k->button->setText(text); + active_key->key = kp; + const wchar_t *text = wgettext(kp.name()); + active_key->button->setText(text); delete[] text; - this->key_used.push_back(kp); - // Allow characters made with shift - if(shift_went_down){ + if (shift_went_down){ shift_down = true; return false; } - activeKey = -1; + active_key = nullptr; return true; } - } else if (event.EventType == EET_KEY_INPUT_EVENT && activeKey < 0 + } else if (event.EventType == EET_KEY_INPUT_EVENT && !active_key && event.KeyInput.PressedDown && event.KeyInput.Key == irr::KEY_ESCAPE) { quitMenu(); @@ -359,7 +371,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) { if (!canTakeFocus(event.GUIEvent.Element)) { - dstream << "GUIMainMenu: Not allowing focus change." + infostream << "GUIKeyChangeMenu: Not allowing focus change." << std::endl; // Returning true disables focus change return true; @@ -377,24 +389,19 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) quitMenu(); return true; default: - key_setting *k = NULL; - + resetMenu(); for (key_setting *ks : key_settings) { if (ks->id == event.GUIEvent.Caller->getID()) { - k = ks; + active_key = ks; break; } } - FATAL_ERROR_IF(k == NULL, "Key setting not found"); + FATAL_ERROR_IF(!active_key, "Key setting not found"); - resetMenu(); shift_down = false; - activeKey = event.GUIEvent.Caller->getID(); const wchar_t *text = wgettext("press key"); - k->button->setText(text); + active_key->button->setText(text); delete[] text; - this->key_used.erase(std::remove(this->key_used.begin(), - this->key_used.end(), k->key), this->key_used.end()); break; } Environment->setFocus(this); @@ -425,6 +432,7 @@ void GUIKeyChangeMenu::init_keys() this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wgettext("Sneak"), "keymap_sneak"); this->add_key(GUI_ID_KEY_DROP_BUTTON, wgettext("Drop"), "keymap_drop"); this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), "keymap_inventory"); + this->add_key(GUI_ID_KEY_ENDERCHEST_BUTTON,wgettext("Enderchest"), "keymap_enderchest"); this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON,wgettext("Prev. item"), "keymap_hotbar_previous"); this->add_key(GUI_ID_KEY_HOTBAR_NEXT_BUTTON,wgettext("Next item"), "keymap_hotbar_next"); this->add_key(GUI_ID_KEY_ZOOM_BUTTON, wgettext("Zoom"), "keymap_zoom"); @@ -449,4 +457,14 @@ void GUIKeyChangeMenu::init_keys() this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud"); this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat"); this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog"); + this->add_key(GUI_ID_KEY_CHEAT_MENU_BUTTON,wgettext("Toggle C. Menu"),"keymap_toggle_cheat_menu"); + this->add_key(GUI_ID_KEY_KILLAURA_BUTTON, wgettext("Killaura"), "keymap_toggle_killaura"); + this->add_key(GUI_ID_KEY_FREECAM_BUTTON, wgettext("Freecam"), "keymap_toggle_freecam"); + this->add_key(GUI_ID_KEY_SCAFFOLD_BUTTON, wgettext("Scaffold"), "keymap_toggle_scaffold"); + this->add_key(GUI_ID_KEY_NEXT_ITEM_BUTTON, wgettext("NextItem"), "keymap_toggle_next_item"); + this->add_key(GUI_ID_KEY_SELECT_UP_BUTTON, wgettext("C. Menu Up"), "keymap_select_up"); + this->add_key(GUI_ID_KEY_SELECT_DOWN_BUTTON,wgettext("C. Menu Down"), "keymap_select_down"); + this->add_key(GUI_ID_KEY_SELECT_LEFT_BUTTON,wgettext("C. Menu Left"), "keymap_select_left"); + this->add_key(GUI_ID_KEY_SELECT_RIGHT_BUTTON,wgettext("C. Menu Right"),"keymap_select_right"); + this->add_key(GUI_ID_KEY_SELECT_CONFIRM_BUTTON,wgettext("C. Menu Enter"),"keymap_select_confirm"); }