trying to make fixtures with UIs working, was not successful

This commit is contained in:
minjaesong
2019-07-08 04:05:04 +09:00
parent 84e4c82b60
commit e8ba837b09
28 changed files with 366 additions and 86 deletions

View File

@@ -115,7 +115,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
val uiPenMenu = UIBuildingMakerPenMenu(this)
val uiContainer = ArrayList<UICanvas>()
val uiContainer = ArrayList<UICanvas?>()
private val pensMustShowSelection = arrayOf(
PENMODE_MARQUEE, PENMODE_MARQUEE_ERASE
@@ -353,8 +353,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
actorNowPlaying?.update(delta)
var overwriteMouseOnUI = false
uiContainer.forEach {
it.update(delta)
if (it.isVisible && it.mouseUp) {
it?.update(delta)
if (it?.isVisible == true && it?.mouseUp == true) {
overwriteMouseOnUI = true
}
}
@@ -502,43 +502,43 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
screen.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) }
screen.uiContainer.forEach { it?.touchUp(screenX, screenY, pointer, button) }
screen.tappedOnUI = false
return true
}
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
screen.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
screen.uiContainer.forEach { it?.mouseMoved(screenX, screenY) }
return true
}
override fun keyTyped(character: Char): Boolean {
screen.uiContainer.forEach { it.keyTyped(character) }
screen.uiContainer.forEach { it?.keyTyped(character) }
return true
}
override fun scrolled(amount: Int): Boolean {
screen.uiContainer.forEach { it.scrolled(amount) }
screen.uiContainer.forEach { it?.scrolled(amount) }
return true
}
override fun keyUp(keycode: Int): Boolean {
screen.uiContainer.forEach { it.keyUp(keycode) }
screen.uiContainer.forEach { it?.keyUp(keycode) }
return true
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
screen.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
screen.uiContainer.forEach { it?.touchDragged(screenX, screenY, pointer) }
return true
}
override fun keyDown(keycode: Int): Boolean {
screen.uiContainer.forEach { it.keyDown(keycode) }
screen.uiContainer.forEach { it?.keyDown(keycode) }
return true
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
screen.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
screen.uiContainer.forEach { it?.touchDown(screenX, screenY, pointer, button) }
return true
}
}

View File

