Toggle and Switches for upward/sideway WiimoteEmu

This commit is contained in:
Tim Maile 2016-08-23 11:03:19 +02:00
parent 52af0770c3
commit 3266bf052a
4 changed files with 88 additions and 3 deletions

View File

@ -293,6 +293,16 @@ Wiimote::Wiimote(const unsigned int index)
m_options->numeric_settings.emplace_back(
std::make_unique<ControlGroup::NumericSetting>(_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<u8>("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);

View File

@ -156,6 +156,7 @@ private:
ControlGroup* m_rumble;
Extension* m_extension;
ControlGroup* m_options;
ModifySettingsButton* m_hotkeys;
// Wiimote accel data
AccelData m_accel;

View File

@ -5,6 +5,7 @@
#include "InputCommon/ControllerEmu.h"
#include <memory>
#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<NumericSetting>(_trans("Threshold"), 0.5));
}
ControllerEmu::ModifySettingsButton::ModifySettingsButton(std::string button_name)
: Buttons(std::move(button_name))
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_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)
{

View File

@ -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<bool>& isSettingToggled() const { return associated_settings_toggle; }
const std::vector<bool>& getSettingsModifier() const { return associated_settings; }
private:
std::vector<bool> threshold_exceeded; // internal calculation (if "state" was above threshold)
std::vector<bool> associated_settings_toggle; // is setting toggled or hold?
std::vector<bool> associated_settings; // result
};
class MixedTriggers : public ControlGroup
{
public: