LR click behav change/mouse clicks were sticky and causes unwanted behaviour on some fixture UIs

This commit is contained in:
minjaesong
2024-03-05 05:21:17 +09:00
parent 0090cc7d40
commit 5b5534bcb9
27 changed files with 206 additions and 181 deletions

View File

@@ -533,7 +533,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
fun getActorsAt(worldX: Double, worldY: Double): List<ActorWithBody> {
val outList = ArrayList<ActorWithBody>()
try {
actorsRTree.find(worldX, worldY, worldX, worldY, outList)
actorsRTree.find(worldX - 0.5, worldY - 0.5, worldX + 0.5, worldY + 0.5, outList)
}
catch (e: NullPointerException) {}
return outList

View File

@@ -7,11 +7,16 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameitems.ItemID
/**
* FIXME Constructor is super expensive
*
* Created by minjaesong on 2024-03-05.
*/
interface InternalActor {
}
/**
* Created by minjaesong on 2021-07-30.
*/
class WireActor : ActorWithBody, NoSerialise {
class WireActor : ActorWithBody, NoSerialise, InternalActor {
companion object {
val WIRE_NEARBY = arrayOf(

View File

@@ -208,7 +208,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
}
}
terrarumIngame.uiContainer.forEach { it?.keyDown(keycode) } // for KeyboardControlled UIcanvases
terrarumIngame.uiContainer.forEach { if (it?.justOpened == false) it.keyDown(keycode) } // for KeyboardControlled UIcanvases
// Debug UIs
if (keycode == Input.Keys.GRAVE) {
@@ -233,7 +233,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
terrarumIngame.uiQuickBar.setAsOpen()
}
terrarumIngame.uiContainer.forEach { it?.keyUp(keycode) } // for KeyboardControlled UIcanvases
terrarumIngame.uiContainer.forEach { if (it?.justOpened == false) it.keyUp(keycode) } // for KeyboardControlled UIcanvases
// screenshot key
if (keycode == Input.Keys.F12) f12Down = false
@@ -243,27 +243,25 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
}
override fun keyTyped(character: Char): Boolean {
terrarumIngame.uiContainer.forEach { if (it?.isVisible == true) it.keyTyped(character) }
terrarumIngame.uiContainer.forEach { if (it?.justOpened == false && it.isVisible) it.keyTyped(character) }
return true
}
private fun tTouchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (!terrarumIngame.paused && !terrarumIngame.playerControlDisabled) {
// 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) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
// disable the IFs: the "unlatching" must happen no matter what, even if a UI is been opened
if (
terrarumIngame.actorNowPlaying != null &&
(button == App.getConfigInt("config_mouseprimary") ||
button == App.getConfigInt("config_mousesecondary"))) {
// if (!terrarumIngame.paused && !terrarumIngame.playerControlDisabled) {
// 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) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
if (button == App.getConfigInt("config_mouseprimary")) {
terrarumIngame.worldPrimaryClickEnd(terrarumIngame.actorNowPlaying!!, App.UPDATE_RATE)
}
if (button == App.getConfigInt("config_mousesecondary")) {
terrarumIngame.worldSecondaryClickEnd(terrarumIngame.actorNowPlaying!!, App.UPDATE_RATE)
}
}
}
// }
// }
// pie menu
if (button == App.getConfigInt("control_mouse_quicksel")) {
@@ -271,7 +269,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
terrarumIngame.uiQuickBar.setAsOpen()
}
terrarumIngame.uiContainer.forEach { it?.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
terrarumIngame.uiContainer.forEach { if (it?.justOpened == false) it.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
return true
}
@@ -289,17 +287,17 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
it.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, selection fmod UIQuickslotBar.SLOT_COUNT)
}
}
terrarumIngame.uiContainer.forEach { it?.scrolled(amountX, amountY) }
terrarumIngame.uiContainer.forEach { if (it?.justOpened == false) it?.scrolled(amountX, amountY) }
return true
}
private fun tTouchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
terrarumIngame.uiContainer.forEach { it?.touchDragged(screenX, screenY, pointer) }
terrarumIngame.uiContainer.forEach { if (it?.justOpened == false) it.touchDragged(screenX, screenY, pointer) }
return true
}
private fun tTouchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
terrarumIngame.uiContainer.forEach { it?.touchDown(screenX, screenY, pointer, button) }
terrarumIngame.uiContainer.forEach { if (it?.justOpened == false) it.touchDown(screenX, screenY, pointer, button) }
// pie menu
if (button == App.getConfigInt("control_mouse_quicksel")) {

View File

@@ -256,8 +256,6 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
open fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long = -1
/**
* I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
*
* Apply effects (continuously or not) while secondary button is down
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item)
*
@@ -267,10 +265,10 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
*
* note: DO NOT super() this!
*/
//open fun startSecondaryUse(delta: Float): Boolean = false
open fun startSecondaryUse(actor: ActorWithBody, delta: Float): Long = -1
open fun endPrimaryUse(actor: ActorWithBody, delta: Float): Boolean = false
//open fun endSecondaryUse(actor: ActorWithBody, delta: Float): Boolean = false
open fun endSecondaryUse(actor: ActorWithBody, delta: Float): Boolean = false
/**
* Effects applied immediately only once when thrown (discarded) from pocket

View File

@@ -691,6 +691,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
private var worldPrimaryClickLatch = false
// 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) {
//println("[Ingame] worldPrimaryClickStart $delta")
@@ -699,6 +700,12 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
val itemOnGrip = ItemCodex[(actor as Pocketed).inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)]
// bring up the UIs of the fixtures (e.g. crafting menu from a crafting table)
var uiOpened = false
val fixtureUnderMouse0: List<FixtureBase> = getActorsUnderMouse(Terrarum.mouseX, Terrarum.mouseY).filterIsInstance<FixtureBase>()
if (fixtureUnderMouse0.size > 1) {
App.printdbgerr(this, "Multiple fixtures at world coord ${Terrarum.mouseX}, ${Terrarum.mouseY}")
}
val fixtureUnderMouse = fixtureUnderMouse0.firstOrNull()
////////////////////////////////
@@ -708,12 +715,41 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
val consumptionSuccessful = itemOnGrip.startPrimaryUse(actor, delta)
if (consumptionSuccessful > -1)
(actor as Pocketed).inventory.consumeItem(itemOnGrip, consumptionSuccessful)
worldPrimaryClickLatch = true
}
// #2. If I'm not holding any item and I can do barehandaction (size big enough that barehandactionminheight check passes), perform it
else if (itemOnGrip == null) {
else {
mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
performBarehandAction(actor, delta, mwx, mwy, mtx, mty)
0L
// #2. interact with the fixture
// scan for the one with non-null UI.
// what if there's multiple of such fixtures? whatever, you are supposed to DISALLOW such situation.
if (fixtureUnderMouse != null) {
if (!worldPrimaryClickLatch) {
worldPrimaryClickLatch = true
fixtureUnderMouse.let { fixture ->
fixture.mainUI?.let { ui ->
uiOpened = true
// property 'uiFixture' is a dedicated property that the TerrarumIngame recognises.
// 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
uiFixture = ui
ui.setPosition(
(Toolkit.drawWidth - ui.width) / 4,
(App.scr.height - ui.height) / 4 // what the fuck?
)
ui.setAsOpen()
}
}
}
0L
}
// #3. If not holding any item and can do barehandaction (size big enough that barehandactionminheight check passes), do it
else {
performBarehandAction(actor, delta, mwx, mwy, mtx, mty)
0L
}
}
}
}
@@ -728,46 +764,26 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
if (canPerformBarehandAction) {
endPerformBarehandAction(actor)
}
worldPrimaryClickLatch = false
}
// right click: use fixture
override fun worldSecondaryClickStart(actor: ActorWithBody, delta: Float) {
val itemOnGrip = ItemCodex[(actor as Pocketed).inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)]
var uiOpened = false
val actorsUnderMouse: List<FixtureBase> = getActorsAt(Terrarum.mouseX, Terrarum.mouseY).filterIsInstance<FixtureBase>()
if (actorsUnderMouse.size > 1) {
App.printdbgerr(this, "Multiple fixtures at world coord ${Terrarum.mouseX}, ${Terrarum.mouseY}")
// #1. If ~~there is no UI under and~~ I'm holding an item, use it
// don't want to open the UI and use the item at the same time, would ya?
if (itemOnGrip != null) {
val consumptionSuccessful = itemOnGrip.startSecondaryUse(actor, delta)
if (consumptionSuccessful > -1)
(actor as Pocketed).inventory.consumeItem(itemOnGrip, consumptionSuccessful)
}
// #1. Try to open a UI under the cursor
// 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 actorsUnderMouse.indices) {
if (mouseInInteractableRange(actor) { _, _, _, _ ->
actorsUnderMouse[kk].let { fixture ->
fixture.mainUI?.let { ui ->
uiOpened = true
// property 'uiFixture' is a dedicated property that the TerrarumIngame recognises.
// 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
uiFixture = ui
ui.setPosition(
(Toolkit.drawWidth - ui.width) / 4,
(App.scr.height - ui.height) / 4 // what the fuck?
)
// if (fixture.mainUIopenFun == null)
ui.setAsOpen()
// else
// fixture.mainUIopenFun!!.invoke(ui)
}
}
// #2. Try to pick up the fixture
else {
mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
pickupFixture(actor, delta, mwx, mwy, mtx, mty)
0L
} == 0L) break
}
if (!uiOpened) {
//...
}
}
}
@@ -1546,8 +1562,20 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
}
}
fun performBarehandAction(actor: ActorWithBody, delta: Float, mwx: Double, mwy: Double, mtx: Int, mty: Int) {
private fun getActorsAtVicinity(worldX: Double, worldY: Double, radius: Double): List<ActorWithBody> {
val outList = java.util.ArrayList<ActorWithBody>()
try {
actorsRTree.find(worldX - radius, worldY - radius, worldX + radius, worldY + radius, outList)
}
catch (e: NullPointerException) {
}
return outList
}
private fun getPunchSize(actor: ActorWithBody) = actor.scale * actor.actorValue.getAsDouble(AVKey.BAREHAND_BASE_DIGSIZE)!!
fun performBarehandAction(actor: ActorWithBody, delta: Float, mwx: Double, mwy: Double, mtx: Int, mty: Int) {
// for giant actors punching every structure pickaxe can dig out
val canAttackOrDig =
actor.scale * actor.baseHitboxH >= (actor.actorValue.getAsDouble(AVKey.BAREHAND_MINHEIGHT) ?: 4294967296.0)
@@ -1556,62 +1584,15 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
val canDigSoftTileOnly =
actor is ActorHumanoid && (actor.baseHitboxH * actor.scale) >= 32f
fun getActorsAtVicinity(worldX: Double, worldY: Double, radius: Double): List<ActorWithBody> {
val outList = java.util.ArrayList<ActorWithBody>()
try {
actorsRTree.find(worldX - radius, worldY - radius, worldX + radius, worldY + radius, outList)
}
catch (e: NullPointerException) {
}
return outList
}
val punchSize = actor.scale * actor.actorValue.getAsDouble(AVKey.BAREHAND_BASE_DIGSIZE)!!
val punchSize = getPunchSize(actor)
val punchBlockSize = punchSize.div(TILE_SIZED).floorToInt()
val mouseUnderPunchableTree = BlockCodex[world.getTileFromTerrain(mtx, mty)].hasAnyTagOf("LEAVES", "TREESMALL")
// if there are attackable actor or fixtures
val actorsUnderMouse: List<ActorWithBody> = getActorsAtVicinity(mwx, mwy, punchSize / 2.0).sortedBy {
(mwx - it.hitbox.centeredX).sqr() + (mwy - it.hitbox.centeredY).sqr()
} // sorted by the distance from the mouse
// prioritise actors
val fixturesUnderHand = ArrayList<FixtureBase>()
val mobsUnderHand = ArrayList<ActorWithBody>()
actorsUnderMouse.forEach {
if (it is FixtureBase) // && it.mainUI == null) // pickup avail check must be done against fixture.canBeDespawned
fixturesUnderHand.add(it)
else if (it !is FixtureBase)
mobsUnderHand.add(it)
}
// pickup a fixture
if (fixturesUnderHand.size > 0 && fixturesUnderHand[0].canBeDespawned &&
System.nanoTime() - fixturesUnderHand[0].spawnRequestedTime > 500000000) { // don't pick up the fixture if it was recently placed (0.5 seconds)
val fixture = fixturesUnderHand[0]
val fixtureItem = ItemCodex.fixtureToItemID(fixture)
printdbg(this, "Fixture pickup at F${WORLD_UPDATE_TIMER}: ${fixture.javaClass.canonicalName} -> $fixtureItem")
// 0. hide tooltips
setTooltipMessage(null)
// 1. put the fixture to the inventory
fixture.flagDespawn()
// 2. register this item(fixture) to the quickslot so that the player sprite would be actually lifting the fixture
if (actor is Pocketed) {
actor.inventory.add(fixtureItem)
actor.equipItem(fixtureItem)
actor.inventory.setQuickslotItemAtSelected(fixtureItem)
// 2-1. unregister if other slot has the same item
for (k in 0..9) {
if (actor.inventory.getQuickslotItem(k)?.itm == fixtureItem && k != actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)) {
actor.inventory.setQuickslotItem(k, null)
}
}
}
}
// punch a small tree/shrub
else if (mouseUnderPunchableTree) {
if (mouseUnderPunchableTree) {
barehandAxeInUse = true
AxeCore.startPrimaryUse(actor, delta, null, mtx, mty, punchBlockSize.coerceAtLeast(1), punchBlockSize.coerceAtLeast(1), listOf("TREESMALL"))
}
@@ -1634,6 +1615,55 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
}
}
private fun getActorsUnderMouse(mwx: Double, mwy: Double): List<ActorWithBody> {
val actorsUnderMouse: List<ActorWithBody> = getActorsAt(mwx, mwy).filter { it !is InternalActor }.sortedBy {
(mwx - it.hitbox.centeredX).sqr() + (mwy - it.hitbox.centeredY).sqr()
} // sorted by the distance from the mouse
return actorsUnderMouse
}
fun pickupFixture(actor: ActorWithBody, delta: Float, mwx: Double, mwy: Double, mtx: Int, mty: Int, assignToQuickslot: Boolean = true) {
printdbg(this, "Pickup fixture fired")
val nearestActorUnderMouse = getActorsUnderMouse(mwx, mwy).firstOrNull()
// pickup a fixture
if (nearestActorUnderMouse != null && nearestActorUnderMouse is FixtureBase && nearestActorUnderMouse.canBeDespawned &&
System.nanoTime() - nearestActorUnderMouse.spawnRequestedTime > 500000000) { // don't pick up the fixture if it was recently placed (0.5 seconds)
val fixture = nearestActorUnderMouse
val fixtureItem = ItemCodex.fixtureToItemID(fixture)
printdbg(this, "Fixture pickup at F${WORLD_UPDATE_TIMER}: ${fixture.javaClass.canonicalName} -> $fixtureItem")
// 0. hide tooltips
setTooltipMessage(null)
if (!fixture.flagDespawn) {
// 1. put the fixture to the inventory
fixture.flagDespawn()
// 2. register this item(fixture) to the quickslot so that the player sprite would be actually lifting the fixture
if (actor is Pocketed) {
actor.inventory.add(fixtureItem)
if (assignToQuickslot) {
actor.equipItem(fixtureItem)
actor.inventory.setQuickslotItemAtSelected(fixtureItem)
// 2-1. unregister if other slot has the same item
for (k in 0..9) {
if (actor.inventory.getQuickslotItem(k)?.itm == fixtureItem && k != actor.actorValue.getAsInt(
AVKey.__PLAYER_QUICKSLOTSEL
)
) {
actor.inventory.setQuickslotItem(k, null)
}
}
}
}
}
}
else if (nearestActorUnderMouse != null && nearestActorUnderMouse.canBeDespawned) {
}
// TODO pickup a mob
}
override fun hide() {
uiContainer.forEach { it?.handler?.dispose() }
}

View File

@@ -65,7 +65,7 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
internal var disc: ItemID? = null
@Transient private val clickLatch = MouseLatch(listOf(App.getConfigInt("config_mousesecondary")))
@Transient private val clickLatch = MouseLatch()
override val canBeDespawned: Boolean
get() = disc == null

View File

@@ -59,7 +59,7 @@ class FixtureSignalSwitchManual : Electric {
setWireEmissionAt(0, 0, Vector2(state.toInt().toDouble(), 0.0))
}
@Transient private val clickLatch = MouseLatch(listOf(App.getConfigInt("config_mousesecondary")))
@Transient private val clickLatch = MouseLatch()
override fun updateImpl(delta: Float) {
super.updateImpl(delta)

View File

@@ -104,6 +104,11 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
// return true when placed, false when cannot be placed
}
override fun startSecondaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
(INGAME as TerrarumIngame).pickupFixture(actor, delta, mwx, mwy, mtx, mty, false)
-1
}
/**
* Also see: [net.torvald.terrarum.modulebasegame.gameactors.FixtureBase.Companion]
*/

View File

@@ -446,8 +446,6 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
itemListCraftable.numberMultiplier = 1L
}
private var openingClickLatched = false
override fun show() {
nearbyCraftingStations = getCraftingStationsWithinReach()
// printdbg(this, "Nearby crafting stations: $nearbyCraftingStations")
@@ -455,7 +453,7 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
playerThings.setGetInventoryFun { INGAME.actorNowPlaying!!.inventory }
itemListUpdate()
openingClickLatched = Terrarum.mouseDown
super.show()
tooltipShowing.clear()
INGAME.setTooltipMessage(null)
@@ -472,18 +470,9 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
encumbrancePerc = getPlayerInventory().encumberment.toFloat()
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (!openingClickLatched) {
return super.touchDown(screenX, screenY, pointer, button)
}
return false
}
override fun updateImpl(delta: Float) {
// NO super.update due to an infinite recursion
this.uiItems.forEach { it.update(delta) }
if (openingClickLatched && !Terrarum.mouseDown) openingClickLatched = false
}
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {

View File

@@ -180,6 +180,7 @@ internal class UIInventoryCells(
}
override fun show() {
super.show()
tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}

View File

@@ -304,6 +304,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
)
override fun show() {
super.show()
tooltipShowing.clear()
INGAME.setTooltipMessage(null)
toInitScreen()

View File

@@ -323,15 +323,11 @@ class UIInventoryFull(
}
override fun show() {
transitionPanel.show()
super.show()
tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
override fun hide() {
transitionPanel.hide()
}
internal var offsetX = ((width - internalWidth) / 2).toFloat()
private set
internal var offsetY = ((App.scr.height - internalHeight) / 2).toFloat()

View File

@@ -65,7 +65,7 @@ abstract class UIItemInventoryCellBase(
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (mouseUp) {
if (mouseUp && !parentUI.openingClickLatched) {
touchDownFun(item, amount, button, extraInfo, this)
super.touchDown(screenX, screenY, pointer, button)
}

View File

@@ -74,23 +74,20 @@ class UIJukebox : UICanvas(
addUIitem(transitionPanel)
}
private var openingClickLatched = false
override fun show() {
openingClickLatched = Terrarum.mouseDown
super.show()
transitionPanel.show()
tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
override fun hide() {
super.hide()
transitionPanel.hide()
}
override fun updateImpl(delta: Float) {
uiItems.forEach { it.update(delta) }
if (openingClickLatched && !Terrarum.mouseDown) openingClickLatched = false
}
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
@@ -108,10 +105,7 @@ class UIJukebox : UICanvas(
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (!openingClickLatched) {
return super.touchDown(screenX, screenY, pointer, button)
}
return false
return super.touchDown(screenX, screenY, pointer, button)
}
override fun doOpening(delta: Float) {

View File

@@ -141,6 +141,8 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
}
catch (e: UninitializedPropertyAccessException) {
}
super.show()
}
}
@@ -299,6 +301,7 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
}
override fun hide() {
super.hide()
showCalled = false
cellLoadThread.interrupt()
}

View File

@@ -132,6 +132,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
override fun show() {
// takeAutosaveSelectorDown()
super.show()
transitionPanel.show()
nodesForListing.parent = remoCon.treeRoot
@@ -140,6 +141,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
}
override fun hide() {
super.hide()
transitionPanel.hide()
}

View File

@@ -32,6 +32,8 @@ class UIShare : UICanvas() {
private var shareCode = ""
override fun show() {
super.show()
shareCode = Common.encodeUUID(INGAME.world.worldIndex)
App.printdbg(this, shareCode)

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.langpack.Lang
@@ -183,15 +184,13 @@ internal class UIStorageChest : UICanvas(
addUIitem(itemListPlayer)
}
private var openingClickLatched = false
override fun show() {
super.show()
itemListPlayer.itemList.getInventory = { INGAME.actorNowPlaying!!.inventory }
itemListUpdate()
openingClickLatched = Terrarum.mouseDown
tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
@@ -221,18 +220,13 @@ internal class UIStorageChest : UICanvas(
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (!openingClickLatched) {
return super.touchDown(screenX, screenY, pointer, button)
}
return false
return super.touchDown(screenX, screenY, pointer, button)
}
override fun updateImpl(delta: Float) {
catBar.update(delta)
itemListChest.update(delta)
itemListPlayer.update(delta)
if (openingClickLatched && !Terrarum.mouseDown) openingClickLatched = false
}
private val thisOffsetX = Toolkit.hdrawWidth - getWidthOfCells(6) - halfSlotOffset

View File

@@ -70,6 +70,7 @@ class UITemplateHalfInventory(
}
fun rebuild(category: Array<String>) {
itemList.rebuild(category)
}

View File

@@ -119,10 +119,12 @@ class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() {
override fun show() {
initialMouseBlock = true
super.show()
}
override fun hide() {
initialMouseBlock = true
super.hide()
}

View File

@@ -156,9 +156,8 @@ class UIWorldPortal : UICanvas(
}
override fun show() {
super.show()
transitionPanel.forcePosition(0)
transitionPanel.show()
super.show()
INGAME.setTooltipMessage(null)
// add current world to the player's worldportaldict
@@ -166,10 +165,6 @@ class UIWorldPortal : UICanvas(
cleanUpWorldDict()
}
override fun hide() {
transitionPanel.hide()
}
override fun dispose() {
transitionPanel.dispose()
}

View File

@@ -139,15 +139,13 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
addUIitem(itemListPlayer)
}
private var openingClickLatched = false
override fun show() {
super.show()
itemListPlayer.getInventory = { INGAME.actorNowPlaying!!.inventory }
itemListUpdate()
openingClickLatched = Terrarum.mouseDown
tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
@@ -177,9 +175,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (!openingClickLatched) {
return super.touchDown(screenX, screenY, pointer, button)
}
return super.touchDown(screenX, screenY, pointer, button)
return false
}
@@ -187,8 +183,6 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
catBar.update(delta)
itemListChest.update(delta)
itemListPlayer.update(delta)
if (openingClickLatched && !Terrarum.mouseDown) openingClickLatched = false
}
private val thisOffsetX = Toolkit.hdrawWidth - UIInventoryFull.getWidthOfCells(6) - halfSlotOffset

View File

@@ -304,6 +304,8 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
private var threadFired = false
override fun show() {
super.show()
listPage = 0
showSpinner = true
@@ -464,7 +466,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
}
override fun hide() {
uiItems.forEach { it.hide() }
super.hide()
if (::worldCells.isInitialized) worldCells.forEach { it.hide() }
if (::worldCells.isInitialized) worldCells.forEach { it.tryDispose() }
@@ -554,18 +556,6 @@ class UIItemWorldCellsSimple(
var highlighted = false
override fun show() {
super.show()
}
override fun hide() {
super.hide()
}
override fun update(delta: Float) {
super.update(delta)
}
fun render(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera, offX: Int, offY: Int) {
super.render(frameDelta, batch, camera)

View File

@@ -50,6 +50,8 @@ class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() {
private var shareCode = ""
override fun show() {
super.show()
shareCode = Common.encodeUUID(INGAME.world.worldIndex)

View File

@@ -65,6 +65,11 @@ abstract class UICanvas(
doNotWarnConstant: Boolean = false
): Disposable {
internal var openingClickLatched = false
val justOpened: Boolean
get() = handler.justOpened
abstract var width: Int
abstract var height: Int
@@ -130,6 +135,7 @@ abstract class UICanvas(
/** A function that is run ONCE when the UI is requested to be opened; will work identical to [endOpening] if [openCloseTime] is zero */
open fun show() {
openingClickLatched = true
uiItems.forEach { it.show() }
handler.subUIs.forEach { it.show() }
}
@@ -137,6 +143,7 @@ abstract class UICanvas(
open fun hide() {
uiItems.forEach { it.hide() }
handler.subUIs.forEach { it.hide() }
openingClickLatched = true // just in case `justOpened` detection fails
}
@@ -208,7 +215,7 @@ abstract class UICanvas(
}
/** Called by the screen's InputProcessor */
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (this.isVisible && mouseInScreen(screenX, screenY)) {
if (this.isVisible && mouseInScreen(screenX, screenY) && !openingClickLatched) {
uiItems.forEach { it.touchDown(screenX, screenY, pointer, button) }
handler.subUIs.forEach { it.touchDown(screenX, screenY, pointer, button) }
return true

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -109,6 +110,8 @@ void main() {
var openFired = false
var closeFired = false
internal var justOpened = true
var opacity = 1f
/*set(value) {
field = value
@@ -227,6 +230,10 @@ void main() {
if (isVisible || alwaysUpdate) {
ui.updateImpl(delta)
if (ui.openingClickLatched && !Terrarum.mouseDown) {
ui.openingClickLatched = false
// printdbg(this, "UIHandler.update Unlatching openingClick")
}
}
if (isOpening) {
@@ -241,11 +248,13 @@ void main() {
if (openCloseCounter < ui.openCloseTime) {
ui.doOpening(delta)
justOpened = false
// println("UIHandler.opening ${UI.javaClass.simpleName}")
}
else {
ui.doOpening(0f)
ui.endOpening(delta)
justOpened = false
isOpening = false
isClosing = false
isOpened = true
@@ -347,6 +356,8 @@ void main() {
openFired = true
openCloseCounter = 0f
justOpened = true
}
}

View File

@@ -155,6 +155,11 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
}
mouseOverCall?.updateImpl(delta)
if (mouseOverCall?.openingClickLatched == true && !Terrarum.mouseDown) {
mouseOverCall?.openingClickLatched = false
// App.printdbg(this, "UIItem.update Unlatching openingClick of mouseOverCall")
}
mouseUpListener.invoke(itemRelativeMouseX, itemRelativeMouseY)
}
else {