Skip to content
Permalink
Browse files

Make direct item selection keys freely bindable

  • Loading branch information...
Wuzzy authored and paramat committed Dec 18, 2016
1 parent d504831 commit 640ba7727629392211ed3c2bd116e938883a6f90
Showing with 158 additions and 17 deletions.
  1. +92 −0 builtin/settingtypes.txt
  2. +25 −0 src/client/keys.h
  3. +33 −0 src/defaultsettings.cpp
  4. +8 −12 src/game.cpp
  5. +0 −4 src/keycode.cpp
  6. +0 −1 src/keycode.h
@@ -233,6 +233,98 @@ keymap_drop (Drop item key) key KEY_KEY_Q
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_zoom (View zoom key) key KEY_KEY_Z

# Key for selecting the first hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot1 (Hotbar slot 1 key) key KEY_KEY_1

# Key for selecting the second hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot2 (Hotbar slot 2 key) key KEY_KEY_2

# Key for selecting the third hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot3 (Hotbar slot 3 key) key KEY_KEY_3

# Key for selecting the fourth hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot4 (Hotbar slot 4 key) key KEY_KEY_4

# Key for selecting the fifth hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot5 (Hotbar slot 5 key) key KEY_KEY_5

# Key for selecting the sixth hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot6 (Hotbar slot 6 key) key KEY_KEY_6

# Key for selecting the seventh hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot7 (Hotbar slot 7 key) key KEY_KEY_7

# Key for selecting the eighth hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot8 (Hotbar slot 8 key) key KEY_KEY_8

# Key for selecting the ninth hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot9 (Hotbar slot 9 key) key KEY_KEY_9

# Key for selecting the tenth hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot10 (Hotbar slot 10 key) key KEY_KEY_0

# Key for selecting the 11th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot11 (Hotbar slot 11 key) key

# Key for selecting the 12th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot12 (Hotbar slot 12 key) key

# Key for selecting the 13th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot13 (Hotbar slot 13 key) key

# Key for selecting the 14th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot14 (Hotbar slot 14 key) key

# Key for selecting the 15th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot15 (Hotbar slot 15 key) key

# Key for selecting the 16th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot16 (Hotbar slot 16 key) key

# Key for selecting the 17th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot17 (Hotbar slot 17 key) key

# Key for selecting the 18th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot18 (Hotbar slot 18 key) key

# Key for selecting the 19th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot19 (Hotbar slot 19 key) key

# Key for selecting the 20th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot20 (Hotbar slot 20 key) key

# Key for selecting the 21th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot21 (Hotbar slot 21 key) key

# Key for selecting the 22th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot22 (Hotbar slot 22 key) key

# Key for selecting the 23th hotbar slot.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_slot23 (Hotbar slot 23 key) key

# Key for toggling the display of the HUD.
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_toggle_hud (HUD toggle key) key KEY_F1
@@ -76,6 +76,31 @@ class KeyType

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,
@@ -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");
@@ -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;
@@ -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
@@ -57,7 +57,6 @@ class KeyPress

extern const KeyPress EscapeKey;
extern const KeyPress CancelKey;
extern const KeyPress NumberKey[10];

// Key configuration getter
KeyPress getKeySetting(const char *settingname);

0 comments on commit 640ba77

Please sign in to comment.
You can’t perform that action at this time.