From 62630d53ddd08a48a20fe7be28c37afcd0359978 Mon Sep 17 00:00:00 2001 From: "Md. Touhidur Rahman" Date: Fri, 19 Sep 2025 23:16:52 +0600 Subject: [PATCH] lighten `AlternatingStateManager` --- .../unciv/logic/AlternatingStateManager.kt | 16 +++++++-------- .../ui/screens/worldscreen/chat/ChatButton.kt | 20 ++++++------------- .../status/MultiplayerStatusButton.kt | 20 ++++++------------- 3 files changed, 20 insertions(+), 36 deletions(-) diff --git a/core/src/com/unciv/logic/AlternatingStateManager.kt b/core/src/com/unciv/logic/AlternatingStateManager.kt index b3624da95e..707186035c 100644 --- a/core/src/com/unciv/logic/AlternatingStateManager.kt +++ b/core/src/com/unciv/logic/AlternatingStateManager.kt @@ -1,5 +1,6 @@ package com.unciv.logic +import com.badlogic.gdx.Gdx import com.unciv.utils.Concurrency import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -9,11 +10,10 @@ import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime -class AlternatingStateManager( +class AlternatingStateManager( private val name: String, - private val state: State, - private val originalState: (State) -> Unit, - private val alternateState: (State) -> Unit + private val originalState: () -> Unit, + private val alternateState: () -> Unit ) { private var job: Job? = null @@ -28,15 +28,15 @@ class AlternatingStateManager( var isAlternateState = true while (true) { if (isAlternateState) { - alternateState(state) + Gdx.app.postRunnable(alternateState) isAlternateState = false } else { - originalState(state) + Gdx.app.postRunnable(originalState) isAlternateState = true } if (Clock.System.now() - startTime >= duration) { - originalState(state) + Gdx.app.postRunnable(originalState) return@run } @@ -47,6 +47,6 @@ class AlternatingStateManager( fun stop() { job?.cancel() - originalState(state) + Gdx.app.postRunnable(originalState) } } diff --git a/core/src/com/unciv/ui/screens/worldscreen/chat/ChatButton.kt b/core/src/com/unciv/ui/screens/worldscreen/chat/ChatButton.kt index 2f9e03e77f..73fdf7e8dd 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/chat/ChatButton.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/chat/ChatButton.kt @@ -1,6 +1,5 @@ package com.unciv.ui.screens.worldscreen.chat -import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.utils.Align import com.unciv.UncivGame @@ -30,19 +29,12 @@ class ChatButton(val worldScreen: WorldScreen) : IconTextButton( val flash = AlternatingStateManager( name = "ChatButton color flash", - state = object { - val initialColor = fontColor - val targetColor = Color.ORANGE - }, originalState = { state -> - Gdx.app.postRunnable { - icon?.color = state.initialColor - label.color = state.initialColor - } - }, alternateState = { state -> - Gdx.app.postRunnable { - icon?.color = state.targetColor - label.color = state.targetColor - } + originalState = { + icon?.color = fontColor + label.color = fontColor + }, alternateState = { + icon?.color = Color.ORANGE + label.color = Color.ORANGE } ) diff --git a/core/src/com/unciv/ui/screens/worldscreen/status/MultiplayerStatusButton.kt b/core/src/com/unciv/ui/screens/worldscreen/status/MultiplayerStatusButton.kt index fb65e82634..b9351cc76d 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/status/MultiplayerStatusButton.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/status/MultiplayerStatusButton.kt @@ -1,6 +1,5 @@ package com.unciv.ui.screens.worldscreen.status -import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.ui.Button @@ -137,19 +136,12 @@ private class TurnIndicator : HorizontalGroup(), Disposable { val flash = AlternatingStateManager( name = "StatusButton color flash", - state = object { - val initialColor = Color.WHITE - val targetColor = Color.ORANGE - }, originalState = { state -> - Gdx.app.postRunnable { - image.color = state.initialColor - gameAmount.color = state.initialColor - } - }, alternateState = { state -> - Gdx.app.postRunnable { - image.color = state.targetColor - gameAmount.color = state.targetColor - } + originalState = { + image.color = Color.WHITE + gameAmount.color = Color.WHITE + }, alternateState = { + image.color = Color.ORANGE + gameAmount.color = Color.ORANGE } )