ControllerEmu: Add default mappings for Android

Unlike PCs, Android doesn't really have any input method (not counting
touch) that can reasonably be expected to exist on most devices.
Because of this, I don't think shipping with a default mapping for the
buttons and sticks of GameCube controllers and Wii Remotes makes sense.
I would however like to ship default mappings for a few things:

1. Mapping the Wii Remote's accelerometer and gyroscope to the device's
   accelerometer and gyroscope. This functionality is useful mainly
   for people who use the touchscreen, but can also be useful when
   using a clip-on controller. The disadvantage of having this mapped
   by default is that games disable pointer input if the accelerometer
   reports that the Wii Remote is pointed at the ceiling.

2. Mapping GC keyboards for use with a physical keyboard, like on PC.
   After all, there's no other way of mapping them that makes sense.

3. Mapping rumble to the device's vibrator.

Aside from the GC keyboards, this approach is effectively the same as
what we were doing before the input overhaul.
This commit is contained in:
JosJuice 2022-02-05 15:09:45 +01:00
parent 8e33458f48
commit e0562abb7d
6 changed files with 80 additions and 9 deletions

View File

@ -120,6 +120,7 @@ void FreeLookController::LoadDefaults(const ControllerInterface& ciface)
{ {
EmulatedController::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);
#ifndef ANDROID
auto hotkey_string = [](std::vector<std::string> inputs) { auto hotkey_string = [](std::vector<std::string> inputs) {
return "@(" + JoinStrings(inputs, "+") + ')'; return "@(" + JoinStrings(inputs, "+") + ')';
}; };
@ -194,6 +195,7 @@ void FreeLookController::LoadDefaults(const ControllerInterface& ciface)
m_rotation_gyro->SetControlExpression(GyroButtons::YawRight, m_rotation_gyro->SetControlExpression(GyroButtons::YawRight,
"if(`Click 1`,`RelativeMouse X+` * 0.10, 0)"); "if(`Click 1`,`RelativeMouse X+` * 0.10, 0)");
#endif #endif
#endif
} }
ControllerEmu::ControlGroup* FreeLookController::GetGroup(FreeLookGroup group) const ControllerEmu::ControlGroup* FreeLookController::GetGroup(FreeLookGroup group) const

View File

@ -83,6 +83,7 @@ void GBAPad::LoadDefaults(const ControllerInterface& ciface)
{ {
EmulatedController::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);
#ifndef ANDROID
// Buttons // Buttons
m_buttons->SetControlExpression(0, "`Z`"); // B m_buttons->SetControlExpression(0, "`Z`"); // B
m_buttons->SetControlExpression(1, "`X`"); // A m_buttons->SetControlExpression(1, "`X`"); // A
@ -101,4 +102,5 @@ void GBAPad::LoadDefaults(const ControllerInterface& ciface)
m_dpad->SetControlExpression(1, "`G`"); // Down m_dpad->SetControlExpression(1, "`G`"); // Down
m_dpad->SetControlExpression(2, "`F`"); // Left m_dpad->SetControlExpression(2, "`F`"); // Left
m_dpad->SetControlExpression(3, "`H`"); // Right m_dpad->SetControlExpression(3, "`H`"); // Right
#endif
} }

View File

