You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gamejam-22/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt

114 lines
3.0 KiB
Kotlin

package com.last.commit.screen
import com.badlogic.gdx.Gdx
2 years ago
import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.math.MathUtils
2 years ago
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.viewport.ScreenViewport
import com.last.commit.ColorState
import com.last.commit.Game
2 years ago
import com.last.commit.TimeTravelAssetManager
import com.last.commit.audio.SoundEngine
2 years ago
2 years ago
class MainMenu(val parent: Game) : Screen {
2 years ago
2 years ago
var stage = Stage(ScreenViewport())
2 years ago
2 years ago
lateinit var uiSkin: Skin
2 years ago
val state = ColorState()
override fun show() {
2 years ago
Gdx.input.setInputProcessor(stage);
SoundEngine.resume()
uiSkin = TimeTravelAssetManager.getSkin()
stage.clear()
2 years ago
//add buttons to table
2 years ago
createTable();
2 years ago
}
2 years ago
fun createTable(): Table {
var table = Table()
2 years ago
table.setFillParent(true);
2 years ago
table.setDebug(true)
stage.addActor(table);
2 years ago
val newGame = TextButton("Play Game", uiSkin)
2 years ago
val preferences = TextButton("Settings", uiSkin)
2 years ago
val exit = TextButton("Exit", uiSkin)
exit.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
Gdx.app.exit()
}
})
newGame.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
parent.changeScreen(Screens.GAME)
}
})
preferences.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
parent.changeScreen(Screens.SETTINGS)
}
})
2 years ago
table.add(newGame).fillX().uniformX()
table.row().pad(10F, 0F, 10F, 0F)
table.add(preferences).fill().uniformX()
table.row()
table.add(exit).fillX().uniformX()
return table
2 years ago
}
override fun render(delta: Float) {
state.step((delta * 1000).toLong())
// Draw your screen here. "delta" is the time since last render in seconds.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
2 years ago
var red = MathUtils.clamp(state.red, 0.1F, 0.5F)
var blue = MathUtils.clamp(state.green, 0.1F, 0.5F)
var green = MathUtils.clamp(state.blue, 0.1F, 0.5F)
Gdx.gl.glClearColor(red, green, blue, 1f)
2 years ago
// tell our stage to do actions and draw itself
stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
stage.draw();
}
override fun resize(width: Int, height: Int) {
2 years ago
println("width $width, height $height")
stage.viewport.update(width, height, true);
}
override fun pause() {
}
override fun resume() {
}
override fun hide() {
}
override fun dispose() {
2 years ago
stage.dispose();
}
}