From c7c93a8e8027085d2b8fd6b7c6acc73595e6a2c0 Mon Sep 17 00:00:00 2001 From: spycrab Date: Mon, 2 Jul 2018 15:15:23 +0200 Subject: [PATCH 1/3] ControllerEmu/BooleanSetting: Add exclusive flag --- .../ControllerEmu/Setting/BooleanSetting.cpp | 15 +++++++++++---- .../ControllerEmu/Setting/BooleanSetting.h | 11 +++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.cpp b/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.cpp index 3f7c4e0752..d9aa61b9f6 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.cpp +++ b/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.cpp @@ -7,15 +7,16 @@ namespace ControllerEmu { BooleanSetting::BooleanSetting(const std::string& setting_name, const std::string& ui_name, - const bool default_value, const SettingType setting_type) + const bool default_value, const SettingType setting_type, + const bool exclusive) : m_type(setting_type), m_name(setting_name), m_ui_name(ui_name), - m_default_value(default_value), m_value(default_value) + m_default_value(default_value), m_value(default_value), m_exclusive(exclusive) { } BooleanSetting::BooleanSetting(const std::string& setting_name, const bool default_value, - const SettingType setting_type) - : BooleanSetting(setting_name, setting_name, default_value, setting_type) + const SettingType setting_type, const bool exclusive) + : BooleanSetting(setting_name, setting_name, default_value, setting_type, exclusive) { } @@ -23,6 +24,12 @@ bool BooleanSetting::GetValue() const { return m_value; } + +bool BooleanSetting::IsExclusive() const +{ + return m_exclusive; +} + void BooleanSetting::SetValue(bool value) { m_value = value; diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.h b/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.h index 98c1614a6a..a2729a588e 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.h +++ b/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.h @@ -15,17 +15,24 @@ class BooleanSetting { public: BooleanSetting(const std::string& setting_name, const std::string& ui_name, - const bool default_value, const SettingType setting_type = SettingType::NORMAL); + const bool default_value, const SettingType setting_type = SettingType::NORMAL, + const bool exclusive = false); BooleanSetting(const std::string& setting_name, const bool default_value, - const SettingType setting_type = SettingType::NORMAL); + const SettingType setting_type = SettingType::NORMAL, + const bool exclusive = false); bool GetValue() const; void SetValue(bool value); + bool IsExclusive() const; + const SettingType m_type; const std::string m_name; const std::string m_ui_name; const bool m_default_value; bool m_value; + +private: + const bool m_exclusive; }; } // namespace ControllerEmu From 3e2e8136072f4c58dae12dc569f7cd4cf627ee8b Mon Sep 17 00:00:00 2001 From: spycrab Date: Mon, 2 Jul 2018 15:15:53 +0200 Subject: [PATCH 2/3] HW/WiimoteEmu: Make "Upright / Sideways Wii Remote" mutually exclusive --- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 1b435328e6..72e6dc3bed 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -49,7 +49,7 @@ namespace // :) auto const TAU = 6.28318530717958647692; auto const PI = TAU / 2.0; -} +} // namespace namespace WiimoteEmu { @@ -308,12 +308,13 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index), ir_sin(0), ir_cos(1 // options groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); - m_options->boolean_settings.emplace_back( - m_sideways_setting = new ControllerEmu::BooleanSetting("Sideways Wiimote", - _trans("Sideways Wii Remote"), false)); - m_options->boolean_settings.emplace_back( - m_upright_setting = new ControllerEmu::BooleanSetting("Upright Wiimote", - _trans("Upright Wii Remote"), false)); + m_options->boolean_settings.emplace_back(m_upright_setting = new ControllerEmu::BooleanSetting( + "Upright Wiimote", _trans("Upright Wii Remote"), + true, ControllerEmu::SettingType::NORMAL, true)); + m_options->boolean_settings.emplace_back(m_sideways_setting = new ControllerEmu::BooleanSetting( + "Sideways Wiimote", _trans("Sideways Wii Remote"), + false, ControllerEmu::SettingType::NORMAL, true)); + m_options->numeric_settings.emplace_back( std::make_unique(_trans("Speaker Pan"), 0, -127, 127)); m_options->numeric_settings.emplace_back( From 0f4865393506ffedc8c1fb93b891a9249a6c0b2a Mon Sep 17 00:00:00 2001 From: spycrab Date: Mon, 2 Jul 2018 15:16:43 +0200 Subject: [PATCH 3/3] Qt/Mapping: Add support for exclusive boolean settings --- Source/Core/DolphinQt2/CMakeLists.txt | 1 + .../Config/Mapping/MappingRadio.cpp | 39 +++++++++++++++++++ .../DolphinQt2/Config/Mapping/MappingRadio.h | 29 ++++++++++++++ .../Config/Mapping/MappingWidget.cpp | 22 +++++++++++ .../DolphinQt2/Config/Mapping/MappingWidget.h | 2 + Source/Core/DolphinQt2/DolphinQt2.vcxproj | 4 +- 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 Source/Core/DolphinQt2/Config/Mapping/MappingRadio.cpp create mode 100644 Source/Core/DolphinQt2/Config/Mapping/MappingRadio.h diff --git a/Source/Core/DolphinQt2/CMakeLists.txt b/Source/Core/DolphinQt2/CMakeLists.txt index ebd98f7e95..b45c4c8bec 100644 --- a/Source/Core/DolphinQt2/CMakeLists.txt +++ b/Source/Core/DolphinQt2/CMakeLists.txt @@ -63,6 +63,7 @@ add_executable(dolphin-emu Config/Mapping/MappingCommon.cpp Config/Mapping/MappingIndicator.cpp Config/Mapping/MappingNumeric.cpp + Config/Mapping/MappingRadio.cpp Config/Mapping/MappingWidget.cpp Config/Mapping/MappingWindow.cpp Config/Mapping/WiimoteEmuExtension.cpp diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingRadio.cpp b/Source/Core/DolphinQt2/Config/Mapping/MappingRadio.cpp new file mode 100644 index 0000000000..4e42224147 --- /dev/null +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingRadio.cpp @@ -0,0 +1,39 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DolphinQt2/Config/Mapping/MappingRadio.h" + +#include "DolphinQt2/Config/Mapping/MappingWidget.h" + +#include "InputCommon/ControllerEmu/ControllerEmu.h" +#include "InputCommon/ControllerEmu/Setting/BooleanSetting.h" +#include "InputCommon/ControllerInterface/ControllerInterface.h" + +MappingRadio::MappingRadio(MappingWidget* widget, ControllerEmu::BooleanSetting* setting) + : QRadioButton(tr(setting->m_ui_name.c_str())), m_parent(widget), m_setting(setting) +{ + Update(); + Connect(); +} + +void MappingRadio::Connect() +{ + connect(this, &QRadioButton::toggled, this, [this](int value) { + m_setting->SetValue(value); + m_parent->SaveSettings(); + m_parent->GetController()->UpdateReferences(g_controller_interface); + }); +} + +void MappingRadio::Clear() +{ + m_setting->SetValue(false); + m_parent->SaveSettings(); + Update(); +} + +void MappingRadio::Update() +{ + setChecked(m_setting->GetValue()); +} diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingRadio.h b/Source/Core/DolphinQt2/Config/Mapping/MappingRadio.h new file mode 100644 index 0000000000..8f4974dd5d --- /dev/null +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingRadio.h @@ -0,0 +1,29 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +class MappingWidget; + +namespace ControllerEmu +{ +class BooleanSetting; +}; + +class MappingRadio : public QRadioButton +{ +public: + MappingRadio(MappingWidget* widget, ControllerEmu::BooleanSetting* setting); + + void Clear(); + void Update(); + +private: + void Connect(); + + MappingWidget* m_parent; + ControllerEmu::BooleanSetting* m_setting; +}; diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp b/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp index 0b6686a687..bfb29eca21 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp @@ -13,6 +13,7 @@ #include "DolphinQt2/Config/Mapping/MappingButton.h" #include "DolphinQt2/Config/Mapping/MappingIndicator.h" #include "DolphinQt2/Config/Mapping/MappingNumeric.h" +#include "DolphinQt2/Config/Mapping/MappingRadio.h" #include "DolphinQt2/Config/Mapping/MappingWindow.h" #include "InputCommon/ControlReference/ControlReference.h" @@ -114,7 +115,22 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con for (auto& boolean : group->boolean_settings) { + if (!boolean->IsExclusive()) + continue; + + auto* checkbox = new MappingRadio(this, boolean.get()); + + form_layout->addRow(checkbox); + m_radio.push_back(checkbox); + } + + for (auto& boolean : group->boolean_settings) + { + if (boolean->IsExclusive()) + continue; + auto* checkbox = new MappingBool(this, boolean.get()); + form_layout->addRow(checkbox); m_bools.push_back(checkbox); } @@ -135,6 +151,9 @@ void MappingWidget::OnClearFields() for (auto* checkbox : m_bools) checkbox->Clear(); + + for (auto* radio : m_radio) + radio->Clear(); } void MappingWidget::Update() @@ -148,6 +167,9 @@ void MappingWidget::Update() for (auto* checkbox : m_bools) checkbox->Update(); + for (auto* radio : m_radio) + radio->Update(); + SaveSettings(); } diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.h b/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.h index def4c46ed2..cf0467b1bc 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.h +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.h @@ -17,6 +17,7 @@ class MappingBool; class MappingButton; class MappingNumeric; class MappingWindow; +class MappingRadio; class QGroupBox; namespace ControllerEmu @@ -64,6 +65,7 @@ private: MappingWindow* m_parent; bool m_first = true; std::vector m_bools; + std::vector m_radio; std::vector m_buttons; std::vector m_numerics; }; diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj index 2ea3ef872e..75d90eac84 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj @@ -296,6 +296,7 @@ + @@ -368,6 +369,7 @@ + @@ -462,4 +464,4 @@ - + \ No newline at end of file