Fix grabbing mouse input wasn't true grab
This commit is contained in:
parent
0432fa0ed9
commit
f3cb4772aa
@ -434,6 +434,16 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
return null
|
||||
}
|
||||
|
||||
fun isMouseGrabbed(): Boolean {
|
||||
for (panel in panels) {
|
||||
if (panel.isGrabbingMouseInput()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override fun render(poseStack: PoseStack, mouseX: Int, mouseY: Int, partialTick: Float) {
|
||||
val mouseXf = mouseX.toFloat()
|
||||
val mouseYf = mouseY.toFloat()
|
||||
|
@ -51,8 +51,11 @@ open class ButtonPanel<out S : Screen>(
|
||||
return true
|
||||
}
|
||||
|
||||
if (!tryToGrabMouseInput()) {
|
||||
return true
|
||||
}
|
||||
|
||||
pressed = true
|
||||
trapMouseInput = true
|
||||
playGuiClickSound()
|
||||
return true
|
||||
}
|
||||
@ -62,7 +65,7 @@ open class ButtonPanel<out S : Screen>(
|
||||
return true
|
||||
}
|
||||
|
||||
trapMouseInput = false
|
||||
grabMouseInput = false
|
||||
pressed = false
|
||||
|
||||
if (isHovered) {
|
||||
@ -83,7 +86,7 @@ open class ButtonPanel<out S : Screen>(
|
||||
if (field != value) {
|
||||
if (!value) {
|
||||
pressed = false
|
||||
trapMouseInput = false
|
||||
grabMouseInput = false
|
||||
}
|
||||
|
||||
field = value
|
||||
@ -142,7 +145,7 @@ abstract class RectangleButtonPanel<out S : Screen>(
|
||||
if (field != value) {
|
||||
if (!value) {
|
||||
pressed = false
|
||||
trapMouseInput = false
|
||||
grabMouseInput = false
|
||||
}
|
||||
|
||||
field = value
|
||||
@ -167,8 +170,9 @@ abstract class RectangleButtonPanel<out S : Screen>(
|
||||
playGuiClickSound()
|
||||
}
|
||||
|
||||
pressed = true
|
||||
trapMouseInput = true
|
||||
if (tryToGrabMouseInput()) {
|
||||
pressed = true
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
@ -183,7 +187,7 @@ abstract class RectangleButtonPanel<out S : Screen>(
|
||||
}
|
||||
}
|
||||
|
||||
trapMouseInput = false
|
||||
grabMouseInput = false
|
||||
|
||||
return true
|
||||
}
|
||||
@ -319,7 +323,7 @@ abstract class EnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean {
|
||||
if (!isHovered && !isTrappingMouseInput()) {
|
||||
if (!isHovered && !isGrabbingMouseInput()) {
|
||||
return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick)
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package ru.dbotthepony.mc.otm.client.screen.panels
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
open class DiscreteScrollBarPanel<S : Screen> @JvmOverloads constructor(
|
||||
@ -39,9 +38,8 @@ open class DiscreteScrollBarPanel<S : Screen> @JvmOverloads constructor(
|
||||
return true
|
||||
}
|
||||
|
||||
if (button == InputConstants.MOUSE_BUTTON_LEFT) {
|
||||
if (button == InputConstants.MOUSE_BUTTON_LEFT && tryToGrabMouseInput()) {
|
||||
isScrolling = true
|
||||
trapMouseInput = true
|
||||
rememberScroll = scroll
|
||||
rememberY = y
|
||||
}
|
||||
@ -52,7 +50,7 @@ open class DiscreteScrollBarPanel<S : Screen> @JvmOverloads constructor(
|
||||
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
||||
if (isScrolling && button == InputConstants.MOUSE_BUTTON_LEFT) {
|
||||
isScrolling = false
|
||||
trapMouseInput = false
|
||||
grabMouseInput = false
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ru.dbotthepony.mc.otm.client.screen.panels
|
||||
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
|
||||
open class DraggableCanvasPanel<out S : Screen> @JvmOverloads constructor(
|
||||
screen: S,
|
||||
@ -15,13 +14,17 @@ open class DraggableCanvasPanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||
dragging = true
|
||||
trapMouseInput = true
|
||||
|
||||
if (tryToGrabMouseInput()) {
|
||||
grabMouseInput = true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
||||
dragging = false
|
||||
trapMouseInput = false
|
||||
grabMouseInput = false
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,25 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
var acceptMouseInput = true
|
||||
var acceptKeyboardInput = true
|
||||
var trapMouseInput = false
|
||||
var grabMouseInput = false
|
||||
|
||||
fun tryToGrabMouseInput(): Boolean {
|
||||
if (grabMouseInput) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (screen !is MatteryScreen<*>) {
|
||||
grabMouseInput = true
|
||||
return true
|
||||
}
|
||||
|
||||
if (screen.isMouseGrabbed()) {
|
||||
return false
|
||||
}
|
||||
|
||||
grabMouseInput = true
|
||||
return true
|
||||
}
|
||||
|
||||
var tooltip: Component? = null
|
||||
set(value) {
|
||||
@ -541,7 +559,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
mouseY <= absoluteY + height) to null
|
||||
}
|
||||
|
||||
if (trapMouseInput && this is ISlotPanel<*>) {
|
||||
if (grabMouseInput && this is ISlotPanel<*>) {
|
||||
return true to this.slot
|
||||
}
|
||||
|
||||
@ -581,7 +599,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
mouseY <= absoluteY + height) to ItemStack.EMPTY
|
||||
}
|
||||
|
||||
if (trapMouseInput && this is IItemStackPanel) {
|
||||
if (grabMouseInput && this is IItemStackPanel) {
|
||||
return true to this.itemStack
|
||||
}
|
||||
|
||||
@ -1016,13 +1034,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
return children[index]
|
||||
}
|
||||
|
||||
fun isTrappingMouseInput(): Boolean {
|
||||
if (trapMouseInput) {
|
||||
fun isGrabbingMouseInput(): Boolean {
|
||||
if (grabMouseInput) {
|
||||
return true
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.isTrappingMouseInput()) {
|
||||
if (child.isGrabbingMouseInput()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -1072,7 +1090,14 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
final override fun mouseClicked(x: Double, y: Double, button: Int): Boolean {
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
|
||||
if (trapMouseInput) return mouseClickedInner(x, y, button)
|
||||
if (grabMouseInput) return mouseClickedInner(x, y, button)
|
||||
|
||||
for (child in children) {
|
||||
if (child.isGrabbingMouseInput() && child.mouseClickedChecked(x, y, button)) {
|
||||
killFocusForEverythingExcept(child)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.mouseClickedChecked(x, y, button)) {
|
||||
@ -1087,7 +1112,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
fun mouseClickedChecked(x: Double, y: Double, button: Int): Boolean {
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
|
||||
if (isTrappingMouseInput() || withinBounds(x, y)) {
|
||||
if (isGrabbingMouseInput() || withinBounds(x, y)) {
|
||||
if (acceptMouseInput && parent == null) popup()
|
||||
return mouseClicked(x, y, button)
|
||||
} else if (withinExtendedBounds(x, y)) {
|
||||
@ -1113,7 +1138,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
final override fun mouseReleased(x: Double, y: Double, button: Int): Boolean {
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
|
||||
if (trapMouseInput) return mouseReleasedInner(x, y, button)
|
||||
if (grabMouseInput) return mouseReleasedInner(x, y, button)
|
||||
|
||||
for (child in children) {
|
||||
if (child.isGrabbingMouseInput() && child.mouseReleasedChecked(x, y, button)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.mouseReleasedChecked(x, y, button)) {
|
||||
@ -1127,7 +1158,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
fun mouseReleasedChecked(x: Double, y: Double, button: Int): Boolean {
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
|
||||
if (isTrappingMouseInput() || withinBounds(x, y)) {
|
||||
if (isGrabbingMouseInput() || withinBounds(x, y)) {
|
||||
return mouseReleased(x, y, button)
|
||||
} else if (withinExtendedBounds(x, y)) {
|
||||
for (child in children) {
|
||||
@ -1147,7 +1178,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
final override fun mouseDragged(x: Double, y: Double, button: Int, xDelta: Double, yDelta: Double): Boolean {
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
|
||||
if (trapMouseInput) return mouseDraggedInner(x, y, button, xDelta, yDelta)
|
||||
if (grabMouseInput) return mouseDraggedInner(x, y, button, xDelta, yDelta)
|
||||
|
||||
for (child in children) {
|
||||
if (child.isGrabbingMouseInput() && child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) {
|
||||
@ -1161,7 +1198,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
fun mouseDraggedChecked(x: Double, y: Double, button: Int, xDelta: Double, yDelta: Double): Boolean {
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
|
||||
if (isTrappingMouseInput() || withinBounds(x, y)) {
|
||||
if (isGrabbingMouseInput() || withinBounds(x, y)) {
|
||||
return mouseDragged(x, y, button, xDelta, yDelta)
|
||||
} else if (withinExtendedBounds(x, y)) {
|
||||
for (child in children) {
|
||||
@ -1182,7 +1219,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
final override fun mouseScrolled(x: Double, y: Double, scroll: Double): Boolean {
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
|
||||
if (trapMouseInput) return mouseScrolledInner(x, y, scroll)
|
||||
if (grabMouseInput) return mouseScrolledInner(x, y, scroll)
|
||||
|
||||
for (child in children) {
|
||||
if (child.isGrabbingMouseInput() && child.mouseScrolledChecked(x, y, scroll)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.mouseScrolledChecked(x, y, scroll)) {
|
||||
@ -1196,7 +1239,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
fun mouseScrolledChecked(x: Double, y: Double, scroll: Double): Boolean {
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
|
||||
if (isTrappingMouseInput() || withinBounds(x, y)) {
|
||||
if (isGrabbingMouseInput() || withinBounds(x, y)) {
|
||||
return mouseScrolled(x, y, scroll)
|
||||
} else if (withinExtendedBounds(x, y)) {
|
||||
for (child in children) {
|
||||
@ -1272,7 +1315,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
final override fun isMouseOver(x: Double, y: Double): Boolean { // called to check whenever we are hovering at this
|
||||
if (!isVisible() || !acceptMouseInput) return false
|
||||
if (isTrappingMouseInput()) return true
|
||||
if (isGrabbingMouseInput()) return true
|
||||
|
||||
val pos = localToScreen()
|
||||
return x >= pos.x && x <= pos.x + width && y >= pos.y && y + height <= pos.y
|
||||
|
@ -140,8 +140,7 @@ open class FramePanel<out S : Screen>(
|
||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||
val (_, y1) = screenToLocal(x, y)
|
||||
|
||||
if (parent == null && y1 >= 0 && y1 <= 12) {
|
||||
trapMouseInput = true
|
||||
if (parent == null && y1 >= 0 && y1 <= 12 && tryToGrabMouseInput()) {
|
||||
dragging = true
|
||||
return true
|
||||
}
|
||||
@ -151,7 +150,7 @@ open class FramePanel<out S : Screen>(
|
||||
|
||||
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
||||
if (dragging) {
|
||||
trapMouseInput = false
|
||||
grabMouseInput = false
|
||||
dragging = false
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user