Merge pull request #10808 from t895/settings-stuffs

android: Expose settings
This commit is contained in:
bunnei 2023-06-16 16:52:54 -07:00 committed by GitHub
commit 24e1e4dcee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 164 additions and 73 deletions

View File

@ -8,6 +8,9 @@ enum class BooleanSetting(
override val section: String, override val section: String,
override val defaultValue: Boolean override val defaultValue: Boolean
) : AbstractBooleanSetting { ) : AbstractBooleanSetting {
CPU_DEBUG_MODE("cpu_debug_mode", Settings.SECTION_CPU, false),
FASTMEM("cpuopt_fastmem", Settings.SECTION_CPU, true),
FASTMEM_EXCLUSIVES("cpuopt_fastmem_exclusives", Settings.SECTION_CPU, true),
PICTURE_IN_PICTURE("picture_in_picture", Settings.SECTION_GENERAL, true), PICTURE_IN_PICTURE("picture_in_picture", Settings.SECTION_GENERAL, true),
USE_CUSTOM_RTC("custom_rtc_enabled", Settings.SECTION_SYSTEM, false); USE_CUSTOM_RTC("custom_rtc_enabled", Settings.SECTION_SYSTEM, false);

View File

@ -8,6 +8,7 @@ enum class StringSetting(
override val section: String, override val section: String,
override val defaultValue: String override val defaultValue: String
) : AbstractStringSetting { ) : AbstractStringSetting {
AUDIO_OUTPUT_ENGINE("output_engine", Settings.SECTION_AUDIO, "auto"),
CUSTOM_RTC("custom_rtc", Settings.SECTION_SYSTEM, "0"); CUSTOM_RTC("custom_rtc", Settings.SECTION_SYSTEM, "0");
override var string: String = defaultValue override var string: String = defaultValue

View File

@ -3,12 +3,8 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
class HeaderSetting( class HeaderSetting(
setting: AbstractSetting?, titleId: Int
titleId: Int, ) : SettingsItem(null, titleId, 0) {
descriptionId: Int
) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_HEADER override val type = TYPE_HEADER
} }

View File

@ -7,20 +7,20 @@ import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting
class StringSingleChoiceSetting( class StringSingleChoiceSetting(
val key: String? = null,
setting: AbstractSetting?, setting: AbstractSetting?,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
val choicesId: Array<String>, val choices: Array<String>,
private val valuesId: Array<String>?, val values: Array<String>?,
val key: String? = null,
private val defaultValue: String? = null private val defaultValue: String? = null
) : SettingsItem(setting, titleId, descriptionId) { ) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_STRING_SINGLE_CHOICE override val type = TYPE_STRING_SINGLE_CHOICE
fun getValueAt(index: Int): String? { fun getValueAt(index: Int): String? {
if (valuesId == null) return null if (values == null) return null
return if (index >= 0 && index < valuesId.size) { return if (index >= 0 && index < values.size) {
valuesId[index] values[index]
} else { } else {
"" ""
} }
@ -36,8 +36,8 @@ class StringSingleChoiceSetting(
val selectValueIndex: Int val selectValueIndex: Int
get() { get() {
val selectedValue = selectedValue val selectedValue = selectedValue
for (i in valuesId!!.indices) { for (i in values!!.indices) {
if (valuesId[i] == selectedValue) { if (values[i] == selectedValue) {
return i return i
} }
} }

View File

@ -138,7 +138,7 @@ class SettingsAdapter(
clickedItem = item clickedItem = item
dialog = MaterialAlertDialogBuilder(context) dialog = MaterialAlertDialogBuilder(context)
.setTitle(item.nameId) .setTitle(item.nameId)
.setSingleChoiceItems(item.choicesId, item.selectValueIndex, this) .setSingleChoiceItems(item.choices, item.selectValueIndex, this)
.show() .show()
} }

View File

@ -42,7 +42,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
} }
fun putSetting(setting: AbstractSetting) { fun putSetting(setting: AbstractSetting) {
if (setting.section == null) { if (setting.section == null || setting.key == null) {
return return
} }
@ -353,18 +353,31 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
private fun addAudioSettings(sl: ArrayList<SettingsItem>) { private fun addAudioSettings(sl: ArrayList<SettingsItem>) {
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_audio)) settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_audio))
sl.add( sl.apply {
SliderSetting( add(
IntSetting.AUDIO_VOLUME, StringSingleChoiceSetting(
R.string.audio_volume, StringSetting.AUDIO_OUTPUT_ENGINE,
R.string.audio_volume_description, R.string.audio_output_engine,
0, 0,
100, settingsActivity.resources.getStringArray(R.array.outputEngineEntries),
"%", settingsActivity.resources.getStringArray(R.array.outputEngineValues),
IntSetting.AUDIO_VOLUME.key, StringSetting.AUDIO_OUTPUT_ENGINE.key,
IntSetting.AUDIO_VOLUME.defaultValue StringSetting.AUDIO_OUTPUT_ENGINE.defaultValue
)
) )
) add(
SliderSetting(
IntSetting.AUDIO_VOLUME,
R.string.audio_volume,
R.string.audio_volume_description,
0,
100,
"%",
IntSetting.AUDIO_VOLUME.key,
IntSetting.AUDIO_VOLUME.defaultValue
)
)
}
} }
private fun addThemeSettings(sl: ArrayList<SettingsItem>) { private fun addThemeSettings(sl: ArrayList<SettingsItem>) {
@ -467,6 +480,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
private fun addDebugSettings(sl: ArrayList<SettingsItem>) { private fun addDebugSettings(sl: ArrayList<SettingsItem>) {
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_debug)) settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_debug))
sl.apply { sl.apply {
add(HeaderSetting(R.string.gpu))
add( add(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_BACKEND, IntSetting.RENDERER_BACKEND,
@ -487,6 +501,39 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
IntSetting.RENDERER_DEBUG.defaultValue IntSetting.RENDERER_DEBUG.defaultValue
) )
) )
add(HeaderSetting(R.string.cpu))
add(
SwitchSetting(
BooleanSetting.CPU_DEBUG_MODE,
R.string.cpu_debug_mode,
R.string.cpu_debug_mode_description,
BooleanSetting.CPU_DEBUG_MODE.key,
BooleanSetting.CPU_DEBUG_MODE.defaultValue
)
)
val fastmem = object : AbstractBooleanSetting {
override var boolean: Boolean
get() =
BooleanSetting.FASTMEM.boolean && BooleanSetting.FASTMEM_EXCLUSIVES.boolean
set(value) {
BooleanSetting.FASTMEM.boolean = value
BooleanSetting.FASTMEM_EXCLUSIVES.boolean = value
}
override val key: String? = null
override val section: String = Settings.SECTION_CPU
override val isRuntimeEditable: Boolean = false
override val valueAsString: String = ""
override val defaultValue: Any = true
}
add(
SwitchSetting(
fastmem,
R.string.fastmem,
0
)
)
} }
} }
} }

