Return proper "input handled" booleans when possible

This commit is contained in:
DBotThePony 2023-01-27 12:29:57 +07:00
parent c47082e3f3
commit 864d8b8df2
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 31 additions and 14 deletions

View File

@ -318,10 +318,11 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
override fun mouseClicked(x: Double, y: Double, button: Int): Boolean {
var click = false
var focusKilled = false
for (panel in panels) {
if (click || !panel.mouseClickedChecked(x, y, button)) {
panel.killFocusForEverythingExceptInner()
focusKilled = panel.killFocusForEverythingExceptInner() || focusKilled
} else {
if (returnSlot != null) {
super.mouseClicked(x, y, button)
@ -332,7 +333,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
}
}
return true
return click || focusKilled
}
private var lastDragSlot: Slot? = null
@ -350,7 +351,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
}
}
return true
return false
}
override fun mouseReleased(p_97812_: Double, p_97813_: Double, p_97814_: Int): Boolean {
@ -388,7 +389,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
}
}
return true
return false
}
override fun keyReleased(p_94715_: Int, p_94716_: Int, p_94717_: Int): Boolean {
@ -398,7 +399,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
}
}
return true
return false
}
override fun charTyped(p_94683_: Char, p_94684_: Int): Boolean {
@ -408,7 +409,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
}
}
return true
return false
}
override fun keyPressed(key: Int, scancode: Int, mods: Int): Boolean {

View File

@ -1108,16 +1108,24 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
}
}
private fun killFocusInternal() {
private fun killFocusInternal(): Boolean {
var status = false
for (child in childrenInternal) {
child.killFocusInternal()
status = child.killFocusInternal() || status
}
if (isFocused) {
isFocused = false
status = true
}
grabMouseInput = false
if (grabMouseInput) {
grabMouseInput = false
status = true
}
return status
}
private fun killGrabMouseInput() {
@ -1128,13 +1136,17 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
grabMouseInput = false
}
fun killFocus() {
fun killFocus(): Boolean {
if (isEverFocused()) {
killFocusInternal()
val status = killFocusInternal()
findAbsoluteRoot().updateFocus()
return status
} else if (isGrabbingMouseInput()) {
killGrabMouseInput()
return true
}
return false
}
fun findHierarchicalFocus(): EditablePanel<*>? {
@ -1310,14 +1322,18 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
}
}
fun killFocusForEverythingExceptInner() {
fun killFocusForEverythingExceptInner(): Boolean {
var focusKilled = false
for (child in childrenInternal) {
child.killFocusForEverythingExceptInner()
focusKilled = child.killFocusForEverythingExceptInner() || focusKilled
}
if (autoKillFocus) {
killFocus()
focusKilled = killFocus() || focusKilled
}
return focusKilled
}
final override fun mouseClicked(x: Double, y: Double, button: Int): Boolean {