diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FloatSliderSetting.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FloatSliderSetting.kt index 5b2ee40fe7..c226e3e47e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FloatSliderSetting.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FloatSliderSetting.kt @@ -6,7 +6,8 @@ import android.content.Context import org.dolphinemu.dolphinemu.features.settings.model.AbstractFloatSetting import org.dolphinemu.dolphinemu.features.settings.model.AbstractSetting import org.dolphinemu.dolphinemu.features.settings.model.Settings -import kotlin.math.roundToInt +import java.math.BigDecimal +import java.math.MathContext open class FloatSliderSetting : SliderSetting { var floatSetting: AbstractFloatSetting @@ -19,11 +20,12 @@ open class FloatSliderSetting : SliderSetting { setting: AbstractFloatSetting, titleId: Int, descriptionId: Int, - min: Int, - max: Int, + min: Float, + max: Float, units: String?, - stepSize: Int - ) : super(context, titleId, descriptionId, min, max, units, stepSize) { + stepSize: Float, + showDecimal: Boolean + ) : super(context, titleId, descriptionId, min, max, units, stepSize, showDecimal) { floatSetting = setting } @@ -31,17 +33,21 @@ open class FloatSliderSetting : SliderSetting { setting: AbstractFloatSetting, name: CharSequence, description: CharSequence?, - min: Int, - max: Int, - units: String? - ) : super(name, description, min, max, units) { + min: Float, + max: Float, + units: String?, + showDecimal: Boolean + ) : super(name, description, min, max, units, showDecimal) { floatSetting = setting } - override val selectedValue: Int - get() = floatSetting.float.roundToInt() + override val selectedValue: Float + get() = floatSetting.float open fun setSelectedValue(settings: Settings?, selection: Float) { - floatSetting.setFloat(settings!!, selection) + floatSetting.setFloat( + settings!!, + BigDecimal((selection).toDouble()).round(MathContext(3)).toFloat() + ) } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/IntSliderSetting.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/IntSliderSetting.kt index 23bcd49317..09a415fc97 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/IntSliderSetting.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/IntSliderSetting.kt @@ -16,7 +16,7 @@ class IntSliderSetting( max: Int, units: String?, stepSize: Int -) : SliderSetting(context, titleId, descriptionId, min, max, units, stepSize) { +) : SliderSetting(context, titleId, descriptionId, min, max, units, stepSize, false) { override val setting: AbstractSetting get() = intSetting diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/PercentSliderSetting.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/PercentSliderSetting.kt index db6454b0c5..165bdebdc8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/PercentSliderSetting.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/PercentSliderSetting.kt @@ -4,24 +4,38 @@ package org.dolphinemu.dolphinemu.features.settings.model.view import android.content.Context import org.dolphinemu.dolphinemu.features.settings.model.AbstractFloatSetting -import org.dolphinemu.dolphinemu.features.settings.model.AbstractSetting import org.dolphinemu.dolphinemu.features.settings.model.Settings -import kotlin.math.roundToInt +import java.math.BigDecimal +import java.math.MathContext class PercentSliderSetting( context: Context, override val setting: AbstractFloatSetting, titleId: Int, descriptionId: Int, - min: Int, - max: Int, + min: Float, + max: Float, units: String?, - stepSize: Int -) : FloatSliderSetting(context, setting, titleId, descriptionId, min, max, units, stepSize) { - override val selectedValue: Int - get() = (floatSetting.float * 100).roundToInt() + stepSize: Float, + showDecimal: Boolean +) : FloatSliderSetting( + context, + setting, + titleId, + descriptionId, + min, + max, + units, + stepSize, + showDecimal +) { + override val selectedValue: Float + get() = (floatSetting.float * 100) override fun setSelectedValue(settings: Settings?, selection: Float) { - floatSetting.setFloat(settings!!, selection / 100) + floatSetting.setFloat( + settings!!, + BigDecimal((selection / 100).toDouble()).round(MathContext(3)).toFloat() + ) } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SliderSetting.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SliderSetting.kt index f595c4cea3..d3edccc025 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SliderSetting.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SliderSetting.kt @@ -4,44 +4,50 @@ package org.dolphinemu.dolphinemu.features.settings.model.view import android.content.Context -abstract class SliderSetting : SettingsItem { +sealed class SliderSetting : SettingsItem { override val type: Int = TYPE_SLIDER - var min: Int + var min: Any private set - var max: Int + var max: Any private set var units: String? private set - var stepSize = 0 + var stepSize: Any = 0 + private set + var showDecimal: Boolean = false private set constructor( context: Context, nameId: Int, descriptionId: Int, - min: Int, - max: Int, + min: Any, + max: Any, units: String?, - stepSize: Int + stepSize: Any, + showDecimal: Boolean ) : super(context, nameId, descriptionId) { this.min = min this.max = max this.units = units this.stepSize = stepSize + this.showDecimal = showDecimal } constructor( name: CharSequence, description: CharSequence?, - min: Int, - max: Int, - units: String? + min: Any, + max: Any, + units: String?, + showDecimal: Boolean ) : super(name, description) { this.min = min this.max = max this.units = units + this.showDecimal = showDecimal } - abstract val selectedValue: Int + abstract val selectedValue: Any } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/MenuTag.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/MenuTag.kt index 6b4def552c..0bfcb96d6c 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/MenuTag.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/MenuTag.kt @@ -19,6 +19,7 @@ enum class MenuTag { DEBUG("debug"), GRAPHICS("graphics"), ENHANCEMENTS("enhancements"), + COLOR_CORRECTION("color_correction"), STEREOSCOPY("stereoscopy"), HACKS("hacks"), STATISTICS("statistics"), diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt index 3623f167bb..eff1b3ba13 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt @@ -51,7 +51,7 @@ class SettingsAdapter( private var settingsList: ArrayList? = null private var clickedItem: SettingsItem? = null private var clickedPosition: Int = -1 - private var seekbarProgress = 0 + private var seekbarProgress: Float = 0f private var dialog: AlertDialog? = null private var textSliderValue: TextView? = null @@ -229,21 +229,37 @@ class SettingsAdapter( fun onSliderClick(item: SliderSetting, position: Int) { clickedItem = item clickedPosition = position - seekbarProgress = item.selectedValue + seekbarProgress = when (item) { + is FloatSliderSetting -> item.selectedValue + is IntSliderSetting -> item.selectedValue.toFloat() + } val inflater = LayoutInflater.from(fragmentView.fragmentActivity) val binding = DialogSliderBinding.inflate(inflater) textSliderValue = binding.textValue - textSliderValue!!.text = seekbarProgress.toString() + textSliderValue!!.text = if (item.showDecimal) { + String.format("%.2f", seekbarProgress) + } else { + seekbarProgress.toInt().toString() + } binding.textUnits.text = item.units val slider = binding.slider - slider.valueFrom = item.min.toFloat() - slider.valueTo = item.max.toFloat() - slider.value = seekbarProgress.toFloat() - slider.stepSize = item.stepSize.toFloat() + when (item) { + is FloatSliderSetting -> { + slider.valueFrom = item.min as Float + slider.valueTo = item.max as Float + slider.stepSize = item.stepSize as Float + } + is IntSliderSetting -> { + slider.valueFrom = (item.min as Int).toFloat() + slider.valueTo = (item.max as Int).toFloat() + slider.stepSize = (item.stepSize as Int).toFloat() + } + } + slider.value = seekbarProgress slider.addOnChangeListener(this) dialog = MaterialAlertDialogBuilder(fragmentView.fragmentActivity) @@ -480,8 +496,10 @@ class SettingsAdapter( } is IntSliderSetting -> { val sliderSetting = clickedItem as IntSliderSetting - if (sliderSetting.selectedValue != seekbarProgress) fragmentView.onSettingChanged() - sliderSetting.setSelectedValue(settings, seekbarProgress) + if (sliderSetting.selectedValue != seekbarProgress.toInt()) { + fragmentView.onSettingChanged() + } + sliderSetting.setSelectedValue(settings, seekbarProgress.toInt()) closeDialog() } is FloatSliderSetting -> { @@ -489,13 +507,13 @@ class SettingsAdapter( if (sliderSetting.selectedValue != seekbarProgress) fragmentView.onSettingChanged() - sliderSetting.setSelectedValue(settings, seekbarProgress.toFloat()) + sliderSetting.setSelectedValue(settings, seekbarProgress) closeDialog() } } clickedItem = null - seekbarProgress = -1 + seekbarProgress = -1f } fun closeDialog() { @@ -510,8 +528,12 @@ class SettingsAdapter( } override fun onValueChange(slider: Slider, progress: Float, fromUser: Boolean) { - seekbarProgress = progress.toInt() - textSliderValue!!.text = seekbarProgress.toString() + seekbarProgress = progress + textSliderValue!!.text = if ((clickedItem as SliderSetting).showDecimal) { + String.format("%.2f", seekbarProgress) + } else { + seekbarProgress.toInt().toString() + } } private fun getValueForSingleChoiceSelection(item: SingleChoiceSetting, which: Int): Int { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt index 99b95bb7e3..15d678f752 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt @@ -34,6 +34,7 @@ import org.dolphinemu.dolphinemu.model.GpuDriverMetadata import org.dolphinemu.dolphinemu.ui.main.MainPresenter import org.dolphinemu.dolphinemu.utils.* import java.util.* +import kotlin.collections.ArrayList import kotlin.math.ceil import kotlin.math.floor @@ -119,6 +120,7 @@ class SettingsFragmentPresenter( MenuTag.GCPAD_TYPE -> addGcPadSettings(sl) MenuTag.WIIMOTE -> addWiimoteSettings(sl) MenuTag.ENHANCEMENTS -> addEnhanceSettings(sl) + MenuTag.COLOR_CORRECTION -> addColorCorrectionSettings(sl) MenuTag.STEREOSCOPY -> addStereoSettings(sl) MenuTag.HACKS -> addHackSettings(sl) MenuTag.STATISTICS -> addStatisticsSettings(sl) @@ -249,10 +251,11 @@ class SettingsFragmentPresenter( FloatSetting.MAIN_EMULATION_SPEED, R.string.speed_limit, 0, - 0, - 200, + 0f, + 200f, "%", - 1 + 1f, + false ) ) sl.add( @@ -1000,10 +1003,11 @@ class SettingsFragmentPresenter( FloatSetting.MAIN_OVERCLOCK, R.string.overclock_title, R.string.overclock_title_description, - 0, - 400, + 0f, + 400f, "%", - 1 + 1f, + false ) ) @@ -2349,9 +2353,10 @@ class SettingsFragmentPresenter( InputMappingDoubleSetting(setting), setting.getUiName(), "", - ceil(setting.getDoubleMin()).toInt(), - floor(setting.getDoubleMax()).toInt(), - setting.getUiSuffix() + ceil(setting.getDoubleMin()).toFloat(), + floor(setting.getDoubleMax()).toFloat(), + setting.getUiSuffix(), + false ) ) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.kt index 9009be4e7d..6dde8749c2 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.kt @@ -7,6 +7,7 @@ import android.text.TextUtils import android.view.View import org.dolphinemu.dolphinemu.R import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding +import org.dolphinemu.dolphinemu.features.settings.model.view.IntSliderSetting import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter @@ -14,7 +15,7 @@ import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter class SliderViewHolder( private val binding: ListItemSettingBinding, adapter: SettingsAdapter?, private val context: Context -) : SettingViewHolder(binding.getRoot(), adapter!!) { +) : SettingViewHolder(binding.root, adapter!!) { private lateinit var setting: SliderSetting override val item: SettingsItem @@ -28,11 +29,25 @@ class SliderViewHolder( if (!TextUtils.isEmpty(item.description)) { binding.textSettingDescription.text = item.description } else { - binding.textSettingDescription.text = context.getString( - R.string.slider_setting_value, - setting.selectedValue, - setting.units - ) + val selectedValue: Float = if (item is IntSliderSetting) { + (setting.selectedValue as Int).toFloat() + } else { + setting.selectedValue as Float + } + + if (setting.showDecimal) { + binding.textSettingDescription.text = String.format( + context.getString(R.string.slider_setting_float_value), + selectedValue, + setting.units + ) + } else { + binding.textSettingDescription.text = String.format( + context.getString(R.string.slider_setting_value), + selectedValue, + setting.units + ) + } } setStyle(binding.textSettingName, setting) diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 17421bb7ed..015b19bae5 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -632,7 +632,8 @@ It can efficiently compress both junk data and encrypted Wii data. Enabled Default Values - %1$d%2$s + %.0f%2$s + %.2f%2$s Disc %1$d GameCube Adapter couldn\'t be opened. Please re-plug the device. The selected GameCube controller is set to \"None\"