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.
80 lines
2.0 KiB
Kotlin
80 lines
2.0 KiB
Kotlin
package com.last.commit.stages
|
|
|
|
import com.badlogic.gdx.utils.viewport.ExtendViewport
|
|
import com.badlogic.gdx.utils.Align
|
|
import com.badlogic.gdx.scenes.scene2d.Stage
|
|
import com.badlogic.gdx.scenes.scene2d.ui.TextArea
|
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
|
import com.badlogic.gdx.graphics.g2d.Batch
|
|
import com.badlogic.gdx.Input
|
|
|
|
class PromptStage(skin: Skin?): Stage(ExtendViewport(300f, 300f)) {
|
|
|
|
private val textArea: TextArea;
|
|
var visible = false
|
|
private val text: ArrayList<String> = ArrayList()
|
|
|
|
init {
|
|
textArea = TextArea("", skin)
|
|
textArea.setSize(viewport.worldWidth * 0.8f, viewport.worldHeight * 0.6f)
|
|
textArea.setPosition(viewport.worldWidth * 0.1f, viewport.worldHeight * 0.2f)
|
|
textArea.setAlignment(Align.center)
|
|
|
|
this.addActor(textArea)
|
|
}
|
|
|
|
override fun act(delta: Float) {
|
|
if (visible) {
|
|
if (this.textArea.text.isEmpty()) {
|
|
this.next()
|
|
}
|
|
super.act(delta)
|
|
}
|
|
}
|
|
|
|
override fun draw() {
|
|
if (visible) {
|
|
this.viewport.apply()
|
|
super.draw()
|
|
}
|
|
}
|
|
|
|
fun clearText() {
|
|
this.text.clear()
|
|
}
|
|
|
|
fun addText(text: String) {
|
|
this.text.add(text)
|
|
}
|
|
|
|
fun resize(width: Int, height: Int) {
|
|
this.viewport.update(width, height)
|
|
this.camera.update()
|
|
}
|
|
|
|
override fun keyDown(keyCode: Int): Boolean {
|
|
return if (!visible) {
|
|
false
|
|
} else if (keyCode == Input.Keys.SPACE) {
|
|
next()
|
|
false
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
|
|
private operator fun next() {
|
|
textArea.clear()
|
|
|
|
if (text.isNotEmpty()) {
|
|
val text = text.removeAt(0).trimIndent()
|
|
textArea.text = text
|
|
} else {
|
|
visible = false
|
|
}
|
|
}
|
|
|
|
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
|
return keyDown(Input.Keys.SPACE)
|
|
}
|
|
} |