diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index 44d846347..a70cae4d9 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -175,6 +175,14 @@ class StateInGame : BasicGameState() { // audio test //AudioResourceLibrary.ambientsWoods[0].play() + + + + val vitalmetre = UIHandler(UIVitalMetre(player, { 100f }, { 100f }, Color(255, 182, 0))) + //vitalmetre.setAsAlwaysVisible() + vitalmetre.isVisible = true + vitalmetre.UI.handler = vitalmetre + uiContainer.add(vitalmetre) } var particlesActive = 0 diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 0afb6c775..8da88ce03 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -581,7 +581,7 @@ infix fun Color.screen(other: Color) = Color( 1f - (1f - this.a) * (1f - other.a) ) -infix fun Color.mul(other: Color) = Color( +operator fun Color.times(other: Color) = Color( this.r * other.r, this.g * other.g, this.b * other.b, diff --git a/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt b/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt index 4950b9844..6dd71d2d7 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt @@ -44,10 +44,14 @@ open class ActorWithSprite(renderOrder: ActorOrder, val immobileBody: Boolean = @Transient private val world: GameWorld = Terrarum.ingame.world - protected var hitboxTranslateX: Double = 0.0// relative to spritePosX - protected var hitboxTranslateY: Double = 0.0// relative to spritePosY - protected var baseHitboxW: Int = 0 - protected var baseHitboxH: Int = 0 + var hitboxTranslateX: Double = 0.0// relative to spritePosX + protected set + var hitboxTranslateY: Double = 0.0// relative to spritePosY + protected set + var baseHitboxW: Int = 0 + protected set + var baseHitboxH: Int = 0 + protected set /** * * Position: top-left point * * Unit: pixel diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index deb3c3205..b6deec8cf 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -49,6 +49,28 @@ interface UICanvas { * Do not modify handler!!.openCloseCounter here. */ fun endClosing(gc: GameContainer, delta: Int) -} -const val OPENCLOSE_GENERIC = 200 \ No newline at end of file + companion object { + const val OPENCLOSE_GENERIC = 200 + + fun doOpeningFade(handler: UIHandler?, openCloseTime: Int) { + handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime + } + + fun doClosingFade(handler: UIHandler?, openCloseTime: Int) { + handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime + } + + fun endOpeningFade(handler: UIHandler?) { + handler!!.opacity = 1f + } + + fun endClosingFade(handler: UIHandler?) { + handler!!.opacity = 0f + } + + // TODO add drawer slide in/out (quadratic) + + // TODO add blackboard take in/out (sinusoidal) + } +} diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt index f5d31a898..bbea31f51 100644 --- a/src/net/torvald/terrarum/ui/UIHandler.kt +++ b/src/net/torvald/terrarum/ui/UIHandler.kt @@ -133,8 +133,8 @@ constructor(val UI: UICanvas) { } fun setAsAlwaysVisible() { - alwaysVisible = true isVisible = true + alwaysVisible = true isOpened = true isOpening = false isClosing = false diff --git a/src/net/torvald/terrarum/ui/UIPieMenu.kt b/src/net/torvald/terrarum/ui/UIPieMenu.kt index ee98945b0..c55386d34 100644 --- a/src/net/torvald/terrarum/ui/UIPieMenu.kt +++ b/src/net/torvald/terrarum/ui/UIPieMenu.kt @@ -82,22 +82,22 @@ class UIPieMenu : UICanvas { } override fun doOpening(gc: GameContainer, delta: Int) { - handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime + UICanvas.doOpeningFade(handler, openCloseTime) handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity) } override fun doClosing(gc: GameContainer, delta: Int) { - handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime + UICanvas.doClosingFade(handler, openCloseTime) handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity) } override fun endOpening(gc: GameContainer, delta: Int) { - handler!!.opacity = 1f + UICanvas.endOpeningFade(handler) handler!!.scale = 1f } override fun endClosing(gc: GameContainer, delta: Int) { - handler!!.opacity = 0f + UICanvas.endClosingFade(handler) handler!!.scale = 1f } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UIVitalMetre.kt b/src/net/torvald/terrarum/ui/UIVitalMetre.kt new file mode 100644 index 000000000..262974b48 --- /dev/null +++ b/src/net/torvald/terrarum/ui/UIVitalMetre.kt @@ -0,0 +1,107 @@ +package net.torvald.terrarum.ui + +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.gameactors.ActorHumanoid +import net.torvald.terrarum.gameactors.floorInt +import net.torvald.terrarum.gameactors.roundInt +import net.torvald.terrarum.times +import org.newdawn.slick.Color +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.Input + +/** + * Created by SKYHi14 on 2017-03-03. + */ +class UIVitalMetre( + var player: ActorHumanoid, + val vitalGetterVal: () -> Float, + val vitalGetterMax: () -> Float, + val color: Color, + val order: Int = 0 +) : UICanvas { + + override var width: Int = 84 + override var height: Int = player.baseHitboxH * 3 + 2 + override var handler: UIHandler? = null + override var openCloseTime: Int = 50 + + private val relativePX = width / 2f + private val relativePY = player.baseHitboxH * 1.5f + private val circleRadius = player.baseHitboxH * 3f + + private val theta = 33f + private val halfTheta = theta / 2f + + override fun update(gc: GameContainer, delta: Int) { + handler!!.setPosition( + (Terrarum.HALFW - relativePX).roundInt(), + (Terrarum.HALFH - relativePY).floorInt() + ) + } + + override fun render(gc: GameContainer, g: Graphics) { + g.lineWidth = 1.8f + val saturation = 2f + + // background + g.color = Color( + (color.r * saturation) - (saturation - 1), + (color.g * saturation) - (saturation - 1), + (color.b * saturation) - (saturation - 1), + 0.9f + ) + g.drawArc( + relativePX - circleRadius, + -circleRadius, + circleRadius * 2f, + circleRadius * 2f, + 90f - halfTheta, + 90f + halfTheta + ) + + g.color = color + g.drawArc( + relativePX - circleRadius, + -circleRadius, + circleRadius * 2f, + circleRadius * 2f, + 90f + halfTheta - theta * (vitalGetterVal() / vitalGetterMax()), + 90f + halfTheta + ) + } + + override fun processInput(gc: GameContainer, delta: Int, input: Input) { + } + + override fun doOpening(gc: GameContainer, delta: Int) { + UICanvas.doOpeningFade(handler, openCloseTime) + } + + override fun doClosing(gc: GameContainer, delta: Int) { + UICanvas.doClosingFade(handler, openCloseTime) + } + + override fun endOpening(gc: GameContainer, delta: Int) { + UICanvas.endOpeningFade(handler) + } + + override fun endClosing(gc: GameContainer, delta: Int) { + UICanvas.endClosingFade(handler) + } +} + +/* + +X-------------+ (84) +| | +| | +| @ | +| @ | +|, ,| +| ''-------'' | ++-------------+ + +X: UICanvas position + + */ \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputer/worldobject/ui/UITextTerminal.kt b/src/net/torvald/terrarum/virtualcomputer/worldobject/ui/UITextTerminal.kt index 9699a0fd4..03993092f 100644 --- a/src/net/torvald/terrarum/virtualcomputer/worldobject/ui/UITextTerminal.kt +++ b/src/net/torvald/terrarum/virtualcomputer/worldobject/ui/UITextTerminal.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.virtualcomputer.worldobject.ui import net.torvald.terrarum.ui.* +import net.torvald.terrarum.ui.UICanvas.Companion.OPENCLOSE_GENERIC import net.torvald.terrarum.virtualcomputer.terminal.Terminal import org.newdawn.slick.GameContainer import org.newdawn.slick.Graphics diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index 4acf33d46..ee411f181 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -133,7 +133,7 @@ object WeatherMixer { fun Float.clampOne() = if (this > 1) 1f else this - operator fun Color.times(other: Color) = Color(this.r * other.r, this.g * other.g, this.b * other.b, 1f) + private operator fun Color.times(other: Color) = Color(this.r * other.r, this.g * other.g, this.b * other.b, 1f) /** * Get a GL of specific time diff --git a/work_files/UI/vital_metres_2_annotation.png b/work_files/UI/vital_metres_2_annotation.png index 1a66eabcf..cadd4cc35 100644 Binary files a/work_files/UI/vital_metres_2_annotation.png and b/work_files/UI/vital_metres_2_annotation.png differ