Skip to content

Commit

Permalink
Mapping ZR to return
Browse files Browse the repository at this point in the history
  • Loading branch information
capsterx committed Nov 7, 2020
1 parent b288d91 commit 2aa73fc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/core/InputEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ enum class Switch_Joy
KEY_SL_LEFT, KEY_SR_LEFT, KEY_SL_RIGHT, KEY_SR_RIGHT
};

bool is_switch_keyboad_from_joy(SDL_Event const & event)
bool is_switch_keyboard_from_joy(SDL_Event const & event)
{
auto ret =
event.jbutton.which == 0 &&
Expand All @@ -215,14 +215,17 @@ bool is_switch_keyboad_from_joy(SDL_Event const & event)
event.jbutton.button == (int)Switch_Joy::KEY_RSTICK_RIGHT ||
event.jbutton.button == (int)Switch_Joy::KEY_RSTICK_UP ||
event.jbutton.button == (int)Switch_Joy::KEY_RSTICK_DOWN ||
event.jbutton.button == (int)Switch_Joy::KEY_MINUS
event.jbutton.button == (int)Switch_Joy::KEY_MINUS ||
event.jbutton.button == (int)Switch_Joy::KEY_ZR
);
return ret;
}

bool is_switch_keyboard_from_joy_direction(SDL_Event const & event)
{
return is_switch_keyboad_from_joy(event) && event.jbutton.button != (int)Switch_Joy::KEY_MINUS;
return is_switch_keyboard_from_joy(event)
&& event.jbutton.button != (int)Switch_Joy::KEY_MINUS
&& event.jbutton.button != (int)Switch_Joy::KEY_ZR;
}
#endif

Expand Down Expand Up @@ -681,7 +684,7 @@ bool InputEvent::is_keyboard_event() const {
return (internal_event.type == SDL_KEYDOWN || internal_event.type == SDL_KEYUP)
&& (!internal_event.key.repeat || repeat_keyboard);
#else
return (internal_event.type == SDL_JOYBUTTONDOWN || internal_event.type == SDL_JOYBUTTONUP) && is_switch_keyboad_from_joy(internal_event);
return (internal_event.type == SDL_JOYBUTTONDOWN || internal_event.type == SDL_JOYBUTTONUP) && is_switch_keyboard_from_joy(internal_event);
#endif
}

Expand Down Expand Up @@ -741,7 +744,7 @@ bool InputEvent::is_keyboard_key_pressed() const {
auto ret = internal_event.type == SDL_KEYDOWN
&& (!internal_event.key.repeat || repeat_keyboard);
#else
auto ret = (internal_event.type == SDL_JOYBUTTONDOWN && is_switch_keyboad_from_joy(internal_event));
auto ret = (internal_event.type == SDL_JOYBUTTONDOWN && is_switch_keyboard_from_joy(internal_event));
#endif
//printf("is_keyboard_key_pressed: %d\n", ret);
return ret;
Expand Down Expand Up @@ -819,7 +822,7 @@ bool InputEvent::is_keyboard_key_released() const {
return internal_event.type == SDL_KEYUP
&& (!internal_event.key.repeat || repeat_keyboard);
#else
return ((internal_event.type == SDL_JOYBUTTONUP) && is_switch_keyboad_from_joy(internal_event));
return ((internal_event.type == SDL_JOYBUTTONUP) && is_switch_keyboard_from_joy(internal_event));
#endif
}

Expand Down Expand Up @@ -967,6 +970,9 @@ InputEvent::KeyboardKey InputEvent::get_keyboard_key() const {
case (int)Switch_Joy::KEY_LSTICK_DOWN:
case (int)Switch_Joy::KEY_DDOWN:
return KeyboardKey::DOWN;

case (int)Switch_Joy::KEY_ZR:
return KeyboardKey::RETURN;

case (int)Switch_Joy::KEY_MINUS:
return KeyboardKey::ESCAPE;
Expand Down Expand Up @@ -1095,7 +1101,7 @@ void InputEvent::set_joypad_enabled(bool joypad_enabled) {
bool InputEvent::is_joypad_button_pressed() const {
auto ret = internal_event.type == SDL_JOYBUTTONDOWN;
#ifdef __SWITCH__
ret &= !is_switch_keyboad_from_joy(internal_event);
ret &= !is_switch_keyboard_from_joy(internal_event);
#endif
//printf("is_joypad_button_pressed=%d\n", ret);
return ret;
Expand Down

0 comments on commit 2aa73fc

Please sign in to comment.