Skip to content

Commit 640ba77

Browse files
Wuzzyparamat
Wuzzy
authored andcommittedJul 30, 2017
Make direct item selection keys freely bindable
1 parent d504831 commit 640ba77

File tree

6 files changed

+158
-17
lines changed

6 files changed

+158
-17
lines changed
 

Diff for: ‎builtin/settingtypes.txt

+92
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,98 @@ keymap_drop (Drop item key) key KEY_KEY_Q
233233
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
234234
keymap_zoom (View zoom key) key KEY_KEY_Z
235235

236+
# Key for selecting the first hotbar slot.
237+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
238+
keymap_slot1 (Hotbar slot 1 key) key KEY_KEY_1
239+
240+
# Key for selecting the second hotbar slot.
241+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
242+
keymap_slot2 (Hotbar slot 2 key) key KEY_KEY_2
243+
244+
# Key for selecting the third hotbar slot.
245+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
246+
keymap_slot3 (Hotbar slot 3 key) key KEY_KEY_3
247+
248+
# Key for selecting the fourth hotbar slot.
249+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
250+
keymap_slot4 (Hotbar slot 4 key) key KEY_KEY_4
251+
252+
# Key for selecting the fifth hotbar slot.
253+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
254+
keymap_slot5 (Hotbar slot 5 key) key KEY_KEY_5
255+
256+
# Key for selecting the sixth hotbar slot.
257+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
258+
keymap_slot6 (Hotbar slot 6 key) key KEY_KEY_6
259+
260+
# Key for selecting the seventh hotbar slot.
261+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
262+
keymap_slot7 (Hotbar slot 7 key) key KEY_KEY_7
263+
264+
# Key for selecting the eighth hotbar slot.
265+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
266+
keymap_slot8 (Hotbar slot 8 key) key KEY_KEY_8
267+
268+
# Key for selecting the ninth hotbar slot.
269+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
270+
keymap_slot9 (Hotbar slot 9 key) key KEY_KEY_9
271+
272+
# Key for selecting the tenth hotbar slot.
273+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
274+
keymap_slot10 (Hotbar slot 10 key) key KEY_KEY_0
275+
276+
# Key for selecting the 11th hotbar slot.
277+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
278+
keymap_slot11 (Hotbar slot 11 key) key
279+
280+
# Key for selecting the 12th hotbar slot.
281+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
282+
keymap_slot12 (Hotbar slot 12 key) key
283+
284+
# Key for selecting the 13th hotbar slot.
285+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
286+
keymap_slot13 (Hotbar slot 13 key) key
287+
288+
# Key for selecting the 14th hotbar slot.
289+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
290+
keymap_slot14 (Hotbar slot 14 key) key
291+
292+
# Key for selecting the 15th hotbar slot.
293+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
294+
keymap_slot15 (Hotbar slot 15 key) key
295+
296+
# Key for selecting the 16th hotbar slot.
297+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
298+
keymap_slot16 (Hotbar slot 16 key) key
299+
300+
# Key for selecting the 17th hotbar slot.
301+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
302+
keymap_slot17 (Hotbar slot 17 key) key
303+
304+
# Key for selecting the 18th hotbar slot.
305+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
306+
keymap_slot18 (Hotbar slot 18 key) key
307+
308+
# Key for selecting the 19th hotbar slot.
309+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
310+
keymap_slot19 (Hotbar slot 19 key) key
311+
312+
# Key for selecting the 20th hotbar slot.
313+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
314+
keymap_slot20 (Hotbar slot 20 key) key
315+
316+
# Key for selecting the 21th hotbar slot.
317+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
318+
keymap_slot21 (Hotbar slot 21 key) key
319+
320+
# Key for selecting the 22th hotbar slot.
321+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
322+
keymap_slot22 (Hotbar slot 22 key) key
323+
324+
# Key for selecting the 23th hotbar slot.
325+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
326+
keymap_slot23 (Hotbar slot 23 key) key
327+
236328
# Key for toggling the display of the HUD.
237329
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
238330
keymap_toggle_hud (HUD toggle key) key KEY_F1

Diff for: ‎src/client/keys.h

+25
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@ class KeyType
7676

7777
DEBUG_STACKS,
7878

79+
// hotbar
80+
SLOT_1,
81+
SLOT_2,
82+
SLOT_3,
83+
SLOT_4,
84+
SLOT_5,
85+
SLOT_6,
86+
SLOT_7,
87+
SLOT_8,
88+
SLOT_9,
89+
SLOT_10,
90+
SLOT_11,
91+
SLOT_12,
92+
SLOT_13,
93+
SLOT_14,
94+
SLOT_15,
95+
SLOT_16,
96+
SLOT_17,
97+
SLOT_18,
98+
SLOT_19,
99+
SLOT_20,
100+
SLOT_21,
101+
SLOT_22,
102+
SLOT_23,
103+
79104
// joystick specific keys
80105
MOUSE_L,
81106
MOUSE_R,

