2011-06-01 19:44:07 +02:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
Copyright (C) 2013 Ciaran Gultnieks <ciaran@ciarang.com>
|
|
|
|
Copyright (C) 2013 teddydestodes <derkomtur@schattengang.net>
|
2011-06-01 19:44:07 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2011-06-01 19:44:07 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-06-01 19:44:07 +02:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-06-01 19:44:07 +02:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "guiKeyChangeMenu.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "serialization.h"
|
|
|
|
#include <string>
|
2011-10-12 12:53:38 +02:00
|
|
|
#include <IGUICheckBox.h>
|
|
|
|
#include <IGUIEditBox.h>
|
|
|
|
#include <IGUIButton.h>
|
|
|
|
#include <IGUIStaticText.h>
|
|
|
|
#include <IGUIFont.h>
|
|
|
|
#include "settings.h"
|
2012-07-26 09:49:00 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-11-10 03:26:19 +01:00
|
|
|
#include "mainmenumanager.h" // for g_gamecallback
|
|
|
|
|
2012-07-26 09:49:00 +02:00
|
|
|
#define KMaxButtonPerColumns 12
|
2011-06-01 19:44:07 +02:00
|
|
|
|
2014-11-10 03:26:19 +01:00
|
|
|
extern MainGameCallback *g_gamecallback;
|
|
|
|
|
2012-03-12 23:06:37 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
GUI_ID_BACK_BUTTON = 101, GUI_ID_ABORT_BUTTON, GUI_ID_SCROLL_BAR,
|
2012-09-04 23:55:19 +02:00
|
|
|
// buttons
|
2012-03-12 23:06:37 +01:00
|
|
|
GUI_ID_KEY_FORWARD_BUTTON,
|
|
|
|
GUI_ID_KEY_BACKWARD_BUTTON,
|
|
|
|
GUI_ID_KEY_LEFT_BUTTON,
|
|
|
|
GUI_ID_KEY_RIGHT_BUTTON,
|
|
|
|
GUI_ID_KEY_USE_BUTTON,
|
|
|
|
GUI_ID_KEY_FLY_BUTTON,
|
|
|
|
GUI_ID_KEY_FAST_BUTTON,
|
|
|
|
GUI_ID_KEY_JUMP_BUTTON,
|
2012-12-09 13:34:16 +01:00
|
|
|
GUI_ID_KEY_NOCLIP_BUTTON,
|
2015-02-15 20:27:15 +01:00
|
|
|
GUI_ID_KEY_CINEMATIC_BUTTON,
|
2012-03-12 23:06:37 +01:00
|
|
|
GUI_ID_KEY_CHAT_BUTTON,
|
|
|
|
GUI_ID_KEY_CMD_BUTTON,
|
2017-03-25 00:43:36 +01:00
|
|
|
GUI_ID_KEY_CMD_LOCAL_BUTTON,
|
2012-03-12 23:06:37 +01:00
|
|
|
GUI_ID_KEY_CONSOLE_BUTTON,
|
|
|
|
GUI_ID_KEY_SNEAK_BUTTON,
|
|
|
|
GUI_ID_KEY_DROP_BUTTON,
|
|
|
|
GUI_ID_KEY_INVENTORY_BUTTON,
|
2014-07-03 07:46:19 +02:00
|
|
|
GUI_ID_KEY_HOTBAR_PREV_BUTTON,
|
|
|
|
GUI_ID_KEY_HOTBAR_NEXT_BUTTON,
|
|
|
|
GUI_ID_KEY_MUTE_BUTTON,
|
|
|
|
GUI_ID_KEY_DEC_VOLUME_BUTTON,
|
|
|
|
GUI_ID_KEY_INC_VOLUME_BUTTON,
|
2012-09-04 23:55:19 +02:00
|
|
|
GUI_ID_KEY_RANGE_BUTTON,
|
2013-03-31 05:30:32 +02:00
|
|
|
GUI_ID_KEY_ZOOM_BUTTON,
|
2017-07-25 18:56:45 +02:00
|
|
|
GUI_ID_KEY_CAMERA_BUTTON,
|
|
|
|
GUI_ID_KEY_MINIMAP_BUTTON,
|
|
|
|
GUI_ID_KEY_SCREENSHOT_BUTTON,
|
|
|
|
GUI_ID_KEY_CHATLOG_BUTTON,
|
|
|
|
GUI_ID_KEY_HUD_BUTTON,
|
|
|
|
GUI_ID_KEY_FOG_BUTTON,
|
|
|
|
GUI_ID_KEY_DEC_RANGE_BUTTON,
|
|
|
|
GUI_ID_KEY_INC_RANGE_BUTTON,
|
|
|
|
GUI_ID_KEY_AUTOFWD_BUTTON,
|
2012-09-04 23:55:19 +02:00
|
|
|
// other
|
|
|
|
GUI_ID_CB_AUX1_DESCENDS,
|
2013-01-04 20:00:49 +01:00
|
|
|
GUI_ID_CB_DOUBLETAP_JUMP,
|
2018-11-22 22:47:15 +01:00
|
|
|
GUI_ID_CB_AUTOJUMP,
|
2012-03-12 23:06:37 +01:00
|
|
|
};
|
|
|
|
|
2011-06-01 19:44:07 +02:00
|
|
|
GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
|
2012-07-26 09:49:00 +02:00
|
|
|
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) :
|
|
|
|
GUIModalMenu(env, parent, id, menumgr)
|
2011-06-01 19:44:07 +02:00
|
|
|
{
|
|
|
|
init_keys();
|
2017-08-20 19:37:29 +02:00
|
|
|
for (key_setting *ks : key_settings)
|
|
|
|
key_used.push_back(ks->key);
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GUIKeyChangeMenu::~GUIKeyChangeMenu()
|
|
|
|
{
|
|
|
|
removeChildren();
|
2013-04-07 19:15:17 +02:00
|
|
|
|
2017-08-20 19:37:29 +02:00
|
|
|
for (key_setting *ks : key_settings) {
|
|
|
|
delete[] ks->button_name;
|
|
|
|
delete ks;
|
2013-04-07 19:15:17 +02:00
|
|
|
}
|
|
|
|
key_settings.clear();
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIKeyChangeMenu::removeChildren()
|
|
|
|
{
|
|
|
|
const core::list<gui::IGUIElement*> &children = getChildren();
|
|
|
|
core::list<gui::IGUIElement*> children_copy;
|
2017-08-20 19:37:29 +02:00
|
|
|
for (gui::IGUIElement*i : children) {
|
|
|
|
children_copy.push_back(i);
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
|
|
|
|
for (gui::IGUIElement *i : children_copy) {
|
|
|
|
i->remove();
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
|
|
|
|
{
|
|
|
|
removeChildren();
|
2017-06-17 19:11:28 +02:00
|
|
|
|
2018-11-26 22:55:24 +01:00
|
|
|
const float s = m_gui_scale;
|
|
|
|
DesiredRect = core::rect<s32>(
|
|
|
|
screensize.X / 2 - 745 * s / 2,
|
|
|
|
screensize.Y / 2 - 430 * s / 2,
|
|
|
|
screensize.X / 2 + 745 * s / 2,
|
|
|
|
screensize.Y / 2 + 430 * s / 2
|
|
|
|
);
|
2011-06-01 19:44:07 +02:00
|
|
|
recalculateAbsolutePosition(false);
|
|
|
|
|
2018-11-26 22:55:24 +01:00
|
|
|
v2s32 size = DesiredRect.getSize();
|
2011-06-01 19:44:07 +02:00
|
|
|
v2s32 topleft(0, 0);
|
2017-06-17 19:11:28 +02:00
|
|
|
|
2011-06-01 19:44:07 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 600 * s, 40 * s);
|
|
|
|
rect += topleft + v2s32(25 * s, 3 * s);
|
2011-06-01 19:44:07 +02:00
|
|
|
//gui::IGUIStaticText *t =
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("Keybindings. (If this menu screws up, remove stuff from minetest.conf)");
|
2013-04-07 19:15:17 +02:00
|
|
|
Environment->addStaticText(text,
|
2012-07-26 09:49:00 +02:00
|
|
|
rect, false, true, this, -1);
|
2013-04-07 19:15:17 +02:00
|
|
|
delete[] text;
|
2011-11-27 04:01:38 +01:00
|
|
|
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
|
|
|
|
}
|
|
|
|
|
2012-07-26 09:49:00 +02:00
|
|
|
// Build buttons
|
2011-06-01 19:44:07 +02:00
|
|
|
|
2018-11-26 22:55:24 +01:00
|
|
|
v2s32 offset(25 * s, 60 * s);
|
2011-06-01 19:44:07 +02:00
|
|
|
|
2012-07-26 09:49:00 +02:00
|
|
|
for(size_t i = 0; i < key_settings.size(); i++)
|
2011-06-01 19:44:07 +02:00
|
|
|
{
|
2012-07-26 09:49:00 +02:00
|
|
|
key_setting *k = key_settings.at(i);
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 150 * s, 20 * s);
|
2012-07-26 09:49:00 +02:00
|
|
|
rect += topleft + v2s32(offset.X, offset.Y);
|
|
|
|
Environment->addStaticText(k->button_name, rect, false, true, this, -1);
|
|
|
|
}
|
2011-06-01 19:44:07 +02:00
|
|
|
|
2012-07-26 09:49:00 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 100 * s, 30 * s);
|
|
|
|
rect += topleft + v2s32(offset.X + 120 * s, offset.Y - 5 * s);
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext(k->key.name());
|
|
|
|
k->button = Environment->addButton(rect, this, k->id, text);
|
2013-04-07 19:15:17 +02:00
|
|
|
delete[] text;
|
2012-07-26 09:49:00 +02:00
|
|
|
}
|
2014-07-03 07:46:19 +02:00
|
|
|
if ((i + 1) % KMaxButtonPerColumns == 0) {
|
2018-11-26 22:55:24 +01:00
|
|
|
offset.X += 230 * s;
|
|
|
|
offset.Y = 60 * s;
|
2014-07-03 07:46:19 +02:00
|
|
|
} else {
|
2018-11-26 22:55:24 +01:00
|
|
|
offset += v2s32(0, 25 * s);
|
2014-07-03 07:46:19 +02:00
|
|
|
}
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
2017-06-17 19:11:28 +02:00
|
|
|
|
2012-09-04 23:55:19 +02:00
|
|
|
{
|
2015-01-21 02:50:33 +01:00
|
|
|
s32 option_x = offset.X;
|
2018-11-26 22:55:24 +01:00
|
|
|
s32 option_y = offset.Y + 5 * s;
|
|
|
|
u32 option_w = 180 * s;
|
2012-09-04 23:55:19 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, option_w, 30 * s);
|
2012-09-04 23:55:19 +02:00
|
|
|
rect += topleft + v2s32(option_x, option_y);
|
2017-07-29 19:24:10 +02:00
|
|
|
const wchar_t *text = wgettext("\"Special\" = climb down");
|
2012-09-04 23:55:19 +02:00
|
|
|
Environment->addCheckBox(g_settings->getBool("aux1_descends"), rect, this,
|
2013-04-07 19:15:17 +02:00
|
|
|
GUI_ID_CB_AUX1_DESCENDS, text);
|
|
|
|
delete[] text;
|
2012-09-04 23:55:19 +02:00
|
|
|
}
|
2018-11-26 22:55:24 +01:00
|
|
|
offset += v2s32(0, 25 * s);
|
2013-01-03 19:51:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-01-21 02:50:33 +01:00
|
|
|
s32 option_x = offset.X;
|
2018-11-26 22:55:24 +01:00
|
|
|
s32 option_y = offset.Y + 5 * s;
|
|
|
|
u32 option_w = 280 * s;
|
2013-01-03 19:51:52 +01:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, option_w, 30 * s);
|
2013-01-03 19:51:52 +01:00
|
|
|
rect += topleft + v2s32(option_x, option_y);
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("Double tap \"jump\" to toggle fly");
|
2013-01-04 20:00:49 +01:00
|
|
|
Environment->addCheckBox(g_settings->getBool("doubletap_jump"), rect, this,
|
2013-04-07 19:15:17 +02:00
|
|
|
GUI_ID_CB_DOUBLETAP_JUMP, text);
|
|
|
|
delete[] text;
|
2013-01-03 19:51:52 +01:00
|
|
|
}
|
2018-11-26 22:55:24 +01:00
|
|
|
offset += v2s32(0, 25 * s);
|
2012-09-04 23:55:19 +02:00
|
|
|
}
|
2011-06-01 19:44:07 +02:00
|
|
|
|
2018-11-22 22:47:15 +01:00
|
|
|
{
|
|
|
|
s32 option_x = offset.X;
|
2018-11-26 22:55:24 +01:00
|
|
|
s32 option_y = offset.Y + 5 * s;
|
2018-11-22 22:47:15 +01:00
|
|
|
u32 option_w = 280;
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, option_w, 30 * s);
|
2018-11-22 22:47:15 +01:00
|
|
|
rect += topleft + v2s32(option_x, option_y);
|
|
|
|
const wchar_t *text = wgettext("Automatic jumping");
|
|
|
|
Environment->addCheckBox(g_settings->getBool("autojump"), rect, this,
|
|
|
|
GUI_ID_CB_AUTOJUMP, text);
|
|
|
|
delete[] text;
|
|
|
|
}
|
|
|
|
offset += v2s32(0, 25);
|
|
|
|
}
|
|
|
|
|
2011-06-01 19:44:07 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 100 * s, 30 * s);
|
|
|
|
rect += topleft + v2s32(size.X / 2 - 105 * s, size.Y - 40 * s);
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("Save");
|
2011-07-30 11:43:20 +02:00
|
|
|
Environment->addButton(rect, this, GUI_ID_BACK_BUTTON,
|
2015-02-01 23:59:23 +01:00
|
|
|
text);
|
2013-04-07 19:15:17 +02:00
|
|
|
delete[] text;
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 100 * s, 30 * s);
|
|
|
|
rect += topleft + v2s32(size.X / 2 + 5 * s, size.Y - 40 * s);
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("Cancel");
|
2011-07-30 11:43:20 +02:00
|
|
|
Environment->addButton(rect, this, GUI_ID_ABORT_BUTTON,
|
2015-02-01 23:59:23 +01:00
|
|
|
text);
|
2013-04-07 19:15:17 +02:00
|
|
|
delete[] text;
|
2017-06-17 19:11:28 +02:00
|
|
|
}
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIKeyChangeMenu::drawMenu()
|
|
|
|
{
|
|
|
|
gui::IGUISkin* skin = Environment->getSkin();
|
|
|
|
if (!skin)
|
|
|
|
return;
|
|
|
|
video::IVideoDriver* driver = Environment->getVideoDriver();
|
|
|
|
|
|
|
|
video::SColor bgcolor(140, 0, 0, 0);
|
2018-11-26 22:55:24 +01:00
|
|
|
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
|
2011-06-01 19:44:07 +02:00
|
|
|
|
|
|
|
gui::IGUIElement::draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GUIKeyChangeMenu::acceptInput()
|
|
|
|
{
|
2017-08-20 19:37:29 +02:00
|
|
|
for (key_setting *k : key_settings) {
|
2012-07-26 09:49:00 +02:00
|
|
|
g_settings->set(k->setting_name, k->key.sym());
|
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
|
2012-09-04 23:55:19 +02:00
|
|
|
{
|
|
|
|
gui::IGUIElement *e = getElementFromId(GUI_ID_CB_AUX1_DESCENDS);
|
2018-11-22 22:47:15 +01:00
|
|
|
if(e && e->getType() == gui::EGUIET_CHECK_BOX)
|
2012-09-04 23:55:19 +02:00
|
|
|
g_settings->setBool("aux1_descends", ((gui::IGUICheckBox*)e)->isChecked());
|
|
|
|
}
|
2013-01-03 19:51:52 +01:00
|
|
|
{
|
2013-01-04 20:00:49 +01:00
|
|
|
gui::IGUIElement *e = getElementFromId(GUI_ID_CB_DOUBLETAP_JUMP);
|
2018-11-22 22:47:15 +01:00
|
|
|
if(e && e->getType() == gui::EGUIET_CHECK_BOX)
|
2013-01-04 20:00:49 +01:00
|
|
|
g_settings->setBool("doubletap_jump", ((gui::IGUICheckBox*)e)->isChecked());
|
2013-01-03 19:51:52 +01:00
|
|
|
}
|
2018-11-22 22:47:15 +01:00
|
|
|
{
|
|
|
|
gui::IGUIElement *e = getElementFromId(GUI_ID_CB_AUTOJUMP);
|
|
|
|
if(e && e->getType() == gui::EGUIET_CHECK_BOX)
|
|
|
|
g_settings->setBool("autojump", ((gui::IGUICheckBox*)e)->isChecked());
|
|
|
|
}
|
2014-11-10 03:26:19 +01:00
|
|
|
|
2011-07-22 21:53:50 +02:00
|
|
|
clearKeyCache();
|
2014-11-10 03:26:19 +01:00
|
|
|
|
|
|
|
g_gamecallback->signalKeyConfigChange();
|
|
|
|
|
2011-06-01 19:44:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GUIKeyChangeMenu::resetMenu()
|
|
|
|
{
|
|
|
|
if (activeKey >= 0)
|
|
|
|
{
|
2017-08-20 19:37:29 +02:00
|
|
|
for (key_setting *k : key_settings) {
|
|
|
|
if (k->id == activeKey) {
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext(k->key.name());
|
2013-04-07 19:15:17 +02:00
|
|
|
k->button->setText(text);
|
|
|
|
delete[] text;
|
2012-07-26 09:49:00 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
|
|
|
activeKey = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
|
|
|
|
{
|
|
|
|
if (event.EventType == EET_KEY_INPUT_EVENT && activeKey >= 0
|
2015-06-30 21:04:06 +02:00
|
|
|
&& event.KeyInput.PressedDown) {
|
2017-06-17 19:11:28 +02:00
|
|
|
|
2012-09-01 17:02:29 +02:00
|
|
|
bool prefer_character = shift_down;
|
|
|
|
KeyPress kp(event.KeyInput, prefer_character);
|
2017-06-17 19:11:28 +02:00
|
|
|
|
2012-09-01 17:02:29 +02:00
|
|
|
bool shift_went_down = false;
|
|
|
|
if(!shift_down &&
|
|
|
|
(event.KeyInput.Key == irr::KEY_SHIFT ||
|
|
|
|
event.KeyInput.Key == irr::KEY_LSHIFT ||
|
|
|
|
event.KeyInput.Key == irr::KEY_RSHIFT))
|
|
|
|
shift_went_down = true;
|
2011-08-13 22:44:31 +02:00
|
|
|
|
2012-07-26 09:49:00 +02:00
|
|
|
// Remove Key already in use message
|
|
|
|
if(this->key_used_text)
|
2011-11-27 04:01:38 +01:00
|
|
|
{
|
2012-07-26 09:49:00 +02:00
|
|
|
this->key_used_text->remove();
|
|
|
|
this->key_used_text = NULL;
|
2011-11-27 04:01:38 +01:00
|
|
|
}
|
2012-07-26 09:49:00 +02:00
|
|
|
// Display Key already in use message
|
|
|
|
if (std::find(this->key_used.begin(), this->key_used.end(), kp) != this->key_used.end())
|
2011-06-01 19:44:07 +02:00
|
|
|
{
|
2012-07-26 09:49:00 +02:00
|
|
|
core::rect < s32 > rect(0, 0, 600, 40);
|
|
|
|
rect += v2s32(0, 0) + v2s32(25, 30);
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("Key already in use");
|
2013-04-07 19:15:17 +02:00
|
|
|
this->key_used_text = Environment->addStaticText(text,
|
2015-02-01 23:59:23 +01:00
|
|
|
rect, false, true, this, -1);
|
2013-04-07 19:15:17 +02:00
|
|
|
delete[] text;
|
2012-07-26 09:49:00 +02:00
|
|
|
//infostream << "Key already in use" << std::endl;
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
2012-07-26 09:49:00 +02:00
|
|
|
|
|
|
|
// But go on
|
2011-06-01 19:44:07 +02:00
|
|
|
{
|
2015-03-06 11:21:51 +01:00
|
|
|
key_setting *k = NULL;
|
2017-08-20 19:37:29 +02:00
|
|
|
for (key_setting *ks : key_settings) {
|
|
|
|
if (ks->id == activeKey) {
|
|
|
|
k = ks;
|
2012-07-26 09:49:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-03-06 11:21:51 +01:00
|
|
|
FATAL_ERROR_IF(k == NULL, "Key setting not found");
|
2012-07-26 09:49:00 +02:00
|
|
|
k->key = kp;
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext(k->key.name());
|
2013-04-07 19:15:17 +02:00
|
|
|
k->button->setText(text);
|
|
|
|
delete[] text;
|
2012-07-26 09:49:00 +02:00
|
|
|
|
|
|
|
this->key_used.push_back(kp);
|
|
|
|
|
2012-09-01 17:02:29 +02:00
|
|
|
// Allow characters made with shift
|
|
|
|
if(shift_went_down){
|
|
|
|
shift_down = true;
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
|
|
|
|
activeKey = -1;
|
|
|
|
return true;
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
2015-06-30 21:04:06 +02:00
|
|
|
} else if (event.EventType == EET_KEY_INPUT_EVENT && activeKey < 0
|
|
|
|
&& event.KeyInput.PressedDown
|
|
|
|
&& event.KeyInput.Key == irr::KEY_ESCAPE) {
|
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
} else if (event.EventType == EET_GUI_EVENT) {
|
2011-06-01 19:44:07 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST
|
2012-07-26 09:49:00 +02:00
|
|
|
&& isVisible())
|
2011-06-01 19:44:07 +02:00
|
|
|
{
|
|
|
|
if (!canTakeFocus(event.GUIEvent.Element))
|
|
|
|
{
|
|
|
|
dstream << "GUIMainMenu: Not allowing focus change."
|
2012-07-26 09:49:00 +02:00
|
|
|
<< std::endl;
|
2011-06-01 19:44:07 +02:00
|
|
|
// Returning true disables focus change
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED)
|
|
|
|
{
|
|
|
|
switch (event.GUIEvent.Caller->getID())
|
|
|
|
{
|
2012-07-26 09:49:00 +02:00
|
|
|
case GUI_ID_BACK_BUTTON: //back
|
|
|
|
acceptInput();
|
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
case GUI_ID_ABORT_BUTTON: //abort
|
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
key_setting *k = NULL;
|
2017-08-20 19:37:29 +02:00
|
|
|
|
|
|
|
for (key_setting *ks : key_settings) {
|
|
|
|
if (ks->id == event.GUIEvent.Caller->getID()) {
|
|
|
|
k = ks;
|
2012-07-26 09:49:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-03-06 11:21:51 +01:00
|
|
|
FATAL_ERROR_IF(k == NULL, "Key setting not found");
|
2012-07-26 09:49:00 +02:00
|
|
|
|
|
|
|
resetMenu();
|
2012-09-01 17:02:29 +02:00
|
|
|
shift_down = false;
|
2012-07-26 09:49:00 +02:00
|
|
|
activeKey = event.GUIEvent.Caller->getID();
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("press key");
|
2013-04-07 19:15:17 +02:00
|
|
|
k->button->setText(text);
|
|
|
|
delete[] text;
|
2012-07-26 09:49:00 +02:00
|
|
|
this->key_used.erase(std::remove(this->key_used.begin(),
|
|
|
|
this->key_used.end(), k->key), this->key_used.end());
|
|
|
|
break;
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
2012-07-26 09:49:00 +02:00
|
|
|
Environment->setFocus(this);
|
2011-06-01 19:44:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Parent ? Parent->OnEvent(event) : false;
|
|
|
|
}
|
|
|
|
|
2015-02-01 23:59:23 +01:00
|
|
|
void GUIKeyChangeMenu::add_key(int id, const wchar_t *button_name, const std::string &setting_name)
|
2012-07-26 09:49:00 +02:00
|
|
|
{
|
|
|
|
key_setting *k = new key_setting;
|
|
|
|
k->id = id;
|
2013-04-07 19:15:17 +02:00
|
|
|
|
|
|
|
k->button_name = button_name;
|
2012-07-26 09:49:00 +02:00
|
|
|
k->setting_name = setting_name;
|
|
|
|
k->key = getKeySetting(k->setting_name.c_str());
|
|
|
|
key_settings.push_back(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIKeyChangeMenu::init_keys()
|
|
|
|
{
|
2015-02-15 20:27:15 +01:00
|
|
|
this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wgettext("Forward"), "keymap_forward");
|
|
|
|
this->add_key(GUI_ID_KEY_BACKWARD_BUTTON, wgettext("Backward"), "keymap_backward");
|
|
|
|
this->add_key(GUI_ID_KEY_LEFT_BUTTON, wgettext("Left"), "keymap_left");
|
|
|
|
this->add_key(GUI_ID_KEY_RIGHT_BUTTON, wgettext("Right"), "keymap_right");
|
2017-07-29 19:24:10 +02:00
|
|
|
this->add_key(GUI_ID_KEY_USE_BUTTON, wgettext("Special"), "keymap_special1");
|
2015-02-15 20:27:15 +01:00
|
|
|
this->add_key(GUI_ID_KEY_JUMP_BUTTON, wgettext("Jump"), "keymap_jump");
|
|
|
|
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");
|
2014-07-03 07:46:19 +02:00
|
|
|
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");
|
2017-07-25 18:56:45 +02:00
|
|
|
this->add_key(GUI_ID_KEY_ZOOM_BUTTON, wgettext("Zoom"), "keymap_zoom");
|
|
|
|
this->add_key(GUI_ID_KEY_CAMERA_BUTTON, wgettext("Change camera"), "keymap_camera_mode");
|
|
|
|
this->add_key(GUI_ID_KEY_CINEMATIC_BUTTON, wgettext("Toggle Cinematic"), "keymap_cinematic");
|
|
|
|
this->add_key(GUI_ID_KEY_MINIMAP_BUTTON, wgettext("Toggle minimap"), "keymap_minimap");
|
|
|
|
this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove");
|
|
|
|
this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove");
|
|
|
|
this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip");
|
2014-07-03 07:46:19 +02:00
|
|
|
this->add_key(GUI_ID_KEY_MUTE_BUTTON, wgettext("Mute"), "keymap_mute");
|
|
|
|
this->add_key(GUI_ID_KEY_DEC_VOLUME_BUTTON,wgettext("Dec. volume"), "keymap_decrease_volume");
|
|
|
|
this->add_key(GUI_ID_KEY_INC_VOLUME_BUTTON,wgettext("Inc. volume"), "keymap_increase_volume");
|
2017-07-25 18:56:45 +02:00
|
|
|
this->add_key(GUI_ID_KEY_AUTOFWD_BUTTON, wgettext("Autoforward"), "keymap_autoforward");
|
2015-02-15 20:27:15 +01:00
|
|
|
this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat");
|
2017-07-25 18:56:45 +02:00
|
|
|
this->add_key(GUI_ID_KEY_SCREENSHOT_BUTTON,wgettext("Screenshot"), "keymap_screenshot");
|
|
|
|
this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect");
|
|
|
|
this->add_key(GUI_ID_KEY_DEC_RANGE_BUTTON, wgettext("Dec. range"), "keymap_decrease_viewing_range_min");
|
|
|
|
this->add_key(GUI_ID_KEY_INC_RANGE_BUTTON, wgettext("Inc. range"), "keymap_increase_viewing_range_min");
|
|
|
|
this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console");
|
2015-02-15 20:27:15 +01:00
|
|
|
this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd");
|
2017-03-25 00:43:36 +01:00
|
|
|
this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local");
|
2017-07-25 18:56:45 +02:00
|
|
|
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");
|
2018-02-09 09:39:34 +01:00
|
|
|
this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog");
|
2012-07-26 09:49:00 +02:00
|
|
|
}
|
2015-02-01 23:59:23 +01:00
|
|
|
|