Merge pull request #8617 from jordan-woyak/control-creation-cleanup

InputCommon: Clean up creation of inputs.
This commit is contained in:
Tilka 2020-02-10 02:05:24 +00:00 committed by GitHub
commit ce1bc0b3ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 127 additions and 122 deletions

View File

@ -55,27 +55,27 @@ GCKeyboard::GCKeyboard(const unsigned int index) : m_index(index)
// buttons // buttons
groups.emplace_back(m_keys0x = new ControllerEmu::Buttons(_trans("Keys"))); groups.emplace_back(m_keys0x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys0) for (const char* key : named_keys0)
m_keys0x->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, key)); m_keys0x->AddInput(ControllerEmu::DoNotTranslate, key);
groups.emplace_back(m_keys1x = new ControllerEmu::Buttons(_trans("Keys"))); groups.emplace_back(m_keys1x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys1) for (const char* key : named_keys1)
m_keys1x->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, key)); m_keys1x->AddInput(ControllerEmu::DoNotTranslate, key);
groups.emplace_back(m_keys2x = new ControllerEmu::Buttons(_trans("Keys"))); groups.emplace_back(m_keys2x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys2) for (const char* key : named_keys2)
m_keys2x->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, key)); m_keys2x->AddInput(ControllerEmu::DoNotTranslate, key);
groups.emplace_back(m_keys3x = new ControllerEmu::Buttons(_trans("Keys"))); groups.emplace_back(m_keys3x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys3) for (const char* key : named_keys3)
m_keys3x->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, key)); m_keys3x->AddInput(ControllerEmu::DoNotTranslate, key);
groups.emplace_back(m_keys4x = new ControllerEmu::Buttons(_trans("Keys"))); groups.emplace_back(m_keys4x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys4) for (const char* key : named_keys4)
m_keys4x->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, key)); m_keys4x->AddInput(ControllerEmu::DoNotTranslate, key);
groups.emplace_back(m_keys5x = new ControllerEmu::Buttons(_trans("Keys"))); groups.emplace_back(m_keys5x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys5) for (const char* key : named_keys5)
m_keys5x->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, key)); m_keys5x->AddInput(ControllerEmu::DoNotTranslate, key);
// options // options
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));

View File