Diff for: ‎src/defaultsettings.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ void set_default_settings(Settings *settings)
101101
settings->setDefault("keymap_screenshot", "KEY_F12");
102102
settings->setDefault("keymap_increase_viewing_range_min", "+");
103103
settings->setDefault("keymap_decrease_viewing_range_min", "-");
104+
settings->setDefault("keymap_slot1", "KEY_KEY_1");
105+
settings->setDefault("keymap_slot2", "KEY_KEY_2");
106+
settings->setDefault("keymap_slot3", "KEY_KEY_3");
107+
settings->setDefault("keymap_slot4", "KEY_KEY_4");
108+
settings->setDefault("keymap_slot5", "KEY_KEY_5");
109+
settings->setDefault("keymap_slot6", "KEY_KEY_6");
110+
settings->setDefault("keymap_slot7", "KEY_KEY_7");
111+
settings->setDefault("keymap_slot8", "KEY_KEY_8");
112+
settings->setDefault("keymap_slot9", "KEY_KEY_9");
113+
settings->setDefault("keymap_slot10", "KEY_KEY_0");
114+
settings->setDefault("keymap_slot11", "");
115+
settings->setDefault("keymap_slot12", "");
116+
settings->setDefault("keymap_slot13", "");
117+
settings->setDefault("keymap_slot14", "");
118+
settings->setDefault("keymap_slot15", "");
119+
settings->setDefault("keymap_slot16", "");
120+
settings->setDefault("keymap_slot17", "");
121+
settings->setDefault("keymap_slot18", "");
122+
settings->setDefault("keymap_slot19", "");
123+
settings->setDefault("keymap_slot20", "");
124+
settings->setDefault("keymap_slot21", "");
125+
settings->setDefault("keymap_slot22", "");
126+
settings->setDefault("keymap_slot23", "");
127+
settings->setDefault("enable_build_where_you_stand", "false" );
128+
settings->setDefault("3d_mode", "none");
129+
settings->setDefault("3d_paralax_strength", "0.025");
130+
settings->setDefault("aux1_descends", "false");
131+
settings->setDefault("doubletap_jump", "false");
132+
settings->setDefault("always_fly_fast", "true");
133+
settings->setDefault("directional_colored_fog", "true");
134+
settings->setDefault("tooltip_show_delay", "400");
135+
settings->setDefault("zoom_fov", "15");
136+
104137
// Some (temporary) keys for debugging
105138
settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
106139
settings->setDefault("keymap_quicktune_prev", "KEY_HOME");

Diff for: ‎src/game.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,11 @@ void KeyCache::populate()
11071107

11081108
key[KeyType::DEBUG_STACKS] = getKeySetting("keymap_print_debug_stacks");
11091109

1110+
for (int i = 0; i < 23; i++) {
1111+
std::string slot_key_name = "keymap_slot" + std::to_string(i + 1);
1112+
key[KeyType::SLOT_1 + i] = getKeySetting(slot_key_name.c_str());
1113+
}
1114+
11101115
if (handler) {
11111116
// First clear all keys, then re-add the ones we listen for
11121117
handler->dontListenForKeys();
@@ -1115,9 +1120,6 @@ void KeyCache::populate()
11151120
}
11161121
handler->listenForKey(EscapeKey);
11171122
handler->listenForKey(CancelKey);
1118-
for (size_t i = 0; i < 10; i++) {
1119-
handler->listenForKey(NumberKey[i]);
1120-
}
11211123
}
11221124
}
11231125

@@ -2639,16 +2641,10 @@ void Game::processItemSelection(u16 *new_playeritem)
26392641
*new_playeritem = *new_playeritem > 0 ? *new_playeritem - 1 : max_item;
26402642
// else dir == 0
26412643

2642-
/* Item selection using keyboard
2644+
/* Item selection using hotbar slot keys
26432645
*/
2644-
for (u16 i = 0; i < 10; i++) {
2645-
static const KeyPress *item_keys[10] = {
2646-
NumberKey + 1, NumberKey + 2, NumberKey + 3, NumberKey + 4,
2647-
NumberKey + 5, NumberKey + 6, NumberKey + 7, NumberKey + 8,
2648-
NumberKey + 9, NumberKey + 0,
2649-
};
2650-
2651-
if (input->wasKeyDown(*item_keys[i])) {
2646+
for (u16 i = 0; i < 23; i++) {
2647+
if (wasKeyDown((GameKeyType) (KeyType::SLOT_1 + i))) {
26522648
if (i < PLAYER_INVENTORY_SIZE && i < player->hud_hotbar_itemcount) {
26532649
*new_playeritem = i;
26542650
infostream << "Selected item: " << new_playeritem << std::endl;

Diff for: ‎src/keycode.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,6 @@ const char *KeyPress::name() const
351351

352352
const KeyPress EscapeKey("KEY_ESCAPE");
353353
const KeyPress CancelKey("KEY_CANCEL");
354-
const KeyPress NumberKey[] = {
355-
KeyPress("0"), KeyPress("1"), KeyPress("2"), KeyPress("3"), KeyPress("4"),
356-
KeyPress("5"), KeyPress("6"), KeyPress("7"), KeyPress("8"), KeyPress("9")
357-
};
358354

359355
/*
360356
Key config

Diff for: ‎src/keycode.h

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class KeyPress
5757

5858
extern const KeyPress EscapeKey;
5959
extern const KeyPress CancelKey;
60-
extern const KeyPress NumberKey[10];
6160

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

0 commit comments

Comments
 (0)
Please sign in to comment.