com.torvald → net.torvald

Former-commit-id: 375604da8a20a6ba7cd0a8d05a44add02b2d04f4
Former-commit-id: 287287c5920b07618174d7a7573f049d350ded66
This commit is contained in:
Song Minjae
2016-04-12 12:29:02 +09:00
parent 2a34efb489
commit ac9f5b5138
148 changed files with 473 additions and 524 deletions

View File

@@ -0,0 +1,198 @@
package net.torvald.terrarum.ui
import net.torvald.terrarum.gamemap.PairedMapLayer
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.mapdrawer.LightmapRenderer
import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.mapdrawer.MapDrawer
import net.torvald.terrarum.Terrarum
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.Input
import java.util.*
/**
* Created by minjaesong on 16-03-14.
*/
class BasicDebugInfoWindow : UICanvas {
override var width: Int = Terrarum.WIDTH
override var height: Int = Terrarum.HEIGHT
override var openCloseTime: Int = 0
private var prevPlayerX = 0f
private var prevPlayerY = 0f
private var xdelta = 0f
private var ydelta = 0f
override fun processInput(input: Input) {
}
override fun update(gc: GameContainer, delta: Int) {
val player = Terrarum.game.player
val hitbox = player.hitbox!!
xdelta = hitbox.pointedX - prevPlayerX
ydelta = hitbox.pointedY - prevPlayerY
prevPlayerX = hitbox.pointedX
prevPlayerY = hitbox.pointedY
}
override fun render(gc: GameContainer, g: Graphics) {
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.game.player
val sb = StringBuilder()
val formatter = Formatter(sb)
val mouseTileX = ((MapCamera.cameraX + gc.getInput().mouseX / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt()
val mouseTileY = ((MapCamera.cameraY + gc.getInput().mouseY / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt()
g.color = Color.white
val hitbox = player.hitbox
val nextHitbox = player.nextHitbox
printLine(g, 1, "posX: "
+ "${hitbox!!.pointedX.toString()}"
+ " ("
+ "${(hitbox.pointedX / MapDrawer.TILE_SIZE).toInt().toString()}"
+ ")")
printLine(g, 2, "posY: "
+ hitbox.pointedY.toString()
+ " ("
+ (hitbox.pointedY / MapDrawer.TILE_SIZE).toInt().toString()
+ ")")
printLine(g, 3, "veloX reported: ${player.veloX}")
printLine(g, 4, "veloY reported: ${player.veloY}")
printLineColumn(g, 2, 3, "veloX measured: ${xdelta}")
printLineColumn(g, 2, 4, "veloY measured: ${ydelta}")
printLine(g, 5, "grounded : ${player.grounded}")
printLine(g, 6, "noClip : ${player.noClip}")
val lightVal: String
var mtX = mouseTileX.toString()
var mtY = mouseTileY.toString()
val valRaw = LightmapRenderer.getValueFromMap(mouseTileX, mouseTileY) ?: -1
val rawR = valRaw.rawR()
val rawG = valRaw.rawG()
val rawB = valRaw.rawB()
lightVal = if (valRaw == -1)
""
else
valRaw.toInt().toString() + " (" +
rawR.toString() + " " +
rawG.toString() + " " +
rawB.toString() + ")"
printLine(g, 7, "light at cursor : " + lightVal)
val tileNo: String
val tileNumRaw = Terrarum.game.map.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
val tilenum = tileNumRaw / PairedMapLayer.RANGE
val tiledmg = tileNumRaw % PairedMapLayer.RANGE
tileNo = if (tileNumRaw == -1) "" else "$tilenum:$tiledmg"
printLine(g, 8, "tile at cursor : $tileNo ($mtX, $mtY)")
/**
* Second column
*/
printLineColumn(g, 2, 1, "${Lang["MENU_OPTIONS_VSYNC"]} : " + Terrarum.appgc.isVSyncRequested)
printLineColumn(g, 2, 2, "Env colour temp : " + MapDrawer.getColTemp())
printLineColumn(g, 2, 5, "Time : ${Terrarum.game.map.worldTime.elapsedSeconds()}" +
" (${Terrarum.game.map.worldTime.getFormattedTime()})")
printLineColumn(g, 2, 6, "Mass : ${player.mass}")
/**
* On screen
*/
// Memory allocation
val memInUse = Terrarum.game.memInUse
val totalVMMem = Terrarum.game.totalVMMem
g.color = Color(0xFF7F00)
g.drawString(
Lang["DEV_MEMORY_SHORT_CAP"]
+ " : "
+ formatter.format(
Lang["DEV_MEMORY_A_OF_B"], memInUse, totalVMMem), (Terrarum.WIDTH - 200).toFloat(), line(1).toFloat())
// Hitbox
val zoom = Terrarum.game.screenZoom
g.color = Color(0x007f00)
g.drawRect(hitbox.hitboxStart.x * zoom - MapCamera.cameraX * zoom
, hitbox.hitboxStart.y * zoom - MapCamera.cameraY * zoom
, hitbox.width * zoom
, hitbox.height * zoom)
// ...and its point
g.fillRect(
(hitbox.pointedX - 1) * zoom - MapCamera.cameraX * zoom
, (hitbox.pointedY - 1) * zoom - MapCamera.cameraY * zoom
, 3f, 3f)
g.drawString(
Lang["DEV_COLOUR_LEGEND_GREEN"] + " : hitbox", (Terrarum.WIDTH - 200).toFloat()
, line(2).toFloat())
// Next hitbox
g.color = Color.blue
g.drawRect(nextHitbox!!.hitboxStart.x * zoom - MapCamera.cameraX * zoom
, nextHitbox.hitboxStart.y * zoom - MapCamera.cameraY * zoom
, nextHitbox.width * zoom
, nextHitbox.height * zoom)
// ...and its point
g.fillRect(
(nextHitbox.pointedX - 1) * zoom - MapCamera.cameraX * zoom
, (nextHitbox.pointedY - 1) * zoom - MapCamera.cameraY * zoom
, 3f, 3f)
g.drawString(
Lang["DEV_COLOUR_LEGEND_BLUE"] + " : nextHitbox", (Terrarum.WIDTH - 200).toFloat()
, line(3).toFloat())
}
private fun printLine(g: Graphics, l: Int, s: String) {
g.drawString(s, 20f, line(l).toFloat())
}
private fun printLineColumn(g: Graphics, col: Int, row: Int, s: String) {
g.drawString(s, (20 + column(col)).toFloat(), line(row).toFloat())
}
private fun line(i: Int): Int {
return i * 20
}
private fun column(i: Int): Int {
return 250 * (i - 1)
}
override fun doOpening(gc: GameContainer, delta: Int) {
}
override fun doClosing(gc: GameContainer, delta: Int) {
}
override fun endOpening(gc: GameContainer, delta: Int) {
}
override fun endClosing(gc: GameContainer, delta: Int) {
}
}

View File

@@ -0,0 +1,181 @@
package net.torvald.terrarum.ui
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.CommandInterpreter
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, UITypable {
internal var UIColour = Color(0xCC000000.toInt())
private var commandInputPool: StringBuilder? = null
private var prevCommand: String? = null
private var inputCursorPos: Int = 0
private val MESSAGES_MAX = 5000
private var messages = Array(MESSAGES_MAX, {""})
private var messageDisplayPos: Int = 0
private var messagesCount: Int = 0
private val LINE_HEIGHT = 20
private val MESSAGES_DISPLAY_COUNT = 9
override var width: Int = Terrarum.WIDTH
override var height: Int = 200
override var openCloseTime: Int = 0
private var drawOffX: Float = 0f
private var drawOffY: Float = -height.toFloat()
private var openingTimeCounter = 0
init {
reset()
}
override fun update(gc: GameContainer, delta: Int) {
}
override fun render(gc: GameContainer, g: Graphics) {
// background
g.color = UIColour
g.fillRect(drawOffX, drawOffY, width.toFloat(), height.toFloat())
g.fillRect(drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat())
val input = commandInputPool!!.toString()
val inputDrawWidth = g.font.getWidth(input)
val inputDrawHeight = g.font.lineHeight
// text and cursor
g.color = Color.white
g.drawString(input, 1f + drawOffX, drawOffY)
g.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight.toFloat())
// 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)
}
}
override fun keyPressed(key: Int, c: Char) {
// execute
if (key == Key.RET && commandInputPool!!.length > 0) {
prevCommand = commandInputPool!!.toString()
executeCommand()
commandInputPool = StringBuilder()
}
else if (key == Key.BKSP && commandInputPool!!.length > 0) {
commandInputPool!!.deleteCharAt(commandInputPool!!.length - 1)
}
else if (key >= 2 && key <= 13
|| key >= 16 && key <= 27
|| key >= 30 && key <= 40
|| key >= 44 && key <= 53
|| commandInputPool!!.length > 0 && key == 57) {
commandInputPool!!.append(c)
inputCursorPos += 1
}
else if (key == Key.UP) {
commandInputPool = StringBuilder()
commandInputPool!!.append(prevCommand)
}
else if (key == Key.PGUP) {
setDisplayPos(-MESSAGES_DISPLAY_COUNT + 1)
}
else if (key == Key.PGDN) {
setDisplayPos(MESSAGES_DISPLAY_COUNT - 1)
}// scroll down
// scroll up
// prev command
// get input
// backspace
}
override fun keyReleased(key: Int, c: Char) {
}
override fun processInput(input: Input) {
}
private fun executeCommand() {
sendMessage("> " + commandInputPool!!.toString())
CommandInterpreter.execute(commandInputPool!!.toString())
}
fun sendMessage(msg: String) {
messages[messagesCount] = msg
messagesCount += 1
if (messagesCount > MESSAGES_DISPLAY_COUNT) {
messageDisplayPos = messagesCount - MESSAGES_DISPLAY_COUNT
}
}
private fun setDisplayPos(change: Int) {
val lowLim = 0
val highLim = if (messagesCount <= MESSAGES_DISPLAY_COUNT)
0
else
messagesCount - MESSAGES_DISPLAY_COUNT
val newVal = messageDisplayPos + change
if (newVal < lowLim) {
messageDisplayPos = lowLim
}
else if (newVal > highLim) {
messageDisplayPos = highLim
}
else {
messageDisplayPos = newVal
}
}
fun reset() {
messages = Array(MESSAGES_MAX, {""})
messageDisplayPos = 0
messagesCount = 0
inputCursorPos = 0
prevCommand = ""
commandInputPool = StringBuilder()
if (Terrarum.game.auth.b()) sendMessage(Lang.get("DEV_MESSAGE_CONSOLE_CODEX"))
}
override fun doOpening(gc: GameContainer, delta: Int) {
/*openingTimeCounter += delta
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
-height.toFloat(), 0f
)*/
}
override fun doClosing(gc: GameContainer, delta: Int) {
/*openingTimeCounter += delta
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
0f, -height.toFloat()
)*/
}
override fun endOpening(gc: GameContainer, delta: Int) {
drawOffY = 0f
openingTimeCounter = 0
}
override fun endClosing(gc: GameContainer, delta: Int) {
drawOffY = -height.toFloat()
openingTimeCounter = 0
}
}

View File

@@ -0,0 +1,124 @@
package net.torvald.terrarum.ui
import net.torvald.imagefont.GameFontWhite
import com.jme3.math.FastMath
import net.torvald.terrarum.setBlendDisable
import net.torvald.terrarum.setBlendNormal
import org.lwjgl.opengl.GL11
import org.newdawn.slick.*
/**
* Created by minjaesong on 16-01-27.
*/
class MessageWindow @Throws(SlickException::class)
constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
private var segmentLeft: Image? = null
private var segmentRight: Image? = null
private var segmentBody: Image? = null
private lateinit var messagesList: Array<String>
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
override var openCloseTime: Int = OPEN_CLOSE_TIME
internal var opacity = 0f
internal var openCloseCounter = 0
private lateinit var uidrawCanvas: Image // render all the images and fonts here; will be faded
init {
if (!isBlackVariant) {
segmentLeft = Image("./res/graphics/gui/message_twoline_white_left.png");
segmentRight = Image("./res/graphics/gui/message_twoline_white_right.png");
segmentBody = Image("./res/graphics/gui/message_twoline_white_body.png");
}
else {
segmentLeft = Image("./res/graphics/gui/message_twoline_black_left.png")
segmentRight = Image("./res/graphics/gui/message_twoline_black_right.png")
segmentBody = Image("./res/graphics/gui/message_twoline_black_body.png")
}
uiFont = GameFontWhite()
height = segmentLeft!!.height
messageWindowRadius = segmentLeft!!.width
messagesList = arrayOf("", "")
uidrawCanvas = Image(FastMath.nearestPowerOfTwo(width), FastMath.nearestPowerOfTwo(height))
}
fun setMessage(messagesList: Array<String>) {
this.messagesList = messagesList
}
override fun update(gc: GameContainer, delta: Int) {
}
override fun render(gc: GameContainer, g: Graphics) {
val canvasG = uidrawCanvas.graphics
setBlendDisable()
drawSegments(canvasG)
canvasG.setDrawMode(Graphics.MODE_ALPHA_MAP)
drawSegments(canvasG)
canvasG.font = uiFont
canvasG.setDrawMode(Graphics.MODE_NORMAL)
for (i in 0..Math.min(messagesList.size, MESSAGES_DISPLAY) - 1) {
canvasG.color = fontCol
canvasG.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat())
}
setBlendNormal()
g.drawImage(uidrawCanvas, 0f, 0f, Color(1f,1f,1f,opacity))
canvasG.clear()
}
override fun processInput(input: Input) {
}
override fun doOpening(gc: GameContainer, delta: Int) {
openCloseCounter += delta
opacity = FastMath.interpolateLinear(openCloseCounter.toFloat() / openCloseTime.toFloat(),
0f, 1f
)
}
override fun doClosing(gc: GameContainer, delta: Int) {
openCloseCounter += delta
opacity = FastMath.interpolateLinear(openCloseCounter.toFloat() / openCloseTime.toFloat(),
1f, 0f
)
}
override fun endOpening(gc: GameContainer, delta: Int) {
opacity = 1f
openCloseCounter = 0
}
override fun endClosing(gc: GameContainer, delta: Int) {
opacity = 0f
openCloseCounter = 0
}
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)
}
companion object {
// private int messagesShowingIndex = 0;
val MESSAGES_DISPLAY = 2
val OPEN_CLOSE_TIME = 160
}
}

