Commit bab3564b authored by Mathias O. Myklebust's avatar Mathias O. Myklebust 🦆
Browse files

Merge branch 'i70/turn-timer-ui' into 'master'

Show turn timer UI

Closes #70

See merge request !60
parents e42f521e ea7f63d0
Pipeline #175809 canceled with stages
in 30 minutes and 54 seconds
......@@ -92,6 +92,15 @@ class BattleController(
private val maxTurnTimeSeconds = 60
private var turnStartMillis: Long? = null
private var turnElapsedMillis: Long? = null
private var turnCounterSeconds: Int? = null
set(value) {
field = value
if (value != null) {
view.turnTimer = maxTurnTimeSeconds - value - 1
} else {
view.turnTimer = null
}
}
private var battleOver = false
......@@ -112,8 +121,13 @@ class BattleController(
turnStartMillis?.let { startTime ->
(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - startTime).let { elapsed ->
turnElapsedMillis = elapsed
if (elapsed > maxTurnTimeSeconds * 1000) {
onPass()
turnCounterSeconds?.let {
if (elapsed >= it * 1000) {
turnCounterSeconds = it + 1
}
if (it >= maxTurnTimeSeconds) {
onPass()
}
}
}
}
......@@ -133,11 +147,13 @@ class BattleController(
applySpells(if (battle.yourTurn) battle.activeSpells.first else battle.activeSpells.second)
if (battle.yourTurn) {
turnStartMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime())
turnCounterSeconds = 0
}
}
private fun endTurn() {
turnStartMillis = null
turnCounterSeconds = null
battle.getCurrentOutcome()?.let(::resolveGame)
battle.nextTurn()
startTurn()
......
package se.battlegoo.battlegoose.views
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.Sprite
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table
import se.battlegoo.battlegoose.Game
......@@ -27,8 +29,7 @@ class BattleView(
val hero: Hero,
enemyHero: Hero,
val stage: Stage
) :
ViewBase() {
) : ViewBase() {
companion object {
// Relative values in percentage (0f - 1f) to place elements atop the background
......@@ -62,6 +63,23 @@ class BattleView(
)
private val backgroundSprite = Sprite(backgroundTexture)
private val skin = Skin(Gdx.files.internal(Skins.STAR_SOLDIER.filepath))
private val turnTimerLabel: Label = Label("", skin).also {
it.setPosition(
position.x + heroIconMarginUpLeft,
position.y + maxSize.y - heroIconWidth - heroIconMarginUpLeft * 2
)
it.setScale(2f)
it.color = Color.BLACK
stage.addActor(it)
}
var turnTimer: Int? = null
set(value) {
field = value
turnTimerLabel.setText(turnTimer?.toString() ?: "")
}
private val heroIconView = HeroIconView(
ScreenVector(
position.x + heroIconMarginUpLeft,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment