utilising new mouselatch

This commit is contained in:
minjaesong
2024-01-10 01:46:39 +09:00
parent a149107b48
commit acaedc4d80
11 changed files with 45 additions and 40 deletions

View File

@@ -314,7 +314,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
// make button work
mouseLatch.latch {
if (mouseUp) mouseLatch.latch {
if (mouseOnButton != null) {
when (mouseOnButton) {
0 -> { // album

View File

@@ -503,13 +503,10 @@ class UIItemControlPaletteBaloon(val parent: UIKeyboardControlPanel, initialX: I
closeButton2.update(delta)
// close
if (!mouseLatched && mousePushed) {
mouseLatched = true
if (mouseUp) mouseLatch.latch {
parent.setControlOf(parent.keycapClicked, selected)
parent.keycapClicked = -13372
}
if (!mouseDown) mouseLatched = false
}
}

View File

@@ -44,6 +44,24 @@ class MouseLatch(val button: List<Int> = listOf(App.getConfigInt("config_mousepr
}
}
/**
* Your usual latch except it does not auto-unlatch
*/
fun latchNoRelease(action: () -> Unit) {
if (isNotLatched() && button.any { Gdx.input.isButtonPressed(it) }) {
status.set(true)
action()
}
}
fun forceLatch() {
status.set(true)
}
fun forceUnlatch() {
status.set(false)
}
fun unlatch() {
if (button.none { Gdx.input.isButtonPressed(it) }) {
status.set(false)

View File

@@ -99,7 +99,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
/** to be used by customised mouse handling */
protected var mouseLatched = false
protected var mouseLatch = MouseLatch()
/** UI to call (show up) while mouse is up */
open var mouseOverCall: UICanvas? = null

View File

@@ -41,6 +41,8 @@ class UIItemHorzSlider(
var value: Double = initialValue; private set
var selectionChangeListener: (Double) -> Unit = {}
private var mouseLatched = false // trust me this one needs its own binary latch
override fun update(delta: Float) {
super.update(delta)

View File

@@ -58,10 +58,10 @@ class UIItemList<Item: UIItem>(
/** (oldIndex: Int?, newIndex: Int) -> Unit */
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
private var clickLatched = false
private var clickLatch = MouseLatch()
override fun show() {
clickLatched = true
clickLatch.forceLatch()
}
@@ -94,7 +94,7 @@ class UIItemList<Item: UIItem>(
item.update(delta)
if (!clickLatched && item.mousePushed) {
if (item.mouseUp) clickLatch.latchNoRelease {
val oldIndex = selectedIndex
if (kinematic) {
@@ -114,9 +114,7 @@ class UIItemList<Item: UIItem>(
}
if (!Terrarum.mouseDown) {
clickLatched = false
}
clickLatch.latch { } // update to unlatch
oldPosX = posX
}

View File

@@ -101,14 +101,11 @@ class UIItemSpinner(
else
0
if (!mouseLatched && Terrarum.mouseDown && mouseOnButton in 1..2) {
mouseLatched = true
if (mouseOnButton in 1..2) mouseLatch.latch {
changeValueBy((mouseOnButton * 2) - 3)
fboUpdateLatch = true
selectionChangeListener(value)
}
else if (!Terrarum.mouseDown) mouseLatched = false
}
private var textCache = ""

View File

@@ -158,11 +158,11 @@ class UIItemTextButtonList(
private var highlighterYStart = highlightY
private var highlighterYEnd = highlightY
private var clickLatched = false
private var clickLatch = MouseLatch()
override fun show() {
// printdbg(this, "${this.javaClass.simpleName} show()")
clickLatched = true
clickLatch.forceLatch()
}
/** (oldIndex: Int?, newIndex: Int) -> Unit */
@@ -196,9 +196,7 @@ class UIItemTextButtonList(
buttons.forEachIndexed { index, btn ->
btn.update(delta)
if (!clickLatched && btn.mousePushed) {
clickLatched = true
if (btn.mouseUp) clickLatch.latchNoRelease {
val oldIndex = selectedIndex
// if (kinematic) {
@@ -217,9 +215,7 @@ class UIItemTextButtonList(
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
}
if (clickLatched && !Terrarum.mouseDown) {
clickLatched = false
}
clickLatch.latch { } // update to unlatch
oldPosX = posX
}

View File

@@ -133,7 +133,7 @@ class UIItemTextLineInput(
set(value) {
field = value
if (!value) {
mouseLatched = false
mouseLatch.forceUnlatch()
fboUpdateLatch = false
isEnabled = false
cursorOn = false
@@ -449,17 +449,15 @@ class UIItemTextLineInput(
}
}
if (mouseDown && !mouseLatched && mouseUpOnIMEButton) {
mouseLatch.latch {
if (mouseUpOnIMEButton) {
toggleIME()
mouseLatched = true
}
else if (mouseDown && !mouseLatched && mouseUpOnPasteButton) {
else if (mouseUpOnPasteButton) {
endComposing()
paste(Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints())
mouseLatched = true
}
if (!mouseDown) mouseLatched = false
}
imeOn = KeyToggler.isOn(ControlPresets.getKey("control_key_toggleime"))
}

View File

@@ -98,7 +98,7 @@ class UIItemTextSelector(
}
if (!mouseLatched && Terrarum.mouseDown) {
mouseLatch.latch {
if (paletteShowing && mouseOnPaletteItem != null ) {
selection = mouseOnPaletteItem!!
fboUpdateLatch = true
@@ -125,10 +125,7 @@ class UIItemTextSelector(
else {
paletteShowing = false
}
mouseLatched = true
}
else if (!Terrarum.mouseDown) mouseLatched = false
}
private val leftIcon = if (useSpinnerButtons) labels.get(9,2) else labels.get(16,0)

View File

@@ -36,6 +36,8 @@ class UIItemVertSlider(
var value: Double = initialValue; private set
var selectionChangeListener: (Double) -> Unit = {}
private var mouseLatched = false // trust me this one needs its own binary latch
init {
printdbg(this, "slider max=$max")
}