View File

@@ -0,0 +1,30 @@
package net.torvald.terrarum.ui
import com.jme3.math.FastMath
/**
* Created by minjaesong on 16-03-22.
*/
object MovementInterpolator {
/**
* Pretty fast at the beginning, getting slow over time.
*/
fun fastPullOut(scale: Float, start: Float = 0f, end: Float = 1f): Float =
if (scale < 0f) start
else if (scale > 1f) end
else (start - end) * FastMath.sqr(scale - 1) + end
/**
* Slow at the beginning, getting fast over time.
*/
fun dropDown(scale: Float, start: Float = 0f, end: Float = 1f): Float =
if (scale < 0f) start
else if (scale > 1f) end
else (end - start) * FastMath.sqr(scale) + start
fun sinusoid(scale: Float, start: Float = 0f, end: Float = 1f): Float =
if (scale < 0f) start
else if (scale > 1f) end
else (start - end) * FastMath.cos2(0.5f * FastMath.PI * scale) + end
}

View File

@@ -0,0 +1,87 @@
package net.torvald.terrarum.ui
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
/**
* Created by minjaesong on 16-01-23.
*/
class Notification @Throws(SlickException::class)
constructor() : UICanvas {
override var width: Int = 0
override var height: Int = 0
internal var visibleTime: Int
internal var showupTimeConuter = 0
internal var isShowing = false
internal var message: Array<String> = Array(MessageWindow.MESSAGES_DISPLAY, { i -> ""})
internal var msgUI: MessageWindow
override var openCloseTime: Int = MessageWindow.OPEN_CLOSE_TIME
private val SHOWUP_MAX = 15000
init {
width = 500
msgUI = MessageWindow(width, true)
height = msgUI.height
visibleTime = Math.min(
Terrarum.getConfigInt("notificationshowuptime"),
SHOWUP_MAX
)
}
override fun update(gc: GameContainer, delta: Int) {
if (showupTimeConuter >= visibleTime && isShowing) {
// invoke closing mode
doClosing(gc, delta)
// check if msgUI is fully fade out
if (msgUI.opacity <= 0.001f) {
endClosing(gc, delta)
isShowing = false
}
}
if (isShowing) {
showupTimeConuter += delta
}
}
override fun render(gc: GameContainer, g: Graphics) {
if (isShowing) {
msgUI.render(gc, g)
}
}
override fun doOpening(gc: GameContainer, delta: Int) {
msgUI.doOpening(gc, delta)
}
override fun doClosing(gc: GameContainer, delta: Int) {
msgUI.doClosing(gc, delta)
}
override fun endOpening(gc: GameContainer, delta: Int) {
msgUI.endOpening(gc, delta)
}
override fun endClosing(gc: GameContainer, delta: Int) {
msgUI.endClosing(gc, delta)
}
override fun processInput(input: Input) {
}
fun sendNotification(gc: GameContainer, delta: Int, message: Array<String>) {
isShowing = true
this.message = message
msgUI.setMessage(this.message)
showupTimeConuter = 0
}
}

