diff options
author | Wuzzy <almikes@aol.com> | 2016-12-18 23:34:52 +0100 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2017-07-30 18:24:45 +0100 |
commit | 640ba7727629392211ed3c2bd116e938883a6f90 (patch) | |
tree | cc50d7cbce56771fa5f2a88bc48616d8014b0232 /src | |
parent | d504831ee2adf59421e82202e350f82701bd3cd0 (diff) | |
download | minetest-640ba7727629392211ed3c2bd116e938883a6f90.tar.gz minetest-640ba7727629392211ed3c2bd116e938883a6f90.tar.bz2 minetest-640ba7727629392211ed3c2bd116e938883a6f90.zip |
Make direct item selection keys freely bindable
Diffstat (limited to 'src')
-rw-r--r-- | src/client/keys.h | 25 | ||||
-rw-r--r-- | src/defaultsettings.cpp | 33 | ||||
-rw-r--r-- | src/game.cpp | 20 | ||||
-rw-r--r-- | src/keycode.cpp | 4 | ||||
-rw-r--r-- | src/keycode.h | 1 |
5 files changed, 66 insertions, 17 deletions
diff --git a/src/client/keys.h b/src/client/keys.h index 886ae8791..d10c96240 100644 --- a/src/client/keys.h +++ b/src/client/keys.h @@ -76,6 +76,31 @@ public: DEBUG_STACKS, + // hotbar + SLOT_1, + SLOT_2, + SLOT_3, + SLOT_4, + SLOT_5, + SLOT_6, + SLOT_7, + SLOT_8, + SLOT_9, + SLOT_10, + SLOT_11, + SLOT_12, + SLOT_13, + SLOT_14, + SLOT_15, + SLOT_16, + SLOT_17, + SLOT_18, + SLOT_19, + SLOT_20, + SLOT_21, + SLOT_22, + SLOT_23, + // joystick specific keys MOUSE_L, MOUSE_R, diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 9785b5f5b..797beb3d7 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -101,6 +101,39 @@ void set_default_settings(Settings *settings) settings->setDefault("keymap_screenshot", "KEY_F12"); settings->setDefault("keymap_increase_viewing_range_min", "+"); settings->setDefault("keymap_decrease_viewing_range_min", "-"); + settings->setDefault("keymap_slot1", "KEY_KEY_1"); + settings->setDefault("keymap_slot2", "KEY_KEY_2"); + settings->setDefault("keymap_slot3", "KEY_KEY_3"); + settings->setDefault("keymap_slot4", "KEY_KEY_4"); + settings->setDefault("keymap_slot5", "KEY_KEY_5"); + settings->setDefault("keymap_slot6", "KEY_KEY_6"); + settings->setDefault("keymap_slot7", "KEY_KEY_7"); + settings->setDefault("keymap_slot8", "KEY_KEY_8"); + settings->setDefault("keymap_slot9", "KEY_KEY_9"); + settings->setDefault("keymap_slot10", "KEY_KEY_0"); + settings->setDefault("keymap_slot11", ""); + settings->setDefault("keymap_slot12", ""); + settings->setDefault("keymap_slot13", ""); + settings->setDefault("keymap_slot14", ""); + settings->setDefault("keymap_slot15", ""); + settings->setDefault("keymap_slot16", ""); + settings->setDefault("keymap_slot17", ""); + settings->setDefault("keymap_slot18", ""); + settings->setDefault("keymap_slot19", ""); + settings->setDefault("keymap_slot20", ""); + settings->setDefault("keymap_slot21", ""); + settings->setDefault("keymap_slot22", ""); + settings->setDefault("keymap_slot23", ""); + settings->setDefault("enable_build_where_you_stand", "false" ); + settings->setDefault("3d_mode", "none"); + settings->setDefault("3d_paralax_strength", "0.025"); + settings->setDefault("aux1_descends", "false"); + settings->setDefault("doubletap_jump", "false"); + settings->setDefault("always_fly_fast", "true"); + settings->setDefault("directional_colored_fog", "true"); + settings->setDefault("tooltip_show_delay", "400"); + settings->setDefault("zoom_fov", "15"); + // Some (temporary) keys for debugging settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P"); settings->setDefault("keymap_quicktune_prev", "KEY_HOME"); diff --git a/src/game.cpp b/src/game.cpp index ba4840203..0088bc95d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1107,6 +1107,11 @@ void KeyCache::populate() key[KeyType::DEBUG_STACKS] = getKeySetting("keymap_print_debug_stacks"); + for (int i = 0; i < 23; i++) { + std::string slot_key_name = "keymap_slot" + std::to_string(i + 1); + key[KeyType::SLOT_1 + i] = getKeySetting(slot_key_name.c_str()); + } + if (handler) { // First clear all keys, then re-add the ones we listen for handler->dontListenForKeys(); @@ -1115,9 +1120,6 @@ void KeyCache::populate() } handler->listenForKey(EscapeKey); handler->listenForKey(CancelKey); - for (size_t i = 0; i < 10; i++) { - handler->listenForKey(NumberKey[i]); - } } } @@ -2639,16 +2641,10 @@ void Game::processItemSelection(u16 *new_playeritem) *new_playeritem = *new_playeritem > 0 ? *new_playeritem - 1 : max_item; // else dir == 0 - /* Item selection using keyboard + /* Item selection using hotbar slot keys */ - for (u16 i = 0; i < 10; i++) { - static const KeyPress *item_keys[10] = { - NumberKey + 1, NumberKey + 2, NumberKey + 3, NumberKey + 4, - NumberKey + 5, NumberKey + 6, NumberKey + 7, NumberKey + 8, - NumberKey + 9, NumberKey + 0, - }; - - if (input->wasKeyDown(*item_keys[i])) { + for (u16 i = 0; i < 23; i++) { + if (wasKeyDown((GameKeyType) (KeyType::SLOT_1 + i))) { if (i < PLAYER_INVENTORY_SIZE && i < player->hud_hotbar_itemcount) { *new_playeritem = i; infostream << "Selected item: " << new_playeritem << std::endl; diff --git a/src/keycode.cpp b/src/keycode.cpp index 344ac7c83..3551c385a 100644 --- a/src/keycode.cpp +++ b/src/keycode.cpp @@ -351,10 +351,6 @@ const char *KeyPress::name() const const KeyPress EscapeKey("KEY_ESCAPE"); const KeyPress CancelKey("KEY_CANCEL"); -const KeyPress NumberKey[] = { - KeyPress("0"), KeyPress("1"), KeyPress("2"), KeyPress("3"), KeyPress("4"), - KeyPress("5"), KeyPress("6"), KeyPress("7"), KeyPress("8"), KeyPress("9") -}; /* Key config diff --git a/src/keycode.h b/src/keycode.h index f0012d5eb..b413d0396 100644 --- a/src/keycode.h +++ b/src/keycode.h @@ -57,7 +57,6 @@ protected: extern const KeyPress EscapeKey; extern const KeyPress CancelKey; -extern const KeyPress NumberKey[10]; // Key configuration getter KeyPress getKeySetting(const char *settingname); |