Re-create main menu buttons

This commit is contained in:
2026-03-04 07:49:40 +00:00
parent bdcbfece3b
commit 7974cbd0af
9 changed files with 1765 additions and 99 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
package com.iofferyoutea.WitchQueen
import ktx.app.KtxScreen
import ktx.app.clearScreen
class GameScreen(val players: List<Player>, val map: Map) : KtxScreen {
override fun render(delta: Float) {
super.render(delta)
clearScreen(0.15f, 0.15f, 0.3f)
}
}

View File

@@ -1,5 +1,6 @@
package com.iofferyoutea.WitchQueen
import com.badlogic.gdx.Game
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.Texture.TextureFilter.Linear
import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -10,8 +11,12 @@ import ktx.assets.disposeSafely
import ktx.assets.toInternalFile
import ktx.async.KtxAsync
import ktx.graphics.use
import java.lang.ref.WeakReference
class Main : KtxGame<KtxScreen>() {
//val mainMenu = MainMenu()
//val screenManager = ScreenManager.apply { switchScreen(mainMenu) }
override fun create() {
KtxAsync.initiate()

View File

@@ -2,12 +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.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle
import com.badlogic.gdx.scenes.scene2d.ui.Container
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.ClickListener
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
@@ -20,119 +23,201 @@ import ktx.app.KtxScreen
import ktx.app.clearScreen
class MainMenu : KtxScreen {
val viewport = ScreenViewport().apply {
}
val table = Table().apply {
setFillParent(true)
val myTable = Table().apply {
debug = true
setFillParent(true)
}
val stage = Stage(viewport).apply {
Gdx.app.log("WitchQueen", "Width: " + viewport.screenWidth.toString() + " Height: " + viewport.screenHeight.toString())
Gdx.input.inputProcessor = this
addActor(table)
val myStage = Stage().apply {
addActor(myTable)
}
// Map Selection Button
//region Map Button
val mapButtonStyle = ImageButton.ImageButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png"))
)
val mapButton = ImageButton(mapButtonStyle).apply {
myTable.add(this)
myTable.getCell<ImageButton>(this).padBottom(myStage.viewport.screenHeight * 0.05f) // Figure out how to centre
}
//endregion
// Player Table
// val inviteButton = Button(
// "default.png",
// "default_flipped.png",
// "",
// "Invite Player",
// true,
// 2f
// ).apply {
// table.add(this.button).size(1024f, 512f)
// table.row()
// }
//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!
}
//endregion
// 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()
//region Play Buttons
val casualButtonStyle = TextButton.TextButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.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)
}
// Casual Button
val casualButton = Button(
"default.png",
"default_flipped.png",
"",
"Casual",
true,
2f
).apply { // Could probably do this in Button. Just take in width and aspect ratio and padding?
container.width(viewport.screenWidth * 0.375f)
container.height(((viewport.screenWidth * 0.375f) * 3f) / 4) // container.width is 0. We need to work out the width again.
container.padLeft(viewport.screenWidth * 0.1f)
}
// Competitive Button
val competitiveButton = Button(
"default.png",
"default_flipped.png",
"",
"Competitive",
true,
2f
).apply {
container.width(viewport.screenWidth * 0.375f)
container.height(((viewport.screenWidth * 0.375f) * 3f) / 4) // container.width is 0. We need to work out the width again.
container.padLeft(viewport.screenWidth * 0.05f)
}
val playButtonGroup = HorizontalGroup().apply {
addActor(casualButton.container)
addActor(competitiveButton.container)
table.add(this).width(viewport.screenWidth.toFloat())
}
// Methods
private fun processInput() {
casualButton.button.addListener(object : ClickListener() {
override fun touchUp(
event: InputEvent?,
x: Float,
y: Float,
pointer: Int,
button: Int
) {
Gdx.app.log("My Project", "Clicked!")
}
})
}
override fun resize(width: Int, height: Int) {
super.resize(width, height)
stage.viewport.update(width, height, true)
val competitiveButtonStyle = TextButton.TextButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
BitmapFont()
)
val competitiveButton = TextButton("Competitive", competitiveButtonStyle).apply {
myTable.add(this)
myTable.getCell<TextButton>(this).padLeft(myStage.viewport.screenWidth * 0.1f)
}
//endregion
override fun render(delta: Float) {
super.render(delta)
clearScreen(0f, 255f, 0f)
clearScreen(0.3f, 0.3f, 0.3f)
processInput()
stage.act(delta)
stage.draw()
myStage.act(delta)
myStage.draw()
}
override fun dispose() {
stage.dispose()
myStage.dispose()
}
}
//class MainMenu : KtxScreen {
// val viewport = ScreenViewport().apply {
//
// }
//
// val table = Table().apply {
// setFillParent(true)
// debug = true
// }
// val stage = Stage(viewport).apply {
// Gdx.app.log("WitchQueen", "Width: " + viewport.screenWidth.toString() + " Height: " + viewport.screenHeight.toString())
//
// Gdx.input.inputProcessor = this
// addActor(table)
// }
//
// // Map Selection Button
//
// // Player Table
//// val inviteButton = Button(
//// "default.png",
//// "default_flipped.png",
//// "",
//// "Invite Player",
//// true,
//// 2f
//// ).apply {
//// table.add(this.button).size(1024f, 512f)
//// table.row()
//// }
//
// // 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 playerPlaceholderContainer = Container<ImageButton>(playerPlaceholderButton).apply {
// width(viewport.screenWidth * 0.8f)
// height(((viewport.screenWidth * 0.8f) * 9f) / 32f) // container.width is 0. We need to work out the width again.
// padLeft(0f)
// }
//
// val player1TableButton = PlayerTableButton().apply { // These should only be collections no t buttons?
// container.width(viewport.screenWidth * 0.8f)
// container.height(500f)
// //container.height(((viewport.screenWidth * 0.8f) * 9f) / 32f) // container.width is 0. We need to work out the width again.
// container.padLeft(0f)
// }
// val player2TableButton = PlayerTableButton() // Since the collection contains the buttons we need anyway?
// val playerTableButtonCollection = VerticalGroup().apply {
// addActor(player1TableButton.container)
// addActor(playerPlaceholderContainer)
// table.add(this)
// table.row()
// }
//
// // Casual Button
// val casualButton = Button(
// "default.png",
// "default_flipped.png",
// "",
// "Casual",
// true,
// 2f
// ).apply { // Could probably do this in Button. Just take in width and aspect ratio and padding?
// container.width(viewport.screenWidth * 0.375f)
// container.height(((viewport.screenWidth * 0.375f) * 3f) / 4) // container.width is 0. We need to work out the width again.
// container.padLeft(viewport.screenWidth * 0.1f)
// }
//
// // Competitive Button
// val competitiveButton = Button(
// "default.png",
// "default_flipped.png",
// "",
// "Competitive",
// true,
// 2f
// ).apply {
// container.width(viewport.screenWidth * 0.375f)
// container.height(((viewport.screenWidth * 0.375f) * 3f) / 4) // container.width is 0. We need to work out the width again.
// container.padLeft(viewport.screenWidth * 0.05f)
// }
//
// val playButtonGroup = HorizontalGroup().apply {
// addActor(casualButton.container)
// addActor(competitiveButton.container)
//
// table.add(this).width(viewport.screenWidth.toFloat())
// }
//
// // Methods
// private fun processInput() {
// casualButton.button.addListener(object : ClickListener() {
// override fun touchUp(
// event: InputEvent?,
// x: Float,
// y: Float,
// pointer: Int,
// button: Int
// ) {
// Gdx.app.log("My Project", "Clicked!")
// //setScreen()
// }
// })
// }
//
// override fun resize(width: Int, height: Int) {
// super.resize(width, height)
// stage.viewport.update(width, height, true)
// }
//
// override fun render(delta: Float) {
// super.render(delta)
// clearScreen(0f, 255f, 0f)
//
// processInput()
//
// stage.act(delta)
// stage.draw()
// }
//
// override fun dispose() {
// stage.dispose()
// }
//}

View File

@@ -0,0 +1,4 @@
package com.iofferyoutea.WitchQueen
class Map {
}

View File

@@ -0,0 +1,5 @@
package com.iofferyoutea.WitchQueen
class Player {
val name = String()
}

View File

@@ -0,0 +1,109 @@
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.Container
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
class PlayerButton {
enum class STATE { EMPTY, CONNECTING, FILLED }
// Player Profile
val profileButtonStyle = ImageButton.ImageButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png"))
)
val profileButton = ImageButton(profileButtonStyle)
// Player Username
val usernameStyle = Label.LabelStyle(BitmapFont(), Color.BLACK)
val username = Label("default", usernameStyle)
//region Player Items
val item1ButtonStyle = ImageButton.ImageButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png"))
)
val item1Button = ImageButton(item1ButtonStyle)
val item2ButtonStyle = ImageButton.ImageButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png"))
)
val item2Button = ImageButton(item2ButtonStyle)
val item3ButtonStyle = ImageButton.ImageButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png"))
)
val item3Button = ImageButton(item3ButtonStyle)
val item4ButtonStyle = ImageButton.ImageButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png"))
)
val item4Button = ImageButton(item4ButtonStyle)
//endregion
// Leave Lobby - Only shows for local player on local player's button
val leaveButtonStyle = ImageButton.ImageButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png"))
)
val leaveButton = ImageButton(leaveButtonStyle)
// Kick Player - Only shows for local player on remote player's button
val kickButtonStyle = ImageButton.ImageButtonStyle(
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png")),
TextureRegionDrawable(Texture("default.png"))
)
val kickButton = ImageButton(kickButtonStyle)
val itemGroup = HorizontalGroup().apply {
addActor(item1Button)
addActor(item2Button)
addActor(item3Button)
addActor(item4Button)
}
val nameAndItemGroup = VerticalGroup().apply {
addActor(username)
addActor(itemGroup)
}
val playerGroup = HorizontalGroup().apply {
addActor(profileButton)
addActor(nameAndItemGroup)
addActor(kickButton)
}
}

View File

@@ -5,6 +5,7 @@ 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.Container
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Label
@@ -59,4 +60,6 @@ class PlayerTableButton(val playerIconPath: String = "default.png", val newPlaye
val buttonStyle = ButtonStyle().apply { up = buttonUp; down = buttonDown; checked = buttonChecked }
val button = Button(componentCollection, buttonStyle)
val container = Container<HorizontalGroup>(componentCollection)
}

View File

@@ -0,0 +1,22 @@
package com.iofferyoutea.WitchQueen
import com.badlogic.gdx.Gdx
import kotlinx.coroutines.*
import ktx.app.KtxScreen
import java.lang.ref.WeakReference
object ScreenManager {
var currentScreen: WeakReference<KtxScreen>? = null
val screens: MutableSet<WeakReference<KtxScreen>> = mutableSetOf<WeakReference<KtxScreen>>() // Does this need to be mutable?
fun switchScreen(newScreen: WeakReference<KtxScreen>): Boolean {
if (!screens.contains(newScreen)) {
Gdx.app.log("ScreenManager", "newScreen not found in screens. Adding...")
screens.add(newScreen)
}
currentScreen = screens.find { it == newScreen }
return currentScreen != null
}
}