configure_input: Make None a controller option instead of checkbox

This commit is contained in:
Zach Hilman 2018-11-04 10:18:59 -05:00
parent 3a6cd5b3c8
commit e58c951a59
11 changed files with 150 additions and 154 deletions

View File

@ -5,6 +5,7 @@
#include <QSettings> #include <QSettings>
#include "common/file_util.h" #include "common/file_util.h"
#include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/hid/controllers/npad.h"
#include "input_common/main.h" #include "input_common/main.h"
#include "yuzu/configuration/config.h" #include "yuzu/configuration/config.h"
#include "yuzu/ui_settings.h" #include "yuzu/ui_settings.h"
@ -262,8 +263,11 @@ void Config::ReadPlayerValues() {
} }
} }
std::stable_partition(Settings::values.players.begin(), Settings::values.players.end(), std::stable_partition(
[](const auto& player) { return player.connected; }); Settings::values.players.begin(),
Settings::values.players.begin() +
Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD),
[](const auto& player) { return player.connected; });
} }
void Config::ReadDebugValues() { void Config::ReadDebugValues() {

View File

@ -3,10 +3,6 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "core/core.h" #include "core/core.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/am/applet_ae.h"
#include "core/hle/service/am/applet_oe.h"
#include "core/hle/service/sm/sm.h"
#include "core/settings.h" #include "core/settings.h"
#include "ui_configure_general.h" #include "ui_configure_general.h"
#include "yuzu/configuration/configure_general.h" #include "yuzu/configuration/configure_general.h"
@ -36,7 +32,6 @@ void ConfigureGeneral::setConfiguration() {
ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing);
ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme)); ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme));
ui->use_cpu_jit->setChecked(Settings::values.use_cpu_jit); ui->use_cpu_jit->setChecked(Settings::values.use_cpu_jit);
ui->use_docked_mode->setChecked(Settings::values.use_docked_mode);
ui->enable_nfc->setChecked(Settings::values.enable_nfc); ui->enable_nfc->setChecked(Settings::values.enable_nfc);
} }
@ -44,33 +39,6 @@ void ConfigureGeneral::PopulateHotkeyList(const HotkeyRegistry& registry) {
ui->widget->Populate(registry); ui->widget->Populate(registry);
} }
void ConfigureGeneral::OnDockedModeChanged(bool last_state, bool new_state) {
if (last_state == new_state) {
return;
}
Core::System& system{Core::System::GetInstance()};
if (!system.IsPoweredOn()) {
return;
}
Service::SM::ServiceManager& sm = system.ServiceManager();
// Message queue is shared between these services, we just need to signal an operation
// change to one and it will handle both automatically
auto applet_oe = sm.GetService<Service::AM::AppletOE>("appletOE");
auto applet_ae = sm.GetService<Service::AM::AppletAE>("appletAE");
bool has_signalled = false;
if (applet_oe != nullptr) {
applet_oe->GetMessageQueue()->OperationModeChanged();
has_signalled = true;
}
if (applet_ae != nullptr && !has_signalled) {
applet_ae->GetMessageQueue()->OperationModeChanged();
}
}
void ConfigureGeneral::applyConfiguration() { void ConfigureGeneral::applyConfiguration() {
UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked(); UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked();
UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
@ -78,9 +46,5 @@ void ConfigureGeneral::applyConfiguration() {
ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString(); ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString();
Settings::values.use_cpu_jit = ui->use_cpu_jit->isChecked(); Settings::values.use_cpu_jit = ui->use_cpu_jit->isChecked();
const bool pre_docked_mode = Settings::values.use_docked_mode;
Settings::values.use_docked_mode = ui->use_docked_mode->isChecked();
OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode);
Settings::values.enable_nfc = ui->enable_nfc->isChecked(); Settings::values.enable_nfc = ui->enable_nfc->isChecked();
} }

View File

@ -25,7 +25,6 @@ public:
private: private:
void setConfiguration(); void setConfiguration();
void OnDockedModeChanged(bool last_state, bool new_state);
std::unique_ptr<Ui::ConfigureGeneral> ui; std::unique_ptr<Ui::ConfigureGeneral> ui;
}; };

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>300</width> <width>300</width>
<height>377</height> <height>407</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -71,13 +71,6 @@
<layout class="QHBoxLayout" name="EmulationHorizontalLayout"> <layout class="QHBoxLayout" name="EmulationHorizontalLayout">
<item> <item>
<layout class="QVBoxLayout" name="EmulationVerticalLayout"> <layout class="QVBoxLayout" name="EmulationVerticalLayout">
<item>
<widget class="QCheckBox" name="use_docked_mode">
<property name="text">
<string>Enable docked mode</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="enable_nfc"> <widget class="QCheckBox" name="enable_nfc">
<property name="text"> <property name="text">

