From 1ed88ce8535ebced0000eb5239bbcb4683a0602e Mon Sep 17 00:00:00 2001 From: xerus2000 <27jf@pm.me> Date: Fri, 29 Jan 2021 18:30:22 +0100 Subject: [PATCH] fix(ui): properly update playPauseSkipButton and keep in sync with StatusView --- .../kotlin/sc/gui/controller/GameController.kt | 4 ++++ src/main/kotlin/sc/gui/view/ControlView.kt | 15 ++++++++------- src/main/kotlin/sc/gui/view/StatusView.kt | 7 +++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/sc/gui/controller/GameController.kt b/src/main/kotlin/sc/gui/controller/GameController.kt index 9d33590c..2cb8e7bf 100644 --- a/src/main/kotlin/sc/gui/controller/GameController.kt +++ b/src/main/kotlin/sc/gui/controller/GameController.kt @@ -11,6 +11,7 @@ import sc.plugin2021.* import sc.plugin2021.util.GameRuleLogic import sc.shared.GameResult import tornadofx.Controller +import tornadofx.nonNullObjectBinding import tornadofx.objectProperty import java.util.* import kotlin.math.max @@ -148,6 +149,9 @@ class GameController : Controller() { val teamOneScore = objectProperty(0) val teamTwoScore = objectProperty(0) + val started = nonNullObjectBinding(currentTurn, isHumanTurn) { + value > 0 || isHumanTurn.value + } val playerNames = objectProperty>() val gameResult = objectProperty() diff --git a/src/main/kotlin/sc/gui/view/ControlView.kt b/src/main/kotlin/sc/gui/view/ControlView.kt index c21dd6d3..2c014be3 100644 --- a/src/main/kotlin/sc/gui/view/ControlView.kt +++ b/src/main/kotlin/sc/gui/view/ControlView.kt @@ -104,19 +104,20 @@ class ControlView : View() { gameController.clearGame() } else -> { - clientController.togglePause() updatePauseState(false) + clientController.togglePause() } } } // When the game is paused externally e.g. when rewinding - gameController.currentTurn.addListener { _, _, turn -> - updatePauseState(turn == 0) - } - gameController.gameResult.addListener { _, _, result -> - if (result != null) { - playPauseSkipButton.text = "Spiel beenden" + arrayOf(gameController.currentTurn, gameController.started, gameController.gameResult).forEach { + it.addListener { _, _, _ -> + if (gameController.gameEnded()) { + playPauseSkipButton.text = "Spiel beenden" + } else { + updatePauseState(!gameController.started.value) + } } } } diff --git a/src/main/kotlin/sc/gui/view/StatusView.kt b/src/main/kotlin/sc/gui/view/StatusView.kt index c130d82b..a0d6fa85 100644 --- a/src/main/kotlin/sc/gui/view/StatusView.kt +++ b/src/main/kotlin/sc/gui/view/StatusView.kt @@ -13,12 +13,11 @@ import tornadofx.* class StatusBinding(private val game: GameController) : StringBinding() { init { - bind(game.currentTurn) + bind(game.started) bind(game.currentTeam) - bind(game.isHumanTurn) bind(game.currentColor) - bind(game.gameResult) bind(game.playerNames) + bind(game.gameResult) } fun winner(gameResult: GameResult): String = gameResult.winners?.firstOrNull()?.let { player -> @@ -41,7 +40,7 @@ class StatusBinding(private val game: GameController) : StringBinding() { } override fun computeValue(): String { - if(game.currentTurn.get() <= 0) + if(!game.started.value) return "Drücke auf Start" return game.gameResult.get()?.let { gameResult -> """ Spiel ist beendet