From 0f82eb83f92e356808115387ce18653994a4bde2 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 24 Dec 2018 17:35:18 -0500 Subject: [PATCH] configure_input_simple: Add support for checking configuration errors --- .../configuration/configure_input_simple.cpp | 94 ++++++++++++++++++- .../configuration/configure_input_simple.h | 11 ++- .../configuration/configure_input_simple.ui | 12 ++- 3 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/yuzu/configuration/configure_input_simple.cpp b/src/yuzu/configuration/configure_input_simple.cpp index 07d71e9d18..75fad9954a 100644 --- a/src/yuzu/configuration/configure_input_simple.cpp +++ b/src/yuzu/configuration/configure_input_simple.cpp @@ -90,8 +90,9 @@ void ApplyInputProfileConfiguration(int profile_index) { INPUT_PROFILES.at(std::min(profile_index, static_cast(INPUT_PROFILES.size() - 1))))(); } -ConfigureInputSimple::ConfigureInputSimple(QWidget* parent) - : QWidget(parent), ui(std::make_unique()) { +ConfigureInputSimple::ConfigureInputSimple( + QWidget* parent, std::optional constraints) + : QWidget(parent), ui(std::make_unique()), constraints(constraints) { ui->setupUi(this); for (const auto& profile : INPUT_PROFILES) { @@ -104,6 +105,7 @@ ConfigureInputSimple::ConfigureInputSimple(QWidget* parent) connect(ui->profile_configure, &QPushButton::pressed, this, &ConfigureInputSimple::OnConfigure); this->loadConfiguration(); + UpdateErrors(); } ConfigureInputSimple::~ConfigureInputSimple() = default; @@ -130,8 +132,96 @@ void ConfigureInputSimple::OnSelectProfile(int index) { const auto old_docked = Settings::values.use_docked_mode; ApplyInputProfileConfiguration(index); OnDockedModeChanged(old_docked, Settings::values.use_docked_mode); + UpdateErrors(); } void ConfigureInputSimple::OnConfigure() { std::get<2>(INPUT_PROFILES.at(ui->profile_combobox->currentIndex()))(this); + UpdateErrors(); +} + +static bool AnyPlayersMatchingType(Settings::ControllerType type) { + return std::any_of( + Settings::values.players.begin(), Settings::values.players.begin() + 8, + [type](const Settings::PlayerInput& in) { return in.type == type && in.connected; }); +} + +void ConfigureInputSimple::UpdateErrors() { + if (constraints == std::nullopt) { + ui->error_view->setHidden(true); + return; + } + + ui->error_view->setHidden(false); + + QString text; + + const auto number_player = + std::count_if(Settings::values.players.begin(), Settings::values.players.begin() + 9, + [](const Settings::PlayerInput& in) { return in.connected; }); + + if (number_player < constraints->min_players) { + text += tr("
  • The game requires a minimum of %1 players, you currently have %2 " + "players.
  • ") + .arg(constraints->min_players) + .arg(number_player); + } + + if (number_player > constraints->max_players) { + text += tr("
  • The game allows a maximum of %1 players, you currently have %2 " + "players.
  • ") + .arg(constraints->max_players) + .arg(number_player); + } + + if (AnyPlayersMatchingType(Settings::ControllerType::ProController) && + !constraints->allowed_pro_controller) { + text += tr("
  • The game does not allow the use of the Pro Controller.
  • "); + } + + if (AnyPlayersMatchingType(Settings::ControllerType::DualJoycon) && + !constraints->allowed_joycon_dual) { + text += tr("
  • The game does not allow the use of Dual Joycons.
  • "); + } + + if (AnyPlayersMatchingType(Settings::ControllerType::LeftJoycon) && + !constraints->allowed_joycon_left) { + text += tr("
  • The game does not allow the use of the Single Left Joycon " + "controller.
  • "); + } + + if (AnyPlayersMatchingType(Settings::ControllerType::RightJoycon) && + !constraints->allowed_joycon_right) { + text += tr("
  • The game does not allow the use of the Single Right Joycon " + "controller.
  • "); + } + + if (Settings::values.players[HANDHELD_INDEX].connected && !constraints->allowed_handheld) { + text += tr("
  • The game does not allow the use of the Handheld Controller.
  • "); + } + + const auto has_single = AnyPlayersMatchingType(Settings::ControllerType::LeftJoycon) || + AnyPlayersMatchingType(Settings::ControllerType::RightJoycon); + + if (has_single && !constraints->allowed_single_layout) { + text += tr("
  • The game does not allow single joycon controllers.
  • "); + } + + if (has_single && constraints->merge_dual_joycons) { + text += tr( + "
  • The game requires that pairs of single joycons be merged into one Dual " + "Joycon controller.
  • "); + } + + if (!text.isEmpty()) { + is_valid = false; + ui->error_view->setText( + "

    The following errors were identified in " + "your input configuration:

      " + + text + "
    "); + } else { + is_valid = true; + ui->error_view->setText( + tr("

    Your input configuration is valid.

    ")); + } } diff --git a/src/yuzu/configuration/configure_input_simple.h b/src/yuzu/configuration/configure_input_simple.h index 5b6b699948..aa644558a0 100644 --- a/src/yuzu/configuration/configure_input_simple.h +++ b/src/yuzu/configuration/configure_input_simple.h @@ -5,9 +5,12 @@ #pragma once #include +#include #include +#include "core/frontend/applets/controller.h" + class QPushButton; class QString; class QTimer; @@ -23,7 +26,9 @@ class ConfigureInputSimple : public QWidget { Q_OBJECT public: - explicit ConfigureInputSimple(QWidget* parent = nullptr); + explicit ConfigureInputSimple( + QWidget* parent = nullptr, + std::optional constraints = std::nullopt); ~ConfigureInputSimple() override; /// Save all button configurations to settings file @@ -36,5 +41,9 @@ private: void OnSelectProfile(int index); void OnConfigure(); + void UpdateErrors(); + std::unique_ptr ui; + std::optional constraints; + bool is_valid = true; }; diff --git a/src/yuzu/configuration/configure_input_simple.ui b/src/yuzu/configuration/configure_input_simple.ui index c4889caa99..651d70d6c6 100644 --- a/src/yuzu/configuration/configure_input_simple.ui +++ b/src/yuzu/configuration/configure_input_simple.ui @@ -7,7 +7,7 @@ 0 0 473 - 685 + 247 @@ -90,6 +90,16 @@ + + + + + 16777215 + 120 + + + +