From d22f421bc4c6808f749a115e4760c5688b2904fa Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 15 Mar 2024 22:44:46 +0900 Subject: [PATCH] wire debugger tooltip fix/electronic components now need floor OR wall to spawn --- .../modulebasegame/gameactors/FixtureBase.kt | 17 +++++++++++++++-- .../gameactors/FixtureLogicSignalAdder.kt | 4 ++-- .../gameactors/FixtureLogicSignalBlocker.kt | 4 ++-- .../gameactors/FixtureLogicSignalBulb.kt | 3 ++- .../gameactors/FixtureLogicSignalEmitter.kt | 3 ++- .../gameactors/FixtureLogicSignalLatch.kt | 4 ++-- .../FixtureLogicSignalRepeaterHorz.kt | 4 ++-- .../FixtureLogicSignalSwitchManual.kt | 3 ++- .../gameitems/WireGraphDebugger.kt | 6 ++++++ .../ui/UIItemInventoryCellBase.kt | 3 +-- .../terrarum/ui/UIItemInventoryElemSimple.kt | 10 +++++----- .../terrarum/ui/UIItemInventoryElemWide.kt | 12 +++++------- 12 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 2bfdcc6e2..3f1302ce2 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -28,6 +28,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { @Transient open val spawnNeedsWall: Boolean = false @Transient open val spawnNeedsFloor: Boolean = true + // if both spawnNeedsWall and spawnNeedsFloor are true, the condition will be interpreted as OR-condition + /** Real time, in nanoseconds */ @Transient var spawnRequestedTime: Long = 0L protected set @@ -166,22 +168,33 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { cannotSpawn = everyBlockboxPos.any { (x, y) -> !BlockCodex[world!!.getTileFromTerrain(x, y)].hasTag("INCONSEQUENTIAL") } + + var cannotSpawnNoWall = false + var cannotSpawnNoFloor = false + // check for walls, if spawnNeedsWall = true if (spawnNeedsWall) { - cannotSpawn = cannotSpawn or everyBlockboxPos.any { (x, y) -> !BlockCodex[world!!.getTileFromWall(x, y)].isSolid } + cannotSpawnNoWall = everyBlockboxPos.any { (x, y) -> !BlockCodex[world!!.getTileFromWall(x, y)].isSolid } } // check for floors, if spawnNeedsFloor == true if (spawnNeedsFloor) { val y = posY + blockBox.height val xs = posX until posX + blockBox.width - cannotSpawn = cannotSpawn or xs.any { x -> + cannotSpawnNoFloor = xs.any { x -> world!!.getTileFromTerrain(x, y).let { !canSpawnOnThisFloor(it) } } } + if (spawnNeedsWall && spawnNeedsFloor) + cannotSpawn = cannotSpawn or (cannotSpawnNoWall && cannotSpawnNoFloor) + else if (spawnNeedsFloor) + cannotSpawn = cannotSpawn or cannotSpawnNoFloor + else if (spawnNeedsWall) + cannotSpawn = cannotSpawn or cannotSpawnNoWall + return !cannotSpawn } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalAdder.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalAdder.kt index a99272e0a..17fe08950 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalAdder.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalAdder.kt @@ -14,8 +14,8 @@ import org.dyn4j.geometry.Vector2 */ class FixtureLogicSignalAdder : Electric, Reorientable { - @Transient override val spawnNeedsWall = false - @Transient override val spawnNeedsFloor = false + @Transient override val spawnNeedsFloor = true + @Transient override val spawnNeedsWall = true constructor() : super( BlockBox(BlockBox.NO_COLLISION, 2, 2), diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBlocker.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBlocker.kt index 8554cb22c..f0b485464 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBlocker.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBlocker.kt @@ -34,8 +34,8 @@ interface Reorientable { */ class FixtureLogicSignalBlocker : Electric, Reorientable { - @Transient override val spawnNeedsWall = false - @Transient override val spawnNeedsFloor = false + @Transient override val spawnNeedsFloor = true + @Transient override val spawnNeedsWall = true constructor() : super( BlockBox(BlockBox.NO_COLLISION, 2, 2), diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBulb.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBulb.kt index 5b242e178..f3114df6a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBulb.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBulb.kt @@ -13,7 +13,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack */ class FixtureLogicSignalBulb : Electric { - @Transient override val spawnNeedsFloor = false + @Transient override val spawnNeedsFloor = true + @Transient override val spawnNeedsWall = true constructor() : super( BlockBox(BlockBox.NO_COLLISION, 1, 1), diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt index c750c1753..60c52a894 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt @@ -14,7 +14,8 @@ import org.dyn4j.geometry.Vector2 */ class FixtureLogicSignalEmitter : Electric { - @Transient override val spawnNeedsFloor = false + @Transient override val spawnNeedsFloor = true + @Transient override val spawnNeedsWall = true constructor() : super( BlockBox(BlockBox.NO_COLLISION, 1, 1), diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalLatch.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalLatch.kt index a27bab354..1618ee522 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalLatch.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalLatch.kt @@ -16,8 +16,8 @@ import org.dyn4j.geometry.Vector2 */ class FixtureLogicSignalLatch : Electric, Reorientable { - @Transient override val spawnNeedsWall = false - @Transient override val spawnNeedsFloor = false + @Transient override val spawnNeedsFloor = true + @Transient override val spawnNeedsWall = true constructor() : super( BlockBox(BlockBox.NO_COLLISION, 2, 3), diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt index 045ccd237..64ecf74a3 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt @@ -16,8 +16,8 @@ import org.dyn4j.geometry.Vector2 class FixtureLogicSignalRepeaterHorz : Electric, Reorientable { - @Transient override val spawnNeedsWall = false - @Transient override val spawnNeedsFloor = false + @Transient override val spawnNeedsFloor = true + @Transient override val spawnNeedsWall = true constructor() : super( BlockBox(BlockBox.NO_COLLISION, 2, 1), diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSwitchManual.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSwitchManual.kt index 449ca6c4e..0d0dedb5a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSwitchManual.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSwitchManual.kt @@ -14,7 +14,8 @@ import org.dyn4j.geometry.Vector2 */ class FixtureLogicSignalSwitchManual : Electric { - @Transient override val spawnNeedsFloor = false + @Transient override val spawnNeedsFloor = true + @Transient override val spawnNeedsWall = true constructor() : super( BlockBox(BlockBox.NO_COLLISION, 1, 1), diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/WireGraphDebugger.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/WireGraphDebugger.kt index b4152d01a..66fc394b5 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/WireGraphDebugger.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/WireGraphDebugger.kt @@ -9,9 +9,12 @@ import net.torvald.terrarum.gameactors.BlockMarkerActor import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.modulebasegame.TerrarumIngame +import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) { + @Transient private val tooltipHash = System.nanoTime() + override var baseToolSize: Double? = PickaxeCore.BASE_MASS_AND_SIZE override var inventoryCategory = Category.TOOL override val canBeDynamic = false @@ -62,9 +65,11 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) { } if (sb.isNotEmpty()) { + UIItemInventoryCellCommonRes.tooltipShowing[tooltipHash] = true (Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(sb.toString()) } else { + UIItemInventoryCellCommonRes.tooltipShowing[tooltipHash] = false (Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(null) } } @@ -73,5 +78,6 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) { (Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "" (Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(null) blockMarker.isVisible = false + UIItemInventoryCellCommonRes.tooltipShowing.remove(tooltipHash) } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt index 4c88dcb0b..f1f29b38f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt @@ -1,7 +1,6 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.Gdx -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch @@ -39,7 +38,7 @@ abstract class UIItemInventoryCellBase( abstract override fun update(delta: Float) abstract override fun render(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) - protected val hash = System.nanoTime() + protected val tooltipHash = System.nanoTime() /** Custom highlight rule to highlight tihs button to primary accent colour (blue by default). * Set to `null` to use default rule: diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt index af83ac398..e9c9891fc 100644 --- a/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt @@ -132,7 +132,7 @@ class UIItemInventoryElemSimple( // set tooltip accordingly - if (tooltipShowing[hash] != true && mouseUp) { + if (tooltipShowing[tooltipHash] != true && mouseUp) { // printdbg(this, "calling INGAME.setTooltipMessage by $hash") val grey = App.fontGame.toColorCode(11, 11, 11) @@ -145,7 +145,7 @@ class UIItemInventoryElemSimple( INGAME.setTooltipMessage(finalStr) - tooltipShowing[hash] = true + tooltipShowing[tooltipHash] = true // printdbg(this, tooltipShowing.entries) } } @@ -160,7 +160,7 @@ class UIItemInventoryElemSimple( } if (item == null || !mouseUp) { - tooltipShowing[hash] = false + tooltipShowing[tooltipHash] = false } // see IFs above? @@ -169,10 +169,10 @@ class UIItemInventoryElemSimple( } override fun dispose() { - tooltipShowing.remove(hash) + tooltipShowing.remove(tooltipHash) } override fun hide() { - tooltipShowing.remove(hash) + tooltipShowing.remove(tooltipHash) } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt b/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt index dca68029f..edd534397 100644 --- a/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt @@ -7,8 +7,6 @@ import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.* -import net.torvald.terrarum.App.IS_DEVELOPMENT_BUILD -import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme @@ -164,7 +162,7 @@ class UIItemInventoryElemWide( // set tooltip accordingly - if (tooltipShowing[hash] != true && item != null && mouseUp) { + if (tooltipShowing[tooltipHash] != true && item != null && mouseUp) { // printdbg(this, "calling INGAME.setTooltipMessage by $hash") val grey = App.fontGame.toColorCode(11, 11, 11) @@ -177,13 +175,13 @@ class UIItemInventoryElemWide( INGAME.setTooltipMessage(finalStr) - tooltipShowing[hash] = true + tooltipShowing[tooltipHash] = true // printdbg(this, tooltipShowing.entries) } } if (item == null || !mouseUp) { - tooltipShowing[hash] = false + tooltipShowing[tooltipHash] = false } // see IFs above? @@ -191,10 +189,10 @@ class UIItemInventoryElemWide( } override fun dispose() { - tooltipShowing.remove(hash) + tooltipShowing.remove(tooltipHash) } override fun hide() { - tooltipShowing.remove(hash) + tooltipShowing.remove(tooltipHash) } }