KBM Input Bug Fixes / Added Binds v2 (#3109)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions

* fixed nonload issues with background music (#3094)

* Fixing my pull request branch

* Pull request change part 2

* Continued changes to project and altered kbm_help_dialog.h text to QStringLiterals

* Finalized commit and changed kbm_help_dialog.h

* KBM Input Bug Fixes / Added Binds

Fixed input issues where some inputs would not bind when pressing (side mouse buttons, some symbols, etc). Also, fixed up code formatting in altered files (removed C-style casts and replaced with C++ <static_casts>, added a few macros and one member functions).
This is v2 of my commit, addressing all issues brought up by @kalaposfos

* Updated C-style casts in kbm_gui.cpp

* Fixed formatting from clang-format

* Updated expendable sections location and changed order of appearance

* Merged PR #3098 into kbm_gui.cpp

* Updates from running clang-format

* Potential MacOS error fix

Changes std::string to std::string_view, which prevented MacOS from building

* Undid MacOS commit for new PR

* Revert "Undid MacOS commit for new PR"

This reverts commit fc376c5e1f.

* Updated SDL_INVALID_ID=UINT32_MAX macro to SDL_UNMAPPED=UINT32_MAX-1

* Update from merge conflicts

Updated SDL_INVALID_ID=UINT32_MAX macro to SDL_UNMAPPED=UINT32_MAX-1

* FIxed memory.cpp errors from testing PR  #3117 (MacOS fixes)

* Removed "kp;"

* Fixed help dialogue from kalaposfos' changes

Fixed 3 edits made by kalaposfos from a recent commit.

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
This commit is contained in:
nickci2002 2025-06-20 14:33:27 -04:00 committed by GitHub
parent 7b0249d9ca
commit 8dcd9cc0f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 585 additions and 630 deletions

View file

@ -185,7 +185,7 @@ InputBinding GetBindingFromString(std::string& line) {
if (string_to_keyboard_key_map.find(t) != string_to_keyboard_key_map.end()) {
input = InputID(InputType::KeyboardMouse, string_to_keyboard_key_map.at(t));
} else if (string_to_axis_map.find(t) != string_to_axis_map.end()) {
input = InputID(InputType::Axis, (u32)string_to_axis_map.at(t).axis);
input = InputID(InputType::Axis, string_to_axis_map.at(t).axis);
} else if (string_to_cbutton_map.find(t) != string_to_cbutton_map.end()) {
input = InputID(InputType::Controller, string_to_cbutton_map.at(t));
} else {
@ -236,19 +236,15 @@ void ParseInputConfig(const std::string game_id = "") {
line.erase(std::remove_if(line.begin(), line.end(),
[](unsigned char c) { return std::isspace(c); }),
line.end());
if (line.empty()) {
continue;
}
// Truncate lines starting at #
std::size_t comment_pos = line.find('#');
if (comment_pos != std::string::npos) {
line = line.substr(0, comment_pos);
}
// Remove trailing semicolon
if (!line.empty() && line[line.length() - 1] == ';') {
line = line.substr(0, line.length() - 1);
}
if (line.empty()) {
continue;
}
@ -263,8 +259,13 @@ void ParseInputConfig(const std::string game_id = "") {
std::string output_string = line.substr(0, equal_pos);
std::string input_string = line.substr(equal_pos + 1);
std::size_t comma_pos = input_string.find(',');
// Remove trailing semicolon from input_string
if (!input_string.empty() && input_string[input_string.length() - 1] == ';' &&
input_string != ";") {
line = line.substr(0, line.length() - 1);
}
std::size_t comma_pos = input_string.find(',');
auto parseInt = [](const std::string& s) -> std::optional<int> {
try {
return std::stoi(s);
@ -382,7 +383,6 @@ void ParseInputConfig(const std::string game_id = "") {
BindingConnection connection(InputID(), nullptr);
auto button_it = string_to_cbutton_map.find(output_string);
auto axis_it = string_to_axis_map.find(output_string);
if (binding.IsEmpty()) {
LOG_WARNING(Input, "Invalid format at line: {}, data: \"{}\", skipping line.",
lineCount, line);
@ -420,7 +420,7 @@ void ParseInputConfig(const std::string game_id = "") {
u32 GetMouseWheelEvent(const SDL_Event& event) {
if (event.type != SDL_EVENT_MOUSE_WHEEL && event.type != SDL_EVENT_MOUSE_WHEEL_OFF) {
LOG_WARNING(Input, "Something went wrong with wheel input parsing!");
return (u32)-1;
return SDL_UNMAPPED;
}
if (event.wheel.y > 0) {
return SDL_MOUSE_WHEEL_UP;
@ -431,7 +431,7 @@ u32 GetMouseWheelEvent(const SDL_Event& event) {
} else if (event.wheel.x < 0) {
return SDL_MOUSE_WHEEL_LEFT;
}
return (u32)-1;
return SDL_UNMAPPED;
}
InputEvent InputBinding::GetInputEventFromSDLEvent(const SDL_Event& e) {
@ -441,16 +441,19 @@ 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, static_cast<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, static_cast<u32>(e.gbutton.button), e.gbutton.down,
0); // clang made me do it
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
return InputEvent(InputType::Axis, (u32)e.gaxis.axis, true, e.gaxis.value / 256);
return InputEvent(InputType::Axis, static_cast<u32>(e.gaxis.axis), true,
e.gaxis.value / 256); // this too
default:
return InputEvent();
}
@ -589,7 +592,7 @@ void ControllerOutput::FinalizeUpdate() {
bool UpdatePressedKeys(InputEvent event) {
// Skip invalid inputs
InputID input = event.input;
if (input.sdl_id == (u32)-1) {
if (input.sdl_id == SDL_UNMAPPED) {
return false;
}
if (input.type == InputType::Axis) {