yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

android: Allow SettingsItems to use String or StringRes

This commit is contained in:
t895 2024-02-16 21:04:26 -05:00
parent c7588c042b
commit a251f77556
17 changed files with 278 additions and 214 deletions

View File

@ -3,13 +3,16 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import androidx.annotation.StringRes
import org.yuzu.yuzu_emu.features.settings.model.AbstractLongSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractLongSetting
class DateTimeSetting( class DateTimeSetting(
private val longSetting: AbstractLongSetting, private val longSetting: AbstractLongSetting,
titleId: Int, @StringRes titleId: Int = 0,
descriptionId: Int titleString: String = "",
) : SettingsItem(longSetting, titleId, descriptionId) { @StringRes descriptionId: Int = 0,
descriptionString: String = ""
) : SettingsItem(longSetting, titleId, titleString, descriptionId, descriptionString) {
override val type = TYPE_DATETIME_SETTING override val type = TYPE_DATETIME_SETTING
fun getValue(needsGlobal: Boolean = false): Long = longSetting.getLong(needsGlobal) fun getValue(needsGlobal: Boolean = false): Long = longSetting.getLong(needsGlobal)

View File

@ -3,8 +3,11 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import androidx.annotation.StringRes
class HeaderSetting( class HeaderSetting(
titleId: Int @StringRes titleId: Int = 0,
) : SettingsItem(emptySetting, titleId, 0) { titleString: String = ""
) : SettingsItem(emptySetting, titleId, titleString, 0, "") {
override val type = TYPE_HEADER override val type = TYPE_HEADER
} }

View File

@ -4,13 +4,16 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
class RunnableSetting( class RunnableSetting(
titleId: Int,
descriptionId: Int,
val isRuntimeRunnable: Boolean, val isRuntimeRunnable: Boolean,
@StringRes titleId: Int = 0,
titleString: String = "",
@StringRes descriptionId: Int = 0,
descriptionString: String = "",
@DrawableRes val iconId: Int = 0, @DrawableRes val iconId: Int = 0,
val runnable: () -> Unit val runnable: () -> Unit
) : SettingsItem(emptySetting, titleId, descriptionId) { ) : SettingsItem(emptySetting, titleId, titleString, descriptionId, descriptionString) {
override val type = TYPE_RUNNABLE override val type = TYPE_RUNNABLE
} }

View File

@ -3,8 +3,12 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import androidx.annotation.StringRes
import org.yuzu.yuzu_emu.NativeLibrary import org.yuzu.yuzu_emu.NativeLibrary
import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.YuzuApplication
import org.yuzu.yuzu_emu.features.input.NativeInput
import org.yuzu.yuzu_emu.features.input.model.NpadStyleIndex
import org.yuzu.yuzu_emu.features.settings.model.AbstractBooleanSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractBooleanSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting
@ -23,13 +27,34 @@ import org.yuzu.yuzu_emu.utils.NativeConfig
*/ */
abstract class SettingsItem( abstract class SettingsItem(
val setting: AbstractSetting, val setting: AbstractSetting,
val nameId: Int, @StringRes val titleId: Int,
val descriptionId: Int val titleString: String,
@StringRes val descriptionId: Int,
val descriptionString: String
) { ) {
abstract val type: Int abstract val type: Int
val title: String by lazy {
if (titleId != 0) {
return@lazy YuzuApplication.appContext.getString(titleId)
}
return@lazy titleString
}
val description: String by lazy {
if (descriptionId != 0) {
return@lazy YuzuApplication.appContext.getString(descriptionId)
}
return@lazy descriptionString
}
val isEditable: Boolean val isEditable: Boolean
get() { get() {
// Can't change docked mode toggle when using handheld mode
if (setting.key == BooleanSetting.USE_DOCKED_MODE.key) {
return NativeInput.getStyleIndex(0) != NpadStyleIndex.Handheld
}
// Can't edit settings that aren't saveable in per-game config even if they are switchable // Can't edit settings that aren't saveable in per-game config even if they are switchable
if (NativeConfig.isPerGameConfigLoaded() && !setting.isSaveable) { if (NativeConfig.isPerGameConfigLoaded() && !setting.isSaveable) {
return false return false
@ -59,6 +84,9 @@ abstract class SettingsItem(
const val TYPE_STRING_SINGLE_CHOICE = 5 const val TYPE_STRING_SINGLE_CHOICE = 5
const val TYPE_DATETIME_SETTING = 6 const val TYPE_DATETIME_SETTING = 6
const val TYPE_RUNNABLE = 7 const val TYPE_RUNNABLE = 7
const val TYPE_INPUT = 8
const val TYPE_INT_SINGLE_CHOICE = 9
const val TYPE_INPUT_PROFILE = 10
const val FASTMEM_COMBINED = "fastmem_combined" const val FASTMEM_COMBINED = "fastmem_combined"
@ -80,237 +108,242 @@ abstract class SettingsItem(
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.RENDERER_USE_SPEED_LIMIT, BooleanSetting.RENDERER_USE_SPEED_LIMIT,
R.string.frame_limit_enable, titleId = R.string.frame_limit_enable,
R.string.frame_limit_enable_description descriptionId = R.string.frame_limit_enable_description
) )
) )
put( put(
SliderSetting( SliderSetting(
ShortSetting.RENDERER_SPEED_LIMIT, ShortSetting.RENDERER_SPEED_LIMIT,
R.string.frame_limit_slider, titleId = R.string.frame_limit_slider,
R.string.frame_limit_slider_description, descriptionId = R.string.frame_limit_slider_description,
1, min = 1,
400, max = 400,
"%" units = "%"
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.CPU_BACKEND, IntSetting.CPU_BACKEND,
R.string.cpu_backend, titleId = R.string.cpu_backend,
0, choicesId = R.array.cpuBackendArm64Names,
R.array.cpuBackendArm64Names, valuesId = R.array.cpuBackendArm64Values
R.array.cpuBackendArm64Values
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.CPU_ACCURACY, IntSetting.CPU_ACCURACY,
R.string.cpu_accuracy, titleId = R.string.cpu_accuracy,
0, choicesId = R.array.cpuAccuracyNames,
R.array.cpuAccuracyNames, valuesId = R.array.cpuAccuracyValues
R.array.cpuAccuracyValues
) )
) )
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.PICTURE_IN_PICTURE, BooleanSetting.PICTURE_IN_PICTURE,
R.string.picture_in_picture, titleId = R.string.picture_in_picture,
R.string.picture_in_picture_description descriptionId = R.string.picture_in_picture_description
) )
) )
val dockedModeSetting = object : AbstractBooleanSetting {
override val key = BooleanSetting.USE_DOCKED_MODE.key
override fun getBoolean(needsGlobal: Boolean): Boolean {
if (NativeInput.getStyleIndex(0) == NpadStyleIndex.Handheld) {
return false
}
return BooleanSetting.USE_DOCKED_MODE.getBoolean(needsGlobal)
}
override fun setBoolean(value: Boolean) =
BooleanSetting.USE_DOCKED_MODE.setBoolean(value)
override val defaultValue = BooleanSetting.USE_DOCKED_MODE.defaultValue
override fun getValueAsString(needsGlobal: Boolean): String =
BooleanSetting.USE_DOCKED_MODE.getValueAsString(needsGlobal)
override fun reset() = BooleanSetting.USE_DOCKED_MODE.reset()
}
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.USE_DOCKED_MODE, dockedModeSetting,
R.string.use_docked_mode, titleId = R.string.use_docked_mode,
R.string.use_docked_mode_description descriptionId = R.string.use_docked_mode_description
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.REGION_INDEX, IntSetting.REGION_INDEX,
R.string.emulated_region, titleId = R.string.emulated_region,
0, choicesId = R.array.regionNames,
R.array.regionNames, valuesId = R.array.regionValues
R.array.regionValues
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.LANGUAGE_INDEX, IntSetting.LANGUAGE_INDEX,
R.string.emulated_language, titleId = R.string.emulated_language,
0, choicesId = R.array.languageNames,
R.array.languageNames, valuesId = R.array.languageValues
R.array.languageValues
) )
) )
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.USE_CUSTOM_RTC, BooleanSetting.USE_CUSTOM_RTC,
R.string.use_custom_rtc, titleId = R.string.use_custom_rtc,
R.string.use_custom_rtc_description descriptionId = R.string.use_custom_rtc_description
) )
) )
put(DateTimeSetting(LongSetting.CUSTOM_RTC, R.string.set_custom_rtc, 0)) put(DateTimeSetting(LongSetting.CUSTOM_RTC, titleId = R.string.set_custom_rtc))
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_ACCURACY, IntSetting.RENDERER_ACCURACY,
R.string.renderer_accuracy, titleId = R.string.renderer_accuracy,
0, choicesId = R.array.rendererAccuracyNames,
R.array.rendererAccuracyNames, valuesId = R.array.rendererAccuracyValues
R.array.rendererAccuracyValues
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_RESOLUTION, IntSetting.RENDERER_RESOLUTION,
R.string.renderer_resolution, titleId = R.string.renderer_resolution,
0, choicesId = R.array.rendererResolutionNames,
R.array.rendererResolutionNames, valuesId = R.array.rendererResolutionValues
R.array.rendererResolutionValues
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_VSYNC, IntSetting.RENDERER_VSYNC,
R.string.renderer_vsync, titleId = R.string.renderer_vsync,
0, choicesId = R.array.rendererVSyncNames,
R.array.rendererVSyncNames, valuesId = R.array.rendererVSyncValues
R.array.rendererVSyncValues
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_SCALING_FILTER, IntSetting.RENDERER_SCALING_FILTER,
R.string.renderer_scaling_filter, titleId = R.string.renderer_scaling_filter,
0, choicesId = R.array.rendererScalingFilterNames,
R.array.rendererScalingFilterNames, valuesId = R.array.rendererScalingFilterValues
R.array.rendererScalingFilterValues
) )
) )
put( put(
SliderSetting( SliderSetting(
IntSetting.FSR_SHARPENING_SLIDER, IntSetting.FSR_SHARPENING_SLIDER,
R.string.fsr_sharpness, titleId = R.string.fsr_sharpness,
R.string.fsr_sharpness_description, descriptionId = R.string.fsr_sharpness_description,
0, units = "%"
100,
"%"
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_ANTI_ALIASING, IntSetting.RENDERER_ANTI_ALIASING,
R.string.renderer_anti_aliasing, titleId = R.string.renderer_anti_aliasing,
0, choicesId = R.array.rendererAntiAliasingNames,
R.array.rendererAntiAliasingNames, valuesId = R.array.rendererAntiAliasingValues
R.array.rendererAntiAliasingValues
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_SCREEN_LAYOUT, IntSetting.RENDERER_SCREEN_LAYOUT,
R.string.renderer_screen_layout, titleId = R.string.renderer_screen_layout,
0, choicesId = R.array.rendererScreenLayoutNames,
R.array.rendererScreenLayoutNames, valuesId = R.array.rendererScreenLayoutValues
R.array.rendererScreenLayoutValues
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_ASPECT_RATIO, IntSetting.RENDERER_ASPECT_RATIO,
R.string.renderer_aspect_ratio, titleId = R.string.renderer_aspect_ratio,
0, choicesId = R.array.rendererAspectRatioNames,
R.array.rendererAspectRatioNames, valuesId = R.array.rendererAspectRatioValues
R.array.rendererAspectRatioValues
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.VERTICAL_ALIGNMENT, IntSetting.VERTICAL_ALIGNMENT,
R.string.vertical_alignment, titleId = R.string.vertical_alignment,
0, descriptionId = 0,
R.array.verticalAlignmentEntries, choicesId = R.array.verticalAlignmentEntries,
R.array.verticalAlignmentValues valuesId = R.array.verticalAlignmentValues
) )
) )
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.RENDERER_USE_DISK_SHADER_CACHE, BooleanSetting.RENDERER_USE_DISK_SHADER_CACHE,
R.string.use_disk_shader_cache, titleId = R.string.use_disk_shader_cache,
R.string.use_disk_shader_cache_description descriptionId = R.string.use_disk_shader_cache_description
) )
) )
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.RENDERER_FORCE_MAX_CLOCK, BooleanSetting.RENDERER_FORCE_MAX_CLOCK,
R.string.renderer_force_max_clock, titleId = R.string.renderer_force_max_clock,
R.string.renderer_force_max_clock_description descriptionId = R.string.renderer_force_max_clock_description
) )
) )
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.RENDERER_ASYNCHRONOUS_SHADERS, BooleanSetting.RENDERER_ASYNCHRONOUS_SHADERS,
R.string.renderer_asynchronous_shaders, titleId = R.string.renderer_asynchronous_shaders,
R.string.renderer_asynchronous_shaders_description descriptionId = R.string.renderer_asynchronous_shaders_description
) )
) )
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.RENDERER_REACTIVE_FLUSHING, BooleanSetting.RENDERER_REACTIVE_FLUSHING,
R.string.renderer_reactive_flushing, titleId = R.string.renderer_reactive_flushing,
R.string.renderer_reactive_flushing_description descriptionId = R.string.renderer_reactive_flushing_description
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.MAX_ANISOTROPY, IntSetting.MAX_ANISOTROPY,
R.string.anisotropic_filtering, titleId = R.string.anisotropic_filtering,
R.string.anisotropic_filtering_description, descriptionId = R.string.anisotropic_filtering_description,
R.array.anisoEntries, choicesId = R.array.anisoEntries,
R.array.anisoValues valuesId = R.array.anisoValues
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.AUDIO_OUTPUT_ENGINE, IntSetting.AUDIO_OUTPUT_ENGINE,
R.string.audio_output_engine, titleId = R.string.audio_output_engine,
0, choicesId = R.array.outputEngineEntries,
R.array.outputEngineEntries, valuesId = R.array.outputEngineValues
R.array.outputEngineValues
) )
) )
put( put(
SliderSetting( SliderSetting(
ByteSetting.AUDIO_VOLUME, ByteSetting.AUDIO_VOLUME,
R.string.audio_volume, titleId = R.string.audio_volume,
R.string.audio_volume_description, descriptionId = R.string.audio_volume_description,
0, units = "%"
100,
"%"
) )
) )
put( put(
SingleChoiceSetting( SingleChoiceSetting(
IntSetting.RENDERER_BACKEND, IntSetting.RENDERER_BACKEND,
R.string.renderer_api, titleId = R.string.renderer_api,
0, choicesId = R.array.rendererApiNames,
R.array.rendererApiNames, valuesId = R.array.rendererApiValues
R.array.rendererApiValues
) )
) )
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.RENDERER_DEBUG, BooleanSetting.RENDERER_DEBUG,
R.string.renderer_debug, titleId = R.string.renderer_debug,
R.string.renderer_debug_description descriptionId = R.string.renderer_debug_description
) )
) )
put( put(
SwitchSetting( SwitchSetting(
BooleanSetting.CPU_DEBUG_MODE, BooleanSetting.CPU_DEBUG_MODE,
R.string.cpu_debug_mode, titleId = R.string.cpu_debug_mode,
R.string.cpu_debug_mode_description descriptionId = R.string.cpu_debug_mode_description
) )
) )
@ -346,7 +379,7 @@ abstract class SettingsItem(
override fun reset() = setBoolean(defaultValue) override fun reset() = setBoolean(defaultValue)
} }
put(SwitchSetting(fastmem, R.string.fastmem, 0)) put(SwitchSetting(fastmem, R.string.fastmem))
} }
} }
} }

