Get if casual button is pressed and move play buttons into own horizontal group
This commit is contained in:
@@ -2,7 +2,10 @@ package com.iofferyoutea.WitchQueen
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Texture
|
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.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.InputEvent
|
||||||
import com.badlogic.gdx.scenes.scene2d.Stage
|
import com.badlogic.gdx.scenes.scene2d.Stage
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle
|
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.ClickListener
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||||
import com.badlogic.gdx.utils.Logger
|
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.ScreenViewport
|
||||||
|
import com.badlogic.gdx.utils.viewport.StretchViewport
|
||||||
import com.badlogic.gdx.utils.viewport.Viewport
|
import com.badlogic.gdx.utils.viewport.Viewport
|
||||||
import ktx.actors.centerPosition
|
import ktx.actors.centerPosition
|
||||||
import ktx.actors.setPosition
|
import ktx.actors.setPosition
|
||||||
|
import ktx.actors.stage
|
||||||
import ktx.app.KtxScreen
|
import ktx.app.KtxScreen
|
||||||
import ktx.app.clearScreen
|
import ktx.app.clearScreen
|
||||||
|
import javax.swing.text.View
|
||||||
|
|
||||||
class MainMenu : KtxScreen {
|
class MainMenu : KtxScreen {
|
||||||
val myTable = Table().apply {
|
val myTable = Table().apply {
|
||||||
@@ -28,7 +35,10 @@ class MainMenu : KtxScreen {
|
|||||||
setFillParent(true)
|
setFillParent(true)
|
||||||
}
|
}
|
||||||
val myStage = Stage().apply {
|
val myStage = Stage().apply {
|
||||||
|
Gdx.input.inputProcessor = this
|
||||||
addActor(myTable)
|
addActor(myTable)
|
||||||
|
// We need this to get the size of the table later
|
||||||
|
//myTable.setSize(viewport.screenWidth.toFloat(), viewport.screenHeight.toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
//region Map Button
|
//region Map Button
|
||||||
@@ -42,32 +52,28 @@ class MainMenu : KtxScreen {
|
|||||||
)
|
)
|
||||||
val mapButton = ImageButton(mapButtonStyle).apply {
|
val mapButton = ImageButton(mapButtonStyle).apply {
|
||||||
myTable.add(this)
|
myTable.add(this)
|
||||||
myTable.getCell<ImageButton>(this).padBottom(myStage.viewport.screenHeight * 0.05f) // Figure out how to centre
|
myTable.getCell<ImageButton>(this)
|
||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
//endregion
|
||||||
//region Player Buttons
|
//region Player Buttons
|
||||||
// Local Player
|
// Local Player
|
||||||
// Remote Player
|
// Remote Player
|
||||||
val remotePlayerButton = PlayerButton().apply {
|
val remotePlayerButton = PlayerButton().apply {
|
||||||
myTable.row()
|
myTable.row()
|
||||||
myTable.add(this.playerGroup)
|
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
|
//region Play Buttons
|
||||||
val casualButtonStyle = TextButton.TextButtonStyle(
|
val casualButtonStyle = TextButton.TextButtonStyle(
|
||||||
TextureRegionDrawable(Texture("default.png")),
|
TextureRegionDrawable(Texture("default.png")),
|
||||||
TextureRegionDrawable(Texture("default.png")),
|
TextureRegionDrawable(Texture("default_flipped.png")),
|
||||||
TextureRegionDrawable(Texture("default.png")),
|
TextureRegionDrawable(Texture("default.png")),
|
||||||
BitmapFont()
|
BitmapFont()
|
||||||
)
|
)
|
||||||
val casualButton = TextButton("Casual", casualButtonStyle).apply {
|
val casualButton = TextButton("Casual", casualButtonStyle)
|
||||||
myTable.row() // Start with a new row
|
|
||||||
myTable.add(this)
|
|
||||||
myTable.getCell<TextButton>(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
val competitiveButtonStyle = TextButton.TextButtonStyle(
|
val competitiveButtonStyle = TextButton.TextButtonStyle(
|
||||||
TextureRegionDrawable(Texture("default.png")),
|
TextureRegionDrawable(Texture("default.png")),
|
||||||
@@ -75,17 +81,31 @@ class MainMenu : KtxScreen {
|
|||||||
TextureRegionDrawable(Texture("default.png")),
|
TextureRegionDrawable(Texture("default.png")),
|
||||||
BitmapFont()
|
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.add(this)
|
||||||
myTable.getCell<TextButton>(this).padLeft(myStage.viewport.screenWidth * 0.1f)
|
myTable.getCell<HorizontalGroup>(this)
|
||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
private fun update(delta: Float) {
|
||||||
|
if (casualButton.isPressed) {
|
||||||
|
Gdx.app.log("MainMenu", "Casual Button Pressed!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
clearScreen(0.3f, 0.3f, 0.3f)
|
clearScreen(0.3f, 0.3f, 0.3f)
|
||||||
|
|
||||||
myStage.act(delta)
|
myStage.act(delta)
|
||||||
myStage.draw()
|
myStage.draw()
|
||||||
|
|
||||||
|
update(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
|
|||||||
Reference in New Issue
Block a user