View File

@ -26,6 +26,14 @@ class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: Setti
for (i in values.indices) { for (i in values.indices) {
if (values[i] == item.selectedValue) { if (values[i] == item.selectedValue) {
binding.textSettingDescription.text = resMgr.getStringArray(item.choicesId)[i] binding.textSettingDescription.text = resMgr.getStringArray(item.choicesId)[i]
return
}
}
} else if (item is StringSingleChoiceSetting) {
for (i in item.values!!.indices) {
if (item.values[i] == item.selectedValue) {
binding.textSettingDescription.text = item.choices[i]
return
} }
} }
} else { } else {

View File

@ -244,5 +244,21 @@ object SettingsFile {
val setting = settings[key] val setting = settings[key]
parser.put(header, setting!!.key, setting.valueAsString) parser.put(header, setting!!.key, setting.valueAsString)
} }
BooleanSetting.values().forEach {
if (!keySet.contains(it.key)) {
parser.put(header, it.key, it.valueAsString)
}
}
IntSetting.values().forEach {
if (!keySet.contains(it.key)) {
parser.put(header, it.key, it.valueAsString)
}
}
StringSetting.values().forEach {
if (!keySet.contains(it.key)) {
parser.put(header, it.key, it.valueAsString)
}
}
} }
} }

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:minHeight="72dp" android:minHeight="72dp"
android:paddingVertical="@dimen/spacing_large"
android:paddingStart="@dimen/spacing_large" android:paddingStart="@dimen/spacing_large"
android:paddingEnd="24dp" android:paddingEnd="24dp">
android:paddingVertical="@dimen/spacing_large">
<com.google.android.material.materialswitch.MaterialSwitch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/switch_widget" android:id="@+id/switch_widget"
@ -19,32 +19,35 @@
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_centerVertical="true" /> android:layout_centerVertical="true" />
<com.google.android.material.textview.MaterialTextView <LinearLayout
style="@style/TextAppearance.Material3.BodySmall" android:layout_width="match_parent"
android:id="@+id/text_setting_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignStart="@+id/text_setting_name"
android:layout_below="@+id/text_setting_name"
android:layout_marginEnd="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_small"
android:layout_toStartOf="@+id/switch_widget"
android:textAlignment="viewStart"
tools:text="@string/frame_limit_enable_description" />
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.Material3.HeadlineMedium"
android:id="@+id/text_setting_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/spacing_large" android:layout_marginEnd="@dimen/spacing_large"
android:layout_toStartOf="@+id/switch_widget" android:layout_toStartOf="@+id/switch_widget"
android:textSize="16sp" android:gravity="center_vertical"
android:textAlignment="viewStart" android:orientation="vertical">
app:lineHeight="28dp"
tools:text="@string/frame_limit_enable" /> <com.google.android.material.textview.MaterialTextView
android:id="@+id/text_setting_name"
style="@style/TextAppearance.Material3.HeadlineMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:textSize="16sp"
app:lineHeight="28dp"
tools:text="@string/frame_limit_enable" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_setting_description"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:textAlignment="viewStart"
tools:text="@string/frame_limit_enable_description" />
</LinearLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -1,20 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.textview.MaterialTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text_header_name"
style="@style/TextAppearance.Material3.TitleSmall"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="wrap_content"
android:paddingVertical="4dp" android:layout_gravity="start|center_vertical"
android:paddingHorizontal="@dimen/spacing_large"> android:paddingHorizontal="@dimen/spacing_large"
android:paddingVertical="16dp"
<com.google.android.material.textview.MaterialTextView android:textAlignment="viewStart"
style="@style/TextAppearance.Material3.TitleSmall" android:textColor="?attr/colorPrimary"
android:id="@+id/text_header_name" android:textStyle="bold"
android:layout_width="match_parent" tools:text="CPU Settings" />
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:textColor="?attr/colorPrimary"
android:textAlignment="viewStart"
android:textStyle="bold"
tools:text="CPU Settings" />
</FrameLayout>

