InputCommon: Allow controller settings specified with input expresions.

This commit is contained in:
Jordan Woyak
2019-10-18 14:54:02 -05:00
parent 6a857df219
commit e8152b700f
13 changed files with 172 additions and 28 deletions

View File

@ -132,11 +132,9 @@ void MappingButton::UpdateIndicator()
if (!isActiveWindow())
return;
const auto state = m_reference->State();
QFont f = m_parent->font();
if (state > ControllerEmu::Buttons::ACTIVATION_THRESHOLD)
if (m_reference->GetState<bool>())
f.setBold(true);
setFont(f);

View File

@ -4,6 +4,8 @@
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
#include <limits>
#include "DolphinQt/Config/Mapping/MappingWidget.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
@ -12,24 +14,20 @@
MappingDouble::MappingDouble(MappingWidget* parent, ControllerEmu::NumericSetting<double>* setting)
: QDoubleSpinBox(parent), m_setting(*setting)
{
setRange(m_setting.GetMinValue(), m_setting.GetMaxValue());
setDecimals(2);
setFixedWidth(WIDGET_MAX_WIDTH);
if (const auto ui_suffix = m_setting.GetUISuffix())
setSuffix(QLatin1Char{' '} + tr(ui_suffix));
if (const auto ui_description = m_setting.GetUIDescription())
setToolTip(tr(ui_description));
connect(this, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
[this, parent](double value) {
m_setting.SetValue(value);
ConfigChanged();
parent->SaveSettings();
});
connect(parent, &MappingWidget::ConfigChanged, this, &MappingDouble::ConfigChanged);
connect(parent, &MappingWidget::Update, this, &MappingDouble::Update);
}
// Overriding QDoubleSpinBox's fixup to set the default value when input is cleared.
@ -41,6 +39,36 @@ void MappingDouble::fixup(QString& input) const
void MappingDouble::ConfigChanged()
{
const QSignalBlocker blocker(this);
QString suffix;
if (const auto ui_suffix = m_setting.GetUISuffix())
suffix += QLatin1Char{' '} + tr(ui_suffix);
if (m_setting.IsSimpleValue())
{
setRange(m_setting.GetMinValue(), m_setting.GetMaxValue());
setButtonSymbols(ButtonSymbols::UpDownArrows);
}
else
{
constexpr auto inf = std::numeric_limits<double>::infinity();
setRange(-inf, inf);
setButtonSymbols(ButtonSymbols::NoButtons);
suffix += QString::fromUtf8(" 🎮");
}
setSuffix(suffix);
setValue(m_setting.GetValue());
}
void MappingDouble::Update()
{
if (m_setting.IsSimpleValue() || hasFocus())
return;
const QSignalBlocker blocker(this);
setValue(m_setting.GetValue());
}
@ -49,14 +77,31 @@ MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting<bo
{
connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) {
m_setting.SetValue(value != 0);
ConfigChanged();
parent->SaveSettings();
});
connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
connect(parent, &MappingWidget::Update, this, &MappingBool::Update);
}
void MappingBool::ConfigChanged()
{
const QSignalBlocker blocker(this);
if (m_setting.IsSimpleValue())
setText({});
else
setText(QString::fromUtf8("🎮"));
setChecked(m_setting.GetValue());
}
void MappingBool::Update()
{
if (m_setting.IsSimpleValue())
return;
const QSignalBlocker blocker(this);
setChecked(m_setting.GetValue());
}

View File

@ -21,6 +21,7 @@ private:
void fixup(QString& input) const override;
void ConfigChanged();
void Update();
ControllerEmu::NumericSetting<double>& m_setting;
};
@ -32,6 +33,7 @@ public:
private:
void ConfigChanged();
void Update();
ControllerEmu::NumericSetting<bool>& m_setting;
};

View File

@ -11,6 +11,7 @@
#include <QPushButton>
#include <QTimer>
#include "DolphinQt/Config/Mapping/IOWindow.h"
#include "DolphinQt/Config/Mapping/MappingButton.h"
#include "DolphinQt/Config/Mapping/MappingIndicator.h"
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
@ -141,7 +142,31 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
}
if (setting_widget)
form_layout->addRow(tr(setting->GetUIName()), setting_widget);
{
const auto hbox = new QHBoxLayout;
hbox->addWidget(setting_widget);
const auto advanced_button = new QPushButton(tr("..."));
advanced_button->setFixedWidth(
QFontMetrics(font()).boundingRect(advanced_button->text()).width() * 2);
hbox->addWidget(advanced_button);
advanced_button->connect(
advanced_button, &QPushButton::clicked, [this, &setting = *setting.get()]() {
setting.SetExpressionFromValue();
IOWindow io(this, GetController(), &setting.GetInputReference(), IOWindow::Type::Input);
io.exec();
setting.SimplifyIfPossible();
ConfigChanged();
SaveSettings();
});
form_layout->addRow(tr(setting->GetUIName()), hbox);
}
}
if (group->can_be_disabled)

View File

@ -14,7 +14,6 @@ constexpr int WIDGET_MAX_WIDTH = 112;
class ControlGroupBox;
class InputConfig;
class IOWindow;
class MappingButton;
class MappingNumeric;
class MappingWindow;