Skip to content

Commit

Permalink
Merge pull request #8440 from rlnilsen/motion-input-tweaks
Browse files Browse the repository at this point in the history
Motion Input enhancements
  • Loading branch information
JosJuice committed Nov 15, 2019
2 parents 294fd8d + f7a5054 commit fe39e1e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ void EmulateIMUCursor(std::optional<RotationalState>* state, ControllerEmu::IMUC
// Avoid having to double dereference // Avoid having to double dereference
auto& st = *state; auto& st = *state;


if (!imu_ir_group->enabled)
{
st = std::nullopt;
return;
}

auto accel = imu_accelerometer_group->GetState(); auto accel = imu_accelerometer_group->GetState();
auto ang_vel = imu_gyroscope_group->GetState(); auto ang_vel = imu_gyroscope_group->GetState();


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ void DualShockUDPClientWidget::CreateWidgets()


m_server_address = new QLineEdit( m_server_address = new QLineEdit(
QString::fromStdString(Config::Get(ciface::DualShockUDPClient::Settings::SERVER_ADDRESS))); QString::fromStdString(Config::Get(ciface::DualShockUDPClient::Settings::SERVER_ADDRESS)));
m_server_address->setEnabled(m_server_enabled->isChecked());


m_server_port = new QSpinBox(); m_server_port = new QSpinBox();
m_server_port->setMaximum(65535); m_server_port->setMaximum(65535);
m_server_port->setValue(Config::Get(ciface::DualShockUDPClient::Settings::SERVER_PORT)); m_server_port->setValue(Config::Get(ciface::DualShockUDPClient::Settings::SERVER_PORT));
m_server_port->setEnabled(m_server_enabled->isChecked());


auto* description = auto* description =
new QLabel(tr("DSU protocol enables the use of input and motion data from compatible " new QLabel(tr("DSU protocol enables the use of input and motion data from compatible "
Expand All @@ -58,8 +60,10 @@ void DualShockUDPClientWidget::CreateWidgets()
void DualShockUDPClientWidget::ConnectWidgets() void DualShockUDPClientWidget::ConnectWidgets()
{ {
connect(m_server_enabled, &QCheckBox::toggled, this, [this] { connect(m_server_enabled, &QCheckBox::toggled, this, [this] {
Config::SetBaseOrCurrent(ciface::DualShockUDPClient::Settings::SERVER_ENABLED, bool checked = m_server_enabled->isChecked();
m_server_enabled->isChecked()); Config::SetBaseOrCurrent(ciface::DualShockUDPClient::Settings::SERVER_ENABLED, checked);
m_server_address->setEnabled(checked);
m_server_port->setEnabled(checked);
}); });


connect(m_server_address, &QLineEdit::editingFinished, this, [this] { connect(m_server_address, &QLineEdit::editingFinished, this, [this] {
Expand Down
24 changes: 24 additions & 0 deletions Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@


#include "DolphinQt/Config/Mapping/MappingWidget.h" #include "DolphinQt/Config/Mapping/MappingWidget.h"


#include <QCheckBox>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QTimer> #include <QTimer>


Expand Down Expand Up @@ -144,6 +146,28 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
form_layout->addRow(tr(setting->GetUIName()), setting_widget); form_layout->addRow(tr(setting->GetUIName()), setting_widget);
} }


if (group->can_be_disabled)
{
QLabel* group_enable_label = new QLabel(tr("Enable"));
QCheckBox* group_enable_checkbox = new QCheckBox();
group_enable_checkbox->setChecked(group->enabled);
form_layout->insertRow(0, group_enable_label, group_enable_checkbox);
auto enable_group_by_checkbox = [group, form_layout, group_enable_label,
group_enable_checkbox] {
group->enabled = group_enable_checkbox->isChecked();
for (int i = 0; i < form_layout->count(); ++i)
{
QWidget* widget = form_layout->itemAt(i)->widget();
if (widget != nullptr && widget != group_enable_label && widget != group_enable_checkbox)
widget->setEnabled(group->enabled);
}
};
enable_group_by_checkbox();
connect(group_enable_checkbox, &QCheckBox::toggled, this, enable_group_by_checkbox);
connect(this, &MappingWidget::ConfigChanged, this,
[group_enable_checkbox, group] { group_enable_checkbox->setChecked(group->enabled); });
}

return group_box; return group_box;
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@


namespace ControllerEmu namespace ControllerEmu
{ {
ControlGroup::ControlGroup(std::string name_, const GroupType type_) ControlGroup::ControlGroup(std::string name_, const GroupType type_, CanBeDisabled can_be_disabled_)
: name(name_), ui_name(std::move(name_)), type(type_) : name(name_), ui_name(std::move(name_)), type(type_),
can_be_disabled(can_be_disabled_ == CanBeDisabled::Yes)
{ {
} }


ControlGroup::ControlGroup(std::string name_, std::string ui_name_, const GroupType type_) ControlGroup::ControlGroup(std::string name_, std::string ui_name_, const GroupType type_,
: name(std::move(name_)), ui_name(std::move(ui_name_)), type(type_) CanBeDisabled can_be_disabled_)
: name(std::move(name_)), ui_name(std::move(ui_name_)), type(type_),
can_be_disabled(can_be_disabled_ == CanBeDisabled::Yes)
{ {
} }


Expand All @@ -43,6 +46,10 @@ void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
{ {
const std::string group(base + name + "/"); const std::string group(base + name + "/");


// enabled
if (can_be_disabled)
sec->Get(group + "Enabled", &enabled, true);

for (auto& setting : numeric_settings) for (auto& setting : numeric_settings)
setting->LoadFromIni(*sec, group); setting->LoadFromIni(*sec, group);


Expand Down Expand Up @@ -88,6 +95,9 @@ void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev,
{ {
const std::string group(base + name + "/"); const std::string group(base + name + "/");


// enabled
sec->Set(group + "Enabled", enabled, true);

for (auto& setting : numeric_settings) for (auto& setting : numeric_settings)
setting->SaveToIni(*sec, group); setting->SaveToIni(*sec, group);


Expand Down
14 changes: 12 additions & 2 deletions Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ enum class GroupType
class ControlGroup class ControlGroup
{ {
public: public:
explicit ControlGroup(std::string name, GroupType type = GroupType::Other); enum class CanBeDisabled
ControlGroup(std::string name, std::string ui_name, GroupType type = GroupType::Other); {
No,
Yes,
};

explicit ControlGroup(std::string name, GroupType type = GroupType::Other,
CanBeDisabled can_be_disabled = CanBeDisabled::No);
ControlGroup(std::string name, std::string ui_name, GroupType type = GroupType::Other,
CanBeDisabled can_be_disabled = CanBeDisabled::No);
virtual ~ControlGroup(); virtual ~ControlGroup();


virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "", virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "",
Expand Down Expand Up @@ -79,7 +87,9 @@ class ControlGroup
const std::string name; const std::string name;
const std::string ui_name; const std::string ui_name;
const GroupType type; const GroupType type;
const bool can_be_disabled;


bool enabled = true;
std::vector<std::unique_ptr<Control>> controls; std::vector<std::unique_ptr<Control>> controls;
std::vector<std::unique_ptr<NumericSettingBase>> numeric_settings; std::vector<std::unique_ptr<NumericSettingBase>> numeric_settings;
}; };
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
namespace ControllerEmu namespace ControllerEmu
{ {
IMUCursor::IMUCursor(std::string name, std::string ui_name) IMUCursor::IMUCursor(std::string name, std::string ui_name)
: ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUCursor) : ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUCursor,
ControlGroup::CanBeDisabled::Yes)
{ {
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Recenter"))); controls.emplace_back(std::make_unique<Input>(Translate, _trans("Recenter")));


Expand Down

0 comments on commit fe39e1e

Please sign in to comment.