UI: sub-UIs work?

This commit is contained in:
minjaesong
2017-07-25 17:21:02 +09:00
parent 2ddb2af0e4
commit 46b4dd7532
31 changed files with 390 additions and 283 deletions

View File

@@ -1,19 +1,25 @@
## Minimum requirements ## ## Minimum requirements ##
* Any CPU with 1.8 GHz in speed * Processor with 2.4 GHz speed
* GPU that supports OpenGL 2.0, is capable of 4K texture (8K for Chinese/Japanese language) * GPU that can support OpenGL 2.1, is capable of 4K texture
* 2 GB of RAM * 4 GB of RAM
* 2 GB of free disk space * 2 GB of free disk space
* Windows Vista/Mac OS X Lion or higher (Mac OS X Snow Leopard is incompatible with a shader the game uses)
* PC: Java 8, Up-to-date graphics driver
## Recommended requirements ## ## Recommended requirements ##
* Intel i5 with 2.4+ GHz in speed (or any CPU with 4 or more threads, 2.4+ GHz in speed) * Processor with 3.0 GHz speed, 4 threads available
* GPU that supports OpenGL 2.0, is capable of 8K texture * GPU that can support OpenGL 2.1, is capable of 4K texture
* 4 GB of RAM * 8 GB of RAM
* 5 GB of free disk space * 5 GB of free disk space
* Windows Vista/Mac OS X Lion or higher
* PC: Java 8, Up-to-date graphics driver
## Tested environment ## ## Tested environment ##
(to devs: please extend this list with your test results!) (to devs: please extend this list with your test results!)
* MacBookPro9,2 (MacBook Pro 13 inch mid-2012) * MacBookPro9,2 (MacBook Pro 13 inch mid-2012)
* Intel 6700K, nVidia GTX970, Windows 10

View File

@@ -1,4 +1,7 @@
#version 120 #version 120
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color; varying vec4 v_color;

View File

@@ -1,4 +1,7 @@
#version 120 #version 120
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color; varying vec4 v_color;

View File

@@ -1,4 +1,7 @@
#version 120 #version 100
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color; varying vec4 v_color;
@@ -11,18 +14,5 @@ void main(void) {
vec4 colorTex0 = texture2D(u_texture, v_texCoords); // lightmap (RGB) pre-mixed vec4 colorTex0 = texture2D(u_texture, v_texCoords); // lightmap (RGB) pre-mixed
vec4 colorTex1 = texture2D(tex1, v_texCoords); // lightmap (A) pre-mixed vec4 colorTex1 = texture2D(tex1, v_texCoords); // lightmap (A) pre-mixed
vec4 newColor = vec4(0.0, 0.0, 0.0, colorTex0.a); gl_FragColor = vec4(max(colorTex0.rgb, colorTex1.rgb), colorTex0.a);
if (colorTex0.r > colorTex1.r) newColor.r = colorTex0.r;
else newColor.r = colorTex1.r;
if (colorTex0.g > colorTex1.g) newColor.g = colorTex0.g;
else newColor.g = colorTex1.g;
if (colorTex0.b > colorTex1.b) newColor.b = colorTex0.b;
else newColor.b = colorTex1.b;
gl_FragColor = newColor;
} }

View File