@ -257,6 +257,47 @@ void GCKeyboard::LoadDefaults(const ControllerInterface& ciface)
m_keys5x->SetControlExpression(2, "`Up Arrow`"); m_keys5x->SetControlExpression(2, "`Up Arrow`");
m_keys5x->SetControlExpression(3, "`Right Arrow`"); m_keys5x->SetControlExpression(3, "`Right Arrow`");
m_keys5x->SetControlExpression(4, "Return"); m_keys5x->SetControlExpression(4, "Return");
#elif ANDROID
m_keys0x->SetControlExpression(0, "`Move Home`");
m_keys0x->SetControlExpression(1, "`Move End`");
m_keys0x->SetControlExpression(2, "`Page Up`");
m_keys0x->SetControlExpression(3, "`Page Down`");
m_keys0x->SetControlExpression(4, "`Scroll Lock`");
m_keys2x->SetControlExpression(9, "`Minus`");
m_keys2x->SetControlExpression(10, "`Grave`");
m_keys2x->SetControlExpression(11, "`PrtSc SysRq`");
m_keys2x->SetControlExpression(12, "`Apostrophe`");
m_keys2x->SetControlExpression(13, "`Left Bracket`");
m_keys2x->SetControlExpression(14, "``Equals``");
m_keys2x->SetControlExpression(15, "`Numpad Multiply`");
m_keys3x->SetControlExpression(0, "`Right Bracket`");
m_keys3x->SetControlExpression(1, "`Comma`");
m_keys3x->SetControlExpression(2, "`Period`");
m_keys3x->SetControlExpression(3, "`Slash`");
m_keys3x->SetControlExpression(4, "`Backslash`");
m_keys4x->SetControlExpression(1, "`Escape`");
m_keys4x->SetControlExpression(2, "`Insert`");
m_keys4x->SetControlExpression(3, "`Delete`");
m_keys4x->SetControlExpression(4, "`Semicolon`");
m_keys4x->SetControlExpression(5, "`Backspace`");
m_keys4x->SetControlExpression(6, "`Tab`");
m_keys4x->SetControlExpression(7, "`Caps Lock`");
m_keys4x->SetControlExpression(8, "`Left Shift`");
m_keys4x->SetControlExpression(9, "`Right Shift`");
m_keys4x->SetControlExpression(10, "`Left Ctrl`");
m_keys4x->SetControlExpression(11, "`Right Alt`");
m_keys4x->SetControlExpression(12, "`Left Meta`");
m_keys4x->SetControlExpression(13, "`Space`");
m_keys4x->SetControlExpression(14, "`Right Meta`");
m_keys4x->SetControlExpression(15, "`Menu`");
m_keys5x->SetControlExpression(0, "`Left`");
m_keys5x->SetControlExpression(1, "`Down`");
m_keys5x->SetControlExpression(2, "`Up`");
m_keys5x->SetControlExpression(3, "`Right`");
m_keys5x->SetControlExpression(4, "`Enter`");
#else // linux #else // linux
m_keys0x->SetControlExpression(0, "Home"); m_keys0x->SetControlExpression(0, "Home");
m_keys0x->SetControlExpression(1, "End"); m_keys0x->SetControlExpression(1, "End");

View File

@ -170,12 +170,16 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface)
{ {
EmulatedController::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);
#ifdef ANDROID
// Rumble
m_rumble->SetControlExpression(0, "`Android/0/Device Sensors:Motor 0`");
#else
// Buttons // Buttons
m_buttons->SetControlExpression(0, "`X`"); // A m_buttons->SetControlExpression(0, "`X`"); // A
m_buttons->SetControlExpression(1, "`Z`"); // B m_buttons->SetControlExpression(1, "`Z`"); // B
m_buttons->SetControlExpression(2, "`C`"); // X m_buttons->SetControlExpression(2, "`C`"); // X
m_buttons->SetControlExpression(3, "`S`"); // Y m_buttons->SetControlExpression(3, "`S`"); // Y
m_buttons->SetControlExpression(4, "`D`"); // Z m_buttons->SetControlExpression(4, "`D`"); // Z
#ifdef _WIN32 #ifdef _WIN32
m_buttons->SetControlExpression(5, "`RETURN`"); // Start m_buttons->SetControlExpression(5, "`RETURN`"); // Start
#else #else
@ -225,6 +229,7 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface)
// Triggers // Triggers
m_triggers->SetControlExpression(0, "`Q`"); // L m_triggers->SetControlExpression(0, "`Q`"); // L
m_triggers->SetControlExpression(1, "`W`"); // R m_triggers->SetControlExpression(1, "`W`"); // R
#endif
} }
bool GCPad::GetMicButton() const bool GCPad::GetMicButton() const

View File

