diff options
| author | 2019-05-19 12:08:48 -0400 | |
|---|---|---|
| committer | 2019-05-19 12:34:15 -0400 | |
| commit | aa83639b783145b35e4f8f3abcf6a568c85b4fa9 (patch) | |
| tree | b435eeeb73f9b2acf9fda0b2e61f5ff1ac4cd008 /src | |
| parent | yuzu/configuration/configure_input_player: Specify string conversions explicitly (diff) | |
| download | yuzu-aa83639b783145b35e4f8f3abcf6a568c85b4fa9.tar.gz yuzu-aa83639b783145b35e4f8f3abcf6a568c85b4fa9.tar.xz yuzu-aa83639b783145b35e4f8f3abcf6a568c85b4fa9.zip | |
yuzu/configuration/configure_input_player: Clean up array accesses
Rather than repeatedly index arrays that have quite a large array index,
we can just use a named variable instead.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 80 |
1 files changed, 48 insertions, 32 deletions
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 62a68d912..95b0a656a 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -238,38 +238,42 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 238 | analog_map_stick = {ui->buttonLStickAnalog, ui->buttonRStickAnalog}; | 238 | analog_map_stick = {ui->buttonLStickAnalog, ui->buttonRStickAnalog}; |
| 239 | 239 | ||
| 240 | for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { | 240 | for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { |
| 241 | if (!button_map[button_id]) | 241 | auto* const button = button_map[button_id]; |
| 242 | if (button == nullptr) { | ||
| 242 | continue; | 243 | continue; |
| 243 | button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); | 244 | } |
| 244 | connect(button_map[button_id], &QPushButton::released, [=]() { | 245 | |
| 246 | button->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 247 | connect(button, &QPushButton::released, [=] { | ||
| 245 | handleClick( | 248 | handleClick( |
| 246 | button_map[button_id], | 249 | button_map[button_id], |
| 247 | [=](const Common::ParamPackage& params) { buttons_param[button_id] = params; }, | 250 | [=](const Common::ParamPackage& params) { buttons_param[button_id] = params; }, |
| 248 | InputCommon::Polling::DeviceType::Button); | 251 | InputCommon::Polling::DeviceType::Button); |
| 249 | }); | 252 | }); |
| 250 | connect(button_map[button_id], &QPushButton::customContextMenuRequested, | 253 | connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { |
| 251 | [=](const QPoint& menu_location) { | 254 | QMenu context_menu; |
| 252 | QMenu context_menu; | 255 | context_menu.addAction(tr("Clear"), [&] { |
| 253 | context_menu.addAction(tr("Clear"), [&] { | 256 | buttons_param[button_id].Clear(); |
| 254 | buttons_param[button_id].Clear(); | 257 | button_map[button_id]->setText(tr("[not set]")); |
| 255 | button_map[button_id]->setText(tr("[not set]")); | 258 | }); |
| 256 | }); | 259 | context_menu.addAction(tr("Restore Default"), [&] { |
| 257 | context_menu.addAction(tr("Restore Default"), [&] { | 260 | buttons_param[button_id] = Common::ParamPackage{ |
| 258 | buttons_param[button_id] = Common::ParamPackage{ | 261 | InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; |
| 259 | InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; | 262 | button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); |
| 260 | button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); | 263 | }); |
| 261 | }); | 264 | context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); |
| 262 | context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); | 265 | }); |
| 263 | }); | ||
| 264 | } | 266 | } |
| 265 | 267 | ||
| 266 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { | 268 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { |
| 267 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { | 269 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { |
| 268 | if (!analog_map_buttons[analog_id][sub_button_id]) | 270 | auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; |
| 271 | if (analog_button == nullptr) { | ||
| 269 | continue; | 272 | continue; |
| 270 | analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( | 273 | } |
| 271 | Qt::CustomContextMenu); | 274 | |
| 272 | connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { | 275 | analog_button->setContextMenuPolicy(Qt::CustomContextMenu); |
| 276 | connect(analog_button, &QPushButton::released, [=]() { | ||
| 273 | handleClick(analog_map_buttons[analog_id][sub_button_id], | 277 | handleClick(analog_map_buttons[analog_id][sub_button_id], |
| 274 | [=](const Common::ParamPackage& params) { | 278 | [=](const Common::ParamPackage& params) { |
| 275 | SetAnalogButton(params, analogs_param[analog_id], | 279 | SetAnalogButton(params, analogs_param[analog_id], |
| @@ -277,8 +281,8 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 277 | }, | 281 | }, |
| 278 | InputCommon::Polling::DeviceType::Button); | 282 | InputCommon::Polling::DeviceType::Button); |
| 279 | }); | 283 | }); |
| 280 | connect(analog_map_buttons[analog_id][sub_button_id], | 284 | connect(analog_button, &QPushButton::customContextMenuRequested, |
| 281 | &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { | 285 | [=](const QPoint& menu_location) { |
| 282 | QMenu context_menu; | 286 | QMenu context_menu; |
| 283 | context_menu.addAction(tr("Clear"), [&] { | 287 | context_menu.addAction(tr("Clear"), [&] { |
| 284 | analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); | 288 | analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); |
| @@ -296,7 +300,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 296 | menu_location)); | 300 | menu_location)); |
| 297 | }); | 301 | }); |
| 298 | } | 302 | } |
| 299 | connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { | 303 | connect(analog_map_stick[analog_id], &QPushButton::released, [=] { |
| 300 | QMessageBox::information(this, tr("Information"), | 304 | QMessageBox::information(this, tr("Information"), |
| 301 | tr("After pressing OK, first move your joystick horizontally, " | 305 | tr("After pressing OK, first move your joystick horizontally, " |
| 302 | "and then vertically.")); | 306 | "and then vertically.")); |
| @@ -435,14 +439,22 @@ void ConfigureInputPlayer::restoreDefaults() { | |||
| 435 | 439 | ||
| 436 | void ConfigureInputPlayer::ClearAll() { | 440 | void ConfigureInputPlayer::ClearAll() { |
| 437 | for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { | 441 | for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { |
| 438 | if (button_map[button_id] && button_map[button_id]->isEnabled()) | 442 | const auto* const button = button_map[button_id]; |
| 439 | buttons_param[button_id].Clear(); | 443 | if (button == nullptr || !button->isEnabled()) { |
| 444 | continue; | ||
| 445 | } | ||
| 446 | |||
| 447 | buttons_param[button_id].Clear(); | ||
| 440 | } | 448 | } |
| 449 | |||
| 441 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { | 450 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { |
| 442 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { | 451 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { |
| 443 | if (analog_map_buttons[analog_id][sub_button_id] && | 452 | const auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; |
| 444 | analog_map_buttons[analog_id][sub_button_id]->isEnabled()) | 453 | if (analog_button == nullptr || !analog_button->isEnabled()) { |
| 445 | analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); | 454 | continue; |
| 455 | } | ||
| 456 | |||
| 457 | analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); | ||
| 446 | } | 458 | } |
| 447 | } | 459 | } |
| 448 | 460 | ||
| @@ -456,10 +468,14 @@ void ConfigureInputPlayer::updateButtonLabels() { | |||
| 456 | 468 | ||
| 457 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { | 469 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { |
| 458 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { | 470 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { |
| 459 | if (analog_map_buttons[analog_id][sub_button_id]) { | 471 | auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; |
| 460 | analog_map_buttons[analog_id][sub_button_id]->setText( | 472 | |
| 461 | AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id])); | 473 | if (analog_button == nullptr) { |
| 474 | continue; | ||
| 462 | } | 475 | } |
| 476 | |||
| 477 | analog_button->setText( | ||
| 478 | AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id])); | ||
| 463 | } | 479 | } |
| 464 | analog_map_stick[analog_id]->setText(tr("Set Analog Stick")); | 480 | analog_map_stick[analog_id]->setText(tr("Set Analog Stick")); |
| 465 | } | 481 | } |