From 7d98c4f3a48c455e0072937729ef6c570a59c6c5 Mon Sep 17 00:00:00 2001 From: Ryan Meredith Date: Tue, 16 Jul 2019 01:54:38 -0400 Subject: [PATCH] Add SingleChoiceSettingDynamicDescriptions --- .../settings/model/view/SettingsItem.java | 1 + ...ingleChoiceSettingDynamicDescriptions.java | 106 ++++++++++++++++++ .../features/settings/ui/SettingsAdapter.java | 78 +++++++++++++ .../ui/SettingsFragmentPresenter.java | 10 +- .../ui/viewholder/SingleChoiceViewHolder.java | 22 ++++ .../app/src/main/res/values/arrays.xml | 14 +++ .../app/src/main/res/values/strings.xml | 1 - 7 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSettingDynamicDescriptions.java diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.java index 48df22fc45..944d7f1491 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.java @@ -20,6 +20,7 @@ public abstract class SettingsItem public static final int TYPE_INPUT_BINDING = 5; public static final int TYPE_STRING_SINGLE_CHOICE = 6; public static final int TYPE_RUMBLE_BINDING = 7; + public static final int TYPE_SINGLE_CHOICE_DYNAMIC_DESCRIPTIONS = 8; private String mKey; private String mSection; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSettingDynamicDescriptions.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSettingDynamicDescriptions.java new file mode 100644 index 0000000000..b5d6e605b6 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSettingDynamicDescriptions.java @@ -0,0 +1,106 @@ +package org.dolphinemu.dolphinemu.features.settings.model.view; + +import org.dolphinemu.dolphinemu.features.settings.model.IntSetting; +import org.dolphinemu.dolphinemu.features.settings.model.Setting; +import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; + +public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem +{ + private int mDefaultValue; + + private int mChoicesId; + private int mValuesId; + private int mDescriptionChoicesId; + private int mDescriptionValuesId; + private MenuTag menuTag; + + public SingleChoiceSettingDynamicDescriptions(String key, String section, int titleId, + int descriptionId, + int choicesId, int valuesId, int descriptionChoicesId, int descriptionValuesId, + int defaultValue, Setting setting, MenuTag menuTag) + { + super(key, section, setting, titleId, descriptionId); + mValuesId = valuesId; + mChoicesId = choicesId; + mDescriptionChoicesId = descriptionChoicesId; + mDescriptionValuesId = descriptionValuesId; + mDefaultValue = defaultValue; + this.menuTag = menuTag; + } + + public SingleChoiceSettingDynamicDescriptions(String key, String section, int titleId, + int descriptionId, + int choicesId, int valuesId, int descriptionChoicesId, int descriptionValuesId, + int defaultValue, Setting setting) + { + this(key, section, titleId, descriptionId, choicesId, valuesId, descriptionChoicesId, + descriptionValuesId, defaultValue, setting, null); + } + + public int getChoicesId() + { + return mChoicesId; + } + + public int getValuesId() + { + return mValuesId; + } + + public int getDescriptionChoicesId() + { + return mDescriptionChoicesId; + } + + public int getDescriptionValuesId() + { + return mDescriptionValuesId; + } + + public int getSelectedValue() + { + if (getSetting() != null) + { + IntSetting setting = (IntSetting) getSetting(); + return setting.getValue(); + } + else + { + return mDefaultValue; + } + } + + public MenuTag getMenuTag() + { + return menuTag; + } + + /** + * 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. + * + * @param selection New value of the int. + * @return null if overwritten successfully otherwise; a newly created IntSetting. + */ + public IntSetting setSelectedValue(int selection) + { + if (getSetting() == null) + { + IntSetting setting = new IntSetting(getKey(), getSection(), selection); + setSetting(setting); + return setting; + } + else + { + IntSetting setting = (IntSetting) getSetting(); + setting.setValue(selection); + return null; + } + } + + @Override + public int getType() + { + return TYPE_SINGLE_CHOICE_DYNAMIC_DESCRIPTIONS; + } +} 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 4e128ece86..a4ce9ce7a8 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 @@ -24,6 +24,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSettin import org.dolphinemu.dolphinemu.features.settings.model.view.RumbleBindingSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSetting; +import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSettingDynamicDescriptions; import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.StringSingleChoiceSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.SubmenuSetting; @@ -78,6 +79,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter 0) + { + int[] valuesArray = mContext.getResources().getIntArray(valuesId); + return valuesArray[which]; + } + else + { + return which; + } + } + + private int getSelectionForSingleChoiceDynamicDescriptionsValue( + SingleChoiceSettingDynamicDescriptions item) + { + int value = item.getSelectedValue(); + int valuesId = item.getValuesId(); + + if (valuesId > 0) + { + int[] valuesArray = mContext.getResources().getIntArray(valuesId); + for (int index = 0; index < valuesArray.length; index++) + { + int current = valuesArray[index]; + if (current == value) + { + return index; + } + } + } + else + { + return value; + } + + return -1; + } + private void putVideoBackendSetting(int which) { StringSetting gfxBackend = null; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index daaadde71e..83817cae95 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -18,6 +18,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSettin import org.dolphinemu.dolphinemu.features.settings.model.view.RumbleBindingSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSetting; +import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSettingDynamicDescriptions; import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.StringSingleChoiceSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.SubmenuSetting; @@ -418,10 +419,11 @@ public final class SettingsFragmentPresenter R.array.videoBackendValues, 0, 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 SingleChoiceSetting(SettingsFile.KEY_SHADER_COMPILATION_MODE, - Settings.SECTION_GFX_SETTINGS, R.string.shader_compilation_mode, - R.string.shader_compilation_mode_description, R.array.shaderCompilationModeEntries, - R.array.shaderCompilationModeValues, 0, shaderCompilationMode)); + sl.add(new SingleChoiceSettingDynamicDescriptions(SettingsFile.KEY_SHADER_COMPILATION_MODE, + Settings.SECTION_GFX_SETTINGS, R.string.shader_compilation_mode, 0, + R.array.shaderCompilationModeEntries, + R.array.shaderCompilationModeValues, R.array.shaderCompilationDescriptionEntries, + R.array.shaderCompilationDescriptionValues, 0, shaderCompilationMode)); sl.add(new CheckBoxSetting(SettingsFile.KEY_WAIT_FOR_SHADERS, Settings.SECTION_GFX_SETTINGS, R.string.wait_for_shaders, R.string.wait_for_shaders_description, false, waitForShaders)); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SingleChoiceViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SingleChoiceViewHolder.java index 6de38a4b1f..78db2c09ff 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SingleChoiceViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SingleChoiceViewHolder.java @@ -7,6 +7,7 @@ import android.widget.TextView; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSetting; +import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSettingDynamicDescriptions; import org.dolphinemu.dolphinemu.features.settings.model.view.StringSingleChoiceSetting; import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter; @@ -63,6 +64,22 @@ public final class SingleChoiceViewHolder extends SettingViewHolder if (valueIndex != -1) mTextSettingDescription.setText(choices[valueIndex]); } + else if (item instanceof SingleChoiceSettingDynamicDescriptions) + { + SingleChoiceSettingDynamicDescriptions setting = + (SingleChoiceSettingDynamicDescriptions) item; + int selected = setting.getSelectedValue(); + Resources resMgr = mTextSettingDescription.getContext().getResources(); + String[] choices = resMgr.getStringArray(setting.getDescriptionChoicesId()); + int[] values = resMgr.getIntArray(setting.getDescriptionValuesId()); + for (int i = 0; i < values.length; ++i) + { + if (values[i] == selected) + { + mTextSettingDescription.setText(choices[i]); + } + } + } } @Override @@ -77,5 +94,10 @@ public final class SingleChoiceViewHolder extends SettingViewHolder { getAdapter().onStringSingleChoiceClick((StringSingleChoiceSetting) mItem, position); } + else if (mItem instanceof SingleChoiceSettingDynamicDescriptions) + { + getAdapter().onSingleChoiceDynamicDescriptionsClick( + (SingleChoiceSettingDynamicDescriptions) mItem, position); + } } } diff --git a/Source/Android/app/src/main/res/values/arrays.xml b/Source/Android/app/src/main/res/values/arrays.xml index e4e32e1a7f..9e2f268151 100644 --- a/Source/Android/app/src/main/res/values/arrays.xml +++ b/Source/Android/app/src/main/res/values/arrays.xml @@ -123,6 +123,20 @@ 3 + + + Synchronous: Ubershaders are never used. Stuttering will occur during shader compilation, but GPU demands are low. Recommended for low-end hardware.\nIf unsure, select this mode. + Synchronous (Ubershaders): Ubershaders will always be used. Provides a near stutter-free experience at the cost of high GPU performance requirements. Only recommended for high-end systems. + Asynchronous (Ubershaders): Ubershaders will be used to prevent stuttering during shader compilation, but specialized shaders will be used when they will not cause stuttering. In the best case it eliminates shader compilation stuttering while having minimal performance impact, but results depend on video driver behavior. + Asynchronous (Skip Drawing): Prevents shader compilation stuttering by not rendering waiting objects. Can work in scenarios where Ubershaders doesn\'t, at the cost of introducing visual glitches and broken effects. Not recommended, only use if the other options give poor results on your system. + + + 0 + 1 + 2 + 3 + + 1x Native (640x528) diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index b1b5797ca8..2ecbb07df7 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -238,7 +238,6 @@ Aspect Ratio Select what aspect ratio to use when rendering Shader Compilation Mode - Specifies when to use Ubershaders. Disabled - Never, Hybrid - Use ubershaders while compiling specialized shaders. Exclusive - Use only ubershaders, largest performance impact. Skip Drawing - Do not draw objects while shaders are compiling, will cause broken effects. Compile Shaders Before Starting This causes a delay when launching games, but will reduce stuttering early on.