From ddab82ec7f254e74e47aaf8b57c479327244b2aaff0ee3de777294432011a68f Mon Sep 17 00:00:00 2001 From: snap Date: Wed, 4 Mar 2026 12:18:56 +0000 Subject: [PATCH] Get if casual button is pressed and move play buttons into own horizontal group --- .../com/iofferyoutea/WitchQueen/MainMenu.kt | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/WitchQueen/core/src/main/kotlin/com/iofferyoutea/WitchQueen/MainMenu.kt b/WitchQueen/core/src/main/kotlin/com/iofferyoutea/WitchQueen/MainMenu.kt index c5ef271..2e8f436 100644 --- a/WitchQueen/core/src/main/kotlin/com/iofferyoutea/WitchQueen/MainMenu.kt +++ b/WitchQueen/core/src/main/kotlin/com/iofferyoutea/WitchQueen/MainMenu.kt @@ -2,7 +2,10 @@ package com.iofferyoutea.WitchQueen import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.BitmapFont +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.g3d.ModelCache import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle @@ -15,12 +18,16 @@ import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup import com.badlogic.gdx.scenes.scene2d.utils.ClickListener import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable import com.badlogic.gdx.utils.Logger +import com.badlogic.gdx.utils.Scaling import com.badlogic.gdx.utils.viewport.ScreenViewport +import com.badlogic.gdx.utils.viewport.StretchViewport import com.badlogic.gdx.utils.viewport.Viewport import ktx.actors.centerPosition import ktx.actors.setPosition +import ktx.actors.stage import ktx.app.KtxScreen import ktx.app.clearScreen +import javax.swing.text.View class MainMenu : KtxScreen { val myTable = Table().apply { @@ -28,7 +35,10 @@ class MainMenu : KtxScreen { setFillParent(true) } val myStage = Stage().apply { + Gdx.input.inputProcessor = this addActor(myTable) + // We need this to get the size of the table later + //myTable.setSize(viewport.screenWidth.toFloat(), viewport.screenHeight.toFloat()) } //region Map Button @@ -42,32 +52,28 @@ class MainMenu : KtxScreen { ) val mapButton = ImageButton(mapButtonStyle).apply { myTable.add(this) - myTable.getCell(this).padBottom(myStage.viewport.screenHeight * 0.05f) // Figure out how to centre + myTable.getCell(this) } //endregion + //endregion //region Player Buttons // Local Player // Remote Player val remotePlayerButton = PlayerButton().apply { myTable.row() myTable.add(this.playerGroup) - myTable.getCell(this.playerGroup).padBottom(myStage.viewport.screenHeight * 0.05f) // You've got to size the sub actors! + myTable.getCell(this.playerGroup) // You've got to size the sub actors! } - //endregion //region Play Buttons val casualButtonStyle = TextButton.TextButtonStyle( TextureRegionDrawable(Texture("default.png")), - TextureRegionDrawable(Texture("default.png")), + TextureRegionDrawable(Texture("default_flipped.png")), TextureRegionDrawable(Texture("default.png")), BitmapFont() ) - val casualButton = TextButton("Casual", casualButtonStyle).apply { - myTable.row() // Start with a new row - myTable.add(this) - myTable.getCell(this) - } + val casualButton = TextButton("Casual", casualButtonStyle) val competitiveButtonStyle = TextButton.TextButtonStyle( TextureRegionDrawable(Texture("default.png")), @@ -75,17 +81,31 @@ class MainMenu : KtxScreen { TextureRegionDrawable(Texture("default.png")), BitmapFont() ) - val competitiveButton = TextButton("Competitive", competitiveButtonStyle).apply { + val competitiveButton = TextButton("Competitive", competitiveButtonStyle) + + // We need to wrap the play buttons in a group so they only take up 1 column + val playButtonGroup = HorizontalGroup().apply { + addActor(casualButton) + addActor(competitiveButton) + myTable.row() myTable.add(this) - myTable.getCell(this).padLeft(myStage.viewport.screenWidth * 0.1f) + myTable.getCell(this) } //endregion + private fun update(delta: Float) { + if (casualButton.isPressed) { + Gdx.app.log("MainMenu", "Casual Button Pressed!") + } + } + override fun render(delta: Float) { clearScreen(0.3f, 0.3f, 0.3f) myStage.act(delta) myStage.draw() + + update(delta) } override fun dispose() {