diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 5d3af78..bfe9c80 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp @@ -171,22 +171,7 @@ bool isUpEvent(const SDL_Event& event) { return true; } } - if (event.type == SDL_CONTROLLERBUTTONDOWN) { - if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP ) { - return true; - } - } - if (event.type == SDL_CONTROLLERAXISMOTION && event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY ) { - checkDeadZone(event); - const SDL_ControllerAxisEvent& a = event.caxis; - if (getDeadZone(a.which, a.axis)) { - if (event.caxis.value < -deadZoneLimit) { - setDeadZone(a.which,a.axis,false); - return true; - } - } - } - return false; + return isControllerUpEvent(event); } bool isDownEvent(const SDL_Event& event) { @@ -195,22 +180,7 @@ bool isDownEvent(const SDL_Event& event) { return true; } } - if (event.type == SDL_CONTROLLERBUTTONDOWN) { - if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN ) { - return true; - } - } - if (event.type == SDL_CONTROLLERAXISMOTION && event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY ) { - checkDeadZone(event); - const SDL_ControllerAxisEvent& a = event.caxis; - if (getDeadZone(a.which, a.axis)) { - if (event.caxis.value > deadZoneLimit) { - setDeadZone(a.which,a.axis,false); - return true; - } - } - } - return false; + return isControllerDownEvent(event); } bool isLeftEvent(const SDL_Event& event) { @@ -219,22 +189,7 @@ bool isLeftEvent(const SDL_Event& event) { return true; } } - if (event.type == SDL_CONTROLLERBUTTONDOWN) { - if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT ) { - return true; - } - } - if (event.type == SDL_CONTROLLERAXISMOTION && event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX ) { - checkDeadZone(event); - const SDL_ControllerAxisEvent& a = event.caxis; - if (getDeadZone(a.which, a.axis)) { - if (event.caxis.value < -deadZoneLimit) { - setDeadZone(a.which,a.axis,false); - return true; - } - } - } - return false; + return isControllerLeftEvent(event); } bool isRightEvent(const SDL_Event& event) { @@ -243,22 +198,7 @@ bool isRightEvent(const SDL_Event& event) { return true; } } - if (event.type == SDL_CONTROLLERBUTTONDOWN) { - if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT ) { - return true; - } - } - if (event.type == SDL_CONTROLLERAXISMOTION && event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX ) { - checkDeadZone(event); - const SDL_ControllerAxisEvent& a = event.caxis; - if (getDeadZone(a.which, a.axis)) { - if (event.caxis.value > deadZoneLimit) { - setDeadZone(a.which,a.axis,false); - return true; - } - } - } - return false; + return isControllerRightEvent(event); } bool isEscapeEvent(const SDL_Event& event) { diff --git a/source/code/gamecontroller.cpp b/source/code/gamecontroller.cpp index 05a31a5..1bb6a86 100644 --- a/source/code/gamecontroller.cpp +++ b/source/code/gamecontroller.cpp @@ -173,10 +173,7 @@ bool isGameControllerConnectionEvent(const SDL_Event& event) { return false; } -bool isPlayerDownEvent(int playerNumber, const SDL_Event& event) { - if (skipThisPlayer(playerNumber, event)) { - return false; - } +bool isControllerDownEvent(const SDL_Event& event) { if (event.type == SDL_CONTROLLERBUTTONDOWN) { if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN ) { return true; @@ -195,10 +192,14 @@ bool isPlayerDownEvent(int playerNumber, const SDL_Event& event) { return false; } -bool isPlayerUpEvent(int playerNumber, const SDL_Event& event) { +bool isPlayerDownEvent(int playerNumber, const SDL_Event& event) { if (skipThisPlayer(playerNumber, event)) { return false; } + return isControllerDownEvent(event); +} + +bool isControllerUpEvent(const SDL_Event& event) { if (event.type == SDL_CONTROLLERBUTTONDOWN) { if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP ) { return true; @@ -217,10 +218,14 @@ bool isPlayerUpEvent(int playerNumber, const SDL_Event& event) { return false; } -bool isPlayerLeftEvent(int playerNumber, const SDL_Event& event) { +bool isPlayerUpEvent(int playerNumber, const SDL_Event& event) { if (skipThisPlayer(playerNumber, event)) { return false; } + return isControllerUpEvent(event); +} + +bool isControllerLeftEvent(const SDL_Event& event) { if (event.type == SDL_CONTROLLERBUTTONDOWN) { if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT ) { return true; @@ -239,10 +244,14 @@ bool isPlayerLeftEvent(int playerNumber, const SDL_Event& event) { return false; } -bool isPlayerRightEvent(int playerNumber, const SDL_Event& event) { +bool isPlayerLeftEvent(int playerNumber, const SDL_Event& event) { if (skipThisPlayer(playerNumber, event)) { return false; } + return isControllerLeftEvent(event); +} + +bool isControllerRightEvent(const SDL_Event& event) { if (event.type == SDL_CONTROLLERBUTTONDOWN) { if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT ) { return true; @@ -261,6 +270,13 @@ bool isPlayerRightEvent(int playerNumber, const SDL_Event& event) { return false; } +bool isPlayerRightEvent(int playerNumber, const SDL_Event& event) { + if (skipThisPlayer(playerNumber, event)) { + return false; + } + return isControllerRightEvent(event); +} + bool isPlayerSwitchEvent(int playerNumber, const SDL_Event& event) { if (skipThisPlayer(playerNumber, event)) { return false; diff --git a/source/code/gamecontroller.h b/source/code/gamecontroller.h index 749be39..3648250 100644 --- a/source/code/gamecontroller.h +++ b/source/code/gamecontroller.h @@ -33,6 +33,11 @@ const int deadZoneLimit = 20000; void InitGameControllers(); void UnInitGameControllers(); +bool isControllerDownEvent(const SDL_Event& event); +bool isControllerUpEvent(const SDL_Event& event); +bool isControllerLeftEvent(const SDL_Event& event); +bool isControllerRightEvent(const SDL_Event& event); + bool isPlayerDownEvent(int playerNumber, const SDL_Event& event); bool isPlayerUpEvent(int playerNumber, const SDL_Event& event); bool isPlayerLeftEvent(int playerNumber, const SDL_Event& event);