From 4c409411edb2957a0f6505aaf6c93e5c6c71f896 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 19 May 2022 22:47:30 -0500 Subject: [PATCH] DolphinQt: Don't show the advanced input settings on the main dialog. --- .../Config/Mapping/MappingWidget.cpp | 119 ++++++++++++++---- .../DolphinQt/Config/Mapping/MappingWidget.h | 4 + .../ControllerEmu/Setting/NumericSetting.cpp | 5 + .../ControllerEmu/Setting/NumericSetting.h | 7 +- 4 files changed, 111 insertions(+), 24 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp index 1206ad75ff..a7ea873e41 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp @@ -4,6 +4,7 @@ #include "DolphinQt/Config/Mapping/MappingWidget.h" #include +#include #include #include #include @@ -121,8 +122,54 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con for (auto& control : group->controls) CreateControl(control.get(), form_layout, !indicator); + AddSettingWidgets(form_layout, group, ControllerEmu::SettingVisibility::Normal); + + if (group->default_value != ControllerEmu::ControlGroup::DefaultValue::AlwaysEnabled) + { + QLabel* group_enable_label = new QLabel(tr("Enable")); + QCheckBox* group_enable_checkbox = new QCheckBox(); + group_enable_checkbox->setChecked(group->enabled); + form_layout->insertRow(0, group_enable_label, group_enable_checkbox); + auto enable_group_by_checkbox = [group, form_layout, group_enable_label, + group_enable_checkbox] { + group->enabled = group_enable_checkbox->isChecked(); + for (int i = 0; i < form_layout->count(); ++i) + { + QWidget* widget = form_layout->itemAt(i)->widget(); + if (widget != nullptr && widget != group_enable_label && widget != group_enable_checkbox) + widget->setEnabled(group->enabled); + } + }; + enable_group_by_checkbox(); + connect(group_enable_checkbox, &QCheckBox::toggled, this, enable_group_by_checkbox); + connect(this, &MappingWidget::ConfigChanged, this, + [group_enable_checkbox, group] { group_enable_checkbox->setChecked(group->enabled); }); + } + + const auto advanced_setting_count = std::count_if( + group->numeric_settings.begin(), group->numeric_settings.end(), [](auto& setting) { + return setting->GetVisibility() == ControllerEmu::SettingVisibility::Advanced; + }); + + if (advanced_setting_count != 0) + { + const auto advanced_button = new QPushButton(tr("Advanced")); + form_layout->addRow(advanced_button); + connect(advanced_button, &QPushButton::clicked, + [this, group] { ShowAdvancedControlGroupDialog(group); }); + } + + return group_box; +} + +void MappingWidget::AddSettingWidgets(QFormLayout* layout, ControllerEmu::ControlGroup* group, + ControllerEmu::SettingVisibility visibility) +{ for (auto& setting : group->numeric_settings) { + if (setting->GetVisibility() != visibility) + continue; + QWidget* setting_widget = nullptr; switch (setting->GetType()) @@ -149,33 +196,59 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con hbox->addWidget(setting_widget); hbox->addWidget(CreateSettingAdvancedMappingButton(*setting)); - form_layout->addRow(tr(setting->GetUIName()), hbox); + layout->addRow(tr(setting->GetUIName()), hbox); } } +} - if (group->default_value != ControllerEmu::ControlGroup::DefaultValue::AlwaysEnabled) - { - QLabel* group_enable_label = new QLabel(tr("Enable")); - QCheckBox* group_enable_checkbox = new QCheckBox(); - group_enable_checkbox->setChecked(group->enabled); - form_layout->insertRow(0, group_enable_label, group_enable_checkbox); - auto enable_group_by_checkbox = [group, form_layout, group_enable_label, - group_enable_checkbox] { - group->enabled = group_enable_checkbox->isChecked(); - for (int i = 0; i < form_layout->count(); ++i) - { - QWidget* widget = form_layout->itemAt(i)->widget(); - if (widget != nullptr && widget != group_enable_label && widget != group_enable_checkbox) - widget->setEnabled(group->enabled); - } - }; - enable_group_by_checkbox(); - connect(group_enable_checkbox, &QCheckBox::toggled, this, enable_group_by_checkbox); - connect(this, &MappingWidget::ConfigChanged, this, - [group_enable_checkbox, group] { group_enable_checkbox->setChecked(group->enabled); }); - } +void MappingWidget::ShowAdvancedControlGroupDialog(ControllerEmu::ControlGroup* group) +{ + QDialog dialog{this}; + dialog.setWindowTitle(tr(group->ui_name.c_str())); - return group_box; + const auto group_box = new QGroupBox(tr("Advanced Settings")); + + QFormLayout* form_layout = new QFormLayout(); + + AddSettingWidgets(form_layout, group, ControllerEmu::SettingVisibility::Advanced); + + const auto reset_button = new QPushButton(tr("Reset All")); + form_layout->addRow(reset_button); + + connect(reset_button, &QPushButton::clicked, [this, group] { + for (auto& setting : group->numeric_settings) + { + if (setting->GetVisibility() != ControllerEmu::SettingVisibility::Advanced) + continue; + + setting->SetToDefault(); + } + + emit ConfigChanged(); + }); + + const auto main_layout = new QVBoxLayout(); + const auto button_box = new QDialogButtonBox(QDialogButtonBox::Close); + + group_box->setLayout(form_layout); + + main_layout->addWidget(group_box); + main_layout->addWidget(button_box); + + dialog.setLayout(main_layout); + + // Focusing something else by default instead of the first spin box. + // Dynamically changing expression-backed settings pause when taking input. + // This just avoids that weird edge case behavior when the dialog is first open. + button_box->setFocus(); + + // Signal the newly created numeric setting widgets to display the current values. + emit ConfigChanged(); + + // Enable "Close" button functionality. + connect(button_box, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); + + dialog.exec(); } QGroupBox* MappingWidget::CreateControlsBox(const QString& name, ControllerEmu::ControlGroup* group, diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.h b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.h index ad55172f4a..941bb09577 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.h +++ b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.h @@ -26,6 +26,7 @@ class Control; class ControlGroup; class EmulatedController; class NumericSettingBase; +enum class SettingVisibility; } // namespace ControllerEmu constexpr int INDICATOR_UPDATE_FREQ = 30; @@ -57,6 +58,9 @@ protected: int columns); void CreateControl(const ControllerEmu::Control* control, QFormLayout* layout, bool indicator); QPushButton* CreateSettingAdvancedMappingButton(ControllerEmu::NumericSettingBase& setting); + void AddSettingWidgets(QFormLayout* layout, ControllerEmu::ControlGroup* group, + ControllerEmu::SettingVisibility visibility); + void ShowAdvancedControlGroupDialog(ControllerEmu::ControlGroup* group); private: MappingWindow* m_parent; diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp index 70352ccfd8..f7f2054927 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp +++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp @@ -26,6 +26,11 @@ const char* NumericSettingBase::GetUIDescription() const return m_details.ui_description; } +SettingVisibility NumericSettingBase::GetVisibility() const +{ + return m_details.visibility; +} + template <> void NumericSetting::SetExpressionFromValue() { diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h index 34321d0ebc..8b36ab117e 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h +++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h @@ -76,9 +76,12 @@ public: virtual SettingType GetType() const = 0; + virtual void SetToDefault() = 0; + const char* GetUIName() const; const char* GetUISuffix() const; const char* GetUIDescription() const; + SettingVisibility GetVisibility() const; protected: NumericSettingDetails m_details; @@ -102,9 +105,11 @@ public: : NumericSettingBase(details), m_value(*value), m_default_value(default_value), m_min_value(min_value), m_max_value(max_value) { - m_value.SetValue(m_default_value); + SetToDefault(); } + void SetToDefault() override { m_value.SetValue(m_default_value); } + void LoadFromIni(const IniFile::Section& section, const std::string& group_name) override { std::string str_value;