2017-02-09 03:15:43 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-05-08 19:03:11 +00:00
|
|
|
#include <algorithm>
|
2019-03-29 19:39:48 +00:00
|
|
|
#include <cmath>
|
2017-02-09 03:15:43 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2019-03-29 19:39:48 +00:00
|
|
|
#include <type_traits>
|
2017-02-09 03:15:43 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/IniFile.h"
|
2019-10-27 16:04:08 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
|
|
|
class Control;
|
2019-03-27 00:31:03 +00:00
|
|
|
|
|
|
|
class NumericSettingBase;
|
|
|
|
struct NumericSettingDetails;
|
|
|
|
|
|
|
|
template <typename T>
|
2017-02-26 20:00:24 +00:00
|
|
|
class NumericSetting;
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
template <typename T>
|
|
|
|
class SettingValue;
|
|
|
|
|
2017-02-25 05:35:02 +00:00
|
|
|
enum class GroupType
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2017-02-25 05:35:02 +00:00
|
|
|
Other,
|
|
|
|
Stick,
|
|
|
|
MixedTriggers,
|
|
|
|
Buttons,
|
|
|
|
Force,
|
2019-01-01 14:32:39 +00:00
|
|
|
Attachments,
|
2017-02-25 05:35:02 +00:00
|
|
|
Tilt,
|
|
|
|
Cursor,
|
|
|
|
Triggers,
|
2019-03-29 19:39:48 +00:00
|
|
|
Slider,
|
|
|
|
Shake,
|
2019-09-06 15:09:30 +00:00
|
|
|
IMUAccelerometer,
|
|
|
|
IMUGyroscope,
|
|
|
|
IMUCursor
|
2017-02-09 03:15:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ControlGroup
|
|
|
|
{
|
|
|
|
public:
|
2020-04-07 13:04:14 +00:00
|
|
|
enum class DefaultValue
|
2019-10-30 01:05:42 +00:00
|
|
|
{
|
2020-04-07 13:04:14 +00:00
|
|
|
AlwaysEnabled,
|
|
|
|
Enabled,
|
|
|
|
Disabled,
|
2019-10-30 01:05:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit ControlGroup(std::string name, GroupType type = GroupType::Other,
|
2020-04-07 13:04:14 +00:00
|
|
|
DefaultValue default_value = DefaultValue::AlwaysEnabled);
|
2019-10-30 01:05:42 +00:00
|
|
|
ControlGroup(std::string name, std::string ui_name, GroupType type = GroupType::Other,
|
2020-04-07 13:04:14 +00:00
|
|
|
DefaultValue default_value = DefaultValue::AlwaysEnabled);
|
2017-02-09 03:15:43 +00:00
|
|
|
virtual ~ControlGroup();
|
|
|
|
|
|
|
|
virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "",
|
|
|
|
const std::string& base = "");
|
|
|
|
virtual void SaveConfig(IniFile::Section* sec, const std::string& defdev = "",
|
|
|
|
const std::string& base = "");
|
|
|
|
|
|
|
|
void SetControlExpression(int index, const std::string& expression);
|
|
|
|
|
2019-10-27 16:04:08 +00:00
|
|
|
void AddInput(Translatability translate, std::string name);
|
|
|
|
void AddInput(Translatability translate, std::string name, std::string ui_name);
|
|
|
|
void AddOutput(Translatability translate, std::string name);
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
template <typename T>
|
|
|
|
void AddSetting(SettingValue<T>* value, const NumericSettingDetails& details,
|
2020-07-12 02:18:40 +00:00
|
|
|
std::common_type_t<T> default_value_, std::common_type_t<T> min_value = {},
|
2019-03-27 00:31:03 +00:00
|
|
|
std::common_type_t<T> max_value = T(100))
|
|
|
|
{
|
|
|
|
numeric_settings.emplace_back(
|
2020-07-12 02:18:40 +00:00
|
|
|
std::make_unique<NumericSetting<T>>(value, details, default_value_, min_value, max_value));
|
2019-03-27 00:31:03 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 22:11:34 +00:00
|
|
|
void AddVirtualNotchSetting(SettingValue<double>* value, double max_virtual_notch_deg);
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
void AddDeadzoneSetting(SettingValue<double>* value, double maximum_deadzone);
|
|
|
|
|
2019-03-29 19:39:48 +00:00
|
|
|
template <typename T>
|
|
|
|
static T ApplyDeadzone(T input, std::common_type_t<T> deadzone)
|
|
|
|
{
|
|
|
|
return std::copysign(std::max(T{0}, std::abs(input) - deadzone) / (T{1} - deadzone), input);
|
|
|
|
}
|
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
const std::string name;
|
|
|
|
const std::string ui_name;
|
2017-02-25 05:35:02 +00:00
|
|
|
const GroupType type;
|
2020-04-07 13:04:14 +00:00
|
|
|
const DefaultValue default_value;
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-10-30 01:05:42 +00:00
|
|
|
bool enabled = true;
|
2017-02-09 03:15:43 +00:00
|
|
|
std::vector<std::unique_ptr<Control>> controls;
|
2019-03-27 00:31:03 +00:00
|
|
|
std::vector<std::unique_ptr<NumericSettingBase>> numeric_settings;
|
2017-02-09 03:15:43 +00:00
|
|
|
};
|
|
|
|
} // namespace ControllerEmu
|