View File

@ -11,7 +11,11 @@
#include "common/param_package.h" #include "common/param_package.h"
#include "configuration/configure_touchscreen_advanced.h" #include "configuration/configure_touchscreen_advanced.h"
#include "core/core.h" #include "core/core.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/am/applet_ae.h"
#include "core/hle/service/am/applet_oe.h"
#include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/sm/sm.h"
#include "input_common/main.h" #include "input_common/main.h"
#include "ui_configure_input.h" #include "ui_configure_input.h"
#include "ui_configure_input_player.h" #include "ui_configure_input_player.h"
@ -26,24 +30,19 @@ ConfigureInput::ConfigureInput(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) { : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) {
ui->setupUi(this); ui->setupUi(this);
players_enabled = { players_controller = {
ui->player1_checkbox, ui->player2_checkbox, ui->player3_checkbox, ui->player4_checkbox,
ui->player5_checkbox, ui->player6_checkbox, ui->player7_checkbox, ui->player8_checkbox,
};
player_controller = {
ui->player1_combobox, ui->player2_combobox, ui->player3_combobox, ui->player4_combobox, ui->player1_combobox, ui->player2_combobox, ui->player3_combobox, ui->player4_combobox,
ui->player5_combobox, ui->player6_combobox, ui->player7_combobox, ui->player8_combobox, ui->player5_combobox, ui->player6_combobox, ui->player7_combobox, ui->player8_combobox,
}; };
player_configure = { players_configure = {
ui->player1_configure, ui->player2_configure, ui->player3_configure, ui->player4_configure, ui->player1_configure, ui->player2_configure, ui->player3_configure, ui->player4_configure,
ui->player5_configure, ui->player6_configure, ui->player7_configure, ui->player8_configure, ui->player5_configure, ui->player6_configure, ui->player7_configure, ui->player8_configure,
}; };
for (auto* controller_box : player_controller) { for (auto* controller_box : players_controller) {
controller_box->addItems( controller_box->addItems({"None", "Pro Controller", "Dual Joycons", "Single Right Joycon",
{"Pro Controller", "Dual Joycons", "Single Right Joycon", "Single Left Joycon"}); "Single Left Joycon"});
} }
this->loadConfiguration(); this->loadConfiguration();
@ -52,8 +51,9 @@ ConfigureInput::ConfigureInput(QWidget* parent)
connect(ui->restore_defaults_button, &QPushButton::pressed, this, connect(ui->restore_defaults_button, &QPushButton::pressed, this,
&ConfigureInput::restoreDefaults); &ConfigureInput::restoreDefaults);
for (auto* enabled : players_enabled) for (auto* enabled : players_controller)
connect(enabled, &QCheckBox::stateChanged, this, &ConfigureInput::updateUIEnabled); connect(enabled, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ConfigureInput::updateUIEnabled);
connect(ui->use_docked_mode, &QCheckBox::stateChanged, this, &ConfigureInput::updateUIEnabled); connect(ui->use_docked_mode, &QCheckBox::stateChanged, this, &ConfigureInput::updateUIEnabled);
connect(ui->handheld_connected, &QCheckBox::stateChanged, this, connect(ui->handheld_connected, &QCheckBox::stateChanged, this,
&ConfigureInput::updateUIEnabled); &ConfigureInput::updateUIEnabled);
@ -63,8 +63,8 @@ ConfigureInput::ConfigureInput(QWidget* parent)
connect(ui->touchscreen_enabled, &QCheckBox::stateChanged, this, connect(ui->touchscreen_enabled, &QCheckBox::stateChanged, this,
&ConfigureInput::updateUIEnabled); &ConfigureInput::updateUIEnabled);
for (std::size_t i = 0; i < player_configure.size(); ++i) { for (std::size_t i = 0; i < players_configure.size(); ++i) {
connect(player_configure[i], &QPushButton::pressed, this, connect(players_configure[i], &QPushButton::pressed, this,
[this, i]() { CallConfigureDialog<ConfigureInputPlayer>(i, false); }); [this, i]() { CallConfigureDialog<ConfigureInputPlayer>(i, false); });
} }
@ -79,8 +79,6 @@ ConfigureInput::ConfigureInput(QWidget* parent)
connect(ui->touchscreen_advanced, &QPushButton::pressed, this, connect(ui->touchscreen_advanced, &QPushButton::pressed, this,
[this]() { CallConfigureDialog<ConfigureTouchscreenAdvanced>(); }); [this]() { CallConfigureDialog<ConfigureTouchscreenAdvanced>(); });
ui->use_docked_mode->setEnabled(!Core::System::GetInstance().IsPoweredOn());
} }
template <typename Dialog, typename... Args> template <typename Dialog, typename... Args>
@ -94,14 +92,50 @@ void ConfigureInput::CallConfigureDialog(Args&&... args) {
} }
} }
void ConfigureInput::applyConfiguration() { void ConfigureInput::OnDockedModeChanged(bool last_state, bool new_state) {
for (std::size_t i = 0; i < players_enabled.size(); ++i) { if (last_state == new_state) {
Settings::values.players[i].connected = players_enabled[i]->isChecked(); return;
Settings::values.players[i].type =
static_cast<Settings::ControllerType>(player_controller[i]->currentIndex());
} }
Core::System& system{Core::System::GetInstance()};
if (!system.IsPoweredOn()) {
return;
}
Service::SM::ServiceManager& sm = system.ServiceManager();
// Message queue is shared between these services, we just need to signal an operation
// change to one and it will handle both automatically
auto applet_oe = sm.GetService<Service::AM::AppletOE>("appletOE");
auto applet_ae = sm.GetService<Service::AM::AppletAE>("appletAE");
bool has_signalled = false;
if (applet_oe != nullptr) {
applet_oe->GetMessageQueue()->OperationModeChanged();
has_signalled = true;
}
if (applet_ae != nullptr && !has_signalled) {
applet_ae->GetMessageQueue()->OperationModeChanged();
}
}
void ConfigureInput::applyConfiguration() {
for (std::size_t i = 0; i < players_controller.size(); ++i) {
const auto controller_type_index = players_controller[i]->currentIndex();
Settings::values.players[i].connected = controller_type_index != 0;
if (controller_type_index > 0) {
Settings::values.players[i].type =
static_cast<Settings::ControllerType>(controller_type_index - 1);
} else {
Settings::values.players[i].type = Settings::ControllerType::DualJoycon;
}
}
const bool pre_docked_mode = Settings::values.use_docked_mode;
Settings::values.use_docked_mode = ui->use_docked_mode->isChecked(); Settings::values.use_docked_mode = ui->use_docked_mode->isChecked();
OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode);
Settings::values Settings::values
.players[Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD)] .players[Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD)]
.connected = ui->handheld_connected->isChecked(); .connected = ui->handheld_connected->isChecked();
@ -112,18 +146,15 @@ void ConfigureInput::applyConfiguration() {
} }
void ConfigureInput::updateUIEnabled() { void ConfigureInput::updateUIEnabled() {
for (std::size_t i = 0; i < players_enabled.size(); ++i) { bool hit_disabled = false;
const auto enabled = players_enabled[i]->checkState() == Qt::Checked; for (auto* player : players_controller) {
player->setDisabled(hit_disabled);
player_controller[i]->setEnabled(enabled); if (!hit_disabled && player->currentIndex() == 0)
player_configure[i]->setEnabled(enabled); hit_disabled = true;
} }
bool hit_disabled = false; for (std::size_t i = 0; i < players_controller.size(); ++i) {
for (auto* player : players_enabled) { players_configure[i]->setEnabled(players_controller[i]->currentIndex() != 0);
player->setDisabled(hit_disabled);
if (!player->isChecked())
hit_disabled = true;
} }
ui->handheld_connected->setEnabled(!ui->use_docked_mode->isChecked()); ui->handheld_connected->setEnabled(!ui->use_docked_mode->isChecked());
@ -135,12 +166,16 @@ void ConfigureInput::updateUIEnabled() {
} }
void ConfigureInput::loadConfiguration() { void ConfigureInput::loadConfiguration() {
std::stable_partition(Settings::values.players.begin(), Settings::values.players.end(), std::stable_partition(
[](const auto& player) { return player.connected; }); Settings::values.players.begin(),
Settings::values.players.begin() +
Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD),
[](const auto& player) { return player.connected; });
for (std::size_t i = 0; i < players_enabled.size(); ++i) { for (std::size_t i = 0; i < players_controller.size(); ++i) {
players_enabled[i]->setChecked(Settings::values.players[i].connected); const auto connected = Settings::values.players[i].connected;
player_controller[i]->setCurrentIndex(static_cast<u8>(Settings::values.players[i].type)); players_controller[i]->setCurrentIndex(
connected ? static_cast<u8>(Settings::values.players[i].type) + 1 : 0);
} }
ui->use_docked_mode->setChecked(Settings::values.use_docked_mode); ui->use_docked_mode->setChecked(Settings::values.use_docked_mode);
@ -157,12 +192,10 @@ void ConfigureInput::loadConfiguration() {
} }
void ConfigureInput::restoreDefaults() { void ConfigureInput::restoreDefaults() {
players_enabled[0]->setCheckState(Qt::Checked); players_controller[0]->setCurrentIndex(2);
player_controller[0]->setCurrentIndex(1);
for (std::size_t i = 1; i < players_enabled.size(); ++i) { for (std::size_t i = 1; i < players_controller.size(); ++i) {
players_enabled[i]->setCheckState(Qt::Unchecked); players_controller[i]->setCurrentIndex(0);
player_controller[i]->setCurrentIndex(0);
} }
ui->use_docked_mode->setCheckState(Qt::Unchecked); ui->use_docked_mode->setCheckState(Qt::Unchecked);

View File

@ -43,6 +43,8 @@ private:
template <typename Dialog, typename... Args> template <typename Dialog, typename... Args>
void CallConfigureDialog(Args&&... args); void CallConfigureDialog(Args&&... args);
void OnDockedModeChanged(bool last_state, bool new_state);
/// Load configuration settings. /// Load configuration settings.
void loadConfiguration(); void loadConfiguration();
/// Restore all buttons to their default values. /// Restore all buttons to their default values.
@ -50,7 +52,6 @@ private:
std::unique_ptr<Ui::ConfigureInput> ui; std::unique_ptr<Ui::ConfigureInput> ui;
std::array<QCheckBox*, 8> players_enabled; std::array<QComboBox*, 8> players_controller;
std::array<QComboBox*, 8> player_controller; std::array<QPushButton*, 8> players_configure;
std::array<QPushButton*, 8> player_configure;
}; };

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>473</width> <width>473</width>
<height>677</height> <height>685</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -49,62 +49,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QCheckBox" name="player1_checkbox">
<property name="text">
<string>Player 1</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="player7_checkbox">
<property name="text">
<string>Player 7</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="player4_checkbox">
<property name="text">
<string>Player 4</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="player5_checkbox">
<property name="text">
<string>Player 5</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="player6_checkbox">
<property name="text">
<string>Player 6</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="player8_checkbox">
<property name="text">
<string>Player 8</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="player3_checkbox">
<property name="text">
<string>Player 3</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="player2_checkbox">
<property name="text">
<string>Player 2</string>
</property>
</widget>
</item>
<item row="2" column="2"> <item row="2" column="2">
<widget class="QComboBox" name="player2_combobox"> <widget class="QComboBox" name="player2_combobox">
<property name="minimumSize"> <property name="minimumSize">
@ -250,13 +194,65 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="1"> <item row="1" column="1">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="minimumSize">
<string>Enabled</string> <size>
<width>55</width>
<height>0</height>
</size>
</property> </property>
<property name="alignment"> <property name="text">
<set>Qt::AlignCenter</set> <string>Player 1</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Player 2</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Player 3</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Player 4</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Player 5</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Player 6</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Player 7</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Player 8</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -325,6 +325,8 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, u8 player_index, boo
ui->buttonHome->setEnabled(false); ui->buttonHome->setEnabled(false);
} }
ConfigureInputPlayer::~ConfigureInputPlayer() = default;
void ConfigureInputPlayer::applyConfiguration() { void ConfigureInputPlayer::applyConfiguration() {
auto& buttons = auto& buttons =
debug ? Settings::values.debug_pad_buttons : Settings::values.players[player_index].buttons; debug ? Settings::values.debug_pad_buttons : Settings::values.players[player_index].buttons;

View File

@ -30,6 +30,7 @@ class ConfigureInputPlayer : public QDialog {
public: public:
explicit ConfigureInputPlayer(QWidget* parent, u8 player_index, bool debug = false); explicit ConfigureInputPlayer(QWidget* parent, u8 player_index, bool debug = false);
~ConfigureInputPlayer() override;
/// Save all button configurations to settings file /// Save all button configurations to settings file
void applyConfiguration(); void applyConfiguration();

View File

@ -112,6 +112,8 @@ ConfigureMouseAdvanced::ConfigureMouseAdvanced(QWidget* parent)
resize(0, 0); resize(0, 0);
} }
ConfigureMouseAdvanced::~ConfigureMouseAdvanced() = default;
void ConfigureMouseAdvanced::applyConfiguration() { void ConfigureMouseAdvanced::applyConfiguration() {
std::transform(buttons_param.begin(), buttons_param.end(), std::transform(buttons_param.begin(), buttons_param.end(),
Settings::values.mouse_buttons.begin(), Settings::values.mouse_buttons.begin(),

View File

@ -23,6 +23,7 @@ class ConfigureMouseAdvanced : public QDialog {
public: public:
explicit ConfigureMouseAdvanced(QWidget* parent); explicit ConfigureMouseAdvanced(QWidget* parent);
~ConfigureMouseAdvanced() override;
void applyConfiguration(); void applyConfiguration();