From 42943672bbbed6c18aa2bc85c41102a0616547f7 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 26 Dec 2022 20:25:09 +0100 Subject: [PATCH] Android: Add selecting input profile per game --- .../input/ui/ProfileDialogPresenter.java | 7 +++ .../model/view/StringSingleChoiceSetting.java | 17 +++++- .../features/settings/ui/SettingsAdapter.java | 23 +++++-- .../ui/SettingsFragmentPresenter.java | 61 ++++++++++++++----- .../app/src/main/res/values/strings.xml | 2 + 5 files changed, 89 insertions(+), 21 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialogPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialogPresenter.java index ae35aec46d..667cc9017c 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialogPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialogPresenter.java @@ -29,6 +29,13 @@ public final class ProfileDialogPresenter private final DialogFragment mDialog; private final MenuTag mMenuTag; + public ProfileDialogPresenter(MenuTag menuTag) + { + mContext = null; + mDialog = null; + mMenuTag = menuTag; + } + public ProfileDialogPresenter(DialogFragment dialog, MenuTag menuTag) { mContext = dialog.getContext(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/StringSingleChoiceSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/StringSingleChoiceSetting.java index 70463f216b..1a9e237728 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/StringSingleChoiceSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/StringSingleChoiceSetting.java @@ -12,11 +12,12 @@ import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; public class StringSingleChoiceSetting extends SettingsItem { - private AbstractStringSetting mSetting; + private final AbstractStringSetting mSetting; protected String[] mChoices; protected String[] mValues; - private MenuTag mMenuTag; + private final MenuTag mMenuTag; + private int mNoChoicesAvailableString = 0; public StringSingleChoiceSetting(Context context, AbstractStringSetting setting, int titleId, int descriptionId, String[] choices, String[] values, MenuTag menuTag) @@ -34,6 +35,13 @@ public class StringSingleChoiceSetting extends SettingsItem this(context, setting, titleId, descriptionId, choices, values, null); } + public StringSingleChoiceSetting(Context context, AbstractStringSetting setting, int titleId, + int descriptionId, String[] choices, String[] values, int noChoicesAvailableString) + { + this(context, setting, titleId, descriptionId, choices, values, null); + mNoChoicesAvailableString = noChoicesAvailableString; + } + public StringSingleChoiceSetting(Context context, AbstractStringSetting setting, int titleId, int descriptionId, int choicesId, int valuesId, MenuTag menuTag) { @@ -115,6 +123,11 @@ public class StringSingleChoiceSetting extends SettingsItem return mMenuTag; } + public int getNoChoicesAvailableString() + { + return mNoChoicesAvailableString; + } + public void setSelectedValue(Settings settings, String selection) { mSetting.setString(settings, selection); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java index 2cf2883fda..0a965b953e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java @@ -255,11 +255,24 @@ public final class SettingsAdapter extends RecyclerView.Adapter(Arrays.asList(ControlGroup.TYPE_ATTACHMENTS, ControlGroup.TYPE_OTHER))); + // TYPE_OTHER is included here instead of in addWiimoteGeneralSubSettings so that touchscreen + // users won't have to dig into a submenu to find the Sideways Wii Remote setting + addControllerMappingSettings(sl, wiimote, new ArraySet<>( + Arrays.asList(ControlGroup.TYPE_ATTACHMENTS, ControlGroup.TYPE_OTHER))); + } } private void addExtensionTypeSettings(ArrayList sl, int wiimoteNumber, @@ -1172,6 +1188,23 @@ public final class SettingsFragmentPresenter ControlGroup.TYPE_IMU_GYROSCOPE, ControlGroup.TYPE_IMU_CURSOR))); } + /** + * Adds controller settings that can be set on a per-game basis. + * + * @param sl The list to place controller settings into. + * @param profileString The prefix used for the profile setting in game INI files. + * @param controllerNumber The index of the controller, 0-3. + */ + private void addControllerPerGameSettings(ArrayList sl, String profileString, + int controllerNumber) + { + String[] profiles = new ProfileDialogPresenter(mMenuTag).getProfileNames(false); + String profileKey = profileString + "Profile" + controllerNumber; + sl.add(new StringSingleChoiceSetting(mContext, + new LegacyStringSetting("", "Controls", profileKey, ""), + R.string.input_profile, 0, profiles, profiles, R.string.input_profiles_empty)); + } + /** * Adds settings and actions that apply to a controller as a whole. * For instance, the device setting and the Clear action. diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 0df89707ad..8d1a550962 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -30,6 +30,8 @@ Device Create Mappings for Other Devices Detects inputs from all devices, not just the selected device. + Profile + You haven\'t created any profiles yet. Profiles (New Profile) Load