fixture ui almost working

This commit is contained in:
minjaesong
2019-07-08 19:41:35 +09:00
parent e8ba837b09
commit f95ea1ab0f
7 changed files with 47 additions and 40 deletions

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@ out/*
bin/* bin/*
build/* build/*
.gradle/* .gradle/*
TerrarumBuild.jar
# Java native errors # Java native errors
hs_err_pid* hs_err_pid*

Binary file not shown.

View File

@@ -56,7 +56,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre // don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (terrarumIngame.canPlayerControl) { if (terrarumIngame.canPlayerControl) {
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event // fire world click events; the event is defined as Ingame's (or any others') WorldClick event
if (terrarumIngame.uiContainer.map { if ((it?.isOpening == true || it?.isOpened == true) && it?.mouseUp == true) 1 else 0 }.sum() == 0) { // no UI on the mouse, right? if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) || if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) ||
Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) { Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
@@ -97,7 +97,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
} }
} }
terrarumIngame.uiContainer.forEach { it?.keyDown(keycode) } // for KeyboardControlled UIcanvases terrarumIngame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases
// Debug UIs // Debug UIs
if (keycode == Input.Keys.GRAVE) { if (keycode == Input.Keys.GRAVE) {
@@ -123,7 +123,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
terrarumIngame.uiQuickBar.setAsOpen() terrarumIngame.uiQuickBar.setAsOpen()
} }
terrarumIngame.uiContainer.forEach { it?.keyUp(keycode) } // for KeyboardControlled UIcanvases terrarumIngame.uiContainer.forEach { it.keyUp(keycode) } // for KeyboardControlled UIcanvases
// screenshot key // screenshot key
@@ -134,12 +134,12 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
} }
override fun keyTyped(character: Char): Boolean { override fun keyTyped(character: Char): Boolean {
terrarumIngame.uiContainer.forEach { if (it?.isVisible == true) it.keyTyped(character) } terrarumIngame.uiContainer.forEach { if (it.isVisible) it.keyTyped(character) }
return true return true
} }
override fun mouseMoved(screenX: Int, screenY: Int): Boolean { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
terrarumIngame.uiContainer.forEach { it?.mouseMoved(screenX, screenY) } terrarumIngame.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
return true return true
} }
@@ -147,7 +147,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre // don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (terrarumIngame.canPlayerControl) { if (terrarumIngame.canPlayerControl) {
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event // fire world click events; the event is defined as Ingame's (or any others') WorldClick event
if (terrarumIngame.uiContainer.map { if ((it?.isOpening == true || it?.isOpened == true) && it?.mouseUp == true) 1 else 0 }.sum() == 0) { // no UI on the mouse, right? if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
if ( if (
button == AppLoader.getConfigInt("mouseprimary") || button == AppLoader.getConfigInt("mouseprimary") ||
@@ -161,7 +161,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
} }
terrarumIngame.uiContainer.forEach { it?.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases terrarumIngame.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
return true return true
} }
@@ -177,17 +177,17 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
} }
} }
terrarumIngame.uiContainer.forEach { it?.scrolled(amount) } terrarumIngame.uiContainer.forEach { it.scrolled(amount) }
return true return true
} }
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
terrarumIngame.uiContainer.forEach { it?.touchDragged(screenX, screenY, pointer) } terrarumIngame.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
return true return true
} }
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
terrarumIngame.uiContainer.forEach { it?.touchDown(screenX, screenY, pointer, button) } terrarumIngame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
return true return true
} }

View File

@@ -21,6 +21,7 @@ import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.* import net.torvald.terrarum.worlddrawer.*
import net.torvald.util.CircularArray import net.torvald.util.CircularArray
import javax.swing.JFileChooser import javax.swing.JFileChooser
import kotlin.system.exitProcess
/** /**
* This will be rendered to a postprocessor FBO. * This will be rendered to a postprocessor FBO.
@@ -60,7 +61,7 @@ object IngameRenderer : Disposable {
private var player: ActorWithBody? = null private var player: ActorWithBody? = null
var uiListToDraw = ArrayList<UICanvas?>() var uiListToDraw: List<UICanvas?> = arrayListOf()
const val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred const val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred
@@ -112,19 +113,19 @@ object IngameRenderer : Disposable {
if (!shaderBlendGlow.isCompiled) { if (!shaderBlendGlow.isCompiled) {
Gdx.app.log("shaderBlendGlow", shaderBlendGlow.log) Gdx.app.log("shaderBlendGlow", shaderBlendGlow.log)
System.exit(1) exitProcess(1)
} }
if (AppLoader.getConfigBoolean("fxdither")) { if (AppLoader.getConfigBoolean("fxdither")) {
if (!shaderBayer.isCompiled) { if (!shaderBayer.isCompiled) {
Gdx.app.log("shaderBayer", shaderBayer.log) Gdx.app.log("shaderBayer", shaderBayer.log)
System.exit(1) exitProcess(1)
} }
if (!shaderSkyboxFill.isCompiled) { if (!shaderSkyboxFill.isCompiled) {
Gdx.app.log("shaderSkyboxFill", shaderSkyboxFill.log) Gdx.app.log("shaderSkyboxFill", shaderSkyboxFill.log)
System.exit(1) exitProcess(1)
} }
} }
@@ -186,7 +187,7 @@ object IngameRenderer : Disposable {
actorsRenderOverlay: List<ActorWithBody>? = null, actorsRenderOverlay: List<ActorWithBody>? = null,
particlesContainer : CircularArray<ParticleBase>? = null, particlesContainer : CircularArray<ParticleBase>? = null,
player: ActorWithBody? = null, player: ActorWithBody? = null,
uisToDraw: ArrayList<UICanvas?>? = null uisToDraw: List<UICanvas?>? = null
) { ) {
renderingActorsCount = (actorsRenderBehind?.size ?: 0) + renderingActorsCount = (actorsRenderBehind?.size ?: 0) +
(actorsRenderMiddle?.size ?: 0) + (actorsRenderMiddle?.size ?: 0) +

View File

@@ -58,7 +58,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
//val actorContainerActive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE) //val actorContainerActive = 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<UICanvas?>() 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)
@@ -105,8 +105,15 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var uiPieMenu: UICanvas lateinit var uiPieMenu: UICanvas
lateinit var uiQuickBar: UICanvas lateinit var uiQuickBar: UICanvas
lateinit var uiInventoryPlayer: UICanvas lateinit var uiInventoryPlayer: UICanvas
// this will not allow multiple fixture UIs from popping up (does not prevent them actually being open) /**
// because UI updating and rendering is whitelist-operated * This is a dedicated property for the fixtures' UI.
*
* When it's not null, the UI will be updated and rendered;
* when the UI is closed, it'll be replaced with a null value.
*
* This will not allow multiple fixture UIs from popping up (does not prevent them actually being open)
* because UI updating and rendering is whitelist-operated
*/
var uiFixture: UICanvas? = null var uiFixture: UICanvas? = null
set(value) { set(value) {
printdbg(this, "uiFixture change: $uiFixture -> $value") printdbg(this, "uiFixture change: $uiFixture -> $value")
@@ -129,9 +136,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var uiCheatMotherfuckerNootNoot: UICheatDetected lateinit var uiCheatMotherfuckerNootNoot: UICheatDetected
// UI aliases // UI aliases
lateinit var uiAliases: ArrayList<UICanvas?> lateinit var uiAliases: ArrayList<UICanvas>
private set private set
lateinit var uiAliasesPausing: ArrayList<UICanvas?> lateinit var uiAliasesPausing: ArrayList<UICanvas>
private set private set
//var paused: Boolean = false //var paused: Boolean = false
@@ -373,7 +380,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
uiAliasesPausing = arrayListOf( uiAliasesPausing = arrayListOf(
uiInventoryPlayer, uiInventoryPlayer,
//uiInventoryContainer, //uiInventoryContainer,
uiFixture,
consoleHandler, consoleHandler,
uiCheatMotherfuckerNootNoot uiCheatMotherfuckerNootNoot
) )
@@ -401,6 +407,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
override fun worldPrimaryClickStart(delta: Float) { override fun worldPrimaryClickStart(delta: Float) {
// bring up the UIs of the fixtures (e.g. crafting menu from a crafting table) // bring up the UIs of the fixtures (e.g. crafting menu from a crafting table)
var uiOpened = false var uiOpened = false
// TODO actorsUnderMouse: support ROUNDWORLD
val actorsUnderMouse: List<FixtureBase> = WorldSimulator.getActorsAt(Terrarum.mouseX, Terrarum.mouseY).filterIsInstance<FixtureBase>() val actorsUnderMouse: List<FixtureBase> = WorldSimulator.getActorsAt(Terrarum.mouseX, Terrarum.mouseY).filterIsInstance<FixtureBase>()
if (actorsUnderMouse.size > 1) { if (actorsUnderMouse.size > 1) {
AppLoader.printdbgerr(this, "Multiple fixtures at world coord ${Terrarum.mouseX}, ${Terrarum.mouseY}") AppLoader.printdbgerr(this, "Multiple fixtures at world coord ${Terrarum.mouseX}, ${Terrarum.mouseY}")
@@ -411,10 +419,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
actorsUnderMouse[kk].mainUI?.let { actorsUnderMouse[kk].mainUI?.let {
uiOpened = true uiOpened = true
println("ui = $it") // property 'uiFixture' is a dedicated property that the TerrarumIngame recognises.
// when it's not null, the UI will be updated and rendered
// whitelist the UI // when the UI is closed, it'll be replaced with a null value
// unlisting is done when renderGame() is called, in which, if the UI is 'isClosed', it'll be unlisted
uiFixture = it uiFixture = it
it.setPosition(0, 0) it.setPosition(0, 0)
@@ -559,7 +566,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// determine whether the inactive actor should be activated // determine whether the inactive actor should be activated
wakeDormantActors() wakeDormantActors()
// determine whether the actor should keep being activated or be dormant // determine whether the actor should keep being activated or be dormant
KillOrKnockdownActors() killOrKnockdownActors()
updateActors(delta) updateActors(delta)
particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) } particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) }
// TODO thread pool(?) // TODO thread pool(?)
@@ -602,11 +609,10 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
Gdx.graphics.setTitle(getCanonicalTitle()) Gdx.graphics.setTitle(getCanonicalTitle())
filterVisibleActors() filterVisibleActors()
uiContainer.forEach { it?.update(Gdx.graphics.rawDeltaTime) } uiContainer.forEach { it.update(Gdx.graphics.rawDeltaTime) }
uiFixture?.update(Gdx.graphics.rawDeltaTime)
// deal with the uiFixture being closed // deal with the uiFixture being closed
if (uiFixture?.isClosed == true) { if (uiFixture?.isClosed == true) { uiFixture = null }
uiFixture = null
}
IngameRenderer.invoke( IngameRenderer.invoke(
paused, paused,
@@ -617,7 +623,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
visibleActorsRenderOverlay, visibleActorsRenderOverlay,
particlesContainer, particlesContainer,
actorNowPlaying, actorNowPlaying,
uiContainer uiContainer + uiFixture
) )
} }
@@ -689,7 +695,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
* If the actor must be dormant, the target actor will be put to the list specifically for them. * If the actor must be dormant, the target actor will be put to the list specifically for them.
* if the actor is not to be dormant, it will be just ignored. * if the actor is not to be dormant, it will be just ignored.
*/ */
fun KillOrKnockdownActors() { fun killOrKnockdownActors() {
var actorContainerSize = actorContainerActive.size var actorContainerSize = actorContainerActive.size
var i = 0 var i = 0
while (i < actorContainerSize) { // loop through actorContainerActive while (i < actorContainerSize) { // loop through actorContainerActive
@@ -957,11 +963,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
particlesContainer.add(particle) particlesContainer.add(particle)
} }
fun addUI(ui: UICanvas?) { 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?.javaClass?.simpleName}" "Exact copy of the UI already exists: The instance of ${ui.javaClass.simpleName}"
) )
} }
@@ -1000,7 +1006,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
} }
override fun hide() { override fun hide() {
uiContainer.forEach { it?.handler?.dispose() } uiContainer.forEach { it.handler.dispose() }
} }
@@ -1060,8 +1066,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderOverlay.forEach { it.dispose() } actorsRenderOverlay.forEach { it.dispose() }
uiContainer.forEach { uiContainer.forEach {
it?.handler?.dispose() it.handler.dispose()
it?.dispose() it.dispose()
} }
uiFixturesHistory.forEach { uiFixturesHistory.forEach {
it.handler.dispose() it.handler.dispose()

View File

@@ -45,7 +45,6 @@ internal object UICraftingTable : UICanvas() {
} }
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
println("TurdTurdTurdTurd")
batch.color = Color.WHITE batch.color = Color.WHITE
batch.draw(AppLoader.resourcePool.getAsTextureRegion("test_texture"), 0f, 0f) batch.draw(AppLoader.resourcePool.getAsTextureRegion("test_texture"), 0f, 0f)
@@ -58,7 +57,6 @@ internal object UICraftingTable : UICanvas() {
override fun doOpening(delta: Float) { override fun doOpening(delta: Float) {
Terrarum.ingame?.paused = true Terrarum.ingame?.paused = true
println("You hit me!")
} }
override fun doClosing(delta: Float) { override fun doClosing(delta: Float) {

View File

@@ -21,6 +21,7 @@ import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.realestate.LandUtil
import kotlin.system.exitProcess
/** /**
* Sub-portion of IngameRenderer. You are not supposed to directly deal with this. * Sub-portion of IngameRenderer. You are not supposed to directly deal with this.
@@ -467,7 +468,7 @@ object LightmapRenderer {
} }
System.err.println("\nMINIMINIDUMP END") System.err.println("\nMINIMINIDUMP END")
System.exit(1) exitProcess(1)
} }
if (thisFluid.type != Fluid.NULL) { if (thisFluid.type != Fluid.NULL) {