View File

@ -236,4 +236,15 @@
<item>2</item> <item>2</item>
</integer-array> </integer-array>
<string-array name="outputEngineEntries">
<item>@string/auto</item>
<item>@string/cubeb</item>
<item>@string/string_null</item>
</string-array>
<string-array name="outputEngineValues">
<item>auto</item>
<item>cubeb</item>
<item>null</item>
</string-array>
</resources> </resources>

View File

@ -158,7 +158,6 @@
<string name="set_custom_rtc">Set custom RTC</string> <string name="set_custom_rtc">Set custom RTC</string>
<!-- Graphics settings strings --> <!-- Graphics settings strings -->
<string name="renderer_api">API</string>
<string name="renderer_accuracy">Accuracy level</string> <string name="renderer_accuracy">Accuracy level</string>
<string name="renderer_resolution">Resolution (Handheld/Docked)</string> <string name="renderer_resolution">Resolution (Handheld/Docked)</string>
<string name="renderer_vsync">VSync mode</string> <string name="renderer_vsync">VSync mode</string>
@ -172,12 +171,21 @@
<string name="renderer_asynchronous_shaders_description">Compiles shaders asynchronously, reducing stutter but may introduce glitches.</string> <string name="renderer_asynchronous_shaders_description">Compiles shaders asynchronously, reducing stutter but may introduce glitches.</string>
<string name="renderer_reactive_flushing">Use reactive flushing</string> <string name="renderer_reactive_flushing">Use reactive flushing</string>
<string name="renderer_reactive_flushing_description">Improves rendering accuracy in some games at the cost of performance.</string> <string name="renderer_reactive_flushing_description">Improves rendering accuracy in some games at the cost of performance.</string>
<string name="renderer_debug">Graphics debugging</string>
<string name="renderer_debug_description">Sets the graphics API to a slow debugging mode.</string>
<string name="use_disk_shader_cache">Disk shader cache</string> <string name="use_disk_shader_cache">Disk shader cache</string>
<string name="use_disk_shader_cache_description">Reduces stuttering by locally storing and loading generated shaders.</string> <string name="use_disk_shader_cache_description">Reduces stuttering by locally storing and loading generated shaders.</string>
<!-- Debug settings strings -->
<string name="cpu">CPU</string>
<string name="cpu_debug_mode">CPU Debugging</string>
<string name="cpu_debug_mode_description">Puts the CPU in a slow debugging mode.</string>
<string name="gpu">GPU</string>
<string name="renderer_api">API</string>
<string name="renderer_debug">Graphics debugging</string>
<string name="renderer_debug_description">Sets the graphics API to a slow debugging mode.</string>
<string name="fastmem">Fastmem</string>
<!-- Audio settings strings --> <!-- Audio settings strings -->
<string name="audio_output_engine">Output engine</string>
<string name="audio_volume">Volume</string> <string name="audio_volume">Volume</string>
<string name="audio_volume_description">Specifies the volume of audio output.</string> <string name="audio_volume_description">Specifies the volume of audio output.</string>
@ -196,6 +204,7 @@
<string name="learn_more">Learn more</string> <string name="learn_more">Learn more</string>
<string name="auto">Auto</string> <string name="auto">Auto</string>
<string name="submit">Submit</string> <string name="submit">Submit</string>
<string name="string_null">Null</string>
<!-- GPU driver installation --> <!-- GPU driver installation -->
<string name="select_gpu_driver">Select GPU driver</string> <string name="select_gpu_driver">Select GPU driver</string>
@ -366,6 +375,9 @@
<string name="theme_mode_light">Light</string> <string name="theme_mode_light">Light</string>
<string name="theme_mode_dark">Dark</string> <string name="theme_mode_dark">Dark</string>
<!-- Audio output engines -->
<string name="cubeb">cubeb</string>
<!-- Black backgrounds theme --> <!-- Black backgrounds theme -->
<string name="use_black_backgrounds">Black backgrounds</string> <string name="use_black_backgrounds">Black backgrounds</string>
<string name="use_black_backgrounds_description">When using the dark theme, apply black backgrounds.</string> <string name="use_black_backgrounds_description">When using the dark theme, apply black backgrounds.</string>