@ -59,8 +59,8 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
const ControllerEmu::Translatability translate = const ControllerEmu::Translatability translate =
is_start ? ControllerEmu::Translate : ControllerEmu::DoNotTranslate; is_start ? ControllerEmu::Translate : ControllerEmu::DoNotTranslate;
// i18n: The START/PAUSE button on GameCube controllers // i18n: The START/PAUSE button on GameCube controllers
const std::string& ui_name = is_start ? _trans("START") : named_button; std::string ui_name = is_start ? _trans("START") : named_button;
m_buttons->controls.emplace_back(new ControllerEmu::Input(translate, named_button, ui_name)); m_buttons->AddInput(translate, named_button, std::move(ui_name));
} }
// sticks // sticks
@ -77,26 +77,22 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers"))); groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
for (const char* named_trigger : named_triggers) for (const char* named_trigger : named_triggers)
{ {
m_triggers->controls.emplace_back( m_triggers->AddInput(ControllerEmu::Translate, named_trigger);
new ControllerEmu::Input(ControllerEmu::Translate, named_trigger));
} }
// rumble // rumble
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble"))); groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back( m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));
new ControllerEmu::Output(ControllerEmu::Translate, _trans("Motor")));
// Microphone // Microphone
groups.emplace_back(m_mic = new ControllerEmu::Buttons(_trans("Microphone"))); groups.emplace_back(m_mic = new ControllerEmu::Buttons(_trans("Microphone")));
m_mic->controls.emplace_back( m_mic->AddInput(ControllerEmu::Translate, _trans("Button"));
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Button")));
// dpad // dpad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad"))); groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
for (const char* named_direction : named_directions) for (const char* named_direction : named_directions)
{ {
m_dpad->controls.emplace_back( m_dpad->AddInput(ControllerEmu::Translate, named_direction);
new ControllerEmu::Input(ControllerEmu::Translate, named_direction));
} }
// options // options

View File

@ -6,6 +6,7 @@
#include <array> #include <array>
#include <cassert> #include <cassert>
#include <string_view>
#include "Common/BitUtils.h" #include "Common/BitUtils.h"
#include "Common/Common.h" #include "Common/Common.h"
@ -37,7 +38,7 @@ constexpr std::array<u16, 9> classic_button_bitmasks{{
Classic::BUTTON_HOME, Classic::BUTTON_HOME,
}}; }};
constexpr std::array<const char*, 9> classic_button_names{{ constexpr std::array<std::string_view, 9> classic_button_names{{
"A", "A",
"B", "B",
"X", "X",
@ -76,11 +77,11 @@ Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller"))
{ {
// buttons // buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (const char* button_name : classic_button_names) for (auto& button_name : classic_button_names)
{ {
const std::string& ui_name = (button_name == std::string("Home")) ? "HOME" : button_name; std::string_view ui_name = (button_name == "Home") ? "HOME" : button_name;
m_buttons->controls.emplace_back( m_buttons->AddInput(ControllerEmu::DoNotTranslate, std::string(button_name),
new ControllerEmu::Input(ControllerEmu::DoNotTranslate, button_name, ui_name)); std::string(ui_name));
} }
// sticks // sticks
@ -94,16 +95,14 @@ Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller"))
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers"))); groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
for (const char* trigger_name : classic_trigger_names) for (const char* trigger_name : classic_trigger_names)
{ {
m_triggers->controls.emplace_back( m_triggers->AddInput(ControllerEmu::Translate, trigger_name);
new ControllerEmu::Input(ControllerEmu::Translate, trigger_name));
} }
// dpad // dpad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad"))); groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
for (const char* named_direction : named_directions) for (const char* named_direction : named_directions)
{ {
m_dpad->controls.emplace_back( m_dpad->AddInput(ControllerEmu::Translate, named_direction);
new ControllerEmu::Input(ControllerEmu::Translate, named_direction));
} }
} }

View File

@ -29,8 +29,7 @@ DrawsomeTablet::DrawsomeTablet() : Extension3rdParty("Drawsome", _trans("Drawsom
// Touch // Touch
groups.emplace_back(m_touch = new ControllerEmu::Triggers(_trans("Touch"))); groups.emplace_back(m_touch = new ControllerEmu::Triggers(_trans("Touch")));
m_touch->controls.emplace_back( m_touch->AddInput(ControllerEmu::Translate, _trans("Pressure"));
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Pressure")));
} }
void DrawsomeTablet::Update() void DrawsomeTablet::Update()

View File

@ -58,8 +58,7 @@ Drums::Drums() : Extension1stParty("Drums", _trans("Drum Kit"))
groups.emplace_back(m_pads = new ControllerEmu::Buttons(_trans("Pads"))); groups.emplace_back(m_pads = new ControllerEmu::Buttons(_trans("Pads")));
for (auto& drum_pad_name : drum_pad_names) for (auto& drum_pad_name : drum_pad_names)
{ {
m_pads->controls.emplace_back( m_pads->AddInput(ControllerEmu::Translate, drum_pad_name);
new ControllerEmu::Input(ControllerEmu::Translate, drum_pad_name));
} }
m_pads->AddSetting(&m_hit_strength_setting, m_pads->AddSetting(&m_hit_strength_setting,
@ -75,8 +74,8 @@ Drums::Drums() : Extension1stParty("Drums", _trans("Drum Kit"))
// Buttons. // Buttons.
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "-")); m_buttons->AddInput(ControllerEmu::DoNotTranslate, "-");
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "+")); m_buttons->AddInput(ControllerEmu::DoNotTranslate, "+");
} }
void Drums::Update() void Drums::Update()

View File

@ -68,20 +68,18 @@ Guitar::Guitar() : Extension1stParty(_trans("Guitar"))
groups.emplace_back(m_frets = new ControllerEmu::Buttons(_trans("Frets"))); groups.emplace_back(m_frets = new ControllerEmu::Buttons(_trans("Frets")));
for (auto& guitar_fret_name : guitar_fret_names) for (auto& guitar_fret_name : guitar_fret_names)
{ {
m_frets->controls.emplace_back( m_frets->AddInput(ControllerEmu::Translate, guitar_fret_name);
new ControllerEmu::Input(ControllerEmu::Translate, guitar_fret_name));
} }
// strum // strum
groups.emplace_back(m_strum = new ControllerEmu::Buttons(_trans("Strum"))); groups.emplace_back(m_strum = new ControllerEmu::Buttons(_trans("Strum")));
m_strum->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, _trans("Up"))); m_strum->AddInput(ControllerEmu::Translate, _trans("Up"));
m_strum->controls.emplace_back( m_strum->AddInput(ControllerEmu::Translate, _trans("Down"));
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Down")));
// buttons // buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "-")); m_buttons->AddInput(ControllerEmu::DoNotTranslate, "-");
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "+")); m_buttons->AddInput(ControllerEmu::DoNotTranslate, "+");
// stick // stick
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS; constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
@ -90,8 +88,7 @@ Guitar::Guitar() : Extension1stParty(_trans("Guitar"))
// whammy // whammy
groups.emplace_back(m_whammy = new ControllerEmu::Triggers(_trans("Whammy"))); groups.emplace_back(m_whammy = new ControllerEmu::Triggers(_trans("Whammy")));
m_whammy->controls.emplace_back( m_whammy->AddInput(ControllerEmu::Translate, _trans("Bar"));
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Bar")));
// slider bar // slider bar
groups.emplace_back(m_slider_bar = new ControllerEmu::Slider(_trans("Slider Bar"))); groups.emplace_back(m_slider_bar = new ControllerEmu::Slider(_trans("Slider Bar")));

View File

@ -37,8 +37,8 @@ Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk"))
{ {
// buttons // buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "C")); m_buttons->AddInput(ControllerEmu::DoNotTranslate, "C");
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Z")); m_buttons->AddInput(ControllerEmu::DoNotTranslate, "Z");
// stick // stick
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS; constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;

View File

@ -41,12 +41,12 @@ TaTaCon::TaTaCon() : Extension3rdParty("TaTaCon", _trans("Taiko Drum"))
// i18n: Refers to the "center" of a TaTaCon drum. // i18n: Refers to the "center" of a TaTaCon drum.
groups.emplace_back(m_center = new ControllerEmu::Buttons(_trans("Center"))); groups.emplace_back(m_center = new ControllerEmu::Buttons(_trans("Center")));
for (auto& name : position_names) for (auto& name : position_names)
m_center->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, name)); m_center->AddInput(ControllerEmu::Translate, name);
// i18n: Refers to the "rim" of a TaTaCon drum. // i18n: Refers to the "rim" of a TaTaCon drum.
groups.emplace_back(m_rim = new ControllerEmu::Buttons(_trans("Rim"))); groups.emplace_back(m_rim = new ControllerEmu::Buttons(_trans("Rim")));
for (auto& name : position_names) for (auto& name : position_names)
m_rim->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, name)); m_rim->AddInput(ControllerEmu::Translate, name);
} }
void TaTaCon::Update() void TaTaCon::Update()

