Skip to content
Permalink
Browse files

Joystick: Remap joystick-specific KeyTypes to generic ones

According to the following table:
	* MOUSE_L     -> DIG
	* MOUSE_R     -> PLACE
	* SCROLL_UP   -> HOTBAR_NEXT
	* SCROLL_DOWN -> HOTBAR_PREV

This commit entirely removes the special KeyTypes used for joysticks.

Support for the MOUSE KeyTypes had already been removed in the main
game code without adapting the joystick code, breaking joystick
input. This commit restores joystick functionality.
  • Loading branch information
m42uko authored and sfan5 committed Nov 9, 2020
1 parent 7589cbe commit e1142ee57f2d7b59a86f6d0d72ae043844bc3121
Showing with 17 additions and 27 deletions.
  1. +6 −10 src/client/game.cpp
  2. +11 −11 src/client/joystick_controller.cpp
  3. +0 −6 src/client/keys.h
@@ -2014,15 +2014,11 @@ void Game::processItemSelection(u16 *new_playeritem)

s32 dir = wheel;

if (input->joystick.wasKeyDown(KeyType::SCROLL_DOWN) ||
wasKeyDown(KeyType::HOTBAR_NEXT)) {
if (wasKeyDown(KeyType::HOTBAR_NEXT))
dir = -1;
}

if (input->joystick.wasKeyDown(KeyType::SCROLL_UP) ||
wasKeyDown(KeyType::HOTBAR_PREV)) {
if (wasKeyDown(KeyType::HOTBAR_PREV))
dir = 1;
}

if (dir < 0)
*new_playeritem = *new_playeritem < max_item ? *new_playeritem + 1 : 0;
@@ -3138,11 +3134,11 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
input->clearWasKeyPressed();
input->clearWasKeyReleased();

input->joystick.clearWasKeyDown(KeyType::MOUSE_L);
input->joystick.clearWasKeyDown(KeyType::MOUSE_R);
input->joystick.clearWasKeyDown(KeyType::DIG);
input->joystick.clearWasKeyDown(KeyType::PLACE);

input->joystick.clearWasKeyReleased(KeyType::MOUSE_L);
input->joystick.clearWasKeyReleased(KeyType::MOUSE_R);
input->joystick.clearWasKeyReleased(KeyType::DIG);
input->joystick.clearWasKeyReleased(KeyType::PLACE);
}


@@ -74,18 +74,18 @@ JoystickLayout create_default_layout()

// Accessible without four modifier button pressed
// regardless whether start is pressed or not
JLO_B_PB(KeyType::MOUSE_L, fb | 1 << 4, 1 << 4);
JLO_B_PB(KeyType::MOUSE_R, fb | 1 << 5, 1 << 5);
JLO_B_PB(KeyType::DIG, fb | 1 << 4, 1 << 4);
JLO_B_PB(KeyType::PLACE, fb | 1 << 5, 1 << 5);

// Accessible without any modifier pressed
JLO_B_PB(KeyType::JUMP, bm | 1 << 0, 1 << 0);
JLO_B_PB(KeyType::SPECIAL1, bm | 1 << 1, 1 << 1);

// Accessible with start button not pressed, but four pressed
// TODO find usage for button 0
JLO_B_PB(KeyType::DROP, bm | 1 << 1, fb | 1 << 1);
JLO_B_PB(KeyType::SCROLL_UP, bm | 1 << 4, fb | 1 << 4);
JLO_B_PB(KeyType::SCROLL_DOWN,bm | 1 << 5, fb | 1 << 5);
JLO_B_PB(KeyType::DROP, bm | 1 << 1, fb | 1 << 1);
JLO_B_PB(KeyType::HOTBAR_PREV, bm | 1 << 4, fb | 1 << 4);
JLO_B_PB(KeyType::HOTBAR_NEXT, bm | 1 << 5, fb | 1 << 5);

// Accessible with start button and four pressed
// TODO find usage for buttons 0, 1 and 4, 5
@@ -99,8 +99,8 @@ JoystickLayout create_default_layout()
JLO_A_PB(KeyType::RIGHT, 0, -1, 1024);

// Scroll buttons
JLO_A_PB(KeyType::SCROLL_UP, 2, -1, 1024);
JLO_A_PB(KeyType::SCROLL_DOWN, 5, -1, 1024);
JLO_A_PB(KeyType::HOTBAR_PREV, 2, -1, 1024);
JLO_A_PB(KeyType::HOTBAR_NEXT, 5, -1, 1024);

return jlo;
}
@@ -134,10 +134,10 @@ JoystickLayout create_xbox_layout()
JLO_B_PB(KeyType::SNEAK, 1 << 12, 1 << 12); // right

// Triggers
JLO_B_PB(KeyType::MOUSE_L, 1 << 6, 1 << 6); // lt
JLO_B_PB(KeyType::MOUSE_R, 1 << 7, 1 << 7); // rt
JLO_B_PB(KeyType::SCROLL_UP, 1 << 4, 1 << 4); // lb
JLO_B_PB(KeyType::SCROLL_DOWN, 1 << 5, 1 << 5); // rb
JLO_B_PB(KeyType::DIG, 1 << 6, 1 << 6); // lt
JLO_B_PB(KeyType::PLACE, 1 << 7, 1 << 7); // rt
JLO_B_PB(KeyType::HOTBAR_PREV, 1 << 4, 1 << 4); // lb
JLO_B_PB(KeyType::HOTBAR_NEXT, 1 << 5, 1 << 5); // rb

// D-PAD
JLO_B_PB(KeyType::ZOOM, 1 << 15, 1 << 15); // up
@@ -110,12 +110,6 @@ class KeyType
SLOT_31,
SLOT_32,

// joystick specific keys
MOUSE_L,
MOUSE_R,
SCROLL_UP,
SCROLL_DOWN,

// Fake keycode for array size and internal checks
INTERNAL_ENUM_COUNT

0 comments on commit e1142ee

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