Mouse cursors support
This commit is contained in:
parent
005c8b0396
commit
c52995541b
src/main
java/ru/dbotthepony/mc/otm
kotlin/ru/dbotthepony/mc/otm/client
@ -241,6 +241,7 @@ public final class OverdriveThatMatters {
|
|||||||
EVENT_BUS.addListener(EventPriority.LOWEST, ClientTickHandlerKt::onClientTick);
|
EVENT_BUS.addListener(EventPriority.LOWEST, ClientTickHandlerKt::onClientTick);
|
||||||
EVENT_BUS.addListener(EventPriority.HIGHEST, ClientTickHandlerKt::onClientConnected);
|
EVENT_BUS.addListener(EventPriority.HIGHEST, ClientTickHandlerKt::onClientConnected);
|
||||||
EVENT_BUS.addListener(EventPriority.HIGHEST, ClientTickHandlerKt::onClientDisconnected);
|
EVENT_BUS.addListener(EventPriority.HIGHEST, ClientTickHandlerKt::onClientDisconnected);
|
||||||
|
EVENT_BUS.addListener(EventPriority.NORMAL, ClientTickHandlerKt::onClientPostRender);
|
||||||
EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandlerKt::tooltipEvent);
|
EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandlerKt::tooltipEvent);
|
||||||
|
|
||||||
EVENT_BUS.addListener(EventPriority.NORMAL, QuantumBatteryItem.Companion::clientDisconnect);
|
EVENT_BUS.addListener(EventPriority.NORMAL, QuantumBatteryItem.Companion::clientDisconnect);
|
||||||
@ -254,5 +255,6 @@ public final class OverdriveThatMatters {
|
|||||||
EVENT_BUS.addListener(EventPriority.NORMAL, ExosuitModel::onPlayerRendered);
|
EVENT_BUS.addListener(EventPriority.NORMAL, ExosuitModel::onPlayerRendered);
|
||||||
|
|
||||||
event.enqueueWork(GlobalEventHandlerKt::recordClientThread);
|
event.enqueueWork(GlobalEventHandlerKt::recordClientThread);
|
||||||
|
event.enqueueWork(ClientTickHandlerKt::createCursors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,62 @@ package ru.dbotthepony.mc.otm.client
|
|||||||
|
|
||||||
import net.minecraftforge.client.event.ClientPlayerNetworkEvent
|
import net.minecraftforge.client.event.ClientPlayerNetworkEvent
|
||||||
import net.minecraftforge.event.TickEvent
|
import net.minecraftforge.event.TickEvent
|
||||||
|
import net.minecraftforge.event.TickEvent.RenderTickEvent
|
||||||
|
import org.lwjgl.glfw.GLFW
|
||||||
import ru.dbotthepony.mc.otm.core.util.IConditionalTickable
|
import ru.dbotthepony.mc.otm.core.util.IConditionalTickable
|
||||||
import ru.dbotthepony.mc.otm.core.util.ITickable
|
import ru.dbotthepony.mc.otm.core.util.ITickable
|
||||||
import ru.dbotthepony.mc.otm.core.util.TickList
|
import ru.dbotthepony.mc.otm.core.util.TickList
|
||||||
|
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
||||||
import ru.dbotthepony.mc.otm.isClient
|
import ru.dbotthepony.mc.otm.isClient
|
||||||
|
import java.util.function.LongSupplier
|
||||||
|
|
||||||
private val preTickList = TickList()
|
private val preTickList = TickList()
|
||||||
private val postTickList = TickList()
|
private val postTickList = TickList()
|
||||||
|
|
||||||
|
var MODIFIED_CURSOR = false
|
||||||
|
private set
|
||||||
|
|
||||||
|
private var MODIFIED_CURSOR_FRAMES = 3
|
||||||
|
|
||||||
|
private var ARROW_CURSOR by WriteOnce<Long>()
|
||||||
|
private var BEAM_CURSOR by WriteOnce<Long>()
|
||||||
|
private var HAND_CURSOR by WriteOnce<Long>()
|
||||||
|
private var NOT_ALLOWED_CURSOR by WriteOnce<Long>()
|
||||||
|
private var CROSSHAIR_CURSOR by WriteOnce<Long>()
|
||||||
|
|
||||||
|
fun createCursors() {
|
||||||
|
ARROW_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR)
|
||||||
|
BEAM_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_IBEAM_CURSOR)
|
||||||
|
HAND_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_POINTING_HAND_CURSOR)
|
||||||
|
NOT_ALLOWED_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_NOT_ALLOWED_CURSOR)
|
||||||
|
CROSSHAIR_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_CROSSHAIR_CURSOR)
|
||||||
|
|
||||||
|
check(ARROW_CURSOR != 0L) { "Failed to create ARROW_CURSOR. Are we not on main game thread?" }
|
||||||
|
check(BEAM_CURSOR != 0L) { "Failed to create BEAM_CURSOR. Are we not on main game thread?" }
|
||||||
|
check(HAND_CURSOR != 0L) { "Failed to create HAND_CURSOR. Are we not on main game thread?" }
|
||||||
|
check(NOT_ALLOWED_CURSOR != 0L) { "Failed to create NOT_ALLOWED_CURSOR. Are we not on main game thread?" }
|
||||||
|
check(CROSSHAIR_CURSOR != 0L) { "Failed to create CROSSHAIR_CURSOR. Are we not on main game thread?" }
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class CursorType(val pointer: LongSupplier) {
|
||||||
|
ARROW(::ARROW_CURSOR), BEAM(::BEAM_CURSOR), HAND(::HAND_CURSOR), NOT_ALLOWED(::NOT_ALLOWED_CURSOR), CROSSHAIR(::CROSSHAIR_CURSOR);
|
||||||
|
|
||||||
|
fun setTo() {
|
||||||
|
GLFW.glfwSetCursor(minecraft.window.window, pointer.asLong)
|
||||||
|
MODIFIED_CURSOR = true
|
||||||
|
MODIFIED_CURSOR_FRAMES = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onClientPostRender(event: RenderTickEvent) {
|
||||||
|
if (event.phase == TickEvent.Phase.END) {
|
||||||
|
if (MODIFIED_CURSOR_FRAMES-- <= 0 && MODIFIED_CURSOR) {
|
||||||
|
GLFW.glfwSetCursor(minecraft.window.window, ARROW_CURSOR)
|
||||||
|
MODIFIED_CURSOR = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var LOGGED_IN = false
|
var LOGGED_IN = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import net.minecraft.client.gui.screens.Screen
|
|||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||||
|
import ru.dbotthepony.mc.otm.client.CursorType
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
||||||
import ru.dbotthepony.mc.otm.client.render.sprites.MatterySprite
|
import ru.dbotthepony.mc.otm.client.render.sprites.MatterySprite
|
||||||
@ -39,6 +40,9 @@ open class ColorBoxPanel<out S : Screen>(
|
|||||||
var markerPos = backgroundColor.toHSV()
|
var markerPos = backgroundColor.toHSV()
|
||||||
protected set
|
protected set
|
||||||
|
|
||||||
|
override val cursorType: CursorType
|
||||||
|
get() = if (isDisabled.get()) CursorType.NOT_ALLOWED else CursorType.CROSSHAIR
|
||||||
|
|
||||||
fun setColor(color: Either<RGBAColor, HSVColor>) {
|
fun setColor(color: Either<RGBAColor, HSVColor>) {
|
||||||
color.map(
|
color.map(
|
||||||
{ markerPos = it.toHSV(); if (it.canRepresentHue()) backgroundColor = HSVColor(it.toHSV().hue, 1f, 1f).toRGBA() },
|
{ markerPos = it.toHSV(); if (it.canRepresentHue()) backgroundColor = HSVColor(it.toHSV().hue, 1f, 1f).toRGBA() },
|
||||||
@ -146,6 +150,9 @@ abstract class AbstractColorWangPanel<out S : Screen>(
|
|||||||
|
|
||||||
protected abstract fun onWangInput(newPosition: Float)
|
protected abstract fun onWangInput(newPosition: Float)
|
||||||
|
|
||||||
|
override val cursorType: CursorType
|
||||||
|
get() = if (isDisabled.get()) CursorType.NOT_ALLOWED else CursorType.ARROW
|
||||||
|
|
||||||
init {
|
init {
|
||||||
scissor = true
|
scissor = true
|
||||||
}
|
}
|
||||||
@ -577,6 +584,9 @@ open class ColorPickerPanel<out S : Screen>(
|
|||||||
val middleStrip = EditablePanel(screen, this)
|
val middleStrip = EditablePanel(screen, this)
|
||||||
val palette = ColorPalettePanel(screen, this, callback = { onPaletteChoose(it) }, isDisabled = isDisabled)
|
val palette = ColorPalettePanel(screen, this, callback = { onPaletteChoose(it) }, isDisabled = isDisabled)
|
||||||
|
|
||||||
|
override val cursorType: CursorType
|
||||||
|
get() = if (isDisabled.get()) CursorType.NOT_ALLOWED else CursorType.ARROW
|
||||||
|
|
||||||
val hexInput = object : TextInputPanel<S>(screen, middleStrip, width = 50f) {
|
val hexInput = object : TextInputPanel<S>(screen, middleStrip, width = 50f) {
|
||||||
init {
|
init {
|
||||||
dock = Dock.RIGHT
|
dock = Dock.RIGHT
|
||||||
|
@ -17,6 +17,7 @@ import net.minecraft.world.inventory.Slot
|
|||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.mc.otm.SystemTime
|
import ru.dbotthepony.mc.otm.SystemTime
|
||||||
|
import ru.dbotthepony.mc.otm.client.CursorType
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||||
@ -421,6 +422,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
var acceptMouseInput = true
|
var acceptMouseInput = true
|
||||||
var acceptKeyboardInput = true
|
var acceptKeyboardInput = true
|
||||||
var grabMouseInput = false
|
var grabMouseInput = false
|
||||||
|
open val cursorType: CursorType get() = CursorType.ARROW
|
||||||
|
|
||||||
fun tryToGrabMouseInput(): Boolean {
|
fun tryToGrabMouseInput(): Boolean {
|
||||||
if (grabMouseInput) {
|
if (grabMouseInput) {
|
||||||
@ -898,6 +900,10 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
if (scissor) {
|
if (scissor) {
|
||||||
popScissorRect()
|
popScissorRect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isHovered) {
|
||||||
|
cursorType.setTo()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateAbsolutePosition() {
|
fun updateAbsolutePosition() {
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button
|
|||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants
|
import com.mojang.blaze3d.platform.InputConstants
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
|
import ru.dbotthepony.mc.otm.client.CursorType
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
@ -30,6 +31,9 @@ abstract class AbstractButtonPanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val cursorType: CursorType
|
||||||
|
get() = if (isDisabled) CursorType.NOT_ALLOWED else CursorType.ARROW
|
||||||
|
|
||||||
override fun test(value: Int): Boolean {
|
override fun test(value: Int): Boolean {
|
||||||
return value == InputConstants.MOUSE_BUTTON_LEFT
|
return value == InputConstants.MOUSE_BUTTON_LEFT
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.client.screen.panels.input
|
|||||||
|
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import ru.dbotthepony.mc.otm.client.CursorType
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import ru.dbotthepony.mc.otm.core.TextComponent
|
import ru.dbotthepony.mc.otm.core.TextComponent
|
||||||
@ -14,7 +15,7 @@ open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
parent: EditablePanel<*>?,
|
parent: EditablePanel<*>?,
|
||||||
val networkValue: () -> BigDecimal,
|
val networkValue: () -> BigDecimal,
|
||||||
val callback: (BigDecimal) -> Unit,
|
val callback: (BigDecimal) -> Unit,
|
||||||
val isAvailable: BooleanSupplier = BooleanSupplier { true },
|
val isEnabled: BooleanSupplier = BooleanSupplier { true },
|
||||||
x: Float = 0f,
|
x: Float = 0f,
|
||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float = 0f,
|
width: Float = 0f,
|
||||||
@ -35,7 +36,7 @@ open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
screen = screen,
|
screen = screen,
|
||||||
parent = parent,
|
parent = parent,
|
||||||
callback = widget::accept,
|
callback = widget::accept,
|
||||||
isAvailable = { widget.allowSpectators || minecraft.player?.isSpectator != true },
|
isEnabled = { widget.allowSpectators || minecraft.player?.isSpectator != true },
|
||||||
networkValue = networkValue,
|
networkValue = networkValue,
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
@ -48,7 +49,7 @@ open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
protected var inputStr = ""
|
protected var inputStr = ""
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
if (!isAvailable.asBoolean) {
|
if (!isEnabled.asBoolean) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
super.tickInner()
|
super.tickInner()
|
||||||
|
|
||||||
if (isFocusedThis) {
|
if (isFocusedThis) {
|
||||||
if (!isAvailable.asBoolean) {
|
if (!isEnabled.asBoolean) {
|
||||||
killFocus()
|
killFocus()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -70,7 +71,7 @@ open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
if (nextUpdateFromServer < System.currentTimeMillis()) {
|
if (nextUpdateFromServer < System.currentTimeMillis()) {
|
||||||
getOrCreateWidget().value = networkValue.invoke().toPlainString()
|
getOrCreateWidget().value = networkValue.invoke().toPlainString()
|
||||||
inputStr = getOrCreateWidget().value
|
inputStr = getOrCreateWidget().value
|
||||||
} else if (isAvailable.asBoolean) {
|
} else if (isEnabled.asBoolean) {
|
||||||
if (inputStr != getOrCreateWidget().value) {
|
if (inputStr != getOrCreateWidget().value) {
|
||||||
inputStr = getOrCreateWidget().value
|
inputStr = getOrCreateWidget().value
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import net.minecraft.client.gui.screens.Screen
|
|||||||
import net.minecraft.client.renderer.GameRenderer
|
import net.minecraft.client.renderer.GameRenderer
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import org.joml.Vector2i
|
import org.joml.Vector2i
|
||||||
|
import ru.dbotthepony.mc.otm.client.CursorType
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
import ru.dbotthepony.mc.otm.client.isCtrlDown
|
import ru.dbotthepony.mc.otm.client.isCtrlDown
|
||||||
import ru.dbotthepony.mc.otm.client.isShiftDown
|
import ru.dbotthepony.mc.otm.client.isShiftDown
|
||||||
@ -151,6 +152,9 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
open var backgroundColor = RGBAColor.BLACK
|
open var backgroundColor = RGBAColor.BLACK
|
||||||
open var isActive = true
|
open var isActive = true
|
||||||
|
|
||||||
|
override val cursorType: CursorType
|
||||||
|
get() = if (isActive) CursorType.BEAM else CursorType.NOT_ALLOWED
|
||||||
|
|
||||||
init {
|
init {
|
||||||
scissor = true
|
scissor = true
|
||||||
dockPadding = DockProperty(2f, 2f, 2f, 2f)
|
dockPadding = DockProperty(2f, 2f, 2f, 2f)
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.client.screen.panels.util
|
|||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants
|
import com.mojang.blaze3d.platform.InputConstants
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
|
import ru.dbotthepony.mc.otm.client.CursorType
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
||||||
@ -26,6 +27,9 @@ open class AnalogScrollBarPanel<out S : Screen>(
|
|||||||
var isScrolling = false
|
var isScrolling = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
override val cursorType: CursorType
|
||||||
|
get() = if (maxScroll.invoke(this@AnalogScrollBarPanel) <= 0) CursorType.NOT_ALLOWED else CursorType.ARROW
|
||||||
|
|
||||||
override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
if (this@AnalogScrollBarPanel.width == ScrollBarConstants.SLIM_WIDTH) {
|
if (this@AnalogScrollBarPanel.width == ScrollBarConstants.SLIM_WIDTH) {
|
||||||
if (isScrolling) {
|
if (isScrolling) {
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.client.screen.panels.util
|
|||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants
|
import com.mojang.blaze3d.platform.InputConstants
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
|
import ru.dbotthepony.mc.otm.client.CursorType
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@ -20,6 +21,9 @@ open class DiscreteScrollBarPanel<out S : Screen>(
|
|||||||
var isScrolling = false
|
var isScrolling = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
override val cursorType: CursorType
|
||||||
|
get() = if (maxScroll.invoke(this@DiscreteScrollBarPanel) <= 0) CursorType.NOT_ALLOWED else CursorType.ARROW
|
||||||
|
|
||||||
override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
if (this@DiscreteScrollBarPanel.width == ScrollBarConstants.SLIM_WIDTH) {
|
if (this@DiscreteScrollBarPanel.width == ScrollBarConstants.SLIM_WIDTH) {
|
||||||
if (isScrolling) {
|
if (isScrolling) {
|
||||||
|
Loading…
Reference in New Issue
Block a user