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() {
config.enabled = defaultEnabled
config.alpha = OnScreenConfiguration.DefaultAlpha
config.textColor = OnScreenConfiguration.DefaultTextColor
config.backgroundColor = OnScreenConfiguration.DefaultBackgroundColor
config.scale = OnScreenConfiguration.DefaultScale
config.relativeX = defaultRelativeX
config.relativeY = defaultRelativeY

View File

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

View File

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

View File

@ -240,16 +240,4 @@ class Controls(onScreenControllerView : OnScreenControllerView) {
val triggerButtons = listOf(buttonZL, buttonZR)
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
}