mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-07-11 02:14:43 -06:00
applied ktlintFormat
This commit is contained in:
parent
ab4f0cae65
commit
bda55af09a
@ -41,6 +41,7 @@ import org.citra.citra_emu.features.settings.model.BooleanSetting
|
||||
import org.citra.citra_emu.features.settings.model.IntSetting
|
||||
import org.citra.citra_emu.features.settings.model.Settings
|
||||
import org.citra.citra_emu.features.settings.model.view.InputBindingSetting
|
||||
import org.citra.citra_emu.features.settings.utils.SettingsFile
|
||||
import org.citra.citra_emu.fragments.EmulationFragment
|
||||
import org.citra.citra_emu.fragments.MessageDialogFragment
|
||||
import org.citra.citra_emu.model.Game
|
||||
@ -53,7 +54,6 @@ import org.citra.citra_emu.utils.Log
|
||||
import org.citra.citra_emu.utils.RefreshRateUtil
|
||||
import org.citra.citra_emu.utils.ThemeUtil
|
||||
import org.citra.citra_emu.viewmodel.EmulationViewModel
|
||||
import org.citra.citra_emu.features.settings.utils.SettingsFile
|
||||
|
||||
class EmulationActivity : AppCompatActivity() {
|
||||
private val preferences: SharedPreferences
|
||||
|
||||
@ -44,7 +44,7 @@ class ScreenAdjustmentUtil(
|
||||
}
|
||||
val portraitValues = context.resources.getIntArray(R.array.portraitValues)
|
||||
|
||||
if (NativeLibrary.isPortraitMode) {
|
||||
if (NativeLibrary.isPortraitMode()) {
|
||||
val currentLayout = settings.get(IntSetting.PORTRAIT_SCREEN_LAYOUT)
|
||||
val pos = portraitValues.indexOf(currentLayout)
|
||||
val layoutOption = portraitValues[(pos + 1) % portraitValues.size]
|
||||
|
||||
@ -17,10 +17,12 @@ import android.view.SurfaceView
|
||||
import android.view.WindowManager
|
||||
import org.citra.citra_emu.NativeLibrary
|
||||
import org.citra.citra_emu.features.settings.model.BooleanSetting
|
||||
import org.citra.citra_emu.features.settings.model.IntSetting
|
||||
import org.citra.citra_emu.features.settings.model.Settings
|
||||
import org.citra.citra_emu.utils.Log
|
||||
|
||||
class SecondaryDisplay(val context: Context, private val settings: Settings) : DisplayManager.DisplayListener {
|
||||
class SecondaryDisplay(val context: Context, private val settings: Settings) :
|
||||
DisplayManager.DisplayListener {
|
||||
private var pres: SecondaryDisplayPresentation? = null
|
||||
private val displayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
|
||||
private val vd: VirtualDisplay
|
||||
@ -89,7 +91,7 @@ class SecondaryDisplay(val context: Context, private val settings: Settings) : D
|
||||
// Theoretically, the NONE option is no longer selectable, but
|
||||
// I am leaving this in for backwards compatibility
|
||||
settings.get(IntSetting.SECONDARY_DISPLAY_LAYOUT) == SecondaryDisplayLayout.NONE.int ||
|
||||
! settings.get(BooleanSetting.ENABLE_SECONDARY_DISPLAY)
|
||||
!settings.get(BooleanSetting.ENABLE_SECONDARY_DISPLAY)
|
||||
) {
|
||||
currentDisplayId = -1
|
||||
vd.display
|
||||
|
||||
@ -126,12 +126,10 @@ enum class BooleanSetting(
|
||||
true
|
||||
);
|
||||
|
||||
override fun valueFromString(string: String): Boolean? {
|
||||
return when (string.trim().lowercase()) {
|
||||
"1", "true" -> true
|
||||
"0", "false" -> false
|
||||
else -> null
|
||||
}
|
||||
override fun valueFromString(string: String): Boolean? = when (string.trim().lowercase()) {
|
||||
"1", "true" -> true
|
||||
"0", "false" -> false
|
||||
else -> null
|
||||
}
|
||||
|
||||
override val isRuntimeEditable: Boolean
|
||||
@ -170,5 +168,5 @@ enum class BooleanSetting(
|
||||
|
||||
fun from(key: String): BooleanSetting? =
|
||||
BooleanSetting.values().firstOrNull { it.key == key }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,24 +10,24 @@ enum class FloatSetting(
|
||||
override val key: String,
|
||||
override val section: String,
|
||||
override val defaultValue: Float,
|
||||
val scale:Int = 1
|
||||
val scale: Int = 1
|
||||
) : AbstractSetting<Float> {
|
||||
LARGE_SCREEN_PROPORTION(SettingKeys.large_screen_proportion(),Settings.SECTION_LAYOUT,2.25f),
|
||||
SECOND_SCREEN_OPACITY(SettingKeys.custom_second_layer_opacity(), Settings.SECTION_RENDERER, 100f),
|
||||
LARGE_SCREEN_PROPORTION(SettingKeys.large_screen_proportion(), Settings.SECTION_LAYOUT, 2.25f),
|
||||
SECOND_SCREEN_OPACITY(
|
||||
SettingKeys.custom_second_layer_opacity(),
|
||||
Settings.SECTION_RENDERER,
|
||||
100f
|
||||
),
|
||||
BACKGROUND_RED(SettingKeys.bg_red(), Settings.SECTION_RENDERER, 0f, 255),
|
||||
BACKGROUND_BLUE(SettingKeys.bg_blue(), Settings.SECTION_RENDERER, 0f, 255),
|
||||
BACKGROUND_GREEN(SettingKeys.bg_green(), Settings.SECTION_RENDERER, 0f, 255),
|
||||
AUDIO_VOLUME(SettingKeys.volume(), Settings.SECTION_AUDIO, 100f, 100);
|
||||
|
||||
// valueFromString reads raw setting from file, scales up for UI
|
||||
override fun valueFromString(string: String): Float? {
|
||||
return string.toFloatOrNull()?.times(scale)
|
||||
}
|
||||
override fun valueFromString(string: String): Float? = string.toFloatOrNull()?.times(scale)
|
||||
|
||||
// valueToString scales back down to raw for file
|
||||
override fun valueToString(value: Float): String {
|
||||
return (value / scale).toString()
|
||||
}
|
||||
override fun valueToString(value: Float): String = (value / scale).toString()
|
||||
|
||||
override val isRuntimeEditable: Boolean
|
||||
get() {
|
||||
|
||||
@ -22,11 +22,9 @@ enum class IntListSetting(
|
||||
|
||||
override fun valueToString(value: List<Int>): String = value.joinToString()
|
||||
|
||||
override fun valueFromString(string: String): List<Int>? {
|
||||
return string.split(",")
|
||||
.mapNotNull { it.trim().toIntOrNull() }
|
||||
.takeIf { canBeEmpty || it.isNotEmpty() }
|
||||
}
|
||||
override fun valueFromString(string: String): List<Int>? = string.split(",")
|
||||
.mapNotNull { it.trim().toIntOrNull() }
|
||||
.takeIf { canBeEmpty || it.isNotEmpty() }
|
||||
override val isRuntimeEditable: Boolean
|
||||
get() {
|
||||
for (setting in NOT_RUNTIME_EDITABLE) {
|
||||
@ -40,7 +38,6 @@ enum class IntListSetting(
|
||||
companion object {
|
||||
private val NOT_RUNTIME_EDITABLE: List<IntListSetting> = emptyList()
|
||||
|
||||
fun from(key: String): IntListSetting? =
|
||||
values().firstOrNull { it.key == key }
|
||||
fun from(key: String): IntListSetting? = values().firstOrNull { it.key == key }
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,15 +65,12 @@ enum class IntSetting(
|
||||
RENDER_3D_WHICH_DISPLAY(SettingKeys.render_3d_which_display(), Settings.SECTION_RENDERER, 0),
|
||||
ASPECT_RATIO(SettingKeys.aspect_ratio(), Settings.SECTION_LAYOUT, 0);
|
||||
|
||||
|
||||
override fun valueFromString(string: String): Int? {
|
||||
return string.toIntOrNull() ?: when (string.trim().lowercase()) {
|
||||
override fun valueFromString(string: String): Int? =
|
||||
string.toIntOrNull() ?: when (string.trim().lowercase()) {
|
||||
"true" -> 1
|
||||
"false" -> 0
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override val isRuntimeEditable: Boolean
|
||||
get() {
|
||||
@ -94,6 +91,5 @@ enum class IntSetting(
|
||||
)
|
||||
|
||||
fun from(key: String): IntSetting? = IntSetting.values().firstOrNull { it.key == key }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,9 +16,11 @@ class Settings {
|
||||
|
||||
fun <T> get(setting: AbstractSetting<T>): T {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return (perGameOverrides[setting.key]
|
||||
?: globalValues[setting.key]
|
||||
?: setting.defaultValue) as T
|
||||
return (
|
||||
perGameOverrides[setting.key]
|
||||
?: globalValues[setting.key]
|
||||
?: setting.defaultValue
|
||||
) as T
|
||||
}
|
||||
|
||||
fun <T> getGlobal(setting: AbstractSetting<T>): T {
|
||||
@ -51,14 +53,14 @@ class Settings {
|
||||
|
||||
/** Merge the globals from other into the current settings. Merge per-game if game id is the same. */
|
||||
fun mergeSettings(other: Settings) {
|
||||
other.globalValues.forEach{ (key, value) ->
|
||||
other.globalValues.forEach { (key, value) ->
|
||||
globalValues[key] = value
|
||||
}
|
||||
|
||||
if (gameId != other.gameId) return
|
||||
|
||||
perGameOverrides.clear()
|
||||
other.perGameOverrides.forEach{ (key, value) ->
|
||||
other.perGameOverrides.forEach { (key, value) ->
|
||||
perGameOverrides[key] = value
|
||||
}
|
||||
}
|
||||
@ -67,9 +69,8 @@ class Settings {
|
||||
perGameOverrides.remove(setting.key)
|
||||
}
|
||||
|
||||
fun hasOverride(setting: AbstractSetting<*>): Boolean {
|
||||
return perGameOverrides.containsKey(setting.key)
|
||||
}
|
||||
fun hasOverride(setting: AbstractSetting<*>): Boolean =
|
||||
perGameOverrides.containsKey(setting.key)
|
||||
|
||||
fun getAllOverrides(): Map<String, Any> = perGameOverrides.toMap()
|
||||
|
||||
@ -89,7 +90,6 @@ class Settings {
|
||||
gameId = null
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
|
||||
const val SECTION_CORE = "Core"
|
||||
|
||||
@ -10,7 +10,7 @@ enum class StringSetting(
|
||||
override val key: String,
|
||||
override val section: String,
|
||||
override val defaultValue: String
|
||||
) : AbstractSetting<String>{
|
||||
) : AbstractSetting<String> {
|
||||
INIT_TIME(SettingKeys.init_time(), Settings.SECTION_SYSTEM, "946731601"),
|
||||
CAMERA_INNER_NAME(SettingKeys.camera_inner_name(), Settings.SECTION_CAMERA, "ndk"),
|
||||
CAMERA_INNER_CONFIG(SettingKeys.camera_inner_config(), Settings.SECTION_CAMERA, "_front"),
|
||||
@ -51,6 +51,5 @@ enum class StringSetting(
|
||||
)
|
||||
|
||||
fun from(key: String): StringSetting? = StringSetting.values().firstOrNull { it.key == key }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,10 +17,10 @@ class DateTimeSetting(
|
||||
val key: String? = null,
|
||||
private val defaultValue: String? = null,
|
||||
override var isEnabled: Boolean = true,
|
||||
private val getValue: (()->String)? = null,
|
||||
private val setValue: ((String)-> Unit)? = null,
|
||||
private val getValue: (() -> String)? = null,
|
||||
private val setValue: ((String) -> Unit)? = null,
|
||||
@StringRes override var disabledMessage: Int =
|
||||
R.string.setting_disabled_description_incompatible_setting
|
||||
R.string.setting_disabled_description_incompatible_setting
|
||||
) : SettingsItem(setting, titleId, descriptionId) {
|
||||
override val type = TYPE_DATETIME_SETTING
|
||||
|
||||
@ -37,7 +37,7 @@ class DateTimeSetting(
|
||||
fun setSelectedValue(datetime: String) {
|
||||
if (setValue != null) {
|
||||
setValue(datetime)
|
||||
}else {
|
||||
} else {
|
||||
val stringSetting = setting as AbstractSetting<String>
|
||||
settings.set(stringSetting, datetime)
|
||||
}
|
||||
|
||||
@ -19,10 +19,8 @@ import org.citra.citra_emu.features.hotkeys.Hotkey
|
||||
import org.citra.citra_emu.features.settings.model.AbstractSetting
|
||||
import org.citra.citra_emu.features.settings.model.Settings
|
||||
|
||||
class InputBindingSetting(
|
||||
val abstractSetting: AbstractSetting<*>,
|
||||
titleId: Int
|
||||
) : SettingsItem(abstractSetting, titleId, 0) {
|
||||
class InputBindingSetting(val abstractSetting: AbstractSetting<*>, titleId: Int) :
|
||||
SettingsItem(abstractSetting, titleId, 0) {
|
||||
private val context: Context get() = CitraApplication.appContext
|
||||
private val preferences: SharedPreferences
|
||||
get() = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
@ -157,7 +155,7 @@ class InputBindingSetting(
|
||||
// Try remove all possible keys we wrote for this setting
|
||||
val oldKey = preferences.getString(reverseKey, "")
|
||||
if (oldKey != "") {
|
||||
//settings.set(setting as AbstractSetting<String>,"")
|
||||
// settings.set(setting as AbstractSetting<String>,"")
|
||||
preferences.edit()
|
||||
.remove(abstractSetting.key) // Used for ui text
|
||||
.remove(oldKey + "_GuestOrientation") // Used for axis orientation
|
||||
|
||||
@ -19,8 +19,8 @@ class MultiChoiceSetting(
|
||||
val key: String? = null,
|
||||
val defaultValue: List<Int>? = null,
|
||||
override var isEnabled: Boolean = true,
|
||||
private val getValue: (()->List<Int>)? = null,
|
||||
private val setValue: ((List<Int>)-> Unit)? = null,
|
||||
private val getValue: (() -> List<Int>)? = null,
|
||||
private val setValue: ((List<Int>) -> Unit)? = null,
|
||||
@StringRes override var disabledMessage: Int =
|
||||
R.string.setting_disabled_description_incompatible_setting
|
||||
) : SettingsItem(setting, titleId, descriptionId) {
|
||||
@ -51,7 +51,7 @@ class MultiChoiceSetting(
|
||||
fun setSelectedValue(selection: List<Int>) {
|
||||
if (setValue != null) {
|
||||
setValue(selection)
|
||||
}else {
|
||||
} else {
|
||||
val intSetting = setting as IntListSetting
|
||||
settings.set(intSetting, selection)
|
||||
}
|
||||
|
||||
@ -39,8 +39,6 @@ abstract class SettingsItem(
|
||||
return this.isEditable && this.isEnabled
|
||||
}
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
const val TYPE_HEADER = 0
|
||||
const val TYPE_SWITCH = 1
|
||||
|
||||
@ -19,8 +19,8 @@ class SingleChoiceSetting(
|
||||
val key: String? = null,
|
||||
val defaultValue: Int? = null,
|
||||
override var isEnabled: Boolean = true,
|
||||
private val getValue: (()->Int)? = null,
|
||||
private val setValue: ((Int)-> Unit)? = null,
|
||||
private val getValue: (() -> Int)? = null,
|
||||
private val setValue: ((Int) -> Unit)? = null,
|
||||
@StringRes override var disabledMessage: Int =
|
||||
R.string.setting_disabled_description_incompatible_setting
|
||||
) : SettingsItem(setting, titleId, descriptionId) {
|
||||
@ -43,7 +43,7 @@ class SingleChoiceSetting(
|
||||
fun setSelectedValue(selection: Int) {
|
||||
if (setValue != null) {
|
||||
setValue(selection)
|
||||
}else {
|
||||
} else {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val backSetting = setting as AbstractSetting<Int>
|
||||
settings.set(backSetting, selection)
|
||||
|
||||
@ -5,13 +5,12 @@
|
||||
package org.citra.citra_emu.features.settings.model.view
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import org.citra.citra_emu.R
|
||||
import org.citra.citra_emu.features.settings.model.AbstractSetting
|
||||
import org.citra.citra_emu.features.settings.model.FloatSetting
|
||||
import org.citra.citra_emu.features.settings.model.Settings
|
||||
import org.citra.citra_emu.utils.Log
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
import org.citra.citra_emu.R
|
||||
import org.citra.citra_emu.features.settings.model.AbstractSetting
|
||||
import org.citra.citra_emu.features.settings.model.Settings
|
||||
import org.citra.citra_emu.utils.Log
|
||||
|
||||
class SliderSetting(
|
||||
val settings: Settings,
|
||||
@ -25,8 +24,8 @@ class SliderSetting(
|
||||
val defaultValue: Float? = null,
|
||||
val rounding: Int = 2,
|
||||
override var isEnabled: Boolean = true,
|
||||
private val getValue: (()->Float)? = null,
|
||||
private val setValue: ((Float)-> Unit)? = null,
|
||||
private val getValue: (() -> Float)? = null,
|
||||
private val setValue: ((Float) -> Unit)? = null,
|
||||
@StringRes override var disabledMessage: Int =
|
||||
R.string.setting_disabled_description_incompatible_setting
|
||||
) : SettingsItem(setting, titleId, descriptionId) {
|
||||
@ -92,7 +91,7 @@ class SliderSetting(
|
||||
fun setSelectedValue(selection: Float) {
|
||||
if (setValue != null) {
|
||||
setValue(selection)
|
||||
}else {
|
||||
} else {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val floatSetting = setting as AbstractSetting<Float>
|
||||
settings.set(floatSetting, selection)
|
||||
|
||||
@ -17,8 +17,8 @@ class StringInputSetting(
|
||||
val defaultValue: String,
|
||||
val characterLimit: Int = 0,
|
||||
override var isEnabled: Boolean = true,
|
||||
private val getValue: (()->String)? = null,
|
||||
private val setValue: ((String)-> Unit)? = null,
|
||||
private val getValue: (() -> String)? = null,
|
||||
private val setValue: ((String) -> Unit)? = null,
|
||||
@StringRes override var disabledMessage: Int =
|
||||
R.string.setting_disabled_description_incompatible_setting
|
||||
) : SettingsItem(setting, titleId, descriptionId) {
|
||||
@ -35,7 +35,7 @@ class StringInputSetting(
|
||||
fun setSelectedValue(selection: String) {
|
||||
if (setValue != null) {
|
||||
setValue.invoke(selection)
|
||||
}else {
|
||||
} else {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val stringSetting = setting as AbstractSetting<String>
|
||||
settings.set(stringSetting, selection)
|
||||
|
||||
@ -19,8 +19,8 @@ class StringSingleChoiceSetting(
|
||||
val key: String? = null,
|
||||
private val defaultValue: String? = null,
|
||||
override var isEnabled: Boolean = true,
|
||||
private val getValue: (()->String)? = null,
|
||||
private val setValue: ((String)-> Unit)? = null,
|
||||
private val getValue: (() -> String)? = null,
|
||||
private val setValue: ((String) -> Unit)? = null,
|
||||
@StringRes override var disabledMessage: Int =
|
||||
R.string.setting_disabled_description_incompatible_setting
|
||||
) : SettingsItem(setting, titleId, descriptionId) {
|
||||
@ -64,7 +64,7 @@ class StringSingleChoiceSetting(
|
||||
fun setSelectedValue(selection: String) {
|
||||
if (setValue != null) {
|
||||
setValue(selection)
|
||||
}else {
|
||||
} else {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val stringSetting = setting as AbstractSetting<String>
|
||||
settings.set(stringSetting, selection)
|
||||
|
||||
@ -43,7 +43,7 @@ class SwitchSetting(
|
||||
fun setChecked(checked: Boolean) {
|
||||
if (setValue != null) {
|
||||
setValue(checked)
|
||||
}else {
|
||||
} else {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val setting = setting as AbstractSetting<Boolean>
|
||||
settings.set(setting, checked)
|
||||
|
||||
@ -6,7 +6,6 @@ package org.citra.citra_emu.features.settings.ui
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import org.citra.citra_emu.CitraApplication
|
||||
import org.citra.citra_emu.NativeLibrary
|
||||
@ -21,7 +20,10 @@ import org.citra.citra_emu.utils.PermissionsHandler
|
||||
import org.citra.citra_emu.utils.SystemSaveGame
|
||||
import org.citra.citra_emu.utils.TurboHelper
|
||||
|
||||
class SettingsActivityPresenter(private val activityView: SettingsActivityView, private val viewModel: SettingsViewModel) {
|
||||
class SettingsActivityPresenter(
|
||||
private val activityView: SettingsActivityView,
|
||||
private val viewModel: SettingsViewModel
|
||||
) {
|
||||
val settings: Settings get() = viewModel.settings
|
||||
|
||||
private var shouldSave = false
|
||||
@ -97,9 +99,9 @@ class SettingsActivityPresenter(private val activityView: SettingsActivityView,
|
||||
if (finishing && shouldSave) {
|
||||
Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI...")
|
||||
if (settings.isPerGame()) {
|
||||
SettingsFile.saveCustomFile(settings,activityView)
|
||||
}else{
|
||||
SettingsFile.saveGlobalFile(settings,activityView)
|
||||
SettingsFile.saveCustomFile(settings, activityView)
|
||||
} else {
|
||||
SettingsFile.saveGlobalFile(settings, activityView)
|
||||
}
|
||||
// merge the edited settings back into the active settings
|
||||
Settings.settings.mergeSettings(settings)
|
||||
|
||||
@ -67,9 +67,9 @@ import org.citra.citra_emu.fragments.MessageDialogFragment
|
||||
import org.citra.citra_emu.fragments.MotionBottomSheetDialogFragment
|
||||
import org.citra.citra_emu.utils.SystemSaveGame
|
||||
|
||||
class SettingsAdapter(val fragmentView: SettingsFragmentView,
|
||||
val context: Context
|
||||
) : RecyclerView.Adapter<SettingViewHolder<SettingsItem>?>(), DialogInterface.OnClickListener,
|
||||
class SettingsAdapter(val fragmentView: SettingsFragmentView, val context: Context) :
|
||||
RecyclerView.Adapter<SettingViewHolder<SettingsItem>?>(),
|
||||
DialogInterface.OnClickListener,
|
||||
DialogInterface.OnMultiChoiceClickListener {
|
||||
private var settings: ArrayList<SettingsItem>? = null
|
||||
private var clickedItem: SettingsItem? = null
|
||||
@ -414,7 +414,7 @@ class SettingsAdapter(val fragmentView: SettingsFragmentView,
|
||||
is Int -> (item.setting!!.defaultValue as Int).toFloat()
|
||||
else -> 0f
|
||||
}
|
||||
onClick(dialog, which)
|
||||
onClick(dialog, which)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
@ -491,7 +491,10 @@ class SettingsAdapter(val fragmentView: SettingsFragmentView,
|
||||
if (sliderval != it.selectedFloat) fragmentView.onSettingChanged()
|
||||
val s = it.setting
|
||||
when {
|
||||
it.setting?.defaultValue is Int -> it.setSelectedValue(sliderProgress.roundToInt())
|
||||
it.setting?.defaultValue is Int -> it.setSelectedValue(
|
||||
sliderProgress.roundToInt()
|
||||
)
|
||||
|
||||
else -> it.setSelectedValue(sliderProgress)
|
||||
}
|
||||
fragmentView.loadSettingsList()
|
||||
@ -522,7 +525,16 @@ class SettingsAdapter(val fragmentView: SettingsFragmentView,
|
||||
mcsetting?.let {
|
||||
val value = getValueForMultiChoiceSelection(it, which)
|
||||
if (it.selectedValues.contains(value) != isChecked) {
|
||||
it.setSelectedValue((if (isChecked) it.selectedValues + value else it.selectedValues - value).sorted())
|
||||
it.setSelectedValue(
|
||||
(
|
||||
if (isChecked) {
|
||||
it.selectedValues + value
|
||||
} else {
|
||||
it.selectedValues -
|
||||
value
|
||||
}
|
||||
).sorted()
|
||||
)
|
||||
fragmentView.onSettingChanged()
|
||||
}
|
||||
fragmentView.loadSettingsList()
|
||||
@ -542,7 +554,7 @@ class SettingsAdapter(val fragmentView: SettingsFragmentView,
|
||||
}
|
||||
|
||||
fun <T> resetSettingToDefault(setting: AbstractSetting<T>, position: Int) {
|
||||
fragmentView.activityView?.settings?.set(setting,setting.defaultValue)
|
||||
fragmentView.activityView?.settings?.set(setting, setting.defaultValue)
|
||||
notifyItemChanged(position)
|
||||
fragmentView.onSettingChanged()
|
||||
fragmentView.loadSettingsList()
|
||||
|
||||
@ -15,10 +15,10 @@ import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import kotlin.getValue
|
||||
import org.citra.citra_emu.databinding.FragmentSettingsBinding
|
||||
import org.citra.citra_emu.features.settings.model.SettingsViewModel
|
||||
import org.citra.citra_emu.features.settings.model.view.SettingsItem
|
||||
import kotlin.getValue
|
||||
|
||||
class SettingsFragment :
|
||||
Fragment(),
|
||||
|
||||
@ -14,6 +14,7 @@ import android.os.Build
|
||||
import android.text.TextUtils
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlin.math.roundToInt
|
||||
import org.citra.citra_emu.CitraApplication
|
||||
import org.citra.citra_emu.R
|
||||
import org.citra.citra_emu.display.ScreenLayout
|
||||
@ -22,8 +23,8 @@ import org.citra.citra_emu.display.StereoWhichDisplay
|
||||
import org.citra.citra_emu.features.settings.model.AbstractSetting
|
||||
import org.citra.citra_emu.features.settings.model.BooleanSetting
|
||||
import org.citra.citra_emu.features.settings.model.FloatSetting
|
||||
import org.citra.citra_emu.features.settings.model.IntSetting
|
||||
import org.citra.citra_emu.features.settings.model.IntListSetting
|
||||
import org.citra.citra_emu.features.settings.model.IntSetting
|
||||
import org.citra.citra_emu.features.settings.model.Settings
|
||||
import org.citra.citra_emu.features.settings.model.StringSetting
|
||||
import org.citra.citra_emu.features.settings.model.view.DateTimeSetting
|
||||
@ -45,7 +46,6 @@ import org.citra.citra_emu.utils.GraphicsUtil
|
||||
import org.citra.citra_emu.utils.Log
|
||||
import org.citra.citra_emu.utils.SystemSaveGame
|
||||
import org.citra.citra_emu.utils.ThemeUtil
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) {
|
||||
private var menuTag: String? = null
|
||||
@ -70,7 +70,6 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
loadSettingsList()
|
||||
}
|
||||
|
||||
|
||||
fun loadSettingsList() {
|
||||
if (!TextUtils.isEmpty(gameId)) {
|
||||
settingsActivity.setToolbarTitle("Application Settings: $gameId")
|
||||
@ -274,7 +273,9 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
private fun checkCountryCompatibility() {
|
||||
if (countryCompatibilityChanged) {
|
||||
countryCompatibilityChanged = false
|
||||
val compatFlags = SystemSaveGame.getCountryCompatibility(settings.get(IntSetting.EMULATED_REGION))
|
||||
val compatFlags = SystemSaveGame.getCountryCompatibility(
|
||||
settings.get(IntSetting.EMULATED_REGION)
|
||||
)
|
||||
if (compatFlags != 0) {
|
||||
var message = ""
|
||||
if (compatFlags and 1 != 0) {
|
||||
@ -839,8 +840,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getInputObject(key: String): AbstractSetting<String> {
|
||||
return object : AbstractSetting<String> {
|
||||
private fun getInputObject(key: String): AbstractSetting<String> =
|
||||
object : AbstractSetting<String> {
|
||||
override val key = key
|
||||
override val section = Settings.SECTION_CONTROLS
|
||||
override val isRuntimeEditable = true
|
||||
@ -850,7 +851,6 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
// TODO: make input mappings also work per-game, which will be easy if we move
|
||||
// them to config files
|
||||
}
|
||||
}
|
||||
private fun addGraphicsSettings(sl: ArrayList<SettingsItem>) {
|
||||
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_graphics))
|
||||
sl.apply {
|
||||
@ -1000,7 +1000,9 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
R.array.render3dValues,
|
||||
IntSetting.STEREOSCOPIC_3D_MODE.key,
|
||||
IntSetting.STEREOSCOPIC_3D_MODE.defaultValue,
|
||||
isEnabled = settings.get(IntSetting.RENDER_3D_WHICH_DISPLAY) != StereoWhichDisplay.NONE.int
|
||||
isEnabled =
|
||||
settings.get(IntSetting.RENDER_3D_WHICH_DISPLAY) !=
|
||||
StereoWhichDisplay.NONE.int
|
||||
)
|
||||
)
|
||||
|
||||
@ -1036,7 +1038,9 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
R.string.swap_eyes_3d_description,
|
||||
BooleanSetting.SWAP_EYES_3D.key,
|
||||
BooleanSetting.SWAP_EYES_3D.defaultValue,
|
||||
isEnabled = settings.get(IntSetting.RENDER_3D_WHICH_DISPLAY) != StereoWhichDisplay.NONE.int
|
||||
isEnabled =
|
||||
settings.get(IntSetting.RENDER_3D_WHICH_DISPLAY) !=
|
||||
StereoWhichDisplay.NONE.int
|
||||
)
|
||||
)
|
||||
|
||||
@ -1052,7 +1056,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
"%",
|
||||
IntSetting.CARDBOARD_SCREEN_SIZE.key,
|
||||
IntSetting.CARDBOARD_SCREEN_SIZE.defaultValue.toFloat(),
|
||||
isEnabled = settings.get(IntSetting.STEREOSCOPIC_3D_MODE) == StereoMode.CARDBOARD_VR.int
|
||||
isEnabled =
|
||||
settings.get(IntSetting.STEREOSCOPIC_3D_MODE) == StereoMode.CARDBOARD_VR.int
|
||||
)
|
||||
)
|
||||
add(
|
||||
@ -1066,7 +1071,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
"%",
|
||||
IntSetting.CARDBOARD_X_SHIFT.key,
|
||||
IntSetting.CARDBOARD_X_SHIFT.defaultValue.toFloat(),
|
||||
isEnabled = settings.get(IntSetting.STEREOSCOPIC_3D_MODE) == StereoMode.CARDBOARD_VR.int
|
||||
isEnabled =
|
||||
settings.get(IntSetting.STEREOSCOPIC_3D_MODE) == StereoMode.CARDBOARD_VR.int
|
||||
)
|
||||
)
|
||||
add(
|
||||
@ -1080,7 +1086,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
"%",
|
||||
IntSetting.CARDBOARD_Y_SHIFT.key,
|
||||
IntSetting.CARDBOARD_Y_SHIFT.defaultValue.toFloat(),
|
||||
isEnabled = settings.get(IntSetting.STEREOSCOPIC_3D_MODE) == StereoMode.CARDBOARD_VR.int
|
||||
isEnabled =
|
||||
settings.get(IntSetting.STEREOSCOPIC_3D_MODE) == StereoMode.CARDBOARD_VR.int
|
||||
)
|
||||
)
|
||||
|
||||
@ -1248,7 +1255,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
R.array.aspectRatioValues,
|
||||
IntSetting.ASPECT_RATIO.key,
|
||||
IntSetting.ASPECT_RATIO.defaultValue,
|
||||
isEnabled = settings.get(IntSetting.SCREEN_LAYOUT) == ScreenLayout.SINGLE_SCREEN.int,
|
||||
isEnabled =
|
||||
settings.get(IntSetting.SCREEN_LAYOUT) == ScreenLayout.SINGLE_SCREEN.int
|
||||
)
|
||||
)
|
||||
add(
|
||||
@ -1301,7 +1309,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
||||
FloatSetting.SECOND_SCREEN_OPACITY.key,
|
||||
FloatSetting.SECOND_SCREEN_OPACITY.defaultValue,
|
||||
0,
|
||||
isEnabled = settings.get(IntSetting.SCREEN_LAYOUT) == ScreenLayout.CUSTOM_LAYOUT.int
|
||||
isEnabled =
|
||||
settings.get(IntSetting.SCREEN_LAYOUT) == ScreenLayout.CUSTOM_LAYOUT.int
|
||||
)
|
||||
)
|
||||
add(HeaderSetting(R.string.bg_color, R.string.bg_color_description))
|
||||
|
||||
@ -20,6 +20,7 @@ import org.citra.citra_emu.features.settings.ui.SettingsAdapter
|
||||
class DateTimeViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) :
|
||||
SettingViewHolder<DateTimeSetting>(binding.root, adapter) {
|
||||
override lateinit var setting: DateTimeSetting
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
override fun bind(item: SettingsItem) {
|
||||
setting = item as? DateTimeSetting ?: return
|
||||
|
||||
@ -9,8 +9,10 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import org.citra.citra_emu.features.settings.model.view.SettingsItem
|
||||
import org.citra.citra_emu.features.settings.ui.SettingsAdapter
|
||||
|
||||
abstract class SettingViewHolder<out T: SettingsItem>(itemView: View, protected val adapter: SettingsAdapter) :
|
||||
RecyclerView.ViewHolder(itemView),
|
||||
abstract class SettingViewHolder<out T : SettingsItem>(
|
||||
itemView: View,
|
||||
protected val adapter: SettingsAdapter
|
||||
) : RecyclerView.ViewHolder(itemView),
|
||||
View.OnClickListener,
|
||||
View.OnLongClickListener {
|
||||
|
||||
@ -23,6 +25,7 @@ abstract class SettingViewHolder<out T: SettingsItem>(itemView: View, protected
|
||||
* The SettingsItem we are holding
|
||||
*/
|
||||
abstract val setting: T?
|
||||
|
||||
/**
|
||||
* Called by the adapter to set this ViewHolder's child views to display the list item
|
||||
* it must now represent.
|
||||
|
||||
@ -6,7 +6,6 @@ package org.citra.citra_emu.features.settings.ui.viewholder
|
||||
|
||||
import android.view.View
|
||||
import org.citra.citra_emu.databinding.ListItemSettingBinding
|
||||
import org.citra.citra_emu.features.settings.model.FloatSetting
|
||||
import org.citra.citra_emu.features.settings.model.view.SettingsItem
|
||||
import org.citra.citra_emu.features.settings.model.view.SliderSetting
|
||||
import org.citra.citra_emu.features.settings.ui.SettingsAdapter
|
||||
|
||||
@ -11,7 +11,6 @@ import java.io.BufferedReader
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import java.util.TreeMap
|
||||
import org.citra.citra_emu.CitraApplication
|
||||
import org.citra.citra_emu.R
|
||||
import org.citra.citra_emu.features.settings.model.AbstractSetting
|
||||
@ -34,14 +33,15 @@ object SettingsFile {
|
||||
|
||||
private val allSettings: List<AbstractSetting<*>> by lazy {
|
||||
BooleanSetting.values().toList() +
|
||||
IntSetting.values().toList() +
|
||||
FloatSetting.values().toList() +
|
||||
StringSetting.values().toList() +
|
||||
IntListSetting.values().toList()
|
||||
IntSetting.values().toList() +
|
||||
FloatSetting.values().toList() +
|
||||
StringSetting.values().toList() +
|
||||
IntListSetting.values().toList()
|
||||
}
|
||||
|
||||
private fun findSettingByKey(key: String): AbstractSetting<*>? =
|
||||
allSettings.firstOrNull { it.key == key }
|
||||
|
||||
/**
|
||||
* Reads a given .ini file from disk and updates a instance of the Settings class appropriately
|
||||
*
|
||||
@ -66,7 +66,7 @@ object SettingsFile {
|
||||
var line: String?
|
||||
while (reader.readLine().also { line = it } != null) {
|
||||
if (line!!.startsWith("[") && line.endsWith("]")) {
|
||||
currentSection = line.substring(1, line.length-1)
|
||||
currentSection = line.substring(1, line.length - 1)
|
||||
} else if (currentSection != null) {
|
||||
val pair = parseLineToKeyValuePair(line) ?: continue
|
||||
val (key, rawValue) = pair
|
||||
@ -95,7 +95,7 @@ object SettingsFile {
|
||||
* Load global settings from the config file into the settings instance
|
||||
*/
|
||||
fun loadSettings(settings: Settings, view: SettingsActivityView? = null) {
|
||||
readFile(getSettingsFile(FILE_NAME_CONFIG),settings,false,view)
|
||||
readFile(getSettingsFile(FILE_NAME_CONFIG), settings, false, view)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,10 +134,7 @@ object SettingsFile {
|
||||
* @param settings The Settings instance we are saving
|
||||
* @param view The current view.
|
||||
*/
|
||||
fun saveGlobalFile(
|
||||
settings: Settings,
|
||||
view: SettingsActivityView? = null
|
||||
) {
|
||||
fun saveGlobalFile(settings: Settings, view: SettingsActivityView? = null) {
|
||||
val ini = getSettingsFile(FILE_NAME_CONFIG)
|
||||
try {
|
||||
val context: Context = CitraApplication.appContext
|
||||
@ -158,7 +155,7 @@ object SettingsFile {
|
||||
Log.error("[SettingsFile] File not found: $FILE_NAME_CONFIG.ini: ${e.message}")
|
||||
view?.showToastMessage(
|
||||
CitraApplication.appContext
|
||||
.getString(R.string.error_saving, fileName, e.message),
|
||||
.getString(R.string.error_saving, FILE_NAME_CONFIG, e.message),
|
||||
false
|
||||
)
|
||||
}
|
||||
@ -168,10 +165,7 @@ object SettingsFile {
|
||||
* Save the per-game overrides to a per-game config file
|
||||
*/
|
||||
|
||||
fun saveCustomFile(
|
||||
settings: Settings,
|
||||
view: SettingsActivityView? = null
|
||||
) {
|
||||
fun saveCustomFile(settings: Settings, view: SettingsActivityView? = null) {
|
||||
if (!settings.isPerGame()) return
|
||||
val ini = getOrCreateCustomGameSettingsFile(settings.gameId!!)
|
||||
try {
|
||||
@ -189,7 +183,9 @@ object SettingsFile {
|
||||
outputStream?.flush()
|
||||
outputStream?.close()
|
||||
} catch (e: Exception) {
|
||||
Log.error("[SettingsFile] Error saving custom file for ${settings.gameId}: ${e.message}")
|
||||
Log.error(
|
||||
"[SettingsFile] Error saving custom file for ${settings.gameId}: ${e.message}"
|
||||
)
|
||||
view?.onSettingsFileNotFound()
|
||||
}
|
||||
}
|
||||
@ -206,7 +202,11 @@ object SettingsFile {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> writeSingleSettingToFile(ini: DocumentFile, setting: AbstractSetting<T>, value: T) {
|
||||
private fun <T> writeSingleSettingToFile(
|
||||
ini: DocumentFile,
|
||||
setting: AbstractSetting<T>,
|
||||
value: T
|
||||
) {
|
||||
try {
|
||||
val context = CitraApplication.appContext
|
||||
val inputStream = context.contentResolver.openInputStream(ini.uri)
|
||||
@ -221,6 +221,7 @@ object SettingsFile {
|
||||
Log.error("[SettingsFile] Error saving setting ${setting.key}: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <T> writeSettingToWini(writer: Wini, descriptor: AbstractSetting<T>, value: Any) {
|
||||
val typedValue = value as T
|
||||
@ -236,7 +237,6 @@ object SettingsFile {
|
||||
return Pair(key, value)
|
||||
}
|
||||
|
||||
|
||||
fun getSettingsFile(fileName: String): DocumentFile {
|
||||
val root = DocumentFile.fromTreeUri(CitraApplication.appContext, Uri.parse(userDirectory))
|
||||
val configDirectory = root!!.findFile("config")
|
||||
|
||||
@ -35,7 +35,6 @@ import android.widget.PopupMenu
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.graphics.Insets
|
||||
@ -46,6 +45,7 @@ import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.drawerlayout.widget.DrawerLayout.DrawerListener
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
@ -199,7 +199,11 @@ class EmulationFragment :
|
||||
retainInstance = true
|
||||
emulationState = EmulationState(game.path)
|
||||
screenAdjustmentUtil =
|
||||
ScreenAdjustmentUtil(requireContext(), requireActivity().windowManager, Settings.settings)
|
||||
ScreenAdjustmentUtil(
|
||||
requireContext(),
|
||||
requireActivity().windowManager,
|
||||
Settings.settings
|
||||
)
|
||||
EmulationLifecycleUtil.addPauseResumeHook(onPause)
|
||||
EmulationLifecycleUtil.addShutdownHook(onShutdown)
|
||||
}
|
||||
@ -752,8 +756,10 @@ class EmulationFragment :
|
||||
}
|
||||
|
||||
R.id.menu_performance_overlay_show -> {
|
||||
Settings.settings.update(BooleanSetting.PERF_OVERLAY_ENABLE,
|
||||
Settings.settings.get(BooleanSetting.PERF_OVERLAY_ENABLE))
|
||||
Settings.settings.update(
|
||||
BooleanSetting.PERF_OVERLAY_ENABLE,
|
||||
Settings.settings.get(BooleanSetting.PERF_OVERLAY_ENABLE)
|
||||
)
|
||||
SettingsFile.saveSetting(BooleanSetting.PERF_OVERLAY_ENABLE, Settings.settings)
|
||||
updateShowPerformanceOverlay()
|
||||
true
|
||||
@ -1474,7 +1480,7 @@ class EmulationFragment :
|
||||
val dividerString = "\u00A0\u2502 "
|
||||
if (perfStats[fps] > 0) {
|
||||
if (Settings.settings.get(BooleanSetting.PERF_OVERLAY_SHOW_FPS)) {
|
||||
sb.append(String.format("FPS:\u00A0%d", (perfStats[FPS] + 0.5).toInt()))
|
||||
sb.append(String.format("FPS:\u00A0%d", (perfStats[fps] + 0.5).toInt()))
|
||||
}
|
||||
|
||||
if (Settings.settings.get(BooleanSetting.PERF_OVERLAY_SHOW_FRAMETIME)) {
|
||||
|
||||
@ -11,6 +11,7 @@ import org.citra.citra_emu.features.settings.model.Settings
|
||||
|
||||
class EmulationViewModel : ViewModel() {
|
||||
val emulationStarted get() = _emulationStarted.asStateFlow()
|
||||
|
||||
// convenience shortcut for
|
||||
val settings = Settings.settings
|
||||
|
||||
@ -25,7 +26,6 @@ class EmulationViewModel : ViewModel() {
|
||||
val shaderMessage get() = _shaderMessage.asStateFlow()
|
||||
private val _shaderMessage = MutableStateFlow("")
|
||||
|
||||
|
||||
fun setShaderProgress(progress: Int) {
|
||||
_shaderProgress.value = progress
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user