Skip to content

Commit

Permalink
fix(ui): properly update playPauseSkipButton and keep in sync with St…
Browse files Browse the repository at this point in the history
…atusView
  • Loading branch information
xeruf committed Jan 29, 2021
1 parent 1e76551 commit 1ed88ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/sc/gui/controller/GameController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Array<String>>()
val gameResult = objectProperty<GameResult>()

Expand Down
15 changes: 8 additions & 7 deletions src/main/kotlin/sc/gui/view/ControlView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/sc/gui/view/StatusView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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
Expand Down

0 comments on commit 1ed88ce

Please sign in to comment.