Skip to content

Commit

Permalink
Tweaks to input handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pierr3 committed May 9, 2024
1 parent d1db498 commit c2dce0c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:

- name: Upload artifacts
uses: softprops/action-gh-release@v2
if: matrix.os == 'windows-2019'
if: matrix.os == 'windows-2019' && always()
with:
tag_name: ${{ steps.relinfo.outputs.release }}
files: "out/make/**/*.exe"
Expand Down
2 changes: 1 addition & 1 deletion backend/include/Shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct RemoteDataStatus {

struct UserSettings {
public:
inline static int PttKey = 0;
inline static int PttKey = -1;
inline static int JoystickId = 0;
inline static bool isJoystickButton = false;
// NOLINTNEXTLINE
Expand Down
51 changes: 29 additions & 22 deletions backend/src/InputHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "InputHandler.hpp"
#include "Helpers.hpp"
#include "Shared.hpp"
#include <SFML/Window/Joystick.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <string>

Expand Down Expand Up @@ -44,8 +45,8 @@ void InputHandler::onTimer(Poco::Timer& /*timer*/)
if (isPttSetupRunning) {

// Check for Key presses
for (int i = 0; i < sf::Keyboard::Scan::ScancodeCount; i++) {
if (sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Scan::Scancode>(i))) {
for (int i = sf::Keyboard::Scancode::A; i < sf::Keyboard::Scancode::ScancodeCount; i++) {
if (sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Scancode>(i))) {
TRACK_LOG_INFO("Ptt Key set: {}", i);
updatePttKey(i, false);

Expand All @@ -56,44 +57,49 @@ void InputHandler::onTimer(Poco::Timer& /*timer*/)

// Check for Joystick presses
for (int i = 0; i < sf::Joystick::Count; i++) {
if (sf::Joystick::isConnected(i)) {
for (int j = 0; j < sf::Joystick::getButtonCount(i); j++) {
if (sf::Joystick::isButtonPressed(i, j)) {
TRACK_LOG_INFO("Joystick Ptt Key set: {} on Joystick {}", j, i);
updatePttKey(j, true, i);

isPttSetupRunning = false;
return;
}
if (!sf::Joystick::isConnected(i)) {
continue;
}

for (int j = 0; j < sf::Joystick::getButtonCount(i); j++) {
if (sf::Joystick::isButtonPressed(i, j)) {
TRACK_LOG_INFO("Joystick Ptt Key set: {} on Joystick {}", j, i);
updatePttKey(j, true, i);

isPttSetupRunning = false;
return;
}
}
}

return;
}

if (UserSettings::PttKey == 0) {
if (UserSettings::PttKey == -1) {
return;
}

if (UserSettings::isJoystickButton) {
if (sf::Joystick::isButtonPressed(UserSettings::JoystickId, UserSettings::PttKey)
&& !isPttOpen) {
if (!sf::Joystick::isConnected(UserSettings::JoystickId)) {
return;
}

auto isButtonPressed
= sf::Joystick::isButtonPressed(UserSettings::JoystickId, UserSettings::PttKey);
if (isButtonPressed && !isPttOpen) {
mClient->SetPtt(true);
isPttOpen = true;
} else if (!sf::Joystick::isButtonPressed(UserSettings::JoystickId, UserSettings::PttKey)
&& isPttOpen) {
} else if (!isButtonPressed && isPttOpen) {
mClient->SetPtt(false);
isPttOpen = false;
}
} else {
if (sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Scancode>(UserSettings::PttKey))
&& !isPttOpen) {
auto isKeyPressed
= sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Scancode>(UserSettings::PttKey));
if (isKeyPressed && !isPttOpen) {
mClient->SetPtt(true);
isPttOpen = true;
} else if (!sf::Keyboard::isKeyPressed(
static_cast<sf::Keyboard::Scancode>(UserSettings::PttKey))
&& isPttOpen) {
} else if (!isKeyPressed && isPttOpen) {
mClient->SetPtt(false);
isPttOpen = false;
}
Expand All @@ -115,7 +121,8 @@ std::string InputHandler::getPttKeyName()
}

if (UserSettings::isJoystickButton) {
return "Joystick " + std::to_string(UserSettings::PttKey);
return sf::Joystick::getIdentification(UserSettings::JoystickId).name + " "
+ std::to_string(UserSettings::PttKey);
}

return sf::Keyboard::getDescription(
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2dce0c

Please sign in to comment.