View File

@ -51,16 +51,14 @@ Turntable::Turntable() : Extension1stParty("Turntable", _trans("DJ Turntable"))
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (auto& turntable_button_name : turntable_button_names) for (auto& turntable_button_name : turntable_button_names)
{ {
m_buttons->controls.emplace_back( m_buttons->AddInput(ControllerEmu::Translate, turntable_button_name);
new ControllerEmu::Input(ControllerEmu::Translate, turntable_button_name));
} }
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "-")); m_buttons->AddInput(ControllerEmu::DoNotTranslate, "-");
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "+")); m_buttons->AddInput(ControllerEmu::DoNotTranslate, "+");
m_buttons->controls.emplace_back(
// i18n: This button name refers to a gameplay element in DJ Hero // i18n: This button name refers to a gameplay element in DJ Hero
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Euphoria"))); m_buttons->AddInput(ControllerEmu::Translate, _trans("Euphoria"));
// turntables // turntables
// i18n: "Table" refers to a turntable // i18n: "Table" refers to a turntable

View File

@ -37,8 +37,7 @@ UDrawTablet::UDrawTablet() : Extension3rdParty("uDraw", _trans("uDraw GameTablet
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (auto& button_name : udraw_tablet_button_names) for (auto& button_name : udraw_tablet_button_names)
{ {
m_buttons->controls.emplace_back( m_buttons->AddInput(ControllerEmu::Translate, button_name);
new ControllerEmu::Input(ControllerEmu::Translate, button_name));
} }
// Stylus // Stylus
@ -47,8 +46,7 @@ UDrawTablet::UDrawTablet() : Extension3rdParty("uDraw", _trans("uDraw GameTablet
// Touch // Touch
groups.emplace_back(m_touch = new ControllerEmu::Triggers(_trans("Touch"))); groups.emplace_back(m_touch = new ControllerEmu::Triggers(_trans("Touch")));
m_touch->controls.emplace_back( m_touch->AddInput(ControllerEmu::Translate, _trans("Pressure"));
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Pressure")));
} }
void UDrawTablet::Update() void UDrawTablet::Update()

View File

@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <memory> #include <memory>
#include <string_view>
#include <fmt/format.h> #include <fmt/format.h>
@ -62,7 +63,7 @@ static const u16 dpad_bitmasks[] = {Wiimote::PAD_UP, Wiimote::PAD_DOWN, Wiimote:
static const u16 dpad_sideways_bitmasks[] = {Wiimote::PAD_RIGHT, Wiimote::PAD_LEFT, Wiimote::PAD_UP, static const u16 dpad_sideways_bitmasks[] = {Wiimote::PAD_RIGHT, Wiimote::PAD_LEFT, Wiimote::PAD_UP,
Wiimote::PAD_DOWN}; Wiimote::PAD_DOWN};
static const char* const named_buttons[] = { constexpr std::array<std::string_view, 7> named_buttons{
"A", "B", "1", "2", "-", "+", "Home", "A", "B", "1", "2", "-", "+", "Home",
}; };
@ -198,11 +199,11 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
{ {
// Buttons // Buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (const char* named_button : named_buttons) for (auto& named_button : named_buttons)
{ {
const std::string& ui_name = (named_button == std::string("Home")) ? "HOME" : named_button; std::string_view ui_name = (named_button == "Home") ? "HOME" : named_button;
m_buttons->controls.emplace_back( m_buttons->AddInput(ControllerEmu::DoNotTranslate, std::string(named_button),
new ControllerEmu::Input(ControllerEmu::DoNotTranslate, named_button, ui_name)); std::string(ui_name));
} }
// Pointing (IR) // Pointing (IR)
@ -233,15 +234,13 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
// Rumble // Rumble
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble"))); groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back( m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));
m_motor = new ControllerEmu::Output(ControllerEmu::Translate, _trans("Motor")));
// D-Pad // D-Pad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad"))); groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
for (const char* named_direction : named_directions) for (const char* named_direction : named_directions)
{ {
m_dpad->controls.emplace_back( m_dpad->AddInput(ControllerEmu::Translate, named_direction);
new ControllerEmu::Input(ControllerEmu::Translate, named_direction));
} }
// Options // Options
@ -780,7 +779,7 @@ bool Wiimote::IsUpright() const
void Wiimote::SetRumble(bool on) void Wiimote::SetRumble(bool on)
{ {
const auto lock = GetStateLock(); const auto lock = GetStateLock();
m_motor->control_ref->State(on); m_rumble->controls.front()->control_ref->State(on);
} }
void Wiimote::StepDynamics() void Wiimote::StepDynamics()

View File

@ -253,7 +253,6 @@ private:
ControllerEmu::Tilt* m_tilt; ControllerEmu::Tilt* m_tilt;
ControllerEmu::Force* m_swing; ControllerEmu::Force* m_swing;
ControllerEmu::ControlGroup* m_rumble; ControllerEmu::ControlGroup* m_rumble;
ControllerEmu::Output* m_motor;
ControllerEmu::Attachments* m_attachments; ControllerEmu::Attachments* m_attachments;
ControllerEmu::ControlGroup* m_options; ControllerEmu::ControlGroup* m_options;
ControllerEmu::ModifySettingsButton* m_hotkeys; ControllerEmu::ModifySettingsButton* m_hotkeys;

View File

@ -310,8 +310,7 @@ HotkeyManager::HotkeyManager()
groups.emplace_back(m_hotkey_groups[group]); groups.emplace_back(m_hotkey_groups[group]);
for (int key = s_groups_info[group].first; key <= s_groups_info[group].last; key++) for (int key = s_groups_info[group].first; key <= s_groups_info[group].last; key++)
{ {
m_keys[group]->controls.emplace_back( m_keys[group]->AddInput(ControllerEmu::Translate, s_hotkey_labels[key]);
new ControllerEmu::Input(ControllerEmu::Translate, s_hotkey_labels[key]));
} }
} }
} }

View File

@ -10,14 +10,15 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Control::Control(std::unique_ptr<ControlReference> ref, Translatability translate_, Control::Control(std::unique_ptr<ControlReference> ref, Translatability translate_,
const std::string& name_, const std::string& ui_name_) std::string name_, std::string ui_name_)
: control_ref(std::move(ref)), translate(translate_), name(name_), ui_name(ui_name_) : control_ref(std::move(ref)), translate(translate_), name(std::move(name_)),
ui_name(std::move(ui_name_))
{ {
} }
Control::Control(std::unique_ptr<ControlReference> ref, Translatability translate_, Control::Control(std::unique_ptr<ControlReference> ref, Translatability translate_,
const std::string& name_) std::string name_)
: Control(std::move(ref), translate_, name_, name_) : control_ref(std::move(ref)), translate(translate_), name(name_), ui_name(std::move(name_))
{ {
} }

View File

@ -34,10 +34,9 @@ public:
const std::string ui_name; const std::string ui_name;
protected: protected:
Control(std::unique_ptr<ControlReference> ref, Translatability translate, const std::string& name, Control(std::unique_ptr<ControlReference> ref, Translatability translate, std::string name,
const std::string& ui_name); std::string ui_name);
Control(std::unique_ptr<ControlReference> ref, Translatability translate, Control(std::unique_ptr<ControlReference> ref, Translatability translate, std::string name);
const std::string& name);
}; };
} // namespace ControllerEmu } // namespace ControllerEmu

