diff --git a/src/input/input_handler.cpp b/src/input/input_handler.cpp index 785e96d41..89701e645 100644 --- a/src/input/input_handler.cpp +++ b/src/input/input_handler.cpp @@ -223,8 +223,10 @@ void ParseInputConfig(const std::string game_id = "") { while (std::getline(file, line)) { lineCount++; + auto line_kpmask = (line.substr(0, 2) == "kp ") ? line.begin() + 2 : line.begin(); + // Strip the ; and whitespace - line.erase(std::remove_if(line.begin(), line.end(), + line.erase(std::remove_if(line_kpmask, line.end(), [](unsigned char c) { return std::isspace(c); }), line.end()); diff --git a/src/qt_gui/kbm_gui.cpp b/src/qt_gui/kbm_gui.cpp index d19ac13d0..86fd9fa49 100644 --- a/src/qt_gui/kbm_gui.cpp +++ b/src/qt_gui/kbm_gui.cpp @@ -144,169 +144,63 @@ void KBMSettings::EnableMappingButtons() { } } -void KBMSettings::SaveKBMConfig(bool CloseOnSave) { +void KBMSettings::SaveKBMConfig(bool close_on_save) { std::string output_string = "", input_string = ""; std::vector lines, inputs; + // Comment lines for config file lines.push_back("#Feeling lost? Check out the Help section!"); lines.push_back(""); lines.push_back("#Keyboard bindings"); lines.push_back(""); - input_string = ui->CrossButton->text().toStdString(); - output_string = "cross"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->CircleButton->text().toStdString(); - output_string = "circle"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->TriangleButton->text().toStdString(); - output_string = "triangle"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->SquareButton->text().toStdString(); - output_string = "square"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); + // Lambda to reduce repetitive code for mapping buttons to config lines + auto add_mapping = [&](const QString& buttonText, const std::string& output_name) { + input_string = buttonText.toStdString(); + output_string = output_name; + lines.push_back(output_string + " = " + input_string); + if (input_string != "unmapped") { + inputs.push_back(input_string); + } + }; + add_mapping(ui->CrossButton->text(), "cross"); + add_mapping(ui->CircleButton->text(), "circle"); + add_mapping(ui->TriangleButton->text(), "triangle"); + add_mapping(ui->SquareButton->text(), "square"); + lines.push_back(""); - input_string = ui->DpadUpButton->text().toStdString(); - output_string = "pad_up"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->DpadDownButton->text().toStdString(); - output_string = "pad_down"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->DpadLeftButton->text().toStdString(); - output_string = "pad_left"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->DpadRightButton->text().toStdString(); - output_string = "pad_right"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - + add_mapping(ui->DpadUpButton->text(), "pad_up"); + add_mapping(ui->DpadDownButton->text(), "pad_down"); + add_mapping(ui->DpadLeftButton->text(), "pad_left"); + add_mapping(ui->DpadRightButton->text(), "pad_right"); + lines.push_back(""); - input_string = ui->L1Button->text().toStdString(); - output_string = "l1"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->R1Button->text().toStdString(); - output_string = "r1"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->L2Button->text().toStdString(); - output_string = "l2"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->R2Button->text().toStdString(); - output_string = "r2"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->L3Button->text().toStdString(); - output_string = "l3"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->R3Button->text().toStdString(); - output_string = "r3"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - + add_mapping(ui->L1Button->text(), "l1"); + add_mapping(ui->R1Button->text(), "r1"); + add_mapping(ui->L2Button->text(), "l2"); + add_mapping(ui->R2Button->text(), "r2"); + add_mapping(ui->L3Button->text(), "l3"); + add_mapping(ui->R3Button->text(), "r3"); + lines.push_back(""); - input_string = ui->OptionsButton->text().toStdString(); - output_string = "options"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->TouchpadButton->text().toStdString(); - output_string = "touchpad"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - + add_mapping(ui->OptionsButton->text(), "options"); + add_mapping(ui->TouchpadButton->text(), "touchpad"); lines.push_back(""); - input_string = ui->LStickUpButton->text().toStdString(); - output_string = "axis_left_y_minus"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->LStickDownButton->text().toStdString(); - output_string = "axis_left_y_plus"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->LStickLeftButton->text().toStdString(); - output_string = "axis_left_x_minus"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->LStickRightButton->text().toStdString(); - output_string = "axis_left_x_plus"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - + add_mapping(ui->LStickUpButton->text(), "axis_left_y_minus"); + add_mapping(ui->LStickDownButton->text(), "axis_left_y_plus"); + add_mapping(ui->LStickLeftButton->text(), "axis_left_x_minus"); + add_mapping(ui->LStickRightButton->text(), "axis_left_x_plus"); lines.push_back(""); - input_string = ui->RStickUpButton->text().toStdString(); - output_string = "axis_right_y_minus"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->RStickDownButton->text().toStdString(); - output_string = "axis_right_y_plus"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->RStickLeftButton->text().toStdString(); - output_string = "axis_right_x_minus"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->RStickRightButton->text().toStdString(); - output_string = "axis_right_x_plus"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - + add_mapping(ui->RStickUpButton->text(), "axis_right_y_minus"); + add_mapping(ui->RStickDownButton->text(), "axis_right_y_plus"); + add_mapping(ui->RStickLeftButton->text(), "axis_right_x_minus"); + add_mapping(ui->RStickRightButton->text(), "axis_right_x_plus"); lines.push_back(""); input_string = ui->MouseJoystickBox->currentText().toStdString(); @@ -314,17 +208,8 @@ void KBMSettings::SaveKBMConfig(bool CloseOnSave) { if (input_string != "unmapped") lines.push_back(output_string + " = " + input_string); - input_string = ui->LHalfButton->text().toStdString(); - output_string = "leftjoystick_halfmode"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); - - input_string = ui->RHalfButton->text().toStdString(); - output_string = "rightjoystick_halfmode"; - lines.push_back(output_string + " = " + input_string); - if (input_string != "unmapped") - inputs.push_back(input_string); + add_mapping(ui->LHalfButton->text(), "leftjoystick_halfmode"); + add_mapping(ui->RHalfButton->text(), "rightjoystick_halfmode"); std::string DOString = std::format("{:.2f}", (ui->DeadzoneOffsetSlider->value() / 100.f)); std::string SMString = std::format("{:.1f}", (ui->SpeedMultiplierSlider->value() / 10.f)); @@ -398,15 +283,15 @@ void KBMSettings::SaveKBMConfig(bool CloseOnSave) { Config::SetUseUnifiedInputConfig(!ui->PerGameCheckBox->isChecked()); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); - if (CloseOnSave) + if (close_on_save) QWidget::close(); } void KBMSettings::SetDefault() { - ui->CrossButton->setText("kp2"); - ui->CircleButton->setText("kp6"); - ui->TriangleButton->setText("kp8"); - ui->SquareButton->setText("kp4"); + ui->CrossButton->setText("kp 2"); + ui->CircleButton->setText("kp 6"); + ui->TriangleButton->setText("kp 8"); + ui->SquareButton->setText("kp 4"); ui->L1Button->setText("q"); ui->L2Button->setText("e"); @@ -645,6 +530,16 @@ void KBMSettings::SetMapping(QString input) { MappingCompleted = true; } +// Helper lambda to get the modified button text based on the current keyboard modifiers +auto GetModifiedButton = [](Qt::KeyboardModifiers modifier, + const std::string& m_button, const std::string& n_button) -> QString { + if (QApplication::keyboardModifiers() & modifier) { + return QString::fromStdString(m_button); + } else { + return QString::fromStdString(n_button); + } +}; + bool KBMSettings::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::Close) { if (HelpWindowOpen) { @@ -745,34 +640,34 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) { pressedKeys.insert("z"); break; case Qt::Key_0: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp0", "0")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 0", "0")); break; case Qt::Key_1: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp1", "1")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 1", "1")); break; case Qt::Key_2: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp2", "2")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 2", "2")); break; case Qt::Key_3: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp3", "3")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 3", "3")); break; case Qt::Key_4: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp4", "4")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 4", "4")); break; case Qt::Key_5: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp5", "5")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 5", "5")); break; case Qt::Key_6: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp6", "6")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 6", "6")); break; case Qt::Key_7: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp7", "7")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 7", "7")); break; case Qt::Key_8: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp8", "8")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 8", "8")); break; case Qt::Key_9: - pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp9", "9")); + pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 9", "9")); break; // symbols @@ -869,13 +764,13 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) { // special keys case Qt::Key_Print: - pressedKeys.insert("print"); + pressedKeys.insert("printscreen"); break; case Qt::Key_ScrollLock: pressedKeys.insert("scrolllock"); break; case Qt::Key_Pause: - pressedKeys.insert("pause"); + pressedKeys.insert("pausebreak"); break; case Qt::Key_Backspace: pressedKeys.insert("backspace"); @@ -1045,23 +940,4 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) { return QDialog::eventFilter(obj, event); } -// m_button is modified button name, n_button is normal button name -QString KBMSettings::GetModifiedButton(Qt::KeyboardModifiers modifier, - std::string m_button, std::string n_button) { - if (QApplication::keyboardModifiers() & modifier) { - return QString::fromStdString(m_button); - } else { - return QString::fromStdString(n_button); - } -} - -// // Lambda version of GetModifiedButton -// auto GetModifiedButton = [](Qt::KeyboardModifiers modifier, const std::string& m_button, const std::string& n_button) -> QString { -// if (QApplication::keyboardModifiers() & modifier) { -// return QString::fromStdString(m_button); -// } else { -// return QString::fromStdString(n_button); -// } -// }; - -KBMSettings::~KBMSettings() {} +KBMSettings::~KBMSettings() {} \ No newline at end of file diff --git a/src/qt_gui/kbm_gui.h b/src/qt_gui/kbm_gui.h index 7115ea958..09a9166b9 100644 --- a/src/qt_gui/kbm_gui.h +++ b/src/qt_gui/kbm_gui.h @@ -38,8 +38,6 @@ private: std::shared_ptr m_game_info; bool eventFilter(QObject* obj, QEvent* event) override; - QString GetModifiedButton(Qt::KeyboardModifiers modifier, - std::string m_button, std::string n_button); void ButtonConnects(); void SetUIValuestoMappings(std::string config_id); void GetGameTitle(); diff --git a/src/qt_gui/kbm_help_dialog.cpp b/src/qt_gui/kbm_help_dialog.cpp index c13e18b59..e6135988a 100644 --- a/src/qt_gui/kbm_help_dialog.cpp +++ b/src/qt_gui/kbm_help_dialog.cpp @@ -4,6 +4,7 @@ #include "kbm_help_dialog.h" #include +//#include #include #include #include diff --git a/src/qt_gui/kbm_help_dialog.h b/src/qt_gui/kbm_help_dialog.h index 3e39d4397..858685dc0 100644 --- a/src/qt_gui/kbm_help_dialog.h +++ b/src/qt_gui/kbm_help_dialog.h @@ -43,17 +43,18 @@ private: bool* help_open_ptr; QString quickstart() { - return - R"(The keyboard and controller remapping backend, GUI and documentation have been written by kalaposfos + return QStringLiteral(R"( +The keyboard and controller remapping backend, GUI and documentation have been written by kalaposfos In this section, you will find information about the project, its features and help on setting up your ideal setup. To view the config file's syntax, check out the Syntax tab, for keybind names, visit Normal Keybinds and Special Bindings, and if you are here to view emulator-wide keybinds, you can find it in the FAQ section. This project started out because I didn't like the original unchangeable keybinds, but rather than waiting for someone else to do it, I implemented this myself. From the default keybinds, you can clearly tell this was a project built for Bloodborne, but ovbiously you can make adjustments however you like. -)"; +)"); } + QString faq() { - return - R"(Q: What are the emulator-wide keybinds? + return QStringLiteral(R"( +Q: What are the emulator-wide keybinds? A: -F12: Triggers Renderdoc capture -F11: Toggles fullscreen -F10: Toggles FPS counter @@ -76,11 +77,12 @@ A: If you're using per-game configs, it's the base from which all new games gene Q: What does the use Per-game Config checkbox do? A: It controls whether the config is loaded from CUSAXXXXX.ini for a game, or from default.ini. This way, if you only want to manage one set of bindings, you can do so, but if you want to use a different setup for every game, that's possible as well. -)"; +)"); } + QString syntax() { - return - R"(This is the full list of currently supported mouse, keyboard and controller inputs, and how to use them. + return QStringLiteral(R"( +This is the full list of currently supported mouse, keyboard and controller inputs, and how to use them. Emulator-reserved keys: F1 through F12 Syntax (aka how a line can look like): @@ -100,22 +102,31 @@ axis_left_y_minus = w; You can make a comment line by putting # as the first character. Whitespace doesn't matter, =; is just as valid as = ; ';' at the ends of lines is also optional. -)"; +)"); } + QString bindings() { - return - R"(The following names should be interpreted without the '' around them, and for inputs that have left and right versions, only the left one is shown, but the right can be inferred from that. -Example: 'lshift', 'rshift' + return QStringLiteral(R"( +The following names should be interpreted without the '' around them, and for inputs that have left and right versions, only the left one is shown, but the right can be inferred from that. + Example: 'lshift', 'rshift' Keyboard: -Alphabet: 'a', 'b', ..., 'z' -Numbers: '0', '1', ..., '9' -Keypad: 'kp0', kp1', ..., 'kp9', 'kpperiod', 'kpcomma', - 'kpdivide', 'kpmultiply', 'kpdivide', 'kpplus', 'kpminus', 'kpenter' -Punctuation and misc: - 'space', 'comma', 'period', 'question', 'semicolon', 'minus', 'plus', 'lparenthesis', 'lbracket', 'lbrace', 'backslash', 'dash', - 'enter', 'tab', backspace', 'escape' -Arrow keys: 'up', 'down', 'left', 'right' +Alphabet: + 'a', 'b', ..., 'z' +Numbers: + '0', '1', ..., '9' +Keypad: + 'kp 0', kp 1', ..., 'kp 9', + 'kp .', 'kp ,', 'kp /', 'kp *', 'kp -', 'kp +', 'kp =', 'kp enter' +Symbols: + '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '{', '}', '[', ']', '\', '|', + ';', ':', ''', '"', ',', '<', '.', '>', '/', '?' +Special keys: + 'escape (text editor only)', 'printscreen', 'scrolllock', 'pausebreak', + 'backspace', 'insert', 'delete', 'home', 'end', 'pgup', 'pgdown', 'tab', + 'capslock', 'enter', 'space' +Arrow keys: + 'up', 'down', 'left', 'right' Modifier keys: 'lctrl', 'lshift', 'lalt', 'lwin' = 'lmeta' (same input, different names, so if you are not on Windows and don't like calling this the Windows key, there is an alternative) @@ -138,11 +149,12 @@ Controller: Axes if you bind them to another axis input: 'axis_left_x' 'axis_left_y' 'axis_right_x' 'axis_right_y', 'l2' -)"; +)"); } + QString special() { - return - R"(There are some extra bindings you can put into the config file, that don't correspond to a controller input, but rather something else. + return QStringLiteral(R"( +There are some extra bindings you can put into the config file, that don't correspond to a controller input, but rather something else. You can find these here, with detailed comments, examples and suggestions for most of them. 'leftjoystick_halfmode' and 'rightjoystick_halfmode' = ; @@ -171,6 +183,6 @@ You can find these here, with detailed comments, examples and suggestions for mo Values go from 1 to 127 (no deadzone to max deadzone), first is the inner, second is the outer deadzone If you only want inner or outer deadzone, set the other to 1 or 127, respectively Devices: leftjoystick, rightjoystick, l2, r2 -)"; +)"); } }; \ No newline at end of file