mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-23 13:35:38 +01:00
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()
This commit is contained in:
parent
5ce3015945
commit
aeec0f8a38
@ -171,14 +171,14 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
|
|||||||
ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected,
|
ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (std::size_t i = 0; i < player_widgets.size(); ++i) {
|
for (std::size_t i = 0; i < NUM_PLAYERS; ++i) {
|
||||||
connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) {
|
connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
for (std::size_t index = 0; index <= i; ++index) {
|
for (std::size_t index = 0; index <= i; ++index) {
|
||||||
connected_controller_checkboxes[index]->setChecked(checked);
|
connected_controller_checkboxes[index]->setChecked(checked);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (std::size_t index = i; index < player_widgets.size(); ++index) {
|
for (std::size_t index = i; index < NUM_PLAYERS; ++index) {
|
||||||
connected_controller_checkboxes[index]->setChecked(checked);
|
connected_controller_checkboxes[index]->setChecked(checked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,6 +237,11 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
|
|||||||
QtControllerSelectorDialog::~QtControllerSelectorDialog() = default;
|
QtControllerSelectorDialog::~QtControllerSelectorDialog() = default;
|
||||||
|
|
||||||
void QtControllerSelectorDialog::ApplyConfiguration() {
|
void QtControllerSelectorDialog::ApplyConfiguration() {
|
||||||
|
// Update the controller state once more, just to be sure they are properly applied.
|
||||||
|
for (std::size_t index = 0; index < NUM_PLAYERS; ++index) {
|
||||||
|
UpdateControllerState(index);
|
||||||
|
}
|
||||||
|
|
||||||
const bool pre_docked_mode = Settings::values.use_docked_mode;
|
const bool pre_docked_mode = Settings::values.use_docked_mode;
|
||||||
Settings::values.use_docked_mode = ui->radioDocked->isChecked();
|
Settings::values.use_docked_mode = ui->radioDocked->isChecked();
|
||||||
OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode);
|
OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode);
|
||||||
@ -281,7 +286,7 @@ void QtControllerSelectorDialog::CheckIfParametersMet() {
|
|||||||
|
|
||||||
// Next, check against all connected controllers.
|
// Next, check against all connected controllers.
|
||||||
const auto all_controllers_compatible = [this] {
|
const auto all_controllers_compatible = [this] {
|
||||||
for (std::size_t index = 0; index < player_widgets.size(); ++index) {
|
for (std::size_t index = 0; index < NUM_PLAYERS; ++index) {
|
||||||
// Skip controllers that are not used, we only care about the currently connected ones.
|
// Skip controllers that are not used, we only care about the currently connected ones.
|
||||||
if (!player_groupboxes[index]->isChecked() || !player_groupboxes[index]->isEnabled()) {
|
if (!player_groupboxes[index]->isChecked() || !player_groupboxes[index]->isEnabled()) {
|
||||||
continue;
|
continue;
|
||||||
@ -535,7 +540,7 @@ void QtControllerSelectorDialog::DisableUnsupportedPlayers() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = max_supported_players; index < player_widgets.size(); ++index) {
|
for (std::size_t index = max_supported_players; index < NUM_PLAYERS; ++index) {
|
||||||
// Disconnect any unsupported players here and disable or hide them if applicable.
|
// Disconnect any unsupported players here and disable or hide them if applicable.
|
||||||
Settings::values.players[index].connected = false;
|
Settings::values.players[index].connected = false;
|
||||||
UpdateController(Settings::values.players[index].controller_type, index, false);
|
UpdateController(Settings::values.players[index].controller_type, index, false);
|
||||||
@ -553,7 +558,7 @@ void QtControllerSelectorDialog::DisableUnsupportedPlayers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QtControllerSelectorDialog::LoadConfiguration() {
|
void QtControllerSelectorDialog::LoadConfiguration() {
|
||||||
for (std::size_t index = 0; index < player_widgets.size(); ++index) {
|
for (std::size_t index = 0; index < NUM_PLAYERS; ++index) {
|
||||||
const auto connected = Settings::values.players[index].connected ||
|
const auto connected = Settings::values.players[index].connected ||
|
||||||
(index == 0 && Settings::values.players[8].connected);
|
(index == 0 && Settings::values.players[8].connected);
|
||||||
player_groupboxes[index]->setChecked(connected);
|
player_groupboxes[index]->setChecked(connected);
|
||||||
|
@ -79,36 +79,38 @@ private:
|
|||||||
InputCommon::InputSubsystem* input_subsystem;
|
InputCommon::InputSubsystem* input_subsystem;
|
||||||
|
|
||||||
// This is true if and only if all parameters are met. Otherwise, this is false.
|
// This is true if and only if all parameters are met. Otherwise, this is false.
|
||||||
// This determines whether the "Ok" button can be clicked to exit the applet.
|
// This determines whether the "OK" button can be clicked to exit the applet.
|
||||||
bool parameters_met{false};
|
bool parameters_met{false};
|
||||||
|
|
||||||
|
static constexpr std::size_t NUM_PLAYERS = 8;
|
||||||
|
|
||||||
// Widgets encapsulating the groupboxes and comboboxes per player.
|
// Widgets encapsulating the groupboxes and comboboxes per player.
|
||||||
std::array<QWidget*, 8> player_widgets;
|
std::array<QWidget*, NUM_PLAYERS> player_widgets;
|
||||||
|
|
||||||
// Groupboxes encapsulating the controller icons and LED patterns per player.
|
// Groupboxes encapsulating the controller icons and LED patterns per player.
|
||||||
std::array<QGroupBox*, 8> player_groupboxes;
|
std::array<QGroupBox*, NUM_PLAYERS> player_groupboxes;
|
||||||
|
|
||||||
// Icons for currently connected controllers/players.
|
// Icons for currently connected controllers/players.
|
||||||
std::array<QWidget*, 8> connected_controller_icons;
|
std::array<QWidget*, NUM_PLAYERS> connected_controller_icons;
|
||||||
|
|
||||||
// Labels that represent the player numbers in place of the controller icons.
|
// Labels that represent the player numbers in place of the controller icons.
|
||||||
std::array<QLabel*, 8> player_labels;
|
std::array<QLabel*, NUM_PLAYERS> player_labels;
|
||||||
|
|
||||||
// LED patterns for currently connected controllers/players.
|
// LED patterns for currently connected controllers/players.
|
||||||
std::array<std::array<QCheckBox*, 4>, 8> led_patterns_boxes;
|
std::array<std::array<QCheckBox*, 4>, NUM_PLAYERS> led_patterns_boxes;
|
||||||
|
|
||||||
// Labels representing additional information known as "Explain Text" per player.
|
// Labels representing additional information known as "Explain Text" per player.
|
||||||
std::array<QLabel*, 8> explain_text_labels;
|
std::array<QLabel*, NUM_PLAYERS> explain_text_labels;
|
||||||
|
|
||||||
// Comboboxes with a list of emulated controllers per player.
|
// Comboboxes with a list of emulated controllers per player.
|
||||||
std::array<QComboBox*, 8> emulated_controllers;
|
std::array<QComboBox*, NUM_PLAYERS> emulated_controllers;
|
||||||
|
|
||||||
// Labels representing the number of connected controllers
|
// Labels representing the number of connected controllers
|
||||||
// above the "Connected Controllers" checkboxes.
|
// above the "Connected Controllers" checkboxes.
|
||||||
std::array<QLabel*, 8> connected_controller_labels;
|
std::array<QLabel*, NUM_PLAYERS> connected_controller_labels;
|
||||||
|
|
||||||
// Checkboxes representing the "Connected Controllers".
|
// Checkboxes representing the "Connected Controllers".
|
||||||
std::array<QCheckBox*, 8> connected_controller_checkboxes;
|
std::array<QCheckBox*, NUM_PLAYERS> connected_controller_checkboxes;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QtControllerSelector final : public QObject, public Core::Frontend::ControllerApplet {
|
class QtControllerSelector final : public QObject, public Core::Frontend::ControllerApplet {
|
||||||
|
Loading…
Reference in New Issue
Block a user