aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-05-14 15:43:26 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-05-14 15:43:26 +0300
commit974c5cc08cc4d9e77de44b3667d5945a5cb3c496 (patch)
treebb8db1b1f4e078454f509c18a99be74958da71be
parent0674db4a6b687a73637844fa354d2ac662e42820 (diff)
downloadminetest-974c5cc08cc4d9e77de44b3667d5945a5cb3c496.tar.gz
minetest-974c5cc08cc4d9e77de44b3667d5945a5cb3c496.tar.bz2
minetest-974c5cc08cc4d9e77de44b3667d5945a5cb3c496.zip
Added key configuration in the configuration file.
-rw-r--r--minetest.conf.example13
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/defaultsettings.cpp19
-rw-r--r--src/game.cpp31
-rw-r--r--src/guiInventoryMenu.cpp3
-rw-r--r--src/keycode.cpp192
-rw-r--r--src/keycode.h27
-rw-r--r--src/main.cpp19
8 files changed, 280 insertions, 25 deletions
diff --git a/minetest.conf.example b/minetest.conf.example
index 48f326229..6f5e7a9f7 100644
--- a/minetest.conf.example
+++ b/minetest.conf.example
@@ -11,6 +11,19 @@
# Client side stuff
#
+#keymap_forward = KEY_KEY_W
+#keymap_backward = KEY_KEY_S
+#keymap_left = KEY_KEY_A
+#keymap_right = KEY_KEY_D
+#keymap_jump = KEY_SPACE
+#keymap_sneak = KEY_RSHIFT
+#keymap_inventory = KEY_KEY_I
+#keymap_chat = KEY_KEY_T
+#keymap_rangeselect = KEY_KEY_R
+# Some (temporary) keys for debugging
+#keymap_special1 = KEY_KEY_E
+#keymap_print_debug_stacks = KEY_KEY_P
+
#wanted_fps = 30
#fps_max = 60
#viewing_range_nodes_max = 300
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ef42d002e..8e6f54303 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -81,6 +81,7 @@ set(common_SRCS
# Client sources
set(minetest_SRCS
${common_SRCS}
+ keycode.cpp
clouds.cpp
clientobject.cpp
guiFurnaceMenu.cpp
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 1ba8c1194..eb3b3c92e 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -24,18 +24,33 @@ extern Settings g_settings;
void set_default_settings()
{
// Client and server
+
+ g_settings.setDefault("port", "");
+ g_settings.setDefault("name", "");
g_settings.setDefault("footprints", "false");
// Client stuff
+
+ g_settings.setDefault("keymap_forward", "KEY_KEY_W");
+ g_settings.setDefault("keymap_backward", "KEY_KEY_S");
+ g_settings.setDefault("keymap_left", "KEY_KEY_A");
+ g_settings.setDefault("keymap_right", "KEY_KEY_D");
+ g_settings.setDefault("keymap_jump", "KEY_SPACE");
+ g_settings.setDefault("keymap_sneak", "KEY_RSHIFT");
+ g_settings.setDefault("keymap_inventory", "KEY_KEY_I");
+ g_settings.setDefault("keymap_chat", "KEY_KEY_T");
+ g_settings.setDefault("keymap_rangeselect", "KEY_KEY_R");
+ // Some (temporary) keys for debugging
+ g_settings.setDefault("keymap_special1", "KEY_KEY_E");
+ g_settings.setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
+
g_settings.setDefault("wanted_fps", "30");
g_settings.setDefault("fps_max", "60");
g_settings.setDefault("viewing_range_nodes_max", "300");
g_settings.setDefault("viewing_range_nodes_min", "35");
g_settings.setDefault("screenW", "800");
g_settings.setDefault("screenH", "600");
- g_settings.setDefault("port", "");
g_settings.setDefault("address", "");
- g_settings.setDefault("name", "");
g_settings.setDefault("random_input", "false");
g_settings.setDefault("client_delete_unused_sectors_timeout", "1200");
g_settings.setDefault("enable_fog", "true");
diff --git a/src/game.cpp b/src/game.cpp
index f32a2f0c9..43d6bd362 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "materials.h"
#include "config.h"
#include "clouds.h"
+#include "keycode.h"
/*
Setting this to 1 enables a special camera mode that forces
@@ -1079,7 +1080,7 @@ void the_game(
/*
Launch menus according to keys
*/
- if(input->wasKeyDown(irr::KEY_KEY_I))
+ if(input->wasKeyDown(getKeySetting("keymap_inventory")))
{
dstream<<DTIME<<"the_game: "
<<"Launching inventory"<<std::endl;
@@ -1105,7 +1106,7 @@ void the_game(
menu->drop();
}
- else if(input->wasKeyDown(irr::KEY_ESCAPE))
+ else if(input->wasKeyDown(KEY_ESCAPE))
{
dstream<<DTIME<<"the_game: "
<<"Launching pause menu"<<std::endl;
@@ -1113,7 +1114,7 @@ void the_game(
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
&g_menumgr))->drop();
}
- else if(input->wasKeyDown(irr::KEY_KEY_T))
+ else if(input->wasKeyDown(getKeySetting("keymap_chat")))
{
TextDest *dest = new TextDestChat(&client);
@@ -1163,7 +1164,7 @@ void the_game(
}
// Viewing range selection
- if(input->wasKeyDown(irr::KEY_KEY_R))
+ if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
{
if(draw_control.range_all)
{
@@ -1178,7 +1179,7 @@ void the_game(
}
// Print debug stacks
- if(input->wasKeyDown(irr::KEY_KEY_P))
+ if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
{
dstream<<"-----------------------------------------"
<<std::endl;
@@ -1190,6 +1191,7 @@ void the_game(
/*
Player speed control
+ TODO: Cache the keycodes from getKeySetting
*/
{
@@ -1203,14 +1205,13 @@ void the_game(
float a_pitch,
float a_yaw*/
PlayerControl control(
- input->isKeyDown(irr::KEY_KEY_W),
- input->isKeyDown(irr::KEY_KEY_S),
- input->isKeyDown(irr::KEY_KEY_A),
- input->isKeyDown(irr::KEY_KEY_D),
- input->isKeyDown(irr::KEY_SPACE),
- input->isKeyDown(irr::KEY_KEY_E),
- input->isKeyDown(irr::KEY_LSHIFT)
- || input->isKeyDown(irr::KEY_RSHIFT),
+ input->isKeyDown(getKeySetting("keymap_forward")),
+ input->isKeyDown(getKeySetting("keymap_backward")),
+ input->isKeyDown(getKeySetting("keymap_left")),
+ input->isKeyDown(getKeySetting("keymap_right")),
+ input->isKeyDown(getKeySetting("keymap_jump")),
+ input->isKeyDown(getKeySetting("keymap_special1")),
+ input->isKeyDown(getKeySetting("keymap_sneak")),
camera_pitch,
camera_yaw
);
@@ -1281,7 +1282,7 @@ void the_game(
s32 dy = input->getMousePos().Y - displaycenter.Y;
//std::cout<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
- const float keyspeed = 500;
+ /*const float keyspeed = 500;
if(input->isKeyDown(irr::KEY_UP))
dy -= dtime * keyspeed;
if(input->isKeyDown(irr::KEY_DOWN))
@@ -1289,7 +1290,7 @@ void the_game(
if(input->isKeyDown(irr::KEY_LEFT))
dx -= dtime * keyspeed;
if(input->isKeyDown(irr::KEY_RIGHT))
- dx += dtime * keyspeed;
+ dx += dtime * keyspeed;*/
camera_yaw -= dx*0.2;
camera_pitch += dy*0.2;
diff --git a/src/guiInventoryMenu.cpp b/src/guiInventoryMenu.cpp
index ec5328dcc..a4ba472f8 100644
--- a/src/guiInventoryMenu.cpp
+++ b/src/guiInventoryMenu.cpp
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiInventoryMenu.h"
#include "constants.h"
+#include "keycode.h"
void drawInventoryItem(video::IVideoDriver *driver,
gui::IGUIFont *font,
@@ -293,7 +294,7 @@ bool GUIInventoryMenu::OnEvent(const SEvent& event)
quitMenu();
return true;
}
- if(event.KeyInput.Key==KEY_KEY_I && event.KeyInput.PressedDown)
+ if(event.KeyInput.Key==getKeySetting("keymap_inventory") && event.KeyInput.PressedDown)
{
quitMenu();
return true;
diff --git a/src/keycode.cpp b/src/keycode.cpp
new file mode 100644
index 000000000..ad3c0b401
--- /dev/null
+++ b/src/keycode.cpp
@@ -0,0 +1,192 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(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
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "keycode.h"
+#include "main.h" // For g_settings
+
+#define CHECKKEY(x){if(strcmp(name, #x)==0) return irr::x;}
+
+irr::EKEY_CODE keyname_to_keycode(const char *name)
+{
+ CHECKKEY(KEY_LBUTTON)
+ CHECKKEY(KEY_RBUTTON)
+ CHECKKEY(KEY_CANCEL)
+ CHECKKEY(KEY_MBUTTON)
+ CHECKKEY(KEY_XBUTTON1)
+ CHECKKEY(KEY_XBUTTON2)
+ CHECKKEY(KEY_BACK)
+ CHECKKEY(KEY_TAB)
+ CHECKKEY(KEY_CLEAR)
+ CHECKKEY(KEY_RETURN)
+ CHECKKEY(KEY_SHIFT)
+ CHECKKEY(KEY_CONTROL)
+ CHECKKEY(KEY_MENU)
+ CHECKKEY(KEY_PAUSE)
+ CHECKKEY(KEY_CAPITAL)
+ CHECKKEY(KEY_KANA)
+ CHECKKEY(KEY_HANGUEL)
+ CHECKKEY(KEY_HANGUL)
+ CHECKKEY(KEY_JUNJA)
+ CHECKKEY(KEY_FINAL)
+ CHECKKEY(KEY_HANJA)
+ CHECKKEY(KEY_KANJI)
+ CHECKKEY(KEY_ESCAPE)
+ CHECKKEY(KEY_CONVERT)
+ CHECKKEY(KEY_NONCONVERT)
+ CHECKKEY(KEY_ACCEPT)
+ CHECKKEY(KEY_MODECHANGE)
+ CHECKKEY(KEY_SPACE)
+ CHECKKEY(KEY_PRIOR)
+ CHECKKEY(KEY_NEXT)
+ CHECKKEY(KEY_END)
+ CHECKKEY(KEY_HOME)
+ CHECKKEY(KEY_LEFT)
+ CHECKKEY(KEY_UP)
+ CHECKKEY(KEY_RIG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ERIOD)
+ CHECKKEY(KEY_ATTN)
+ CHECKKEY(KEY_CRSEL)
+ CHECKKEY(KEY_EXSEL)
+ CHECKKEY(KEY_EREOF)
+ CHECKKEY(KEY_PLAY)
+ CHECKKEY(KEY_ZOOM)
+ CHECKKEY(KEY_PA1)
+ CHECKKEY(KEY_OEM_CLEAR)
+
+ return irr::KEY_KEY_CODES_COUNT;
+}
+
+/*
+ Key config
+*/
+
+// A simple cache for quicker lookup
+core::map<std::string, irr::EKEY_CODE> g_key_setting_cache;
+
+irr::EKEY_CODE getKeySetting(const char *settingname)
+{
+ core::map<std::string, irr::EKEY_CODE>::Node *n;
+ n = g_key_setting_cache.find(settingname);
+ if(n)
+ return n->getValue();
+ irr::EKEY_CODE c = keyname_to_keycode(g_settings.get(settingname).c_str());
+ g_key_setting_cache.insert(settingname, c);
+ return c;
+}
+
+
diff --git a/src/keycode.h b/src/keycode.h
new file mode 100644
index 000000000..4201debc4
--- /dev/null
+++ b/src/keycode.h
@@ -0,0 +1,27 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(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
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "common_irrlicht.h"
+
+irr::EKEY_CODE keyname_to_keycode(const char *name);
+
+// Key configuration getter
+irr::EKEY_CODE getKeySetting(const char *settingname);
+
+
diff --git a/src/main.cpp b/src/main.cpp
index 8098a450f..e1760331b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -137,10 +137,10 @@ Networking and serialization:
TODO: Get rid of GotSplitPacketException
-GUI:
-----
+User Interface:
+---------------
-TODO: Configuration menu, at least for keys
+TODO: Use getKeySetting everywhere for ESC key and stuff
Graphics:
---------
@@ -326,6 +326,7 @@ Making it more portable:
//#include "tile.h"
#include "materials.h"
#include "game.h"
+#include "keycode.h"
// This makes textures
ITextureSource *g_texturesource = NULL;
@@ -721,7 +722,8 @@ public:
if(counter1 < 0.0)
{
counter1 = 0.1*Rand(1, 40);
- keydown[irr::KEY_SPACE] = !keydown[irr::KEY_SPACE];
+ keydown[getKeySetting("keymap_jump")] =
+ !keydown[getKeySetting("keymap_jump")];
}
}
{
@@ -730,7 +732,8 @@ public:
if(counter1 < 0.0)
{
counter1 = 0.1*Rand(1, 40);
- keydown[irr::KEY_KEY_E] = !keydown[irr::KEY_KEY_E];
+ keydown[getKeySetting("keymap_special1")] =
+ !keydown[getKeySetting("keymap_special1")];
}
}
{
@@ -739,7 +742,8 @@ public:
if(counter1 < 0.0)
{
counter1 = 0.1*Rand(1, 40);
- keydown[irr::KEY_KEY_W] = !keydown[irr::KEY_KEY_W];
+ keydown[getKeySetting("keymap_forward")] =
+ !keydown[getKeySetting("keymap_forward")];
}
}
{
@@ -748,7 +752,8 @@ public:
if(counter1 < 0.0)
{
counter1 = 0.1*Rand(1, 40);
- keydown[irr::KEY_KEY_A] = !keydown[irr::KEY_KEY_A];
+ keydown[getKeySetting("keymap_left")] =
+ !keydown[getKeySetting("keymap_left")];
}
}
{