mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
storage chest still wip
This commit is contained in:
@@ -17,6 +17,7 @@ import net.torvald.terrarum.AppLoader.*
|
|||||||
import net.torvald.terrarum.gameactors.Actor
|
import net.torvald.terrarum.gameactors.Actor
|
||||||
import net.torvald.terrarum.gameactors.ActorID
|
import net.torvald.terrarum.gameactors.ActorID
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
||||||
@@ -26,7 +27,6 @@ import java.io.File
|
|||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.math.round
|
import kotlin.math.round
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -578,3 +578,48 @@ fun printStackTrace(obj: Any, out: PrintStream = System.out) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UIContainer {
|
||||||
|
private val data = ArrayList<Any>()
|
||||||
|
fun add(vararg things: Any) {
|
||||||
|
things.forEach {
|
||||||
|
if (it is UICanvas || it is Id_UICanvasNullable)
|
||||||
|
data.add(it)
|
||||||
|
else throw IllegalArgumentException(it.javaClass.name) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun iterator() = object : Iterator<UICanvas?> {
|
||||||
|
private var cursor = 0
|
||||||
|
|
||||||
|
override fun hasNext() = cursor < data.size
|
||||||
|
|
||||||
|
override fun next(): UICanvas? {
|
||||||
|
val it = data[cursor]
|
||||||
|
// whatever the fucking reason when() does not work
|
||||||
|
if (it is UICanvas) {
|
||||||
|
cursor += 1
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
else if (it is Id_UICanvasNullable) {
|
||||||
|
cursor += 1
|
||||||
|
return it.get()
|
||||||
|
}
|
||||||
|
else throw IllegalArgumentException("Unacceptable type ${it.javaClass.name}, instance of ${it.javaClass.superclass.name}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun forEach(operation: (UICanvas?) -> Unit) = iterator().forEach(operation)
|
||||||
|
fun countVisible(): Int {
|
||||||
|
var c = 0
|
||||||
|
forEach { if (it?.isVisible == true) c += 1 }
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
fun contains(element: Any) = data.contains(element)
|
||||||
|
|
||||||
|
fun <T> map(transformation: (UICanvas?) -> T) = iterator().asSequence().map(transformation)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Id_UICanvasNullable {
|
||||||
|
fun get(): UICanvas?
|
||||||
|
}
|
||||||
@@ -114,7 +114,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
private val gradWhiteBottom = Color(0xd8d8d8ff.toInt())
|
private val gradWhiteBottom = Color(0xd8d8d8ff.toInt())
|
||||||
|
|
||||||
|
|
||||||
val uiContainer = ArrayList<UICanvas?>()
|
val uiContainer = UIContainer()
|
||||||
private lateinit var uiMenu: UICanvas
|
private lateinit var uiMenu: UICanvas
|
||||||
|
|
||||||
private lateinit var worldFBO: FrameBuffer
|
private lateinit var worldFBO: FrameBuffer
|
||||||
@@ -242,7 +242,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
|
|
||||||
if (!demoWorld.layerTerrain.ptr.destroyed) { // FIXME q&d hack to circumvent the dangling pointer issue #26
|
if (!demoWorld.layerTerrain.ptr.destroyed) { // FIXME q&d hack to circumvent the dangling pointer issue #26
|
||||||
IngameRenderer.invoke(gamePaused = false, uisToDraw = uiContainer)
|
IngameRenderer.invoke(gamePaused = false, uiContainer = uiContainer)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printdbgerr(this, "Demoworld is already been destroyed")
|
printdbgerr(this, "Demoworld is already been destroyed")
|
||||||
|
|||||||
@@ -113,7 +113,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) {
|
||||||
@@ -138,8 +138,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
|
||||||
if (keycode == Input.Keys.F12) f12Down = false
|
if (keycode == Input.Keys.F12) f12Down = false
|
||||||
@@ -149,12 +148,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) it.keyTyped(character) }
|
terrarumIngame.uiContainer.forEach { if (it?.isVisible == true) 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +161,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.paused) {
|
if (!terrarumIngame.paused) {
|
||||||
// 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 || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
if (terrarumIngame.uiContainer.map { if ((it?.isOpening == true || it?.isOpened == true) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||||
|
|
||||||
if (
|
if (
|
||||||
button == AppLoader.getConfigInt("config_mouseprimary") ||
|
button == AppLoader.getConfigInt("config_mouseprimary") ||
|
||||||
@@ -181,8 +180,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
terrarumIngame.uiQuickBar.setAsOpen()
|
terrarumIngame.uiQuickBar.setAsOpen()
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,17 +195,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) }
|
||||||
|
|
||||||
// pie menu
|
// pie menu
|
||||||
if (button == AppLoader.getConfigInt("config_mousequicksel")) {
|
if (button == AppLoader.getConfigInt("config_mousequicksel")) {
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
val uiPenMenu = UIBuildingMakerPenMenu(this)
|
val uiPenMenu = UIBuildingMakerPenMenu(this)
|
||||||
|
|
||||||
|
|
||||||
val uiContainer = ArrayList<UICanvas?>()
|
val uiContainer = UIContainer()
|
||||||
|
|
||||||
private val pensMustShowSelection = arrayOf(
|
private val pensMustShowSelection = arrayOf(
|
||||||
PENMODE_MARQUEE, PENMODE_MARQUEE_ERASE
|
PENMODE_MARQUEE, PENMODE_MARQUEE_ERASE
|
||||||
@@ -392,7 +392,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
private fun renderGame() {
|
private fun renderGame() {
|
||||||
_testMarkerDrawCalls = 0L
|
_testMarkerDrawCalls = 0L
|
||||||
|
|
||||||
IngameRenderer.invoke(false, actorsRenderOverlay = if (showSelection) actorsRenderOverlay + essentialOverlays else essentialOverlays, uisToDraw = uiContainer)
|
IngameRenderer.invoke(false, actorsRenderOverlay = if (showSelection) actorsRenderOverlay + essentialOverlays else essentialOverlays, uiContainer = uiContainer)
|
||||||
|
|
||||||
AppLoader.setDebugTime("Test.MarkerDrawCalls", _testMarkerDrawCalls)
|
AppLoader.setDebugTime("Test.MarkerDrawCalls", _testMarkerDrawCalls)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,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: List<UICanvas?>? = null
|
uiContainer: UIContainer? = null
|
||||||
) {
|
) {
|
||||||
renderingActorsCount = (actorsRenderBehind?.size ?: 0) +
|
renderingActorsCount = (actorsRenderBehind?.size ?: 0) +
|
||||||
(actorsRenderMiddle?.size ?: 0) +
|
(actorsRenderMiddle?.size ?: 0) +
|
||||||
@@ -182,15 +182,9 @@ object IngameRenderer : Disposable {
|
|||||||
(actorsRenderOverlay?.size ?: 0)
|
(actorsRenderOverlay?.size ?: 0)
|
||||||
//renderingParticleCount = particlesContainer?.size ?: 0
|
//renderingParticleCount = particlesContainer?.size ?: 0
|
||||||
//renderingParticleCount = (particlesContainer?.buffer?.map { (!it.flagDespawn).toInt() } ?: listOf(0)).sum()
|
//renderingParticleCount = (particlesContainer?.buffer?.map { (!it.flagDespawn).toInt() } ?: listOf(0)).sum()
|
||||||
renderingUIsCount = ((uisToDraw?.map { (it?.isVisible ?: false).toInt() }) ?: listOf(0)).sum()
|
renderingUIsCount = uiContainer?.countVisible() ?: 0
|
||||||
|
|
||||||
val zoom = Terrarum.ingame?.screenZoom ?: 1f
|
val zoom = Terrarum.ingame?.screenZoom ?: 1f
|
||||||
|
|
||||||
|
|
||||||
if (uisToDraw != null) {
|
|
||||||
uiListToDraw = uisToDraw
|
|
||||||
}
|
|
||||||
|
|
||||||
invokeInit()
|
invokeInit()
|
||||||
|
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
@@ -331,7 +325,7 @@ object IngameRenderer : Disposable {
|
|||||||
batch.shader = null
|
batch.shader = null
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
|
|
||||||
uiListToDraw.forEach {
|
uiContainer?.forEach {
|
||||||
it?.render(batch, camera)
|
it?.render(batch, camera)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ 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.Camera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import net.torvald.EMDASH
|
import net.torvald.EMDASH
|
||||||
import net.torvald.UnsafeHelper
|
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||||
@@ -62,7 +62,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, true)
|
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX, true)
|
||||||
val uiContainer = ArrayList<UICanvas>()
|
val uiContainer = UIContainer()
|
||||||
|
|
||||||
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)
|
||||||
@@ -118,13 +118,20 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
* This will not allow multiple fixture UIs from popping up (does not prevent them actually being open)
|
* 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
|
* because UI updating and rendering is whitelist-operated
|
||||||
*/
|
*/
|
||||||
var uiFixture: UICanvas? = null
|
private var uiFixture: UICanvas? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
printdbg(this, "uiFixture change: $uiFixture -> $value")
|
printdbg(this, "uiFixture change: $uiFixture -> $value")
|
||||||
field?.let { it.setAsClose() }
|
field?.let { it.setAsClose() }
|
||||||
value?.let { uiFixturesHistory.add(it) }
|
value?.let { uiFixturesHistory.add(it) }
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val getUIFixture = object : Id_UICanvasNullable { // quick workaround for the type erasure (you can't use lambda...)
|
||||||
|
override fun get(): UICanvas? {
|
||||||
|
return uiFixture
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lateinit var uiInventoryContainer: UICanvas
|
lateinit var uiInventoryContainer: UICanvas
|
||||||
lateinit var uiVitalPrimary: UICanvas
|
lateinit var uiVitalPrimary: UICanvas
|
||||||
lateinit var uiVitalSecondary: UICanvas
|
lateinit var uiVitalSecondary: UICanvas
|
||||||
@@ -361,7 +368,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
// batch-process uiAliases
|
// batch-process uiAliases
|
||||||
// NOTE: UIs that should pause the game (e.g. Inventory) must have relevant codes ON THEIR SIDE
|
// NOTE: UIs that should pause the game (e.g. Inventory) must have relevant codes ON THEIR SIDE
|
||||||
arrayListOf(
|
uiContainer.add(
|
||||||
// drawn first
|
// drawn first
|
||||||
//uiVitalPrimary,
|
//uiVitalPrimary,
|
||||||
//uiVitalSecondary,
|
//uiVitalSecondary,
|
||||||
@@ -373,13 +380,12 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
uiWatchTierOne,
|
uiWatchTierOne,
|
||||||
UIScreenZoom(),
|
UIScreenZoom(),
|
||||||
uiInventoryPlayer,
|
uiInventoryPlayer,
|
||||||
//uiInventoryContainer,
|
getUIFixture,
|
||||||
uiTooltip,
|
uiTooltip,
|
||||||
consoleHandler,
|
consoleHandler,
|
||||||
uiCheatMotherfuckerNootNoot
|
uiCheatMotherfuckerNootNoot
|
||||||
// drawn last
|
// drawn last
|
||||||
).forEach { addUI(it) }
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ingameUpdateThread = ThreadIngameUpdate(this)
|
ingameUpdateThread = ThreadIngameUpdate(this)
|
||||||
@@ -605,8 +611,13 @@ 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 {
|
||||||
uiFixture?.update(Gdx.graphics.rawDeltaTime)
|
when (it) {
|
||||||
|
is UICanvas -> it.update(Gdx.graphics.rawDeltaTime)
|
||||||
|
is Id_UICanvasNullable -> it.get()?.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) { uiFixture = null }
|
if (uiFixture?.isClosed == true) { uiFixture = null }
|
||||||
|
|
||||||
@@ -619,7 +630,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
visibleActorsRenderOverlay,
|
visibleActorsRenderOverlay,
|
||||||
particlesContainer,
|
particlesContainer,
|
||||||
actorNowPlaying,
|
actorNowPlaying,
|
||||||
uiContainer + uiFixture
|
uiContainer// + uiFixture
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -828,7 +839,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
|
if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
|
||||||
throw RuntimeException("Attempted to remove player.")
|
throw RuntimeException("Attempted to remove player.")
|
||||||
val indexToDelete = actorContainerActive.searchForIndex(actor.referenceID!!) { it.referenceID!! }
|
val indexToDelete = actorContainerActive.searchForIndex(actor.referenceID) { it.referenceID!! }
|
||||||
if (indexToDelete != null) {
|
if (indexToDelete != null) {
|
||||||
printdbg(this, "Removing actor $actor")
|
printdbg(this, "Removing actor $actor")
|
||||||
printStackTrace(this)
|
printStackTrace(this)
|
||||||
@@ -840,23 +851,23 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
if (actor is ActorWithBody) {
|
if (actor is ActorWithBody) {
|
||||||
when (actor.renderOrder) {
|
when (actor.renderOrder) {
|
||||||
Actor.RenderOrder.BEHIND -> {
|
Actor.RenderOrder.BEHIND -> {
|
||||||
val i = actorsRenderBehind.binarySearch(actor.referenceID!!)
|
val i = actorsRenderBehind.binarySearch(actor.referenceID)
|
||||||
actorsRenderBehind.removeAt(i)
|
actorsRenderBehind.removeAt(i)
|
||||||
}
|
}
|
||||||
Actor.RenderOrder.MIDDLE -> {
|
Actor.RenderOrder.MIDDLE -> {
|
||||||
val i = actorsRenderMiddle.binarySearch(actor.referenceID!!)
|
val i = actorsRenderMiddle.binarySearch(actor.referenceID)
|
||||||
actorsRenderMiddle.removeAt(i)
|
actorsRenderMiddle.removeAt(i)
|
||||||
}
|
}
|
||||||
Actor.RenderOrder.MIDTOP -> {
|
Actor.RenderOrder.MIDTOP -> {
|
||||||
val i = actorsRenderMidTop.binarySearch(actor.referenceID!!)
|
val i = actorsRenderMidTop.binarySearch(actor.referenceID)
|
||||||
actorsRenderMidTop.removeAt(i)
|
actorsRenderMidTop.removeAt(i)
|
||||||
}
|
}
|
||||||
Actor.RenderOrder.FRONT -> {
|
Actor.RenderOrder.FRONT -> {
|
||||||
val i = actorsRenderFront.binarySearch(actor.referenceID!!)
|
val i = actorsRenderFront.binarySearch(actor.referenceID)
|
||||||
actorsRenderFront.removeAt(i)
|
actorsRenderFront.removeAt(i)
|
||||||
}
|
}
|
||||||
Actor.RenderOrder.OVERLAY-> {
|
Actor.RenderOrder.OVERLAY-> {
|
||||||
val i = actorsRenderOverlay.binarySearch(actor.referenceID!!)
|
val i = actorsRenderOverlay.binarySearch(actor.referenceID)
|
||||||
actorsRenderFront.removeAt(i)
|
actorsRenderFront.removeAt(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -864,7 +875,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ArrayList<*>.binarySearch(actor: Actor) = this.binarySearch(actor.referenceID!!)
|
private fun ArrayList<*>.binarySearch(actor: Actor) = this.binarySearch(actor.referenceID)
|
||||||
|
|
||||||
private fun ArrayList<*>.binarySearch(ID: Int): Int {
|
private fun ArrayList<*>.binarySearch(ID: Int): Int {
|
||||||
// code from collections/Collections.kt
|
// code from collections/Collections.kt
|
||||||
@@ -892,7 +903,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
override fun addNewActor(actor: Actor?) {
|
override fun addNewActor(actor: Actor?) {
|
||||||
if (actor == null) return
|
if (actor == null) return
|
||||||
|
|
||||||
if (AppLoader.IS_DEVELOPMENT_BUILD && theGameHasActor(actor.referenceID!!)) {
|
if (AppLoader.IS_DEVELOPMENT_BUILD && theGameHasActor(actor.referenceID)) {
|
||||||
throw Error("The actor $actor already exists in the game")
|
throw Error("The actor $actor already exists in the game")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -924,8 +935,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun activateDormantActor(actor: Actor) {
|
fun activateDormantActor(actor: Actor) {
|
||||||
if (AppLoader.IS_DEVELOPMENT_BUILD && !isInactive(actor.referenceID!!)) {
|
if (AppLoader.IS_DEVELOPMENT_BUILD && !isInactive(actor.referenceID)) {
|
||||||
if (isActive(actor.referenceID!!))
|
if (isActive(actor.referenceID))
|
||||||
throw Error("The actor $actor is already activated")
|
throw Error("The actor $actor is already activated")
|
||||||
else
|
else
|
||||||
throw Error("The actor $actor already exists in the game")
|
throw Error("The actor $actor already exists in the game")
|
||||||
@@ -960,17 +971,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
particlesContainer.appendHead(particle)
|
particlesContainer.appendHead(particle)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addUI(ui: UICanvas) {
|
|
||||||
// check for exact duplicates
|
|
||||||
if (uiContainer.contains(ui)) {
|
|
||||||
throw IllegalArgumentException(
|
|
||||||
"Exact copy of the UI already exists: The instance of ${ui.javaClass.simpleName}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
uiContainer.add(ui)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun insertionSortLastElemAV(arr: ArrayList<ActorWithBody>) { // out-projection doesn't work, duh
|
private fun insertionSortLastElemAV(arr: ArrayList<ActorWithBody>) { // out-projection doesn't work, duh
|
||||||
ReentrantLock().lock {
|
ReentrantLock().lock {
|
||||||
var j = arr.lastIndex - 1
|
var j = arr.lastIndex - 1
|
||||||
@@ -1003,7 +1003,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hide() {
|
override fun hide() {
|
||||||
uiContainer.forEach { it.handler.dispose() }
|
uiContainer.forEach { it?.handler?.dispose() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1063,15 +1063,17 @@ 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()
|
try {
|
||||||
it.dispose()
|
it.handler.dispose()
|
||||||
|
it.dispose()
|
||||||
|
}
|
||||||
|
catch (e: GdxRuntimeException) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dispose()
|
super.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,9 +44,7 @@ internal object UIStorageChest : UICanvas(), HasInventory {
|
|||||||
override var height = 512
|
override var height = 512
|
||||||
override var openCloseTime: Second = 0.0f
|
override var openCloseTime: Second = 0.0f
|
||||||
|
|
||||||
private val negotiator = object : InventoryNegotiator {
|
private val negotiator = object : InventoryNegotiator() {
|
||||||
override fun getItemFilter(): List<String> = listOf(CAT_ALL)
|
|
||||||
|
|
||||||
override fun accept(item: GameItem, amount: Int) {
|
override fun accept(item: GameItem, amount: Int) {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
@@ -66,32 +64,38 @@ internal object UIStorageChest : UICanvas(), HasInventory {
|
|||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private lateinit var catBar: UIItemInventoryCatBar
|
||||||
|
|
||||||
|
private lateinit var itemList: UIItemInventoryItemGrid
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
catBar = UIItemInventoryCatBar(
|
||||||
|
this,
|
||||||
|
100,
|
||||||
|
50,
|
||||||
|
500,
|
||||||
|
500,
|
||||||
|
{ itemList.rebuild(catBar.catIconsMeaning[catBar.selectedIcon]) },
|
||||||
|
false
|
||||||
|
)
|
||||||
|
itemList = UIItemInventoryItemGrid(
|
||||||
|
this,
|
||||||
|
catBar,
|
||||||
|
Terrarum.ingame!!.actorNowPlaying!!.inventory, // just for a placeholder...
|
||||||
|
100,
|
||||||
|
100,
|
||||||
|
4, 5,
|
||||||
|
drawScrollOnRightside = true,
|
||||||
|
drawWallet = true,
|
||||||
|
listRebuildFun = { itemListUpdate() }
|
||||||
|
)
|
||||||
|
|
||||||
handler.allowESCtoClose = true
|
handler.allowESCtoClose = true
|
||||||
|
|
||||||
|
addUIitem(catBar)
|
||||||
|
addUIitem(itemList)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val catBar = UIItemInventoryCatBar(
|
|
||||||
this,
|
|
||||||
100,
|
|
||||||
50,
|
|
||||||
500,
|
|
||||||
500,
|
|
||||||
{},
|
|
||||||
false
|
|
||||||
)
|
|
||||||
|
|
||||||
private val itemList = UIItemInventoryItemGrid(
|
|
||||||
this,
|
|
||||||
catBar,
|
|
||||||
Terrarum.ingame!!.actorNowPlaying!!.inventory, // just for a placeholder...
|
|
||||||
100,
|
|
||||||
100,
|
|
||||||
4, 5,
|
|
||||||
drawScrollOnRightside = true,
|
|
||||||
drawWallet = true,
|
|
||||||
listRebuildFun = { itemListUpdate() }
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun itemListUpdate() {
|
private fun itemListUpdate() {
|
||||||
itemList.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
|
itemList.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
|
||||||
}
|
}
|
||||||
@@ -104,6 +108,7 @@ internal object UIStorageChest : UICanvas(), HasInventory {
|
|||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
|
|
||||||
|
catBar.render(batch, camera)
|
||||||
itemList.render(batch, camera)
|
itemList.render(batch, camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.ui
|
package net.torvald.terrarum.modulebasegame.ui
|
||||||
|
|
||||||
|
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2021-03-12.
|
* Created by minjaesong on 2021-03-12.
|
||||||
*/
|
*/
|
||||||
interface InventoryNegotiator {
|
abstract class InventoryNegotiator {
|
||||||
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
|
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
|
||||||
fun getItemFilter(): List<String> // GameItem.Category
|
open fun getItemFilter(): List<String> = listOf(CAT_ALL) // GameItem.Category
|
||||||
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
|
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
|
||||||
fun accept(item: GameItem, amount: Int = 1)
|
abstract fun accept(item: GameItem, amount: Int = 1)
|
||||||
/** Rejects item and perhaps returns it back to the player, or make explosion, etc... */
|
/** Rejects item and perhaps returns it back to the player, or make explosion, etc... */
|
||||||
fun reject(item: GameItem, amount: Int = 1)
|
abstract fun reject(item: GameItem, amount: Int = 1)
|
||||||
}
|
}
|
||||||
@@ -221,6 +221,8 @@ class UIItemInventoryItemGrid(
|
|||||||
gridModeButtons[1].highlighted = false
|
gridModeButtons[1].highlighted = false
|
||||||
itemPage = 0
|
itemPage = 0
|
||||||
rebuild(currentFilter)
|
rebuild(currentFilter)
|
||||||
|
|
||||||
|
println("ItemGridMode 0 touchdown")
|
||||||
}
|
}
|
||||||
gridModeButtons[1].touchDownListener = { _, _, _, _ ->
|
gridModeButtons[1].touchDownListener = { _, _, _, _ ->
|
||||||
isCompactMode = true
|
isCompactMode = true
|
||||||
@@ -228,6 +230,8 @@ class UIItemInventoryItemGrid(
|
|||||||
gridModeButtons[1].highlighted = true
|
gridModeButtons[1].highlighted = true
|
||||||
itemPage = 0
|
itemPage = 0
|
||||||
rebuild(currentFilter)
|
rebuild(currentFilter)
|
||||||
|
|
||||||
|
println("ItemGridMode 1 touchdown")
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollUpButton.clickOnceListener = { _, _, _ ->
|
scrollUpButton.clickOnceListener = { _, _, _ ->
|
||||||
|
|||||||
@@ -65,10 +65,6 @@ abstract class UICanvas(
|
|||||||
*/
|
*/
|
||||||
val handler = UIHandler(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant)
|
val handler = UIHandler(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant)
|
||||||
|
|
||||||
init {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In milliseconds
|
* In milliseconds
|
||||||
*
|
*
|
||||||
@@ -285,6 +281,9 @@ abstract class UICanvas(
|
|||||||
|
|
||||||
// end of handler func aliases
|
// end of handler func aliases
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (uiItems.isEmpty()) println("UICanvas '${this.javaClass.name}' has no UIItem registered, just so you know...")
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val OPENCLOSE_GENERIC = 0.2f
|
const val OPENCLOSE_GENERIC = 0.2f
|
||||||
|
|||||||
@@ -193,6 +193,8 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
|
println("uiitem ${this.javaClass.name} touchdown")
|
||||||
|
|
||||||
var actionDone = false
|
var actionDone = false
|
||||||
|
|
||||||
if (parentUI.isVisible) {
|
if (parentUI.isVisible) {
|
||||||
|
|||||||
Reference in New Issue
Block a user