Add map descripton and fps counter
parent
eeba41edbc
commit
b04d982198
@ -1,47 +0,0 @@
|
|||||||
package com.last.commit.stages
|
|
||||||
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.Stage
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
|
||||||
import com.last.commit.inventory.Inventory
|
|
||||||
import com.last.commit.inventory.InventoryItemTextureLoader
|
|
||||||
|
|
||||||
class InventoryStage(path: String, val inventory: Inventory) : Stage() {
|
|
||||||
val textureLoader = InventoryItemTextureLoader(path)
|
|
||||||
|
|
||||||
init {
|
|
||||||
textureLoader.parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
var visible = false
|
|
||||||
set(visible) {
|
|
||||||
field = visible
|
|
||||||
if (visible) {
|
|
||||||
refresh()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun refresh() {
|
|
||||||
super.clear()
|
|
||||||
inventory.items.forEachIndexed { index, inventoryItem ->
|
|
||||||
val image = Image(textureLoader.getTexture(inventoryItem.name))
|
|
||||||
image.x = index * 32f
|
|
||||||
image.width = 32f
|
|
||||||
image.height = 32f
|
|
||||||
|
|
||||||
addActor(image)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun resize(width: Int, height: Int) {
|
|
||||||
viewport.update(width, height, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun draw() {
|
|
||||||
if (inventory.updated) {
|
|
||||||
this.refresh()
|
|
||||||
}
|
|
||||||
if (visible) {
|
|
||||||
super.draw()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.last.commit.stages
|
||||||
|
|
||||||
|
import GameState
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Stage
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
|
import com.last.commit.inventory.InventoryItemTextureLoader
|
||||||
|
|
||||||
|
class UIStage(path: String, val state: GameState) : Stage() {
|
||||||
|
val textureLoader = InventoryItemTextureLoader(path)
|
||||||
|
private val labelStyle = Label.LabelStyle(BitmapFont(), Color.BLACK)
|
||||||
|
var mapLabel = Label(state.mapDescription, labelStyle)
|
||||||
|
var fpsLabel = Label("0", labelStyle)
|
||||||
|
private var lastFpsUpdate = 0L
|
||||||
|
|
||||||
|
init {
|
||||||
|
textureLoader.parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun refresh() {
|
||||||
|
super.clear()
|
||||||
|
state.inventory.items.forEachIndexed { index, inventoryItem ->
|
||||||
|
val image = Image(textureLoader.getTexture(inventoryItem.name))
|
||||||
|
image.x = index * 32f
|
||||||
|
image.width = 32f
|
||||||
|
image.height = 32f
|
||||||
|
|
||||||
|
addActor(image)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resize(width: Int, height: Int) {
|
||||||
|
viewport.update(width, height, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun act(delta: Float) {
|
||||||
|
if (state.inventory.updated) {
|
||||||
|
this.refresh()
|
||||||
|
state.inventory.updated = false
|
||||||
|
}
|
||||||
|
this.addFpsLabel(delta)
|
||||||
|
this.addMapDescriptionLabel()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw() {
|
||||||
|
super.draw()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addFpsLabel(delta: Float) {
|
||||||
|
if (System.currentTimeMillis() - lastFpsUpdate > 500) {
|
||||||
|
actors.removeValue(this.fpsLabel, true)
|
||||||
|
fpsLabel = Label((1 / delta).toInt().toString(), labelStyle)
|
||||||
|
fpsLabel.x = this.viewport.worldWidth - fpsLabel.width
|
||||||
|
fpsLabel.y = this.viewport.worldHeight - fpsLabel.height
|
||||||
|
addActor(fpsLabel)
|
||||||
|
lastFpsUpdate = System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addMapDescriptionLabel() {
|
||||||
|
this.actors.removeValue(this.mapLabel, true)
|
||||||
|
this.mapLabel = Label(state.mapDescription, labelStyle)
|
||||||
|
mapLabel.x = 0f
|
||||||
|
mapLabel.y = this.viewport.worldHeight - mapLabel.height
|
||||||
|
addActor(mapLabel)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue