InputCommon: Clean up creation of inputs.

This commit is contained in:
Jordan Woyak
2019-10-27 11:04:08 -05:00
parent 01d69ba81a
commit 47877ecf2c
30 changed files with 127 additions and 122 deletions

View File

@ -27,9 +27,9 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
: ReshapableInput(name_, ui_name_, GroupType::Stick), m_stick_gate(std::move(stick_gate))
{
for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(Translate, named_direction));
AddInput(Translate, named_direction);
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Modifier")));
AddInput(Translate, _trans("Modifier"));
}
AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted)

View File

@ -8,7 +8,8 @@
#include "Common/IniFile.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/Control/Output.h"
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
@ -138,4 +139,20 @@ void ControlGroup::SetControlExpression(int index, const std::string& expression
{
controls.at(index)->control_ref->SetExpression(expression);
}
void ControlGroup::AddInput(Translatability translate, std::string name_)
{
controls.emplace_back(std::make_unique<Input>(translate, std::move(name_)));
}
void ControlGroup::AddInput(Translatability translate, std::string name_, std::string ui_name_)
{
controls.emplace_back(std::make_unique<Input>(translate, std::move(name_), std::move(ui_name_)));
}
void ControlGroup::AddOutput(Translatability translate, std::string name_)
{
controls.emplace_back(std::make_unique<Output>(translate, std::move(name_)));
}
} // namespace ControllerEmu

View File

@ -13,6 +13,7 @@
#include "Common/CommonTypes.h"
#include "Common/IniFile.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
namespace ControllerEmu
{
@ -67,6 +68,10 @@ public:
void SetControlExpression(int index, const std::string& expression);
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);
template <typename T>
void AddSetting(SettingValue<T>* value, const NumericSettingDetails& details,
std::common_type_t<T> default_value, std::common_type_t<T> min_value = {},

View File

@ -26,12 +26,12 @@ Cursor::Cursor(std::string name, std::string ui_name)
m_last_update(Clock::now())
{
for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(Translate, named_direction));
AddInput(Translate, named_direction);
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Hide")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Recenter")));
AddInput(Translate, _trans("Hide"));
AddInput(Translate, _trans("Recenter"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Relative Input Hold")));
AddInput(Translate, _trans("Relative Input Hold"));
// Default values are optimized for "Super Mario Galaxy 2".
// This seems to be acceptable for a good number of games.

View File

@ -18,12 +18,12 @@ namespace ControllerEmu
{
Force::Force(const std::string& name_) : ReshapableInput(name_, name_, GroupType::Force)
{
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Up")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Down")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Left")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Forward")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Backward")));
AddInput(Translate, _trans("Up"));
AddInput(Translate, _trans("Down"));
AddInput(Translate, _trans("Left"));
AddInput(Translate, _trans("Right"));
AddInput(Translate, _trans("Forward"));
AddInput(Translate, _trans("Backward"));
AddSetting(&m_distance_setting,
{_trans("Distance"),
@ -127,11 +127,11 @@ Shake::Shake(const std::string& name_, ControlState default_intensity_scale)
: ControlGroup(name_, name_, GroupType::Shake)
{
// i18n: Refers to a 3D axis (used when mapping motion controls)
controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, _trans("X")));
AddInput(ControllerEmu::Translate, _trans("X"));
// i18n: Refers to a 3D axis (used when mapping motion controls)
controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, _trans("Y")));
AddInput(ControllerEmu::Translate, _trans("Y"));
// i18n: Refers to a 3D axis (used when mapping motion controls)
controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, _trans("Z")));
AddInput(ControllerEmu::Translate, _trans("Z"));
AddDeadzoneSetting(&m_deadzone_setting, 50);

View File

@ -17,12 +17,12 @@ namespace ControllerEmu
IMUAccelerometer::IMUAccelerometer(std::string name, std::string ui_name)
: ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUAccelerometer)
{
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Up")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Down")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Left")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Forward")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Backward")));
AddInput(Translate, _trans("Up"));
AddInput(Translate, _trans("Down"));
AddInput(Translate, _trans("Left"));
AddInput(Translate, _trans("Right"));
AddInput(Translate, _trans("Forward"));
AddInput(Translate, _trans("Backward"));
}
std::optional<IMUAccelerometer::StateData> IMUAccelerometer::GetState() const

View File

@ -20,7 +20,7 @@ IMUCursor::IMUCursor(std::string name, std::string ui_name)
: ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUCursor,
ControlGroup::CanBeDisabled::Yes)
{
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Recenter")));
AddInput(Translate, _trans("Recenter"));
// Default values are optimized for "Super Mario Galaxy 2".
// This seems to be acceptable for a good number of games.

View File

@ -17,12 +17,12 @@ namespace ControllerEmu
IMUGyroscope::IMUGyroscope(std::string name, std::string ui_name)
: ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUGyroscope)
{
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Pitch Up")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Pitch Down")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Roll Left")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Roll Right")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Yaw Left")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Yaw Right")));
AddInput(Translate, _trans("Pitch Up"));
AddInput(Translate, _trans("Pitch Down"));
AddInput(Translate, _trans("Roll Left"));
AddInput(Translate, _trans("Roll Right"));
AddInput(Translate, _trans("Yaw Left"));
AddInput(Translate, _trans("Yaw Right"));
}
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState() const

View File

@ -25,7 +25,7 @@ ModifySettingsButton::ModifySettingsButton(std::string button_name)
void ModifySettingsButton::AddInput(std::string button_name, bool toggle)
{
controls.emplace_back(std::make_unique<Input>(Translate, std::move(button_name)));
ControlGroup::AddInput(Translate, std::move(button_name));
threshold_exceeded.emplace_back(false);
associated_settings.emplace_back(false);
associated_settings_toggle.emplace_back(toggle);

View File

@ -19,8 +19,8 @@ namespace ControllerEmu
Slider::Slider(const std::string& name_, const std::string& ui_name_)
: ControlGroup(name_, ui_name_, GroupType::Slider)
{
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Left")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right")));
AddInput(Translate, _trans("Left"));
AddInput(Translate, _trans("Right"));
AddDeadzoneSetting(&m_deadzone_setting, 50);
}

View File

@ -18,12 +18,12 @@ namespace ControllerEmu
{
Tilt::Tilt(const std::string& name_) : ReshapableInput(name_, name_, GroupType::Tilt)
{
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Forward")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Backward")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Left")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right")));
AddInput(Translate, _trans("Forward"));
AddInput(Translate, _trans("Backward"));
AddInput(Translate, _trans("Left"));
AddInput(Translate, _trans("Right"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Modifier")));
AddInput(Translate, _trans("Modifier"));
AddSetting(&m_max_angle_setting,
{_trans("Angle"),