View File

@ -3,16 +3,20 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import androidx.annotation.ArrayRes
import androidx.annotation.StringRes
import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
class SingleChoiceSetting( class SingleChoiceSetting(
setting: AbstractSetting, setting: AbstractSetting,
titleId: Int, @StringRes titleId: Int = 0,
descriptionId: Int, titleString: String = "",
val choicesId: Int, @StringRes descriptionId: Int = 0,
val valuesId: Int descriptionString: String = "",
) : SettingsItem(setting, titleId, descriptionId) { @ArrayRes val choicesId: Int,
@ArrayRes val valuesId: Int
) : SettingsItem(setting, titleId, titleString, descriptionId, descriptionString) {
override val type = TYPE_SINGLE_CHOICE override val type = TYPE_SINGLE_CHOICE
fun getSelectedValue(needsGlobal: Boolean = false) = fun getSelectedValue(needsGlobal: Boolean = false) =

View File

@ -3,6 +3,7 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import androidx.annotation.StringRes
import org.yuzu.yuzu_emu.features.settings.model.AbstractByteSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractByteSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractFloatSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractFloatSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting
@ -12,12 +13,14 @@ import kotlin.math.roundToInt
class SliderSetting( class SliderSetting(
setting: AbstractSetting, setting: AbstractSetting,
titleId: Int, @StringRes titleId: Int = 0,
descriptionId: Int, titleString: String = "",
val min: Int, @StringRes descriptionId: Int = 0,
val max: Int, descriptionString: String = "",
val units: String val min: Int = 0,
) : SettingsItem(setting, titleId, descriptionId) { val max: Int = 100,
val units: String = ""
) : SettingsItem(setting, titleId, titleString, descriptionId, descriptionString) {
override val type = TYPE_SLIDER override val type = TYPE_SLIDER
fun getSelectedValue(needsGlobal: Boolean = false) = fun getSelectedValue(needsGlobal: Boolean = false) =

View File

@ -3,15 +3,18 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import androidx.annotation.StringRes
import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting
class StringSingleChoiceSetting( class StringSingleChoiceSetting(
private val stringSetting: AbstractStringSetting, private val stringSetting: AbstractStringSetting,
titleId: Int, @StringRes titleId: Int = 0,
descriptionId: Int, titleString: String = "",
@StringRes descriptionId: Int = 0,
descriptionString: String = "",
val choices: Array<String>, val choices: Array<String>,
val values: Array<String> val values: Array<String>
) : SettingsItem(stringSetting, titleId, descriptionId) { ) : SettingsItem(stringSetting, titleId, titleString, descriptionId, descriptionString) {
override val type = TYPE_STRING_SINGLE_CHOICE override val type = TYPE_STRING_SINGLE_CHOICE
fun getValueAt(index: Int): String = fun getValueAt(index: Int): String =
@ -20,7 +23,7 @@ class StringSingleChoiceSetting(
fun getSelectedValue(needsGlobal: Boolean = false) = stringSetting.getString(needsGlobal) fun getSelectedValue(needsGlobal: Boolean = false) = stringSetting.getString(needsGlobal)
fun setSelectedValue(value: String) = stringSetting.setString(value) fun setSelectedValue(value: String) = stringSetting.setString(value)
val selectValueIndex: Int val selectedValueIndex: Int
get() { get() {
for (i in values.indices) { for (i in values.indices) {
if (values[i] == getSelectedValue()) { if (values[i] == getSelectedValue()) {

View File

@ -8,10 +8,12 @@ import androidx.annotation.StringRes
import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.features.settings.model.Settings
class SubmenuSetting( class SubmenuSetting(
@StringRes titleId: Int, @StringRes titleId: Int = 0,
@StringRes descriptionId: Int, titleString: String = "",
@DrawableRes val iconId: Int, @StringRes descriptionId: Int = 0,
descriptionString: String = "",
@DrawableRes val iconId: Int = 0,
val menuKey: Settings.MenuTag val menuKey: Settings.MenuTag
) : SettingsItem(emptySetting, titleId, descriptionId) { ) : SettingsItem(emptySetting, titleId, titleString, descriptionId, descriptionString) {
override val type = TYPE_SUBMENU override val type = TYPE_SUBMENU
} }

View File

@ -3,15 +3,18 @@
package org.yuzu.yuzu_emu.features.settings.model.view package org.yuzu.yuzu_emu.features.settings.model.view
import androidx.annotation.StringRes
import org.yuzu.yuzu_emu.features.settings.model.AbstractBooleanSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractBooleanSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
class SwitchSetting( class SwitchSetting(
setting: AbstractSetting, setting: AbstractSetting,
titleId: Int, @StringRes titleId: Int = 0,
descriptionId: Int titleString: String = "",
) : SettingsItem(setting, titleId, descriptionId) { @StringRes descriptionId: Int = 0,
descriptionString: String = ""
) : SettingsItem(setting, titleId, titleString, descriptionId, descriptionString) {
override val type = TYPE_SWITCH override val type = TYPE_SWITCH
fun getIsChecked(needsGlobal: Boolean = false): Boolean { fun getIsChecked(needsGlobal: Boolean = false): Boolean {

View File

@ -84,42 +84,41 @@ class SettingsFragmentPresenter(
sl.apply { sl.apply {
add( add(
SubmenuSetting( SubmenuSetting(
R.string.preferences_system, titleId = R.string.preferences_system,
R.string.preferences_system_description, descriptionId = R.string.preferences_system_description,
R.drawable.ic_system_settings, iconId = R.drawable.ic_system_settings,
Settings.MenuTag.SECTION_SYSTEM menuKey = MenuTag.SECTION_SYSTEM
) )
) )
add( add(
SubmenuSetting( SubmenuSetting(
R.string.preferences_graphics, titleId = R.string.preferences_graphics,
R.string.preferences_graphics_description, descriptionId = R.string.preferences_graphics_description,
R.drawable.ic_graphics, iconId = R.drawable.ic_graphics,
Settings.MenuTag.SECTION_RENDERER menuKey = MenuTag.SECTION_RENDERER
) )
) )
add( add(
SubmenuSetting( SubmenuSetting(
R.string.preferences_audio, titleId = R.string.preferences_audio,
R.string.preferences_audio_description, descriptionId = R.string.preferences_audio_description,
R.drawable.ic_audio, iconId = R.drawable.ic_audio,
Settings.MenuTag.SECTION_AUDIO menuKey = MenuTag.SECTION_AUDIO
) )
) )
add( add(
SubmenuSetting( SubmenuSetting(
R.string.preferences_debug, titleId = R.string.preferences_debug,
R.string.preferences_debug_description, descriptionId = R.string.preferences_debug_description,
R.drawable.ic_code, iconId = R.drawable.ic_code,
Settings.MenuTag.SECTION_DEBUG menuKey = MenuTag.SECTION_DEBUG
) )
) )
add( add(
RunnableSetting( RunnableSetting(
R.string.reset_to_default, titleId = R.string.reset_to_default,
R.string.reset_to_default_description, descriptionId = R.string.reset_to_default_description,
false, iconId = R.drawable.ic_restore
R.drawable.ic_restore
) { settingsViewModel.setShouldShowResetSettingsDialog(true) } ) { settingsViewModel.setShouldShowResetSettingsDialog(true) }
) )
} }
@ -186,20 +185,18 @@ class SettingsFragmentPresenter(
add( add(
SingleChoiceSetting( SingleChoiceSetting(
theme, theme,
R.string.change_app_theme, titleId = R.string.change_app_theme,
0, choicesId = R.array.themeEntriesA12,
R.array.themeEntriesA12, valuesId = R.array.themeValuesA12
R.array.themeValuesA12
) )
) )
} else { } else {
add( add(
SingleChoiceSetting( SingleChoiceSetting(
theme, theme,
R.string.change_app_theme, titleId = R.string.change_app_theme,
0, choicesId = R.array.themeEntries,
R.array.themeEntries, valuesId = R.array.themeValues
R.array.themeValues
) )
) )
} }
@ -228,10 +225,9 @@ class SettingsFragmentPresenter(
add( add(
SingleChoiceSetting( SingleChoiceSetting(
themeMode, themeMode,
R.string.change_theme_mode, titleId = R.string.change_theme_mode,
0, choicesId = R.array.themeModeEntries,
R.array.themeModeEntries, valuesId = R.array.themeModeValues
R.array.themeModeValues
) )
) )
@ -262,8 +258,8 @@ class SettingsFragmentPresenter(
add( add(
SwitchSetting( SwitchSetting(
blackBackgrounds, blackBackgrounds,
R.string.use_black_backgrounds, titleId = R.string.use_black_backgrounds,
R.string.use_black_backgrounds_description descriptionId = R.string.use_black_backgrounds_description
) )
) )
} }

View File

@ -21,9 +21,9 @@ class DateTimeViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA
override fun bind(item: SettingsItem) { override fun bind(item: SettingsItem) {
setting = item as DateTimeSetting setting = item as DateTimeSetting
binding.textSettingName.setText(item.nameId) binding.textSettingName.text = item.title
if (item.descriptionId != 0) { if (setting.description.isNotEmpty()) {
binding.textSettingDescription.setText(item.descriptionId) binding.textSettingDescription.text = item.description
binding.textSettingDescription.visibility = View.VISIBLE binding.textSettingDescription.visibility = View.VISIBLE
} else { } else {
binding.textSettingDescription.visibility = View.GONE binding.textSettingDescription.visibility = View.GONE

View File

@ -16,7 +16,7 @@ class HeaderViewHolder(val binding: ListItemSettingsHeaderBinding, adapter: Sett
} }
override fun bind(item: SettingsItem) { override fun bind(item: SettingsItem) {
binding.textHeaderName.setText(item.nameId) binding.textHeaderName.text = item.title
} }
override fun onClick(clicked: View) { override fun onClick(clicked: View) {

View File

@ -5,7 +5,6 @@ package org.yuzu.yuzu_emu.features.settings.ui.viewholder
import android.view.View import android.view.View
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import org.yuzu.yuzu_emu.NativeLibrary
import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding
import org.yuzu.yuzu_emu.features.settings.model.view.RunnableSetting import org.yuzu.yuzu_emu.features.settings.model.view.RunnableSetting
import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
@ -17,12 +16,12 @@ class RunnableViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA
override fun bind(item: SettingsItem) { override fun bind(item: SettingsItem) {
setting = item as RunnableSetting setting = item as RunnableSetting
if (item.iconId != 0) { if (setting.iconId != 0) {
binding.icon.visibility = View.VISIBLE binding.icon.visibility = View.VISIBLE
binding.icon.setImageDrawable( binding.icon.setImageDrawable(
ResourcesCompat.getDrawable( ResourcesCompat.getDrawable(
binding.icon.resources, binding.icon.resources,
item.iconId, setting.iconId,
binding.icon.context.theme binding.icon.context.theme
) )
) )
@ -30,8 +29,8 @@ class RunnableViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA
binding.icon.visibility = View.GONE binding.icon.visibility = View.GONE
} }
binding.textSettingName.setText(item.nameId) binding.textSettingName.text = setting.title
if (item.descriptionId != 0) { if (setting.description.isNotEmpty()) {
binding.textSettingDescription.setText(item.descriptionId) binding.textSettingDescription.setText(item.descriptionId)
binding.textSettingDescription.visibility = View.VISIBLE binding.textSettingDescription.visibility = View.VISIBLE
} else { } else {
@ -44,7 +43,7 @@ class RunnableViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA
} }
override fun onClick(clicked: View) { override fun onClick(clicked: View) {
if (!setting.isRuntimeRunnable && !NativeLibrary.isRunning()) { if (setting.isRunnable) {
setting.runnable.invoke() setting.runnable.invoke()
} }
} }

View File

@ -5,6 +5,7 @@ package org.yuzu.yuzu_emu.features.settings.ui.viewholder
import android.view.View import android.view.View
import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding
import org.yuzu.yuzu_emu.features.settings.model.view.IntSingleChoiceSetting
import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
import org.yuzu.yuzu_emu.features.settings.model.view.SingleChoiceSetting import org.yuzu.yuzu_emu.features.settings.model.view.SingleChoiceSetting
import org.yuzu.yuzu_emu.features.settings.model.view.StringSingleChoiceSetting import org.yuzu.yuzu_emu.features.settings.model.view.StringSingleChoiceSetting
@ -17,16 +18,17 @@ class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: Setti
override fun bind(item: SettingsItem) { override fun bind(item: SettingsItem) {
setting = item setting = item
binding.textSettingName.setText(item.nameId) binding.textSettingName.text = setting.title
if (item.descriptionId != 0) { if (item.description.isNotEmpty()) {
binding.textSettingDescription.setText(item.descriptionId) binding.textSettingDescription.text = item.description
binding.textSettingDescription.visibility = View.VISIBLE binding.textSettingDescription.visibility = View.VISIBLE
} else { } else {
binding.textSettingDescription.visibility = View.GONE binding.textSettingDescription.visibility = View.GONE
} }
binding.textSettingValue.visibility = View.VISIBLE binding.textSettingValue.visibility = View.VISIBLE
if (item is SingleChoiceSetting) { when (item) {
is SingleChoiceSetting -> {
val resMgr = binding.textSettingValue.context.resources val resMgr = binding.textSettingValue.context.resources
val values = resMgr.getIntArray(item.valuesId) val values = resMgr.getIntArray(item.valuesId)
for (i in values.indices) { for (i in values.indices) {
@ -35,12 +37,14 @@ class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: Setti
break break
} }
} }
} else if (item is StringSingleChoiceSetting) {
for (i in item.values.indices) {
if (item.values[i] == item.getSelectedValue()) {
binding.textSettingValue.text = item.choices[i]
break
} }
is StringSingleChoiceSetting -> {
binding.textSettingValue.text = item.getSelectedValue()
}
is IntSingleChoiceSetting -> {
binding.textSettingValue.text = item.getChoiceAt(item.getSelectedValue())
} }
} }
@ -63,17 +67,26 @@ class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: Setti
return return
} }
if (setting is SingleChoiceSetting) { when (setting) {
adapter.onSingleChoiceClick( is SingleChoiceSetting -> adapter.onSingleChoiceClick(
(setting as SingleChoiceSetting), setting as SingleChoiceSetting,
bindingAdapterPosition bindingAdapterPosition
) )
} else if (setting is StringSingleChoiceSetting) {
is StringSingleChoiceSetting -> {
adapter.onStringSingleChoiceClick( adapter.onStringSingleChoiceClick(
(setting as StringSingleChoiceSetting), setting as StringSingleChoiceSetting,
bindingAdapterPosition bindingAdapterPosition
) )
} }
is IntSingleChoiceSetting -> {
adapter.onIntSingleChoiceClick(
setting as IntSingleChoiceSetting,
bindingAdapterPosition
)
}
}
} }
override fun onLongClick(clicked: View): Boolean { override fun onLongClick(clicked: View): Boolean {

View File

@ -17,9 +17,9 @@ class SliderViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAda
override fun bind(item: SettingsItem) { override fun bind(item: SettingsItem) {
setting = item as SliderSetting setting = item as SliderSetting
binding.textSettingName.setText(item.nameId) binding.textSettingName.text = setting.title
if (item.descriptionId != 0) { if (item.description.isNotEmpty()) {
binding.textSettingDescription.setText(item.descriptionId) binding.textSettingDescription.text = setting.description
binding.textSettingDescription.visibility = View.VISIBLE binding.textSettingDescription.visibility = View.VISIBLE
} else { } else {
binding.textSettingDescription.visibility = View.GONE binding.textSettingDescription.visibility = View.GONE

View File

@ -12,16 +12,16 @@ import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter
class SubmenuViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) : class SubmenuViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) :
SettingViewHolder(binding.root, adapter) { SettingViewHolder(binding.root, adapter) {
private lateinit var item: SubmenuSetting private lateinit var setting: SubmenuSetting
override fun bind(item: SettingsItem) { override fun bind(item: SettingsItem) {
this.item = item as SubmenuSetting setting = item as SubmenuSetting
if (item.iconId != 0) { if (setting.iconId != 0) {
binding.icon.visibility = View.VISIBLE binding.icon.visibility = View.VISIBLE
binding.icon.setImageDrawable( binding.icon.setImageDrawable(
ResourcesCompat.getDrawable( ResourcesCompat.getDrawable(
binding.icon.resources, binding.icon.resources,
item.iconId, setting.iconId,
binding.icon.context.theme binding.icon.context.theme
) )
) )
@ -29,9 +29,9 @@ class SubmenuViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAd
binding.icon.visibility = View.GONE binding.icon.visibility = View.GONE
} }
binding.textSettingName.setText(item.nameId) binding.textSettingName.text = setting.title
if (item.descriptionId != 0) { if (setting.description.isNotEmpty()) {
binding.textSettingDescription.setText(item.descriptionId) binding.textSettingDescription.text = setting.description
binding.textSettingDescription.visibility = View.VISIBLE binding.textSettingDescription.visibility = View.VISIBLE
} else { } else {
binding.textSettingDescription.visibility = View.GONE binding.textSettingDescription.visibility = View.GONE
@ -41,7 +41,7 @@ class SubmenuViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAd
} }
override fun onClick(clicked: View) { override fun onClick(clicked: View) {
adapter.onSubmenuClick(item) adapter.onSubmenuClick(setting)
} }
override fun onLongClick(clicked: View): Boolean { override fun onLongClick(clicked: View): Boolean {

View File

@ -18,19 +18,18 @@ class SwitchSettingViewHolder(val binding: ListItemSettingSwitchBinding, adapter
override fun bind(item: SettingsItem) { override fun bind(item: SettingsItem) {
setting = item as SwitchSetting setting = item as SwitchSetting
binding.textSettingName.setText(item.nameId) binding.textSettingName.text = setting.title
if (item.descriptionId != 0) { if (setting.description.isNotEmpty()) {
binding.textSettingDescription.setText(item.descriptionId) binding.textSettingDescription.text = setting.description
binding.textSettingDescription.visibility = View.VISIBLE binding.textSettingDescription.visibility = View.VISIBLE
} else { } else {
binding.textSettingDescription.text = ""
binding.textSettingDescription.visibility = View.GONE binding.textSettingDescription.visibility = View.GONE
} }
binding.switchWidget.setOnCheckedChangeListener(null) binding.switchWidget.setOnCheckedChangeListener(null)
binding.switchWidget.isChecked = setting.getIsChecked(setting.needsRuntimeGlobal) binding.switchWidget.isChecked = setting.getIsChecked(setting.needsRuntimeGlobal)
binding.switchWidget.setOnCheckedChangeListener { _: CompoundButton, _: Boolean -> binding.switchWidget.setOnCheckedChangeListener { _: CompoundButton, _: Boolean ->
adapter.onBooleanClick(item, binding.switchWidget.isChecked, bindingAdapterPosition) adapter.onBooleanClick(setting, binding.switchWidget.isChecked, bindingAdapterPosition)
} }
binding.buttonClear.visibility = if (setting.setting.global || binding.buttonClear.visibility = if (setting.setting.global ||