Android: Use switch for trait game settings

This commit is contained in:
Connor McLaughlin 2021-06-01 22:53:27 +10:00
parent b2447e2270
commit 7ff35828e4
2 changed files with 44 additions and 5 deletions

View File

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

View File

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