diff --git a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/Area.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/Area.kt index 16d711c1a..5b4ba070e 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/Area.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/Area.kt @@ -58,10 +58,13 @@ open class Area( visual: Visual = Visual.EMPTY ) : GameComponentContainer( - posX = posX, posY = posY, width = width, height = height, visual = visual) { - /** Internal onRemove handler. */ - override fun T.onRemove() = Unit + posX = posX, posY = posY, width = width, height = height, visual = visual + ), + Iterable { - /** Internal onAdd handler. */ - override fun T.onAdd() = Unit + /** Internal onRemove handler. */ + override fun T.onRemove() = Unit + + /** Internal onAdd handler. */ + override fun T.onAdd() = Unit } diff --git a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/CardStack.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/CardStack.kt index 39983f58c..455d8e180 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/CardStack.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/CardStack.kt @@ -136,6 +136,8 @@ open class CardStack( removePosListeners() } + override fun iterator(): Iterator = observableComponents.reversed().iterator() + private fun T.addPosListeners() { posXProperty.setInternalListenerAndInvoke(0.0) { _, _ -> layoutX() } posYProperty.setInternalListenerAndInvoke(0.0) { _, _ -> layoutY() } diff --git a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/GameComponentContainer.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/GameComponentContainer.kt index 8bb89a67e..9d3b35049 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/GameComponentContainer.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/GameComponentContainer.kt @@ -54,7 +54,6 @@ sealed class GameComponentContainer( visual: Visual ) : DynamicComponentView(posX = posX, posY = posY, width = width, height = height, visual = visual), - Iterable, LayeredContainer { /** * An [ObservableList] to store the [GameComponentView]s that are contained in this @@ -292,7 +291,7 @@ sealed class GameComponentContainer( * * @return Iterator over the elements of this [GameComponentContainer]. */ - override fun iterator(): Iterator = observableComponents.iterator() + open fun iterator(): Iterator = observableComponents.iterator() /** * Puts the [component] to the front inside the [LayeredContainer] and Changes its [zIndex] diff --git a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/LinearLayout.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/LinearLayout.kt index 99500a869..8d6796d43 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/LinearLayout.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/LinearLayout.kt @@ -74,7 +74,8 @@ open class LinearLayout( ) : GameComponentContainer( posX = posX, posY = posY, width = width, height = height, visual = visual - ) { + ), + Iterable { /** * [Property] for the spacing of [GameComponentView]s in this [LinearLayout]. diff --git a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/Satchel.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/Satchel.kt index d8f6d8b10..30285d78d 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/Satchel.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/components/container/Satchel.kt @@ -72,7 +72,8 @@ open class Satchel( ) : GameComponentContainer( posX = posX, posY = posY, width = width, height = height, visual = visual - ) { + ), + Iterable { private val initialStates: HashMap = HashMap() 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 ddc54466c..0783bf9df 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 @@ -23,12 +23,12 @@ internal object Application : BoardGameApplication(aspectRatio = AspectRatio.of( init { loadFont("Rubik.ttf") - // showGameScene(cardLayoutScene) + showGameScene(cardLayoutScene) // 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/CardLayoutScene.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/CardLayoutScene.kt index 9d73305e9..f510c8694 100644 --- a/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/CardLayoutScene.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/main/view/CardLayoutScene.kt @@ -1,5 +1,6 @@ package tools.aqua.bgw.main.view +import tools.aqua.bgw.components.container.CardStack import tools.aqua.bgw.components.container.LinearLayout import tools.aqua.bgw.components.gamecomponentviews.CardView import tools.aqua.bgw.components.uicomponents.Button @@ -13,6 +14,30 @@ import kotlin.random.Random internal class CardLayoutScene : BoardGameScene() { + val cardStack = CardStack( + width = 300, + height = 200, + posX = 900, + posY = 100, + alignment = Alignment.CENTER, + visual = ColorVisual.LIGHT_GRAY + ).apply { + repeat(5) { i -> + val card = CardView( + posX = 0, + posY = 0, + width = i, + height = 200, + front = ColorVisual(Color(Random.nextInt(255), Random.nextInt(255), Random.nextInt(255))) + ) + println(card.width) + this.add(card) + } + + println(this.iterator().asSequence().map { it.width }.toList()) + println(this.peek().width) + } + val button = Button( width = 200, height = 200, @@ -68,7 +93,7 @@ internal class CardLayoutScene : BoardGameScene() { } init { - addComponents(layout, button) + addComponents(layout, button, cardStack) repeat(5) { val card = CardView( posX = 0,