@ -198,6 +198,7 @@ void Nunchuk::DoState(PointerWrap& p)
void Nunchuk::LoadDefaults(const ControllerInterface& ciface) void Nunchuk::LoadDefaults(const ControllerInterface& ciface)
{ {
#ifndef ANDROID
// Stick // Stick
m_stick->SetControlExpression(0, "W"); // up m_stick->SetControlExpression(0, "W"); // up
m_stick->SetControlExpression(1, "S"); // down m_stick->SetControlExpression(1, "S"); // down
@ -228,5 +229,6 @@ void Nunchuk::LoadDefaults(const ControllerInterface& ciface)
m_shake->SetControlExpression(i, "`Click 2`"); m_shake->SetControlExpression(i, "`Click 2`");
#endif #endif
} }
#endif
} }
} // namespace WiimoteEmu } // namespace WiimoteEmu

View File

@ -655,6 +655,24 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
{ {
EmulatedController::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);
#ifdef ANDROID
// Rumble
m_rumble->SetControlExpression(0, "`Android/0/Device Sensors:Motor 0`");
// Motion Source
m_imu_accelerometer->SetControlExpression(0, "`Android/0/Device Sensors:Accel Up`");
m_imu_accelerometer->SetControlExpression(1, "`Android/0/Device Sensors:Accel Down`");
m_imu_accelerometer->SetControlExpression(2, "`Android/0/Device Sensors:Accel Left`");
m_imu_accelerometer->SetControlExpression(3, "`Android/0/Device Sensors:Accel Right`");
m_imu_accelerometer->SetControlExpression(4, "`Android/0/Device Sensors:Accel Forward`");
m_imu_accelerometer->SetControlExpression(5, "`Android/0/Device Sensors:Accel Backward`");
m_imu_gyroscope->SetControlExpression(0, "`Android/0/Device Sensors:Gyro Pitch Up`");
m_imu_gyroscope->SetControlExpression(1, "`Android/0/Device Sensors:Gyro Pitch Down`");
m_imu_gyroscope->SetControlExpression(2, "`Android/0/Device Sensors:Gyro Roll Left`");
m_imu_gyroscope->SetControlExpression(3, "`Android/0/Device Sensors:Gyro Roll Right`");
m_imu_gyroscope->SetControlExpression(4, "`Android/0/Device Sensors:Gyro Yaw Left`");
m_imu_gyroscope->SetControlExpression(5, "`Android/0/Device Sensors:Gyro Yaw Right`");
#else
// Buttons // Buttons
#if defined HAVE_X11 && HAVE_X11 #if defined HAVE_X11 && HAVE_X11
// A // A
@ -672,10 +690,10 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
// B // B
m_buttons->SetControlExpression(1, "`Click 1`"); m_buttons->SetControlExpression(1, "`Click 1`");
#endif #endif
m_buttons->SetControlExpression(2, "`1`"); // 1 m_buttons->SetControlExpression(2, "`1`"); // 1
m_buttons->SetControlExpression(3, "`2`"); // 2 m_buttons->SetControlExpression(3, "`2`"); // 2
m_buttons->SetControlExpression(4, "Q"); // - m_buttons->SetControlExpression(4, "Q"); // -
m_buttons->SetControlExpression(5, "E"); // + m_buttons->SetControlExpression(5, "E"); // +
#ifdef _WIN32 #ifdef _WIN32
m_buttons->SetControlExpression(6, "RETURN"); // Home m_buttons->SetControlExpression(6, "RETURN"); // Home
@ -729,6 +747,7 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
m_imu_gyroscope->SetControlExpression(3, "`Gyro Roll Right`"); m_imu_gyroscope->SetControlExpression(3, "`Gyro Roll Right`");
m_imu_gyroscope->SetControlExpression(4, "`Gyro Yaw Left`"); m_imu_gyroscope->SetControlExpression(4, "`Gyro Yaw Left`");
m_imu_gyroscope->SetControlExpression(5, "`Gyro Yaw Right`"); m_imu_gyroscope->SetControlExpression(5, "`Gyro Yaw Right`");
#endif
// Enable Nunchuk: // Enable Nunchuk:
constexpr ExtensionNumber DEFAULT_EXT = ExtensionNumber::NUNCHUK; constexpr ExtensionNumber DEFAULT_EXT = ExtensionNumber::NUNCHUK;