UI: sub-UIs work?

This commit is contained in:
minjaesong
2017-07-25 17:21:02 +09:00
parent 07ee987411
commit 33da9777ea
31 changed files with 390 additions and 283 deletions

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
@@ -27,7 +28,7 @@ class BasicDebugInfoWindow : UICanvas() {
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
val player = Terrarum.ingame!!.player
val hitbox = player.hitbox
@@ -38,7 +39,7 @@ class BasicDebugInfoWindow : UICanvas() {
prevPlayerY = hitbox.canonicalY
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
fun Int.rawR() = this / LightmapRenderer.MUL_2
fun Int.rawG() = this % LightmapRenderer.MUL_2 / LightmapRenderer.MUL
fun Int.rawB() = this % LightmapRenderer.MUL
@@ -87,16 +88,14 @@ class BasicDebugInfoWindow : UICanvas() {
printLineColumn(batch, 2, 3, "veloX measured $ccG${xdelta}")
printLineColumn(batch, 2, 4, "veloY measured $ccG${ydelta}")
if (player != null) {
printLineColumn(batch, 1, 7,
"walled " +
"${if (player.walledLeft) "$ccR" else "$ccG"}L" +
"${if (player.walledBottom) "$ccR" else "$ccG"}${0x1F.toChar()}" +
"${if (player.walledTop) "$ccR" else "$ccG"}${0x1E.toChar()}" +
"${if (player.walledRight) "$ccR" else "$ccG"}R" +
"${if (player.colliding) "$ccR" else "$ccG"}${0x08.toChar()}"
)
}
printLineColumn(batch, 1, 7,
"walled " +
"${if (player.walledLeft) "$ccR" else "$ccG"}L" +
"${if (player.walledBottom) "$ccR" else "$ccG"}${0x1F.toChar()}" +
"${if (player.walledTop) "$ccR" else "$ccG"}${0x1E.toChar()}" +
"${if (player.walledRight) "$ccR" else "$ccG"}R" +
"${if (player.colliding) "$ccR" else "$ccG"}${0x08.toChar()}"
)

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.dataclass.HistoryArray
@@ -46,10 +47,10 @@ class ConsoleWindow : UICanvas() {
reset()
}
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// background
batch.color = UIColour
batch.fillRect(drawOffX, drawOffY, width.toFloat(), height.toFloat())

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
@@ -30,10 +31,10 @@ class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas
this.messagesList = messagesList
}
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
blendNormal()
val textWidth = messagesList.map { Terrarum.fontGame.getWidth(it) }.sorted()[1]

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.Second
@@ -26,7 +27,7 @@ class Notification : UICanvas() {
override var openCloseTime: Second = MessageWindow.OPEN_CLOSE_TIME
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
if (handler.isOpened)
displayTimer += delta
@@ -36,24 +37,24 @@ class Notification : UICanvas() {
}
}
override fun render(batch: SpriteBatch) {
msgUI.render(batch)
override fun renderUI(batch: SpriteBatch, camera: Camera) {
msgUI.render(batch, camera)
}
override fun doOpening(delta: Float) {
UICanvas.doOpeningFade(handler, openCloseTime)
UICanvas.doOpeningFade(this, openCloseTime)
}
override fun doClosing(delta: Float) {
UICanvas.doClosingFade(handler, openCloseTime)
UICanvas.doClosingFade(this, openCloseTime)
}
override fun endOpening(delta: Float) {
UICanvas.endOpeningFade(handler)
UICanvas.endOpeningFade(this)
}
override fun endClosing(delta: Float) {
UICanvas.endClosingFade(handler)
UICanvas.endClosingFade(this)
}
fun sendNotification(message: Array<String>) {

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
/**
@@ -10,10 +11,10 @@ class NullUI : UICanvas() {
override var height: Int = 0
override var openCloseTime = 0f
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
}
override fun doOpening(delta: Float) {

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
@@ -28,7 +29,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
private var font = Watch7SegSmall
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
if (ELon) {
ELuptimer += delta
}
@@ -100,7 +101,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
return sb.toString()
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// light overlay or EL
if (ELon) {
blendNormal()

View File

@@ -1,6 +1,8 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.Second
@@ -12,20 +14,36 @@ import net.torvald.terrarum.gameactors.roundInt
*
* Created by minjaesong on 15-12-31.
*/
abstract class UICanvas {
abstract class UICanvas(
toggleKeyLiteral: Int? = null, toggleButtonLiteral: Int? = null,
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
customPositioning: Boolean = false, // mainly used by vital meter
doNotWarnConstant: Boolean = false
) {
abstract var width: Int
abstract var height: Int
inline var posX: Int
get() = handler.posX
set(value) { handler.posX = value }
inline var posY: Int
get() = handler.posY
set(value) { handler.posY = value }
/**
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
*/
open lateinit var handler: UIHandler
protected val handler = UIHandler(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant)
init {
}
/**
* In milliseconds
*
* Timer itself is implemented in the handler.
* Timer itself is implemented in the ui.handler.
*/
abstract var openCloseTime: Second
@@ -46,27 +64,41 @@ abstract class UICanvas {
get() = mouseUp && Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary"))
abstract fun update(delta: Float)
fun update(delta: Float) {
handler.update(this, delta)
}
fun render(batch: SpriteBatch, camera: Camera) {
handler.render(this, batch, camera)
}
abstract fun render(batch: SpriteBatch)
inline fun addSubUI(ui: UICanvas) {
handler.addSubUI(ui)
}
/** Override this for the actual update */
abstract fun updateUI(delta: Float)
/** Override this for the actual render */
abstract fun renderUI(batch: SpriteBatch, camera: Camera)
/**
* Do not modify handler.openCloseCounter here.
* Do not modify ui.handler.openCloseCounter here.
*/
abstract fun doOpening(delta: Float)
/**
* Do not modify handler.openCloseCounter here.
* Do not modify ui.handler.openCloseCounter here.
*/
abstract fun doClosing(delta: Float)
/**
* Do not modify handler.openCloseCounter here.
* Do not modify ui.handler.openCloseCounter here.
*/
abstract fun endOpening(delta: Float)
/**
* Do not modify handler.openCloseCounter here.
* Do not modify ui.handler.openCloseCounter here.
*/
abstract fun endClosing(delta: Float)
@@ -78,31 +110,37 @@ abstract class UICanvas {
open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
uiItems.forEach { it.mouseMoved(screenX, screenY) }
handler.subUIs.forEach { it.mouseMoved(screenX, screenY) }
return true
}
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
uiItems.forEach { it.touchDragged(screenX, screenY, pointer) }
handler.subUIs.forEach { it.touchDragged(screenX, screenY, pointer) }
return true
}
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
uiItems.forEach { it.touchDown(screenX, screenY, pointer, button) }
handler.subUIs.forEach { it.touchDown(screenX, screenY, pointer, button) }
return true
}
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
uiItems.forEach { it.touchUp(screenX, screenY, pointer, button) }
handler.subUIs.forEach { it.touchUp(screenX, screenY, pointer, button) }
return true
}
open fun scrolled(amount: Int): Boolean {
uiItems.forEach { it.scrolled(amount) }
handler.subUIs.forEach { it.scrolled(amount) }
return true
}
open fun keyDown(keycode: Int): Boolean {
uiItems.forEach { it.keyDown(keycode) }
handler.subUIs.forEach { it.keyDown(keycode) }
return true
}
open fun keyUp(keycode: Int): Boolean {
uiItems.forEach { it.keyUp(keycode) }
handler.subUIs.forEach { it.keyUp(keycode) }
return true
}
open fun keyTyped(character: Char): Boolean {
@@ -115,85 +153,138 @@ abstract class UICanvas {
this.height = height
}
// handler func aliases //
inline fun setPosition(x: Int, y: Int) {
handler.setPosition(x, y)
}
inline fun setAsAlwaysVisible() {
handler.setAsAlwaysVisible()
}
inline fun setAsOpen() {
handler.setAsOpen()
}
inline fun setAsClose() {
handler.setAsClose()
}
inline fun toggleOpening() {
handler.toggleOpening()
}
inline val isOpened: Boolean
get() = handler.isOpened
inline val isOpening: Boolean
get() = handler.isOpening
inline val isClosing: Boolean
get() = handler.isClosing
inline val isClosed: Boolean
get() = handler.isClosed
inline var opacity: Float
get() = handler.opacity
set(value) { handler.opacity = value }
inline var scale: Float
get() = handler.scale
set(value) { handler.scale = value }
inline val isTakingControl: Boolean
get() = handler.isTakingControl
inline var isVisible: Boolean
get() = handler.isVisible
set(value) { handler.isVisible = value }
// end of handler func aliases
companion object {
const val OPENCLOSE_GENERIC = 0.2f
fun doOpeningFade(handler: UIHandler, openCloseTime: Second) {
handler.opacity = handler.openCloseCounter / openCloseTime
fun doOpeningFade(ui: UICanvas, openCloseTime: Second) {
ui.handler.opacity = ui.handler.openCloseCounter / openCloseTime
}
fun doClosingFade(handler: UIHandler, openCloseTime: Second) {
handler.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime
fun doClosingFade(ui: UICanvas, openCloseTime: Second) {
ui.handler.opacity = (openCloseTime - ui.handler.openCloseCounter) / openCloseTime
}
fun endOpeningFade(handler: UIHandler) {
handler.opacity = 1f
fun endOpeningFade(ui: UICanvas) {
ui.handler.opacity = 1f
}
fun endClosingFade(handler: UIHandler) {
handler.opacity = 0f
fun endClosingFade(ui: UICanvas) {
ui.handler.opacity = 0f
}
fun doOpeningPopOut(handler: UIHandler, openCloseTime: Second, position: Position) {
fun doOpeningPopOut(ui: UICanvas, openCloseTime: Second, position: Position) {
when (position) {
Position.LEFT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
-handler.UI.width.toFloat(),
Position.LEFT -> ui.handler.posX = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
-ui.width.toFloat(),
0f
).roundInt()
Position.TOP -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
-handler.UI.height.toFloat(),
Position.TOP -> ui.handler.posY = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
-ui.height.toFloat(),
0f
).roundInt()
Position.RIGHT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Position.RIGHT -> ui.handler.posX = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH.toFloat(),
Terrarum.WIDTH - handler.UI.width.toFloat()
Terrarum.WIDTH - ui.width.toFloat()
).roundInt()
Position.BOTTOM -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Position.BOTTOM -> ui.handler.posY = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT.toFloat(),
Terrarum.HEIGHT - handler.UI.height.toFloat()
Terrarum.HEIGHT - ui.height.toFloat()
).roundInt()
}
}
fun doClosingPopOut(handler: UIHandler, openCloseTime: Second, position: Position) {
fun doClosingPopOut(ui: UICanvas, openCloseTime: Second, position: Position) {
when (position) {
Position.LEFT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Position.LEFT -> ui.handler.posX = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
0f,
-handler.UI.width.toFloat()
-ui.width.toFloat()
).roundInt()
Position.TOP -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Position.TOP -> ui.handler.posY = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
0f,
-handler.UI.height.toFloat()
-ui.height.toFloat()
).roundInt()
Position.RIGHT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH - handler.UI.width.toFloat(),
Position.RIGHT -> ui.handler.posX = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH - ui.width.toFloat(),
Terrarum.WIDTH.toFloat()
).roundInt()
Position.BOTTOM -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT - handler.UI.height.toFloat(),
Position.BOTTOM -> ui.handler.posY = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT - ui.height.toFloat(),
Terrarum.HEIGHT.toFloat()
).roundInt()
}
}
fun endOpeningPopOut(handler: UIHandler, position: Position) {
fun endOpeningPopOut(ui: UICanvas, position: Position) {
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.LEFT -> ui.handler.posX = 0
Position.TOP -> ui.handler.posY = 0
Position.RIGHT -> ui.handler.posX = Terrarum.WIDTH - ui.width
Position.BOTTOM -> ui.handler.posY = Terrarum.HEIGHT - ui.height
}
}
fun endClosingPopOut(handler: UIHandler, position: Position) {
fun endClosingPopOut(ui: UICanvas, 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.LEFT -> ui.handler.posX = -ui.width
Position.TOP -> ui.handler.posY = -ui.height
Position.RIGHT -> ui.handler.posX = Terrarum.WIDTH
Position.BOTTOM -> ui.handler.posY = Terrarum.HEIGHT
}
}

View File

@@ -17,7 +17,7 @@ import net.torvald.terrarum.round
*
* Created by minjaesong on 15-12-31.
*/
class UIHandler(var UI: UICanvas,
class UIHandler(//var UI: UICanvas,
var toggleKeyLiteral: Int? = null, var toggleButtonLiteral: Int? = null,
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
var customPositioning: Boolean = false, // mainly used by vital meter
@@ -61,7 +61,7 @@ class UIHandler(var UI: UICanvas,
var openCloseCounter = 0f
init {
UI.handler = this
//UI.handler = this
}
@@ -69,7 +69,23 @@ class UIHandler(var UI: UICanvas,
private val toggleButton: Int?; get() = toggleButtonLiteral // to support in-screen keybind changing
fun update(delta: Float) {
val subUIs = ArrayList<UICanvas>()
fun addSubUI(ui: UICanvas) {
if (subUIs.contains(ui))
throw IllegalArgumentException(
"Exact copy of the UI already exists: The instance of ${ui.javaClass.simpleName}"
)
subUIs.add(ui)
}
fun removeSubUI(ui: UICanvas) {
subUIs.remove(ui)
}
fun update(ui: UICanvas, delta: Float) {
// open/close UI by key pressed
if (toggleKey != null) {
if (KeyToggler.isOn(toggleKey!!)) {
@@ -89,7 +105,7 @@ class UIHandler(var UI: UICanvas,
if (isVisible || alwaysVisible) {
UI.update(delta)
ui.updateUI(delta)
}
if (isOpening) {
@@ -99,12 +115,12 @@ class UIHandler(var UI: UICanvas,
// println("UI ${UI.javaClass.simpleName} (open)")
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
if (openCloseCounter < UI.openCloseTime) {
UI.doOpening(delta)
if (openCloseCounter < ui.openCloseTime) {
ui.doOpening(delta)
// println("UIHandler.opening ${UI.javaClass.simpleName}")
}
else {
UI.endOpening(delta)
ui.endOpening(delta)
isOpening = false
isClosing = false
isOpened = true
@@ -117,12 +133,12 @@ class UIHandler(var UI: UICanvas,
// println("UI ${UI.javaClass.simpleName} (close)")
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
if (openCloseCounter < UI.openCloseTime) {
UI.doClosing(delta)
if (openCloseCounter < ui.openCloseTime) {
ui.doClosing(delta)
// println("UIHandler.closing ${UI.javaClass.simpleName}")
}
else {
UI.endClosing(delta)
ui.endClosing(delta)
isClosing = false
isOpening = false
isOpened = false
@@ -130,9 +146,13 @@ class UIHandler(var UI: UICanvas,
openCloseCounter = 0f
}
}
subUIs.forEach { it.update(delta) }
}
fun render(batch: SpriteBatch, camera: Camera) {
fun render(ui: UICanvas, batch: SpriteBatch, camera: Camera) {
if (isVisible || alwaysVisible) {
// camera SHOULD BE CENTERED to HALFX and HALFY (see StateInGame) //
@@ -149,9 +169,13 @@ class UIHandler(var UI: UICanvas,
}
batch.color = Color.WHITE
UI.render(batch)
ui.renderUI(batch, camera)
//ingameGraphics.flush()
}
subUIs.forEach { it.render(batch, camera) }
}
fun setPosition(x: Int, y: Int) {
@@ -219,68 +243,6 @@ class UIHandler(var UI: UICanvas,
}
}
fun keyDown(keycode: Int): Boolean {
if (isVisible) {
return UI.keyDown(keycode)
}
return false
}
fun keyUp(keycode: Int): Boolean {
if (isVisible) {
return UI.keyUp(keycode)
}
return false
}
fun keyTyped(char: Char): Boolean {
if (isVisible) {
return UI.keyTyped(char)
}
return false
}
fun mouseMoved(screenX: Int, screenY: Int) {
if (isVisible) {
UI.mouseMoved(screenX, screenY)
}
}
fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (isVisible) {
UI.touchDragged(screenX, screenY, pointer)
}
return false
}
fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (isVisible) {
UI.touchDown(screenX, screenY, pointer, button)
}
return false
}
fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (isVisible) {
UI.touchUp(screenX, screenY, pointer, button)
}
return false
}
fun scrolled(amount: Int): Boolean {
if (isVisible) {
UI.scrolled(amount)
}
return false
}
// constant UI can't take control
val isTakingControl: Boolean
get() {
@@ -290,10 +252,6 @@ class UIHandler(var UI: UICanvas,
return isVisible && !isOpening
}
fun dispose() {
UI.dispose()
}
fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
Ingame.setCameraPosition(batch, camera, newX, newY)
}

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
@@ -23,8 +24,13 @@ class UIInventory(
var actor: Pocketed?,
override var width: Int,
override var height: Int,
var categoryWidth: Int
) : UICanvas() {
var categoryWidth: Int,
toggleKeyLiteral: Int? = null, toggleButtonLiteral: Int? = null,
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
customPositioning: Boolean = false, // mainly used by vital meter
doNotWarnConstant: Boolean = false
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
val inventory: ActorInventory?
get() = actor?.inventory
@@ -189,10 +195,7 @@ class UIInventory(
}
override fun update(delta: Float) {
if (handler == null) {
throw Error("Handler for this UI is null, you douchebag.")
}
override fun updateUI(delta: Float) {
catButtons.update(delta)
@@ -223,7 +226,7 @@ class UIInventory(
private val weightBarWidth = 60f
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// background
blendNormal()
batch.color = backgroundColour
@@ -369,19 +372,19 @@ class UIInventory(
override fun doOpening(delta: Float) {
UICanvas.doOpeningPopOut(handler, openCloseTime, UICanvas.Companion.Position.LEFT)
UICanvas.doOpeningPopOut(this, openCloseTime, UICanvas.Companion.Position.LEFT)
}
override fun doClosing(delta: Float) {
UICanvas.doClosingPopOut(handler, openCloseTime, UICanvas.Companion.Position.LEFT)
UICanvas.doClosingPopOut(this, openCloseTime, UICanvas.Companion.Position.LEFT)
}
override fun endOpening(delta: Float) {
UICanvas.endOpeningPopOut(handler, UICanvas.Companion.Position.LEFT)
UICanvas.endOpeningPopOut(this, UICanvas.Companion.Position.LEFT)
}
override fun endClosing(delta: Float) {
UICanvas.endClosingPopOut(handler, UICanvas.Companion.Position.LEFT)
UICanvas.endClosingPopOut(this, UICanvas.Companion.Position.LEFT)
}
override fun keyDown(keycode: Int): Boolean {

View File

@@ -43,9 +43,9 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
abstract val height: Int
protected val relativeMouseX: Int
get() = (Terrarum.mouseScreenX - (parentUI.handler?.posX ?: 0) - this.posX)
get() = (Terrarum.mouseScreenX - (parentUI.posX) - this.posX)
protected val relativeMouseY: Int
get() = (Terrarum.mouseScreenY - (parentUI.handler?.posY ?: 0) - this.posY)
get() = (Terrarum.mouseScreenY - (parentUI.posY) - this.posY)
/** If mouse is hovering over it */
open val mouseUp: Boolean
@@ -122,8 +122,6 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
}
if (clickOnceListener != null && !clickOnceListenerFired && mouseUp) {
println("arstineotarsneio")
clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button)
actionDone = true
}

View File

@@ -173,6 +173,14 @@ class UIItemTextButtonList(
batch.color = backgroundCol
}
fun select(index: Int) {
selectedIndex = index
}
fun unselect() {
selectedIndex = null
}
override fun dispose() {
iconSpriteSheet?.dispose()
}

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
@@ -34,7 +35,7 @@ class UIPieMenu : UICanvas() {
var selection: Int = -1
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
if (selection >= 0)
Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount
@@ -53,7 +54,7 @@ class UIPieMenu : UICanvas() {
}
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// draw radial thingies
for (i in 0..slotCount - 1) {
// set position
@@ -98,22 +99,22 @@ class UIPieMenu : UICanvas() {
}
override fun doOpening(delta: Float) {
UICanvas.doOpeningFade(handler, openCloseTime)
UICanvas.doOpeningFade(this, openCloseTime)
handler.scale = smallenSize + (1f.minus(smallenSize) * handler.opacity)
}
override fun doClosing(delta: Float) {
UICanvas.doClosingFade(handler, openCloseTime)
UICanvas.doClosingFade(this, openCloseTime)
handler.scale = smallenSize + (1f.minus(smallenSize) * handler.opacity)
}
override fun endOpening(delta: Float) {
UICanvas.endOpeningFade(handler)
UICanvas.endOpeningFade(this)
handler.scale = 1f
}
override fun endClosing(delta: Float) {
UICanvas.endClosingFade(handler)
UICanvas.endClosingFade(this)
handler.scale = 1f
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
@@ -28,10 +29,10 @@ class UIQuickBar : UICanvas() {
get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { Terrarum.ingame!!.player.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
for (i in 0..SLOT_COUNT - 1) {
val image = if (i == selection)

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
@@ -40,7 +41,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
get() = Terrarum.ingame!!.world.time
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
if (ELon) {
ELuptimer += delta
}
@@ -55,7 +56,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
}
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// light overlay or EL
if (ELon) {
blendNormal()

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.gameactors.Second
@@ -29,7 +30,7 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
defaultSelection = 0
)
init {
@@ -38,16 +39,17 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
superMenu.handler.setAsOpen()
this.handler.setAsClose()
println("UITitleRemoConCredits srtaenirstneiotrsaeinoarst")
superMenu.setAsOpen()
this.setAsClose()
}
}
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
menubar.update(delta)
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
}

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
@@ -44,22 +45,37 @@ class UITitleRemoConRoot : UICanvas() {
//private val paneCredits = UIHandler()
private val remoConCredits = UIHandler(UITitleRemoConCredits(this))
private val remoConCredits = UITitleRemoConCredits(this)
init {
remoConCredits.setPosition(0, menubarOffY)
addSubUI(remoConCredits)
////////////////////////////
uiItems.add(menubar)
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_CREDITS")].clickOnceListener = { _, _, _ ->
remoConCredits.setAsOpen()
this.setAsClose()
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> System.exit(0) }
}
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
menubar.update(delta)
//println("UITitleRemoConRoot bro u even updatez")
}
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
}

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
@@ -46,7 +47,7 @@ class UIVitalMetre(
return c
}
override fun update(delta: Float) {
override fun updateUI(delta: Float) {
handler.setPosition(
Terrarum.HALFW,
Terrarum.HALFH
@@ -56,7 +57,7 @@ class UIVitalMetre(
/**
* g must be same as World Graphics!
*/
override fun render(batch: SpriteBatch) {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// TODO now that we just can't draw arcs, we need to re-think about this
/*if (vitalGetterVal() != null && vitalGetterMax() != null && player != null) {
@@ -99,19 +100,19 @@ class UIVitalMetre(
}
override fun doOpening(delta: Float) {
UICanvas.doOpeningFade(handler, openCloseTime)
UICanvas.doOpeningFade(this, openCloseTime)
}
override fun doClosing(delta: Float) {
UICanvas.doClosingFade(handler, openCloseTime)
UICanvas.doClosingFade(this, openCloseTime)
}
override fun endOpening(delta: Float) {
UICanvas.endOpeningFade(handler)
UICanvas.endOpeningFade(this)
}
override fun endClosing(delta: Float) {
UICanvas.endClosingFade(handler)
UICanvas.endClosingFade(this)
}
override fun dispose() {