From 4177fef15bd9dfd606341bb4747e1e47e7caf9d5 Mon Sep 17 00:00:00 2001 From: Luca Raddatz Date: Sat, 30 Nov 2024 23:24:41 +0100 Subject: [PATCH] Added fix for pane not expanding --- .../bgw/components/container/HexagonGrid.kt | 29 +++++++++-- .../tools/aqua/bgw/main/view/Application.kt | 6 +-- .../aqua/bgw/main/view/HexGridGameScene.kt | 50 ++++++++++++++++--- 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/HexagonGrid.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/HexagonGrid.kt index b048c9d81..2b31b1fde 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/HexagonGrid.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/HexagonGrid.kt @@ -91,6 +91,12 @@ class HexagonGrid( * @param coordinateSystem The coordinate system to use for the layout. */ private fun layout(coordinateSystem: CoordinateSystem) { + var minX = Double.MAX_VALUE + var minY = Double.MAX_VALUE + + var maxX = Double.MIN_VALUE + var maxY = Double.MIN_VALUE + map.forEach { (coords, hexagon) -> val (x, y) = coords val (q, r) = @@ -106,17 +112,32 @@ class HexagonGrid( with(hexagon) { if (orientation == HexOrientation.POINTY_TOP) { hexagon.orientation = HexOrientation.POINTY_TOP - val actualWidth = width / 2 * sqrt(3.0) - posXProperty.setSilent(actualWidth * q + if (r % 2 == 0) 0.0 else actualWidth / 2) + val hexWidth = width / 2 * sqrt(3.0) + posXProperty.setSilent(hexWidth * q + if (r % 2 == 0) 0.0 else hexWidth / 2) posYProperty.setSilent(height * r - r * height / 4) + + if (posXProperty.value < minX) minX = posXProperty.value + if (posYProperty.value < minY) minY = posYProperty.value + + if (posXProperty.value + hexWidth > maxX) maxX = posXProperty.value + hexWidth + if (posYProperty.value + height > maxY) maxY = posYProperty.value + height } else { hexagon.orientation = HexOrientation.FLAT_TOP - val actualHeight = height / 2 * sqrt(3.0) - posYProperty.setSilent(actualHeight * q + if (r % 2 == 0) 0.0 else actualHeight / 2) + val hexHeight = height / 2 * sqrt(3.0) + posYProperty.setSilent(hexHeight * q + if (r % 2 == 0) 0.0 else hexHeight / 2) posXProperty.setSilent(width * r - r * width / 4) + + if (posXProperty.value < minX) minX = posXProperty.value + if (posYProperty.value < minY) minY = posYProperty.value + + if (posXProperty.value + width > maxX) maxX = posXProperty.value + width + if (posYProperty.value + hexHeight > maxY) maxY = posYProperty.value + hexHeight } } } + + widthProperty.setSilent(maxX - minX) + heightProperty.setSilent(maxY - minY) } override fun T.onRemove() {} diff --git a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/Application.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/Application.kt index 87916ef4b..b50a9176c 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/Application.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/Application.kt @@ -22,14 +22,12 @@ internal object Application : BoardGameApplication() { init { loadFont("Rubik.ttf") - loadFont("Staatliches-Regular.ttf", "Staatliches", Font.FontWeight.NORMAL) - loadFont("JetBrainsMono-ExtraBold.ttf", "JetBrainsMono", Font.FontWeight.EXTRA_BOLD) // showGameScene(cardLayoutScene) - // showGameScene(hexGrid) + showGameScene(hexGrid) // showGameScene(animation) // showGameScene(grid) // showGameScene(dragDropScene) - showMenuScene(uiScene) + // showMenuScene(uiScene) // showGameScene(visualScene) } } \ No newline at end of file diff --git a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/HexGridGameScene.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/HexGridGameScene.kt index 9c08e0639..9d46e941f 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/HexGridGameScene.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/HexGridGameScene.kt @@ -5,6 +5,8 @@ import tools.aqua.bgw.components.container.HexagonGrid import tools.aqua.bgw.components.container.Satchel import tools.aqua.bgw.components.gamecomponentviews.HexagonView import tools.aqua.bgw.components.gamecomponentviews.TokenView +import tools.aqua.bgw.components.layoutviews.CameraPane +import tools.aqua.bgw.components.layoutviews.Pane import tools.aqua.bgw.core.BoardGameScene import tools.aqua.bgw.core.Color import tools.aqua.bgw.core.HexOrientation @@ -19,10 +21,32 @@ internal class HexGridGameScene : BoardGameScene() { height = 500, posX = 0, posY = 0, - coordinateSystem = HexagonGrid.CoordinateSystem.AXIAL, + coordinateSystem = HexagonGrid.CoordinateSystem.OFFSET, visual = Visual.EMPTY, - orientation = HexOrientation.FLAT_TOP - ) + orientation = HexOrientation.POINTY_TOP + ).apply { + onMouseClicked = { + placeOnHexGrid(HexagonView(visual = ColorVisual(Color(0, 0, 255)), size = 40)) + } + } + + private val targetPane = Pane>( + width = 900, + height = 900, + posX = 0, + posY = 0, + visual = ColorVisual.RED + ).apply { + add(hexGrid) + } + + private val cameraPane = CameraPane( + width = 1920, + height = 1080, + target = targetPane, + ).apply { + interactive = true + } private val satchel = Satchel( posX = 800, @@ -43,10 +67,9 @@ internal class HexGridGameScene : BoardGameScene() { private val hexFlat = HexagonView(posX = 900, posY = 200, visual = ColorVisual(Color(0, 255, 0)), size = 50, orientation = HexOrientation.FLAT_TOP) fun placeOnHexGrid(hexagon: HexagonView) { - satchel.remove(hexagon) - hexGrid[Random.nextInt(-5, 5), Random.nextInt(-5, 5)] = hexagon.apply { - isDraggable = true - } + hexGrid[10,0] = HexagonView(visual = ColorVisual(Color(255, 0, 0)), size = 50, orientation = HexOrientation.POINTY_TOP) + targetPane.width = hexGrid.width + targetPane.height = hexGrid.height } fun placeInSatchel(hexagon: HexagonView) { @@ -82,12 +105,23 @@ internal class HexGridGameScene : BoardGameScene() { onDragGestureExited = { visual = ColorVisual.LIGHT_GRAY } + + onMouseEntered = { + visual = ColorVisual.GRAY + } + + onMouseExited = { + visual = ColorVisual.LIGHT_GRAY + } } hexGrid[q,r] = hexagon hexMap[Pair(q,r)] = hexagon } } } + + targetPane.width = hexGrid.width + targetPane.height = hexGrid.height } fun refreshHexGrid() { @@ -97,7 +131,7 @@ internal class HexGridGameScene : BoardGameScene() { init { buildHexGrid() - addComponents(hexGrid, satchel) + addComponents(cameraPane, satchel) repeat(20) { val hexagon = HexagonView(posX = 800, posY = 800, visual = ImageVisual("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSwc4YbxNBYXWRkgqzh9tbaSQh2Uy-f4e1Nl0teHHWFisub3gxv4rxn1eFjgVUUMASaNSg&usqp=CAU"), size = 40, orientation = HexOrientation.FLAT_TOP).apply { isDraggable = true