From 3266bf052a2e5d26b62a98548d1b126f052b5d78 Mon Sep 17 00:00:00 2001 From: Tim Maile Date: Tue, 23 Aug 2016 11:03:19 +0200 Subject: [PATCH] Toggle and Switches for upward/sideway WiimoteEmu --- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 28 +++++++++-- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h | 1 + Source/Core/InputCommon/ControllerEmu.cpp | 46 +++++++++++++++++++ Source/Core/InputCommon/ControllerEmu.h | 16 +++++++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index b9dec6f554..4973749cfb 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -293,6 +293,16 @@ Wiimote::Wiimote(const unsigned int index) m_options->numeric_settings.emplace_back( std::make_unique(_trans("Battery"), 95.0 / 100, 0, 255)); + // hotkeys + groups.emplace_back(m_hotkeys = new ModifySettingsButton(_trans("Hotkeys"))); + // hotkeys to temporarily modify the Wiimote orientation (sideways, upright) + // this setting modifier is toggled + m_hotkeys->AddInput(_trans("Sideways Toggle"), true); + m_hotkeys->AddInput(_trans("Upright Toggle"), true); + // this setting modifier is not toggled + m_hotkeys->AddInput(_trans("Sideways Hold"), false); + m_hotkeys->AddInput(_trans("Upright Hold"), false); + // TODO: This value should probably be re-read if SYSCONF gets changed m_sensor_bar_on_top = SConfig::GetInstance().m_SYSCONF->GetData("BT.BAR") != 0; @@ -361,7 +371,10 @@ void Wiimote::UpdateButtonsStatus() { // update buttons in status struct m_status.buttons.hex = 0; - const bool is_sideways = m_options->boolean_settings[1]->GetValue(); + const bool sideways_modifier_toggle = m_hotkeys->getSettingsModifier()[0]; + const bool sideways_modifier_switch = m_hotkeys->getSettingsModifier()[2]; + const bool is_sideways = m_options->boolean_settings[1]->GetValue() ^ sideways_modifier_toggle ^ + sideways_modifier_switch; m_buttons->GetState(&m_status.buttons.hex, button_bitmasks); m_dpad->GetState(&m_status.buttons.hex, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks); } @@ -380,8 +393,14 @@ void Wiimote::GetButtonData(u8* const data) void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf) { - const bool is_sideways = m_options->boolean_settings[1]->GetValue(); - const bool is_upright = m_options->boolean_settings[2]->GetValue(); + const bool sideways_modifier_toggle = m_hotkeys->getSettingsModifier()[0]; + const bool upright_modifier_toggle = m_hotkeys->getSettingsModifier()[1]; + const bool sideways_modifier_switch = m_hotkeys->getSettingsModifier()[2]; + const bool upright_modifier_switch = m_hotkeys->getSettingsModifier()[3]; + const bool is_sideways = m_options->boolean_settings[1]->GetValue() ^ sideways_modifier_toggle ^ + sideways_modifier_switch; + const bool is_upright = m_options->boolean_settings[2]->GetValue() ^ upright_modifier_toggle ^ + upright_modifier_switch; EmulateTilt(&m_accel, m_tilt, is_sideways, is_upright); EmulateSwing(&m_accel, m_swing, is_sideways, is_upright); @@ -651,6 +670,9 @@ void Wiimote::Update() auto lock = ControllerEmu::GetStateLock(); + // hotkey/settings modifier + m_hotkeys->GetState(); // data is later accessed in UpdateButtonsStatus and GetAccelData + // core buttons if (rptf.core) GetButtonData(data + rptf.core); diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index 777c10057d..debb9df116 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -156,6 +156,7 @@ private: ControlGroup* m_rumble; Extension* m_extension; ControlGroup* m_options; + ModifySettingsButton* m_hotkeys; // Wiimote accel data AccelData m_accel; diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp index b3b13b796a..2fd85b3fac 100644 --- a/Source/Core/InputCommon/ControllerEmu.cpp +++ b/Source/Core/InputCommon/ControllerEmu.cpp @@ -5,6 +5,7 @@ #include "InputCommon/ControllerEmu.h" #include #include "Common/Common.h" +#include "VideoCommon/OnScreenDisplay.h" // This should be called before calling GetState() or State() on a control reference // to prevent a race condition. @@ -191,6 +192,51 @@ ControllerEmu::Buttons::Buttons(const std::string& _name) : ControlGroup(_name, numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); } +ControllerEmu::ModifySettingsButton::ModifySettingsButton(std::string button_name) + : Buttons(std::move(button_name)) +{ + numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); +} + +void ControllerEmu::ModifySettingsButton::AddInput(std::string button_name, bool toggle) +{ + controls.emplace_back(new ControlGroup::Input(std::move(button_name))); + threshold_exceeded.emplace_back(false); + associated_settings.emplace_back(false); + associated_settings_toggle.emplace_back(toggle); +} + +void ControllerEmu::ModifySettingsButton::GetState() +{ + for (size_t i = 0; i < controls.size(); ++i) + { + ControlState state = controls[i]->control_ref->State(); + + if (!associated_settings_toggle[i]) + { + // not toggled + associated_settings[i] = state > numeric_settings[0]->GetValue(); + } + else + { + // toggle (loading savestates does not en-/disable toggle) + // after we passed the threshold, we en-/disable. but after that, we don't change it + // anymore + if (!threshold_exceeded[i] && state > numeric_settings[0]->GetValue()) + { + associated_settings[i] = !associated_settings[i]; + if (associated_settings[i]) + OSD::AddMessage(controls[i]->name + ": " + _trans("on")); + else + OSD::AddMessage(controls[i]->name + ": " + _trans("off")); + threshold_exceeded[i] = true; + } + if (state < numeric_settings[0]->GetValue()) + threshold_exceeded[i] = false; + } + } +} + ControllerEmu::MixedTriggers::MixedTriggers(const std::string& _name) : ControlGroup(_name, GROUP_TYPE_MIXED_TRIGGERS) { diff --git a/Source/Core/InputCommon/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu.h index 9416b5f0de..215b2557b4 100644 --- a/Source/Core/InputCommon/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu.h @@ -217,6 +217,22 @@ public: } }; + class ModifySettingsButton : public Buttons + { + public: + ModifySettingsButton(std::string button_name); + void AddInput(std::string button_name, bool toggle = false); + + void GetState(); + + const std::vector& isSettingToggled() const { return associated_settings_toggle; } + const std::vector& getSettingsModifier() const { return associated_settings; } + private: + std::vector threshold_exceeded; // internal calculation (if "state" was above threshold) + std::vector associated_settings_toggle; // is setting toggled or hold? + std::vector associated_settings; // result + }; + class MixedTriggers : public ControlGroup { public: