From 980de7b67c67ca9c269e0cbe41b905ab5887cec1 Mon Sep 17 00:00:00 2001 From: Thomaltarix Date: Fri, 21 Jun 2024 17:32:27 +0200 Subject: [PATCH 1/2] feat: GamePad controller inputs all inputs are done except the window closing --- gui/include/Event/Event.hpp | 25 +++++++++++++++++++++++++ gui/src/Event/Event.cpp | 14 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/gui/include/Event/Event.hpp b/gui/include/Event/Event.hpp index f7a8236b..149a8a6e 100644 --- a/gui/include/Event/Event.hpp +++ b/gui/include/Event/Event.hpp @@ -57,6 +57,12 @@ class Gui::Event : public Gui::AEvent { {KEY_LEFT_SHIFT, [this](){moveDownCamera();}}, }; + std::unordered_map> _eventsGamepadButtonDown = + { + {GAMEPAD_BUTTON_RIGHT_TRIGGER_2, [this](){handleSpaceGamepad();}}, + {GAMEPAD_BUTTON_LEFT_TRIGGER_2, [this](){moveDownCamera();}}, + }; + /** * @brief Map for events by pressing key. * @@ -75,6 +81,20 @@ class Gui::Event : public Gui::AEvent { {KEY_KP_SUBTRACT, [this](){decreaseTimeUnit();}}, }; + std::unordered_map> _eventsGamepadButtonPressed = + { + {GAMEPAD_BUTTON_RIGHT_FACE_DOWN, [this](){handleLeftClick();}}, + {GAMEPAD_BUTTON_RIGHT_TRIGGER_1, [this](){handleLeftClick();}}, + {GAMEPAD_BUTTON_LEFT_TRIGGER_1, [this](){handleRightClick();}}, + {GAMEPAD_BUTTON_LEFT_FACE_UP, [this](){increaseRenderDistance();}}, + {GAMEPAD_BUTTON_LEFT_FACE_DOWN, [this](){decreaseRenderDistance();}}, + {GAMEPAD_BUTTON_LEFT_FACE_LEFT, [this](){decreaseTimeUnit();}}, + {GAMEPAD_BUTTON_LEFT_FACE_RIGHT, [this](){increaseTimeUnit();}}, + {GAMEPAD_BUTTON_RIGHT_FACE_LEFT, [this](){switchDisplayDebug();}}, + {GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, [this](){switchTileHudToGame();}}, + {GAMEPAD_BUTTON_RIGHT_FACE_UP, [this](){changeActualPlayerPov();}} + }; + /** * @brief Map for events by pressing mouse. * @@ -172,4 +192,9 @@ class Gui::Event : public Gui::AEvent { * */ void decreaseTimeUnit(); + + /** + * @brief Handle Space for Gamepad + */ + void handleSpaceGamepad(); }; diff --git a/gui/src/Event/Event.cpp b/gui/src/Event/Event.cpp index c98f3c95..43ec9d5b 100644 --- a/gui/src/Event/Event.cpp +++ b/gui/src/Event/Event.cpp @@ -28,6 +28,14 @@ void Gui::Event::listen() if (IsMouseButtonPressed(event.first)) event.second(); } + for (auto &event : _eventsGamepadButtonDown) { + if (IsGamepadButtonDown(0, event.first)) + event.second(); + } + for (auto &event : _eventsGamepadButtonPressed) { + if (IsGamepadButtonPressed(0, event.first)) + event.second(); + } } void Gui::Event::moveUpCamera() @@ -192,3 +200,9 @@ void Gui::Event::decreaseTimeUnit() if (_gameData.get()->getTimeUnitFromServer() == GameData::TimeUnitState::NONE) _gameData.get()->setTimeUnitFromServer(GameData::TimeUnitState::DECREASE); } + +void Gui::Event::handleSpaceGamepad() +{ + setFreeCam(); + moveUpCamera(); +} From 33c7cf1da417023fca10603c6c520c744fb365f4 Mon Sep 17 00:00:00 2001 From: Thomaltarix Date: Fri, 21 Jun 2024 20:59:08 +0200 Subject: [PATCH 2/2] feat: Enable the possibility to close the window from a GamePad --- gui/include/Event/Event.hpp | 8 +++++++- gui/src/Event/Event.cpp | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gui/include/Event/Event.hpp b/gui/include/Event/Event.hpp index 149a8a6e..def8129d 100644 --- a/gui/include/Event/Event.hpp +++ b/gui/include/Event/Event.hpp @@ -92,7 +92,8 @@ class Gui::Event : public Gui::AEvent { {GAMEPAD_BUTTON_LEFT_FACE_RIGHT, [this](){increaseTimeUnit();}}, {GAMEPAD_BUTTON_RIGHT_FACE_LEFT, [this](){switchDisplayDebug();}}, {GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, [this](){switchTileHudToGame();}}, - {GAMEPAD_BUTTON_RIGHT_FACE_UP, [this](){changeActualPlayerPov();}} + {GAMEPAD_BUTTON_RIGHT_FACE_UP, [this](){changeActualPlayerPov();}}, + {GAMEPAD_BUTTON_MIDDLE_RIGHT, [this](){closeWindowGamepad();}}, }; /** @@ -197,4 +198,9 @@ class Gui::Event : public Gui::AEvent { * @brief Handle Space for Gamepad */ void handleSpaceGamepad(); + + /** + * @brief Close the window for Gamepad + */ + void closeWindowGamepad(); }; diff --git a/gui/src/Event/Event.cpp b/gui/src/Event/Event.cpp index 43ec9d5b..d35b6230 100644 --- a/gui/src/Event/Event.cpp +++ b/gui/src/Event/Event.cpp @@ -206,3 +206,8 @@ void Gui::Event::handleSpaceGamepad() setFreeCam(); moveUpCamera(); } + +void Gui::Event::closeWindowGamepad() +{ + _gameData.get()->setIsEndGame(true); +}