Android: Add selecting input profile per game

This commit is contained in:
JosJuice 2022-12-26 20:25:09 +01:00
parent 1eeded23df
commit 42943672bb
5 changed files with 89 additions and 21 deletions

View File

@ -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();

View File

@ -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);

View File

@ -255,11 +255,24 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
item.refreshChoicesAndValues();
mDialog = new MaterialAlertDialogBuilder(mView.getActivity())
.setTitle(item.getName())
.setSingleChoiceItems(item.getChoices(), item.getSelectedValueIndex(getSettings()),
this)
.show();
String[] choices = item.getChoices();
int noChoicesAvailableString = item.getNoChoicesAvailableString();
if (noChoicesAvailableString != 0 && choices.length == 0)
{
mDialog = new MaterialAlertDialogBuilder(mView.getActivity())
.setTitle(item.getName())
.setMessage(noChoicesAvailableString)
.setPositiveButton(R.string.ok, null)
.show();
}
else
{
mDialog = new MaterialAlertDialogBuilder(mView.getActivity())
.setTitle(item.getName())
.setSingleChoiceItems(item.getChoices(), item.getSelectedValueIndex(getSettings()),
this)
.show();
}
}
public void onSingleChoiceDynamicDescriptionsClick(SingleChoiceSettingDynamicDescriptions item,

View File

@ -25,12 +25,14 @@ import org.dolphinemu.dolphinemu.features.input.model.controlleremu.NumericSetti
import org.dolphinemu.dolphinemu.features.input.model.view.InputDeviceSetting;
import org.dolphinemu.dolphinemu.features.input.model.view.InputMappingControlSetting;
import org.dolphinemu.dolphinemu.features.input.ui.ProfileDialog;
import org.dolphinemu.dolphinemu.features.input.ui.ProfileDialogPresenter;
import org.dolphinemu.dolphinemu.features.settings.model.AbstractBooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.AbstractIntSetting;
import org.dolphinemu.dolphinemu.features.settings.model.AdHocBooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.FloatSetting;
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
import org.dolphinemu.dolphinemu.features.settings.model.LegacyStringSetting;
import org.dolphinemu.dolphinemu.features.settings.model.PostProcessing;
import org.dolphinemu.dolphinemu.features.settings.model.ScaledIntSetting;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
@ -1113,8 +1115,15 @@ public final class SettingsFragmentPresenter
{
EmulatedController gcPad = EmulatedController.getGcPad(gcPadNumber);
addControllerMetaSettings(sl, gcPad);
addControllerMappingSettings(sl, gcPad, null);
if (!TextUtils.isEmpty(mGameID))
{
addControllerPerGameSettings(sl, "Pad", gcPadNumber);
}
else
{
addControllerMetaSettings(sl, gcPad);
addControllerMappingSettings(sl, gcPad, null);
}
}
else if (gcPadType == 12) // Adapter
{
@ -1129,20 +1138,27 @@ public final class SettingsFragmentPresenter
{
EmulatedController wiimote = EmulatedController.getWiimote(wiimoteNumber);
addControllerMetaSettings(sl, wiimote);
if (!TextUtils.isEmpty(mGameID))
{
addControllerPerGameSettings(sl, "Wiimote", wiimoteNumber);
}
else
{
addControllerMetaSettings(sl, wiimote);
sl.add(new HeaderSetting(mContext, R.string.wiimote, 0));
sl.add(new SubmenuSetting(mContext, R.string.wiimote_general,
MenuTag.getWiimoteGeneralMenuTag(wiimoteNumber)));
sl.add(new SubmenuSetting(mContext, R.string.wiimote_motion_simulation,
MenuTag.getWiimoteMotionSimulationMenuTag(wiimoteNumber)));
sl.add(new SubmenuSetting(mContext, R.string.wiimote_motion_input,
MenuTag.getWiimoteMotionInputMenuTag(wiimoteNumber)));
sl.add(new HeaderSetting(mContext, R.string.wiimote, 0));
sl.add(new SubmenuSetting(mContext, R.string.wiimote_general,
MenuTag.getWiimoteGeneralMenuTag(wiimoteNumber)));
sl.add(new SubmenuSetting(mContext, R.string.wiimote_motion_simulation,
MenuTag.getWiimoteMotionSimulationMenuTag(wiimoteNumber)));
sl.add(new SubmenuSetting(mContext, R.string.wiimote_motion_input,
MenuTag.getWiimoteMotionInputMenuTag(wiimoteNumber)));
// 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)));
// 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<SettingsItem> 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<SettingsItem> 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.

View File

@ -30,6 +30,8 @@
<string name="input_device">Device</string>
<string name="input_device_all_devices">Create Mappings for Other Devices</string>
<string name="input_device_all_devices_description">Detects inputs from all devices, not just the selected device.</string>
<string name="input_profile">Profile</string>
<string name="input_profiles_empty">You haven\'t created any profiles yet.</string>
<string name="input_profiles">Profiles</string>
<string name="input_profile_new">(New Profile)</string>
<string name="input_profile_load">Load</string>