fixed a bug where colourmap won't interpolate properly. BUG: fadeout/fadein is somewhat glitched, UIQuickBar does not fade-in/out instead it just (dis)appears with no effect

Former-commit-id: 029f504b7e2e4d85676ec8b36b27dcbed5e5db47
Former-commit-id: 0b56ca1e8976bfc5e7ea8d665e6ed6496a52de85
This commit is contained in:
Song Minjae
2016-07-27 00:20:36 +09:00
parent 00dd5e99bb
commit ee647652d2
36 changed files with 368 additions and 223 deletions

View File

@@ -19,7 +19,7 @@ import java.util.*
/**
* Created by minjaesong on 16-03-14.
*/
class BasicDebugInfoWindow:UICanvas {
class BasicDebugInfoWindow : UICanvas {
override var width: Int = Terrarum.WIDTH
override var height: Int = Terrarum.HEIGHT
@@ -101,6 +101,8 @@ class BasicDebugInfoWindow:UICanvas {
printLine(g, 5, "grounded $ccG${player.grounded}")
printLine(g, 6, "noClip $ccG${player.noClip}")
printLine(g, 7, "jump $ccG${player.jumpAcc}")
val lightVal: String
val mtX = mouseTileX.toString()
val mtY = mouseTileY.toString()
@@ -114,7 +116,7 @@ class BasicDebugInfoWindow:UICanvas {
rawR.toString() + " " +
rawG.toString() + " " +
rawB.toString() + ")"
printLine(g, 7, "light@cursor $ccG$lightVal")
printLine(g, 8, "light@cursor $ccG$lightVal")
val tileNo: String
val tileNumRaw = Terrarum.ingame.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
@@ -122,18 +124,22 @@ class BasicDebugInfoWindow:UICanvas {
val tiledmg = tileNumRaw % PairedMapLayer.RANGE
tileNo = if (tileNumRaw == -1) "" else "$tilenum:$tiledmg"
printLine(g, 8, "tile@cursor $ccG$tileNo ($mtX, $mtY)")
printLine(g, 9, "tile@cursor $ccG$tileNo ($mtX, $mtY)")
/**
* Second column
*/
printLineColumn(g, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
printLineColumn(g, 2, 2, "Env colour temp $ccG" + MapDrawer.getColTemp())
printLineColumn(g, 2, 2, "Env colour temp $ccG" + MapDrawer.colTemp)
printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame.world.time.elapsedSeconds()}" +
" (${Terrarum.ingame.world.time.getFormattedTime()})")
printLineColumn(g, 2, 6, "Mass $ccG${player.mass}")
printLineColumn(g, 2, 7, "p_WalkX $ccG${player.walkX}")
printLineColumn(g, 2, 8, "p_WalkY $ccG${player.walkY}")
drawHistogram(g, LightmapRenderer.histogram,
Terrarum.WIDTH - histogramW - 30,
Terrarum.HEIGHT - histogramH - 30
@@ -220,7 +226,7 @@ class BasicDebugInfoWindow:UICanvas {
private fun line(i: Int): Float = i * 10f
private fun column(i: Int): Float = 250f * (i - 1)
private fun column(i: Int): Float = 300f * (i - 1)
override fun doOpening(gc: GameContainer, delta: Int) {

View File

@@ -13,7 +13,7 @@ import org.newdawn.slick.Input
/**
* Created by minjaesong on 15-12-31.
*/
class ConsoleWindow : UICanvas, UITypable {
class ConsoleWindow : UICanvas, KeyboardControlled {
internal var UIColour = Color(0xCC000000.toInt())

View File

@@ -0,0 +1,12 @@
package net.torvald.terrarum.ui
/**
* Button pressing only. If you want stick-controls, use processInput()
*
* Created by minjaesong on 16-07-21.
*/
interface GamepadControlled {
fun controllerButtonPressed(controller: Int, button: Int)
fun controllerButtonReleased(controller: Int, button: Int)
}

View File

@@ -23,10 +23,16 @@ object ItemSlotImageBuilder {
SpriteSheet("./res/graphics/fonts/numeric_small.png", 5, 8),
'0'
)
private val slotImage = Image("./res/graphics/gui/quickbar/item_slot.png")
val slotImage = Image("./res/graphics/gui/quickbar/item_slot.png") // must have same w/h as slotLarge
val slotLarge = Image("./res/graphics/gui/quickbar/item_slot_large.png")
private val canvas = Image(slotImage.width, slotImage.height)
private val canvasLarge = Image(slotLarge.width, slotLarge.height)
val slotImageSize = slotImage.width
fun produce(color: Int, number: Int = -1): Image {
canvas.graphics.clear()
if (color == COLOR_BLACK)
canvas.graphics.drawImage(slotImage, 0f, 0f, colourBlack)
else if (color == COLOR_WHITE)
@@ -41,12 +47,38 @@ object ItemSlotImageBuilder {
canvas.graphics.color = colourBlack
canvas.graphics.drawString(number.mod(UIQuickBar.SLOT_COUNT).toString(),
slotImage.width - 6f,
slotImage.height - 10f
slotImage.width - 10f,
slotImage.height - 13f
)
}
return canvas
}
fun produceLarge(color: Int, number: Int = -1): Image {
canvasLarge.graphics.clear()
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
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
)
}
return canvasLarge
}
}

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.ui
/**
* Created by minjaesong on 16-03-06.
*/
interface UITypable {
interface KeyboardControlled {
fun keyPressed(key: Int, c: Char)
fun keyReleased(key: Int, c: Char)

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.ui
/**
* Created by minjaesong on 16-03-06.
*/
interface UIClickable {
interface MouseControlled {
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int)
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int)
@@ -13,9 +13,4 @@ interface UIClickable {
fun mouseReleased(button: Int, x: Int, y: Int)
fun mouseWheelMoved(change: Int)
fun controllerButtonPressed(controller: Int, button: Int)
fun controllerButtonReleased(controller: Int, button: Int)
}

View File

@@ -11,14 +11,18 @@ interface UICanvas {
var width: Int
var height: Int
var handler: UIHandler?
/**
* In milliseconds
*/
var openCloseTime: Int
/**
* Usage: get() = handler!!.openCloseCounter
*/
var openCloseTimer: Int
var handler: UIHandler?
fun update(gc: GameContainer, delta: Int)
fun render(gc: GameContainer, g: Graphics)

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.Terrarum
import com.jme3.math.FastMath
import org.lwjgl.opengl.GL11
import org.newdawn.slick.*
import org.newdawn.slick.state.StateBasedGame
@@ -44,22 +45,25 @@ constructor(val UI: UICanvas) {
set(value) {
if (alwaysVisible)
throw RuntimeException("[UIHandler] Tried to 'set visibility of' constant UI")
field = value
if (value == true) {
isOpened = true
field = value
}
else {
isOpened = false
field = value
}
}
var opacity = 1f
var scale = 1f
var openCloseCounter = 0
var openCloseCounter: Int = 0
init {
println("[UIHandler] Creating UI '${UI.javaClass.simpleName}'")
UIDrawnCanvas = Image(
//FastMath.nearestPowerOfTwo(UI.width), FastMath.nearestPowerOfTwo(UI.height))
UI.width, UI.height)
UIDrawnCanvas.filter = Image.FILTER_LINEAR
UIDrawnCanvas = Image(UI.width, UI.height)
UIGraphicInstance = UIDrawnCanvas.graphics
}
@@ -84,6 +88,7 @@ constructor(val UI: UICanvas) {
else {
UI.endOpening(gc, delta)
isOpening = false
isClosing = false
isOpened = true
openCloseCounter = 0
}
@@ -101,6 +106,7 @@ constructor(val UI: UICanvas) {
else {
UI.endClosing(gc, delta)
isClosing = false
isOpening = false
isOpened = false
isVisible = false
openCloseCounter = 0
@@ -113,8 +119,6 @@ constructor(val UI: UICanvas) {
UIGraphicInstance.clear()
UIGraphicInstance.font = Terrarum.gameFont
UIGraphicInstance.setAntiAlias(true)
UI.render(gc, UIGraphicInstance)
if (sbg.currentStateID == Terrarum.SCENE_ID_GAME) {
ingameGraphics.drawImage(UIDrawnCanvas.getScaledCopy(scale),
@@ -151,39 +155,47 @@ constructor(val UI: UICanvas) {
/**
* Send OPEN signal to the attached UI.
*/
fun setAsOpening() {
fun setAsOpen() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'open' constant UI")
}
if (!isOpened && !isVisible) {
if (!isOpened && !isOpening) {
isOpened = false
isOpening = true
isClosing = false
isVisible = true
}
}
/**
* Send CLOSE signal to the attached UI.
*/
fun setAsClosing() {
fun setAsClose() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'close' constant UI")
}
isOpened = false
isClosing = true
if ((isOpening || isOpened) && !isClosing && isVisible) {
isOpened = false
isClosing = true
isOpening = false
}
}
val isClosed: Boolean
get() = !isOpened && !isClosing && !isOpening
fun toggleOpening() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'toggle opening of' constant UI")
}
if (isVisible) {
if (!isClosing) {
setAsClosing()
setAsClose()
}
}
else {
if (!isOpening) {
setAsOpening()
setAsOpen()
}
}
}
@@ -195,55 +207,55 @@ constructor(val UI: UICanvas) {
}
fun keyPressed(key: Int, c: Char) {
if (isVisible && UI is UITypable) {
if (isVisible && UI is KeyboardControlled) {
UI.keyPressed(key, c)
}
}
fun keyReleased(key: Int, c: Char) {
if (isVisible && UI is UITypable) {
if (isVisible && UI is KeyboardControlled) {
UI.keyReleased(key, c)
}
}
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
if (isVisible && UI is UIClickable) {
if (isVisible && UI is MouseControlled) {
UI.mouseMoved(oldx, oldy, newx, newy)
}
}
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
if (isVisible && UI is UIClickable) {
if (isVisible && UI is MouseControlled) {
UI.mouseDragged(oldx, oldy, newx, newy)
}
}
fun mousePressed(button: Int, x: Int, y: Int) {
if (isVisible && UI is UIClickable) {
if (isVisible && UI is MouseControlled) {
UI.mousePressed(button, x, y)
}
}
fun mouseReleased(button: Int, x: Int, y: Int) {
if (isVisible && UI is UIClickable) {
if (isVisible && UI is MouseControlled) {
UI.mouseReleased(button, x, y)
}
}
fun mouseWheelMoved(change: Int) {
if (isVisible && UI is UIClickable) {
if (isVisible && UI is MouseControlled) {
UI.mouseWheelMoved(change)
}
}
fun controllerButtonPressed(controller: Int, button: Int) {
if (isVisible && UI is UIClickable) {
if (isVisible && UI is GamepadControlled) {
UI.controllerButtonPressed(controller, button)
}
}
fun controllerButtonReleased(controller: Int, button: Int) {
if (isVisible && UI is UIClickable) {
if (isVisible && UI is GamepadControlled) {
UI.controllerButtonReleased(controller, button)
}
}

View File

@@ -13,29 +13,31 @@ import org.newdawn.slick.Input
* Created by minjaesong on 16-07-20.
*/
class UIPieMenu : UICanvas {
private val cellSize = 32
private val cellSize = UIQuickBar.CELL_SIZE
private val slotCount = UIQuickBar.SLOT_COUNT
private val roundRectRadius = 6
private val slotDistanceFromCentre = cellSize * 2.7
override var width: Int = cellSize * 7
override var height: Int = width
override var handler: UIHandler? = null
/**
* In milliseconds
*/
override var openCloseTime: Int = 160
override var openCloseTimer: Int = 0
override var handler: UIHandler? = null
get() = handler!!.openCloseCounter
private val smallenSize = 0.93f
var menuSelection: Int = -1
var selection: Int = -1
override fun update(gc: GameContainer, delta: Int) {
if (menuSelection >= 0)
if (selection >= 0)
Terrarum.ingame.player.actorValue[AVKey._PLAYER_QUICKBARSEL] =
menuSelection % quickbarSlots
selection % slotCount
}
override fun render(gc: GameContainer, g: Graphics) {
@@ -45,17 +47,19 @@ class UIPieMenu : UICanvas {
for (i in 0..slotCount - 1) {
// set position
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
val slotCentrePoint = Vector2(0.0, cellSize * 3.0).setDirection(angle) + centrePoint
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre.toDouble()).setDirection(angle) + centrePoint
// draw cells
g.color = if (menuSelection == i) Color(0xC0C0C0) else Color(0x404040)
g.drawImage(ItemSlotImageBuilder.produce(
if (menuSelection == i)
ItemSlotImageBuilder.COLOR_WHITE
val color = if (i == selection)
ItemSlotImageBuilder.COLOR_WHITE
else
ItemSlotImageBuilder.COLOR_BLACK
g.drawImage(
if (i == selection)
ItemSlotImageBuilder.produceLarge(color, i + 1)
else
ItemSlotImageBuilder.COLOR_BLACK,
i + 1
),
ItemSlotImageBuilder.produce(color, i + 1),
slotCentrePoint.x.toFloat() - (cellSize / 2f),
slotCentrePoint.y.toFloat() - (cellSize / 2f)
)
@@ -70,38 +74,29 @@ class UIPieMenu : UICanvas {
val centre = Vector2(Terrarum.WIDTH / 2.0, Terrarum.HEIGHT / 2.0)
val deg = (centre - cursorPos).direction.toFloat()
menuSelection = Math.round(deg * slotCount / FastMath.TWO_PI)
if (menuSelection < 0) menuSelection += 10
selection = Math.round(deg * slotCount / FastMath.TWO_PI)
if (selection < 0) selection += 10
// TODO add gamepad support
}
}
override fun doOpening(gc: GameContainer, delta: Int) {
if (openCloseTimer < openCloseTime) {
openCloseTimer += delta
handler!!.opacity = openCloseTimer.toFloat() / openCloseTime
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
handler!!.opacity = openCloseTimer.toFloat() / openCloseTime
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
override fun doClosing(gc: GameContainer, delta: Int) {
if (openCloseTimer < openCloseTime) {
openCloseTimer += delta
handler!!.isOpened = false
handler!!.opacity = (openCloseTime - openCloseTimer.toFloat()) / openCloseTime
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
handler!!.opacity = (openCloseTime - openCloseTimer.toFloat()) / openCloseTime
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
override fun endOpening(gc: GameContainer, delta: Int) {
openCloseTimer = 0
handler!!.opacity = 1f
handler!!.scale = 1f
}
override fun endClosing(gc: GameContainer, delta: Int) {
openCloseTimer = 0
handler!!.opacity = 0f
handler!!.scale = 1f
}

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.ui
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.Input
@@ -7,58 +9,87 @@ import org.newdawn.slick.Input
/**
* Created by minjaesong on 16-07-20.
*/
class UIQuickBar : UICanvas {
override var width: Int
get() = throw UnsupportedOperationException()
set(value) {
}
override var height: Int
get() = throw UnsupportedOperationException()
set(value) {
}
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.gameFont.lineHeight
/**
* In milliseconds
*/
override var openCloseTime: Int
get() = throw UnsupportedOperationException()
set(value) {
}
override var openCloseTimer: Int
get() = throw UnsupportedOperationException()
set(value) {
}
override var openCloseTime: Int = 160
override var openCloseTimer: Int = 0
private val startPointX = ItemSlotImageBuilder.slotLarge.width / 2
private val startPointY = ItemSlotImageBuilder.slotLarge.height / 2
override var handler: UIHandler? = null
private var selection: Int
get() = Terrarum.ingame.player.actorValue.getAsInt(AVKey._PLAYER_QUICKBARSEL)!!
set(value) { Terrarum.ingame.player.actorValue[AVKey._PLAYER_QUICKBARSEL] = value }
override fun update(gc: GameContainer, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun render(gc: GameContainer, g: Graphics) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
for (i in 0..SLOT_COUNT - 1) {
val color = if (i == selection)
ItemSlotImageBuilder.COLOR_WHITE
else
ItemSlotImageBuilder.COLOR_BLACK
// draw slots
g.drawImage(
if (i == selection)
ItemSlotImageBuilder.produceLarge(color, i + 1)
else
ItemSlotImageBuilder.produce(color, i + 1),
startPointX + (CELL_SIZE + gutter).times(i).toFloat(),
startPointY.toFloat()
)
// draw items
}
}
override fun processInput(input: Input) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun doOpening(gc: GameContainer, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
handler!!.opacity = openCloseTimer.toFloat() / openCloseTime
}
override fun doClosing(gc: GameContainer, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
handler!!.opacity = (openCloseTime - openCloseTimer.toFloat()) / openCloseTime
}
override fun endOpening(gc: GameContainer, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
handler!!.opacity = 1f
}
override fun endClosing(gc: GameContainer, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
handler!!.opacity = 0f
}
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
}
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
}
override fun mousePressed(button: Int, x: Int, y: Int) {
}
override fun mouseReleased(button: Int, x: Int, y: Int) {
}
override fun mouseWheelMoved(change: Int) {
selection = selection.plus(if (change > 1) 1 else if (change < -1) -1 else 0).mod(SLOT_COUNT)
if (selection < 0) selection += SLOT_COUNT
}
companion object {
const val SLOT_COUNT = 10
const val CELL_SIZE = 32
}
}