mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
LibGDX, here I am.
This commit is contained in:
36
src/net/torvald/terrarum/ui/AmmoMeterProxy.kt
Normal file
36
src/net/torvald/terrarum/ui/AmmoMeterProxy.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.ui.UIVitalMetre
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-04-21.
|
||||
*/
|
||||
object AmmoMeterProxy {
|
||||
|
||||
operator fun invoke(actor: ActorHumanoid, meter: UIVitalMetre) {
|
||||
val currentItem = actor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
|
||||
|
||||
if (currentItem == null) {
|
||||
meter.vitalGetterMax = { null }
|
||||
meter.vitalGetterVal = { null }
|
||||
}
|
||||
else {
|
||||
meter.vitalGetterVal = {
|
||||
if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA) {
|
||||
actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat()
|
||||
}
|
||||
else
|
||||
currentItem.durability
|
||||
}
|
||||
|
||||
meter.vitalGetterMax = {
|
||||
if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA)
|
||||
500f
|
||||
else
|
||||
currentItem.maxDurability.toFloat()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,26 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.imagefont.GameFontBase
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.blendScreen
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-14.
|
||||
*/
|
||||
class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
override var width: Int = Terrarum.WIDTH
|
||||
override var height: Int = Terrarum.HEIGHT
|
||||
override var width: Int = Gdx.graphics.width
|
||||
override var height: Int = Gdx.graphics.height
|
||||
|
||||
override var openCloseTime: Int = 0
|
||||
override var openCloseTime: Float = 0f
|
||||
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
@@ -31,18 +30,16 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
private var xdelta = 0.0
|
||||
private var ydelta = 0.0
|
||||
|
||||
val ccW = GameFontBase.colToCode["w"]
|
||||
val ccG = GameFontBase.colToCode["g"]
|
||||
val ccY = GameFontBase.colToCode["y"]
|
||||
val ccR = GameFontBase.colToCode["r"]
|
||||
val ccM = GameFontBase.colToCode["m"]
|
||||
val ccW = 0.toChar()//GameFontBase.colToCode["w"]
|
||||
val ccG = 0.toChar()//GameFontBase.colToCode["g"]
|
||||
val ccY = 0.toChar()//GameFontBase.colToCode["y"]
|
||||
val ccR = 0.toChar()//GameFontBase.colToCode["r"]
|
||||
val ccM = 0.toChar()//GameFontBase.colToCode["m"]
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
val player = Terrarum.ingame!!.player!!
|
||||
override fun update(delta: Float) {
|
||||
val player = TerrarumGDX.ingame!!.player!!
|
||||
val hitbox = player.hitbox
|
||||
|
||||
xdelta = hitbox.canonicalX - prevPlayerX
|
||||
@@ -52,18 +49,19 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
prevPlayerY = hitbox.canonicalY
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
fun Int.rawR() = this / LightmapRenderer.MUL_2
|
||||
fun Int.rawG() = this % LightmapRenderer.MUL_2 / LightmapRenderer.MUL
|
||||
fun Int.rawB() = this % LightmapRenderer.MUL
|
||||
|
||||
val player = Terrarum.ingame!!.player
|
||||
val player = TerrarumGDX.ingame!!.player
|
||||
|
||||
val mouseTileX = ((WorldCamera.x + gc.input.mouseX / Terrarum.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((WorldCamera.y + gc.input.mouseY / Terrarum.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileX = ((WorldCamera.x + TerrarumGDX.mouseX / TerrarumGDX.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((WorldCamera.y + TerrarumGDX.mouseY / TerrarumGDX.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
|
||||
g.font = Terrarum.fontSmallNumbers
|
||||
g.color = GameFontBase.codeToCol["y"]
|
||||
//g.color = GameFontBase.codeToCol["y"]
|
||||
|
||||
batch.color = Color.WHITE
|
||||
|
||||
val hitbox = player?.hitbox
|
||||
|
||||
@@ -71,42 +69,42 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
* First column
|
||||
*/
|
||||
|
||||
printLineColumn(g, 1, 1, "startX "
|
||||
printLineColumn(batch, 1, 1, "startX "
|
||||
+ ccG
|
||||
+ "${hitbox?.startX}"
|
||||
+ " ("
|
||||
+ "${(hitbox?.startX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
printLineColumn(g, 2, 1, "endX "
|
||||
printLineColumn(batch, 2, 1, "endX "
|
||||
+ ccG
|
||||
+ "${hitbox?.endX}"
|
||||
+ " ("
|
||||
+ "${(hitbox?.endX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
printLineColumn(g, 1, 2, "startY "
|
||||
printLineColumn(batch, 1, 2, "startY "
|
||||
+ ccG
|
||||
+ "${hitbox?.startY}"
|
||||
+ " ("
|
||||
+ "${(hitbox?.startY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
printLineColumn(g, 2, 2, "endY "
|
||||
printLineColumn(batch, 2, 2, "endY "
|
||||
+ ccG
|
||||
+ "${hitbox?.endY}"
|
||||
+ " ("
|
||||
+ "${(hitbox?.endY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
|
||||
printLine(g, 3, "veloX reported $ccG${player?.externalForce?.x}")
|
||||
printLine(g, 4, "veloY reported $ccG${player?.externalForce?.y}")
|
||||
printLine(batch, 3, "veloX reported $ccG${player?.externalForce?.x}")
|
||||
printLine(batch, 4, "veloY reported $ccG${player?.externalForce?.y}")
|
||||
|
||||
printLine(g, 5, "p_WalkX $ccG${player?.controllerMoveDelta?.x}")
|
||||
printLine(g, 6, "p_WalkY $ccG${player?.controllerMoveDelta?.y}")
|
||||
printLine(batch, 5, "p_WalkX $ccG${player?.controllerMoveDelta?.x}")
|
||||
printLine(batch, 6, "p_WalkY $ccG${player?.controllerMoveDelta?.y}")
|
||||
|
||||
printLineColumn(g, 2, 3, "veloX measured $ccG${xdelta}")
|
||||
printLineColumn(g, 2, 4, "veloY measured $ccG${ydelta}")
|
||||
printLineColumn(batch, 2, 3, "veloX measured $ccG${xdelta}")
|
||||
printLineColumn(batch, 2, 4, "veloY measured $ccG${ydelta}")
|
||||
|
||||
if (player != null) {
|
||||
printLineColumn(g, 1, 7,
|
||||
printLineColumn(batch, 1, 7,
|
||||
"walled " +
|
||||
"${if (player.walledLeft) "$ccR" else "$ccG"}L" +
|
||||
"${if (player.walledBottom) "$ccR" else "$ccG"}${0x1F.toChar()}" +
|
||||
@@ -118,7 +116,7 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
|
||||
|
||||
//printLine(g, 7, "jump $ccG${player.jumpAcc}")
|
||||
//printLine(batch, 7, "jump $ccG${player.jumpAcc}")
|
||||
|
||||
val lightVal: String
|
||||
val mtX = mouseTileX.toString()
|
||||
@@ -133,35 +131,35 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
rawR.toString() + " " +
|
||||
rawG.toString() + " " +
|
||||
rawB.toString() + ")"
|
||||
printLine(g, 8, "light@cursor $ccG$lightVal")
|
||||
printLine(batch, 8, "light@cursor $ccG$lightVal")
|
||||
|
||||
val tileNum = Terrarum.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
|
||||
val tileNum = TerrarumGDX.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
|
||||
|
||||
printLine(g, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)")
|
||||
printLine(batch, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)")
|
||||
|
||||
/**
|
||||
* Second column
|
||||
*/
|
||||
|
||||
//printLineColumn(g, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
|
||||
//printLineColumn(g, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
|
||||
//printLineColumn(batch, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
|
||||
//printLineColumn(batch, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
|
||||
|
||||
printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" +
|
||||
" (${Terrarum.ingame!!.world.time.getFormattedTime()})")
|
||||
printLineColumn(g, 2, 6, "Mass $ccG${player?.mass}")
|
||||
printLineColumn(batch, 2, 5, "Time $ccG${TerrarumGDX.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" +
|
||||
" (${TerrarumGDX.ingame!!.world.time.getFormattedTime()})")
|
||||
printLineColumn(batch, 2, 6, "Mass $ccG${player?.mass}")
|
||||
|
||||
printLineColumn(g, 2, 7, "noClip $ccG${player?.noClip}")
|
||||
printLineColumn(batch, 2, 7, "noClip $ccG${player?.noClip}")
|
||||
|
||||
|
||||
drawHistogram(g, LightmapRenderer.histogram,
|
||||
Terrarum.WIDTH - histogramW - 30,
|
||||
Terrarum.HEIGHT - histogramH - 30
|
||||
drawHistogram(batch, LightmapRenderer.histogram,
|
||||
Gdx.graphics.width - histogramW - 30,
|
||||
Gdx.graphics.height - histogramH - 30
|
||||
)
|
||||
if (Terrarum.controller != null) {
|
||||
drawGamepadAxis(g,
|
||||
Terrarum.controller!!.getAxisValue(3),
|
||||
Terrarum.controller!!.getAxisValue(2),
|
||||
Terrarum.WIDTH - 135,
|
||||
if (TerrarumGDX.controller != null) {
|
||||
drawGamepadAxis(batch,
|
||||
TerrarumGDX.controller!!.getAxisValue(3),
|
||||
TerrarumGDX.controller!!.getAxisValue(2),
|
||||
Gdx.graphics.width - 135,
|
||||
40
|
||||
)
|
||||
}
|
||||
@@ -170,65 +168,69 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
* Top right
|
||||
*/
|
||||
|
||||
g.color = GameFontBase.codeToCol["y"]
|
||||
g.drawString("${ccY}MEM ", (Terrarum.WIDTH - 21 * 8 - 2).toFloat(), 2f)
|
||||
//g.drawString("${ccY}FPS $ccG${Terrarum.appgc.fps}", (Terrarum.WIDTH - 6 * 8 - 2).toFloat(), 10f)
|
||||
g.drawString("${ccY}CPUs ${if (Terrarum.MULTITHREAD) ccG else ccR}${Terrarum.THREADS}",
|
||||
(Terrarum.WIDTH - 2 - 6*8).toFloat(), 10f)
|
||||
//g.color = GameFontBase.codeToCol["y"]
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}MEM ", (Gdx.graphics.width - 21 * 8 - 2).toFloat(), 2f)
|
||||
//g.draw(batch, "${ccY}FPS $ccG${Terrarum.appgc.fps}", (Gdx.graphics.width - 6 * 8 - 2).toFloat(), 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}CPUs ${if (TerrarumGDX.MULTITHREAD) ccG else ccR}${TerrarumGDX.THREADS}",
|
||||
(Gdx.graphics.width - 2 - 6*8).toFloat(), 10f)
|
||||
|
||||
g.color = GameFontBase.codeToCol["g"]
|
||||
g.drawString("${Terrarum.memInUse}M",
|
||||
(Terrarum.WIDTH - 17 * 8 - 2).toFloat(), 2f)
|
||||
g.drawString("/${Terrarum.memTotal}M/",
|
||||
(Terrarum.WIDTH - 12 * 8 - 2).toFloat(), 2f)
|
||||
g.color = GameFontBase.codeToCol["m"]
|
||||
g.drawString("${Terrarum.memXmx}M",
|
||||
(Terrarum.WIDTH - 5 * 8 - 2).toFloat(), 2f)
|
||||
//g.color = GameFontBase.codeToCol["g"]
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${TerrarumGDX.memInUse}M",
|
||||
(Gdx.graphics.width - 17 * 8 - 2).toFloat(), 2f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "/${TerrarumGDX.memTotal}M/",
|
||||
(Gdx.graphics.width - 12 * 8 - 2).toFloat(), 2f)
|
||||
//TerrarumGDX.fontSmallNumbers.color = GameFontBase.codeToCol["m"]
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${TerrarumGDX.memXmx}M",
|
||||
(Gdx.graphics.width - 5 * 8 - 2).toFloat(), 2f)
|
||||
|
||||
/**
|
||||
* Bottom left
|
||||
*/
|
||||
|
||||
g.drawString("${ccY}Actors total $ccG${Terrarum.ingame!!.actorContainer.size + Terrarum.ingame!!.actorContainerInactive.size}",
|
||||
2f, Terrarum.HEIGHT - 10f)
|
||||
g.drawString("${ccY}Active $ccG${Terrarum.ingame!!.actorContainer.size}",
|
||||
(2 + 17*8).toFloat(), Terrarum.HEIGHT - 10f)
|
||||
g.drawString("${ccY}Dormant $ccG${Terrarum.ingame!!.actorContainerInactive.size}",
|
||||
(2 + 28*8).toFloat(), Terrarum.HEIGHT - 10f)
|
||||
g.drawString("${ccM}Particles $ccG${Terrarum.ingame!!.particlesActive}",
|
||||
(2 + 41*8).toFloat(), Terrarum.HEIGHT - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Actors total $ccG${TerrarumGDX.ingame!!.actorContainer.size + TerrarumGDX.ingame!!.actorContainerInactive.size}",
|
||||
2f, Gdx.graphics.height - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Active $ccG${TerrarumGDX.ingame!!.actorContainer.size}",
|
||||
(2 + 17*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Dormant $ccG${TerrarumGDX.ingame!!.actorContainerInactive.size}",
|
||||
(2 + 28*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${TerrarumGDX.ingame!!.particlesActive}",
|
||||
(2 + 41*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
}
|
||||
|
||||
private fun printLine(g: Graphics, l: Int, s: String) {
|
||||
g.drawString(s, 10f, line(l))
|
||||
private fun printLine(batch: SpriteBatch, l: Int, s: String) {
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch,
|
||||
s, 10f, line(l)
|
||||
)
|
||||
}
|
||||
|
||||
private fun printLineColumn(g: Graphics, col: Int, row: Int, s: String) {
|
||||
g.drawString(s, (10 + column(col)), line(row))
|
||||
private fun printLineColumn(batch: SpriteBatch, col: Int, row: Int, s: String) {
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch,
|
||||
s, (10 + column(col)), line(row)
|
||||
)
|
||||
}
|
||||
|
||||
val histogramW = 256
|
||||
val histogramH = 200
|
||||
|
||||
private fun drawHistogram(g: Graphics, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
|
||||
val uiColour = Color(0x80000000.toInt())
|
||||
val barR = Color(0xDD0000)
|
||||
val barG = Color(0x00DD00)
|
||||
val barB = Color(0x0000DD)
|
||||
private fun drawHistogram(batch: SpriteBatch, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
|
||||
val uiColour = Color(0x000000_80.toInt())
|
||||
val barR = Color(0xDD0000_FF.toInt())
|
||||
val barG = Color(0x00DD00_FF.toInt())
|
||||
val barB = Color(0x0000DD_FF.toInt())
|
||||
val barColour = arrayOf(barR, barG, barB)
|
||||
val w = histogramW.toFloat()
|
||||
val h = histogramH.toFloat()
|
||||
val range = histogram.range
|
||||
val histogramMax = histogram.screen_tiles.toFloat()
|
||||
|
||||
g.color = uiColour
|
||||
g.fillRect(x.toFloat(), y.toFloat(), w.plus(1), h)
|
||||
g.color = Color.gray
|
||||
g.drawString("0", x.toFloat(), y.toFloat() + h + 2)
|
||||
g.drawString("255", x.toFloat() + w + 1 - 8*3, y.toFloat() + h + 2)
|
||||
g.drawString("Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
|
||||
batch.color = uiColour
|
||||
batch.fillRect(x.toFloat(), y.toFloat(), w.plus(1), h)
|
||||
batch.color = Color.GRAY
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "0", x.toFloat(), y.toFloat() + h + 2)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "255", x.toFloat() + w + 1 - 8*3, y.toFloat() + h + 2)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
|
||||
|
||||
blendScreen()
|
||||
//blendScreen()
|
||||
for (c in 0..2) {
|
||||
for (i in 0..255) {
|
||||
var histogram_value = if (i == 255) 0 else histogram.get(c)[i]
|
||||
@@ -243,14 +245,14 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
val bar_y = y + (h / histogramMax) - bar_h + h
|
||||
val bar_w = 1f
|
||||
|
||||
g.color = barColour[c]
|
||||
g.fillRect(bar_x, bar_y, bar_w, bar_h)
|
||||
batch.color = barColour[c]
|
||||
batch.fillRect(bar_x, bar_y, bar_w, bar_h)
|
||||
}
|
||||
}
|
||||
blendNormal()
|
||||
//blendNormal()
|
||||
}
|
||||
|
||||
private fun drawGamepadAxis(g: Graphics, axisX: Float, axisY: Float, uiX: Int, uiY: Int) {
|
||||
private fun drawGamepadAxis(batch: SpriteBatch, axisX: Float, axisY: Float, uiX: Int, uiY: Int) {
|
||||
val uiColour = Color(0xAA000000.toInt())
|
||||
val w = 128f
|
||||
val h = 128f
|
||||
@@ -260,36 +262,41 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
val pointDX = axisX * halfW
|
||||
val pointDY = axisY * halfH
|
||||
|
||||
val padName = if (Terrarum.controller!!.name.isEmpty()) "Gamepad"
|
||||
else Terrarum.controller!!.name
|
||||
val padName = if (TerrarumGDX.controller!!.name.isEmpty()) "Gamepad"
|
||||
else TerrarumGDX.controller!!.name
|
||||
|
||||
blendNormal()
|
||||
|
||||
g.color = uiColour
|
||||
g.fillRect(uiX.toFloat(), uiY.toFloat(), w, h)
|
||||
g.color = Color.white
|
||||
g.drawLine(uiX + halfW, uiY + halfH, uiX + halfW + pointDX, uiY + halfH + pointDY)
|
||||
g.color = Color.gray
|
||||
g.drawString(padName, uiX + w / 2 - (padName.length) * 4, uiY.toFloat() + h + 2)
|
||||
batch.end()
|
||||
TerrarumGDX.inShapeRenderer {
|
||||
it.color = uiColour
|
||||
it.rect(uiX.toFloat(), uiY.toFloat(), w, h)
|
||||
it.color = Color.WHITE
|
||||
it.line(uiX + halfW, uiY + halfH, uiX + halfW + pointDX, uiY + halfH + pointDY)
|
||||
it.color = Color.GRAY
|
||||
}
|
||||
batch.begin()
|
||||
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, padName, uiX + w / 2 - (padName.length) * 4, uiY.toFloat() + h + 2)
|
||||
|
||||
}
|
||||
|
||||
private fun line(i: Int): Float = i * 10f
|
||||
|
||||
private fun column(i: Int): Float = 300f * (i - 1)
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.dataclass.HistoryArray
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.console.Authenticator
|
||||
import net.torvald.terrarum.console.CommandInterpreter
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
class ConsoleWindow : UICanvas, KeyControlled {
|
||||
|
||||
internal var UIColour = Color(0x80404080.toInt())
|
||||
internal var UIColour = Color(0x404080_80.toInt())
|
||||
|
||||
private var inputCursorPos: Int = 0
|
||||
private val MESSAGES_MAX = 5000
|
||||
@@ -31,14 +32,14 @@ class ConsoleWindow : UICanvas, KeyControlled {
|
||||
private val LINE_HEIGHT = 20
|
||||
private val MESSAGES_DISPLAY_COUNT = 11
|
||||
|
||||
override var width: Int = Terrarum.WIDTH
|
||||
override var width: Int = Gdx.graphics.width
|
||||
override var height: Int = LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT + 1)
|
||||
|
||||
override var openCloseTime: Int = 0
|
||||
override var openCloseTime = 0f
|
||||
|
||||
private var drawOffX: Float = 0f
|
||||
private var drawOffY: Float = -height.toFloat()
|
||||
private var openingTimeCounter = 0
|
||||
private var openingTimeCounter = 0f
|
||||
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
@@ -48,34 +49,33 @@ class ConsoleWindow : UICanvas, KeyControlled {
|
||||
reset()
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun update(delta: Float) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
// background
|
||||
g.color = UIColour
|
||||
g.fillRect(drawOffX, drawOffY, width.toFloat(), height.toFloat())
|
||||
g.fillRect(drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat())
|
||||
batch.color = UIColour
|
||||
batch.fillRect(drawOffX, drawOffY, width.toFloat(), height.toFloat())
|
||||
batch.fillRect(drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat())
|
||||
|
||||
val input = commandInputPool!!.toString()
|
||||
val inputDrawWidth = g.font.getWidth(input)
|
||||
val inputDrawHeight = g.font.lineHeight
|
||||
val inputDrawWidth = TerrarumGDX.fontGame.getWidth(input)
|
||||
val inputDrawHeight = TerrarumGDX.fontGame.lineHeight
|
||||
|
||||
// text and cursor
|
||||
g.color = Color.white
|
||||
g.drawString(input, 1f + drawOffX, drawOffY)
|
||||
batch.color = Color.WHITE
|
||||
TerrarumGDX.fontGame.draw(batch, input, 1f + drawOffX, drawOffY)
|
||||
|
||||
g.color = Color(0x7f7f7f)
|
||||
g.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight.toFloat())
|
||||
g.color = Color.white
|
||||
g.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 1f, inputDrawHeight.toFloat() - 1)
|
||||
batch.color = Color(0x7f7f7f_ff)
|
||||
batch.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight)
|
||||
batch.color = Color.WHITE
|
||||
batch.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 1f, inputDrawHeight - 1)
|
||||
|
||||
|
||||
// messages
|
||||
for (i in 0..MESSAGES_DISPLAY_COUNT - 1) {
|
||||
val message = messages[messageDisplayPos + i]
|
||||
g.drawString(message, 1f + drawOffX, (LINE_HEIGHT * (i + 1)).toFloat() + drawOffY)
|
||||
TerrarumGDX.fontGame.draw(batch, message, 1f + drawOffX, (LINE_HEIGHT * (i + 1)).toFloat() + drawOffY)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,9 +133,7 @@ class ConsoleWindow : UICanvas, KeyControlled {
|
||||
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
|
||||
}
|
||||
|
||||
private fun executeCommand() {
|
||||
CommandInterpreter.execute(commandInputPool!!.toString())
|
||||
@@ -178,33 +176,33 @@ class ConsoleWindow : UICanvas, KeyControlled {
|
||||
commandInputPool = StringBuilder()
|
||||
|
||||
if (Authenticator.b()) {
|
||||
sendMessage("${Terrarum.NAME} ${Terrarum.VERSION_STRING}")
|
||||
sendMessage("${TerrarumGDX.NAME} ${TerrarumGDX.VERSION_STRING}")
|
||||
sendMessage(Lang["DEV_MESSAGE_CONSOLE_CODEX"])
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
/*openingTimeCounter += delta
|
||||
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
|
||||
-height.toFloat(), 0f
|
||||
)*/
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
/*openingTimeCounter += delta
|
||||
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
|
||||
0f, -height.toFloat()
|
||||
)*/
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
drawOffY = 0f
|
||||
openingTimeCounter = 0
|
||||
openingTimeCounter = 0f
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
drawOffY = -height.toFloat()
|
||||
openingTimeCounter = 0
|
||||
openingTimeCounter = 0f
|
||||
}
|
||||
|
||||
override fun controllerButtonPressed(controller: Int, button: Int) {
|
||||
@@ -212,4 +210,7 @@ class ConsoleWindow : UICanvas, KeyControlled {
|
||||
|
||||
override fun controllerButtonReleased(controller: Int, button: Int) {
|
||||
}
|
||||
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-08-04.
|
||||
*/
|
||||
object DrawUtil {
|
||||
fun drawCentered(g: Graphics, image: Image, screenPosY: Int, ui: UICanvas? = null) {
|
||||
fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, ui: UICanvas? = null) {
|
||||
val imageW = image.width
|
||||
val targetW = if (ui == null) Terrarum.WIDTH else ui.width
|
||||
val targetW = if (ui == null) Gdx.graphics.width else ui.width
|
||||
|
||||
g.drawImage(image, targetW.minus(imageW).ushr(1).toFloat(), screenPosY.toFloat())
|
||||
batch.draw(image, targetW.minus(imageW).ushr(1).toFloat(), screenPosY.toFloat())
|
||||
}
|
||||
|
||||
fun drawCentered(g: Graphics, image: Image, screenPosY: Int, targetW: Int, offsetX: Int = 0, offsetY: Int = 0) {
|
||||
fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, targetW: Int, offsetX: Int = 0, offsetY: Int = 0) {
|
||||
val imageW = image.width
|
||||
g.drawImage(image, targetW.minus(imageW).ushr(1).toFloat() + offsetX, screenPosY.toFloat() + offsetY)
|
||||
batch.draw(image, targetW.minus(imageW).ushr(1).toFloat() + offsetX, screenPosY.toFloat() + offsetY)
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.Image
|
||||
import org.newdawn.slick.SpriteSheet
|
||||
import org.newdawn.slick.SpriteSheetFont
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
* Make item slot image with number on bottom-right
|
||||
@@ -13,72 +15,88 @@ import org.newdawn.slick.SpriteSheetFont
|
||||
*/
|
||||
object ItemSlotImageBuilder {
|
||||
|
||||
const val COLOR_BLACK = 1
|
||||
const val COLOR_WHITE = 2
|
||||
val colourBlack = Color(0x404040_FF)
|
||||
val colourWhite = Color(0xC0C0C0_FF.toInt())
|
||||
|
||||
private val colourBlack = Color(0x40, 0x40, 0x40)
|
||||
private val colourWhite = Color(0xC0, 0xC0, 0xC0)
|
||||
|
||||
private val numberFont = SpriteSheetFont(
|
||||
SpriteSheet("./assets/graphics/fonts/numeric_small.tga", 5, 8),
|
||||
'0'
|
||||
private val numberFont = TextureRegionPack(
|
||||
"./assets/graphics/fonts/numeric_small.tga", 5, 8
|
||||
)
|
||||
val slotImage = Image("./assets/graphics/gui/quickbar/item_slot.tga") // must have same w/h as slotLarge
|
||||
val slotLarge = Image("./assets/graphics/gui/quickbar/item_slot_large.tga")
|
||||
private val canvas = Image(slotImage.width, slotImage.height)
|
||||
private val canvasLarge = Image(slotLarge.width, slotLarge.height)
|
||||
val slotImage = Pixmap(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slot.tga")) // must have same w/h as slotLarge
|
||||
val slotLarge = Pixmap(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slot_large.tga"))
|
||||
|
||||
val slotImageSize = slotImage.width
|
||||
|
||||
fun produce(color: Int, number: Int = -1): Image {
|
||||
canvas.graphics.clear()
|
||||
private val imageDict = HashMap<ImageDesc, Texture>()
|
||||
|
||||
if (color == COLOR_BLACK)
|
||||
canvas.graphics.drawImage(slotImage, 0f, 0f, colourBlack)
|
||||
else if (color == COLOR_WHITE)
|
||||
canvas.graphics.drawImage(slotImage, 0f, 0f, colourWhite)
|
||||
|
||||
if (number >= 0) {
|
||||
canvas.graphics.font = numberFont
|
||||
fun produce(isBlack: Boolean, number: Int = -1): Texture {
|
||||
val pixmap = Pixmap(slotImage.width, slotImage.height, Pixmap.Format.RGBA8888)
|
||||
val color = if (isBlack) colourBlack else colourWhite
|
||||
|
||||
if (color == COLOR_BLACK)
|
||||
canvas.graphics.color = colourWhite
|
||||
else if (color == COLOR_WHITE)
|
||||
canvas.graphics.color = colourBlack
|
||||
|
||||
canvas.graphics.drawString(number.mod(UIQuickBar.SLOT_COUNT).toString(),
|
||||
slotImage.width - 10f,
|
||||
slotImage.height - 13f
|
||||
val desc = ImageDesc(color, number, false)
|
||||
if (imageDict.containsKey(desc))
|
||||
return imageDict[desc]!!
|
||||
|
||||
|
||||
pixmap.setColor(color)
|
||||
pixmap.drawPixmap(slotImage, 0, 0)
|
||||
|
||||
|
||||
/*if (number >= 0) {
|
||||
if (isBlack)
|
||||
pixmap.setColor(colourWhite)
|
||||
else
|
||||
pixmap.setColor(colourBlack)
|
||||
|
||||
|
||||
pixmap.drawPixmap(fontPixmap,
|
||||
slotImage.width - 10,
|
||||
slotImage.height - 13
|
||||
)
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
return canvas
|
||||
val retTex = Texture(pixmap)
|
||||
pixmap.dispose()
|
||||
imageDict.put(desc, retTex)
|
||||
return retTex
|
||||
}
|
||||
|
||||
fun produceLarge(color: Int, number: Int = -1): Image {
|
||||
canvasLarge.graphics.clear()
|
||||
fun produceLarge(isBlack: Boolean, number: Int = -1): Texture {
|
||||
val pixmap = Pixmap(slotLarge.width, slotLarge.height, Pixmap.Format.RGBA8888)
|
||||
val color = if (isBlack) colourBlack else colourWhite
|
||||
|
||||
if (color == COLOR_BLACK)
|
||||
canvasLarge.graphics.drawImage(slotLarge, 0f, 0f, colourBlack)
|
||||
else if (color == COLOR_WHITE)
|
||||
canvasLarge.graphics.drawImage(slotLarge, 0f, 0f, colourWhite)
|
||||
|
||||
if (number >= 0) {
|
||||
canvasLarge.graphics.font = numberFont
|
||||
val desc = ImageDesc(color, number, false)
|
||||
if (imageDict.containsKey(desc))
|
||||
return imageDict[desc]!!
|
||||
|
||||
if (color == COLOR_BLACK)
|
||||
canvasLarge.graphics.color = colourWhite
|
||||
else if (color == COLOR_WHITE)
|
||||
canvasLarge.graphics.color = colourBlack
|
||||
|
||||
canvasLarge.graphics.drawString(number.mod(UIQuickBar.SLOT_COUNT).toString(),
|
||||
slotLarge.width - 10f,
|
||||
slotLarge.height - 13f
|
||||
pixmap.setColor(color)
|
||||
pixmap.drawPixmap(slotLarge, 0, 0)
|
||||
|
||||
|
||||
/*if (number >= 0) {
|
||||
if (isBlack)
|
||||
pixmap.setColor(colourWhite)
|
||||
else
|
||||
pixmap.setColor(colourBlack)
|
||||
|
||||
|
||||
pixmap.drawPixmap(fontPixmap,
|
||||
slotImage.width - 10,
|
||||
slotImage.height - 13
|
||||
)
|
||||
}
|
||||
}*/
|
||||
|
||||
return canvasLarge
|
||||
|
||||
val retTex = Texture(pixmap)
|
||||
pixmap.dispose()
|
||||
imageDict.put(desc, retTex)
|
||||
return retTex
|
||||
}
|
||||
|
||||
|
||||
private data class ImageDesc(val color: Color, val number: Int, val isLarge: Boolean)
|
||||
|
||||
}
|
||||
@@ -1,100 +1,78 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.imagefont.GameFontImpl
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.blendDisable
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import org.lwjgl.opengl.GL11
|
||||
import org.newdawn.slick.*
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-27.
|
||||
*/
|
||||
class MessageWindow @Throws(SlickException::class)
|
||||
constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
|
||||
class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas {
|
||||
|
||||
private var segmentLeft: Image? = null
|
||||
private var segmentRight: Image? = null
|
||||
private var segmentBody: Image? = null
|
||||
private val segment = if (isBlackVariant) SEGMENT_BLACK else SEGMENT_WHITE
|
||||
|
||||
var messagesList: Array<String>
|
||||
var messagesList = arrayOf("", "")
|
||||
override var height: Int = 0
|
||||
private val messageWindowRadius: Int
|
||||
|
||||
private var uiFont: Font? = null
|
||||
private var fontCol: Color = if (!isBlackVariant) Color.black else Color.white
|
||||
private val GLYPH_HEIGHT = 20
|
||||
private var fontCol: Color = if (!isBlackVariant) Color.BLACK else Color.WHITE
|
||||
private val GLYPH_HEIGHT = TerrarumGDX.fontGame.lineHeight
|
||||
|
||||
override var openCloseTime: Int = OPEN_CLOSE_TIME
|
||||
override var openCloseTime: Second = OPEN_CLOSE_TIME
|
||||
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
init {
|
||||
if (!isBlackVariant) {
|
||||
segmentLeft = Image("./assets/graphics/gui/message_twoline_white_left.tga")
|
||||
segmentRight = Image("./assets/graphics/gui/message_twoline_white_right.tga")
|
||||
segmentBody = Image("./assets/graphics/gui/message_twoline_white_body.tga")
|
||||
}
|
||||
else {
|
||||
segmentLeft = Image("./assets/graphics/gui/message_black_left.tga")
|
||||
segmentRight = Image("./assets/graphics/gui/message_black_right.tga")
|
||||
segmentBody = Image("./assets/graphics/gui/message_black_body.tga") // keep width=2 or greater; no width 1 !!
|
||||
}
|
||||
uiFont = GameFontImpl()
|
||||
height = segmentLeft!!.height
|
||||
messageWindowRadius = segmentLeft!!.width
|
||||
messagesList = arrayOf("", "")
|
||||
}
|
||||
private val LRmargin = 0f // there's "base value" of 8 px for LR (width of segment tile)
|
||||
|
||||
|
||||
fun setMessage(messagesList: Array<String>) {
|
||||
this.messagesList = messagesList
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun update(delta: Float) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
blendNormal()
|
||||
drawSegments(g)
|
||||
|
||||
g.font = uiFont
|
||||
|
||||
for (i in 0..Math.min(messagesList.size, MESSAGES_DISPLAY) - 1) {
|
||||
g.color = fontCol
|
||||
g.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat())
|
||||
val textWidth = messagesList.map { TerrarumGDX.fontGame.getWidth(it) }.sorted()[1]
|
||||
|
||||
batch.color = Color.WHITE
|
||||
|
||||
batch.draw(segment.get(1, 0), segment.tileW.toFloat(), 0f, 2 * LRmargin + textWidth, segment.tileH.toFloat())
|
||||
batch.draw(segment.get(0, 0), 0f, 0f)
|
||||
batch.draw(segment.get(2, 0), 2 * LRmargin + textWidth, 0f)
|
||||
|
||||
messagesList.forEachIndexed { index, s ->
|
||||
TerrarumGDX.fontGame.draw(batch, s, segment.tileW + LRmargin, (segment.tileH - TerrarumGDX.fontGame.lineHeight) / 2f)
|
||||
}
|
||||
|
||||
blendNormal()
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
private fun drawSegments(g: Graphics) {
|
||||
g.drawImage(segmentLeft, 0f, 0f)
|
||||
val scaledSegCentre = segmentBody!!.getScaledCopy(
|
||||
width - (segmentRight!!.width + segmentLeft!!.width), segmentLeft!!.height)
|
||||
g.drawImage(scaledSegCentre, segmentLeft!!.width.toFloat(), 0f)
|
||||
g.drawImage(segmentRight, (width - segmentRight!!.width).toFloat(), 0f)
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
// private int messagesShowingIndex = 0;
|
||||
val MESSAGES_DISPLAY = 2
|
||||
val OPEN_CLOSE_TIME = 160
|
||||
val OPEN_CLOSE_TIME = 0.16f
|
||||
|
||||
|
||||
val SEGMENT_BLACK = TextureRegionPack("assets/graphics/gui/message_black.tga", 8, 56)
|
||||
val SEGMENT_WHITE = TextureRegionPack("assets/graphics/gui/message_white.tga", 8, 56)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
import org.newdawn.slick.SlickException
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-23.
|
||||
@@ -20,57 +17,54 @@ class Notification : UICanvas {
|
||||
|
||||
override var height: Int = msgUI.height
|
||||
private val visibleTime = Math.min(
|
||||
Terrarum.getConfigInt("notificationshowuptime"),
|
||||
TerrarumGDX.getConfigInt("notificationshowuptime"),
|
||||
SHOWUP_MAX
|
||||
)
|
||||
private var displayTimer = 0
|
||||
private var displayTimer = 0f
|
||||
|
||||
internal var message: Array<String> = Array(MessageWindow.MESSAGES_DISPLAY, { "" })
|
||||
|
||||
override var openCloseTime: Int = MessageWindow.OPEN_CLOSE_TIME
|
||||
override var openCloseTime: Second = MessageWindow.OPEN_CLOSE_TIME
|
||||
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
if (handler!!.isOpened)
|
||||
displayTimer += delta
|
||||
|
||||
if (displayTimer >= visibleTime) {
|
||||
handler!!.setAsClose()
|
||||
displayTimer = 0
|
||||
displayTimer = 0f
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
msgUI.render(gc, g)
|
||||
override fun render(batch: SpriteBatch) {
|
||||
msgUI.render(batch)
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
UICanvas.doOpeningFade(handler, openCloseTime)
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
UICanvas.doClosingFade(handler, openCloseTime)
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
UICanvas.endOpeningFade(handler)
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
UICanvas.endClosingFade(handler)
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
}
|
||||
|
||||
|
||||
fun sendNotification(message: Array<String>) {
|
||||
this.message = message
|
||||
msgUI.setMessage(this.message)
|
||||
handler!!.openCloseCounter = 0
|
||||
handler!!.openCloseCounter = 0f
|
||||
handler!!.opacity = 0f
|
||||
handler!!.setAsOpen()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
@@ -11,26 +9,26 @@ class NullUI : UICanvas {
|
||||
override var width: Int = 0
|
||||
override var height: Int = 0
|
||||
override var handler: UIHandler? = null
|
||||
override var openCloseTime: Int = 0
|
||||
override var openCloseTime = 0f
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import org.newdawn.slick.Graphics
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-07-06.
|
||||
*/
|
||||
object Typography {
|
||||
fun printCentered(g: Graphics, string: String, screenPosY: Int, ui: UICanvas? = null) {
|
||||
val stringW = g.font.getWidth(string)
|
||||
val targetW = if (ui == null) Terrarum.WIDTH else ui.width
|
||||
|
||||
g.drawString(string, targetW.minus(stringW).ushr(1).toFloat(), screenPosY.toFloat())
|
||||
}
|
||||
|
||||
fun printCentered(g: Graphics, string: String, posX: Int, posY: Int, frameWidth: Int) {
|
||||
val stringW = g.font.getWidth(string)
|
||||
|
||||
g.drawString(string, frameWidth.minus(stringW).ushr(1).toFloat() + posX, posY.toFloat())
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameactors.abs
|
||||
import net.torvald.terrarum.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer.normaliseToColour
|
||||
import org.newdawn.slick.*
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-10.
|
||||
@@ -14,23 +19,23 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas {
|
||||
override var width = 116
|
||||
override var height = 24
|
||||
override var handler: UIHandler? = null
|
||||
override var openCloseTime: Millisec = 0
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
private var ELuptimer = 9999 // to make the light turned off by default
|
||||
private val ELuptime = 4000
|
||||
private var ELuptimer = 10f // to make the light turned off by default
|
||||
private val ELuptime = 4f
|
||||
private var ELon = false
|
||||
|
||||
private var atlas = SpriteSheet(ModMgr.getPath("basegame", "gui/basic_meter_atlas.tga"), width, height)
|
||||
private var atlas = TextureRegionPack(ModMgr.getPath("basegame", "gui/basic_meter_atlas.tga"), width, height)
|
||||
|
||||
private var font = SpriteSheetFont(SpriteSheet(ModMgr.getPath("basegame", "fonts/7seg_small.tga"), 9, 12), ' ')
|
||||
private var font = Watch7SegSmall
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
if (ELon) {
|
||||
ELuptimer += delta
|
||||
}
|
||||
|
||||
if (mouseUp || gc.input.isKeyDown(Terrarum.getConfigInt("keyinteract"))) {
|
||||
ELuptimer = 0
|
||||
if (mouseUp || Gdx.input.isKeyPressed(TerrarumGDX.getConfigInt("keyinteract"))) {
|
||||
ELuptimer = 0f
|
||||
ELon = true
|
||||
}
|
||||
|
||||
@@ -39,13 +44,12 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private val temperature: Int
|
||||
get() = -2
|
||||
private val mailCount: Int
|
||||
get() = 0
|
||||
|
||||
private val lcdLitCol = Color(20,20,20)
|
||||
private val lcdLitCol = Color(0x141414_ff)
|
||||
|
||||
fun getTempStr(): String {
|
||||
val sb = StringBuilder()
|
||||
@@ -78,64 +82,60 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas {
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
atlas.startUse()
|
||||
|
||||
override fun render(batch: SpriteBatch) {
|
||||
// backplate
|
||||
g.drawImage(atlas.getSubImage(0, 0), 0f, 0f)
|
||||
batch.draw(atlas.get(0, 0), 0f, 0f)
|
||||
|
||||
// because what the fuck
|
||||
blendScreen()
|
||||
g.drawImage(atlas.getSubImage(0, 1), 0f, 0f, Color(12, 12, 12))
|
||||
// because what the fuck (rendered darker than what it supposed to be)
|
||||
/*blendScreen()
|
||||
batch.color = Color(0x0c0c0c_ff)
|
||||
batch.draw(atlas.get(0, 1), 0f, 0f)*/
|
||||
|
||||
// light overlay or EL
|
||||
if (ELon) {
|
||||
blendNormal()
|
||||
g.drawImage(atlas.getSubImage(0, 2), 0f, 0f)
|
||||
batch.draw(atlas.get(0, 2), 0f, 0f)
|
||||
}
|
||||
else {
|
||||
var lightLevel = Color.black
|
||||
val lightLevel: Color
|
||||
|
||||
if (player != null) {
|
||||
val playerPos = player.tilewiseHitbox
|
||||
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
|
||||
Terrarum.ingame!!.world.globalLight
|
||||
).normaliseToColour()
|
||||
TerrarumGDX.ingame!!.world.globalLight
|
||||
).normaliseToColour()
|
||||
}
|
||||
else {
|
||||
lightLevel = Terrarum.ingame!!.world.globalLight.normaliseToColour()
|
||||
lightLevel = TerrarumGDX.ingame!!.world.globalLight.normaliseToColour()
|
||||
}
|
||||
blendMul()
|
||||
g.drawImage(atlas.getSubImage(0, 1), 0f, 0f, lightLevel)
|
||||
batch.color = lightLevel
|
||||
batch.draw(atlas.get(0, 1), 0f, 0f)
|
||||
}
|
||||
|
||||
// LCD back
|
||||
blendNormal()
|
||||
g.drawImage(atlas.getSubImage(0, 3), 0f, 0f)
|
||||
|
||||
atlas.endUse()
|
||||
batch.draw(atlas.get(0, 3), 0f, 0f)
|
||||
|
||||
|
||||
// LCD contents
|
||||
g.color = lcdLitCol
|
||||
g.font = font
|
||||
g.drawString(getTempStr(), 21f, 5f)
|
||||
g.drawString(getMailStr(), 93f, 5f)
|
||||
batch.color = lcdLitCol
|
||||
font.draw(batch, getTempStr(), 21f, 5f)
|
||||
font.draw(batch, getMailStr(), 93f, 5f)
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.point.Point2d
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gamecontroller.mouseScreenX
|
||||
import net.torvald.terrarum.gamecontroller.mouseScreenY
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
@@ -28,56 +25,56 @@ interface UICanvas {
|
||||
*
|
||||
* Timer itself is implemented in the handler.
|
||||
*/
|
||||
var openCloseTime: Millisec
|
||||
var openCloseTime: Second
|
||||
|
||||
|
||||
val relativeMouseX: Int
|
||||
get() = (Terrarum.appgc.mouseScreenX - (handler?.posX ?: 0))
|
||||
get() = (TerrarumGDX.mouseScreenX - (handler?.posX ?: 0))
|
||||
val relativeMouseY: Int
|
||||
get() = (Terrarum.appgc.mouseScreenY - (handler?.posY ?: 0))
|
||||
get() = (TerrarumGDX.mouseScreenY - (handler?.posY ?: 0))
|
||||
|
||||
/** If mouse is hovering over it */
|
||||
val mouseUp: Boolean
|
||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||
/** If mouse is hovering over it and mouse is down */
|
||||
val mousePushed: Boolean
|
||||
get() = mouseUp && Terrarum.appgc.input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")!!)
|
||||
get() = mouseUp && Gdx.input.isButtonPressed(TerrarumGDX.getConfigInt("mouseprimary"))
|
||||
|
||||
|
||||
fun update(gc: GameContainer, delta: Int)
|
||||
fun update(delta: Float)
|
||||
|
||||
fun render(gc: GameContainer, g: Graphics)
|
||||
fun render(batch: SpriteBatch)
|
||||
|
||||
fun processInput(gc: GameContainer, delta: Int, input: Input)
|
||||
fun processInput(delta: Float)
|
||||
|
||||
/**
|
||||
* Do not modify handler!!.openCloseCounter here.
|
||||
*/
|
||||
fun doOpening(gc: GameContainer, delta: Int)
|
||||
fun doOpening(delta: Float)
|
||||
|
||||
/**
|
||||
* Do not modify handler!!.openCloseCounter here.
|
||||
*/
|
||||
fun doClosing(gc: GameContainer, delta: Int)
|
||||
fun doClosing(delta: Float)
|
||||
|
||||
/**
|
||||
* Do not modify handler!!.openCloseCounter here.
|
||||
*/
|
||||
fun endOpening(gc: GameContainer, delta: Int)
|
||||
fun endOpening(delta: Float)
|
||||
|
||||
/**
|
||||
* Do not modify handler!!.openCloseCounter here.
|
||||
*/
|
||||
fun endClosing(gc: GameContainer, delta: Int)
|
||||
fun endClosing(delta: Float)
|
||||
|
||||
companion object {
|
||||
const val OPENCLOSE_GENERIC = 200
|
||||
const val OPENCLOSE_GENERIC = 0.2f
|
||||
|
||||
fun doOpeningFade(handler: UIHandler?, openCloseTime: Int) {
|
||||
handler!!.opacity = handler.openCloseCounter.toFloat() / openCloseTime
|
||||
fun doOpeningFade(handler: UIHandler?, openCloseTime: Second) {
|
||||
handler!!.opacity = handler.openCloseCounter / openCloseTime
|
||||
}
|
||||
fun doClosingFade(handler: UIHandler?, openCloseTime: Int) {
|
||||
handler!!.opacity = (openCloseTime - handler.openCloseCounter.toFloat()) / openCloseTime
|
||||
fun doClosingFade(handler: UIHandler?, openCloseTime: Second) {
|
||||
handler!!.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime
|
||||
}
|
||||
fun endOpeningFade(handler: UIHandler?) {
|
||||
handler!!.opacity = 1f
|
||||
@@ -87,51 +84,51 @@ interface UICanvas {
|
||||
}
|
||||
|
||||
|
||||
fun doOpeningPopOut(handler: UIHandler?, openCloseTime: Int, position: Position) {
|
||||
fun doOpeningPopOut(handler: UIHandler?, openCloseTime: Second, position: Position) {
|
||||
when (position) {
|
||||
Position.LEFT -> handler!!.posX = Movement.fastPullOut(
|
||||
handler.openCloseCounter.toFloat() / openCloseTime,
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
-handler.UI.width.toFloat(),
|
||||
0f
|
||||
).roundInt()
|
||||
Position.TOP -> handler!!.posY = Movement.fastPullOut(
|
||||
handler.openCloseCounter.toFloat() / openCloseTime,
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
-handler.UI.height.toFloat(),
|
||||
0f
|
||||
).roundInt()
|
||||
Position.RIGHT -> handler!!.posX = Movement.fastPullOut(
|
||||
handler.openCloseCounter.toFloat() / openCloseTime,
|
||||
Terrarum.WIDTH.toFloat(),
|
||||
Terrarum.WIDTH - handler.UI.width.toFloat()
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
Gdx.graphics.width.toFloat(),
|
||||
Gdx.graphics.width - handler.UI.width.toFloat()
|
||||
).roundInt()
|
||||
Position.BOTTOM -> handler!!.posY = Movement.fastPullOut(
|
||||
handler.openCloseCounter.toFloat() / openCloseTime,
|
||||
Terrarum.HEIGHT.toFloat(),
|
||||
Terrarum.HEIGHT - handler.UI.height.toFloat()
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
Gdx.graphics.height.toFloat(),
|
||||
Gdx.graphics.height - handler.UI.height.toFloat()
|
||||
).roundInt()
|
||||
}
|
||||
}
|
||||
fun doClosingPopOut(handler: UIHandler?, openCloseTime: Int, position: Position) {
|
||||
fun doClosingPopOut(handler: UIHandler?, openCloseTime: Second, position: Position) {
|
||||
when (position) {
|
||||
Position.LEFT -> handler!!.posX = Movement.fastPullOut(
|
||||
handler.openCloseCounter.toFloat() / openCloseTime,
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
0f,
|
||||
-handler.UI.width.toFloat()
|
||||
).roundInt()
|
||||
Position.TOP -> handler!!.posY = Movement.fastPullOut(
|
||||
handler.openCloseCounter.toFloat() / openCloseTime,
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
0f,
|
||||
-handler.UI.height.toFloat()
|
||||
).roundInt()
|
||||
Position.RIGHT -> handler!!.posX = Movement.fastPullOut(
|
||||
handler.openCloseCounter.toFloat() / openCloseTime,
|
||||
Terrarum.WIDTH - handler.UI.width.toFloat(),
|
||||
Terrarum.WIDTH.toFloat()
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
Gdx.graphics.width - handler.UI.width.toFloat(),
|
||||
Gdx.graphics.width.toFloat()
|
||||
).roundInt()
|
||||
Position.BOTTOM -> handler!!.posY = Movement.fastPullOut(
|
||||
handler.openCloseCounter.toFloat() / openCloseTime,
|
||||
Terrarum.HEIGHT - handler.UI.height.toFloat(),
|
||||
Terrarum.HEIGHT.toFloat()
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
Gdx.graphics.height - handler.UI.height.toFloat(),
|
||||
Gdx.graphics.height.toFloat()
|
||||
).roundInt()
|
||||
}
|
||||
}
|
||||
@@ -139,16 +136,16 @@ interface UICanvas {
|
||||
when (position) {
|
||||
Position.LEFT -> handler!!.posX = 0
|
||||
Position.TOP -> handler!!.posY = 0
|
||||
Position.RIGHT -> handler!!.posX = Terrarum.WIDTH - handler.UI.width
|
||||
Position.BOTTOM -> handler!!.posY = Terrarum.HEIGHT - handler.UI.height
|
||||
Position.RIGHT -> handler!!.posX = Gdx.graphics.width - handler.UI.width
|
||||
Position.BOTTOM -> handler!!.posY = Gdx.graphics.height - handler.UI.height
|
||||
}
|
||||
}
|
||||
fun endClosingPopOut(handler: UIHandler?, position: Position) {
|
||||
when (position) {
|
||||
Position.LEFT -> handler!!.posX = -handler.UI.width
|
||||
Position.TOP -> handler!!.posY = -handler.UI.height
|
||||
Position.RIGHT -> handler!!.posX = Terrarum.WIDTH
|
||||
Position.BOTTOM -> handler!!.posY = Terrarum.HEIGHT
|
||||
Position.RIGHT -> handler!!.posX = Gdx.graphics.width
|
||||
Position.BOTTOM -> handler!!.posY = Gdx.graphics.height
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.math.Matrix4
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
|
||||
/**
|
||||
* UIHandler is a handler for UICanvas. It opens/closes the attached UI, moves the "window" (or "canvas")
|
||||
@@ -55,14 +55,14 @@ class UIHandler(val UI: UICanvas,
|
||||
var opacity = 1f
|
||||
var scale = 1f
|
||||
|
||||
var openCloseCounter: Int = 0
|
||||
var openCloseCounter = 0f
|
||||
|
||||
init {
|
||||
UI.handler = this
|
||||
}
|
||||
|
||||
|
||||
fun update(gc: GameContainer, delta: Int) {
|
||||
fun update(delta: Float) {
|
||||
// open/close UI by key pressed
|
||||
if (toggleKey != null) {
|
||||
if (KeyToggler.isOn(toggleKey)) {
|
||||
@@ -82,7 +82,7 @@ class UIHandler(val UI: UICanvas,
|
||||
|
||||
|
||||
if (isVisible || alwaysVisible) {
|
||||
UI.update(gc, delta)
|
||||
UI.update(delta)
|
||||
}
|
||||
|
||||
if (isOpening) {
|
||||
@@ -93,15 +93,15 @@ class UIHandler(val UI: UICanvas,
|
||||
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
|
||||
|
||||
if (openCloseCounter < UI.openCloseTime) {
|
||||
UI.doOpening(gc, delta)
|
||||
UI.doOpening(delta)
|
||||
// println("UIHandler.opening ${UI.javaClass.simpleName}")
|
||||
}
|
||||
else {
|
||||
UI.endOpening(gc, delta)
|
||||
UI.endOpening(delta)
|
||||
isOpening = false
|
||||
isClosing = false
|
||||
isOpened = true
|
||||
openCloseCounter = 0
|
||||
openCloseCounter = 0f
|
||||
}
|
||||
}
|
||||
else if (isClosing) {
|
||||
@@ -111,27 +111,30 @@ class UIHandler(val UI: UICanvas,
|
||||
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
|
||||
|
||||
if (openCloseCounter < UI.openCloseTime) {
|
||||
UI.doClosing(gc, delta)
|
||||
UI.doClosing(delta)
|
||||
// println("UIHandler.closing ${UI.javaClass.simpleName}")
|
||||
}
|
||||
else {
|
||||
UI.endClosing(gc, delta)
|
||||
UI.endClosing(delta)
|
||||
isClosing = false
|
||||
isOpening = false
|
||||
isOpened = false
|
||||
isVisible = false
|
||||
openCloseCounter = 0
|
||||
openCloseCounter = 0f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun render(gc: GameContainer, sbg: StateBasedGame, ingameGraphics: Graphics) {
|
||||
fun render(batch: SpriteBatch) {
|
||||
if (isVisible || alwaysVisible) {
|
||||
ingameGraphics.font = Terrarum.fontGame // default font. Re-assign in the UI to change
|
||||
|
||||
if (!customPositioning) ingameGraphics.translate(posX.toFloat(), posY.toFloat())
|
||||
UI.render(gc, ingameGraphics)
|
||||
ingameGraphics.flush()
|
||||
batch.projectionMatrix = Matrix4()
|
||||
|
||||
if (!customPositioning)
|
||||
TerrarumGDX.ingame?.camera?.position?.set(posX.toFloat(), posY.toFloat(), 0f) // does it work?
|
||||
|
||||
UI.render(batch)
|
||||
//ingameGraphics.flush()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,9 +203,9 @@ class UIHandler(val UI: UICanvas,
|
||||
}
|
||||
}
|
||||
|
||||
fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
fun processInput(delta: Float) {
|
||||
if (isVisible) {
|
||||
UI.processInput(gc, delta, input)
|
||||
UI.processInput(delta)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.Terrarum.joypadLabelNinA
|
||||
import net.torvald.terrarum.Terrarum.joypadLabelNinY
|
||||
import net.torvald.terrarum.TerrarumGDX.joypadLabelNinA
|
||||
import net.torvald.terrarum.TerrarumGDX.joypadLabelNinY
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.newdawn.slick.*
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -27,12 +30,12 @@ class UIInventory(
|
||||
// get() = (actor as Actor).actorValue
|
||||
|
||||
override var handler: UIHandler? = null
|
||||
override var openCloseTime: Int = 120
|
||||
override var openCloseTime: Second = 0.12f
|
||||
|
||||
val catButtonsToCatIdent = HashMap<String, String>()
|
||||
|
||||
val backgroundColour = Color(0x80242424.toInt())
|
||||
val defaultTextColour = Color(0xeaeaea)
|
||||
val backgroundColour = Color(0x242424_80)
|
||||
val defaultTextColour = Color(0xeaeaea_ff.toInt())
|
||||
|
||||
init {
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", GameItem.Category.WEAPON)
|
||||
@@ -54,7 +57,7 @@ class UIInventory(
|
||||
val itemStripGutterH = 8
|
||||
val itemInterColGutter = 8
|
||||
|
||||
val controlHelpHeight = Terrarum.fontGame.lineHeight
|
||||
val controlHelpHeight = TerrarumGDX.fontGame.lineHeight.toInt()
|
||||
|
||||
val catButtons = UIItemTextButtonList(
|
||||
this,
|
||||
@@ -77,12 +80,12 @@ class UIInventory(
|
||||
readFromLang = true,
|
||||
textAreaWidth = 100,
|
||||
defaultSelection = 0,
|
||||
iconSpriteSheet = SpriteSheet("./assets/graphics/gui/inventory/category.tga", 20, 20),
|
||||
iconSpriteSheet = TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20),
|
||||
iconSpriteSheetIndices = intArrayOf(9,6,7,1,0,2,3,4,5,8),
|
||||
iconCol = defaultTextColour,
|
||||
highlightBackCol = Color(0xb8b8b8),
|
||||
highlightBackBlendMode = BlendMode.MULTIPLY,
|
||||
backgroundCol = Color(0,0,0,0), // will use custom background colour!
|
||||
backgroundCol = Color(0), // will use custom background colour!
|
||||
backgroundBlendMode = BlendMode.NORMAL,
|
||||
kinematic = true,
|
||||
inactiveCol = defaultTextColour
|
||||
@@ -113,7 +116,7 @@ class UIInventory(
|
||||
|
||||
private val SP = "${0x3000.toChar()}${0x3000.toChar()}${0x3000.toChar()}"
|
||||
val listControlHelp: String
|
||||
get() = if (Terrarum.environment == RunningEnvironment.PC)
|
||||
get() = if (TerrarumGDX.environment == RunningEnvironment.PC)
|
||||
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" +
|
||||
"${0xe011.toChar()}..${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
|
||||
"${0xe034.toChar()} ${Lang["GAME_INVENTORY_DROP"]}"
|
||||
@@ -122,7 +125,7 @@ class UIInventory(
|
||||
"${0xe011.toChar()}${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
|
||||
"$joypadLabelNinA ${Lang["GAME_INVENTORY_DROP"]}"
|
||||
val listControlClose: String
|
||||
get() = if (Terrarum.environment == RunningEnvironment.PC)
|
||||
get() = if (TerrarumGDX.environment == RunningEnvironment.PC)
|
||||
"${0xe037.toChar()} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
else
|
||||
"${0xe069.toChar()} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
@@ -132,8 +135,8 @@ class UIInventory(
|
||||
private var encumbrancePerc = 0f
|
||||
private var isEncumbered = false
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
catButtons.update(gc, delta)
|
||||
override fun update(delta: Float) {
|
||||
catButtons.update(delta)
|
||||
|
||||
if (actor != null && inventory != null) {
|
||||
// monitor and check if category selection has been changed
|
||||
@@ -155,47 +158,46 @@ class UIInventory(
|
||||
|
||||
private val weightBarWidth = 60f
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
// background
|
||||
blendNormal()
|
||||
g.color = backgroundColour
|
||||
g.fillRect(0f, 0f, width.toFloat(), height.toFloat())
|
||||
batch.color = backgroundColour
|
||||
batch.fillRect(0f, 0f, width.toFloat(), height.toFloat())
|
||||
|
||||
|
||||
// cat bar background
|
||||
blendMul()
|
||||
g.color = Color(0xcccccc)
|
||||
g.fillRect(0f, 0f, catButtons.width.toFloat(), height.toFloat())
|
||||
batch.color = Color(0xcccccc)
|
||||
batch.fillRect(0f, 0f, catButtons.width.toFloat(), height.toFloat())
|
||||
|
||||
|
||||
catButtons.render(gc, g)
|
||||
catButtons.render(batch)
|
||||
|
||||
|
||||
items.forEach {
|
||||
it.render(gc, g)
|
||||
it.render(batch)
|
||||
}
|
||||
|
||||
// texts
|
||||
blendNormal()
|
||||
g.color = defaultTextColour
|
||||
batch.color = defaultTextColour
|
||||
// W - close
|
||||
g.drawString(listControlClose, 4f, height - controlHelpHeight.toFloat())
|
||||
TerrarumGDX.fontGame.draw(batch, listControlClose, 4f, height - controlHelpHeight.toFloat())
|
||||
// MouseL - Use ; 1.9 - Register ; T - Drop
|
||||
g.drawString(listControlHelp, catButtons.width + 4f, height - controlHelpHeight.toFloat())
|
||||
TerrarumGDX.fontGame.draw(batch, listControlHelp, catButtons.width + 4f, height - controlHelpHeight.toFloat())
|
||||
// encumbrance
|
||||
if (inventory != null) {
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
|
||||
g.drawString(
|
||||
TerrarumGDX.fontGame.draw(batch,
|
||||
encumbranceText,
|
||||
width - 9 - g.font.getWidth(encumbranceText) - weightBarWidth,
|
||||
width - 9 - TerrarumGDX.fontGame.getWidth(encumbranceText) - weightBarWidth,
|
||||
height - controlHelpHeight.toFloat()
|
||||
)
|
||||
|
||||
// encumbrance bar background
|
||||
blendMul()
|
||||
g.color = Color(0xa0a0a0)
|
||||
g.fillRect(
|
||||
batch.color = Color(0xa0a0a0)
|
||||
batch.fillRect(
|
||||
width - 3 - weightBarWidth,
|
||||
height - controlHelpHeight + 3f,
|
||||
weightBarWidth,
|
||||
@@ -203,8 +205,8 @@ class UIInventory(
|
||||
)
|
||||
// encumbrance bar
|
||||
blendNormal()
|
||||
g.color = if (isEncumbered) Color(0xccff0000.toInt()) else Color(0xcc00ff00.toInt())
|
||||
g.fillRect(
|
||||
batch.color = if (isEncumbered) Color(0xccff0000.toInt()) else Color(0xcc00ff00.toInt())
|
||||
batch.fillRect(
|
||||
width - 3 - weightBarWidth,
|
||||
height - controlHelpHeight + 3f,
|
||||
if (actor?.inventory?.capacityMode == CAPACITY_MODE_NO_ENCUMBER)
|
||||
@@ -293,23 +295,23 @@ class UIInventory(
|
||||
// Inputs //
|
||||
////////////
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
UICanvas.doOpeningPopOut(handler, openCloseTime, UICanvas.Companion.Position.LEFT)
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
UICanvas.doClosingPopOut(handler, openCloseTime, UICanvas.Companion.Position.LEFT)
|
||||
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
UICanvas.endOpeningPopOut(handler, UICanvas.Companion.Position.LEFT)
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
UICanvas.endClosingPopOut(handler, UICanvas.Companion.Position.LEFT)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gamecontroller.mouseScreenX
|
||||
import net.torvald.terrarum.gamecontroller.mouseScreenY
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
@@ -19,19 +17,19 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
||||
abstract val height: Int
|
||||
|
||||
protected val relativeMouseX: Int
|
||||
get() = (Terrarum.appgc.mouseScreenX - (parentUI.handler?.posX ?: 0) - this.posX)
|
||||
get() = (TerrarumGDX.mouseScreenX - (parentUI.handler?.posX ?: 0) - this.posX)
|
||||
protected val relativeMouseY: Int
|
||||
get() = (Terrarum.appgc.mouseScreenY - (parentUI.handler?.posY ?: 0) - this.posY)
|
||||
get() = (TerrarumGDX.mouseScreenY - (parentUI.handler?.posY ?: 0) - this.posY)
|
||||
|
||||
/** If mouse is hovering over it */
|
||||
open val mouseUp: Boolean
|
||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||
/** If mouse is hovering over it and mouse is down */
|
||||
open val mousePushed: Boolean
|
||||
get() = mouseUp && Terrarum.appgc.input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")!!)
|
||||
get() = mouseUp && Gdx.input.isButtonPressed(TerrarumGDX.getConfigInt("mouseprimary")!!)
|
||||
|
||||
abstract fun update(gc: GameContainer, delta: Int)
|
||||
abstract fun render(gc: GameContainer, g: Graphics)
|
||||
abstract fun update(delta: Float)
|
||||
abstract fun render(batch: SpriteBatch)
|
||||
|
||||
// keyboard controlled
|
||||
abstract fun keyPressed(key: Int, c: Char)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -16,14 +15,14 @@ class UIItemImageGallery(
|
||||
override var posY: Int,
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
val imageList: ArrayList<Image>,
|
||||
val imageList: ArrayList<Texture>,
|
||||
val column: Int = 1
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
fun column(i: Int) = i % column
|
||||
fun row(i: Int) = i / column
|
||||
|
||||
@@ -35,7 +34,7 @@ class UIItemImageGallery(
|
||||
}
|
||||
|
||||
imageList.forEachIndexed { i, image ->
|
||||
DrawUtil.drawCentered(g, image,
|
||||
DrawUtil.drawCentered(batch, image,
|
||||
imagePosY(i),
|
||||
width.toFloat().div(column).times(column(i).plus(1)).roundInt(),
|
||||
posX, posY
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.point.Point2d
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
|
||||
/**
|
||||
* Text button. Height of hitbox is extended (double lineHeight, or 40 px) for better clicking
|
||||
@@ -20,11 +18,11 @@ class UIItemTextButton(
|
||||
override var posY: Int,
|
||||
override val width: Int,
|
||||
val readFromLang: Boolean = false,
|
||||
val activeCol: Color = Color.white,
|
||||
val activeBackCol: Color = Color(0,0,0,0),
|
||||
val activeCol: Color = Color.WHITE,
|
||||
val activeBackCol: Color = Color(0),
|
||||
val activeBackBlendMode: String = BlendMode.NORMAL,
|
||||
val highlightCol: Color = Color(0x00f8ff),
|
||||
val highlightBackCol: Color = Color(0xb0b0b0),
|
||||
val highlightCol: Color = Color(0x00f8ff_ff),
|
||||
val highlightBackCol: Color = Color(0xb0b0b0_ff.toInt()),
|
||||
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
|
||||
val inactiveCol: Color = UIItemTextButton.defaultInactiveCol,
|
||||
val preGapX: Int = 0,
|
||||
@@ -32,9 +30,9 @@ class UIItemTextButton(
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
companion object {
|
||||
val font = Terrarum.fontGame
|
||||
val height = font.lineHeight * 2
|
||||
val defaultInactiveCol: Color = Color(0xc8c8c8)
|
||||
val font = TerrarumGDX.fontGame
|
||||
val height = font.lineHeight.toInt() * 2
|
||||
val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt())
|
||||
}
|
||||
|
||||
val label: String
|
||||
@@ -47,37 +45,41 @@ class UIItemTextButton(
|
||||
var mouseOver = false
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
private val glyphLayout = GlyphLayout()
|
||||
|
||||
override fun render(batch: SpriteBatch) {
|
||||
val textW = font.getWidth(label)
|
||||
|
||||
|
||||
if (highlighted) {
|
||||
BlendMode.resolve(highlightBackBlendMode)
|
||||
g.color = highlightBackCol
|
||||
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
batch.color = highlightBackCol
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
else if (mouseOver) {
|
||||
BlendMode.resolve(activeBackBlendMode)
|
||||
g.color = activeBackCol
|
||||
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
batch.color = activeBackCol
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
|
||||
blendNormal()
|
||||
|
||||
g.font = font
|
||||
mouseOver = mouseUp
|
||||
g.color = if (highlighted) highlightCol
|
||||
else if (mouseOver) activeCol
|
||||
else inactiveCol
|
||||
|
||||
g.drawString(
|
||||
label,
|
||||
posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2),
|
||||
posY.toFloat() + height / 4
|
||||
)
|
||||
batch.inUse {
|
||||
mouseOver = mouseUp
|
||||
batch.color = if (highlighted) highlightCol
|
||||
else if (mouseOver) activeCol
|
||||
else inactiveCol
|
||||
|
||||
font.draw(batch,
|
||||
label,
|
||||
posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2),
|
||||
posY.toFloat() + height / 4
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.SpriteSheet
|
||||
import net.torvald.terrarum.inUse
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
@@ -24,26 +24,26 @@ class UIItemTextButtonList(
|
||||
|
||||
// icons
|
||||
val textAreaWidth: Int,
|
||||
val iconSpriteSheet: SpriteSheet? = null,
|
||||
val iconSpriteSheet: TextureRegionPack? = null,
|
||||
val iconSpriteSheetIndices: IntArray? = null,
|
||||
val iconCol: Color = UIItemTextButton.defaultInactiveCol,
|
||||
|
||||
// copied directly from UIItemTextButton
|
||||
val activeCol: Color = Color(0xfff066),
|
||||
val activeBackCol: Color = Color(0, 0, 0, 0),
|
||||
val activeCol: Color = Color(0xfff066_ff.toInt()),
|
||||
val activeBackCol: Color = Color(0),
|
||||
val activeBackBlendMode: String = BlendMode.NORMAL,
|
||||
val highlightCol: Color = Color(0x00f8ff),
|
||||
val highlightBackCol: Color = Color(0xb0b0b0),
|
||||
val highlightCol: Color = Color(0x00f8ff_ff),
|
||||
val highlightBackCol: Color = Color(0xb0b0b0_ff.toInt()),
|
||||
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
|
||||
val inactiveCol: Color = Color(0xc0c0c0),
|
||||
val backgroundCol: Color = Color(0, 0, 0, 0),
|
||||
val backgroundCol: Color = Color(0),
|
||||
val backgroundBlendMode: String = BlendMode.NORMAL,
|
||||
val kinematic: Boolean = false
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
val iconToTextGap = 20
|
||||
val iconCellWidth = (iconSpriteSheet?.width ?: -iconToTextGap) / (iconSpriteSheet?.horizontalCount ?: 1)
|
||||
val iconCellHeight = (iconSpriteSheet?.height ?: 0) / (iconSpriteSheet?.verticalCount ?: 1)
|
||||
val iconCellWidth = (iconSpriteSheet?.tileW ?: -iconToTextGap) / (iconSpriteSheet?.horizontalCount ?: 1)
|
||||
val iconCellHeight = (iconSpriteSheet?.tileH ?: 0) / (iconSpriteSheet?.verticalCount ?: 1)
|
||||
|
||||
// zero if iconSpriteSheet is null
|
||||
val iconsWithGap: Int = iconToTextGap + iconCellWidth
|
||||
@@ -97,14 +97,14 @@ class UIItemTextButtonList(
|
||||
val selectedButton: UIItemTextButton
|
||||
get() = buttons[selectedIndex]
|
||||
private var highlightY = buttons[selectedIndex].posY.toDouble()
|
||||
private val highlighterMoveDuration: Millisec = 100
|
||||
private var highlighterMoveTimer: Millisec = 0
|
||||
private val highlighterMoveDuration: Second = 0.1f
|
||||
private var highlighterMoveTimer: Second = 0f
|
||||
private var highlighterMoving = false
|
||||
private var highlighterYStart = highlightY
|
||||
private var highlighterYEnd = highlightY
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
if (highlighterMoving) {
|
||||
highlighterMoveTimer += delta
|
||||
highlightY = UIUtils.moveQuick(
|
||||
@@ -115,7 +115,7 @@ class UIItemTextButtonList(
|
||||
)
|
||||
|
||||
if (highlighterMoveTimer > highlighterMoveDuration) {
|
||||
highlighterMoveTimer = 0
|
||||
highlighterMoveTimer = 0f
|
||||
highlighterYStart = highlighterYEnd
|
||||
highlightY = highlighterYEnd
|
||||
highlighterMoving = false
|
||||
@@ -123,7 +123,7 @@ class UIItemTextButtonList(
|
||||
}
|
||||
|
||||
buttons.forEachIndexed { index, btn ->
|
||||
btn.update(gc, delta)
|
||||
btn.update(delta)
|
||||
|
||||
|
||||
if (btn.mousePushed && index != selectedIndex) {
|
||||
@@ -143,30 +143,30 @@ class UIItemTextButtonList(
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
g.color = backgroundCol
|
||||
override fun render(batch: SpriteBatch) {
|
||||
batch.color = backgroundCol
|
||||
BlendMode.resolve(backgroundBlendMode)
|
||||
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
|
||||
g.color = highlightBackCol
|
||||
batch.color = highlightBackCol
|
||||
BlendMode.resolve(highlightBackBlendMode)
|
||||
g.fillRect(posX.toFloat(), highlightY.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
|
||||
batch.fillRect(posX.toFloat(), highlightY.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
|
||||
|
||||
buttons.forEach { it.render(gc, g) }
|
||||
buttons.forEach { it.render(batch) }
|
||||
|
||||
if (iconSpriteSheet != null) {
|
||||
val iconY = (buttons[1].height - iconCellHeight) / 2
|
||||
iconSpriteSheetIndices!!.forEachIndexed { counter, imageIndex ->
|
||||
iconSpriteSheet.getSubImage(imageIndex, 0).draw(
|
||||
32f,
|
||||
buttons[counter].posY + iconY.toFloat(),
|
||||
iconCol
|
||||
)
|
||||
|
||||
batch.inUse {
|
||||
if (iconSpriteSheet != null) {
|
||||
val iconY = (buttons[1].height - iconCellHeight) / 2
|
||||
batch.color = iconCol
|
||||
|
||||
iconSpriteSheetIndices!!.forEachIndexed { counter, imageIndex ->
|
||||
batch.draw(iconSpriteSheet.get(imageIndex, 0), 32f, buttons[counter].posY + iconY.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
batch.color = backgroundCol
|
||||
}
|
||||
|
||||
g.color = backgroundCol
|
||||
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.ui.UIQuickBar.Companion.CELL_SIZE
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-07-20.
|
||||
@@ -30,21 +28,21 @@ class UIPieMenu : UICanvas {
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Millisec = 160
|
||||
override var openCloseTime: Second = 0.16f
|
||||
|
||||
private val smallenSize = 0.93f
|
||||
|
||||
var selection: Int = -1
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
if (Terrarum.ingame!!.player != null) {
|
||||
override fun update(delta: Float) {
|
||||
if (TerrarumGDX.ingame!!.player != null) {
|
||||
if (selection >= 0)
|
||||
Terrarum.ingame!!.player!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
|
||||
TerrarumGDX.ingame!!.player!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
|
||||
selection % slotCount
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
// draw radial thingies
|
||||
for (i in 0..slotCount - 1) {
|
||||
// set position
|
||||
@@ -52,51 +50,46 @@ class UIPieMenu : UICanvas {
|
||||
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(-angle)// + centrePoint
|
||||
|
||||
// draw cells
|
||||
val color = if (i == selection)
|
||||
ItemSlotImageBuilder.COLOR_WHITE
|
||||
else
|
||||
ItemSlotImageBuilder.COLOR_BLACK
|
||||
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(color, i + 1)
|
||||
ItemSlotImageBuilder.produceLarge(false, i + 1)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(color, i + 1)
|
||||
ItemSlotImageBuilder.produce(true, i + 1)
|
||||
|
||||
val slotSize = image.width
|
||||
|
||||
val slotX = slotCentrePoint.x.toFloat() - (slotSize / 2) + Terrarum.HALFW
|
||||
val slotY = slotCentrePoint.y.toFloat() - (slotSize / 2) + Terrarum.HALFH
|
||||
val slotX = slotCentrePoint.x.toFloat() - (slotSize / 2) + TerrarumGDX.HALFW
|
||||
val slotY = slotCentrePoint.y.toFloat() - (slotSize / 2) + TerrarumGDX.HALFH
|
||||
|
||||
g.drawImage(
|
||||
batch.color = Color(1f, 1f, 1f, handler!!.opacity * UIQuickBar.finalOpacity)
|
||||
batch.draw(
|
||||
image,
|
||||
slotX,
|
||||
slotY,
|
||||
Color(1f, 1f, 1f, handler!!.opacity * UIQuickBar.finalOpacity)
|
||||
slotY
|
||||
)
|
||||
|
||||
|
||||
// draw item
|
||||
val itemPair = Terrarum.ingame!!.player!!.inventory.getQuickBar(i)
|
||||
val itemPair = TerrarumGDX.ingame!!.player!!.inventory.getQuickBar(i)
|
||||
|
||||
if (itemPair != null) {
|
||||
val itemImage = ItemCodex.getItemImage(itemPair.item)
|
||||
val itemW = itemImage.width
|
||||
val itemH = itemImage.height
|
||||
val itemW = itemImage.regionWidth
|
||||
val itemH = itemImage.regionHeight
|
||||
|
||||
g.drawImage(
|
||||
batch.color = Color(1f, 1f, 1f, handler!!.opacity)
|
||||
batch.draw(
|
||||
itemImage, // using fixed CELL_SIZE for reasons
|
||||
slotX + (CELL_SIZE - itemW) / 2f,
|
||||
slotY + (CELL_SIZE - itemH) / 2f,
|
||||
Color(1f, 1f, 1f, handler!!.opacity)
|
||||
slotY + (CELL_SIZE - itemH) / 2f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
override fun processInput(delta: Float) {
|
||||
if (handler!!.isOpened || handler!!.isOpening) {
|
||||
val cursorPos = Vector2(input.mouseX.toDouble(), input.mouseY.toDouble())
|
||||
val centre = Vector2(Terrarum.HALFW.toDouble(), Terrarum.HALFH.toDouble())
|
||||
val cursorPos = Vector2(TerrarumGDX.mouseX, TerrarumGDX.mouseY)
|
||||
val centre = Vector2(TerrarumGDX.HALFW.toDouble(), TerrarumGDX.HALFH.toDouble())
|
||||
val deg = -(centre - cursorPos).direction.toFloat()
|
||||
|
||||
selection = Math.round(deg * slotCount / FastMath.TWO_PI)
|
||||
@@ -106,22 +99,22 @@ class UIPieMenu : UICanvas {
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
UICanvas.doOpeningFade(handler, openCloseTime)
|
||||
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
UICanvas.doClosingFade(handler, openCloseTime)
|
||||
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
UICanvas.endOpeningFade(handler)
|
||||
handler!!.scale = 1f
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
UICanvas.endClosingFade(handler)
|
||||
handler!!.scale = 1f
|
||||
}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-07-20.
|
||||
*/
|
||||
class UIQuickBar : UICanvas, MouseControlled {
|
||||
private val gutter = 8
|
||||
override var width: Int = (ItemSlotImageBuilder.slotImageSize + gutter) * SLOT_COUNT
|
||||
override var height: Int = ItemSlotImageBuilder.slotImageSize + 4 + Terrarum.fontGame.lineHeight
|
||||
override var width: Int = (ItemSlotImageBuilder.slotImage.width + gutter) * SLOT_COUNT
|
||||
override var height: Int = ItemSlotImageBuilder.slotImage.height + 4 + TerrarumGDX.fontGame.lineHeight.toInt()
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Millisec = 160
|
||||
override var openCloseTime: Second = 0.16f
|
||||
|
||||
private val startPointX = ItemSlotImageBuilder.slotLarge.width / 2
|
||||
private val startPointY = ItemSlotImageBuilder.slotLarge.height / 2
|
||||
@@ -28,71 +26,66 @@ class UIQuickBar : UICanvas, MouseControlled {
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
private var selection: Int
|
||||
get() = Terrarum.ingame!!.player?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { Terrarum.ingame!!.player?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
|
||||
get() = TerrarumGDX.ingame!!.player?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { TerrarumGDX.ingame!!.player?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun update(delta: Float) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
|
||||
override fun render(batch: SpriteBatch) {
|
||||
for (i in 0..SLOT_COUNT - 1) {
|
||||
val color = if (i == selection)
|
||||
ItemSlotImageBuilder.COLOR_WHITE
|
||||
else
|
||||
ItemSlotImageBuilder.COLOR_BLACK
|
||||
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(color, i + 1)
|
||||
ItemSlotImageBuilder.produceLarge(false, i + 1)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(color, i + 1)
|
||||
ItemSlotImageBuilder.produce(true, i + 1)
|
||||
|
||||
val slotX = startPointX + (CELL_SIZE + gutter).times(i).toFloat()
|
||||
val slotY = startPointY.toFloat()
|
||||
|
||||
// draw slots
|
||||
g.drawImage(
|
||||
batch.color = Color(1f, 1f, 1f, handler!!.opacity * finalOpacity)
|
||||
batch.draw(
|
||||
image,
|
||||
slotX,
|
||||
slotY,
|
||||
Color(1f, 1f, 1f, handler!!.opacity * finalOpacity)
|
||||
slotY
|
||||
)
|
||||
|
||||
// draw item
|
||||
val itemPair = Terrarum.ingame!!.player!!.inventory.getQuickBar(i)
|
||||
val itemPair = TerrarumGDX.ingame!!.player!!.inventory.getQuickBar(i)
|
||||
|
||||
if (itemPair != null) {
|
||||
val itemImage = ItemCodex.getItemImage(itemPair.item)
|
||||
val itemW = itemImage.width
|
||||
val itemH = itemImage.height
|
||||
val itemW = itemImage.regionWidth
|
||||
val itemH = itemImage.regionHeight
|
||||
|
||||
g.drawImage(
|
||||
batch.color = Color(1f, 1f, 1f, handler!!.opacity)
|
||||
batch.draw(
|
||||
itemImage, // using fixed CELL_SIZE for reasons
|
||||
slotX + (CELL_SIZE - itemW) / 2f,
|
||||
slotY + (CELL_SIZE - itemH) / 2f,
|
||||
Color(1f, 1f, 1f, handler!!.opacity)
|
||||
slotY + (CELL_SIZE - itemH) / 2f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
handler!!.opacity = 1f
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
handler!!.opacity = 0f
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.imagefont.Watch7SegMain
|
||||
import net.torvald.terrarum.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.imagefont.WatchDotAlph
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer.normaliseToColour
|
||||
import org.newdawn.slick.*
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-11.
|
||||
@@ -15,33 +22,33 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas {
|
||||
override var width = 85
|
||||
override var height = 52
|
||||
override var handler: UIHandler? = null
|
||||
override var openCloseTime: Millisec = 0
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
private var ELuptimer = 9999 // to make the light turned off by default
|
||||
private val ELuptime = 4000
|
||||
private var ELuptimer = 10f // to make the light turned off by default
|
||||
private val ELuptime = 4f
|
||||
private var ELon = false
|
||||
|
||||
private var atlas = SpriteSheet(ModMgr.getPath("basegame", "gui/watchface_atlas.tga"), width, height)
|
||||
private var atlas = TextureRegionPack(ModMgr.getPath("basegame", "gui/watchface_atlas.tga"), width, height)
|
||||
|
||||
private var littleFont = SpriteSheetFont(SpriteSheet(ModMgr.getPath("basegame", "fonts/7seg_small.tga"), 9, 12), ' ')
|
||||
private var timeFont = SpriteSheetFont(SpriteSheet(ModMgr.getPath("basegame", "fonts/7segnum.tga"), 11, 18), '/')
|
||||
private var textFont = SpriteSheetFont(SpriteSheet(ModMgr.getPath("basegame", "fonts/watch_dotalph.tga"), 12, 10), '@')
|
||||
private var moonDial = SpriteSheet(ModMgr.getPath("basegame", "fonts/watch_17pxmoondial.tga"), 17, 17)
|
||||
private var littleFont = Watch7SegSmall
|
||||
private var timeFont = Watch7SegMain
|
||||
private var textFont = WatchDotAlph
|
||||
private var moonDial = TextureRegionPack(ModMgr.getPath("basegame", "fonts/watch_17pxmoondial.tga"), 17, 17)
|
||||
private var moonDialCount = moonDial.horizontalCount
|
||||
|
||||
private val lcdLitCol = Color(20,20,20)
|
||||
private val lcdLitCol = Color(0x141414_ff)
|
||||
|
||||
private val worldTime: WorldTime
|
||||
get() = Terrarum.ingame!!.world.time
|
||||
get() = TerrarumGDX.ingame!!.world.time
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
if (ELon) {
|
||||
ELuptimer += delta
|
||||
}
|
||||
|
||||
if (mouseUp || gc.input.isKeyDown(Terrarum.getConfigInt("keyinteract"))) {
|
||||
ELuptimer = 0
|
||||
if (mouseUp || Gdx.input.isKeyPressed(TerrarumGDX.getConfigInt("keyinteract"))) {
|
||||
ELuptimer = 0f
|
||||
ELon = true
|
||||
}
|
||||
|
||||
@@ -50,80 +57,76 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
atlas.startUse()
|
||||
|
||||
override fun render(batch: SpriteBatch) {
|
||||
// backplate
|
||||
g.drawImage(atlas.getSubImage(0, 0), 0f, 0f)
|
||||
batch.draw(atlas.get(0, 0), 0f, 0f)
|
||||
|
||||
// because what the fuck
|
||||
blendScreen()
|
||||
g.drawImage(atlas.getSubImage(0, 1), 0f, 0f, Color(12, 12, 12))
|
||||
// because what the fuck (rendered darker than what it supposed to be)
|
||||
/*blendScreen()
|
||||
batch.color = Color(0x0c0c0c_ff)
|
||||
batch.draw(atlas.get(0, 1), 0f, 0f)*/
|
||||
|
||||
// light overlay or EL
|
||||
if (ELon) {
|
||||
blendNormal()
|
||||
g.drawImage(atlas.getSubImage(0, 2), 0f, 0f)
|
||||
batch.draw(atlas.get(0, 2), 0f, 0f)
|
||||
}
|
||||
else {
|
||||
var lightLevel = Color.black
|
||||
val lightLevel: Color
|
||||
|
||||
if (player != null) {
|
||||
val playerPos = player.tilewiseHitbox
|
||||
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
|
||||
Terrarum.ingame!!.world.globalLight
|
||||
TerrarumGDX.ingame!!.world.globalLight
|
||||
).normaliseToColour()
|
||||
}
|
||||
else {
|
||||
lightLevel = Terrarum.ingame!!.world.globalLight.normaliseToColour()
|
||||
lightLevel = TerrarumGDX.ingame!!.world.globalLight.normaliseToColour()
|
||||
}
|
||||
blendMul()
|
||||
g.drawImage(atlas.getSubImage(0, 1), 0f, 0f, lightLevel)
|
||||
batch.color = lightLevel
|
||||
batch.draw(atlas.get(0, 1), 0f, 0f)
|
||||
}
|
||||
|
||||
// LCD back
|
||||
blendNormal()
|
||||
g.drawImage(atlas.getSubImage(0, 3), 0f, 0f)
|
||||
|
||||
atlas.endUse()
|
||||
batch.draw(atlas.get(0, 3), 0f, 0f)
|
||||
|
||||
|
||||
|
||||
// day name
|
||||
g.color = lcdLitCol
|
||||
g.font = textFont
|
||||
g.drawString(worldTime.getDayNameShort().toUpperCase(), 7f, 7f)
|
||||
batch.color = lcdLitCol
|
||||
textFont.draw(batch, worldTime.getDayNameShort().toUpperCase(), 7f, 7f)
|
||||
|
||||
// month
|
||||
g.font = littleFont
|
||||
g.drawString(worldTime.months.toString().padStart(2, ' '), 40f, 6f)
|
||||
littleFont.draw(batch, worldTime.months.toString().padStart(2, ' '), 40f, 6f)
|
||||
// day
|
||||
g.drawString(worldTime.days.toString().padStart(2, ' '), 62f, 6f)
|
||||
littleFont.draw(batch, worldTime.days.toString().padStart(2, ' '), 62f, 6f)
|
||||
|
||||
// hour
|
||||
g.font = timeFont
|
||||
g.drawString(worldTime.hours.toString().padStart(2, '/'), 30f, 28f)
|
||||
timeFont.draw(batch, worldTime.hours.toString().padStart(2, '/'), 30f, 28f)
|
||||
// minute
|
||||
g.drawString(worldTime.minutes.toString().padStart(2, '0'), 58f, 28f)
|
||||
timeFont.draw(batch, worldTime.minutes.toString().padStart(2, '0'), 58f, 28f)
|
||||
|
||||
|
||||
// moon dial
|
||||
val moonPhase = (worldTime.moonPhase * moonDialCount).roundInt() % moonDialCount
|
||||
g.drawImage(moonDial.getSubImage(moonPhase, 0), 4f, 22f, lcdLitCol)
|
||||
batch.color = lcdLitCol
|
||||
batch.draw(moonDial.get(moonPhase, 0), 4f, 22f)
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.CIELabUtil.darkerLab
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
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.
|
||||
@@ -39,7 +38,7 @@ class UIVitalMetre(
|
||||
}
|
||||
field = value
|
||||
}
|
||||
override var openCloseTime: Int = 50
|
||||
override var openCloseTime: Second = 0.05f
|
||||
|
||||
//private val relativePX = width / 2f
|
||||
private val offsetY: Float; get() = (player?.baseHitboxH ?: 0) * 1.5f
|
||||
@@ -50,27 +49,28 @@ class UIVitalMetre(
|
||||
|
||||
private val backColor: Color
|
||||
get(): Color {
|
||||
val c = (color?.darkerLab(0.33f) ?: Color.black)
|
||||
val c = (color?.darkerLab(0.33f) ?: Color.BLACK)
|
||||
c.a = 0.7f
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
handler!!.setPosition(
|
||||
Terrarum.HALFW,
|
||||
Terrarum.HALFH
|
||||
TerrarumGDX.HALFW,
|
||||
TerrarumGDX.HALFH
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* g must be same as World Graphics!
|
||||
*/
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
if (vitalGetterVal() != null && vitalGetterMax() != null && player != null) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
// TODO now that we just can't draw arcs, we need to re-think about this
|
||||
|
||||
/*if (vitalGetterVal() != null && vitalGetterMax() != null && player != null) {
|
||||
g.translate(
|
||||
Terrarum.ingame!!.screenZoom * (player!!.centrePosPoint.x.toFloat() - (WorldCamera.x)),
|
||||
Terrarum.ingame!!.screenZoom * (player!!.centrePosPoint.y.toFloat() - (WorldCamera.y))
|
||||
TerrarumGDX.ingame!!.screenZoom * (player!!.centrePosPoint.x.toFloat() - (WorldCamera.x)),
|
||||
TerrarumGDX.ingame!!.screenZoom * (player!!.centrePosPoint.y.toFloat() - (WorldCamera.y))
|
||||
)
|
||||
|
||||
|
||||
@@ -103,25 +103,25 @@ class UIVitalMetre(
|
||||
|
||||
|
||||
g.flush()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
override fun doOpening(delta: Float) {
|
||||
UICanvas.doOpeningFade(handler, openCloseTime)
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
override fun doClosing(delta: Float) {
|
||||
UICanvas.doClosingFade(handler, openCloseTime)
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
UICanvas.endOpeningFade(handler)
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endClosing(delta: Float) {
|
||||
UICanvas.endClosingFade(handler)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user