Skip to content

Commit

Permalink
DolphinQt: Move advanced control group settings to a new dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-woyak committed May 20, 2022
1 parent 3905010 commit a8ffd59
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
64 changes: 64 additions & 0 deletions Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp
Expand Up @@ -4,6 +4,7 @@
#include "DolphinQt/Config/Mapping/MappingWidget.h"

#include <QCheckBox>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QHBoxLayout>
Expand Down Expand Up @@ -145,6 +146,19 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
[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->GetDifficulty() == ControllerEmu::SettingDifficulty::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;
}

Expand Down Expand Up @@ -187,6 +201,56 @@ void MappingWidget::AddSettingWidgets(QFormLayout* layout, ControllerEmu::Contro
}
}

void MappingWidget::ShowAdvancedControlGroupDialog(ControllerEmu::ControlGroup* group)
{
QDialog dialog{this};
dialog.setWindowTitle(tr(group->ui_name.c_str()));

const auto group_box = new QGroupBox(tr("Advanced Settings"));

QFormLayout* form_layout = new QFormLayout();

AddSettingWidgets(form_layout, group, ControllerEmu::SettingDifficulty::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->GetDifficulty() != ControllerEmu::SettingDifficulty::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,
int columns)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Config/Mapping/MappingWidget.h
Expand Up @@ -60,6 +60,7 @@ class MappingWidget : public QWidget
QPushButton* CreateSettingAdvancedMappingButton(ControllerEmu::NumericSettingBase& setting);
void AddSettingWidgets(QFormLayout* layout, ControllerEmu::ControlGroup* group,
ControllerEmu::SettingDifficulty difficulty);
void ShowAdvancedControlGroupDialog(ControllerEmu::ControlGroup* group);

private:
MappingWindow* m_parent;
Expand Down
Expand Up @@ -76,6 +76,8 @@ class NumericSettingBase

virtual SettingType GetType() const = 0;

virtual void SetToDefault() = 0;

const char* GetUIName() const;
const char* GetUISuffix() const;
const char* GetUIDescription() const;
Expand Down Expand Up @@ -103,9 +105,11 @@ class NumericSetting final : public NumericSettingBase
: 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;
Expand Down

0 comments on commit a8ffd59

Please sign in to comment.