diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2020-01-18 11:19:32 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2020-02-08 16:03:13 -0600 |
| commit | 0a1634bedf17f7b27a3781d8e5ac6bafb20cd546 (patch) | |
| tree | 1422bbcf3adc3b715f0f0f3bf4630da728342899 /Source/Core/InputCommon/ControllerEmu/ControlGroup | |
| parent | e8152b700f76da97d346b93662ef8492bc93190c (diff) | |
InputCommon: Allow Wii remote extension to be set with an input expression.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup')
3 files changed, 35 insertions, 9 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp index e104918fe2..6f980d8c60 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp @@ -17,12 +17,22 @@ void Attachments::AddAttachment(std::unique_ptr<EmulatedController> att) 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) { - 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 diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h index 81e76eccfe..f92bd8b1fd 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h @@ -12,6 +12,7 @@ #include "Common/CommonTypes.h" #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" +#include "InputCommon/ControllerEmu/Setting/NumericSetting.h" namespace ControllerEmu { @@ -27,11 +28,14 @@ public: u32 GetSelectedAttachment() const; void SetSelectedAttachment(u32 val); + NumericSetting<int>& GetSelectionSetting(); + const std::vector<std::unique_ptr<EmulatedController>>& GetAttachmentList() const; 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 diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp index 40ccae24f7..1a262a8dfd 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp @@ -74,15 +74,19 @@ void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev, ext->SetSelectedAttachment(0); u32 n = 0; - std::string extname; - sec->Get(base + name, &extname, ""); + std::string attachment_text; + 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()) { ai->SetDefaultDevice(defdev); ai->LoadConfig(sec, base + ai->GetName() + "/"); - if (ai->GetName() == extname) + if (ai->GetName() == attachment_text) ext->SetSelectedAttachment(n); n++; @@ -114,8 +118,16 @@ void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev, if (type == GroupType::Attachments) { 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()) ai->SaveConfig(sec, base + ai->GetName() + "/"); |
