InputCommon: Allow Wii remote extension to be set with an input expression.
This commit is contained in:
parent
e8152b700f
commit
0a1634bedf
|
@ -83,6 +83,8 @@ MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting<bo
|
||||||
|
|
||||||
connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
|
connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
|
||||||
connect(parent, &MappingWidget::Update, this, &MappingBool::Update);
|
connect(parent, &MappingWidget::Update, this, &MappingBool::Update);
|
||||||
|
|
||||||
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingBool::ConfigChanged()
|
void MappingBool::ConfigChanged()
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "DolphinQt/Config/Mapping/IOWindow.h"
|
#include "DolphinQt/Config/Mapping/IOWindow.h"
|
||||||
#include "DolphinQt/Config/Mapping/MappingButton.h"
|
#include "DolphinQt/Config/Mapping/MappingButton.h"
|
||||||
|
@ -29,14 +28,6 @@ MappingWidget::MappingWidget(MappingWindow* parent) : m_parent(parent)
|
||||||
connect(parent, &MappingWindow::Update, this, &MappingWidget::Update);
|
connect(parent, &MappingWindow::Update, this, &MappingWidget::Update);
|
||||||
connect(parent, &MappingWindow::Save, this, &MappingWidget::SaveSettings);
|
connect(parent, &MappingWindow::Save, this, &MappingWidget::SaveSettings);
|
||||||
connect(parent, &MappingWindow::ConfigChanged, this, &MappingWidget::ConfigChanged);
|
connect(parent, &MappingWindow::ConfigChanged, this, &MappingWidget::ConfigChanged);
|
||||||
|
|
||||||
const auto timer = new QTimer(this);
|
|
||||||
connect(timer, &QTimer::timeout, this, [this] {
|
|
||||||
const auto lock = m_parent->GetController()->GetStateLock();
|
|
||||||
emit Update();
|
|
||||||
});
|
|
||||||
|
|
||||||
timer->start(1000 / INDICATOR_UPDATE_FREQ);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MappingWindow* MappingWidget::GetParent() const
|
MappingWindow* MappingWidget::GetParent() const
|
||||||
|
@ -139,31 +130,18 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
|
||||||
setting_widget =
|
setting_widget =
|
||||||
new MappingBool(this, static_cast<ControllerEmu::NumericSetting<bool>*>(setting.get()));
|
new MappingBool(this, static_cast<ControllerEmu::NumericSetting<bool>*>(setting.get()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// FYI: Widgets for additional types can be implemented as needed.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setting_widget)
|
if (setting_widget)
|
||||||
{
|
{
|
||||||
const auto hbox = new QHBoxLayout;
|
const auto hbox = new QHBoxLayout;
|
||||||
|
|
||||||
hbox->addWidget(setting_widget);
|
hbox->addWidget(setting_widget);
|
||||||
|
hbox->addWidget(CreateSettingAdvancedMappingButton(*setting));
|
||||||
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);
|
form_layout->addRow(tr(setting->GetUIName()), hbox);
|
||||||
}
|
}
|
||||||
|
@ -198,3 +176,25 @@ ControllerEmu::EmulatedController* MappingWidget::GetController() const
|
||||||
{
|
{
|
||||||
return m_parent->GetController();
|
return m_parent->GetController();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPushButton*
|
||||||
|
MappingWidget::CreateSettingAdvancedMappingButton(ControllerEmu::NumericSettingBase& setting)
|
||||||
|
{
|
||||||
|
const auto button = new QPushButton(tr("..."));
|
||||||
|
button->setFixedWidth(QFontMetrics(font()).boundingRect(button->text()).width() * 2);
|
||||||
|
|
||||||
|
button->connect(button, &QPushButton::clicked, [this, &setting]() {
|
||||||
|
if (setting.IsSimpleValue())
|
||||||
|
setting.SetExpressionFromValue();
|
||||||
|
|
||||||
|
IOWindow io(this, GetController(), &setting.GetInputReference(), IOWindow::Type::Input);
|
||||||
|
io.exec();
|
||||||
|
|
||||||
|
setting.SimplifyIfPossible();
|
||||||
|
|
||||||
|
ConfigChanged();
|
||||||
|
SaveSettings();
|
||||||
|
});
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ class InputConfig;
|
||||||
class MappingButton;
|
class MappingButton;
|
||||||
class MappingNumeric;
|
class MappingNumeric;
|
||||||
class MappingWindow;
|
class MappingWindow;
|
||||||
|
class QPushButton;
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
|
|
||||||
namespace ControllerEmu
|
namespace ControllerEmu
|
||||||
|
@ -24,13 +25,9 @@ namespace ControllerEmu
|
||||||
class Control;
|
class Control;
|
||||||
class ControlGroup;
|
class ControlGroup;
|
||||||
class EmulatedController;
|
class EmulatedController;
|
||||||
|
class NumericSettingBase;
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
||||||
namespace ciface::Core
|
|
||||||
{
|
|
||||||
class Device;
|
|
||||||
} // namespace ciface::Core
|
|
||||||
|
|
||||||
constexpr int INDICATOR_UPDATE_FREQ = 30;
|
constexpr int INDICATOR_UPDATE_FREQ = 30;
|
||||||
|
|
||||||
class MappingWidget : public QWidget
|
class MappingWidget : public QWidget
|
||||||
|
@ -56,6 +53,7 @@ protected:
|
||||||
|
|
||||||
QGroupBox* CreateGroupBox(ControllerEmu::ControlGroup* group);
|
QGroupBox* CreateGroupBox(ControllerEmu::ControlGroup* group);
|
||||||
QGroupBox* CreateGroupBox(const QString& name, ControllerEmu::ControlGroup* group);
|
QGroupBox* CreateGroupBox(const QString& name, ControllerEmu::ControlGroup* group);
|
||||||
|
QPushButton* CreateSettingAdvancedMappingButton(ControllerEmu::NumericSettingBase& setting);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MappingWindow* m_parent;
|
MappingWindow* m_parent;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
|
#include <QTimer>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
|
@ -62,6 +63,15 @@ MappingWindow::MappingWindow(QWidget* parent, Type type, int port_num)
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
SetMappingType(type);
|
SetMappingType(type);
|
||||||
|
|
||||||
|
const auto timer = new QTimer(this);
|
||||||
|
connect(timer, &QTimer::timeout, this, [this] {
|
||||||
|
const auto lock = GetController()->GetStateLock();
|
||||||
|
emit Update();
|
||||||
|
});
|
||||||
|
|
||||||
|
timer->start(1000 / INDICATOR_UPDATE_FREQ);
|
||||||
|
|
||||||
|
GetController()->GetStateLock();
|
||||||
emit ConfigChanged();
|
emit ConfigChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +245,7 @@ void MappingWindow::OnLoadProfilePressed()
|
||||||
m_controller->LoadConfig(ini.GetOrCreateSection("Profile"));
|
m_controller->LoadConfig(ini.GetOrCreateSection("Profile"));
|
||||||
m_controller->UpdateReferences(g_controller_interface);
|
m_controller->UpdateReferences(g_controller_interface);
|
||||||
|
|
||||||
|
GetController()->GetStateLock();
|
||||||
emit ConfigChanged();
|
emit ConfigChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,6 +437,8 @@ void MappingWindow::OnDefaultFieldsPressed()
|
||||||
{
|
{
|
||||||
m_controller->LoadDefaults(g_controller_interface);
|
m_controller->LoadDefaults(g_controller_interface);
|
||||||
m_controller->UpdateReferences(g_controller_interface);
|
m_controller->UpdateReferences(g_controller_interface);
|
||||||
|
|
||||||
|
GetController()->GetStateLock();
|
||||||
emit ConfigChanged();
|
emit ConfigChanged();
|
||||||
emit Save();
|
emit Save();
|
||||||
}
|
}
|
||||||
|
@ -441,6 +454,8 @@ void MappingWindow::OnClearFieldsPressed()
|
||||||
m_controller->SetDefaultDevice(default_device);
|
m_controller->SetDefaultDevice(default_device);
|
||||||
|
|
||||||
m_controller->UpdateReferences(g_controller_interface);
|
m_controller->UpdateReferences(g_controller_interface);
|
||||||
|
|
||||||
|
GetController()->GetStateLock();
|
||||||
emit ConfigChanged();
|
emit ConfigChanged();
|
||||||
emit Save();
|
emit Save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
#include "Core/HW/Wiimote.h"
|
#include "Core/HW/Wiimote.h"
|
||||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||||
|
@ -22,7 +24,7 @@ WiimoteEmuGeneral::WiimoteEmuGeneral(MappingWindow* window, WiimoteEmuExtension*
|
||||||
: MappingWidget(window), m_extension_widget(extension)
|
: MappingWidget(window), m_extension_widget(extension)
|
||||||
{
|
{
|
||||||
CreateMainLayout();
|
CreateMainLayout();
|
||||||
Connect(window);
|
Connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteEmuGeneral::CreateMainLayout()
|
void WiimoteEmuGeneral::CreateMainLayout()
|
||||||
|
@ -45,14 +47,20 @@ void WiimoteEmuGeneral::CreateMainLayout()
|
||||||
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments);
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments);
|
||||||
auto* extension = CreateGroupBox(tr("Extension"), extension_group);
|
auto* extension = CreateGroupBox(tr("Extension"), extension_group);
|
||||||
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(extension_group);
|
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(extension_group);
|
||||||
m_extension_combo = new QComboBox();
|
|
||||||
|
const auto combo_hbox = new QHBoxLayout;
|
||||||
|
combo_hbox->addWidget(m_extension_combo = new QComboBox());
|
||||||
|
combo_hbox->addWidget(m_extension_combo_dynamic_indicator = new QLabel(QString::fromUtf8("🎮")));
|
||||||
|
combo_hbox->addWidget(CreateSettingAdvancedMappingButton(ce_extension->GetSelectionSetting()));
|
||||||
|
|
||||||
|
m_extension_combo_dynamic_indicator->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored);
|
||||||
|
|
||||||
for (const auto& attachment : ce_extension->GetAttachmentList())
|
for (const auto& attachment : ce_extension->GetAttachmentList())
|
||||||
m_extension_combo->addItem(tr(attachment->GetDisplayName().c_str()));
|
m_extension_combo->addItem(tr(attachment->GetDisplayName().c_str()));
|
||||||
|
|
||||||
extension->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
extension->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
|
||||||
static_cast<QFormLayout*>(extension->layout())->insertRow(0, m_extension_combo);
|
static_cast<QFormLayout*>(extension->layout())->insertRow(0, combo_hbox);
|
||||||
|
|
||||||
layout->addWidget(extension, 0, 3);
|
layout->addWidget(extension, 0, 3);
|
||||||
layout->addWidget(CreateGroupBox(tr("Rumble"), Wiimote::GetWiimoteGroup(
|
layout->addWidget(CreateGroupBox(tr("Rumble"), Wiimote::GetWiimoteGroup(
|
||||||
|
@ -67,11 +75,14 @@ void WiimoteEmuGeneral::CreateMainLayout()
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteEmuGeneral::Connect(MappingWindow* window)
|
void WiimoteEmuGeneral::Connect()
|
||||||
{
|
{
|
||||||
connect(m_extension_combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
connect(m_extension_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||||
this, &WiimoteEmuGeneral::OnAttachmentChanged);
|
&WiimoteEmuGeneral::OnAttachmentChanged);
|
||||||
connect(window, &MappingWindow::ConfigChanged, this, &WiimoteEmuGeneral::ConfigChanged);
|
connect(m_extension_combo, QOverload<int>::of(&QComboBox::activated), this,
|
||||||
|
&WiimoteEmuGeneral::OnAttachmentSelected);
|
||||||
|
connect(this, &MappingWidget::ConfigChanged, this, &WiimoteEmuGeneral::ConfigChanged);
|
||||||
|
connect(this, &MappingWidget::Update, this, &WiimoteEmuGeneral::Update);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
|
void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
|
||||||
|
@ -79,15 +90,31 @@ void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
|
||||||
GetParent()->ShowExtensionMotionTabs(extension == WiimoteEmu::ExtensionNumber::NUNCHUK);
|
GetParent()->ShowExtensionMotionTabs(extension == WiimoteEmu::ExtensionNumber::NUNCHUK);
|
||||||
|
|
||||||
m_extension_widget->ChangeExtensionType(extension);
|
m_extension_widget->ChangeExtensionType(extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WiimoteEmuGeneral::OnAttachmentSelected(int extension)
|
||||||
|
{
|
||||||
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
|
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
|
||||||
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
|
||||||
|
|
||||||
ce_extension->SetSelectedAttachment(extension);
|
ce_extension->SetSelectedAttachment(extension);
|
||||||
|
|
||||||
|
ConfigChanged();
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteEmuGeneral::ConfigChanged()
|
void WiimoteEmuGeneral::ConfigChanged()
|
||||||
|
{
|
||||||
|
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
|
||||||
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
|
||||||
|
|
||||||
|
m_extension_combo->setCurrentIndex(ce_extension->GetSelectedAttachment());
|
||||||
|
|
||||||
|
m_extension_combo_dynamic_indicator->setVisible(
|
||||||
|
!ce_extension->GetSelectionSetting().IsSimpleValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
void WiimoteEmuGeneral::Update()
|
||||||
{
|
{
|
||||||
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
|
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
|
||||||
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
||||||
|
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
|
class QLabel;
|
||||||
class WiimoteEmuExtension;
|
class WiimoteEmuExtension;
|
||||||
|
|
||||||
class WiimoteEmuGeneral final : public MappingWidget
|
class WiimoteEmuGeneral final : public MappingWidget
|
||||||
|
@ -21,12 +22,19 @@ private:
|
||||||
void LoadSettings() override;
|
void LoadSettings() override;
|
||||||
void SaveSettings() override;
|
void SaveSettings() override;
|
||||||
void CreateMainLayout();
|
void CreateMainLayout();
|
||||||
void Connect(MappingWindow* window);
|
void Connect();
|
||||||
|
|
||||||
|
// Index changed by code/expression.
|
||||||
void OnAttachmentChanged(int index);
|
void OnAttachmentChanged(int index);
|
||||||
|
// Selection chosen by user.
|
||||||
|
void OnAttachmentSelected(int index);
|
||||||
|
|
||||||
void ConfigChanged();
|
void ConfigChanged();
|
||||||
|
void Update();
|
||||||
|
|
||||||
// Extensions
|
// Extensions
|
||||||
QComboBox* m_extension_combo;
|
QComboBox* m_extension_combo;
|
||||||
|
QLabel* m_extension_combo_dynamic_indicator;
|
||||||
|
|
||||||
WiimoteEmuExtension* m_extension_widget;
|
WiimoteEmuExtension* m_extension_widget;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,12 +17,22 @@ void Attachments::AddAttachment(std::unique_ptr<EmulatedController> att)
|
||||||
|
|
||||||
u32 Attachments::GetSelectedAttachment() const
|
u32 Attachments::GetSelectedAttachment() const
|
||||||
{
|
{
|
||||||
return m_selected_attachment;
|
const u32 value = m_selection_value.GetValue();
|
||||||
|
|
||||||
|
if (value < m_attachments.size())
|
||||||
|
return value;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Attachments::SetSelectedAttachment(u32 val)
|
void Attachments::SetSelectedAttachment(u32 val)
|
||||||
{
|
{
|
||||||
m_selected_attachment = val;
|
m_selection_setting.SetValue(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
NumericSetting<int>& Attachments::GetSelectionSetting()
|
||||||
|
{
|
||||||
|
return m_selection_setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::unique_ptr<EmulatedController>>& Attachments::GetAttachmentList() const
|
const std::vector<std::unique_ptr<EmulatedController>>& Attachments::GetAttachmentList() const
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
||||||
|
|
||||||
namespace ControllerEmu
|
namespace ControllerEmu
|
||||||
{
|
{
|
||||||
|
@ -27,11 +28,14 @@ public:
|
||||||
u32 GetSelectedAttachment() const;
|
u32 GetSelectedAttachment() const;
|
||||||
void SetSelectedAttachment(u32 val);
|
void SetSelectedAttachment(u32 val);
|
||||||
|
|
||||||
|
NumericSetting<int>& GetSelectionSetting();
|
||||||
|
|
||||||
const std::vector<std::unique_ptr<EmulatedController>>& GetAttachmentList() const;
|
const std::vector<std::unique_ptr<EmulatedController>>& GetAttachmentList() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<EmulatedController>> m_attachments;
|
SettingValue<int> m_selection_value;
|
||||||
|
NumericSetting<int> m_selection_setting = {&m_selection_value, {""}, 0, 0, 0};
|
||||||
|
|
||||||
std::atomic<u32> m_selected_attachment = {};
|
std::vector<std::unique_ptr<EmulatedController>> m_attachments;
|
||||||
};
|
};
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
|
@ -74,15 +74,19 @@ void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
|
||||||
|
|
||||||
ext->SetSelectedAttachment(0);
|
ext->SetSelectedAttachment(0);
|
||||||
u32 n = 0;
|
u32 n = 0;
|
||||||
std::string extname;
|
std::string attachment_text;
|
||||||
sec->Get(base + name, &extname, "");
|
sec->Get(base + name, &attachment_text, "");
|
||||||
|
|
||||||
|
// First assume attachment string is a valid expression.
|
||||||
|
// If it instead matches one of the names of our attachments it is overridden below.
|
||||||
|
ext->GetSelectionSetting().GetInputReference().SetExpression(attachment_text);
|
||||||
|
|
||||||
for (auto& ai : ext->GetAttachmentList())
|
for (auto& ai : ext->GetAttachmentList())
|
||||||
{
|
{
|
||||||
ai->SetDefaultDevice(defdev);
|
ai->SetDefaultDevice(defdev);
|
||||||
ai->LoadConfig(sec, base + ai->GetName() + "/");
|
ai->LoadConfig(sec, base + ai->GetName() + "/");
|
||||||
|
|
||||||
if (ai->GetName() == extname)
|
if (ai->GetName() == attachment_text)
|
||||||
ext->SetSelectedAttachment(n);
|
ext->SetSelectedAttachment(n);
|
||||||
|
|
||||||
n++;
|
n++;
|
||||||
|
@ -114,8 +118,16 @@ void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev,
|
||||||
if (type == GroupType::Attachments)
|
if (type == GroupType::Attachments)
|
||||||
{
|
{
|
||||||
auto* const ext = static_cast<Attachments*>(this);
|
auto* const ext = static_cast<Attachments*>(this);
|
||||||
sec->Set(base + name, ext->GetAttachmentList()[ext->GetSelectedAttachment()]->GetName(),
|
|
||||||
"None");
|
if (ext->GetSelectionSetting().IsSimpleValue())
|
||||||
|
{
|
||||||
|
sec->Set(base + name, ext->GetAttachmentList()[ext->GetSelectedAttachment()]->GetName(),
|
||||||
|
"None");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sec->Set(base + name, ext->GetSelectionSetting().GetInputReference().GetExpression(), "None");
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& ai : ext->GetAttachmentList())
|
for (auto& ai : ext->GetAttachmentList())
|
||||||
ai->SaveConfig(sec, base + ai->GetName() + "/");
|
ai->SaveConfig(sec, base + ai->GetName() + "/");
|
||||||
|
|
|
@ -61,7 +61,11 @@ void EmulatedController::UpdateReferences(ciface::ExpressionParser::ControlEnvir
|
||||||
// Attachments:
|
// Attachments:
|
||||||
if (ctrlGroup->type == GroupType::Attachments)
|
if (ctrlGroup->type == GroupType::Attachments)
|
||||||
{
|
{
|
||||||
for (auto& attachment : static_cast<Attachments*>(ctrlGroup.get())->GetAttachmentList())
|
auto* const attachments = static_cast<Attachments*>(ctrlGroup.get());
|
||||||
|
|
||||||
|
attachments->GetSelectionSetting().GetInputReference().UpdateReference(env);
|
||||||
|
|
||||||
|
for (auto& attachment : attachments->GetAttachmentList())
|
||||||
attachment->UpdateReferences(env);
|
attachment->UpdateReferences(env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace ControllerEmu
|
namespace ControllerEmu
|
||||||
{
|
{
|
||||||
NumericSettingBase::NumericSettingBase(const NumericSettingDetails& details) : m_details(details)
|
NumericSettingBase::NumericSettingBase(const NumericSettingDetails& details) : m_details(details)
|
||||||
|
@ -25,6 +27,36 @@ const char* NumericSettingBase::GetUIDescription() const
|
||||||
return m_details.ui_description;
|
return m_details.ui_description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void NumericSetting<int>::SetExpressionFromValue()
|
||||||
|
{
|
||||||
|
m_value.m_input.SetExpression(ValueToString(GetValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void NumericSetting<double>::SetExpressionFromValue()
|
||||||
|
{
|
||||||
|
// We must use a dot decimal separator for expression parser.
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss.imbue(std::locale::classic());
|
||||||
|
ss << GetValue();
|
||||||
|
|
||||||
|
m_value.m_input.SetExpression(ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void NumericSetting<bool>::SetExpressionFromValue()
|
||||||
|
{
|
||||||
|
// Cast bool to prevent "true"/"false" strings.
|
||||||
|
m_value.m_input.SetExpression(ValueToString(int(GetValue())));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
SettingType NumericSetting<int>::GetType() const
|
||||||
|
{
|
||||||
|
return SettingType::Int;
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
SettingType NumericSetting<double>::GetType() const
|
SettingType NumericSetting<double>::GetType() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace ControllerEmu
|
||||||
{
|
{
|
||||||
enum class SettingType
|
enum class SettingType
|
||||||
{
|
{
|
||||||
|
Int,
|
||||||
Double,
|
Double,
|
||||||
Bool,
|
Bool,
|
||||||
};
|
};
|
||||||
|
@ -56,6 +57,8 @@ public:
|
||||||
virtual InputReference& GetInputReference() = 0;
|
virtual InputReference& GetInputReference() = 0;
|
||||||
virtual const InputReference& GetInputReference() const = 0;
|
virtual const InputReference& GetInputReference() const = 0;
|
||||||
|
|
||||||
|
virtual bool IsSimpleValue() const = 0;
|
||||||
|
|
||||||
// Convert a literal expression e.g. "7.0" to a regular value. (disables expression parsing)
|
// Convert a literal expression e.g. "7.0" to a regular value. (disables expression parsing)
|
||||||
virtual void SimplifyIfPossible() = 0;
|
virtual void SimplifyIfPossible() = 0;
|
||||||
|
|
||||||
|
@ -76,13 +79,14 @@ template <typename T>
|
||||||
class SettingValue;
|
class SettingValue;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class NumericSetting : public NumericSettingBase
|
class NumericSetting final : public NumericSettingBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using ValueType = T;
|
using ValueType = T;
|
||||||
|
|
||||||
static_assert(std::is_same<ValueType, double>() || std::is_same<ValueType, bool>(),
|
static_assert(std::is_same<ValueType, int>() || std::is_same<ValueType, double>() ||
|
||||||
"NumericSetting is only implemented for double and bool.");
|
std::is_same<ValueType, bool>(),
|
||||||
|
"NumericSetting is only implemented for int, double, and bool.");
|
||||||
|
|
||||||
NumericSetting(SettingValue<ValueType>* value, const NumericSettingDetails& details,
|
NumericSetting(SettingValue<ValueType>* value, const NumericSettingDetails& details,
|
||||||
ValueType default_value, ValueType min_value, ValueType max_value)
|
ValueType default_value, ValueType min_value, ValueType max_value)
|
||||||
|
@ -114,7 +118,7 @@ public:
|
||||||
section.Set(group_name + m_details.ini_name, m_value.m_input.GetExpression(), "");
|
section.Set(group_name + m_details.ini_name, m_value.m_input.GetExpression(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsSimpleValue() const { return m_value.IsSimpleValue(); }
|
bool IsSimpleValue() const override { return m_value.IsSimpleValue(); }
|
||||||
|
|
||||||
void SimplifyIfPossible() override
|
void SimplifyIfPossible() override
|
||||||
{
|
{
|
||||||
|
@ -123,15 +127,7 @@ public:
|
||||||
m_value.SetValue(value);
|
m_value.SetValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetExpressionFromValue() override
|
void SetExpressionFromValue() override;
|
||||||
{
|
|
||||||
if (!IsSimpleValue())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Cast to double to prevent bool -> "true"/"false" strings.
|
|
||||||
m_value.m_input.SetExpression(ValueToString(static_cast<double>(GetValue())));
|
|
||||||
}
|
|
||||||
|
|
||||||
InputReference& GetInputReference() override { return m_value.m_input; }
|
InputReference& GetInputReference() override { return m_value.m_input; }
|
||||||
const InputReference& GetInputReference() const override { return m_value.m_input; }
|
const InputReference& GetInputReference() const override { return m_value.m_input; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue