applets/controller: Auto accept a valid single player configuration

This commit is contained in:
Morph 2020-09-27 11:18:07 -04:00
parent 484623cd61
commit 5cafa70d3b
3 changed files with 24 additions and 14 deletions

View File

@ -229,6 +229,13 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, connect(ui->buttonBox, &QDialogButtonBox::accepted, this,
&QtControllerSelectorDialog::ApplyConfiguration); &QtControllerSelectorDialog::ApplyConfiguration);
// Enhancement: Check if the parameters have already been met before disconnecting controllers.
// If all the parameters are met AND only allows a single player,
// stop the constructor here as we do not need to continue.
if (CheckIfParametersMet() && parameters.enable_single_mode) {
return;
}
// If keep_controllers_connected is false, forcefully disconnect all controllers // If keep_controllers_connected is false, forcefully disconnect all controllers
if (!parameters.keep_controllers_connected) { if (!parameters.keep_controllers_connected) {
for (auto player : player_groupboxes) { for (auto player : player_groupboxes) {
@ -236,13 +243,18 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
} }
} }
CheckIfParametersMet();
resize(0, 0); resize(0, 0);
} }
QtControllerSelectorDialog::~QtControllerSelectorDialog() = default; QtControllerSelectorDialog::~QtControllerSelectorDialog() = default;
int QtControllerSelectorDialog::exec() {
if (parameters_met && parameters.enable_single_mode) {
return QDialog::Accepted;
}
return QDialog::exec();
}
void QtControllerSelectorDialog::ApplyConfiguration() { void QtControllerSelectorDialog::ApplyConfiguration() {
// Update the controller state once more, just to be sure they are properly applied. // Update the controller state once more, just to be sure they are properly applied.
for (std::size_t index = 0; index < NUM_PLAYERS; ++index) { for (std::size_t index = 0; index < NUM_PLAYERS; ++index) {
@ -287,7 +299,7 @@ void QtControllerSelectorDialog::CallConfigureInputDialog() {
CheckIfParametersMet(); CheckIfParametersMet();
} }
void QtControllerSelectorDialog::CheckIfParametersMet() { bool QtControllerSelectorDialog::CheckIfParametersMet() {
// Here, we check and validate the current configuration against all applicable parameters. // Here, we check and validate the current configuration against all applicable parameters.
const auto num_connected_players = static_cast<int>( const auto num_connected_players = static_cast<int>(
std::count_if(player_groupboxes.begin(), player_groupboxes.end(), std::count_if(player_groupboxes.begin(), player_groupboxes.end(),
@ -301,7 +313,7 @@ void QtControllerSelectorDialog::CheckIfParametersMet() {
num_connected_players > max_supported_players) { num_connected_players > max_supported_players) {
parameters_met = false; parameters_met = false;
ui->buttonBox->setEnabled(parameters_met); ui->buttonBox->setEnabled(parameters_met);
return; return parameters_met;
} }
// Next, check against all connected controllers. // Next, check against all connected controllers.
@ -326,14 +338,9 @@ void QtControllerSelectorDialog::CheckIfParametersMet() {
return true; return true;
}(); }();
if (!all_controllers_compatible) { parameters_met = all_controllers_compatible;
parameters_met = false;
ui->buttonBox->setEnabled(parameters_met);
return;
}
parameters_met = true;
ui->buttonBox->setEnabled(parameters_met); ui->buttonBox->setEnabled(parameters_met);
return parameters_met;
} }
void QtControllerSelectorDialog::SetSupportedControllers() { void QtControllerSelectorDialog::SetSupportedControllers() {

View File

@ -33,6 +33,8 @@ public:
InputCommon::InputSubsystem* input_subsystem_); InputCommon::InputSubsystem* input_subsystem_);
~QtControllerSelectorDialog() override; ~QtControllerSelectorDialog() override;
int exec() override;
private: private:
// Applies the current configuration. // Applies the current configuration.
void ApplyConfiguration(); void ApplyConfiguration();
@ -43,9 +45,9 @@ private:
// Initializes the "Configure Input" Dialog. // Initializes the "Configure Input" Dialog.
void CallConfigureInputDialog(); void CallConfigureInputDialog();
// Checks the current configuration against the given parameters and // Checks the current configuration against the given parameters.
// sets the value of parameters_met. // This sets and returns the value of parameters_met.
void CheckIfParametersMet(); bool CheckIfParametersMet();
// Sets the controller icons for "Supported Controller Types". // Sets the controller icons for "Supported Controller Types".
void SetSupportedControllers(); void SetSupportedControllers();

View File

@ -288,6 +288,7 @@ GMainWindow::~GMainWindow() {
void GMainWindow::ControllerSelectorReconfigureControllers( void GMainWindow::ControllerSelectorReconfigureControllers(
const Core::Frontend::ControllerParameters& parameters) { const Core::Frontend::ControllerParameters& parameters) {
QtControllerSelectorDialog dialog(this, parameters, input_subsystem.get()); QtControllerSelectorDialog dialog(this, parameters, input_subsystem.get());
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint |
Qt::WindowTitleHint | Qt::WindowSystemMenuHint); Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);