View File

@ -10,13 +10,13 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Input::Input(Translatability translate_, const std::string& name_, const std::string& ui_name_) Input::Input(Translatability translate_, std::string name_, std::string ui_name_)
: Control(std::make_unique<InputReference>(), translate_, name_, ui_name_) : Control(std::make_unique<InputReference>(), translate_, std::move(name_), std::move(ui_name_))
{ {
} }
Input::Input(Translatability translate_, const std::string& name_) Input::Input(Translatability translate_, std::string name_)
: Control(std::make_unique<InputReference>(), translate_, name_) : Control(std::make_unique<InputReference>(), translate_, std::move(name_))
{ {
} }
} // namespace ControllerEmu } // namespace ControllerEmu

View File

@ -12,7 +12,7 @@ namespace ControllerEmu
class Input : public Control class Input : public Control
{ {
public: public:
Input(Translatability translate, const std::string& name, const std::string& ui_name); Input(Translatability translate, std::string name, std::string ui_name);
Input(Translatability translate, const std::string& name); Input(Translatability translate, std::string name);
}; };
} // namespace ControllerEmu } // namespace ControllerEmu

View File

@ -10,8 +10,8 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Output::Output(Translatability translate_, const std::string& name_) Output::Output(Translatability translate_, std::string name_)
: Control(std::make_unique<OutputReference>(), translate_, name_) : Control(std::make_unique<OutputReference>(), translate_, std::move(name_))
{ {
} }
} // namespace ControllerEmu } // namespace ControllerEmu

