Skip to content

Commit

Permalink
Merge pull request #12215 from JosJuice/android-si-devices
Browse files Browse the repository at this point in the history
Android: Add more GameCube controller types
  • Loading branch information
lioncash committed Nov 28, 2023
2 parents bfc6bca + d811c12 commit ac53766
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 37 deletions.
Expand Up @@ -30,10 +30,15 @@ class EmulatedController private constructor(private val pointer: Long) {

external fun saveProfile(path: String)

external fun getProfileName(): String

companion object {
@JvmStatic
external fun getGcPad(controllerIndex: Int): EmulatedController

@JvmStatic
external fun getGcKeyboard(controllerIndex: Int): EmulatedController

@JvmStatic
external fun getWiimote(controllerIndex: Int): EmulatedController

Expand Down
Expand Up @@ -100,15 +100,14 @@ class ProfileDialogPresenter {
.show()
}

private val profileDirectoryName: String
get() = if (menuTag.isGCPadMenu) "GCPad" else if (menuTag.isWiimoteMenu) "Wiimote" else throw UnsupportedOperationException()

private fun getProfileDirectoryPath(stock: Boolean): String =
if (stock) {
private fun getProfileDirectoryPath(stock: Boolean): String {
val profileDirectoryName = menuTag.correspondingEmulatedController.getProfileName()
return if (stock) {
"${DirectoryInitialization.getSysDirectory()}/Profiles/$profileDirectoryName/"
} else {
"${DirectoryInitialization.getUserDirectory()}/Config/Profiles/$profileDirectoryName/"
}
}

private fun getProfilePath(profileName: String, stock: Boolean): String =
getProfileDirectoryPath(stock) + profileName + EXTENSION
Expand Down
Expand Up @@ -2079,42 +2079,57 @@ class SettingsFragmentPresenter(
}

private fun addGcPadSubSettings(sl: ArrayList<SettingsItem>, gcPadNumber: Int, gcPadType: Int) {
if (gcPadType == 6) {
// Emulated
val gcPad = EmulatedController.getGcPad(gcPadNumber)
when (gcPadType) {
6, 8, 9, 10 -> {
// Emulated
val gcPad = EmulatedController.getGcPad(gcPadNumber)

if (!TextUtils.isEmpty(gameId)) {
addControllerPerGameSettings(sl, "Pad", gcPadNumber)
} else {
addControllerMetaSettings(sl, gcPad)
addControllerMappingSettings(sl, gcPad, null)
if (!TextUtils.isEmpty(gameId)) {
addControllerPerGameSettings(sl, gcPad, gcPadNumber)
} else {
addControllerMetaSettings(sl, gcPad)
addControllerMappingSettings(sl, gcPad, null)
}
}
} else if (gcPadType == 12) {
// Adapter
sl.add(
SwitchSetting(
context,
BooleanSetting.getSettingForAdapterRumble(gcPadNumber),
R.string.gc_adapter_rumble,
R.string.gc_adapter_rumble_description
7 -> {
// Emulated keyboard controller
val gcKeyboard = EmulatedController.getGcKeyboard(gcPadNumber)

if (!TextUtils.isEmpty(gameId)) {
addControllerPerGameSettings(sl, gcKeyboard, gcPadNumber)
} else {
sl.add(HeaderSetting(context, R.string.keyboard_controller_warning, 0))
addControllerMetaSettings(sl, gcKeyboard)
addControllerMappingSettings(sl, gcKeyboard, null)
}
}
12 -> {
// Adapter
sl.add(
SwitchSetting(
context,
BooleanSetting.getSettingForAdapterRumble(gcPadNumber),
R.string.gc_adapter_rumble,
R.string.gc_adapter_rumble_description
)
)
)
sl.add(
SwitchSetting(
context,
BooleanSetting.getSettingForSimulateKonga(gcPadNumber),
R.string.gc_adapter_bongos,
R.string.gc_adapter_bongos_description
sl.add(
SwitchSetting(
context,
BooleanSetting.getSettingForSimulateKonga(gcPadNumber),
R.string.gc_adapter_bongos,
R.string.gc_adapter_bongos_description
)
)
)
}
}
}

private fun addWiimoteSubSettings(sl: ArrayList<SettingsItem>, wiimoteNumber: Int) {
val wiimote = EmulatedController.getWiimote(wiimoteNumber)

if (!TextUtils.isEmpty(gameId)) {
addControllerPerGameSettings(sl, "Wiimote", wiimoteNumber)
addControllerPerGameSettings(sl, wiimote, wiimoteNumber)
} else {
addControllerMetaSettings(sl, wiimote)

Expand Down Expand Up @@ -2210,11 +2225,11 @@ class SettingsFragmentPresenter(
*/
private fun addControllerPerGameSettings(
sl: ArrayList<SettingsItem>,
profileString: String,
controller: EmulatedController,
controllerNumber: Int
) {
val profiles = ProfileDialogPresenter(menuTag).getProfileNames(false)
val profileKey = profileString + "Profile" + (controllerNumber + 1)
val profileKey = controller.getProfileName() + "Profile" + (controllerNumber + 1)
sl.add(
StringSingleChoiceSetting(
context,
Expand Down
8 changes: 8 additions & 0 deletions Source/Android/app/src/main/res/values/arrays.xml
Expand Up @@ -367,11 +367,19 @@
<string-array name="gcpadTypeEntries">
<item>@string/gcpad_disabled</item>
<item>@string/gcpad_emulated</item>
<item>@string/gcpad_keyboard</item>
<item>@string/gcpad_steering_wheel</item>
<item>@string/gcpad_dance_mat</item>
<item>@string/gcpad_taru_konga</item>
<item>@string/gcpad_gc_adapter</item>
</string-array>
<integer-array name="gcpadTypeValues">
<item>0</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>12</item>
</integer-array>

Expand Down
13 changes: 9 additions & 4 deletions Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -47,6 +47,7 @@
<string name="input_clear">Clear</string>
<string name="input_clear_description">Clear settings for this controller.</string>
<string name="input_reset_warning">Are you sure? Your current controller settings will be deleted.</string>
<string name="keyboard_controller_warning">"You are configuring a \"Keyboard Controller\". This device is exclusively for \"Phantasy Star Online Episode I &amp; II\". If you are unsure, turn back now and configure a \"Standard Controller\".</string>
<string name="old_controller_settings">Your controller settings are from an old version of Dolphin and won\'t work in this version. Press \"Default\" to start over with new settings.</string>

<string name="input_binding">Input Binding</string>
Expand Down Expand Up @@ -773,13 +774,17 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="country_unknown">Unknown</string>

<!-- GameCube Gamepad Types -->
<string name="gcpad_disabled">Disabled</string>
<string name="gcpad_emulated">Emulated</string>
<string name="gcpad_disabled">None</string>
<string name="gcpad_emulated">Standard Controller</string>
<string name="gcpad_keyboard">Keyboard Controller</string>
<string name="gcpad_steering_wheel">Steering Wheel</string>
<string name="gcpad_dance_mat">Dance Mat</string>
<string name="gcpad_taru_konga">DK Bongos</string>
<string name="gcpad_gc_adapter">GameCube Adapter</string>

<!-- Wiimote Types -->
<string name="wiimote_disabled">Disabled</string>
<string name="wiimote_emulated">Emulated</string>
<string name="wiimote_disabled">None</string>
<string name="wiimote_emulated">Emulated Wii Remote</string>
<string name="wiimote_real">Real Wii Remote (DolphinBar required)</string>

<!-- Gamepad Controls -->
Expand Down
15 changes: 15 additions & 0 deletions Source/Android/jni/Input/EmulatedController.cpp
Expand Up @@ -5,6 +5,7 @@

#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Core/HW/GCKeyboard.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
Expand Down Expand Up @@ -124,13 +125,27 @@ Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedContro
ini.Save(path);
}

JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getProfileName(
JNIEnv* env, jobject obj)
{
return ToJString(env, EmulatedControllerFromJava(env, obj)->GetConfig()->GetProfileName());
}

JNIEXPORT jobject JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGcPad(
JNIEnv* env, jclass, jint controller_index)
{
return EmulatedControllerToJava(env, Pad::GetConfig()->GetController(controller_index));
}

JNIEXPORT jobject JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGcKeyboard(
JNIEnv* env, jclass, jint controller_index)
{
return EmulatedControllerToJava(env, Keyboard::GetConfig()->GetController(controller_index));
}

JNIEXPORT jobject JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getWiimote(
JNIEnv* env, jclass, jint controller_index)
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/FreeLookManager.cpp
Expand Up @@ -118,6 +118,11 @@ std::string FreeLookController::GetName() const
return std::string("FreeLook") + char('1' + m_index);
}

InputConfig* FreeLookController::GetConfig() const
{
return FreeLook::GetInputConfig();
}

void FreeLookController::LoadDefaults(const ControllerInterface& ciface)
{
EmulatedController::LoadDefaults(ciface);
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/FreeLookManager.h
Expand Up @@ -47,6 +47,7 @@ class FreeLookController final : public ControllerEmu::EmulatedController
explicit FreeLookController(unsigned int index);

std::string GetName() const override;
InputConfig* GetConfig() const override;
void LoadDefaults(const ControllerInterface& ciface) override;

ControllerEmu::ControlGroup* GetGroup(FreeLookGroup group) const;
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/HW/GBAPadEmu.cpp
Expand Up @@ -5,6 +5,8 @@

#include <fmt/format.h>

#include "Core/HW/GBAPad.h"

#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/GCPadStatus.h"
Expand Down Expand Up @@ -43,6 +45,11 @@ std::string GBAPad::GetName() const
return fmt::format("GBA{}", m_index + 1);
}

InputConfig* GBAPad::GetConfig() const
{
return Pad::GetGBAConfig();
}

ControllerEmu::ControlGroup* GBAPad::GetGroup(GBAPadGroup group) const
{
switch (group)
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/GBAPadEmu.h
Expand Up @@ -29,6 +29,8 @@ class GBAPad : public ControllerEmu::EmulatedController

std::string GetName() const override;

InputConfig* GetConfig() const override;

ControllerEmu::ControlGroup* GetGroup(GBAPadGroup group) const;

void LoadDefaults(const ControllerInterface& ciface) override;
Expand Down
8 changes: 8 additions & 0 deletions Source/Core/Core/HW/GCKeyboardEmu.cpp
Expand Up @@ -5,6 +5,9 @@

#include "Common/Common.h"
#include "Common/CommonTypes.h"

#include "Core/HW/GCKeyboard.h"

#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
Expand Down Expand Up @@ -84,6 +87,11 @@ std::string GCKeyboard::GetName() const
return std::string("GCKeyboard") + char('1' + m_index);
}

InputConfig* GCKeyboard::GetConfig() const
{
return Keyboard::GetConfig();
}

ControllerEmu::ControlGroup* GCKeyboard::GetGroup(KeyboardGroup group)
{
switch (group)
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/HW/GCKeyboardEmu.h
Expand Up @@ -31,6 +31,7 @@ class GCKeyboard : public ControllerEmu::EmulatedController
explicit GCKeyboard(unsigned int index);
KeyboardStatus GetInput() const;
std::string GetName() const override;
InputConfig* GetConfig() const override;
ControllerEmu::ControlGroup* GetGroup(KeyboardGroup group);
void LoadDefaults(const ControllerInterface& ciface) override;

Expand Down
8 changes: 7 additions & 1 deletion Source/Core/Core/HW/GCPadEmu.cpp
Expand Up @@ -8,14 +8,15 @@
#include "Common/Common.h"
#include "Common/CommonTypes.h"

#include "Core/HW/GCPad.h"

#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/Control/Output.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
#include "InputCommon/ControllerEmu/StickGate.h"

#include "InputCommon/GCPadStatus.h"

static const u16 button_bitmasks[] = {
Expand Down Expand Up @@ -95,6 +96,11 @@ std::string GCPad::GetName() const
return std::string("GCPad") + char('1' + m_index);
}

InputConfig* GCPad::GetConfig() const
{
return Pad::GetConfig();
}

ControllerEmu::ControlGroup* GCPad::GetGroup(PadGroup group)
{
switch (group)
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/GCPadEmu.h
Expand Up @@ -43,6 +43,8 @@ class GCPad : public ControllerEmu::EmulatedController

std::string GetName() const override;

InputConfig* GetConfig() const override;

ControllerEmu::ControlGroup* GetGroup(PadGroup group);

void LoadDefaults(const ControllerInterface& ciface) override;
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Extension/Extension.cpp
Expand Up @@ -10,6 +10,7 @@
#include "Common/CommonTypes.h"
#include "Common/Inline.h"

#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/Extension/DesiredExtensionState.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"

Expand All @@ -36,6 +37,11 @@ std::string Extension::GetDisplayName() const
return m_display_name;
}

InputConfig* Extension::GetConfig() const
{
return ::Wiimote::GetConfig();
}

None::None() : Extension("None")
{
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Extension/Extension.h
Expand Up @@ -27,6 +27,8 @@ class Extension : public ControllerEmu::EmulatedController, public I2CSlave
std::string GetName() const override;
std::string GetDisplayName() const override;

InputConfig* GetConfig() const override;

// Used by the wiimote to detect extension changes.
// The normal extensions short this pin so it's always connected,
// but M+ does some tricks with it during activation.
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -324,6 +324,11 @@ std::string Wiimote::GetName() const
return fmt::format("Wiimote{}", 1 + m_index);
}

InputConfig* Wiimote::GetConfig() const
{
return ::Wiimote::GetConfig();
}

ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group) const
{
switch (group)
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
Expand Up @@ -137,6 +137,9 @@ class Wiimote : public ControllerEmu::EmulatedController, public WiimoteCommon::
~Wiimote();

std::string GetName() const override;

InputConfig* GetConfig() const override;

void LoadDefaults(const ControllerInterface& ciface) override;

ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group) const;
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/HotkeyManager.cpp
Expand Up @@ -383,6 +383,11 @@ std::string HotkeyManager::GetName() const
return "Hotkeys";
}

InputConfig* HotkeyManager::GetConfig() const
{
return HotkeyManagerEmu::GetConfig();
}

void HotkeyManager::GetInput(HotkeyStatus* kb, bool ignore_focus)
{
const auto lock = GetStateLock();
Expand Down

0 comments on commit ac53766

Please sign in to comment.