configure_input_simple: Add support for checking configuration errors
This commit is contained in:
@@ -90,8 +90,9 @@ void ApplyInputProfileConfiguration(int profile_index) {
|
|||||||
INPUT_PROFILES.at(std::min(profile_index, static_cast<int>(INPUT_PROFILES.size() - 1))))();
|
INPUT_PROFILES.at(std::min(profile_index, static_cast<int>(INPUT_PROFILES.size() - 1))))();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigureInputSimple::ConfigureInputSimple(QWidget* parent)
|
ConfigureInputSimple::ConfigureInputSimple(
|
||||||
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInputSimple>()) {
|
QWidget* parent, std::optional<Core::Frontend::ControllerParameters> constraints)
|
||||||
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInputSimple>()), constraints(constraints) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
for (const auto& profile : INPUT_PROFILES) {
|
for (const auto& profile : INPUT_PROFILES) {
|
||||||
@@ -104,6 +105,7 @@ ConfigureInputSimple::ConfigureInputSimple(QWidget* parent)
|
|||||||
connect(ui->profile_configure, &QPushButton::pressed, this, &ConfigureInputSimple::OnConfigure);
|
connect(ui->profile_configure, &QPushButton::pressed, this, &ConfigureInputSimple::OnConfigure);
|
||||||
|
|
||||||
this->loadConfiguration();
|
this->loadConfiguration();
|
||||||
|
UpdateErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigureInputSimple::~ConfigureInputSimple() = default;
|
ConfigureInputSimple::~ConfigureInputSimple() = default;
|
||||||
@@ -130,8 +132,96 @@ void ConfigureInputSimple::OnSelectProfile(int index) {
|
|||||||
const auto old_docked = Settings::values.use_docked_mode;
|
const auto old_docked = Settings::values.use_docked_mode;
|
||||||
ApplyInputProfileConfiguration(index);
|
ApplyInputProfileConfiguration(index);
|
||||||
OnDockedModeChanged(old_docked, Settings::values.use_docked_mode);
|
OnDockedModeChanged(old_docked, Settings::values.use_docked_mode);
|
||||||
|
UpdateErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureInputSimple::OnConfigure() {
|
void ConfigureInputSimple::OnConfigure() {
|
||||||
std::get<2>(INPUT_PROFILES.at(ui->profile_combobox->currentIndex()))(this);
|
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("<li>The game requires a <i>minimum</i> of %1 players, you currently have %2 "
|
||||||
|
"players.</li>")
|
||||||
|
.arg(constraints->min_players)
|
||||||
|
.arg(number_player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number_player > constraints->max_players) {
|
||||||
|
text += tr("<li>The game allows a <i>maximum</i> of %1 players, you currently have %2 "
|
||||||
|
"players.</li>")
|
||||||
|
.arg(constraints->max_players)
|
||||||
|
.arg(number_player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AnyPlayersMatchingType(Settings::ControllerType::ProController) &&
|
||||||
|
!constraints->allowed_pro_controller) {
|
||||||
|
text += tr("<li>The game does not allow the use of the <i>Pro Controller</i>.</li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AnyPlayersMatchingType(Settings::ControllerType::DualJoycon) &&
|
||||||
|
!constraints->allowed_joycon_dual) {
|
||||||
|
text += tr("<li>The game does not allow the use of <i>Dual Joycons</i>.</li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AnyPlayersMatchingType(Settings::ControllerType::LeftJoycon) &&
|
||||||
|
!constraints->allowed_joycon_left) {
|
||||||
|
text += tr("<li>The game does not allow the use of the <i>Single Left Joycon</i> "
|
||||||
|
"controller.</li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AnyPlayersMatchingType(Settings::ControllerType::RightJoycon) &&
|
||||||
|
!constraints->allowed_joycon_right) {
|
||||||
|
text += tr("<li>The game does not allow the use of the <i>Single Right Joycon</i> "
|
||||||
|
"controller.</li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings::values.players[HANDHELD_INDEX].connected && !constraints->allowed_handheld) {
|
||||||
|
text += tr("<li>The game does not allow the use of the <i>Handheld</i> Controller.</li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto has_single = AnyPlayersMatchingType(Settings::ControllerType::LeftJoycon) ||
|
||||||
|
AnyPlayersMatchingType(Settings::ControllerType::RightJoycon);
|
||||||
|
|
||||||
|
if (has_single && !constraints->allowed_single_layout) {
|
||||||
|
text += tr("<li>The game does not allow <i>single joycon</i> controllers.</li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_single && constraints->merge_dual_joycons) {
|
||||||
|
text += tr(
|
||||||
|
"<li>The game requires that pairs of <i>single joycons</i> be merged into one <i>Dual "
|
||||||
|
"Joycon</i> controller.</li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!text.isEmpty()) {
|
||||||
|
is_valid = false;
|
||||||
|
ui->error_view->setText(
|
||||||
|
"<h4 style=\"color:#CC0000;\">The following errors were identified in "
|
||||||
|
"your input configuration:</h4><ul>" +
|
||||||
|
text + "</ul>");
|
||||||
|
} else {
|
||||||
|
is_valid = true;
|
||||||
|
ui->error_view->setText(
|
||||||
|
tr("<h4 style=\"color:#00CC00;\">Your input configuration is valid.</h4>"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "core/frontend/applets/controller.h"
|
||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QString;
|
class QString;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
@@ -23,7 +26,9 @@ class ConfigureInputSimple : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ConfigureInputSimple(QWidget* parent = nullptr);
|
explicit ConfigureInputSimple(
|
||||||
|
QWidget* parent = nullptr,
|
||||||
|
std::optional<Core::Frontend::ControllerParameters> constraints = std::nullopt);
|
||||||
~ConfigureInputSimple() override;
|
~ConfigureInputSimple() override;
|
||||||
|
|
||||||
/// Save all button configurations to settings file
|
/// Save all button configurations to settings file
|
||||||
@@ -36,5 +41,9 @@ private:
|
|||||||
void OnSelectProfile(int index);
|
void OnSelectProfile(int index);
|
||||||
void OnConfigure();
|
void OnConfigure();
|
||||||
|
|
||||||
|
void UpdateErrors();
|
||||||
|
|
||||||
std::unique_ptr<Ui::ConfigureInputSimple> ui;
|
std::unique_ptr<Ui::ConfigureInputSimple> ui;
|
||||||
|
std::optional<Core::Frontend::ControllerParameters> constraints;
|
||||||
|
bool is_valid = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>473</width>
|
<width>473</width>
|
||||||
<height>685</height>
|
<height>247</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -90,6 +90,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="error_view">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>120</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|||||||
Reference in New Issue
Block a user