This commit is contained in:
kalaposfos13 2025-01-31 15:00:07 +01:00
parent 32ffc1e566
commit eb46ba9968
4 changed files with 31 additions and 32 deletions

View File

@ -68,20 +68,20 @@ auto output_array = std::array{
ControllerOutput(KEY_TOGGLE),
// Button mappings
ControllerOutput(SDL_GAMEPAD_BUTTON_NORTH), // Triangle
ControllerOutput(SDL_GAMEPAD_BUTTON_EAST), // Circle
ControllerOutput(SDL_GAMEPAD_BUTTON_SOUTH), // Cross
ControllerOutput(SDL_GAMEPAD_BUTTON_WEST), // Square
ControllerOutput(SDL_GAMEPAD_BUTTON_NORTH), // Triangle
ControllerOutput(SDL_GAMEPAD_BUTTON_EAST), // Circle
ControllerOutput(SDL_GAMEPAD_BUTTON_SOUTH), // Cross
ControllerOutput(SDL_GAMEPAD_BUTTON_WEST), // Square
ControllerOutput(SDL_GAMEPAD_BUTTON_LEFT_SHOULDER), // L1
ControllerOutput(SDL_GAMEPAD_BUTTON_LEFT_STICK), // L3
ControllerOutput(SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER), // R1
ControllerOutput(SDL_GAMEPAD_BUTTON_RIGHT_STICK), // R3
ControllerOutput(SDL_GAMEPAD_BUTTON_START), // Options
ControllerOutput(SDL_GAMEPAD_BUTTON_TOUCHPAD), // TouchPad
ControllerOutput(SDL_GAMEPAD_BUTTON_DPAD_UP), // Up
ControllerOutput(SDL_GAMEPAD_BUTTON_DPAD_DOWN),// Down
ControllerOutput(SDL_GAMEPAD_BUTTON_DPAD_LEFT),// Left
ControllerOutput(SDL_GAMEPAD_BUTTON_DPAD_RIGHT),// Right
ControllerOutput(SDL_GAMEPAD_BUTTON_START), // Options
ControllerOutput(SDL_GAMEPAD_BUTTON_TOUCHPAD), // TouchPad
ControllerOutput(SDL_GAMEPAD_BUTTON_DPAD_UP), // Up
ControllerOutput(SDL_GAMEPAD_BUTTON_DPAD_DOWN), // Down
ControllerOutput(SDL_GAMEPAD_BUTTON_DPAD_LEFT), // Left
ControllerOutput(SDL_GAMEPAD_BUTTON_DPAD_RIGHT), // Right
// Axis mappings
// ControllerOutput(SDL_GAMEPAD_BUTTON_INVALID, SDL_GAMEPAD_AXIS_LEFTX, false),
@ -146,8 +146,7 @@ static OrbisPadButtonDataOffset SDLGamepadToOrbisButton(u8 button) {
}
Axis GetAxisFromSDLAxis(u8 sdl_axis) {
switch (sdl_axis)
{
switch (sdl_axis) {
case SDL_GAMEPAD_AXIS_LEFTX:
return Axis::LeftX;
case SDL_GAMEPAD_AXIS_LEFTY:
@ -278,8 +277,8 @@ void ParseInputConfig(const std::string game_id = "") {
line);
continue;
}
ControllerOutput* toggle_out = &*std::ranges::find(
output_array, ControllerOutput(KEY_TOGGLE));
ControllerOutput* toggle_out =
&*std::ranges::find(output_array, ControllerOutput(KEY_TOGGLE));
BindingConnection toggle_connection = BindingConnection(
InputBinding(toggle_keys.keys[0]), toggle_out, 0, toggle_keys.keys[1]);
connections.insert(connections.end(), toggle_connection);
@ -348,7 +347,8 @@ void ParseInputConfig(const std::string game_id = "") {
connection = BindingConnection(
binding,
&*std::ranges::find(output_array, ControllerOutput(SDL_GAMEPAD_BUTTON_INVALID,
axis_it->second.axis, axis_it->second.value >= 0)),
axis_it->second.axis,
axis_it->second.value >= 0)),
value_to_set);
connections.insert(connections.end(), connection);
} else {
@ -390,16 +390,14 @@ InputEvent InputBinding::GetInputEventFromSDLEvent(const SDL_Event& e) {
return InputEvent(InputType::KeyboardMouse, e.key.key, e.key.down, 0);
case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
return InputEvent(InputType::KeyboardMouse, (u32)e.button.button,
e.button.down, 0);
return InputEvent(InputType::KeyboardMouse, (u32)e.button.button, e.button.down, 0);
case SDL_EVENT_MOUSE_WHEEL:
case SDL_EVENT_MOUSE_WHEEL_OFF:
return InputEvent(InputType::KeyboardMouse, GetMouseWheelEvent(e),
e.type == SDL_EVENT_MOUSE_WHEEL, 0);
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
return InputEvent(InputType::Controller, (u32)e.gbutton.button,
e.gbutton.down, 0);
return InputEvent(InputType::Controller, (u32)e.gbutton.button, e.gbutton.down, 0);
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
return InputEvent(InputType::Axis, (u32)e.gaxis.axis, true, e.gaxis.value / 256);
default:
@ -467,7 +465,7 @@ void ControllerOutput::FinalizeUpdate() {
if (!state_changed) {
// return;
}
old_button_state = new_button_state;
old_param = *new_param;
float touchpad_x = 0;
@ -545,9 +543,9 @@ bool UpdatePressedKeys(InputEvent event) {
// and from there, it only changes the parameter
auto it = std::lower_bound(pressed_keys.begin(), pressed_keys.end(), input,
[](const std::pair<InputEvent, bool>& e, InputID i) {
return std::tie(e.first.input.type, e.first.input.sdl_id) <
std::tie(i.type, i.sdl_id);
});
return std::tie(e.first.input.type, e.first.input.sdl_id) <
std::tie(i.type, i.sdl_id);
});
if (it == pressed_keys.end() || it->first.input != input) {
pressed_keys.insert(it, {event, false});
LOG_DEBUG(Input, "Added axis {} to the input list", event.input.sdl_id);
@ -559,9 +557,9 @@ bool UpdatePressedKeys(InputEvent event) {
// Find the correct position for insertion to maintain order
auto it = std::lower_bound(pressed_keys.begin(), pressed_keys.end(), input,
[](const std::pair<InputEvent, bool>& e, InputID i) {
return std::tie(e.first.input.type, e.first.input.sdl_id) <
std::tie(i.type, i.sdl_id);
});
return std::tie(e.first.input.type, e.first.input.sdl_id) <
std::tie(i.type, i.sdl_id);
});
// Insert only if 'value' is not already in the list
if (it == pressed_keys.end() || it->first.input != input) {

View File

@ -43,7 +43,7 @@ struct AxisMapping {
};
enum class InputType { Axis, KeyboardMouse, Controller, Count };
const std::array<std::string, 4> input_type_names = { "Axis", "KBM", "Controller", "Unknown"};
const std::array<std::string, 4> input_type_names = {"Axis", "KBM", "Controller", "Unknown"};
class InputID {
public:
@ -310,7 +310,8 @@ public:
case 2:
return fmt::format("({}, {})", keys[0].ToString(), keys[1].ToString());
case 3:
return fmt::format("({}, {}, {})", keys[0].ToString(), keys[1].ToString(), keys[2].ToString());
return fmt::format("({}, {}, {})", keys[0].ToString(), keys[1].ToString(),
keys[2].ToString());
default:
return "Empty";
}
@ -331,7 +332,7 @@ public:
// these are only used as s8,
// but I added some padding to avoid overflow if it's activated by multiple inputs
// axis_plus and axis_minus pairs share a common new_param, the other outputs have their own
s16 old_param;
s16 old_param;
s16* new_param;
bool old_button_state, new_button_state, state_changed, positive_axis;

View File

@ -9,8 +9,8 @@
#include "string"
class EditorDialog : public QDialog {
Q_OBJECT // Necessary for using Qt's meta-object system (signals/slots)
public : explicit EditorDialog(QWidget* parent = nullptr); // Constructor
Q_OBJECT // Necessary for using Qt's meta-object system (signals/slots)
public : explicit EditorDialog(QWidget* parent = nullptr); // Constructor
protected:
void closeEvent(QCloseEvent* event) override; // Override close event

View File

@ -5,8 +5,8 @@
#include "common/types.h"
#include "core/libraries/pad/pad.h"
#include "string"
#include "input/controller.h"
#include "string"
struct SDL_Window;
struct SDL_Gamepad;