Get if casual button is pressed and move play buttons into own horizontal group

This commit is contained in:
2026-03-04 12:18:56 +00:00
parent 7974cbd0af
commit ddab82ec7f

View File

@@ -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<ImageButton>(this).padBottom(myStage.viewport.screenHeight * 0.05f) // Figure out how to centre
myTable.getCell<ImageButton>(this)
}
//endregion
//endregion
//region Player Buttons
// Local Player
// Remote Player
val remotePlayerButton = PlayerButton().apply {
myTable.row()
myTable.add(this.playerGroup)
myTable.getCell<HorizontalGroup>(this.playerGroup).padBottom(myStage.viewport.screenHeight * 0.05f) // You've got to size the sub actors!
myTable.getCell<HorizontalGroup>(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<TextButton>(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<TextButton>(this).padLeft(myStage.viewport.screenWidth * 0.1f)
myTable.getCell<HorizontalGroup>(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() {