mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 04:54:05 +09:00
fixture clicking action is now integrated into the FixtureBase
This commit is contained in:
@@ -692,6 +692,13 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
|
|
||||||
private var worldPrimaryClickLatch = false
|
private var worldPrimaryClickLatch = false
|
||||||
|
|
||||||
|
private fun fireFixtureInteractEvent(fixture: FixtureBase, mwx: Double, mwy: Double) {
|
||||||
|
if (fixture.mouseUp) {
|
||||||
|
fixture.onInteract(mwx, mwy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// left click: use held item, attack, pick up fixture if i'm holding a pickaxe or hammer (aka tool), do 'bare hand action' if holding nothing
|
// left click: use held item, attack, pick up fixture if i'm holding a pickaxe or hammer (aka tool), do 'bare hand action' if holding nothing
|
||||||
override fun worldPrimaryClickStart(actor: ActorWithBody, delta: Float) {
|
override fun worldPrimaryClickStart(actor: ActorWithBody, delta: Float) {
|
||||||
//println("[Ingame] worldPrimaryClickStart $delta")
|
//println("[Ingame] worldPrimaryClickStart $delta")
|
||||||
@@ -709,13 +716,25 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
// #1. If ~~there is no UI under and~~ I'm holding an item, use it
|
// #1. If holding an item, use it
|
||||||
// don't want to open the UI and use the item at the same time, would ya?
|
// don't want to open the UI and use the item at the same time, would ya?
|
||||||
if (itemOnGrip != null) {
|
if (itemOnGrip != null) {
|
||||||
val consumptionSuccessful = itemOnGrip.startPrimaryUse(actor, delta)
|
val consumptionSuccessful = itemOnGrip.startPrimaryUse(actor, delta)
|
||||||
if (consumptionSuccessful > -1)
|
if (consumptionSuccessful > -1)
|
||||||
(actor as Pocketed).inventory.consumeItem(itemOnGrip, consumptionSuccessful)
|
(actor as Pocketed).inventory.consumeItem(itemOnGrip, consumptionSuccessful)
|
||||||
|
|
||||||
|
// TODO filter blocks/walls/wires/wire cutter
|
||||||
|
if (fixtureUnderMouse != null) {
|
||||||
|
if (!worldPrimaryClickLatch) {
|
||||||
|
mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
||||||
|
fixtureUnderMouse.let { fixture ->
|
||||||
|
fireFixtureInteractEvent(fixture, mwx, mwy)
|
||||||
|
}
|
||||||
|
0L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
worldPrimaryClickLatch = true
|
worldPrimaryClickLatch = true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -740,6 +759,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
)
|
)
|
||||||
ui.setAsOpen()
|
ui.setAsOpen()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!uiOpened) {
|
||||||
|
fireFixtureInteractEvent(fixture, mwx, mwy)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
0L
|
0L
|
||||||
|
|||||||
@@ -241,6 +241,19 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
*/
|
*/
|
||||||
open fun onSpawn(tx: Int, ty: Int) {}
|
open fun onSpawn(tx: Int, ty: Int) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the fixture has mainUI, do NOT override this function! Opening of the UI is handled by TerrarumIngame.worldPrimaryClickStart
|
||||||
|
*
|
||||||
|
* For someone might be concerened, you don't need to have a MouseLatch or worry about the `if (mouseUp)`; it's considered by the Ingame
|
||||||
|
*
|
||||||
|
* Fired when "just clicked" by mousePrimary
|
||||||
|
*
|
||||||
|
* @param mx Terrarum.mouseX (mouse position in the world)
|
||||||
|
* @param my Terrarum.omuseY (mouse position in the world)
|
||||||
|
*/
|
||||||
|
open fun onInteract(mx: Double, my: Double) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Making the sprite: do not address the CommonResourcePool directly; just do it like this snippet:
|
* Making the sprite: do not address the CommonResourcePool directly; just do it like this snippet:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
|
|||||||
constructor() : super(
|
constructor() : super(
|
||||||
BlockBox(BlockBox.NO_COLLISION, 1, 1),
|
BlockBox(BlockBox.NO_COLLISION, 1, 1),
|
||||||
nameFun = { Lang["ITEM_TURNTABLE"] }
|
nameFun = { Lang["ITEM_TURNTABLE"] }
|
||||||
) {
|
)
|
||||||
clickLatch.forceLatch()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transient var musicNowPlaying: MusicContainer? = null; private set
|
@Transient var musicNowPlaying: MusicContainer? = null; private set
|
||||||
|
|
||||||
@@ -67,42 +65,36 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
|
|||||||
|
|
||||||
internal var disc: ItemID? = null
|
internal var disc: ItemID? = null
|
||||||
|
|
||||||
@Transient private val clickLatch = MouseLatch()
|
|
||||||
|
|
||||||
override val canBeDespawned: Boolean
|
override val canBeDespawned: Boolean
|
||||||
get() = disc == null
|
get() = disc == null
|
||||||
|
|
||||||
override fun updateImpl(delta: Float) {
|
override fun onInteract(mx: Double, my: Double) {
|
||||||
super.updateImpl(delta)
|
if (disc == null) {
|
||||||
|
if (INGAME.actorNowPlaying != null) {
|
||||||
|
val itemOnGrip =
|
||||||
|
INGAME.actorNowPlaying!!.inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)
|
||||||
|
val itemProp = ItemCodex[itemOnGrip]
|
||||||
|
|
||||||
// right click
|
if (itemProp?.hasAllTagOf("MUSIC", "PHONO") == true) {
|
||||||
if (mouseUp) {
|
disc = itemOnGrip
|
||||||
clickLatch.latch {
|
INGAME.actorNowPlaying!!.removeItem(itemOnGrip!!)
|
||||||
if (disc == null) {
|
playDisc()
|
||||||
if (INGAME.actorNowPlaying != null) {
|
|
||||||
val itemOnGrip =
|
|
||||||
INGAME.actorNowPlaying!!.inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)
|
|
||||||
val itemProp = ItemCodex[itemOnGrip]
|
|
||||||
|
|
||||||
if (itemProp?.hasAllTagOf("MUSIC", "PHONO") == true) {
|
|
||||||
disc = itemOnGrip
|
|
||||||
INGAME.actorNowPlaying!!.removeItem(itemOnGrip!!)
|
|
||||||
playDisc()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stopGracefully()
|
|
||||||
PickaxeCore.dropItem(
|
|
||||||
disc!!,
|
|
||||||
intTilewiseHitbox.canonicalX.toInt(),
|
|
||||||
intTilewiseHitbox.canonicalY.toInt()
|
|
||||||
)
|
|
||||||
disc = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
stopGracefully()
|
||||||
|
PickaxeCore.dropItem(
|
||||||
|
disc!!,
|
||||||
|
intTilewiseHitbox.canonicalX.toInt(),
|
||||||
|
intTilewiseHitbox.canonicalY.toInt()
|
||||||
|
)
|
||||||
|
disc = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateImpl(delta: Float) {
|
||||||
|
super.updateImpl(delta)
|
||||||
|
|
||||||
// supress the normal background music playback
|
// supress the normal background music playback
|
||||||
if (musicIsPlaying && !flagDespawn) {
|
if (musicIsPlaying && !flagDespawn) {
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ class FixtureSignalSwitchManual : Electric {
|
|||||||
constructor() : super(
|
constructor() : super(
|
||||||
BlockBox(BlockBox.NO_COLLISION, 1, 1),
|
BlockBox(BlockBox.NO_COLLISION, 1, 1),
|
||||||
nameFun = { Lang["ITEM_LOGIC_SIGNAL_SWITCH"] }
|
nameFun = { Lang["ITEM_LOGIC_SIGNAL_SWITCH"] }
|
||||||
) {
|
)
|
||||||
clickLatch.forceLatch()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val variant = (Math.random() * 8).toInt()
|
private val variant = (Math.random() * 8).toInt()
|
||||||
private var state = false // false = off
|
private var state = false // false = off
|
||||||
@@ -61,19 +59,9 @@ class FixtureSignalSwitchManual : Electric {
|
|||||||
setWireEmissionAt(0, 0, Vector2(state.toInt().toDouble(), 0.0))
|
setWireEmissionAt(0, 0, Vector2(state.toInt().toDouble(), 0.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient private val clickLatch = MouseLatch()
|
override fun onInteract(mx: Double, my: Double) {
|
||||||
|
state = !state
|
||||||
override fun updateImpl(delta: Float) {
|
(sprite as SheetSpriteAnimation).currentRow = state.toInt()
|
||||||
super.updateImpl(delta)
|
setWireEmissionAt(0, 0, Vector2(state.toInt().toDouble(), 0.0))
|
||||||
|
|
||||||
// right click
|
|
||||||
if (mouseUp) {
|
|
||||||
clickLatch.latch {
|
|
||||||
state = !state
|
|
||||||
(sprite as SheetSpriteAnimation).currentRow = state.toInt()
|
|
||||||
setWireEmissionAt(0, 0, Vector2(state.toInt().toDouble(), 0.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -366,6 +366,25 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
|||||||
private var lastDoorHandler = 0 // 0: automatic, 1: manual
|
private var lastDoorHandler = 0 // 0: automatic, 1: manual
|
||||||
private var doorCloseQueueHandler = 0
|
private var doorCloseQueueHandler = 0
|
||||||
|
|
||||||
|
override fun onInteract(mx: Double, my: Double) {
|
||||||
|
// keep opened/closed as long as the mouse is down
|
||||||
|
if (doorStateTimer != 0f) {
|
||||||
|
oldStateBeforeMouseDown = doorState
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldStateBeforeMouseDown == 0) {
|
||||||
|
if (mouseOnLeftSide(mx, my))
|
||||||
|
openToLeft(1)
|
||||||
|
else if (mouseOnRightSide(mx, my))
|
||||||
|
openToRight(1)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
closeDoor(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
doorStateTimer = 0f
|
||||||
|
}
|
||||||
|
|
||||||
override fun updateImpl(delta: Float) {
|
override fun updateImpl(delta: Float) {
|
||||||
super.updateImpl(delta)
|
super.updateImpl(delta)
|
||||||
|
|
||||||
@@ -389,34 +408,10 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// manual opening/closing
|
// manual opening/closing
|
||||||
if (mouseUp && Gdx.input.isButtonPressed(App.getConfigInt("config_mousesecondary"))) {
|
// is handled on the onInteract()
|
||||||
|
|
||||||
INGAME.actorNowPlaying?.let { player ->
|
|
||||||
mouseInInteractableRange(player) { mx, my, _, _ ->
|
|
||||||
// keep opened/closed as long as the mouse is down
|
|
||||||
if (doorStateTimer != 0f) {
|
|
||||||
oldStateBeforeMouseDown = doorState
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldStateBeforeMouseDown == 0) {
|
|
||||||
if (mouseOnLeftSide(mx, my))
|
|
||||||
openToLeft(1)
|
|
||||||
else if (mouseOnRightSide(mx, my))
|
|
||||||
openToRight(1)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
closeDoor(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
doorStateTimer = 0f
|
|
||||||
|
|
||||||
0L
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// automatic opening/closing
|
// automatic opening/closing
|
||||||
else if (doorStateTimer > doorHoldLength[doorState]!!) {
|
if (doorStateTimer > doorHoldLength[doorState]!!) {
|
||||||
// val actors = INGAME.actorContainerActive.filterIsInstance<ActorWithBody>()
|
// val actors = INGAME.actorContainerActive.filterIsInstance<ActorWithBody>()
|
||||||
|
|
||||||
// auto opening and closing
|
// auto opening and closing
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class WireCutterAll(originalID: ItemID) : GameItem(originalID) {
|
|||||||
override var baseToolSize: Double? = baseMass
|
override var baseToolSize: Double? = baseMass
|
||||||
override var inventoryCategory = Category.TOOL
|
override var inventoryCategory = Category.TOOL
|
||||||
override val canBeDynamic = false
|
override val canBeDynamic = false
|
||||||
override val materialId = ""
|
override val materialId = "STAL" // this is to just increase the reach
|
||||||
override val itemImage: TextureRegion
|
override val itemImage: TextureRegion
|
||||||
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(1, 3)
|
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(1, 3)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user