1
0
Fork 0
forked from suyu/suyu

Merge pull request #11144 from flodavid/master

Enable controller interaction in Controller Applet
This commit is contained in:
liamwhite 2023-10-11 09:23:52 -04:00 committed by GitHub
commit b50ce645ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 104 additions and 7 deletions

View file

@ -120,6 +120,10 @@ QWidget#connectedControllers {
background: transparent; background: transparent;
} }
QWidget#closeButtons {
background: transparent;
}
QWidget#playersSupported, QWidget#playersSupported,
QWidget#controllersSupported, QWidget#controllersSupported,
QWidget#controllerSupported1, QWidget#controllerSupported1,

View file

@ -1380,6 +1380,10 @@ QWidget#connectedControllers {
background: transparent; background: transparent;
} }
QWidget#closeButtons {
background: transparent;
}
QWidget#playersSupported, QWidget#playersSupported,
QWidget#controllersSupported, QWidget#controllersSupported,
QWidget#controllerSupported1, QWidget#controllerSupported1,

View file

@ -2305,6 +2305,10 @@ QWidget#connectedControllers {
background: transparent; background: transparent;
} }
QWidget#closeButtons {
background: transparent;
}
QWidget#playersSupported, QWidget#playersSupported,
QWidget#controllersSupported, QWidget#controllersSupported,
QWidget#controllerSupported1, QWidget#controllerSupported1,

View file

@ -23,6 +23,7 @@
#include "yuzu/configuration/configure_vibration.h" #include "yuzu/configuration/configure_vibration.h"
#include "yuzu/configuration/input_profiles.h" #include "yuzu/configuration/input_profiles.h"
#include "yuzu/main.h" #include "yuzu/main.h"
#include "yuzu/util/controller_navigation.h"
namespace { namespace {
@ -132,6 +133,8 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected, ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected,
}; };
ui->labelError->setVisible(false);
// Setup/load everything prior to setting up connections. // Setup/load everything prior to setting up connections.
// This avoids unintentionally changing the states of elements while loading them in. // This avoids unintentionally changing the states of elements while loading them in.
SetSupportedControllers(); SetSupportedControllers();
@ -143,6 +146,8 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
LoadConfiguration(); LoadConfiguration();
controller_navigation = new ControllerNavigation(system.HIDCore(), this);
for (std::size_t i = 0; i < NUM_PLAYERS; ++i) { for (std::size_t i = 0; i < NUM_PLAYERS; ++i) {
SetExplainText(i); SetExplainText(i);
UpdateControllerIcon(i); UpdateControllerIcon(i);
@ -151,6 +156,8 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) { connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) {
if (checked) { if (checked) {
// Hide eventual error message about number of controllers
ui->labelError->setVisible(false);
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);
} }
@ -199,6 +206,12 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, connect(ui->buttonBox, &QDialogButtonBox::accepted, this,
&QtControllerSelectorDialog::ApplyConfiguration); &QtControllerSelectorDialog::ApplyConfiguration);
connect(controller_navigation, &ControllerNavigation::TriggerKeyboardEvent,
[this](Qt::Key key) {
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier);
QCoreApplication::postEvent(this, event);
});
// Enhancement: Check if the parameters have already been met before disconnecting controllers. // Enhancement: Check if the parameters have already been met before disconnecting controllers.
// If all the parameters are met AND only allows a single player, // If all the parameters are met AND only allows a single player,
// stop the constructor here as we do not need to continue. // stop the constructor here as we do not need to continue.
@ -217,6 +230,7 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
} }
QtControllerSelectorDialog::~QtControllerSelectorDialog() { QtControllerSelectorDialog::~QtControllerSelectorDialog() {
controller_navigation->UnloadController();
system.HIDCore().DisableAllControllerConfiguration(); system.HIDCore().DisableAllControllerConfiguration();
} }
@ -291,6 +305,31 @@ void QtControllerSelectorDialog::CallConfigureInputProfileDialog() {
dialog.exec(); dialog.exec();
} }
void QtControllerSelectorDialog::keyPressEvent(QKeyEvent* evt) {
const auto num_connected_players = static_cast<int>(
std::count_if(player_groupboxes.begin(), player_groupboxes.end(),
[](const QGroupBox* player) { return player->isChecked(); }));
const auto min_supported_players = parameters.enable_single_mode ? 1 : parameters.min_players;
const auto max_supported_players = parameters.enable_single_mode ? 1 : parameters.max_players;
if ((evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) && !parameters_met) {
// Display error message when trying to validate using "Enter" and "OK" button is disabled
ui->labelError->setVisible(true);
return;
} else if (evt->key() == Qt::Key_Left && num_connected_players > min_supported_players) {
// Remove a player if possible
connected_controller_checkboxes[num_connected_players - 1]->setChecked(false);
return;
} else if (evt->key() == Qt::Key_Right && num_connected_players < max_supported_players) {
// Add a player, if possible
ui->labelError->setVisible(false);
connected_controller_checkboxes[num_connected_players]->setChecked(true);
return;
}
QDialog::keyPressEvent(evt);
}
bool 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>(

View file

@ -34,6 +34,8 @@ class HIDCore;
enum class NpadStyleIndex : u8; enum class NpadStyleIndex : u8;
} // namespace Core::HID } // namespace Core::HID
class ControllerNavigation;
class QtControllerSelectorDialog final : public QDialog { class QtControllerSelectorDialog final : public QDialog {
Q_OBJECT Q_OBJECT
@ -46,6 +48,8 @@ public:
int exec() override; int exec() override;
void keyPressEvent(QKeyEvent* evt) override;
private: private:
// Applies the current configuration. // Applies the current configuration.
void ApplyConfiguration(); void ApplyConfiguration();
@ -110,6 +114,8 @@ private:
Core::System& system; Core::System& system;
ControllerNavigation* controller_navigation = nullptr;
// 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};

View file

@ -2624,13 +2624,53 @@
</spacer> </spacer>
</item> </item>
<item alignment="Qt::AlignBottom"> <item alignment="Qt::AlignBottom">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QWidget" name="closeButtons" native="true">
<property name="enabled"> <layout class="QVBoxLayout" name="verticalLayout_46">
<bool>true</bool> <property name="spacing">
</property> <number>7</number>
<property name="standardButtons"> </property>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <property name="leftMargin">
</property> <number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelError">
<property name="enabled">
<bool>true</bool>
</property>
<property name="styleSheet">
<string notr="true">QLabel { color : red; }</string>
</property>
<property name="text">
<string>Not enough controllers</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>