mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
utilising new mouselatch
This commit is contained in:
@@ -314,7 +314,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
|
|
||||||
|
|
||||||
// make button work
|
// make button work
|
||||||
mouseLatch.latch {
|
if (mouseUp) mouseLatch.latch {
|
||||||
if (mouseOnButton != null) {
|
if (mouseOnButton != null) {
|
||||||
when (mouseOnButton) {
|
when (mouseOnButton) {
|
||||||
0 -> { // album
|
0 -> { // album
|
||||||
|
|||||||
@@ -495,7 +495,7 @@ class UIItemControlPaletteBaloon(val parent: UIKeyboardControlPanel, initialX: I
|
|||||||
iconButtons.forEachIndexed { index, it ->
|
iconButtons.forEachIndexed { index, it ->
|
||||||
it.update(delta)
|
it.update(delta)
|
||||||
if (it.mousePushed) {
|
if (it.mousePushed) {
|
||||||
selected = index
|
selected = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,13 +503,10 @@ class UIItemControlPaletteBaloon(val parent: UIKeyboardControlPanel, initialX: I
|
|||||||
closeButton2.update(delta)
|
closeButton2.update(delta)
|
||||||
|
|
||||||
// close
|
// close
|
||||||
if (!mouseLatched && mousePushed) {
|
if (mouseUp) mouseLatch.latch {
|
||||||
mouseLatched = true
|
|
||||||
parent.setControlOf(parent.keycapClicked, selected)
|
parent.setControlOf(parent.keycapClicked, selected)
|
||||||
parent.keycapClicked = -13372
|
parent.keycapClicked = -13372
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mouseDown) mouseLatched = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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() {
|
fun unlatch() {
|
||||||
if (button.none { Gdx.input.isButtonPressed(it) }) {
|
if (button.none { Gdx.input.isButtonPressed(it) }) {
|
||||||
status.set(false)
|
status.set(false)
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
|
|
||||||
|
|
||||||
/** to be used by customised mouse handling */
|
/** to be used by customised mouse handling */
|
||||||
protected var mouseLatched = false
|
protected var mouseLatch = MouseLatch()
|
||||||
|
|
||||||
/** UI to call (show up) while mouse is up */
|
/** UI to call (show up) while mouse is up */
|
||||||
open var mouseOverCall: UICanvas? = null
|
open var mouseOverCall: UICanvas? = null
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ class UIItemHorzSlider(
|
|||||||
var value: Double = initialValue; private set
|
var value: Double = initialValue; private set
|
||||||
var selectionChangeListener: (Double) -> Unit = {}
|
var selectionChangeListener: (Double) -> Unit = {}
|
||||||
|
|
||||||
|
private var mouseLatched = false // trust me this one needs its own binary latch
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
|
|
||||||
|
|||||||
@@ -58,10 +58,10 @@ class UIItemList<Item: UIItem>(
|
|||||||
/** (oldIndex: Int?, newIndex: Int) -> Unit */
|
/** (oldIndex: Int?, newIndex: Int) -> Unit */
|
||||||
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
||||||
|
|
||||||
private var clickLatched = false
|
private var clickLatch = MouseLatch()
|
||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
clickLatched = true
|
clickLatch.forceLatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ class UIItemList<Item: UIItem>(
|
|||||||
item.update(delta)
|
item.update(delta)
|
||||||
|
|
||||||
|
|
||||||
if (!clickLatched && item.mousePushed) {
|
if (item.mouseUp) clickLatch.latchNoRelease {
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
|
|
||||||
if (kinematic) {
|
if (kinematic) {
|
||||||
@@ -114,9 +114,7 @@ class UIItemList<Item: UIItem>(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Terrarum.mouseDown) {
|
clickLatch.latch { } // update to unlatch
|
||||||
clickLatched = false
|
|
||||||
}
|
|
||||||
|
|
||||||
oldPosX = posX
|
oldPosX = posX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,14 +101,11 @@ class UIItemSpinner(
|
|||||||
else
|
else
|
||||||
0
|
0
|
||||||
|
|
||||||
if (!mouseLatched && Terrarum.mouseDown && mouseOnButton in 1..2) {
|
if (mouseOnButton in 1..2) mouseLatch.latch {
|
||||||
mouseLatched = true
|
|
||||||
|
|
||||||
changeValueBy((mouseOnButton * 2) - 3)
|
changeValueBy((mouseOnButton * 2) - 3)
|
||||||
fboUpdateLatch = true
|
fboUpdateLatch = true
|
||||||
selectionChangeListener(value)
|
selectionChangeListener(value)
|
||||||
}
|
}
|
||||||
else if (!Terrarum.mouseDown) mouseLatched = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var textCache = ""
|
private var textCache = ""
|
||||||
|
|||||||
@@ -158,11 +158,11 @@ class UIItemTextButtonList(
|
|||||||
private var highlighterYStart = highlightY
|
private var highlighterYStart = highlightY
|
||||||
private var highlighterYEnd = highlightY
|
private var highlighterYEnd = highlightY
|
||||||
|
|
||||||
private var clickLatched = false
|
private var clickLatch = MouseLatch()
|
||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
// printdbg(this, "${this.javaClass.simpleName} show()")
|
// printdbg(this, "${this.javaClass.simpleName} show()")
|
||||||
clickLatched = true
|
clickLatch.forceLatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** (oldIndex: Int?, newIndex: Int) -> Unit */
|
/** (oldIndex: Int?, newIndex: Int) -> Unit */
|
||||||
@@ -196,9 +196,7 @@ class UIItemTextButtonList(
|
|||||||
buttons.forEachIndexed { index, btn ->
|
buttons.forEachIndexed { index, btn ->
|
||||||
btn.update(delta)
|
btn.update(delta)
|
||||||
|
|
||||||
|
if (btn.mouseUp) clickLatch.latchNoRelease {
|
||||||
if (!clickLatched && btn.mousePushed) {
|
|
||||||
clickLatched = true
|
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
|
|
||||||
// if (kinematic) {
|
// if (kinematic) {
|
||||||
@@ -217,9 +215,7 @@ class UIItemTextButtonList(
|
|||||||
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clickLatched && !Terrarum.mouseDown) {
|
clickLatch.latch { } // update to unlatch
|
||||||
clickLatched = false
|
|
||||||
}
|
|
||||||
|
|
||||||
oldPosX = posX
|
oldPosX = posX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ class UIItemTextLineInput(
|
|||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
if (!value) {
|
if (!value) {
|
||||||
mouseLatched = false
|
mouseLatch.forceUnlatch()
|
||||||
fboUpdateLatch = false
|
fboUpdateLatch = false
|
||||||
isEnabled = false
|
isEnabled = false
|
||||||
cursorOn = false
|
cursorOn = false
|
||||||
@@ -449,17 +449,15 @@ class UIItemTextLineInput(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouseDown && !mouseLatched && mouseUpOnIMEButton) {
|
mouseLatch.latch {
|
||||||
toggleIME()
|
if (mouseUpOnIMEButton) {
|
||||||
mouseLatched = true
|
toggleIME()
|
||||||
|
}
|
||||||
|
else if (mouseUpOnPasteButton) {
|
||||||
|
endComposing()
|
||||||
|
paste(Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (mouseDown && !mouseLatched && mouseUpOnPasteButton) {
|
|
||||||
endComposing()
|
|
||||||
paste(Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints())
|
|
||||||
mouseLatched = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mouseDown) mouseLatched = false
|
|
||||||
|
|
||||||
imeOn = KeyToggler.isOn(ControlPresets.getKey("control_key_toggleime"))
|
imeOn = KeyToggler.isOn(ControlPresets.getKey("control_key_toggleime"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class UIItemTextSelector(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!mouseLatched && Terrarum.mouseDown) {
|
mouseLatch.latch {
|
||||||
if (paletteShowing && mouseOnPaletteItem != null ) {
|
if (paletteShowing && mouseOnPaletteItem != null ) {
|
||||||
selection = mouseOnPaletteItem!!
|
selection = mouseOnPaletteItem!!
|
||||||
fboUpdateLatch = true
|
fboUpdateLatch = true
|
||||||
@@ -125,10 +125,7 @@ class UIItemTextSelector(
|
|||||||
else {
|
else {
|
||||||
paletteShowing = false
|
paletteShowing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseLatched = true
|
|
||||||
}
|
}
|
||||||
else if (!Terrarum.mouseDown) mouseLatched = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val leftIcon = if (useSpinnerButtons) labels.get(9,2) else labels.get(16,0)
|
private val leftIcon = if (useSpinnerButtons) labels.get(9,2) else labels.get(16,0)
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ class UIItemVertSlider(
|
|||||||
var value: Double = initialValue; private set
|
var value: Double = initialValue; private set
|
||||||
var selectionChangeListener: (Double) -> Unit = {}
|
var selectionChangeListener: (Double) -> Unit = {}
|
||||||
|
|
||||||
|
private var mouseLatched = false // trust me this one needs its own binary latch
|
||||||
|
|
||||||
init {
|
init {
|
||||||
printdbg(this, "slider max=$max")
|
printdbg(this, "slider max=$max")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user