@@ -57,7 +57,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE) val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE) val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX) val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
val uiContainer = ArrayList<UIHandler>() val uiContainer = ArrayList<UICanvas>()
private val actorsRenderBehind = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE) private val actorsRenderBehind = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
private val actorsRenderMiddle = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE) private val actorsRenderMiddle = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
@@ -111,26 +111,26 @@ class Ingame(val batch: SpriteBatch) : Screen {
lateinit var consoleHandler: UIHandler lateinit var consoleHandler: UICanvas
lateinit var debugWindow: UIHandler lateinit var debugWindow: UICanvas
lateinit var notifier: UIHandler lateinit var notifier: UICanvas
lateinit var uiPieMenu: UIHandler lateinit var uiPieMenu: UICanvas
lateinit var uiQuickBar: UIHandler lateinit var uiQuickBar: UICanvas
lateinit var uiInventoryPlayer: UIHandler lateinit var uiInventoryPlayer: UICanvas
lateinit var uiInventoryContainer: UIHandler lateinit var uiInventoryContainer: UICanvas
lateinit var uiVitalPrimary: UIHandler lateinit var uiVitalPrimary: UICanvas
lateinit var uiVitalSecondary: UIHandler lateinit var uiVitalSecondary: UICanvas
lateinit var uiVitalItem: UIHandler // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500. lateinit var uiVitalItem: UICanvas // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500.
lateinit var uiWatchBasic: UIHandler lateinit var uiWatchBasic: UICanvas
lateinit var uiWatchTierOne: UIHandler lateinit var uiWatchTierOne: UICanvas
// UI aliases // UI aliases
lateinit var uiAliases: ArrayList<UIHandler> lateinit var uiAliases: ArrayList<UICanvas>
private set private set
lateinit var uiAlasesPausing: ArrayList<UIHandler> lateinit var uiAlasesPausing: ArrayList<UICanvas>
private set private set
inline val paused: Boolean inline val paused: Boolean
@@ -296,66 +296,63 @@ class Ingame(val batch: SpriteBatch) : Screen {
// init console window // init console window
consoleHandler = UIHandler(ConsoleWindow()) consoleHandler = ConsoleWindow()
consoleHandler.setPosition(0, 0) consoleHandler.setPosition(0, 0)
// init debug window // init debug window
debugWindow = UIHandler(BasicDebugInfoWindow()) debugWindow = BasicDebugInfoWindow()
debugWindow.setPosition(0, 0) debugWindow.setPosition(0, 0)
// init notifier // init notifier
notifier = UIHandler(Notification()) notifier = Notification()
notifier.UI.handler = notifier
notifier.setPosition( notifier.setPosition(
(Terrarum.WIDTH - notifier.UI.width) / 2, Terrarum.HEIGHT - notifier.UI.height) (Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
// >- queue up game UIs that should pause the world -< // >- queue up game UIs that should pause the world -<
// inventory // inventory
uiInventoryPlayer = UIHandler( uiInventoryPlayer = UIInventory(player,
UIInventory(player, width = 900,
width = 900, height = Terrarum.HEIGHT - 160,
height = Terrarum.HEIGHT - 160, categoryWidth = 210,
categoryWidth = 210
),
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory") toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
) )
uiInventoryPlayer.setPosition( uiInventoryPlayer.setPosition(
-uiInventoryPlayer.UI.width, -uiInventoryPlayer.width,
70 70
) )
// >- lesser UIs -< // >- lesser UIs -<
// quick bar // quick bar
uiQuickBar = UIHandler(UIQuickBar()) uiQuickBar = UIQuickBar()
uiQuickBar.isVisible = true uiQuickBar.isVisible = true
uiQuickBar.setPosition(0, 0) uiQuickBar.setPosition(0, 0)
// pie menu // pie menu
uiPieMenu = UIHandler(UIPieMenu()) uiPieMenu = UIPieMenu()
uiPieMenu.setPosition(Terrarum.HALFW, Terrarum.HALFH) uiPieMenu.setPosition(Terrarum.HALFW, Terrarum.HALFH)
// vital metre // vital metre
// fill in getter functions by // fill in getter functions by
// (uiAliases[UI_QUICK_BAR]!!.UI as UIVitalMetre).vitalGetterMax = { some_function } // (uiAliases[UI_QUICK_BAR]!!.UI as UIVitalMetre).vitalGetterMax = { some_function }
//uiVitalPrimary = UIHandler(UIVitalMetre(player, { 80f }, { 100f }, Color.red, 2), customPositioning = true) //uiVitalPrimary = UIVitalMetre(player, { 80f }, { 100f }, Color.red, 2, customPositioning = true)
//uiVitalPrimary.setAsAlwaysVisible() //uiVitalPrimary.setAsAlwaysVisible()
//uiVitalSecondary = UIHandler(UIVitalMetre(player, { 73f }, { 100f }, Color(0x00dfff), 1), customPositioning = true) //uiVitalSecondary = UIVitalMetre(player, { 73f }, { 100f }, Color(0x00dfff), 1) customPositioning = true)
//uiVitalSecondary.setAsAlwaysVisible() //uiVitalSecondary.setAsAlwaysVisible()
//uiVitalItem = UIHandler(UIVitalMetre(player, { null }, { null }, Color(0xffcc00), 0), customPositioning = true) //uiVitalItem = UIVitalMetre(player, { null }, { null }, Color(0xffcc00), 0, customPositioning = true)
//uiVitalItem.setAsAlwaysVisible() //uiVitalItem.setAsAlwaysVisible()
// basic watch-style notification bar (temperature, new mail) // basic watch-style notification bar (temperature, new mail)
uiWatchBasic = UIHandler(UIBasicNotifier(player)) uiWatchBasic = UIBasicNotifier(player)
uiWatchBasic.setAsAlwaysVisible() uiWatchBasic.setAsAlwaysVisible()
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.UI.width, 0) uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
uiWatchTierOne = UIHandler(UITierOneWatch(player)) uiWatchTierOne = UITierOneWatch(player)
uiWatchTierOne.setAsAlwaysVisible() uiWatchTierOne.setAsAlwaysVisible()
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2) uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
// batch-process uiAliases // batch-process uiAliases
@@ -994,7 +991,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
/** Send message to notifier UI and toggle the UI as opened. */ /** Send message to notifier UI and toggle the UI as opened. */
fun sendNotification(msg: Array<String>) { fun sendNotification(msg: Array<String>) {
(notifier.UI as Notification).sendNotification(msg) (notifier as Notification).sendNotification(msg)
} }
fun wakeDormantActors() { fun wakeDormantActors() {
@@ -1249,11 +1246,11 @@ class Ingame(val batch: SpriteBatch) : Screen {
particlesContainer.add(particle) particlesContainer.add(particle)
} }
fun addUI(ui: UIHandler) { fun addUI(ui: UICanvas) {
// check for exact duplicates // check for exact duplicates
if (uiContainer.contains(ui)) { if (uiContainer.contains(ui)) {
throw IllegalArgumentException( throw IllegalArgumentException(
"Exact copy of the UI already exists: The instance of ${ui.UI.javaClass.simpleName}" "Exact copy of the UI already exists: The instance of ${ui.javaClass.simpleName}"
) )
} }
@@ -1382,21 +1379,20 @@ class Ingame(val batch: SpriteBatch) : Screen {
// resize UIs // resize UIs
notifier.setPosition( notifier.setPosition(
(Terrarum.WIDTH - notifier.UI.width) / 2, Terrarum.HEIGHT - notifier.UI.height) (Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
// inventory // inventory
uiInventoryPlayer.UI = uiInventoryPlayer =
UIInventory(player, UIInventory(player,
width = 840, width = 840,
height = Terrarum.HEIGHT - 160, height = Terrarum.HEIGHT - 160,
categoryWidth = 210 categoryWidth = 210
) )
uiInventoryPlayer.UI.handler = uiInventoryPlayer
// basic watch-style notification bar (temperature, new mail) // basic watch-style notification bar (temperature, new mail)
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.UI.width, 0) uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2) uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
} }
} }

View File

@@ -32,6 +32,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.lwjgl.input.Controllers import org.lwjgl.input.Controllers
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.lang.management.ManagementFactory
import java.util.* import java.util.*
/** /**
@@ -289,7 +290,7 @@ object Terrarum : Game() {
println("[Terrarum] os.arch = $systemArch") // debug info println("[Terrarum] os.arch = $systemArch") // debug info
if (is32BitJVM) { if (is32BitJVM) {
println("32 Bit JVM detected") System.err.println("[Terrarum] 32 Bit JVM detected")
} }
joypadLabelStart = when (getConfigString("joypadlabelstyle")) { joypadLabelStart = when (getConfigString("joypadlabelstyle")) {
@@ -325,9 +326,25 @@ object Terrarum : Game() {
val USE_VSYNC = getConfigBoolean("usevsync") val USE_VSYNC = getConfigBoolean("usevsync")
var VSYNC = USE_VSYNC var VSYNC = USE_VSYNC
val VSYNC_TRIGGER_THRESHOLD = 56 val VSYNC_TRIGGER_THRESHOLD = 56
val GL_VERSION: Int
get() = Gdx.graphics.glVersion.majorVersion * 100 +
Gdx.graphics.glVersion.minorVersion * 10 +
Gdx.graphics.glVersion.releaseVersion
val MINIMAL_GL_VERSION = 210
override fun create() { override fun create() {
println("[Terrarum] GL_VERSION = $GL_VERSION")
println("[Terrarum] GL info:\n${Gdx.graphics.glVersion.debugVersionString}") // debug info
if (GL_VERSION < MINIMAL_GL_VERSION) {
// TODO notify properly
throw Error("Graphics device not capable -- device's GL_VERSION: $GL_VERSION, required: $MINIMAL_GL_VERSION")
}
fullscreenQuad = Mesh( fullscreenQuad = Mesh(
true, 4, 6, true, 4, 6,
VertexAttribute.Position(), VertexAttribute.Position(),
@@ -409,16 +426,16 @@ object Terrarum : Game() {
// jump right into the ingame // jump right into the ingame
ingame = Ingame(batch) /*ingame = Ingame(batch)
ingame!!.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong()) ingame!!.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
ingame!!.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW ingame!!.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
LoadScreen.screenToLoad = ingame!! LoadScreen.screenToLoad = ingame!!
super.setScreen(LoadScreen) super.setScreen(LoadScreen)*/
// title screen // title screen
//super.setScreen(TitleScreen(batch)) super.setScreen(TitleScreen(batch))
} }
internal fun changeScreen(screen: Screen) { internal fun changeScreen(screen: Screen) {

View File

@@ -16,6 +16,7 @@ import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.serialise.ReadLayerData import net.torvald.terrarum.serialise.ReadLayerData
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIHandler import net.torvald.terrarum.ui.UIHandler
import net.torvald.terrarum.ui.UITitleRemoConRoot import net.torvald.terrarum.ui.UITitleRemoConRoot
import net.torvald.terrarum.weather.WeatherMixer import net.torvald.terrarum.weather.WeatherMixer
@@ -64,7 +65,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
val tileSize = FeaturesDrawer.TILE_SIZE.toFloat() val tileSize = FeaturesDrawer.TILE_SIZE.toFloat()
val catmullRomTension = -1f val catmullRomTension = 0f
// pan camera // pan camera
actor.moveRight(axisMax) actor.moveRight(axisMax)
@@ -80,16 +81,18 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
val p3 = (p1 + 2) fmod codomainSize val p3 = (p1 + 2) fmod codomainSize
val u: Float = 1f - (p2 - (x / (domainSize / codomainSize))) / (p2 - p1) val u: Float = 1f - (p2 - (x / (domainSize / codomainSize))) / (p2 - p1)
val targetYPos = FastMath.interpolateCatmullRom(u, catmullRomTension, cameraNodes[p0], cameraNodes[p1], cameraNodes[p2], cameraNodes[p3]) //val targetYPos = FastMath.interpolateCatmullRom(u, catmullRomTension, cameraNodes[p0], cameraNodes[p1], cameraNodes[p2], cameraNodes[p3])
val targetYPos = FastMath.interpolateLinear(u, cameraNodes[p1], cameraNodes[p2])
val yDiff = targetYPos - actor.hitbox.canonicalY val yDiff = targetYPos - actor.hitbox.canonicalY
if (!firstTime) { /*if (!firstTime) {
actor.moveDown(yDiff.bipolarClamp(axisMax.toDouble()).toFloat()) actor.moveDown(yDiff.bipolarClamp(axisMax.toDouble()).toFloat())
} }
else { else {
actor.hitbox.setPosition(actor.hitbox.canonicalX, targetYPos.toDouble()) actor.hitbox.setPosition(actor.hitbox.canonicalX, targetYPos.toDouble())
firstTime = false firstTime = false
} }*/
actor.hitbox.setPosition(actor.hitbox.canonicalX, targetYPos.toDouble()) // just move the cameraY to interpolated path
//println("${actor.hitbox.canonicalX}, ${actor.hitbox.canonicalY}") //println("${actor.hitbox.canonicalX}, ${actor.hitbox.canonicalY}")
@@ -106,15 +109,15 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
lateinit var logo: TextureRegion lateinit var logo: TextureRegion
val uiContainer = ArrayList<UIHandler>() val uiContainer = ArrayList<UICanvas>()
private lateinit var uiMenu: UIHandler private lateinit var uiMenu: UICanvas
private fun loadThingsWhileIntroIsVisible() { private fun loadThingsWhileIntroIsVisible() {
demoWorld = ReadLayerData(FileInputStream(ModMgr.getFile("basegame", "demoworld"))) demoWorld = ReadLayerData(FileInputStream(ModMgr.getFile("basegame", "demoworld")))
// construct camera nodes // construct camera nodes
val nodeCount = 60 val nodeCount = 100
cameraNodes = kotlin.FloatArray(nodeCount, { it -> cameraNodes = kotlin.FloatArray(nodeCount, { it ->
val tileXPos = (demoWorld.width.toFloat() * it / nodeCount).floorInt() val tileXPos = (demoWorld.width.toFloat() * it / nodeCount).floorInt()
var travelDownCounter = 0 var travelDownCounter = 0
@@ -144,7 +147,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
FeaturesDrawer.world = demoWorld FeaturesDrawer.world = demoWorld
uiMenu = UIHandler(UITitleRemoConRoot()) uiMenu = UITitleRemoConRoot()
uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY) uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY)
uiMenu.setAsOpen() uiMenu.setAsOpen()
@@ -358,7 +361,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
if (loadDone) { if (loadDone) {
// resize UI by re-creating it (!!) // resize UI by re-creating it (!!)
uiMenu.UI.resize(Terrarum.WIDTH, Terrarum.HEIGHT) uiMenu.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY) uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY)
} }

View File

@@ -39,7 +39,7 @@ internal object Authenticator : ConsoleCommand {
Echo(msg) Echo(msg)
println("[Authenticator] " + msg) println("[Authenticator] " + msg)
a = !a a = !a
(Terrarum.ingame!!.consoleHandler.UI as ConsoleWindow).reset() (Terrarum.ingame!!.consoleHandler as ConsoleWindow).reset()
} }
else { else {
printUsage() // thou shalt not pass! printUsage() // thou shalt not pass!

View File

@@ -16,13 +16,13 @@ internal object Echo : ConsoleCommand {
val sb = StringBuilder() val sb = StringBuilder()
for (ch in single_line) { for (ch in single_line) {
if (ch == '\n') { if (ch == '\n') {
(Terrarum.ingame!!.consoleHandler.UI as ConsoleWindow).sendMessage(sb.toString()) (Terrarum.ingame!!.consoleHandler as ConsoleWindow).sendMessage(sb.toString())
sb.delete(0, sb.length - 1) sb.delete(0, sb.length - 1)
} }
else else
sb.append(ch) sb.append(ch)
} }
(Terrarum.ingame!!.consoleHandler.UI as ConsoleWindow).sendMessage(sb.toString()) (Terrarum.ingame!!.consoleHandler as ConsoleWindow).sendMessage(sb.toString())
} }
operator fun invoke(args: Array<String>) = execute(args) operator fun invoke(args: Array<String>) = execute(args)

View File

@@ -14,7 +14,7 @@ internal object EchoError : ConsoleCommand {
} }
fun execute(single_line: String) { fun execute(single_line: String) {
(Terrarum.ingame!!.consoleHandler.UI as ConsoleWindow).sendMessage("$ccR$single_line") (Terrarum.ingame!!.consoleHandler as ConsoleWindow).sendMessage("$ccR$single_line")
} }
operator fun invoke(args: Array<String>) = execute(args) operator fun invoke(args: Array<String>) = execute(args)

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.console package net.torvald.terrarum.console
import com.badlogic.gdx.Gdx
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
@@ -11,6 +12,8 @@ internal object Version : ConsoleCommand {
Echo("${Terrarum.NAME} ${Terrarum.VERSION_STRING}") Echo("${Terrarum.NAME} ${Terrarum.VERSION_STRING}")
Echo("Polyglot language pack version ${Lang.POLYGLOT_VERSION}") Echo("Polyglot language pack version ${Lang.POLYGLOT_VERSION}")
Echo("GL_VERSION: ${Terrarum.GL_VERSION}")
Echo("Renderer: ${Gdx.graphics.glVersion.rendererString}, ${Gdx.graphics.glVersion.vendorString}")
} }
override fun printUsage() { override fun printUsage() {

View File

@@ -530,7 +530,7 @@ open class ActorHumanoid(
// force update inventory UI // force update inventory UI
try { try {
(Terrarum.ingame!!.uiInventoryPlayer.UI as UIInventory).shutUpAndRebuild() (Terrarum.ingame!!.uiInventoryPlayer as UIInventory).shutUpAndRebuild()
} }
catch (LateInitMyArse: kotlin.UninitializedPropertyAccessException) { } catch (LateInitMyArse: kotlin.UninitializedPropertyAccessException) { }
} }

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
@@ -30,10 +31,10 @@ class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas
this.messagesList = messagesList 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() blendNormal()
val textWidth = messagesList.map { Terrarum.fontGame.getWidth(it) }.sorted()[1] val textWidth = messagesList.map { Terrarum.fontGame.getWidth(it) }.sorted()[1]

View File

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

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
/** /**
@@ -10,10 +11,10 @@ class NullUI : UICanvas() {
override var height: Int = 0 override var height: Int = 0
override var openCloseTime = 0f 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) { override fun doOpening(delta: Float) {

View File

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

View File

@@ -1,6 +1,8 @@
package net.torvald.terrarum.ui package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx 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 com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.Second import net.torvald.terrarum.gameactors.Second
@@ -12,20 +14,36 @@ import net.torvald.terrarum.gameactors.roundInt
* *
* Created by minjaesong on 15-12-31. * 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 width: Int
abstract var height: 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 * Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
*/ */
open lateinit var handler: UIHandler protected val handler = UIHandler(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant)
init {
}
/** /**
* In milliseconds * In milliseconds
* *
* Timer itself is implemented in the handler. * Timer itself is implemented in the ui.handler.
*/ */
abstract var openCloseTime: Second abstract var openCloseTime: Second
@@ -46,27 +64,41 @@ abstract class UICanvas {
get() = mouseUp && Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")) 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) abstract fun doOpening(delta: Float)
/** /**
* Do not modify handler.openCloseCounter here. * Do not modify ui.handler.openCloseCounter here.
*/ */
abstract fun doClosing(delta: Float) abstract fun doClosing(delta: Float)
/** /**
* Do not modify handler.openCloseCounter here. * Do not modify ui.handler.openCloseCounter here.
*/ */
abstract fun endOpening(delta: Float) abstract fun endOpening(delta: Float)
/** /**
* Do not modify handler.openCloseCounter here. * Do not modify ui.handler.openCloseCounter here.
*/ */
abstract fun endClosing(delta: Float) abstract fun endClosing(delta: Float)
@@ -78,31 +110,37 @@ abstract class UICanvas {
open fun mouseMoved(screenX: Int, screenY: Int): Boolean { open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
uiItems.forEach { it.mouseMoved(screenX, screenY) } uiItems.forEach { it.mouseMoved(screenX, screenY) }
handler.subUIs.forEach { it.mouseMoved(screenX, screenY) }
return true return true
} }
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
uiItems.forEach { it.touchDragged(screenX, screenY, pointer) } uiItems.forEach { it.touchDragged(screenX, screenY, pointer) }
handler.subUIs.forEach { it.touchDragged(screenX, screenY, pointer) }
return true return true
} }
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
uiItems.forEach { it.touchDown(screenX, screenY, pointer, button) } uiItems.forEach { it.touchDown(screenX, screenY, pointer, button) }
handler.subUIs.forEach { it.touchDown(screenX, screenY, pointer, button) }
return true return true
} }
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
uiItems.forEach { it.touchUp(screenX, screenY, pointer, button) } uiItems.forEach { it.touchUp(screenX, screenY, pointer, button) }
handler.subUIs.forEach { it.touchUp(screenX, screenY, pointer, button) }
return true return true
} }
open fun scrolled(amount: Int): Boolean { open fun scrolled(amount: Int): Boolean {
uiItems.forEach { it.scrolled(amount) } uiItems.forEach { it.scrolled(amount) }
handler.subUIs.forEach { it.scrolled(amount) }
return true return true
} }
open fun keyDown(keycode: Int): Boolean { open fun keyDown(keycode: Int): Boolean {
uiItems.forEach { it.keyDown(keycode) } uiItems.forEach { it.keyDown(keycode) }
handler.subUIs.forEach { it.keyDown(keycode) }
return true return true
} }
open fun keyUp(keycode: Int): Boolean { open fun keyUp(keycode: Int): Boolean {
uiItems.forEach { it.keyUp(keycode) } uiItems.forEach { it.keyUp(keycode) }
handler.subUIs.forEach { it.keyUp(keycode) }
return true return true
} }
open fun keyTyped(character: Char): Boolean { open fun keyTyped(character: Char): Boolean {
@@ -115,85 +153,138 @@ abstract class UICanvas {
this.height = height 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 { companion object {
const val OPENCLOSE_GENERIC = 0.2f const val OPENCLOSE_GENERIC = 0.2f
fun doOpeningFade(handler: UIHandler, openCloseTime: Second) { fun doOpeningFade(ui: UICanvas, openCloseTime: Second) {
handler.opacity = handler.openCloseCounter / openCloseTime ui.handler.opacity = ui.handler.openCloseCounter / openCloseTime
} }
fun doClosingFade(handler: UIHandler, openCloseTime: Second) { fun doClosingFade(ui: UICanvas, openCloseTime: Second) {
handler.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime ui.handler.opacity = (openCloseTime - ui.handler.openCloseCounter) / openCloseTime
} }
fun endOpeningFade(handler: UIHandler) { fun endOpeningFade(ui: UICanvas) {
handler.opacity = 1f ui.handler.opacity = 1f
} }
fun endClosingFade(handler: UIHandler) { fun endClosingFade(ui: UICanvas) {
handler.opacity = 0f ui.handler.opacity = 0f
} }
fun doOpeningPopOut(handler: UIHandler, openCloseTime: Second, position: Position) { fun doOpeningPopOut(ui: UICanvas, openCloseTime: Second, position: Position) {
when (position) { when (position) {
Position.LEFT -> handler.posX = Movement.fastPullOut( Position.LEFT -> ui.handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime, ui.handler.openCloseCounter / openCloseTime,
-handler.UI.width.toFloat(), -ui.width.toFloat(),
0f 0f
).roundInt() ).roundInt()
Position.TOP -> handler.posY = Movement.fastPullOut( Position.TOP -> ui.handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime, ui.handler.openCloseCounter / openCloseTime,
-handler.UI.height.toFloat(), -ui.height.toFloat(),
0f 0f
).roundInt() ).roundInt()
Position.RIGHT -> handler.posX = Movement.fastPullOut( Position.RIGHT -> ui.handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime, ui.handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH.toFloat(), Terrarum.WIDTH.toFloat(),
Terrarum.WIDTH - handler.UI.width.toFloat() Terrarum.WIDTH - ui.width.toFloat()
).roundInt() ).roundInt()
Position.BOTTOM -> handler.posY = Movement.fastPullOut( Position.BOTTOM -> ui.handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime, ui.handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT.toFloat(), Terrarum.HEIGHT.toFloat(),
Terrarum.HEIGHT - handler.UI.height.toFloat() Terrarum.HEIGHT - ui.height.toFloat()
).roundInt() ).roundInt()
} }
} }
fun doClosingPopOut(handler: UIHandler, openCloseTime: Second, position: Position) { fun doClosingPopOut(ui: UICanvas, openCloseTime: Second, position: Position) {
when (position) { when (position) {
Position.LEFT -> handler.posX = Movement.fastPullOut( Position.LEFT -> ui.handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime, ui.handler.openCloseCounter / openCloseTime,
0f, 0f,
-handler.UI.width.toFloat() -ui.width.toFloat()
).roundInt() ).roundInt()
Position.TOP -> handler.posY = Movement.fastPullOut( Position.TOP -> ui.handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime, ui.handler.openCloseCounter / openCloseTime,
0f, 0f,
-handler.UI.height.toFloat() -ui.height.toFloat()
).roundInt() ).roundInt()
Position.RIGHT -> handler.posX = Movement.fastPullOut( Position.RIGHT -> ui.handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime, ui.handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH - handler.UI.width.toFloat(), Terrarum.WIDTH - ui.width.toFloat(),
Terrarum.WIDTH.toFloat() Terrarum.WIDTH.toFloat()
).roundInt() ).roundInt()
Position.BOTTOM -> handler.posY = Movement.fastPullOut( Position.BOTTOM -> ui.handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime, ui.handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT - handler.UI.height.toFloat(), Terrarum.HEIGHT - ui.height.toFloat(),
Terrarum.HEIGHT.toFloat() Terrarum.HEIGHT.toFloat()
).roundInt() ).roundInt()
} }
} }
fun endOpeningPopOut(handler: UIHandler, position: Position) { fun endOpeningPopOut(ui: UICanvas, position: Position) {
when (position) { when (position) {
Position.LEFT -> handler.posX = 0 Position.LEFT -> ui.handler.posX = 0
Position.TOP -> handler.posY = 0 Position.TOP -> ui.handler.posY = 0
Position.RIGHT -> handler.posX = Terrarum.WIDTH - handler.UI.width Position.RIGHT -> ui.handler.posX = Terrarum.WIDTH - ui.width
Position.BOTTOM -> handler.posY = Terrarum.HEIGHT - handler.UI.height Position.BOTTOM -> ui.handler.posY = Terrarum.HEIGHT - ui.height
} }
} }
fun endClosingPopOut(handler: UIHandler, position: Position) { fun endClosingPopOut(ui: UICanvas, position: Position) {
when (position) { when (position) {
Position.LEFT -> handler.posX = -handler.UI.width Position.LEFT -> ui.handler.posX = -ui.width
Position.TOP -> handler.posY = -handler.UI.height Position.TOP -> ui.handler.posY = -ui.height
Position.RIGHT -> handler.posX = Terrarum.WIDTH Position.RIGHT -> ui.handler.posX = Terrarum.WIDTH
Position.BOTTOM -> handler.posY = Terrarum.HEIGHT 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. * 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, var toggleKeyLiteral: Int? = null, var toggleButtonLiteral: Int? = null,
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int)) // UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
var customPositioning: Boolean = false, // mainly used by vital meter var customPositioning: Boolean = false, // mainly used by vital meter
@@ -61,7 +61,7 @@ class UIHandler(var UI: UICanvas,
var openCloseCounter = 0f var openCloseCounter = 0f
init { 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 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 // open/close UI by key pressed
if (toggleKey != null) { if (toggleKey != null) {
if (KeyToggler.isOn(toggleKey!!)) { if (KeyToggler.isOn(toggleKey!!)) {
@@ -89,7 +105,7 @@ class UIHandler(var UI: UICanvas,
if (isVisible || alwaysVisible) { if (isVisible || alwaysVisible) {
UI.update(delta) ui.updateUI(delta)
} }
if (isOpening) { if (isOpening) {
@@ -99,12 +115,12 @@ class UIHandler(var UI: UICanvas,
// println("UI ${UI.javaClass.simpleName} (open)") // println("UI ${UI.javaClass.simpleName} (open)")
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes") // println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
if (openCloseCounter < UI.openCloseTime) { if (openCloseCounter < ui.openCloseTime) {
UI.doOpening(delta) ui.doOpening(delta)
// println("UIHandler.opening ${UI.javaClass.simpleName}") // println("UIHandler.opening ${UI.javaClass.simpleName}")
} }
else { else {
UI.endOpening(delta) ui.endOpening(delta)
isOpening = false isOpening = false
isClosing = false isClosing = false
isOpened = true isOpened = true
@@ -117,12 +133,12 @@ class UIHandler(var UI: UICanvas,
// println("UI ${UI.javaClass.simpleName} (close)") // println("UI ${UI.javaClass.simpleName} (close)")
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes") // println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
if (openCloseCounter < UI.openCloseTime) { if (openCloseCounter < ui.openCloseTime) {
UI.doClosing(delta) ui.doClosing(delta)
// println("UIHandler.closing ${UI.javaClass.simpleName}") // println("UIHandler.closing ${UI.javaClass.simpleName}")
} }
else { else {
UI.endClosing(delta) ui.endClosing(delta)
isClosing = false isClosing = false
isOpening = false isOpening = false
isOpened = false isOpened = false
@@ -130,9 +146,13 @@ class UIHandler(var UI: UICanvas,
openCloseCounter = 0f openCloseCounter = 0f
} }
} }
subUIs.forEach { it.update(delta) }
} }
fun render(batch: SpriteBatch, camera: Camera) { fun render(ui: UICanvas, batch: SpriteBatch, camera: Camera) {
if (isVisible || alwaysVisible) { if (isVisible || alwaysVisible) {
// camera SHOULD BE CENTERED to HALFX and HALFY (see StateInGame) // // camera SHOULD BE CENTERED to HALFX and HALFY (see StateInGame) //
@@ -149,9 +169,13 @@ class UIHandler(var UI: UICanvas,
} }
batch.color = Color.WHITE batch.color = Color.WHITE
UI.render(batch)
ui.renderUI(batch, camera)
//ingameGraphics.flush() //ingameGraphics.flush()
} }
subUIs.forEach { it.render(batch, camera) }
} }
fun setPosition(x: Int, y: Int) { 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 // constant UI can't take control
val isTakingControl: Boolean val isTakingControl: Boolean
get() { get() {
@@ -290,10 +252,6 @@ class UIHandler(var UI: UICanvas,
return isVisible && !isOpening return isVisible && !isOpening
} }
fun dispose() {
UI.dispose()
}
fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) { fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
Ingame.setCameraPosition(batch, camera, newX, newY) 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.Gdx
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.* import net.torvald.terrarum.*
@@ -23,8 +24,13 @@ class UIInventory(
var actor: Pocketed?, var actor: Pocketed?,
override var width: Int, override var width: Int,
override var height: Int, override var height: Int,
var categoryWidth: Int var categoryWidth: Int,
) : 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
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
val inventory: ActorInventory? val inventory: ActorInventory?
get() = actor?.inventory get() = actor?.inventory
@@ -189,10 +195,7 @@ class UIInventory(
} }
override fun update(delta: Float) { override fun updateUI(delta: Float) {
if (handler == null) {
throw Error("Handler for this UI is null, you douchebag.")
}
catButtons.update(delta) catButtons.update(delta)
@@ -223,7 +226,7 @@ class UIInventory(
private val weightBarWidth = 60f private val weightBarWidth = 60f
override fun render(batch: SpriteBatch) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
// background // background
blendNormal() blendNormal()
batch.color = backgroundColour batch.color = backgroundColour
@@ -369,19 +372,19 @@ class UIInventory(
override fun doOpening(delta: Float) { 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) { 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) { override fun endOpening(delta: Float) {
UICanvas.endOpeningPopOut(handler, UICanvas.Companion.Position.LEFT) UICanvas.endOpeningPopOut(this, UICanvas.Companion.Position.LEFT)
} }
override fun endClosing(delta: Float) { 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 { 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 abstract val height: Int
protected val relativeMouseX: 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 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 */ /** If mouse is hovering over it */
open val mouseUp: Boolean 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) { if (clickOnceListener != null && !clickOnceListenerFired && mouseUp) {
println("arstineotarsneio")
clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button) clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button)
actionDone = true actionDone = true
} }

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui package net.torvald.terrarum.ui
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
@@ -28,10 +29,10 @@ class UIQuickBar : UICanvas() {
get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0 get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { Terrarum.ingame!!.player.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) } 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) { for (i in 0..SLOT_COUNT - 1) {
val image = if (i == selection) val image = if (i == selection)

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.virtualcomputer.worldobject.ui package net.torvald.terrarum.virtualcomputer.worldobject.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.gameactors.Second import net.torvald.terrarum.gameactors.Second
import net.torvald.terrarum.ui.* import net.torvald.terrarum.ui.*
@@ -24,11 +25,11 @@ class UITextTerminal(val terminal: Terminal) : UICanvas() {
*/ */
override var openCloseTime: Second = OPENCLOSE_GENERIC override var openCloseTime: Second = OPENCLOSE_GENERIC
override fun update(delta: Float) { override fun updateUI(delta: Float) {
terminal.update(delta) terminal.update(delta)
} }
override fun render(batch: SpriteBatch) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
//terminal.render(gc, terminalDisplay.graphics) //terminal.render(gc, terminalDisplay.graphics)
} }

View File

@@ -135,6 +135,7 @@ object WeatherMixer {
Terrarum.shaderBayerSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b) Terrarum.shaderBayerSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b)
Terrarum.shaderBayerSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b) Terrarum.shaderBayerSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b)
Terrarum.shaderBayerSkyboxFill.setUniformf("parallax", parallax) Terrarum.shaderBayerSkyboxFill.setUniformf("parallax", parallax)
Terrarum.shaderBayerSkyboxFill.setUniformf("parallax_size", 1f/3f)
Terrarum.fullscreenQuad.render(Terrarum.shaderBayerSkyboxFill, GL20.GL_TRIANGLES) Terrarum.fullscreenQuad.render(Terrarum.shaderBayerSkyboxFill, GL20.GL_TRIANGLES)
Terrarum.shaderBayerSkyboxFill.end() Terrarum.shaderBayerSkyboxFill.end()
} }