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

@@ -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 {