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
30 changed files with 127 additions and 122 deletions
+6 -6
View File
@@ -55,27 +55,27 @@ GCKeyboard::GCKeyboard(const unsigned int index) : m_index(index)
// buttons
groups.emplace_back(m_keys0x = new ControllerEmu::Buttons(_trans("Keys")));
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")));
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")));
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")));
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")));
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")));
for (const char* key : named_keys5)
m_keys5x->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, key));
m_keys5x->AddInput(ControllerEmu::DoNotTranslate, key);
// options
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
+6 -10
View File
@@ -59,8 +59,8 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
const ControllerEmu::Translatability translate =
is_start ? ControllerEmu::Translate : ControllerEmu::DoNotTranslate;
// i18n: The START/PAUSE button on GameCube controllers
const std::string& ui_name = is_start ? _trans("START") : named_button;
m_buttons->controls.emplace_back(new ControllerEmu::Input(translate, named_button, ui_name));
std::string ui_name = is_start ? _trans("START") : named_button;
m_buttons->AddInput(translate, named_button, std::move(ui_name));
}
// sticks
@@ -77,26 +77,22 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
for (const char* named_trigger : named_triggers)
{
m_triggers->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, named_trigger));
m_triggers->AddInput(ControllerEmu::Translate, named_trigger);
}
// rumble
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back(
new ControllerEmu::Output(ControllerEmu::Translate, _trans("Motor")));
m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));
// Microphone
groups.emplace_back(m_mic = new ControllerEmu::Buttons(_trans("Microphone")));
m_mic->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Button")));
m_mic->AddInput(ControllerEmu::Translate, _trans("Button"));
// dpad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
for (const char* named_direction : named_directions)
{
m_dpad->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, named_direction));
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
}
// options
@@ -6,6 +6,7 @@
#include <array>
#include <cassert>
#include <string_view>
#include "Common/BitUtils.h"
#include "Common/Common.h"
@@ -37,7 +38,7 @@ constexpr std::array<u16, 9> classic_button_bitmasks{{
Classic::BUTTON_HOME,
}};
constexpr std::array<const char*, 9> classic_button_names{{
constexpr std::array<std::string_view, 9> classic_button_names{{
"A",
"B",
"X",
@@ -76,11 +77,11 @@ Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller"))
{
// 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;
m_buttons->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::DoNotTranslate, button_name, ui_name));
std::string_view ui_name = (button_name == "Home") ? "HOME" : button_name;
m_buttons->AddInput(ControllerEmu::DoNotTranslate, std::string(button_name),
std::string(ui_name));
}
// sticks
@@ -94,16 +95,14 @@ Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller"))
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
for (const char* trigger_name : classic_trigger_names)
{
m_triggers->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, trigger_name));
m_triggers->AddInput(ControllerEmu::Translate, trigger_name);
}
// dpad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
for (const char* named_direction : named_directions)
{
m_dpad->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, named_direction));
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
}
}
@@ -29,8 +29,7 @@ DrawsomeTablet::DrawsomeTablet() : Extension3rdParty("Drawsome", _trans("Drawsom
// Touch
groups.emplace_back(m_touch = new ControllerEmu::Triggers(_trans("Touch")));
m_touch->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Pressure")));
m_touch->AddInput(ControllerEmu::Translate, _trans("Pressure"));
}
void DrawsomeTablet::Update()
@@ -58,8 +58,7 @@ Drums::Drums() : Extension1stParty("Drums", _trans("Drum Kit"))
groups.emplace_back(m_pads = new ControllerEmu::Buttons(_trans("Pads")));
for (auto& drum_pad_name : drum_pad_names)
{
m_pads->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, drum_pad_name));
m_pads->AddInput(ControllerEmu::Translate, drum_pad_name);
}
m_pads->AddSetting(&m_hit_strength_setting,
@@ -75,8 +74,8 @@ Drums::Drums() : Extension1stParty("Drums", _trans("Drum Kit"))
// Buttons.
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "-"));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "+"));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "-");
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "+");
}
void Drums::Update()
@@ -68,20 +68,18 @@ Guitar::Guitar() : Extension1stParty(_trans("Guitar"))
groups.emplace_back(m_frets = new ControllerEmu::Buttons(_trans("Frets")));
for (auto& guitar_fret_name : guitar_fret_names)
{
m_frets->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, guitar_fret_name));
m_frets->AddInput(ControllerEmu::Translate, guitar_fret_name);
}
// 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->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Down")));
m_strum->AddInput(ControllerEmu::Translate, _trans("Up"));
m_strum->AddInput(ControllerEmu::Translate, _trans("Down"));
// buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "-"));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "+"));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "-");
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "+");
// stick
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
@@ -90,8 +88,7 @@ Guitar::Guitar() : Extension1stParty(_trans("Guitar"))
// whammy
groups.emplace_back(m_whammy = new ControllerEmu::Triggers(_trans("Whammy")));
m_whammy->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Bar")));
m_whammy->AddInput(ControllerEmu::Translate, _trans("Bar"));
// slider bar
groups.emplace_back(m_slider_bar = new ControllerEmu::Slider(_trans("Slider Bar")));
@@ -37,8 +37,8 @@ Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk"))
{
// buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "C"));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Z"));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "C");
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "Z");
// stick
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
@@ -41,12 +41,12 @@ TaTaCon::TaTaCon() : Extension3rdParty("TaTaCon", _trans("Taiko Drum"))
// i18n: Refers to the "center" of a TaTaCon drum.
groups.emplace_back(m_center = new ControllerEmu::Buttons(_trans("Center")));
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.
groups.emplace_back(m_rim = new ControllerEmu::Buttons(_trans("Rim")));
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()
@@ -51,16 +51,14 @@ Turntable::Turntable() : Extension1stParty("Turntable", _trans("DJ Turntable"))
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (auto& turntable_button_name : turntable_button_names)
{
m_buttons->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, turntable_button_name));
m_buttons->AddInput(ControllerEmu::Translate, turntable_button_name);
}
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "-"));
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "+"));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "-");
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "+");
m_buttons->controls.emplace_back(
// i18n: This button name refers to a gameplay element in DJ Hero
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Euphoria")));
// i18n: This button name refers to a gameplay element in DJ Hero
m_buttons->AddInput(ControllerEmu::Translate, _trans("Euphoria"));
// turntables
// i18n: "Table" refers to a turntable
@@ -37,8 +37,7 @@ UDrawTablet::UDrawTablet() : Extension3rdParty("uDraw", _trans("uDraw GameTablet
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (auto& button_name : udraw_tablet_button_names)
{
m_buttons->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, button_name));
m_buttons->AddInput(ControllerEmu::Translate, button_name);
}
// Stylus
@@ -47,8 +46,7 @@ UDrawTablet::UDrawTablet() : Extension3rdParty("uDraw", _trans("uDraw GameTablet
// Touch
groups.emplace_back(m_touch = new ControllerEmu::Triggers(_trans("Touch")));
m_touch->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, _trans("Pressure")));
m_touch->AddInput(ControllerEmu::Translate, _trans("Pressure"));
}
void UDrawTablet::Update()
+9 -10
View File
@@ -7,6 +7,7 @@
#include <algorithm>
#include <cassert>
#include <memory>
#include <string_view>
#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,
Wiimote::PAD_DOWN};
static const char* const named_buttons[] = {
constexpr std::array<std::string_view, 7> named_buttons{
"A", "B", "1", "2", "-", "+", "Home",
};
@@ -198,11 +199,11 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
{
// 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;
m_buttons->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::DoNotTranslate, named_button, ui_name));
std::string_view ui_name = (named_button == "Home") ? "HOME" : named_button;
m_buttons->AddInput(ControllerEmu::DoNotTranslate, std::string(named_button),
std::string(ui_name));
}
// Pointing (IR)
@@ -233,15 +234,13 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
// Rumble
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back(
m_motor = new ControllerEmu::Output(ControllerEmu::Translate, _trans("Motor")));
m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));
// D-Pad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
for (const char* named_direction : named_directions)
{
m_dpad->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, named_direction));
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
}
// Options
@@ -780,7 +779,7 @@ bool Wiimote::IsUpright() const
void Wiimote::SetRumble(bool on)
{
const auto lock = GetStateLock();
m_motor->control_ref->State(on);
m_rumble->controls.front()->control_ref->State(on);
}
void Wiimote::StepDynamics()
@@ -253,7 +253,6 @@ private:
ControllerEmu::Tilt* m_tilt;
ControllerEmu::Force* m_swing;
ControllerEmu::ControlGroup* m_rumble;
ControllerEmu::Output* m_motor;
ControllerEmu::Attachments* m_attachments;
ControllerEmu::ControlGroup* m_options;
ControllerEmu::ModifySettingsButton* m_hotkeys;
+1 -2
View File
@@ -310,8 +310,7 @@ HotkeyManager::HotkeyManager()
groups.emplace_back(m_hotkey_groups[group]);
for (int key = s_groups_info[group].first; key <= s_groups_info[group].last; key++)
{
m_keys[group]->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::Translate, s_hotkey_labels[key]));
m_keys[group]->AddInput(ControllerEmu::Translate, s_hotkey_labels[key]);
}
}
}
@@ -10,14 +10,15 @@
namespace ControllerEmu
{
Control::Control(std::unique_ptr<ControlReference> ref, Translatability translate_,
const std::string& name_, const std::string& ui_name_)
: control_ref(std::move(ref)), translate(translate_), name(name_), ui_name(ui_name_)
std::string name_, std::string 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_,
const std::string& name_)
: Control(std::move(ref), translate_, name_, name_)
std::string name_)
: control_ref(std::move(ref)), translate(translate_), name(name_), ui_name(std::move(name_))
{
}
@@ -34,10 +34,9 @@ public:
const std::string ui_name;
protected:
Control(std::unique_ptr<ControlReference> ref, Translatability translate, const std::string& name,
const std::string& ui_name);
Control(std::unique_ptr<ControlReference> ref, Translatability translate,
const std::string& name);
Control(std::unique_ptr<ControlReference> ref, Translatability translate, std::string name,
std::string ui_name);
Control(std::unique_ptr<ControlReference> ref, Translatability translate, std::string name);
};
} // namespace ControllerEmu
@@ -10,13 +10,13 @@
namespace ControllerEmu
{
Input::Input(Translatability translate_, const std::string& name_, const std::string& ui_name_)
: Control(std::make_unique<InputReference>(), translate_, name_, ui_name_)
Input::Input(Translatability translate_, std::string name_, std::string ui_name_)
: Control(std::make_unique<InputReference>(), translate_, std::move(name_), std::move(ui_name_))
{
}
Input::Input(Translatability translate_, const std::string& name_)
: Control(std::make_unique<InputReference>(), translate_, name_)
Input::Input(Translatability translate_, std::string name_)
: Control(std::make_unique<InputReference>(), translate_, std::move(name_))
{
}
} // namespace ControllerEmu
@@ -12,7 +12,7 @@ namespace ControllerEmu
class Input : public Control
{
public:
Input(Translatability translate, const std::string& name, const std::string& ui_name);
Input(Translatability translate, const std::string& name);
Input(Translatability translate, std::string name, std::string ui_name);
Input(Translatability translate, std::string name);
};
} // namespace ControllerEmu
@@ -10,8 +10,8 @@
namespace ControllerEmu
{
Output::Output(Translatability translate_, const std::string& name_)
: Control(std::make_unique<OutputReference>(), translate_, name_)
Output::Output(Translatability translate_, std::string name_)
: Control(std::make_unique<OutputReference>(), translate_, std::move(name_))
{
}
} // namespace ControllerEmu
@@ -12,6 +12,6 @@ namespace ControllerEmu
class Output : public Control
{
public:
Output(Translatability translate, const std::string& name);
Output(Translatability translate, std::string name);
};
} // namespace ControllerEmu
@@ -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)

Some files were not shown because too many files have changed in this diff Show More