diff options
| author | 2020-08-27 01:46:14 -0400 | |
|---|---|---|
| committer | 2020-09-04 12:23:25 -0400 | |
| commit | aeec0f8a38cbe247bbe619a69842700208ee2d79 (patch) | |
| tree | 7d4a39490f02d6af6ac281e6fc5cd09f83ed9942 /src | |
| parent | applets/controller: Implement "Explain Text" (diff) | |
| download | yuzu-aeec0f8a38cbe247bbe619a69842700208ee2d79.tar.gz yuzu-aeec0f8a38cbe247bbe619a69842700208ee2d79.tar.xz yuzu-aeec0f8a38cbe247bbe619a69842700208ee2d79.zip | |
applets/controller: Make 8 a static constexpr value of NUM_PLAYERS
Avoids repetitive usages of the int literal '8' or calls to player_widgets.size()
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/applets/controller.cpp | 15 | ||||
| -rw-r--r-- | src/yuzu/applets/controller.h | 22 |
2 files changed, 22 insertions, 15 deletions
diff --git a/src/yuzu/applets/controller.cpp b/src/yuzu/applets/controller.cpp index 7482174c6..4783446a8 100644 --- a/src/yuzu/applets/controller.cpp +++ b/src/yuzu/applets/controller.cpp | |||
| @@ -171,14 +171,14 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 171 | ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected, | 171 | ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected, |
| 172 | }; | 172 | }; |
| 173 | 173 | ||
| 174 | for (std::size_t i = 0; i < player_widgets.size(); ++i) { | 174 | for (std::size_t i = 0; i < NUM_PLAYERS; ++i) { |
| 175 | connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) { | 175 | connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) { |
| 176 | if (checked) { | 176 | if (checked) { |
| 177 | for (std::size_t index = 0; index <= i; ++index) { | 177 | for (std::size_t index = 0; index <= i; ++index) { |
| 178 | connected_controller_checkboxes[index]->setChecked(checked); | 178 | connected_controller_checkboxes[index]->setChecked(checked); |
| 179 | } | 179 | } |
| 180 | } else { | 180 | } else { |
| 181 | for (std::size_t index = i; index < player_widgets.size(); ++index) { | 181 | for (std::size_t index = i; index < NUM_PLAYERS; ++index) { |
| 182 | connected_controller_checkboxes[index]->setChecked(checked); | 182 | connected_controller_checkboxes[index]->setChecked(checked); |
| 183 | } | 183 | } |
| 184 | } | 184 | } |
| @@ -237,6 +237,11 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 237 | QtControllerSelectorDialog::~QtControllerSelectorDialog() = default; | 237 | QtControllerSelectorDialog::~QtControllerSelectorDialog() = default; |
| 238 | 238 | ||
| 239 | void QtControllerSelectorDialog::ApplyConfiguration() { | 239 | void QtControllerSelectorDialog::ApplyConfiguration() { |
| 240 | // Update the controller state once more, just to be sure they are properly applied. | ||
| 241 | for (std::size_t index = 0; index < NUM_PLAYERS; ++index) { | ||
| 242 | UpdateControllerState(index); | ||
| 243 | } | ||
| 244 | |||
| 240 | const bool pre_docked_mode = Settings::values.use_docked_mode; | 245 | const bool pre_docked_mode = Settings::values.use_docked_mode; |
| 241 | Settings::values.use_docked_mode = ui->radioDocked->isChecked(); | 246 | Settings::values.use_docked_mode = ui->radioDocked->isChecked(); |
| 242 | OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode); | 247 | OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode); |
| @@ -281,7 +286,7 @@ void QtControllerSelectorDialog::CheckIfParametersMet() { | |||
| 281 | 286 | ||
| 282 | // Next, check against all connected controllers. | 287 | // Next, check against all connected controllers. |
| 283 | const auto all_controllers_compatible = [this] { | 288 | const auto all_controllers_compatible = [this] { |
| 284 | for (std::size_t index = 0; index < player_widgets.size(); ++index) { | 289 | for (std::size_t index = 0; index < NUM_PLAYERS; ++index) { |
| 285 | // Skip controllers that are not used, we only care about the currently connected ones. | 290 | // Skip controllers that are not used, we only care about the currently connected ones. |
| 286 | if (!player_groupboxes[index]->isChecked() || !player_groupboxes[index]->isEnabled()) { | 291 | if (!player_groupboxes[index]->isChecked() || !player_groupboxes[index]->isEnabled()) { |
| 287 | continue; | 292 | continue; |
| @@ -535,7 +540,7 @@ void QtControllerSelectorDialog::DisableUnsupportedPlayers() { | |||
| 535 | break; | 540 | break; |
| 536 | } | 541 | } |
| 537 | 542 | ||
| 538 | for (std::size_t index = max_supported_players; index < player_widgets.size(); ++index) { | 543 | for (std::size_t index = max_supported_players; index < NUM_PLAYERS; ++index) { |
| 539 | // Disconnect any unsupported players here and disable or hide them if applicable. | 544 | // Disconnect any unsupported players here and disable or hide them if applicable. |
| 540 | Settings::values.players[index].connected = false; | 545 | Settings::values.players[index].connected = false; |
| 541 | UpdateController(Settings::values.players[index].controller_type, index, false); | 546 | UpdateController(Settings::values.players[index].controller_type, index, false); |
| @@ -553,7 +558,7 @@ void QtControllerSelectorDialog::DisableUnsupportedPlayers() { | |||
| 553 | } | 558 | } |
| 554 | 559 | ||
| 555 | void QtControllerSelectorDialog::LoadConfiguration() { | 560 | void QtControllerSelectorDialog::LoadConfiguration() { |
| 556 | for (std::size_t index = 0; index < player_widgets.size(); ++index) { | 561 | for (std::size_t index = 0; index < NUM_PLAYERS; ++index) { |
| 557 | const auto connected = Settings::values.players[index].connected || | 562 | const auto connected = Settings::values.players[index].connected || |
| 558 | (index == 0 && Settings::values.players[8].connected); | 563 | (index == 0 && Settings::values.players[8].connected); |
| 559 | player_groupboxes[index]->setChecked(connected); | 564 | player_groupboxes[index]->setChecked(connected); |
diff --git a/src/yuzu/applets/controller.h b/src/yuzu/applets/controller.h index db59dd631..6ab4bea09 100644 --- a/src/yuzu/applets/controller.h +++ b/src/yuzu/applets/controller.h | |||
| @@ -79,36 +79,38 @@ private: | |||
| 79 | InputCommon::InputSubsystem* input_subsystem; | 79 | InputCommon::InputSubsystem* input_subsystem; |
| 80 | 80 | ||
| 81 | // This is true if and only if all parameters are met. Otherwise, this is false. | 81 | // This is true if and only if all parameters are met. Otherwise, this is false. |
| 82 | // This determines whether the "Ok" button can be clicked to exit the applet. | 82 | // This determines whether the "OK" button can be clicked to exit the applet. |
| 83 | bool parameters_met{false}; | 83 | bool parameters_met{false}; |
| 84 | 84 | ||
| 85 | static constexpr std::size_t NUM_PLAYERS = 8; | ||
| 86 | |||
| 85 | // Widgets encapsulating the groupboxes and comboboxes per player. | 87 | // Widgets encapsulating the groupboxes and comboboxes per player. |
| 86 | std::array<QWidget*, 8> player_widgets; | 88 | std::array<QWidget*, NUM_PLAYERS> player_widgets; |
| 87 | 89 | ||
| 88 | // Groupboxes encapsulating the controller icons and LED patterns per player. | 90 | // Groupboxes encapsulating the controller icons and LED patterns per player. |
| 89 | std::array<QGroupBox*, 8> player_groupboxes; | 91 | std::array<QGroupBox*, NUM_PLAYERS> player_groupboxes; |
| 90 | 92 | ||
| 91 | // Icons for currently connected controllers/players. | 93 | // Icons for currently connected controllers/players. |
| 92 | std::array<QWidget*, 8> connected_controller_icons; | 94 | std::array<QWidget*, NUM_PLAYERS> connected_controller_icons; |
| 93 | 95 | ||
| 94 | // Labels that represent the player numbers in place of the controller icons. | 96 | // Labels that represent the player numbers in place of the controller icons. |
| 95 | std::array<QLabel*, 8> player_labels; | 97 | std::array<QLabel*, NUM_PLAYERS> player_labels; |
| 96 | 98 | ||
| 97 | // LED patterns for currently connected controllers/players. | 99 | // LED patterns for currently connected controllers/players. |
| 98 | std::array<std::array<QCheckBox*, 4>, 8> led_patterns_boxes; | 100 | std::array<std::array<QCheckBox*, 4>, NUM_PLAYERS> led_patterns_boxes; |
| 99 | 101 | ||
| 100 | // Labels representing additional information known as "Explain Text" per player. | 102 | // Labels representing additional information known as "Explain Text" per player. |
| 101 | std::array<QLabel*, 8> explain_text_labels; | 103 | std::array<QLabel*, NUM_PLAYERS> explain_text_labels; |
| 102 | 104 | ||
| 103 | // Comboboxes with a list of emulated controllers per player. | 105 | // Comboboxes with a list of emulated controllers per player. |
| 104 | std::array<QComboBox*, 8> emulated_controllers; | 106 | std::array<QComboBox*, NUM_PLAYERS> emulated_controllers; |
| 105 | 107 | ||
| 106 | // Labels representing the number of connected controllers | 108 | // Labels representing the number of connected controllers |
| 107 | // above the "Connected Controllers" checkboxes. | 109 | // above the "Connected Controllers" checkboxes. |
| 108 | std::array<QLabel*, 8> connected_controller_labels; | 110 | std::array<QLabel*, NUM_PLAYERS> connected_controller_labels; |
| 109 | 111 | ||
| 110 | // Checkboxes representing the "Connected Controllers". | 112 | // Checkboxes representing the "Connected Controllers". |
| 111 | std::array<QCheckBox*, 8> connected_controller_checkboxes; | 113 | std::array<QCheckBox*, NUM_PLAYERS> connected_controller_checkboxes; |
| 112 | }; | 114 | }; |
| 113 | 115 | ||
| 114 | class QtControllerSelector final : public QObject, public Core::Frontend::ControllerApplet { | 116 | class QtControllerSelector final : public QObject, public Core::Frontend::ControllerApplet { |