@@ -60,7 +60,7 @@ object IngameRenderer : Disposable {
private var player: ActorWithBody? = null
var uiListToDraw = ArrayList<UICanvas>()
var uiListToDraw = ArrayList<UICanvas?>()
const val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred
@@ -186,7 +186,7 @@ object IngameRenderer : Disposable {
actorsRenderOverlay: List<ActorWithBody>? = null,
particlesContainer : CircularArray<ParticleBase>? = null,
player: ActorWithBody? = null,
uisToDraw: ArrayList<UICanvas>? = null
uisToDraw: ArrayList<UICanvas?>? = null
) {
renderingActorsCount = (actorsRenderBehind?.size ?: 0) +
(actorsRenderMiddle?.size ?: 0) +
@@ -195,7 +195,7 @@ object IngameRenderer : Disposable {
(actorsRenderOverlay?.size ?: 0)
//renderingParticleCount = particlesContainer?.size ?: 0
//renderingParticleCount = (particlesContainer?.buffer?.map { (!it.flagDespawn).toInt() } ?: listOf(0)).sum()
renderingUIsCount = ((uisToDraw?.map { it.isVisible.toInt() }) ?: listOf(0)).sum()
renderingUIsCount = ((uisToDraw?.map { (it?.isVisible ?: false).toInt() }) ?: listOf(0)).sum()
if (uisToDraw != null) {
@@ -327,7 +327,7 @@ object IngameRenderer : Disposable {
batch.color = Color.WHITE
uiListToDraw.forEach {
it.render(batch, camera)
it?.render(batch, camera)
}
}

View File

@@ -58,7 +58,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
//val actorContainerActive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
//val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
val uiContainer = ArrayList<UICanvas>()
val uiContainer = ArrayList<UICanvas?>()
private val actorsRenderBehind = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
private val actorsRenderMiddle = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
@@ -105,11 +105,22 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var uiPieMenu: UICanvas
lateinit var uiQuickBar: 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
var uiFixture: UICanvas? = null
set(value) {
printdbg(this, "uiFixture change: $uiFixture -> $value")
field?.let { it.setAsClose() }
value?.let { uiFixturesHistory.add(it) }
field = value
}
lateinit var uiInventoryContainer: UICanvas
lateinit var uiVitalPrimary: UICanvas
lateinit var uiVitalSecondary: UICanvas
lateinit var uiVitalItem: UICanvas // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500.
private val uiFixturesHistory = HashSet<UICanvas>()
private lateinit var uiBasicInfo: UICanvas
private lateinit var uiWatchTierOne: UICanvas
@@ -118,13 +129,13 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var uiCheatMotherfuckerNootNoot: UICheatDetected
// UI aliases
lateinit var uiAliases: ArrayList<UICanvas>
lateinit var uiAliases: ArrayList<UICanvas?>
private set
lateinit var uiAliasesPausing: ArrayList<UICanvas>
lateinit var uiAliasesPausing: ArrayList<UICanvas?>
private set
inline val paused: Boolean
get() = uiAliasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmpty is always false, which we want
//var paused: Boolean = false
//get() = uiAliasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmpty is always false, which we want
/**
* Set to false if UI is opened; set to true if UI is closed.
*/
@@ -313,7 +324,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
uiQuickBar.setPosition((AppLoader.screenW - uiQuickBar.width) / 2, AppLoader.getTvSafeGraphicsHeight())
// pie menu
uiPieMenu = uiQuickslotPie()
uiPieMenu = UIQuickslotPie()
uiPieMenu.setPosition(AppLoader.halfScreenW, AppLoader.halfScreenH)
// vital metre
@@ -362,6 +373,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
uiAliasesPausing = arrayListOf(
uiInventoryPlayer,
//uiInventoryContainer,
uiFixture,
consoleHandler,
uiCheatMotherfuckerNootNoot
)
@@ -387,10 +399,38 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}// END enter
override fun worldPrimaryClickStart(delta: Float) {
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
val consumptionSuccessful = ItemCodex[itemOnGrip]?.startPrimaryUse(delta) ?: false
if (consumptionSuccessful)
actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!)
// bring up the UIs of the fixtures (e.g. crafting menu from a crafting table)
var uiOpened = false
val actorsUnderMouse: List<FixtureBase> = WorldSimulator.getActorsAt(Terrarum.mouseX, Terrarum.mouseY).filterIsInstance<FixtureBase>()
if (actorsUnderMouse.size > 1) {
AppLoader.printdbgerr(this, "Multiple fixtures at world coord ${Terrarum.mouseX}, ${Terrarum.mouseY}")
}
// scan for the one with non-null UI.
// what if there's multiple of such fixtures? whatever, you are supposed to DISALLOW such situation.
for (kk in 0 until actorsUnderMouse.size) {
actorsUnderMouse[kk].mainUI?.let {
uiOpened = true
println("ui = $it")
// whitelist the UI
// unlisting is done when renderGame() is called, in which, if the UI is 'isClosed', it'll be unlisted
uiFixture = it
it.setPosition(0, 0)
it.setAsOpen()
}
break
}
// don't want to open the UI and use the item at the same time, would ya?
if (!uiOpened) {
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
val consumptionSuccessful = ItemCodex[itemOnGrip]?.startPrimaryUse(delta) ?: false
if (consumptionSuccessful)
actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!)
}
}
override fun worldPrimaryClickEnd(delta: Float) {
@@ -553,6 +593,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
AVTracker.update()
ActorsList.update()
}
//println("paused = $paused")
}
@@ -560,7 +602,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
Gdx.graphics.setTitle(getCanonicalTitle())
filterVisibleActors()
uiContainer.forEach { it.update(Gdx.graphics.rawDeltaTime) }
uiContainer.forEach { it?.update(Gdx.graphics.rawDeltaTime) }
// deal with the uiFixture being closed
if (uiFixture?.isClosed == true) {
uiFixture = null
}
IngameRenderer.invoke(
paused,
@@ -911,11 +957,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
particlesContainer.add(particle)
}
fun addUI(ui: UICanvas) {
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}"
"Exact copy of the UI already exists: The instance of ${ui?.javaClass?.simpleName}"
)
}
@@ -954,7 +1000,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
override fun hide() {
uiContainer.forEach { it.handler.dispose() }
uiContainer.forEach { it?.handler?.dispose() }
}
@@ -1014,6 +1060,10 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderOverlay.forEach { it.dispose() }
uiContainer.forEach {
it?.handler?.dispose()
it?.dispose()
}
uiFixturesHistory.forEach {
it.handler.dispose()
it.dispose()
}

View File

