From e9cc89af83fa3db2f9abae711b6bd8337337068b Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 20 Jul 2020 12:15:09 +0200 Subject: [PATCH] Android: Remove hacks for Wii Remote extension and video backend settings --- .../model/view/StringSingleChoiceSetting.java | 36 +++++- .../features/settings/ui/SettingsAdapter.java | 109 ++++------------- .../ui/SettingsFragmentPresenter.java | 115 +++--------------- .../features/settings/utils/SettingsFile.java | 3 - .../app/src/main/res/values/arrays.xml | 32 ++--- 5 files changed, 94 insertions(+), 201 deletions(-) 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 3430258bb0..b2ff1546a5 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 @@ -1,7 +1,9 @@ package org.dolphinemu.dolphinemu.features.settings.model.view; +import org.dolphinemu.dolphinemu.DolphinApplication; import org.dolphinemu.dolphinemu.features.settings.model.Setting; import org.dolphinemu.dolphinemu.features.settings.model.StringSetting; +import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; public class StringSingleChoiceSetting extends SettingsItem { @@ -9,14 +11,39 @@ public class StringSingleChoiceSetting extends SettingsItem private String[] mChoicesId; private String[] mValuesId; + private MenuTag mMenuTag; + + public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId, + String[] choicesId, String[] valuesId, String defaultValue, Setting setting, + MenuTag menuTag) + { + super(key, section, setting, titleId, descriptionId); + mChoicesId = choicesId; + mValuesId = valuesId; + mDefaultValue = defaultValue; + mMenuTag = menuTag; + } public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId, String[] choicesId, String[] valuesId, String defaultValue, Setting setting) + { + this(key, section, titleId, descriptionId, choicesId, valuesId, defaultValue, setting, null); + } + + public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId, + int choicesId, int valuesId, String defaultValue, Setting setting, MenuTag menuTag) { super(key, section, setting, titleId, descriptionId); - mValuesId = valuesId; - mChoicesId = choicesId; + mChoicesId = DolphinApplication.getAppContext().getResources().getStringArray(choicesId); + mValuesId = DolphinApplication.getAppContext().getResources().getStringArray(valuesId); mDefaultValue = defaultValue; + mMenuTag = menuTag; + } + + public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId, + int choicesId, int valuesId, String defaultValue, Setting setting) + { + this(key, section, titleId, descriptionId, choicesId, valuesId, defaultValue, setting, null); } public String[] getChoicesId() @@ -69,6 +96,11 @@ public class StringSingleChoiceSetting extends SettingsItem return -1; } + public MenuTag getMenuTag() + { + return mMenuTag; + } + /** * Write a value to the backing int. If that int was previously null, * initializes a new one and returns it, so it can be added to the Hashmap. 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 e13eb36eb6..7f38ed9162 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 @@ -369,6 +369,27 @@ public final class SettingsAdapter extends RecyclerView.Adapter sl) { - IntSetting videoBackend = - new IntSetting(SettingsFile.KEY_VIDEO_BACKEND_INDEX, Settings.SECTION_INI_CORE, - getVideoBackendValue()); + Setting videoBackend = null; Setting showFps = null; Setting shaderCompilationMode = null; Setting waitForShaders = null; Setting aspectRatio = null; + SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE); + videoBackend = coreSection.getSetting(SettingsFile.KEY_VIDEO_BACKEND); + SettingSection gfxSection = mSettings.getSection(Settings.SECTION_GFX_SETTINGS); showFps = gfxSection.getSetting(SettingsFile.KEY_SHOW_FPS); shaderCompilationMode = gfxSection.getSetting(SettingsFile.KEY_SHADER_COMPILATION_MODE); @@ -515,9 +516,9 @@ public final class SettingsFragmentPresenter aspectRatio = gfxSection.getSetting(SettingsFile.KEY_ASPECT_RATIO); sl.add(new HeaderSetting(null, null, R.string.graphics_general, 0)); - sl.add(new SingleChoiceSetting(SettingsFile.KEY_VIDEO_BACKEND_INDEX, Settings.SECTION_INI_CORE, + sl.add(new StringSingleChoiceSetting(SettingsFile.KEY_VIDEO_BACKEND, Settings.SECTION_INI_CORE, R.string.video_backend, 0, R.array.videoBackendEntries, - R.array.videoBackendValues, 0, videoBackend)); + R.array.videoBackendValues, "OGL", videoBackend)); sl.add(new CheckBoxSetting(SettingsFile.KEY_SHOW_FPS, Settings.SECTION_GFX_SETTINGS, R.string.show_fps, R.string.show_fps_description, false, showFps)); sl.add(new SingleChoiceSettingDynamicDescriptions(SettingsFile.KEY_SHADER_COMPILATION_MODE, @@ -985,28 +986,26 @@ public final class SettingsFragmentPresenter // But game game specific extension settings are saved in their own profile. These profiles // do not have any way to specify the controller that is loaded outside of knowing the filename // of the profile that was loaded. - IntSetting extension; + Setting extension; if (mGameID.equals("")) { - extension = new IntSetting(SettingsFile.KEY_WIIMOTE_EXTENSION, - Settings.SECTION_WIIMOTE + wiimoteNumber, getExtensionValue(wiimoteNumber - 3), - MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber)); - sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION, + extension = mSettings.getSection(Settings.SECTION_WIIMOTE + (wiimoteNumber - 3)). + getSetting(SettingsFile.KEY_WIIMOTE_EXTENSION); + sl.add(new StringSingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION, Settings.SECTION_WIIMOTE + (wiimoteNumber - 3), R.string.wiimote_extensions, 0, R.array.wiimoteExtensionsEntries, - R.array.wiimoteExtensionsValues, 0, extension, + R.array.wiimoteExtensionsValues, getExtensionValue(wiimoteNumber - 3), extension, MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber))); } else { mSettings.loadWiimoteProfile(mGameID, String.valueOf(wiimoteNumber - 4)); - extension = new IntSetting(SettingsFile.KEY_WIIMOTE_EXTENSION + (wiimoteNumber - 4), - Settings.SECTION_CONTROLS, getExtensionValue(wiimoteNumber - 4), - MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber)); - sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION + (wiimoteNumber - 4), + extension = mSettings.getSection(Settings.SECTION_CONTROLS). + getSetting(SettingsFile.KEY_WIIMOTE_EXTENSION + (wiimoteNumber - 4)); + sl.add(new StringSingleChoiceSetting(SettingsFile.KEY_WIIMOTE_EXTENSION + (wiimoteNumber - 4), Settings.SECTION_CONTROLS, R.string.wiimote_extensions, 0, R.array.wiimoteExtensionsEntries, - R.array.wiimoteExtensionsValues, 0, extension, + R.array.wiimoteExtensionsValues, getExtensionValue(wiimoteNumber - 4), extension, MenuTag.getWiimoteExtensionMenuTag(wiimoteNumber))); } @@ -1555,99 +1554,25 @@ public final class SettingsFragmentPresenter } } - private int getVideoBackendValue() + private String getExtensionValue(int wiimoteNumber) { - SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE); - - int videoBackendValue; - try { - String videoBackend = - ((StringSetting) coreSection.getSetting(SettingsFile.KEY_VIDEO_BACKEND)).getValue(); - if (videoBackend.equals("OGL")) - { - videoBackendValue = 0; - } - else if (videoBackend.equals("Vulkan")) - { - videoBackendValue = 1; - } - else if (videoBackend.equals("Software Renderer")) - { - videoBackendValue = 2; - } - else if (videoBackend.equals("Null")) - { - videoBackendValue = 3; - } - else - { - videoBackendValue = 0; - } - } - catch (NullPointerException ex) - { - videoBackendValue = 0; - } - - return videoBackendValue; - } - - private int getExtensionValue(int wiimoteNumber) - { - int extensionValue; - - try - { - String extension; if (mGameID.equals("")) // Main settings { - extension = - ((StringSetting) mSettings.getSection(Settings.SECTION_WIIMOTE + wiimoteNumber) - .getSetting(SettingsFile.KEY_WIIMOTE_EXTENSION)).getValue(); + return ((StringSetting) mSettings.getSection(Settings.SECTION_WIIMOTE + wiimoteNumber) + .getSetting(SettingsFile.KEY_WIIMOTE_EXTENSION)).getValue(); } else // Game settings { - extension = ((StringSetting) mSettings.getSection(Settings.SECTION_PROFILE) + return ((StringSetting) mSettings.getSection(Settings.SECTION_PROFILE) .getSetting(SettingsFile.KEY_WIIMOTE_EXTENSION)).getValue(); } - - if (extension.equals("None")) - { - extensionValue = 0; - } - else if (extension.equals("Nunchuk")) - { - extensionValue = 1; - } - else if (extension.equals("Classic")) - { - extensionValue = 2; - } - else if (extension.equals("Guitar")) - { - extensionValue = 3; - } - else if (extension.equals("Drums")) - { - extensionValue = 4; - } - else if (extension.equals("Turntable")) - { - extensionValue = 5; - } - else - { - extensionValue = 0; - } } catch (NullPointerException ex) { - extensionValue = 0; + return "None"; } - - return extensionValue; } public static String getDefaultNANDRootPath() diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java index befac57321..e4bc8b9bd9 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java @@ -286,9 +286,6 @@ public final class SettingsFile public static final String KEY_WIIMOTE_SCAN = "WiimoteContinuousScanning"; public static final String KEY_WIIMOTE_SPEAKER = "WiimoteEnableSpeaker"; - // Internal only, not actually found in settings file. - public static final String KEY_VIDEO_BACKEND_INDEX = "VideoBackendIndex"; - private static BiMap sectionsMap = new BiMap<>(); static diff --git a/Source/Android/app/src/main/res/values/arrays.xml b/Source/Android/app/src/main/res/values/arrays.xml index 7aa538e46e..881701b9b9 100644 --- a/Source/Android/app/src/main/res/values/arrays.xml +++ b/Source/Android/app/src/main/res/values/arrays.xml @@ -86,21 +86,29 @@ - + OpenGL Vulkan Software Null - - 0 - 1 - 2 - 3 - + + OGL + Vulkan + Software Renderer + Null + - + + None + Nunchuk + Classic + Guitar + Drums + Turntable + + None Nunchuk Classic @@ -108,14 +116,6 @@ Drums Turntable - - 0 - 1 - 2 - 3 - 4 - 5 -