Skip to content

Commit ae72215

Browse files
committed
fix(ui): update pause button when pause state changes externally
1 parent 76125f2 commit ae72215

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/main/kotlin/sc/gui/view/ControlView.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package sc.gui.view
22

3+
import javafx.beans.InvalidationListener
34
import javafx.beans.binding.Bindings
45
import javafx.geometry.Insets
56
import javafx.geometry.Pos
@@ -82,6 +83,13 @@ class ControlView() : View() {
8283
}
8384

8485
init {
86+
val updatePauseState = {
87+
if(clientController.controllingClient?.game?.isPaused!!) {
88+
playPauseButton.text = "Play"
89+
} else {
90+
playPauseButton.text = "Pause"
91+
}
92+
}
8593
playPauseButton.setOnMouseClicked {
8694
if (!gameController.gameStartedProperty().get()) {
8795
gameController.gameStartedProperty().set(true)
@@ -90,15 +98,15 @@ class ControlView() : View() {
9098
appController.changeViewTo(StartView::class)
9199
gameController.clearGame()
92100
} else {
93-
if (clientController.controllingClient?.game?.isPaused!!) {
94-
playPauseButton.text = "Pause"
95-
} else {
96-
playPauseButton.text = "Play"
97-
}
98101
clientController.togglePause()
102+
updatePauseState()
99103
}
100104
}
101-
105+
106+
gameController.currentTurnProperty().addListener(InvalidationListener {
107+
// When the game is paused externally e.g. when rewinding
108+
updatePauseState()
109+
})
102110
gameController.gameStartedProperty().addListener { _, _, started ->
103111
if (!started) {
104112
playPauseButton.text = "Start"

0 commit comments

Comments
 (0)