View File

@@ -0,0 +1,32 @@
package net.torvald.terrarum.ui
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.Input
/**
* Created by minjaesong on 15-12-31.
*/
interface UICanvas {
var width: Int
var height: Int
/**
* In milliseconds
*/
var openCloseTime: Int
fun update(gc: GameContainer, delta: Int)
fun render(gc: GameContainer, g: Graphics)
fun processInput(input: Input)
fun doOpening(gc: GameContainer, delta: Int)
fun doClosing(gc: GameContainer, delta: Int)
fun endOpening(gc: GameContainer, delta: Int)
fun endClosing(gc: GameContainer, delta: Int)
}

View File

@@ -0,0 +1,21 @@
package net.torvald.terrarum.ui
/**
* Created by minjaesong on 16-03-06.
*/
interface UIClickable {
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int)
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int)
fun mousePressed(button: Int, x: Int, y: Int)
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

@@ -0,0 +1,238 @@
package net.torvald.terrarum.ui
import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.Terrarum
import com.jme3.math.FastMath
import org.newdawn.slick.*
/**
* Created by minjaesong on 15-12-31.
*/
class UIHandler
/**
* Construct new UIHandler with given UI attached.
* Invisible in default.
* @param UI
* *
* @throws SlickException
*/
@Throws(SlickException::class)
constructor(val UI: UICanvas) {
// X/Y Position to the game window.
var posX: Int = 0
private set
var posY: Int = 0
private set
private var alwaysVisible = false
private val UIGraphicInstance: Graphics
private val UIDrawnCanvas: Image
private var opening = false
private var closing = false
private var opened = false // fully opened
private var visible = false
var openCloseCounter = 0
init {
println("[UIHandler] Creating UI '${UI.javaClass.simpleName}'")
UIDrawnCanvas = Image(
FastMath.nearestPowerOfTwo(UI.width), FastMath.nearestPowerOfTwo(UI.height))
UIGraphicInstance = UIDrawnCanvas.graphics
}
fun update(gc: GameContainer, delta: Int) {
if (visible || alwaysVisible) {
UI.update(gc, delta)
}
if (opening) {
visible = true
openCloseCounter += delta
// println("UI ${UI.javaClass.simpleName} (open)")
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
if (openCloseCounter < UI.openCloseTime) {
UI.doOpening(gc, delta)
// println("UIHandler.opening ${UI.javaClass.simpleName}")
}
else {
UI.endOpening(gc, delta)
opening = false
opened = true
openCloseCounter = 0
}
}
else if (closing) {
openCloseCounter += delta
// println("UI ${UI.javaClass.simpleName} (close)")
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
if (openCloseCounter < UI.openCloseTime) {
UI.doClosing(gc, delta)
// println("UIHandler.closing ${UI.javaClass.simpleName}")
}
else {
UI.endClosing(gc, delta)
closing = false
opened = false
visible = false
openCloseCounter = 0
}
}
}
fun render(gc: GameContainer, gameGraphicInstance: Graphics) {
if (visible || alwaysVisible) {
UIGraphicInstance.clear()
UIGraphicInstance.font = Terrarum.gameFont
UI.render(gc, UIGraphicInstance)
gameGraphicInstance.drawImage(UIDrawnCanvas,
posX + MapCamera.cameraX * Terrarum.game.screenZoom,
posY + MapCamera.cameraY * Terrarum.game.screenZoom
)// compensate for screenZoom AND camera translation
// (see Game.render -> g.translate())
}
}
fun setPosition(x: Int, y: Int) {
posX = x
posY = y
}
fun setVisibility(b: Boolean) {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'set visibility of' constant UI")
}
visible = b
}
val isVisible: Boolean
get() {
if (alwaysVisible) {
return true
}
else {
return visible
}
}
fun setAsAlwaysVisible() {
alwaysVisible = true
visible = true
opened = true
opening = false
closing = false
}
fun setAsOpening() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'open' constant UI")
}
opened = false
opening = true
}
fun setAsClosing() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'close' constant UI")
}
opened = false
closing = true
}
fun toggleOpening() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'toggle opening of' constant UI")
}
if (visible) {
if (!closing) {
setAsClosing()
}
}
else {
if (!opening) {
setAsOpening()
}
}
}
fun processInput(input: Input) {
if (visible) {
UI.processInput(input)
}
}
fun keyPressed(key: Int, c: Char) {
if (visible && UI is UITypable) {
UI.keyPressed(key, c)
}
}
fun keyReleased(key: Int, c: Char) {
if (visible && UI is UITypable) {
UI.keyReleased(key, c)
}
}
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
if (visible && UI is UIClickable) {
UI.mouseMoved(oldx, oldy, newx, newy)
}
}
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
if (visible && UI is UIClickable) {
UI.mouseDragged(oldx, oldy, newx, newy)
}
}
fun mousePressed(button: Int, x: Int, y: Int) {
if (visible && UI is UIClickable) {
UI.mousePressed(button, x, y)
}
}
fun mouseReleased(button: Int, x: Int, y: Int) {
if (visible && UI is UIClickable) {
UI.mouseReleased(button, x, y)
}
}
fun mouseWheelMoved(change: Int) {
if (visible && UI is UIClickable) {
UI.mouseWheelMoved(change)
}
}
fun controllerButtonPressed(controller: Int, button: Int) {
if (visible && UI is UIClickable) {
UI.controllerButtonPressed(controller, button)
}
}
fun controllerButtonReleased(controller: Int, button: Int) {
if (visible && UI is UIClickable) {
UI.controllerButtonReleased(controller, button)
}
}
// constant UI can't take control
val isTakingControl: Boolean
get() {
if (alwaysVisible) {
return false
}
return visible && !opening
}
}

View File

@@ -0,0 +1,13 @@
package net.torvald.terrarum.ui
/**
* Created by minjaesong on 15-12-31.
*/
class UIItem {
// X/Y Position relative to the containing canvas
internal var posX: Int = 0
internal var posY: Int = 0
}

View File

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