From 7ff35828e4927b8ff89634586f992056dff1bf8a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 1 Jun 2021 22:53:27 +1000 Subject: [PATCH] Android: Use switch for trait game settings --- .../duckstation/GamePropertiesActivity.java | 15 +++++--- .../duckstation/GameTraitPreference.java | 34 +++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 android/app/src/main/java/com/github/stenzek/duckstation/GameTraitPreference.java diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/GamePropertiesActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/GamePropertiesActivity.java index cc42b21c4..683438621 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/GamePropertiesActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/GamePropertiesActivity.java @@ -99,6 +99,11 @@ public class GamePropertiesActivity extends AppCompatActivity { ps.addPreference(pref); } + private void createTraitGameSetting(PreferenceScreen ps, String key, int titleId) { + GameTraitPreference pref = new GameTraitPreference(ps.getContext(), mGameListEntry.getPath(), key, titleId); + ps.addPreference(pref); + } + private void createListGameSetting(PreferenceScreen ps, String key, int titleId, int entryId, int entryValuesId) { GameSettingPreference pref = new GameSettingPreference(ps.getContext(), mGameListEntry.getPath(), key, titleId, entryId, entryValuesId); ps.addPreference(pref); @@ -136,11 +141,11 @@ public class GamePropertiesActivity extends AppCompatActivity { activity.createBooleanGameSetting(ps, "GPUPGXP", R.string.settings_pgxp_geometry_correction); activity.createBooleanGameSetting(ps, "PGXPPreserveProjFP", R.string.settings_pgxp_preserve_projection_precision); activity.createBooleanGameSetting(ps, "GPUPGXPDepthBuffer", R.string.settings_pgxp_depth_buffer); - activity.createBooleanGameSetting(ps, "ForceSoftwareRenderer", R.string.settings_use_software_renderer); - activity.createBooleanGameSetting(ps, "ForceSoftwareRendererForReadbacks", R.string.settings_use_software_renderer_for_readbacks); - activity.createBooleanGameSetting(ps, "DisableWidescreen", R.string.settings_disable_widescreen); - activity.createBooleanGameSetting(ps, "ForcePGXPVertexCache", R.string.settings_pgxp_vertex_cache); - activity.createBooleanGameSetting(ps, "ForcePGXPCPUMode", R.string.settings_pgxp_cpu_mode); + activity.createTraitGameSetting(ps, "ForceSoftwareRenderer", R.string.settings_use_software_renderer); + activity.createTraitGameSetting(ps, "ForceSoftwareRendererForReadbacks", R.string.settings_use_software_renderer_for_readbacks); + activity.createTraitGameSetting(ps, "DisableWidescreen", R.string.settings_disable_widescreen); + activity.createTraitGameSetting(ps, "ForcePGXPVertexCache", R.string.settings_pgxp_vertex_cache); + activity.createTraitGameSetting(ps, "ForcePGXPCPUMode", R.string.settings_pgxp_cpu_mode); setPreferenceScreen(ps); } diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/GameTraitPreference.java b/android/app/src/main/java/com/github/stenzek/duckstation/GameTraitPreference.java new file mode 100644 index 000000000..a3eb13aab --- /dev/null +++ b/android/app/src/main/java/com/github/stenzek/duckstation/GameTraitPreference.java @@ -0,0 +1,34 @@ +package com.github.stenzek.duckstation; + +import android.content.Context; + +import androidx.preference.ListPreference; +import androidx.preference.SwitchPreference; + +public class GameTraitPreference extends SwitchPreference { + private String mGamePath; + + /** + * Creates a boolean game property preference. + */ + public GameTraitPreference(Context context, String gamePath, String settingKey, int titleId) { + super(context); + mGamePath = gamePath; + setPersistent(false); + setTitle(titleId); + setKey(settingKey); + setIconSpaceReserved(false); + updateValue(); + } + + private void updateValue() { + final String value = AndroidHostInterface.getInstance().getGameSettingValue(mGamePath, getKey()); + super.setChecked(value != null && value.equals("true")); + } + + @Override + public void setChecked(boolean checked) { + super.setChecked(checked); + AndroidHostInterface.getInstance().setGameSettingValue(mGamePath, getKey(), checked ? "true" : "false"); + } +}