Continue experimenting with buttons to create a main menu
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.iofferyoutea.WitchQueen
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||
import ktx.assets.toInternalFile
|
||||
|
||||
open class Button(val upTexturePath: String, val downTexturePath: String, val fontPath: String, val defaultText: String = "New Button", val useDefaultFont: Boolean = true, val fontScale: Float = 1f) {
|
||||
val buttonText = defaultText
|
||||
val buttonUp = TextureRegionDrawable(Texture(upTexturePath))
|
||||
val buttonDown = TextureRegionDrawable(Texture(downTexturePath))
|
||||
val buttonFont = (if (useDefaultFont) BitmapFont() else BitmapFont(fontPath.toInternalFile())).apply { data.scale(fontScale) }
|
||||
|
||||
val buttonStyle = TextButtonStyle().apply { up = buttonUp; down = buttonDown; font = buttonFont }
|
||||
|
||||
val button = TextButton(defaultText, buttonStyle)
|
||||
}
|
||||
@@ -2,17 +2,15 @@ package com.iofferyoutea.WitchQueen
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||
import ktx.app.KtxScreen
|
||||
import ktx.app.clearScreen
|
||||
import ktx.assets.toInternalFile
|
||||
import com.badlogic.gdx.graphics.Texture.TextureFilter.Nearest
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
||||
|
||||
class MainMenu : KtxScreen {
|
||||
val table = Table().apply {
|
||||
@@ -24,16 +22,62 @@ class MainMenu : KtxScreen {
|
||||
addActor(table)
|
||||
}
|
||||
|
||||
val mySkin = Skin("uiskin.json".toInternalFile())
|
||||
// Map Selection Button
|
||||
|
||||
val textureRegion = TextureRegion(Texture("default.png").apply { setFilter(Nearest,
|
||||
Nearest
|
||||
)} )
|
||||
val buttonFont = BitmapFont("default.fnt".toInternalFile())
|
||||
val style = TextButton.TextButtonStyle().apply { up = TextureRegionDrawable(textureRegion); font = buttonFont }
|
||||
// Player Table
|
||||
// val inviteButton = Button(
|
||||
// "default.png",
|
||||
// "default_flipped.png",
|
||||
// "",
|
||||
// "Invite Player",
|
||||
// true,
|
||||
// 2f
|
||||
// ).apply {
|
||||
// table.add(this.button).size(1024f, 512f)
|
||||
// table.row()
|
||||
// }
|
||||
|
||||
val button = TextButton("Button", style).apply {
|
||||
table.add(this).size(512f, 512f)
|
||||
// Invite Player Button
|
||||
val playerPlaceholderButtonUp = TextureRegionDrawable(Texture("player-frame-up.png"))
|
||||
val playerPlaceholderButtonDown = TextureRegionDrawable(Texture("player-frame-down.png"))
|
||||
val playerPlaceholderButtonChecked = TextureRegionDrawable(Texture("player-frame-up.png"))
|
||||
val playerPlaceholderButtonStyle = ImageButton.ImageButtonStyle()
|
||||
.apply { up = playerPlaceholderButtonUp; down = playerPlaceholderButtonDown; checked = playerPlaceholderButtonChecked }
|
||||
val playerPlaceholderButton = ImageButton(playerPlaceholderButtonStyle)
|
||||
|
||||
val player1TableButton = PlayerTableButton() // These should only be collections no t buttons?
|
||||
val player2TableButton = PlayerTableButton() // Since the collection contains the buttons we need anyway?
|
||||
val playerTableButtonCollection = VerticalGroup().apply {
|
||||
addActor(player1TableButton.button)
|
||||
addActor(playerPlaceholderButton)
|
||||
table.add(this)
|
||||
table.row()
|
||||
}
|
||||
|
||||
// Casual Button
|
||||
val casualButton = Button(
|
||||
"default.png",
|
||||
"default_flipped.png",
|
||||
"",
|
||||
"Casual",
|
||||
true,
|
||||
2f
|
||||
)
|
||||
|
||||
// Competitive Button
|
||||
val competitiveButton = Button(
|
||||
"default.png",
|
||||
"default_flipped.png",
|
||||
"",
|
||||
"Competitive",
|
||||
true,
|
||||
2f
|
||||
)
|
||||
|
||||
val playButtonGroup = HorizontalGroup().apply {
|
||||
addActor(casualButton.button)
|
||||
addActor(competitiveButton.button)
|
||||
table.add(this)
|
||||
}
|
||||
|
||||
override fun render(delta: Float) {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.iofferyoutea.WitchQueen
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||
import ktx.assets.toInternalFile
|
||||
|
||||
class PlayerTableButton(val playerIconPath: String = "default.png", val newPlayerName: String = "PLAYER"):
|
||||
Table() {
|
||||
val playerIcon = Image(Texture(playerIconPath))
|
||||
val playerNameStyle = Label.LabelStyle(BitmapFont("default.fnt".toInternalFile()), Color.WHITE)
|
||||
val playerName = Label(newPlayerName, playerNameStyle)
|
||||
// Change preparedItems and kickButton into actual buttons
|
||||
var preparedItems: MutableList<Image> = mutableListOf( // We should use libGDX scene2d.ui List?
|
||||
Image(Texture("prepared-item-frame.png")),
|
||||
Image(Texture("prepared-item-frame.png")),
|
||||
Image(Texture("prepared-item-frame.png")),
|
||||
Image(Texture("prepared-item-frame.png"))
|
||||
)
|
||||
val preparedItemsGroup = HorizontalGroup().apply {
|
||||
for (item in preparedItems) addActor(item)
|
||||
}
|
||||
val kickButton = Image(Texture("red-x.png"))
|
||||
|
||||
// Sub-table for Player/Items stack - Use VerticalGroup instead
|
||||
// val playerPlusItemsStack = Table().apply {
|
||||
// add(playerName)
|
||||
// row()
|
||||
// for (item in preparedItems) add(item)
|
||||
// }
|
||||
val playerLabelPlusItemsGroup = VerticalGroup().apply {
|
||||
addActor(playerName)
|
||||
addActor(preparedItemsGroup)
|
||||
}
|
||||
|
||||
// Sub-table for the contents of the PlayerTableButton - Use HorizontalGroup instead
|
||||
// val subTable = Table().apply {
|
||||
// add(playerName, playerPlusItemsStack, kickButton)
|
||||
// }
|
||||
val componentCollection = HorizontalGroup().apply {
|
||||
addActor(playerIcon)
|
||||
addActor(playerLabelPlusItemsGroup)
|
||||
addActor(kickButton)
|
||||
}
|
||||
|
||||
// Base Button stuff
|
||||
val buttonUp = TextureRegionDrawable(Texture("transparent.png"))
|
||||
val buttonDown = TextureRegionDrawable(Texture("transparent.png"))
|
||||
val buttonChecked = TextureRegionDrawable(Texture("transparent.png"))
|
||||
|
||||
val buttonStyle = ButtonStyle().apply { up = buttonUp; down = buttonDown; checked = buttonChecked }
|
||||
|
||||
val button = Button(componentCollection, buttonStyle)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.iofferyoutea.WitchQueen
|
||||
|
||||
class PlayerTablePlaceholderButton {
|
||||
}
|
||||
Reference in New Issue
Block a user