@@ -7,13 +7,19 @@ import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.ui.UICanvas
/**
* Created by minjaesong on 2016-06-17.
*/
open class FixtureBase(blockBox0: BlockBox, val blockBoxProps: BlockBoxProps = BlockBoxProps(0), renderOrder: RenderOrder = RenderOrder.MIDDLE) :
open class FixtureBase(
blockBox0: BlockBox,
val blockBoxProps: BlockBoxProps = BlockBoxProps(0),
renderOrder: RenderOrder = RenderOrder.MIDDLE,
val mainUI: UICanvas? = null
// disabling physics (not allowing the fixture to move) WILL make things easier in many ways
ActorWBMovable(renderOrder, immobileBody = true, usePhysics = false), CuedByTerrainChange {
) : ActorWBMovable(renderOrder, immobileBody = true, usePhysics = false), CuedByTerrainChange {
var blockBox: BlockBox = blockBox0
protected set // something like TapestryObject will want to redefine this

View File

@@ -0,0 +1,78 @@
package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2019-07-08.
*/
internal class FixtureCraftingTable : FixtureBase(
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),
mainUI = UICraftingTable
) {
init {
setHitboxDimension(16, 16, 0, 0)
makeNewSprite(TextureRegionPack(AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16))
sprite!!.setRowsAndFrames(1, 1)
actorValue[AVKey.BASEMASS] = MASS
}
companion object {
const val MASS = 2.0
}
}
internal object UICraftingTable : UICanvas() {
override var width = 512
override var height = 512
override var openCloseTime: Second = 0.05f
override fun updateUI(delta: Float) {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
println("TurdTurdTurdTurd")
batch.color = Color.WHITE
batch.draw(AppLoader.resourcePool.getAsTextureRegion("test_texture"), 0f, 0f)
if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) {
handler.setAsClose()
}
}
override fun doOpening(delta: Float) {
Terrarum.ingame?.paused = true
println("You hit me!")
}
override fun doClosing(delta: Float) {
Terrarum.ingame?.paused = false
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
}

View File

@@ -34,6 +34,10 @@ internal class FixtureTikiTorch : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1,
makeNewSprite(TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32))
sprite!!.setRowsAndFrames(1, 1)
actorValue[AVKey.BASEMASS] = 1.0
actorValue[AVKey.BASEMASS] = MASS
}
companion object {
const val MASS = 1.0
}
}

View File

@@ -89,6 +89,7 @@ object PlayerBuilderSigrid {
inventory.add(8450) // steel pick
inventory.add(8466, 9995) // wire piece
inventory.add(8467, 385930603) // test tiki torch
inventory.add(8468, 95) // crafting table
inventory.add(9000) // TEST water bucket
inventory.add(9001) // TEST lava bucket
}

View File

@@ -0,0 +1,40 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.gameactors.FixtureCraftingTable
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
/**
* Created by minjaesong on 2019-07-08.
*/
class ItemCraftingTable(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "ITEM_CRAFTING_TABLE"
override var baseMass = FixtureTikiTorch.MASS
override var stackable = true
override var inventoryCategory = Category.FIXTURE
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val itemImage: TextureRegion?
get() = AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_16")
override var baseToolSize: Double? = baseMass
init {
equipPosition = EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(delta: Float): Boolean {
val item = FixtureCraftingTable()
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
// return true when placed, false when cannot be placed
}
}

View File

@@ -15,7 +15,7 @@ class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "Tiki Torch"
override var baseMass = 1.0
override var baseMass = FixtureTikiTorch.MASS
override var stackable = true
override var inventoryCategory = Category.FIXTURE
override val isUnique = false
@@ -30,9 +30,9 @@ class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
}
override fun startPrimaryUse(delta: Float): Boolean {
val torch = FixtureTikiTorch()
val item = FixtureTikiTorch()
return torch.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - torch.blockBox.height + 1)
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
// return true when placed, false when cannot be placed
}

View File

@@ -70,7 +70,7 @@ object WorldSimulator {
operator fun invoke(player: ActorHumanoid?, delta: Float) {
// build the r-tree that will be used during a single frame of updating
actorsRTree = PRTree(actorMBRConverter, 24)
actorsRTree.load(ingame.actorContainerActive.filter { it is ActorWithBody })
actorsRTree.load(ingame.actorContainerActive.filterIsInstance<ActorWithBody>())

View File

@@ -48,6 +48,7 @@ class UICheatDetected : UICanvas() {
}
override fun doOpening(delta: Float) {
Terrarum.ingame?.paused = true
}
override fun doClosing(delta: Float) {

View File

@@ -544,10 +544,12 @@ class UIInventoryFull(
override fun doOpening(delta: Float) {
Terrarum.ingame?.paused = true
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
}
override fun doClosing(delta: Float) {
Terrarum.ingame?.paused = false
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
}

View File

@@ -20,7 +20,7 @@ import org.dyn4j.geometry.Vector2
*
* Created by minjaesong on 2016-07-20.
*/
class uiQuickslotPie : UICanvas() {
class UIQuickslotPie : UICanvas() {
private val cellSize = ItemSlotImageFactory.slotImage.tileW
private val slotCount = UIQuickslotBar.SLOT_COUNT