From 441a9b56221394875fbbc9eee8c6537661820618 Mon Sep 17 00:00:00 2001 From: muemart Date: Fri, 8 Dec 2017 13:03:43 +0100 Subject: [PATCH 1/3] Add button labels for sdl joystick mappings --- .../configuration/configure_input.cpp | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 78fedc601f..d94ea93a5a 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -161,34 +161,63 @@ void ConfigureInput::restoreDefaults() { } void ConfigureInput::updateButtonLabels() { - QString non_keyboard(tr("[non-keyboard]")); + QString unknown_mapping(tr("[unknown]")); - auto KeyToText = [&non_keyboard](const Common::ParamPackage& param) { + auto ButtonToText = [&unknown_mapping](const Common::ParamPackage& param) { if (!param.Has("engine")) { return QString("[not set]"); - } else if (param.Get("engine", "") != "keyboard") { - return non_keyboard; - } else { + } else if (param.Get("engine", "") == "keyboard") { return getKeyName(param.Get("code", 0)); + } else if (param.Get("engine", "") == "sdl") { + QString text = QString("Joystick %1").arg(param.Get("joystick", "").c_str()); + if (param.Has("hat")) { + text += QString(" Hat %1 %2") + .arg(param.Get("hat", "").c_str(), param.Get("direction", "").c_str()); + } + if (param.Has("axis")) { + text += QString(" Axis %1%2") + .arg(param.Get("axis", "").c_str(), param.Get("direction", "").c_str()); + } + if (param.Has("button")) { + text += QString(" Button %1").arg(param.Get("button", "").c_str()); + } + return text; + } else { + return unknown_mapping; + } + }; + auto AnalogToText = [&unknown_mapping, &ButtonToText](const Common::ParamPackage& param, + const std::string& dir) { + if (!param.Has("engine")) { + return QString("[not set]"); + } else if (param.Get("engine", "") == "analog_from_button") { + return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); + } else if (param.Get("engine", "") == "sdl") { + if (dir == "modifier") { + return QString("[unused]"); + } + + QString text = QString("Joystick %1").arg(param.Get("joystick", "").c_str()); + if (dir == "left" || dir == "right") { + text += QString(" Axis %1").arg(param.Get("axis_x", "").c_str()); + } else if (dir == "up" || dir == "down") { + text += QString(" Axis %1").arg(param.Get("axis_y", "").c_str()); + } + return text; + } else { + return unknown_mapping; } }; for (int button = 0; button < Settings::NativeButton::NumButtons; button++) { - button_map[button]->setText(KeyToText(buttons_param[button])); + button_map[button]->setText(ButtonToText(buttons_param[button])); } for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { - if (analogs_param[analog_id].Get("engine", "") != "analog_from_button") { - for (QPushButton* button : analog_map_buttons[analog_id]) { - if (button) - button->setText(non_keyboard); - } - } else { - for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { - Common::ParamPackage param( - analogs_param[analog_id].Get(analog_sub_buttons[sub_button_id], "")); - if (analog_map_buttons[analog_id][sub_button_id]) - analog_map_buttons[analog_id][sub_button_id]->setText(KeyToText(param)); + for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { + if (analog_map_buttons[analog_id][sub_button_id]) { + analog_map_buttons[analog_id][sub_button_id]->setText( + AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id])); } } analog_map_stick[analog_id]->setText("Set Analog Stick"); From 53741c6ebd929005d4c074b51c20ae0a07692bba Mon Sep 17 00:00:00 2001 From: muemart Date: Sat, 9 Dec 2017 16:11:17 +0100 Subject: [PATCH 2/3] Add translation support for button labels --- .../configuration/configure_input.cpp | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index d94ea93a5a..2f5cd41a42 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -162,46 +162,47 @@ void ConfigureInput::restoreDefaults() { void ConfigureInput::updateButtonLabels() { QString unknown_mapping(tr("[unknown]")); + QString mapping_not_set(tr("[not set]")); - auto ButtonToText = [&unknown_mapping](const Common::ParamPackage& param) { + auto ButtonToText = [&unknown_mapping, &mapping_not_set](const Common::ParamPackage& param) { if (!param.Has("engine")) { - return QString("[not set]"); + return mapping_not_set; } else if (param.Get("engine", "") == "keyboard") { return getKeyName(param.Get("code", 0)); } else if (param.Get("engine", "") == "sdl") { - QString text = QString("Joystick %1").arg(param.Get("joystick", "").c_str()); + QString text = QString(tr("Joystick %1")).arg(param.Get("joystick", "").c_str()); if (param.Has("hat")) { - text += QString(" Hat %1 %2") + text += QString(tr(" Hat %1 %2")) .arg(param.Get("hat", "").c_str(), param.Get("direction", "").c_str()); } if (param.Has("axis")) { - text += QString(" Axis %1%2") + text += QString(tr(" Axis %1%2")) .arg(param.Get("axis", "").c_str(), param.Get("direction", "").c_str()); } if (param.Has("button")) { - text += QString(" Button %1").arg(param.Get("button", "").c_str()); + text += QString(tr(" Button %1")).arg(param.Get("button", "").c_str()); } return text; } else { return unknown_mapping; } }; - auto AnalogToText = [&unknown_mapping, &ButtonToText](const Common::ParamPackage& param, - const std::string& dir) { + auto AnalogToText = [&unknown_mapping, &mapping_not_set, + &ButtonToText](const Common::ParamPackage& param, const std::string& dir) { if (!param.Has("engine")) { - return QString("[not set]"); + return mapping_not_set; } else if (param.Get("engine", "") == "analog_from_button") { return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); } else if (param.Get("engine", "") == "sdl") { if (dir == "modifier") { - return QString("[unused]"); + return QString(tr("[unused]")); } - QString text = QString("Joystick %1").arg(param.Get("joystick", "").c_str()); + QString text = QString(tr("Joystick %1")).arg(param.Get("joystick", "").c_str()); if (dir == "left" || dir == "right") { - text += QString(" Axis %1").arg(param.Get("axis_x", "").c_str()); + text += QString(tr(" Axis %1")).arg(param.Get("axis_x", "").c_str()); } else if (dir == "up" || dir == "down") { - text += QString(" Axis %1").arg(param.Get("axis_y", "").c_str()); + text += QString(tr(" Axis %1")).arg(param.Get("axis_y", "").c_str()); } return text; } else { @@ -220,7 +221,7 @@ void ConfigureInput::updateButtonLabels() { AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id])); } } - analog_map_stick[analog_id]->setText("Set Analog Stick"); + analog_map_stick[analog_id]->setText(tr("Set Analog Stick")); } } From 23732a9ab348fea4a076d48da6663880c849a674 Mon Sep 17 00:00:00 2001 From: muemart Date: Wed, 13 Dec 2017 19:06:14 +0100 Subject: [PATCH 3/3] Use static functions instead of lambdas --- .../configuration/configure_input.cpp | 95 +++++++++---------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 2f5cd41a42..5a7d269cdb 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -41,6 +41,52 @@ static void SetAnalogButton(const Common::ParamPackage& input_param, analog_param.Set(button_name, input_param.Serialize()); } +static QString ButtonToText(const Common::ParamPackage& param) { + if (!param.Has("engine")) { + return QObject::tr("[not set]"); + } else if (param.Get("engine", "") == "keyboard") { + return getKeyName(param.Get("code", 0)); + } else if (param.Get("engine", "") == "sdl") { + QString text = QString(QObject::tr("Joystick %1")).arg(param.Get("joystick", "").c_str()); + if (param.Has("hat")) { + text += QString(QObject::tr(" Hat %1 %2")) + .arg(param.Get("hat", "").c_str(), param.Get("direction", "").c_str()); + } + if (param.Has("axis")) { + text += QString(QObject::tr(" Axis %1%2")) + .arg(param.Get("axis", "").c_str(), param.Get("direction", "").c_str()); + } + if (param.Has("button")) { + text += QString(QObject::tr(" Button %1")).arg(param.Get("button", "").c_str()); + } + return text; + } else { + return QObject::tr("[unknown]"); + } +}; + +static QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) { + if (!param.Has("engine")) { + return QObject::tr("[not set]"); + } else if (param.Get("engine", "") == "analog_from_button") { + return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); + } else if (param.Get("engine", "") == "sdl") { + if (dir == "modifier") { + return QString(QObject::tr("[unused]")); + } + + QString text = QString(QObject::tr("Joystick %1")).arg(param.Get("joystick", "").c_str()); + if (dir == "left" || dir == "right") { + text += QString(QObject::tr(" Axis %1")).arg(param.Get("axis_x", "").c_str()); + } else if (dir == "up" || dir == "down") { + text += QString(QObject::tr(" Axis %1")).arg(param.Get("axis_y", "").c_str()); + } + return text; + } else { + return QObject::tr("[unknown]"); + } +}; + ConfigureInput::ConfigureInput(QWidget* parent) : QWidget(parent), ui(std::make_unique()), timeout_timer(std::make_unique()), poll_timer(std::make_unique()) { @@ -161,55 +207,6 @@ void ConfigureInput::restoreDefaults() { } void ConfigureInput::updateButtonLabels() { - QString unknown_mapping(tr("[unknown]")); - QString mapping_not_set(tr("[not set]")); - - auto ButtonToText = [&unknown_mapping, &mapping_not_set](const Common::ParamPackage& param) { - if (!param.Has("engine")) { - return mapping_not_set; - } else if (param.Get("engine", "") == "keyboard") { - return getKeyName(param.Get("code", 0)); - } else if (param.Get("engine", "") == "sdl") { - QString text = QString(tr("Joystick %1")).arg(param.Get("joystick", "").c_str()); - if (param.Has("hat")) { - text += QString(tr(" Hat %1 %2")) - .arg(param.Get("hat", "").c_str(), param.Get("direction", "").c_str()); - } - if (param.Has("axis")) { - text += QString(tr(" Axis %1%2")) - .arg(param.Get("axis", "").c_str(), param.Get("direction", "").c_str()); - } - if (param.Has("button")) { - text += QString(tr(" Button %1")).arg(param.Get("button", "").c_str()); - } - return text; - } else { - return unknown_mapping; - } - }; - auto AnalogToText = [&unknown_mapping, &mapping_not_set, - &ButtonToText](const Common::ParamPackage& param, const std::string& dir) { - if (!param.Has("engine")) { - return mapping_not_set; - } else if (param.Get("engine", "") == "analog_from_button") { - return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); - } else if (param.Get("engine", "") == "sdl") { - if (dir == "modifier") { - return QString(tr("[unused]")); - } - - QString text = QString(tr("Joystick %1")).arg(param.Get("joystick", "").c_str()); - if (dir == "left" || dir == "right") { - text += QString(tr(" Axis %1")).arg(param.Get("axis_x", "").c_str()); - } else if (dir == "up" || dir == "down") { - text += QString(tr(" Axis %1")).arg(param.Get("axis_y", "").c_str()); - } - return text; - } else { - return unknown_mapping; - } - }; - for (int button = 0; button < Settings::NativeButton::NumButtons; button++) { button_map[button]->setText(ButtonToText(buttons_param[button])); }