Skip to content

Commit 7ef92fb

Browse files
committed
feat: DialogueScene is no longer limited to showing 5 choices and uses a scroll bar when needed to show more choices, related to #1322
1 parent b5e5c88 commit 7ef92fb

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

fxgl-gameplay/src/main/kotlin/com/almasb/fxgl/cutscene/dialogue/DialogueScene.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import com.almasb.fxgl.input.view.KeyView
2323
import com.almasb.fxgl.logging.Logger
2424
import com.almasb.fxgl.scene.SceneService
2525
import com.almasb.fxgl.scene.SubScene
26+
import com.almasb.fxgl.ui.FXGLScrollPane
2627
import javafx.beans.binding.Bindings
2728
import javafx.geometry.Point2D
2829
import javafx.scene.Group
30+
import javafx.scene.control.ScrollPane
2931
import javafx.scene.input.KeyCode
3032
import javafx.scene.layout.VBox
3133
import javafx.scene.paint.Color
@@ -35,6 +37,7 @@ import javafx.scene.text.Text
3537
import javafx.util.Duration
3638
import java.util.*
3739

40+
3841
/**
3942
*
4043
* @author Almas Baimagambetov ([email protected])
@@ -91,8 +94,27 @@ class DialogueScene(private val sceneService: SceneService) : SubScene() {
9194
topText.translateX = 50.0
9295
topText.translateY = 40.0
9396

94-
boxPlayerLines.translateX = 50.0
95-
boxPlayerLines.translateYProperty().bind(sceneService.prefHeightProperty().subtract(160))
97+
val playerLinesScroll = FXGLScrollPane(boxPlayerLines)
98+
playerLinesScroll.hbarPolicy = ScrollPane.ScrollBarPolicy.NEVER
99+
playerLinesScroll.vbarPolicy = ScrollPane.ScrollBarPolicy.NEVER
100+
playerLinesScroll.prefHeight = botLine.height - 60
101+
playerLinesScroll.translateX = 50.0
102+
playerLinesScroll.translateYProperty().bind(sceneService.prefHeightProperty().subtract(160))
103+
playerLinesScroll.opacityProperty().bind(boxPlayerLines.opacityProperty())
104+
105+
// these dummy objects help us place the scroll bar for [playerLinesScroll] on the left side
106+
val dummyBox = VBox(5.0)
107+
dummyBox.prefHeightProperty().bind(boxPlayerLines.heightProperty())
108+
109+
val dummyScroll = FXGLScrollPane(dummyBox)
110+
dummyScroll.translateX = 0.0
111+
dummyScroll.translateY = playerLinesScroll.translateY
112+
dummyScroll.hbarPolicy = ScrollPane.ScrollBarPolicy.NEVER
113+
dummyScroll.prefHeightProperty().bind(playerLinesScroll.prefHeightProperty())
114+
dummyScroll.vmaxProperty().bind(playerLinesScroll.vmaxProperty())
115+
dummyScroll.vminProperty().bind(playerLinesScroll.vminProperty())
116+
dummyScroll.vvalueProperty().bindBidirectional(playerLinesScroll.vvalueProperty())
117+
96118
boxPlayerLines.opacity = 0.0
97119

98120
val keyView = KeyView(KeyCode.ENTER, Color.GREENYELLOW, 18.0)
@@ -104,7 +126,7 @@ class DialogueScene(private val sceneService: SceneService) : SubScene() {
104126

105127
initUserActions()
106128

107-
contentRoot.children.addAll(topLine, botLineGroup, topText, boxPlayerLines, keyView)
129+
contentRoot.children.addAll(topLine, botLineGroup, topText, dummyScroll, playerLinesScroll, keyView)
108130
}
109131

110132
private fun initUserActions() {

0 commit comments

Comments
 (0)