mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
UI testing env and working text buttons
Former-commit-id: b8fd27c7f71f9bc8da259ae132badcbc9ce117ac
This commit is contained in:
@@ -44,7 +44,7 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
val player = Terrarum.ingame.player
|
||||
val player = Terrarum.ingame!!.player
|
||||
val hitbox = player.hitbox
|
||||
|
||||
xdelta = hitbox.pointedX - prevPlayerX
|
||||
@@ -59,10 +59,10 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
fun Int.rawG() = this % LightmapRenderer.MUL_2 / LightmapRenderer.MUL
|
||||
fun Int.rawB() = this % LightmapRenderer.MUL
|
||||
|
||||
val player = Terrarum.ingame.player
|
||||
val player = Terrarum.ingame!!.player
|
||||
|
||||
val mouseTileX = ((MapCamera.x + gc.input.mouseX / Terrarum.ingame.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((MapCamera.y + gc.input.mouseY / Terrarum.ingame.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileX = ((MapCamera.x + gc.input.mouseX / Terrarum.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((MapCamera.y + gc.input.mouseY / Terrarum.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
|
||||
g.font = Terrarum.fontSmallNumbers
|
||||
g.color = GameFontBase.codeToCol["y"]
|
||||
@@ -114,7 +114,7 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
printLine(g, 8, "light@cursor $ccG$lightVal")
|
||||
|
||||
val tileNo: String
|
||||
val tileNumRaw = Terrarum.ingame.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
|
||||
val tileNumRaw = Terrarum.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
|
||||
val tilenum = tileNumRaw / PairedMapLayer.RANGE
|
||||
val tiledmg = tileNumRaw % PairedMapLayer.RANGE
|
||||
tileNo = if (tileNumRaw == -1) "—" else "$tilenum:$tiledmg"
|
||||
@@ -127,8 +127,8 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
printLineColumn(g, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
|
||||
printLineColumn(g, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
|
||||
printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame.world.time.elapsedSeconds}" +
|
||||
" (${Terrarum.ingame.world.time.getFormattedTime()})")
|
||||
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}")
|
||||
@@ -171,13 +171,13 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
* Bottom left
|
||||
*/
|
||||
|
||||
g.drawString("${ccY}Actors total $ccG${Terrarum.ingame.actorContainer.size + Terrarum.ingame.actorContainerInactive.size}",
|
||||
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}",
|
||||
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}",
|
||||
g.drawString("${ccY}Dormant $ccG${Terrarum.ingame!!.actorContainerInactive.size}",
|
||||
(2 + 28*8).toFloat(), Terrarum.HEIGHT - 10f)
|
||||
g.drawString("${ccM}Particles $ccG${Terrarum.ingame.particlesActive}",
|
||||
g.drawString("${ccM}Particles $ccG${Terrarum.ingame!!.particlesActive}",
|
||||
(2 + 41*8).toFloat(), Terrarum.HEIGHT - 10f)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,15 @@ import java.util.*
|
||||
* Image gallery. Images will be equally spaced, counted from top-left to bottom-right.
|
||||
* Created by minjaesong on 16-08-08.
|
||||
*/
|
||||
class ItemImageGallery(
|
||||
class UIItemImageGallery(
|
||||
parentUI: UICanvas,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
val imageList: ArrayList<Image>,
|
||||
val column: Int = 1) : UIItem {
|
||||
val column: Int = 1
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
36
src/net/torvald/terrarum/ui/NullUI.kt
Normal file
36
src/net/torvald/terrarum/ui/NullUI.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
*/
|
||||
class NullUI : UICanvas {
|
||||
override var width: Int = 0
|
||||
override var height: Int = 0
|
||||
override var handler: UIHandler? = null
|
||||
override var openCloseTime: Int = 0
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
}
|
||||
|
||||
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) {
|
||||
}
|
||||
}
|
||||
@@ -12,24 +12,15 @@ import org.newdawn.slick.state.StateBasedGame
|
||||
* to the coordinate of displayed cartesian coords, and update and render the UI.
|
||||
* It also process game inputs and send control events to the UI so that the UI can handle them.
|
||||
*
|
||||
* Newly created UI is invisible by default.
|
||||
*
|
||||
* 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) {
|
||||
class UIHandler(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
|
||||
|
||||
@@ -61,10 +52,11 @@ constructor(val UI: UICanvas) {
|
||||
var openCloseCounter: Int = 0
|
||||
|
||||
init {
|
||||
UI.handler = this
|
||||
|
||||
println("[UIHandler] Creating framebuffer for UI '${UI.javaClass.simpleName}'")
|
||||
|
||||
UIDrawnCanvas = Image(UI.width, UI.height)
|
||||
|
||||
UIGraphicInstance = UIDrawnCanvas.graphics
|
||||
}
|
||||
|
||||
|
||||
63
src/net/torvald/terrarum/ui/UIInventory.kt
Normal file
63
src/net/torvald/terrarum/ui/UIInventory.kt
Normal file
@@ -0,0 +1,63 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
*/
|
||||
class UIInventory : UICanvas {
|
||||
override var width: Int
|
||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||
set(value) {}
|
||||
override var height: Int
|
||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||
set(value) {}
|
||||
override var handler: UIHandler?
|
||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||
set(value) {}
|
||||
override var openCloseTime: Int
|
||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||
set(value) {}
|
||||
|
||||
|
||||
private val categories = arrayOf(
|
||||
"GAME_INVENTORY_WEAPONS", // weapons and tools
|
||||
"CONTEXT_ITEM_EQUIPMENT_PLURAL",
|
||||
"CONTEXT_ITEM_ARMOR",
|
||||
"GAME_INVENTORY_INGREDIENTS",
|
||||
"GAME_INVENTORY_POTIONS",
|
||||
"GAME_INVENTORY_BLOCKS",
|
||||
"GAME_INVENTORY_WALLPAPERS",
|
||||
"MENU_LABEL_ALL"
|
||||
)
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,48 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gamecontroller.mouseX
|
||||
import net.torvald.terrarum.gamecontroller.mouseY
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
interface UIItem {
|
||||
abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UIHandler!
|
||||
|
||||
// X/Y Position relative to the containing canvas
|
||||
var posX: Int
|
||||
var posY: Int
|
||||
abstract var posX: Int
|
||||
abstract var posY: Int
|
||||
abstract val width: Int
|
||||
abstract val height: Int
|
||||
|
||||
fun update(gc: GameContainer, delta: Int)
|
||||
fun render(gc: GameContainer, g: Graphics)
|
||||
protected val relativeMouseX: Int
|
||||
get() = (Terrarum.appgc.mouseX - (parentUI.handler?.posX ?: 0) - this.posX).roundInt()
|
||||
protected val relativeMouseY: Int
|
||||
get() = (Terrarum.appgc.mouseY - (parentUI.handler?.posY ?: 0) - this.posY).roundInt()
|
||||
|
||||
val mouseUp: Boolean
|
||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||
val mousePushed: Boolean
|
||||
get() = mouseUp && Terrarum.appgc.input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")!!)
|
||||
|
||||
abstract fun update(gc: GameContainer, delta: Int)
|
||||
abstract fun render(gc: GameContainer, g: Graphics)
|
||||
|
||||
// keyboard controlled
|
||||
fun keyPressed(key: Int, c: Char)
|
||||
fun keyReleased(key: Int, c: Char)
|
||||
abstract fun keyPressed(key: Int, c: Char)
|
||||
abstract fun keyReleased(key: Int, c: Char)
|
||||
|
||||
// mouse controlled
|
||||
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)
|
||||
abstract fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int)
|
||||
abstract fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int)
|
||||
abstract fun mousePressed(button: Int, x: Int, y: Int)
|
||||
abstract fun mouseReleased(button: Int, x: Int, y: Int)
|
||||
abstract fun mouseWheelMoved(change: Int)
|
||||
|
||||
// gamepad controlled
|
||||
fun controllerButtonPressed(controller: Int, button: Int)
|
||||
fun controllerButtonReleased(controller: Int, button: Int)
|
||||
abstract fun controllerButtonPressed(controller: Int, button: Int)
|
||||
abstract fun controllerButtonReleased(controller: Int, button: Int)
|
||||
}
|
||||
|
||||
82
src/net/torvald/terrarum/ui/UIItemTextButton.kt
Normal file
82
src/net/torvald/terrarum/ui/UIItemTextButton.kt
Normal file
@@ -0,0 +1,82 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
|
||||
/**
|
||||
* Text button. Height of hitbox is extended (double lineHeight, or 40 px) for better clicking
|
||||
*
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
*/
|
||||
class UIItemTextButton(
|
||||
parentUI: UICanvas,
|
||||
val labelText: String,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
override val width: Int,
|
||||
val readFromLang: Boolean = false,
|
||||
val activeCol: Color = Color.white,
|
||||
val highlightCol: Color = Color(0x00f8ff),
|
||||
val inactiveCol: Color = Color(0xc0c0c0)
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
companion object {
|
||||
val font = Terrarum.fontGame!!
|
||||
val height = font.lineHeight * 2
|
||||
}
|
||||
|
||||
private val label: String
|
||||
get() = if (readFromLang) Lang[labelText] else labelText
|
||||
|
||||
|
||||
override val height: Int = UIItemTextButton.height
|
||||
|
||||
var highlighted: Boolean = false
|
||||
var mouseOver = false
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
val textW = font.getWidth(label)
|
||||
|
||||
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)), posY.toFloat() + height / 4)
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
}
|
||||
|
||||
override fun keyReleased(key: Int, c: Char) {
|
||||
}
|
||||
|
||||
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) {
|
||||
}
|
||||
|
||||
override fun controllerButtonPressed(controller: Int, button: Int) {
|
||||
}
|
||||
|
||||
override fun controllerButtonReleased(controller: Int, button: Int) {
|
||||
}
|
||||
}
|
||||
83
src/net/torvald/terrarum/ui/UIItemTextButtonList.kt
Normal file
83
src/net/torvald/terrarum/ui/UIItemTextButtonList.kt
Normal file
@@ -0,0 +1,83 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
*/
|
||||
class UIItemTextButtonList(
|
||||
parentUI: UICanvas,
|
||||
labelsList: Array<String>,
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
val readFromLang: Boolean = false
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
val buttons = labelsList.mapIndexed { index, s ->
|
||||
val height = this.height - UIItemTextButton.height
|
||||
UIItemTextButton(
|
||||
parentUI, s,
|
||||
0,
|
||||
(height / labelsList.size.minus(1).toFloat() * index).roundInt(),
|
||||
width,
|
||||
readFromLang = true
|
||||
)
|
||||
}
|
||||
|
||||
override var posX = 0
|
||||
override var posY = 0
|
||||
|
||||
var selected: Int? = labelsList.size - 1 // default to "All"
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
buttons.forEachIndexed { index, btn ->
|
||||
// update width because Lang is mutable (you can change language at any moment)
|
||||
val textW = UIItemTextButton.font.getWidth(
|
||||
if (readFromLang) Lang[btn.labelText] else btn.labelText
|
||||
)
|
||||
|
||||
btn.update(gc, delta)
|
||||
|
||||
|
||||
if (btn.mousePushed) {
|
||||
selected = index
|
||||
}
|
||||
btn.highlighted = (index == selected) // forcibly highlight if this.highlighted != null
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
buttons.forEach { it.render(gc, g) }
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
}
|
||||
|
||||
override fun keyReleased(key: Int, c: Char) {
|
||||
}
|
||||
|
||||
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) {
|
||||
}
|
||||
|
||||
override fun controllerButtonPressed(controller: Int, button: Int) {
|
||||
}
|
||||
|
||||
override fun controllerButtonReleased(controller: Int, button: Int) {
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class UIPieMenu : UICanvas {
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
if (selection >= 0)
|
||||
Terrarum.ingame.player.actorValue[AVKey.__PLAYER_QUICKBARSEL] =
|
||||
Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKBARSEL] =
|
||||
selection % slotCount
|
||||
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ class UIQuickBar : UICanvas, MouseControlled {
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
private var selection: Int
|
||||
get() = Terrarum.ingame.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKBARSEL) ?: 0
|
||||
set(value) { Terrarum.ingame.player.actorValue[AVKey.__PLAYER_QUICKBARSEL] = value }
|
||||
get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKBARSEL) ?: 0
|
||||
set(value) { Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKBARSEL] = value }
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.floorInt
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.times
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
|
||||
Reference in New Issue
Block a user