View File

@ -12,6 +12,6 @@ namespace ControllerEmu
class Output : public Control class Output : public Control
{ {
public: public:
Output(Translatability translate, const std::string& name); Output(Translatability translate, std::string name);
}; };
} // namespace ControllerEmu } // namespace ControllerEmu

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)) : ReshapableInput(name_, ui_name_, GroupType::Stick), m_stick_gate(std::move(stick_gate))
{ {
for (auto& named_direction : named_directions) 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) AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted)

View File

@ -8,7 +8,8 @@
#include "Common/IniFile.h" #include "Common/IniFile.h"
#include "InputCommon/ControlReference/ControlReference.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/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.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); 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 } // namespace ControllerEmu

View File

@ -13,6 +13,7 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/IniFile.h" #include "Common/IniFile.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
namespace ControllerEmu namespace ControllerEmu
{ {
@ -67,6 +68,10 @@ public:
void SetControlExpression(int index, const std::string& expression); 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> template <typename T>
void AddSetting(SettingValue<T>* value, const NumericSettingDetails& details, void AddSetting(SettingValue<T>* value, const NumericSettingDetails& details,
std::common_type_t<T> default_value, std::common_type_t<T> min_value = {}, 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()) m_last_update(Clock::now())
{ {
for (auto& named_direction : named_directions) 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"))); AddInput(Translate, _trans("Hide"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Recenter"))); 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". // Default values are optimized for "Super Mario Galaxy 2".
// This seems to be acceptable for a good number of games. // 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) Force::Force(const std::string& name_) : ReshapableInput(name_, name_, GroupType::Force)
{ {
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Up"))); AddInput(Translate, _trans("Up"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Down"))); AddInput(Translate, _trans("Down"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Left"))); AddInput(Translate, _trans("Left"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right"))); AddInput(Translate, _trans("Right"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Forward"))); AddInput(Translate, _trans("Forward"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Backward"))); AddInput(Translate, _trans("Backward"));
AddSetting(&m_distance_setting, AddSetting(&m_distance_setting,
{_trans("Distance"), {_trans("Distance"),
@ -127,11 +127,11 @@ Shake::Shake(const std::string& name_, ControlState default_intensity_scale)
: ControlGroup(name_, name_, GroupType::Shake) : ControlGroup(name_, name_, GroupType::Shake)
{ {
// i18n: Refers to a 3D axis (used when mapping motion controls) // 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) // 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) // 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); AddDeadzoneSetting(&m_deadzone_setting, 50);

View File

@ -17,12 +17,12 @@ namespace ControllerEmu
IMUAccelerometer::IMUAccelerometer(std::string name, std::string ui_name) IMUAccelerometer::IMUAccelerometer(std::string name, std::string ui_name)
: ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUAccelerometer) : ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUAccelerometer)
{ {
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Up"))); AddInput(Translate, _trans("Up"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Down"))); AddInput(Translate, _trans("Down"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Left"))); AddInput(Translate, _trans("Left"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right"))); AddInput(Translate, _trans("Right"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Forward"))); AddInput(Translate, _trans("Forward"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Backward"))); AddInput(Translate, _trans("Backward"));
} }
std::optional<IMUAccelerometer::StateData> IMUAccelerometer::GetState() const 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(std::move(name), std::move(ui_name), GroupType::IMUCursor,
ControlGroup::CanBeDisabled::Yes) 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". // Default values are optimized for "Super Mario Galaxy 2".
// This seems to be acceptable for a good number of games. // 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) IMUGyroscope::IMUGyroscope(std::string name, std::string ui_name)
: ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUGyroscope) : ControlGroup(std::move(name), std::move(ui_name), GroupType::IMUGyroscope)
{ {
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Pitch Up"))); AddInput(Translate, _trans("Pitch Up"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Pitch Down"))); AddInput(Translate, _trans("Pitch Down"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Roll Left"))); AddInput(Translate, _trans("Roll Left"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Roll Right"))); AddInput(Translate, _trans("Roll Right"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Yaw Left"))); AddInput(Translate, _trans("Yaw Left"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Yaw Right"))); AddInput(Translate, _trans("Yaw Right"));
} }
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState() const 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) 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); threshold_exceeded.emplace_back(false);
associated_settings.emplace_back(false); associated_settings.emplace_back(false);
associated_settings_toggle.emplace_back(toggle); 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_) Slider::Slider(const std::string& name_, const std::string& ui_name_)
: ControlGroup(name_, ui_name_, GroupType::Slider) : ControlGroup(name_, ui_name_, GroupType::Slider)
{ {
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Left"))); AddInput(Translate, _trans("Left"));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right"))); AddInput(Translate, _trans("Right"));
AddDeadzoneSetting(&m_deadzone_setting, 50); AddDeadzoneSetting(&m_deadzone_setting, 50);
} }

View File

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