From c4d0d025094006688654e7ccf22789c99ff7e9e5 Mon Sep 17 00:00:00 2001 From: lynxnb Date: Sun, 5 Mar 2023 19:09:43 +0100 Subject: [PATCH] Simplify `OnScreenConfiguration` `ControllerConfigurationDummy` was removed as it isn't needed anymore, and the remaining classes simplified. --- .../skyline/input/onscreen/OnScreenButton.kt | 5 +-- .../input/onscreen/OnScreenConfiguration.kt | 39 ++++--------------- .../input/onscreen/OnScreenItemDefinitions.kt | 1 - 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenButton.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenButton.kt index 1ff87fe3..eaf63719 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenButton.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenButton.kt @@ -35,12 +35,11 @@ abstract class OnScreenButton( const val CONFIGURED_ASPECT_RATIO = 2074f / 874f } - val config = if (onScreenControllerView.isInEditMode) ControllerConfigurationDummy(defaultRelativeX, defaultRelativeY) - else ControllerConfigurationImpl(onScreenControllerView.context, buttonId, defaultRelativeX, defaultRelativeY) + val config = OnScreenConfiguration(onScreenControllerView.context, buttonId, defaultRelativeX, defaultRelativeY) protected val drawable = ContextCompat.getDrawable(onScreenControllerView.context, drawableId)!! - internal val buttonSymbolPaint = Paint().apply { + private val buttonSymbolPaint = Paint().apply { color = config.textColor typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD) isAntiAlias = true diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenConfiguration.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenConfiguration.kt index 7a535f5a..d8919a72 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenConfiguration.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenConfiguration.kt @@ -10,37 +10,14 @@ import emu.skyline.input.ButtonId import emu.skyline.utils.SwitchColors import emu.skyline.utils.sharedPreferences -interface ControllerConfiguration { - var alpha : Int - var textColor : Int - var backgroundColor : Int - var enabled : Boolean - var globalScale : Float - var relativeX : Float - var relativeY : Float -} - -/** - * Dummy implementation so layout editor is able to render [OnScreenControllerView] when [android.view.View.isInEditMode] is true - */ -class ControllerConfigurationDummy(defaultRelativeX : Float, defaultRelativeY : Float) : ControllerConfiguration { - override var alpha : Int = 155 - override var textColor = SwitchColors.BLACK.color - override var backgroundColor = SwitchColors.WHITE.color - override var enabled = true - override var globalScale = 1f - override var relativeX = defaultRelativeX - override var relativeY = defaultRelativeY -} - -class ControllerConfigurationImpl(private val context : Context, private val buttonId : ButtonId, defaultRelativeX : Float, defaultRelativeY : Float) : ControllerConfiguration { +class OnScreenConfiguration(private val context : Context, private val buttonId : ButtonId, defaultRelativeX : Float, defaultRelativeY : Float) { private inline fun config(default : T, prefix : String = "${buttonId.name}_") = sharedPreferences(context, default, prefix, "controller_config") - override var alpha by config(155, "") - override var textColor by config(SwitchColors.BLACK.color) - override var backgroundColor by config(SwitchColors.WHITE.color) - override var enabled by config(true) - override var globalScale by config(1.15f, "") - override var relativeX by config(defaultRelativeX) - override var relativeY by config(defaultRelativeY) + var alpha by config(155, "") + var textColor by config(SwitchColors.BLACK.color) + var backgroundColor by config(SwitchColors.WHITE.color) + var enabled by config(true) + var globalScale by config(1.15f, "") + var relativeX by config(defaultRelativeX) + var relativeY by config(defaultRelativeY) } diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenItemDefinitions.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenItemDefinitions.kt index 55aecba2..2e981db2 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenItemDefinitions.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenItemDefinitions.kt @@ -7,7 +7,6 @@ package emu.skyline.input.onscreen import android.graphics.Canvas import android.graphics.PointF -import android.graphics.Typeface import android.os.SystemClock import androidx.core.graphics.minus import emu.skyline.R