Enable OSC per-button text and color selection

This commit is contained in:
lynxnb 2023-04-01 00:04:33 +02:00 committed by Billy Laws
parent c7d213c3ea
commit 659e090d38
4 changed files with 17 additions and 35 deletions

View File

@ -243,6 +243,8 @@ abstract class OnScreenButton(
override fun resetConfig() { override fun resetConfig() {
config.enabled = defaultEnabled config.enabled = defaultEnabled
config.alpha = OnScreenConfiguration.DefaultAlpha config.alpha = OnScreenConfiguration.DefaultAlpha
config.textColor = OnScreenConfiguration.DefaultTextColor
config.backgroundColor = OnScreenConfiguration.DefaultBackgroundColor
config.scale = OnScreenConfiguration.DefaultScale config.scale = OnScreenConfiguration.DefaultScale
config.relativeX = defaultRelativeX config.relativeX = defaultRelativeX
config.relativeY = defaultRelativeY config.relativeY = defaultRelativeY

View File

@ -350,25 +350,17 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
invalidate() invalidate()
} }
fun getTextColor() : Int { // Used to retrieve the current color to use in the color picker dialog
return controls.globalTextColor fun getButtonTextColor() = editInfo.editButton.config.textColor
} fun getButtonBackgroundColor() = editInfo.editButton.config.backgroundColor
fun getBackGroundColor() : Int { fun setButtonTextColor(color : Int) {
return controls.globalBackgroundColor editInfo.editButton.config.textColor = color
}
fun setTextColor(color : Int) {
for (button in controls.allButtons) {
button.config.textColor = color
}
invalidate() invalidate()
} }
fun setBackGroundColor(color : Int) { fun setButtonBackgroundColor(color : Int) {
for (button in controls.allButtons) { editInfo.editButton.config.backgroundColor = color
button.config.backgroundColor = color
}
invalidate() invalidate()
} }
@ -411,15 +403,15 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
} }
override var textColor : Int override var textColor : Int
get() = controls.globalTextColor get() = controls.allButtons.first().config.textColor
set(value) { set(value) {
setTextColor(value) controls.allButtons.forEach { it.config.textColor = value }
} }
override var backgroundColor : Int override var backgroundColor : Int
get() = controls.globalBackgroundColor get() = controls.allButtons.first().config.backgroundColor
set(value) { set(value) {
setBackGroundColor(value) controls.allButtons.forEach { it.config.backgroundColor = value }
} }
override var scale : Float override var scale : Float

View File

@ -38,15 +38,15 @@ class OnScreenEditActivity : AppCompatActivity() {
private fun paletteAction() { private fun paletteAction() {
DoubleColorPicker(this@OnScreenEditActivity).apply { DoubleColorPicker(this@OnScreenEditActivity).apply {
setTitle(this@OnScreenEditActivity.getString(R.string.osc_background_color)) setTitle(this@OnScreenEditActivity.getString(R.string.osc_background_color))
setDefaultColorButton(binding.onScreenControllerView.getBackGroundColor()) setDefaultColorButton(binding.onScreenControllerView.getButtonBackgroundColor())
setRoundColorButton(true) setRoundColorButton(true)
setColors(*SwitchColors.colors.toIntArray()) setColors(*SwitchColors.colors.toIntArray())
setDefaultDoubleColorButton(binding.onScreenControllerView.getTextColor()) setDefaultDoubleColorButton(binding.onScreenControllerView.getButtonTextColor())
setSecondTitle(this@OnScreenEditActivity.getString(R.string.osc_text_color)) setSecondTitle(this@OnScreenEditActivity.getString(R.string.osc_text_color))
setOnChooseDoubleColorListener(object : OnChooseDoubleColorListener { setOnChooseDoubleColorListener(object : OnChooseDoubleColorListener {
override fun onChooseColor(position : Int, color : Int, position2 : Int, color2 : Int) { override fun onChooseColor(position : Int, color : Int, position2 : Int, color2 : Int) {
binding.onScreenControllerView.setBackGroundColor(SwitchColors.colors[position]) binding.onScreenControllerView.setButtonBackgroundColor(SwitchColors.colors[position])
binding.onScreenControllerView.setTextColor(SwitchColors.colors[position2]) binding.onScreenControllerView.setButtonTextColor(SwitchColors.colors[position2])
} }
override fun onCancel() {} override fun onCancel() {}

View File

@ -240,16 +240,4 @@ class Controls(onScreenControllerView : OnScreenControllerView) {
val triggerButtons = listOf(buttonZL, buttonZR) val triggerButtons = listOf(buttonZL, buttonZR)
val allButtons = circularButtons + joysticks + rectangularButtons + triggerButtons val allButtons = circularButtons + joysticks + rectangularButtons + triggerButtons
/**
* We can take any of the global text color variables from the buttons
*/
val globalTextColor
get() = circularButtons.first().config.textColor
/**
* We can take any of the global background color variables from the buttons
*/
val globalBackgroundColor
get() = circularButtons.first().config.backgroundColor
} }