diff options
| author | 2018-01-16 17:55:59 -0500 | |
|---|---|---|
| committer | 2018-01-16 17:55:59 -0500 | |
| commit | 5f6e29831fa6255fc60fe29d060dd43570edde41 (patch) | |
| tree | 983d6ae4a863d79c7fd0ecaf13e58df80b2dab55 /src | |
| parent | Merge pull request #44 from Rozelette/master (diff) | |
| parent | Use static functions instead of lambdas (diff) | |
| download | yuzu-5f6e29831fa6255fc60fe29d060dd43570edde41.tar.gz yuzu-5f6e29831fa6255fc60fe29d060dd43570edde41.tar.xz yuzu-5f6e29831fa6255fc60fe29d060dd43570edde41.zip | |
Merge pull request #53 from nkatz565/nk-fixlabels
Implement Pull #3240 from Citra: Add button labels for sdl joystick mappings
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_input.cpp | 77 |
1 files changed, 52 insertions, 25 deletions
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index c7f0b613b..10043e6e8 100644 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp | |||
| @@ -42,6 +42,52 @@ static void SetAnalogButton(const Common::ParamPackage& input_param, | |||
| 42 | analog_param.Set(button_name, input_param.Serialize()); | 42 | analog_param.Set(button_name, input_param.Serialize()); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | static QString ButtonToText(const Common::ParamPackage& param) { | ||
| 46 | if (!param.Has("engine")) { | ||
| 47 | return QObject::tr("[not set]"); | ||
| 48 | } else if (param.Get("engine", "") == "keyboard") { | ||
| 49 | return getKeyName(param.Get("code", 0)); | ||
| 50 | } else if (param.Get("engine", "") == "sdl") { | ||
| 51 | QString text = QString(QObject::tr("Joystick %1")).arg(param.Get("joystick", "").c_str()); | ||
| 52 | if (param.Has("hat")) { | ||
| 53 | text += QString(QObject::tr(" Hat %1 %2")) | ||
| 54 | .arg(param.Get("hat", "").c_str(), param.Get("direction", "").c_str()); | ||
| 55 | } | ||
| 56 | if (param.Has("axis")) { | ||
| 57 | text += QString(QObject::tr(" Axis %1%2")) | ||
| 58 | .arg(param.Get("axis", "").c_str(), param.Get("direction", "").c_str()); | ||
| 59 | } | ||
| 60 | if (param.Has("button")) { | ||
| 61 | text += QString(QObject::tr(" Button %1")).arg(param.Get("button", "").c_str()); | ||
| 62 | } | ||
| 63 | return text; | ||
| 64 | } else { | ||
| 65 | return QObject::tr("[unknown]"); | ||
| 66 | } | ||
| 67 | }; | ||
| 68 | |||
| 69 | static QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) { | ||
| 70 | if (!param.Has("engine")) { | ||
| 71 | return QObject::tr("[not set]"); | ||
| 72 | } else if (param.Get("engine", "") == "analog_from_button") { | ||
| 73 | return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); | ||
| 74 | } else if (param.Get("engine", "") == "sdl") { | ||
| 75 | if (dir == "modifier") { | ||
| 76 | return QString(QObject::tr("[unused]")); | ||
| 77 | } | ||
| 78 | |||
| 79 | QString text = QString(QObject::tr("Joystick %1")).arg(param.Get("joystick", "").c_str()); | ||
| 80 | if (dir == "left" || dir == "right") { | ||
| 81 | text += QString(QObject::tr(" Axis %1")).arg(param.Get("axis_x", "").c_str()); | ||
| 82 | } else if (dir == "up" || dir == "down") { | ||
| 83 | text += QString(QObject::tr(" Axis %1")).arg(param.Get("axis_y", "").c_str()); | ||
| 84 | } | ||
| 85 | return text; | ||
| 86 | } else { | ||
| 87 | return QObject::tr("[unknown]"); | ||
| 88 | } | ||
| 89 | }; | ||
| 90 | |||
| 45 | ConfigureInput::ConfigureInput(QWidget* parent) | 91 | ConfigureInput::ConfigureInput(QWidget* parent) |
| 46 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()), | 92 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()), |
| 47 | timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) { | 93 | timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) { |
| @@ -166,37 +212,18 @@ void ConfigureInput::restoreDefaults() { | |||
| 166 | } | 212 | } |
| 167 | 213 | ||
| 168 | void ConfigureInput::updateButtonLabels() { | 214 | void ConfigureInput::updateButtonLabels() { |
| 169 | QString non_keyboard(tr("[non-keyboard]")); | ||
| 170 | |||
| 171 | auto KeyToText = [&non_keyboard](const Common::ParamPackage& param) { | ||
| 172 | if (!param.Has("engine")) { | ||
| 173 | return QString("[not set]"); | ||
| 174 | } else if (param.Get("engine", "") != "keyboard") { | ||
| 175 | return non_keyboard; | ||
| 176 | } else { | ||
| 177 | return getKeyName(param.Get("code", 0)); | ||
| 178 | } | ||
| 179 | }; | ||
| 180 | |||
| 181 | for (int button = 0; button < Settings::NativeButton::NumButtons; button++) { | 215 | for (int button = 0; button < Settings::NativeButton::NumButtons; button++) { |
| 182 | button_map[button]->setText(KeyToText(buttons_param[button])); | 216 | button_map[button]->setText(ButtonToText(buttons_param[button])); |
| 183 | } | 217 | } |
| 184 | 218 | ||
| 185 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { | 219 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { |
| 186 | if (analogs_param[analog_id].Get("engine", "") != "analog_from_button") { | 220 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { |
| 187 | for (QPushButton* button : analog_map_buttons[analog_id]) { | 221 | if (analog_map_buttons[analog_id][sub_button_id]) { |
| 188 | if (button) | 222 | analog_map_buttons[analog_id][sub_button_id]->setText( |
| 189 | button->setText(non_keyboard); | 223 | AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id])); |
| 190 | } | ||
| 191 | } else { | ||
| 192 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { | ||
| 193 | Common::ParamPackage param( | ||
| 194 | analogs_param[analog_id].Get(analog_sub_buttons[sub_button_id], "")); | ||
| 195 | if (analog_map_buttons[analog_id][sub_button_id]) | ||
| 196 | analog_map_buttons[analog_id][sub_button_id]->setText(KeyToText(param)); | ||
| 197 | } | 224 | } |
| 198 | } | 225 | } |
| 199 | analog_map_stick[analog_id]->setText("Set Analog Stick"); | 226 | analog_map_stick[analog_id]->setText(tr("Set Analog Stick")); |
| 200 | } | 227 | } |
| 201 | } | 228 | } |
| 202 | 229 | ||