Use settings values for Input settings

This commit is contained in:
elsid 2023-07-22 00:52:37 +02:00
parent 5a27ccacb7
commit 6c18723bc7
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
13 changed files with 138 additions and 185 deletions

View file

@ -30,10 +30,8 @@ namespace Settings
SettingValue<float> mJoystickDeadZone{ mIndex, "Input", "joystick dead zone",
makeClampSanitizerFloat(0, 0.5f) };
SettingValue<bool> mEnableGyroscope{ mIndex, "Input", "enable gyroscope" };
SettingValue<std::string> mGyroHorizontalAxis{ mIndex, "Input", "gyro horizontal axis",
makeEnumSanitizerString({ "x", "y", "z", "-x", "-y", "-z" }) };
SettingValue<std::string> mGyroVerticalAxis{ mIndex, "Input", "gyro vertical axis",
makeEnumSanitizerString({ "x", "y", "z", "-x", "-y", "-z" }) };
SettingValue<GyroscopeAxis> mGyroHorizontalAxis{ mIndex, "Input", "gyro horizontal axis" };
SettingValue<GyroscopeAxis> mGyroVerticalAxis{ mIndex, "Input", "gyro vertical axis" };
SettingValue<float> mGyroInputThreshold{ mIndex, "Input", "gyro input threshold", makeMaxSanitizerFloat(0) };
SettingValue<float> mGyroHorizontalSensitivity{ mIndex, "Input", "gyro horizontal sensitivity",
makeMaxStrictSanitizerFloat(0) };

View file

@ -0,0 +1,17 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_GYROSCOPEAXIS_H
#define OPENMW_COMPONENTS_SETTINGS_GYROSCOPEAXIS_H
namespace Settings
{
enum class GyroscopeAxis
{
X,
Y,
Z,
MinusX,
MinusY,
MinusZ,
};
}
#endif

View file

@ -464,4 +464,21 @@ namespace Settings
sInitialized.emplace(category, setting);
}
GyroscopeAxis parseGyroscopeAxis(std::string_view value)
{
if (value == "x")
return GyroscopeAxis::X;
else if (value == "y")
return GyroscopeAxis::Y;
else if (value == "z")
return GyroscopeAxis::Z;
else if (value == "-x")
return GyroscopeAxis::MinusX;
else if (value == "-y")
return GyroscopeAxis::MinusY;
else if (value == "-z")
return GyroscopeAxis::MinusZ;
throw std::runtime_error("Invalid gyroscope axis: " + std::string(value));
}
}

View file

@ -2,6 +2,7 @@
#define COMPONENTS_SETTINGS_H
#include "categories.hpp"
#include "gyroscopeaxis.hpp"
#include "components/detournavigator/collisionshapetype.hpp"
@ -197,6 +198,14 @@ namespace Settings
{
return MyGUI::Colour::parse(getString(setting, category));
}
GyroscopeAxis parseGyroscopeAxis(std::string_view value);
template <>
inline GyroscopeAxis Manager::getImpl<GyroscopeAxis>(std::string_view setting, std::string_view category)
{
return parseGyroscopeAxis(getString(setting, category));
}
}
#endif // COMPONENTS_SETTINGS_H

View file

@ -1,6 +1,7 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H
#define OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H
#include "gyroscopeaxis.hpp"
#include "sanitizer.hpp"
#include "settings.hpp"
@ -36,6 +37,7 @@ namespace Settings
CollisionShapeType,
StringArray,
MyGuiColour,
GyroscopeAxis,
};
template <class T>
@ -131,6 +133,12 @@ namespace Settings
return SettingValueType::MyGuiColour;
}
template <>
inline constexpr SettingValueType getSettingValueType<GyroscopeAxis>()
{
return SettingValueType::GyroscopeAxis;
}
inline constexpr std::string_view getSettingValueTypeName(SettingValueType type)
{
switch (type)
@ -165,6 +173,8 @@ namespace Settings
return "string array";
case SettingValueType::MyGuiColour:
return "colour";
case SettingValueType::GyroscopeAxis:
return "gyroscope axis";
}
return "unsupported";
}