| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <algorithm> |
| 7 |
#include <cmath> |
| 8 |
#include <functional> |
| 9 |
#include <memory> |
| 10 |
#include <optional> |
| 11 |
#include <string> |
| 12 |
#include <string_view> |
| 13 |
#include <type_traits> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
#include "Common/IniFile.h" |
| 17 |
#include "InputCommon/ControllerEmu/Control/Control.h" |
| 18 |
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h" |
| 19 |
#include "InputCommon/ControllerInterface/CoreDevice.h" |
| 20 |
|
| 21 |
namespace ControllerEmu |
| 22 |
{ |
| 23 |
class Control; |
| 24 |
|
| 25 |
class NumericSettingBase; |
| 26 |
struct NumericSettingDetails; |
| 27 |
|
| 28 |
template <typename T> |
| 29 |
class NumericSetting; |
| 30 |
|
| 31 |
template <typename T> |
| 32 |
class SettingValue; |
| 33 |
|
| 34 |
using InputOverrideFunction = std::function<std::optional<ControlState>( |
| 35 |
const std::string_view group_name, const std::string_view control_name, ControlState state)>; |
| 36 |
|
| 37 |
enum class GroupType |
| 38 |
{ |
| 39 |
Other, |
| 40 |
Stick, |
| 41 |
MixedTriggers, |
| 42 |
Buttons, |
| 43 |
Force, |
| 44 |
Attachments, |
| 45 |
Tilt, |
| 46 |
Cursor, |
| 47 |
Triggers, |
| 48 |
Slider, |
| 49 |
Shake, |
| 50 |
IMUAccelerometer, |
| 51 |
IMUGyroscope, |
| 52 |
IMUCursor, |
| 53 |
IRPassthrough, |
| 54 |
}; |
| 55 |
|
| 56 |
class ControlGroup |
| 57 |
{ |
| 58 |
public: |
| 59 |
enum class DefaultValue |
| 60 |
{ |
| 61 |
AlwaysEnabled, |
| 62 |
Enabled, |
| 63 |
Disabled, |
| 64 |
}; |
| 65 |
|
| 66 |
explicit ControlGroup(const std::string& name, GroupType type = GroupType::Other, |
| 67 |
DefaultValue default_value = DefaultValue::AlwaysEnabled); |
| 68 |
ControlGroup(std::string name, std::string ui_name, GroupType type = GroupType::Other, |
| 69 |
DefaultValue default_value = DefaultValue::AlwaysEnabled); |
| 70 |
virtual ~ControlGroup(); |
| 71 |
|
| 72 |
virtual void LoadConfig(Common::IniFile::Section* sec, const std::string& base); |
| 73 |
virtual void SaveConfig(Common::IniFile::Section* sec, const std::string& base); |
| 74 |
|
| 75 |
virtual void UpdateReferences(ciface::ExpressionParser::ControlEnvironment& env); |
| 76 |
|
| 77 |
void SetControlExpression(int index, const std::string& expression); |
| 78 |
|
| 79 |
void AddInput(Translatability translate, std::string name); |
| 80 |
void AddInput(Translatability translate, std::string name, std::string ui_name); |
| 81 |
void AddOutput(Translatability translate, std::string name); |
| 82 |
|
| 83 |
template <typename T> |
| 84 |
void AddSetting(SettingValue<T>* value, const NumericSettingDetails& details, |
| 85 |
std::common_type_t<T> default_value_, std::common_type_t<T> min_value = {}, |
| 86 |
std::common_type_t<T> max_value = T(100)) |
| 87 |
{ |
| 88 |
numeric_settings.emplace_back( |
| 89 |
std::make_unique<NumericSetting<T>>(value, details, default_value_, min_value, max_value)); |
| 90 |
} |
| 91 |
|
| 92 |
void AddVirtualNotchSetting(SettingValue<double>* value, double max_virtual_notch_deg); |
| 93 |
|
| 94 |
void AddDeadzoneSetting(SettingValue<double>* value, double maximum_deadzone); |
| 95 |
|
| 96 |
template <typename T> |
| 97 |
static T ApplyDeadzone(T input, std::common_type_t<T> deadzone) |
| 98 |
{ |
| 99 |
return std::copysign(std::max(T{0}, std::abs(input) - deadzone) / (T{1} - deadzone), input); |
| 100 |
} |
| 101 |
|
| 102 |
bool HasEnabledSetting() const; |
| 103 |
|
| 104 |
const std::string name; |
| 105 |
const std::string ui_name; |
| 106 |
const GroupType type; |
| 107 |
|
| 108 |
|
| 109 |
const DefaultValue default_value; |
| 110 |
SettingValue<bool> enabled; |
| 111 |
std::unique_ptr<NumericSetting<bool>> enabled_setting; |
| 112 |
|
| 113 |
std::vector<std::unique_ptr<Control>> controls; |
| 114 |
std::vector<std::unique_ptr<NumericSettingBase>> numeric_settings; |
| 115 |
}; |
| 116 |
} |