diff --git a/src/main/java/de/bixilon/minosoft/data/text/events/hover/TextHoverEvent.kt b/src/main/java/de/bixilon/minosoft/data/text/events/hover/TextHoverEvent.kt index 0738c23d4..0bc2cc820 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/events/hover/TextHoverEvent.kt +++ b/src/main/java/de/bixilon/minosoft/data/text/events/hover/TextHoverEvent.kt @@ -16,7 +16,7 @@ package de.bixilon.minosoft.data.text.events.hover import de.bixilon.kutil.json.JsonObject import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer -import de.bixilon.minosoft.gui.rendering.gui.popper.text.TextPopper +import de.bixilon.minosoft.gui.rendering.gui.gui.popper.text.TextPopper import glm_.vec2.Vec2i import javafx.scene.text.Text diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIElement.kt index 2725d5911..497d60df4 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIElement.kt @@ -14,9 +14,10 @@ package de.bixilon.minosoft.gui.rendering.gui import de.bixilon.minosoft.gui.rendering.RenderWindow +import de.bixilon.minosoft.gui.rendering.gui.input.DraggableHandler import de.bixilon.minosoft.gui.rendering.input.InputHandler -interface GUIElement : InputHandler { +interface GUIElement : InputHandler, DraggableHandler { val guiRenderer: GUIRenderer val renderWindow: RenderWindow var enabled: Boolean diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIElementDrawer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIElementDrawer.kt index 4947c0988..36d7c91e4 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIElementDrawer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIElementDrawer.kt @@ -15,7 +15,7 @@ package de.bixilon.minosoft.gui.rendering.gui import de.bixilon.kutil.time.TimeUtil import de.bixilon.minosoft.gui.rendering.gui.elements.Pollable -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.renderer.Drawable import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIRenderer.kt index 37a02daf3..ca656918a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/GUIRenderer.kt @@ -14,14 +14,16 @@ package de.bixilon.minosoft.gui.rendering.gui import de.bixilon.kutil.latch.CountUpAndDownLatch +import de.bixilon.kutil.watcher.DataWatcher.Companion.watched import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.config.profile.delegate.watcher.SimpleProfileDelegateWatcher.Companion.profileWatchRendering import de.bixilon.minosoft.gui.rendering.RenderWindow import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasManager import de.bixilon.minosoft.gui.rendering.gui.gui.GUIManager +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.DraggedManager +import de.bixilon.minosoft.gui.rendering.gui.gui.popper.PopperManager import de.bixilon.minosoft.gui.rendering.gui.hud.HUDManager import de.bixilon.minosoft.gui.rendering.gui.input.ModifierKeys -import de.bixilon.minosoft.gui.rendering.gui.popper.PopperManager import de.bixilon.minosoft.gui.rendering.input.InputHandler import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent import de.bixilon.minosoft.gui.rendering.renderer.Renderer @@ -31,6 +33,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.PolygonModes import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer import de.bixilon.minosoft.gui.rendering.system.base.phases.OtherDrawable import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes +import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.util.KUtil.toResourceLocation @@ -45,10 +48,11 @@ class GUIRenderer( ) : Renderer, InputHandler, OtherDrawable { private val profile = connection.profiles.gui override val renderSystem = renderWindow.renderSystem - var scaledSize: Vec2i = renderWindow.window.size + var scaledSize: Vec2i by watched(renderWindow.window.size) val gui = GUIManager(this) val hud = HUDManager(this) val popper = PopperManager(this) + val dragged = DraggedManager(this) var matrix: Mat4 = Mat4() private set var matrixChange = true @@ -59,14 +63,15 @@ class GUIRenderer( val shader = renderWindow.renderSystem.createShader("minosoft:hud".toResourceLocation()) val atlasManager = AtlasManager(renderWindow) - val currentCursorPosition: Vec2i - get() = Vec2i(renderWindow.inputHandler.currentMousePosition).scale() + var currentCursorPosition: Vec2i by watched(Vec2i.EMPTY) + private set override fun init(latch: CountUpAndDownLatch) { atlasManager.init() gui.init() hud.init() popper.init() + dragged.init() } override fun postInit(latch: CountUpAndDownLatch) { @@ -81,6 +86,7 @@ class GUIRenderer( gui.postInit() hud.postInit() popper.postInit() + dragged.postInit() } private fun recalculateMatrices(windowSize: Vec2i = renderWindow.window.size, scale: Float = profile.scale) { @@ -91,6 +97,7 @@ class GUIRenderer( gui.onMatrixChange() hud.onMatrixChange() popper.onMatrixChange() + dragged.onMatrixChange() } fun setup() { @@ -106,18 +113,32 @@ class GUIRenderer( } override fun onMouseMove(position: Vec2i): Boolean { - return gui.onMouseMove(position.scale()) + val scaledPosition = position.scale() + currentCursorPosition = scaledPosition + if (dragged.onMouseMove(scaledPosition)) { + return true + } + return gui.onMouseMove(scaledPosition) } override fun onCharPress(char: Int): Boolean { + if (dragged.onCharPress(char)) { + return true + } return gui.onCharPress(char) } override fun onKeyPress(type: KeyChangeTypes, key: KeyCodes): Boolean { + if (dragged.onKeyPress(type, key)) { + return true + } return gui.onKeyPress(type, key) } override fun onScroll(scrollOffset: Vec2d): Boolean { + if (dragged.onScroll(scrollOffset)) { + return true + } return gui.onScroll(scrollOffset) } @@ -125,6 +146,7 @@ class GUIRenderer( hud.draw() gui.draw() popper.draw() + dragged.draw() if (this.matrixChange) { this.matrixChange = false } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt index 228c96ef7..09faaec83 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt @@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.gui.elements import de.bixilon.minosoft.gui.rendering.RenderConstants import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.input.DraggableElement import de.bixilon.minosoft.gui.rendering.gui.input.InputElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMesh import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache @@ -31,7 +32,7 @@ import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList import glm_.vec2.Vec2i import glm_.vec4.Vec4i -abstract class Element(val guiRenderer: GUIRenderer, var initialCacheSize: Int = 1000) : InputElement { +abstract class Element(val guiRenderer: GUIRenderer, var initialCacheSize: Int = 1000) : InputElement, DraggableElement { var ignoreDisplaySize = false val renderWindow = guiRenderer.renderWindow open val activeWhenHidden = false diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ContainerItemsElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ContainerItemsElement.kt index a58233c95..42fb2e1d2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ContainerItemsElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ContainerItemsElement.kt @@ -21,6 +21,10 @@ import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.atlas.Vec2iBinding import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.gui.AbstractLayout +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.elements.item.FloatingItem +import de.bixilon.minosoft.gui.rendering.gui.input.mouse.MouseActions +import de.bixilon.minosoft.gui.rendering.gui.input.mouse.MouseButtons import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY @@ -35,7 +39,9 @@ class ContainerItemsElement( val slots: Int2ObjectOpenHashMap, // ToDo: Use an array? ) : Element(guiRenderer), AbstractLayout { private val itemElements: MutableMap = synchronizedMapOf() + private var floatingItem: FloatingItem? = null override var activeElement: ItemElement? = null + override var activeDragElement: ItemElement? = null private var update = true init { @@ -121,6 +127,29 @@ class ContainerItemsElement( return null } + override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean { + val consumed = super.onMouseAction(position, button, action) + if (action != MouseActions.PRESS) { + return consumed + } + + val activeElement = activeElement + val stack = activeElement?.stack + var floatingItem = this.floatingItem + if ((floatingItem != null && !floatingItem.visible) || stack?._valid != true) { + return consumed + } + floatingItem = FloatingItem(guiRenderer, activeElement.slotId, stack) + this.floatingItem = floatingItem + floatingItem.show() + + return true + } + + override fun onDragMove(position: Vec2i, absolute: Vec2i, draggable: Dragged): Element? { + println("Drag: ($draggable) at $position") + return this + } private data class ItemElementData( val element: ItemElement, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ItemElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ItemElement.kt index 8f28dc40c..40cd3d58a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ItemElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ItemElement.kt @@ -31,10 +31,10 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.VerticalAlignments.Compani import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ColorElement import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ImageElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.popper.item.ItemInfoPopper import de.bixilon.minosoft.gui.rendering.gui.input.ModifierKeys import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions -import de.bixilon.minosoft.gui.rendering.gui.popper.item.ItemInfoPopper import de.bixilon.minosoft.gui.rendering.system.window.CursorShapes import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.EMPTY @@ -182,9 +182,11 @@ class ItemElement( return stack.toString() } - private companion object { + companion object { private val NEGATIVE_INFINITE_TEXT = TextComponent("-∞").color(ChatColors.RED) private val INFINITE_TEXT = TextComponent("∞").color(ChatColors.RED) private val ZERO_TEXT = TextComponent("0").color(ChatColors.YELLOW) + + val DEFAULT_SIZE = Vec2i(17, 17) // 16x16 for the item and 1px for the count offset } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextFlowElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextFlowElement.kt index 833a3901b..5b0287446 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextFlowElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextFlowElement.kt @@ -37,6 +37,7 @@ open class TextFlowElement( private val messages: MutableList = synchronizedListOf() // all messages **from newest to oldest** private var visibleLines: List = listOf() // all visible lines **from bottom to top** override var activeElement: TextElement? = null + override var activeDragElement: TextElement? = null private val background = ColorElement(guiRenderer, size, RenderConstants.TEXT_BACKGROUND_COLOR) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/AbstractLayout.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/AbstractLayout.kt index d98e1fa53..a80aa25b7 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/AbstractLayout.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/AbstractLayout.kt @@ -15,6 +15,8 @@ package de.bixilon.minosoft.gui.rendering.gui.gui import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.gui.rendering.gui.elements.Element +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged +import de.bixilon.minosoft.gui.rendering.gui.input.DraggableElement import de.bixilon.minosoft.gui.rendering.gui.input.InputElement import de.bixilon.minosoft.gui.rendering.gui.input.mouse.MouseActions import de.bixilon.minosoft.gui.rendering.gui.input.mouse.MouseButtons @@ -22,8 +24,9 @@ import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes import glm_.vec2.Vec2d import glm_.vec2.Vec2i -interface AbstractLayout : InputElement { +interface AbstractLayout : InputElement, DraggableElement { var activeElement: T? + var activeDragElement: T? fun getAt(position: Vec2i): Pair? @@ -55,8 +58,8 @@ interface AbstractLayout : InputElement { } override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean { - val pair = getAt(position) ?: return false - return pair.first.onMouseAction(pair.second, button, action) + val (element, offset) = getAt(position) ?: return false + return element.onMouseAction(offset, button, action) } override fun onKey(key: KeyCodes, type: KeyChangeTypes): Boolean { @@ -68,7 +71,40 @@ interface AbstractLayout : InputElement { } override fun onScroll(position: Vec2i, scrollOffset: Vec2d): Boolean { - val pair = getAt(position) ?: return false - return pair.first.onScroll(pair.second, scrollOffset) + val (element, offset) = getAt(position) ?: return false + return element.onScroll(offset, scrollOffset) + } + + override fun onDragEnter(position: Vec2i, absolute: Vec2i, draggable: Dragged): Element? { + val pair = getAt(position) + this.activeDragElement = pair?.first + return pair?.first?.onDragEnter(pair.second, absolute, draggable) + } + + override fun onDragMove(position: Vec2i, absolute: Vec2i, draggable: Dragged): Element? { + val pair = getAt(position) + + if (activeDragElement != pair?.first) { + val activeDragElement = activeDragElement + this.activeDragElement = pair?.first + + // Don't put this in the return line, compiler optimizations break it. + val leaveElement = activeDragElement?.onDragLeave(draggable) + val enterElement = pair?.first?.onDragEnter(pair.second, absolute, draggable) + return enterElement ?: leaveElement + } + return pair?.first?.onDragMove(pair.second, absolute, draggable) + } + + override fun onDragLeave(draggable: Dragged): Element? { + val activeDragElement = this.activeDragElement + this.activeDragElement = null + return activeDragElement?.onDragLeave(draggable) + } + + override fun onDragSuccess(draggable: Dragged): Element? { + val activeDragElement = this.activeDragElement + this.activeDragElement = null + return activeDragElement?.onDragSuccess(draggable) } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt index ffd869600..4c4edf0d6 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt @@ -21,13 +21,15 @@ import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.gui.rendering.gui.GUIElement import de.bixilon.minosoft.gui.rendering.gui.GUIElementDrawer import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.Pollable +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged import de.bixilon.minosoft.gui.rendering.gui.gui.screen.container.inventory.LocalInventoryScreen import de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.pause.PauseMenu import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement +import de.bixilon.minosoft.gui.rendering.gui.input.DraggableHandler import de.bixilon.minosoft.gui.rendering.input.InputHandler import de.bixilon.minosoft.gui.rendering.renderer.Drawable import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes @@ -38,7 +40,7 @@ import glm_.vec2.Vec2i class GUIManager( override val guiRenderer: GUIRenderer, -) : Initializable, InputHandler, GUIElementDrawer { +) : Initializable, InputHandler, GUIElementDrawer, DraggableHandler { private val elementCache: MutableMap, GUIElement> = mutableMapOf() var elementOrder: MutableList = mutableListOf() private val renderWindow = guiRenderer.renderWindow @@ -78,7 +80,7 @@ class GUIManager( for (element in elementCache.values) { // ToDo: Just the current active one if (element is LayoutedGUIElement<*>) { - element.elementLayout.forceSilentApply() + element.element.forceSilentApply() } element.apply() } @@ -140,52 +142,55 @@ class GUIManager( } } - override fun onCharPress(char: Int): Boolean { + private fun runForEach(run: (element: GUIElement) -> Boolean): Boolean { for ((index, element) in elementOrder.toList().withIndex()) { if (index != 0 && !element.activeWhenHidden) { continue } - if (element.onCharPress(char)) { + if (run(element)) { return true } } return false } + override fun onCharPress(char: Int): Boolean { + return runForEach { it.onCharPress(char) } + } + override fun onMouseMove(position: Vec2i): Boolean { - for ((index, element) in elementOrder.toList().withIndex()) { - if (index != 0 && !element.activeWhenHidden) { - continue - } - if (element.onMouseMove(position)) { - return true - } - } - return false + return runForEach { it.onMouseMove(position) } } override fun onKeyPress(type: KeyChangeTypes, key: KeyCodes): Boolean { - for ((index, element) in elementOrder.toList().withIndex()) { - if (index != 0 && !element.activeWhenHidden) { - continue - } - if (element.onKeyPress(type, key)) { - return true - } - } - return false + return runForEach { it.onKeyPress(type, key) } } override fun onScroll(scrollOffset: Vec2d): Boolean { + return runForEach { it.onScroll(scrollOffset) } + } + + private fun runForEachDrag(run: (element: GUIElement) -> Element?): Element? { for ((index, element) in elementOrder.toList().withIndex()) { if (index != 0 && !element.activeWhenHidden) { continue } - if (element.onScroll(scrollOffset)) { - return true - } + + run(element)?.let { return it } } - return false + return null + } + + override fun onDragMove(position: Vec2i, draggable: Dragged): Element? { + return runForEachDrag { it.onDragMove(position, draggable) } + } + + override fun onDragLeave(draggable: Dragged): Element? { + return runForEachDrag { it.onDragLeave(draggable) } + } + + override fun onDragSuccess(draggable: Dragged): Element? { + return runForEachDrag { it.onDragSuccess(draggable) } } fun open(builder: GUIBuilder<*>) { @@ -233,6 +238,7 @@ class GUIManager( if (elementOrder.isEmpty()) { renderWindow.inputHandler.inputHandler = null guiRenderer.popper.clear() + guiRenderer.dragged.element = null } val now = elementOrder.firstOrNull() ?: return now.onOpen() @@ -244,6 +250,7 @@ class GUIManager( } elementOrder.clear() guiRenderer.popper.clear() + guiRenderer.dragged.element = null renderWindow.inputHandler.inputHandler = null } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/LayoutedGUIElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIMeshElement.kt similarity index 54% rename from src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/LayoutedGUIElement.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIMeshElement.kt index 0900fd1ee..812502c5a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/LayoutedGUIElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIMeshElement.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2022 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -11,14 +11,13 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.gui.hud.elements +package de.bixilon.minosoft.gui.rendering.gui.gui -import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.gui.rendering.RenderWindow import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.elements.Element -import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged import de.bixilon.minosoft.gui.rendering.gui.hud.HUDElement import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable import de.bixilon.minosoft.gui.rendering.gui.input.mouse.MouseActions @@ -27,22 +26,22 @@ import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMesh import de.bixilon.minosoft.gui.rendering.renderer.Drawable import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh -import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.isOutside +import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList import glm_.vec2.Vec2d import glm_.vec2.Vec2i -class LayoutedGUIElement( - val layout: T, +open class GUIMeshElement( + val element: T, ) : HUDElement, Drawable { - val elementLayout = layout.unsafeCast() - override val guiRenderer: GUIRenderer = elementLayout.guiRenderer + override val guiRenderer: GUIRenderer = element.guiRenderer override val renderWindow: RenderWindow = guiRenderer.renderWindow var mesh: GUIMesh = GUIMesh(renderWindow, guiRenderer.matrix, DirectArrayFloatList(1000)) - private var lastRevision = 0L override val skipDraw: Boolean - get() = if (layout is Drawable) layout.skipDraw else false - private var lastPosition: Vec2i = Vec2i(-1, -1) + get() = if (element is Drawable) element.skipDraw else false + protected var lastRevision = 0L + protected var lastPosition: Vec2i? = null + protected var dragged = false override var enabled = true set(value) { if (field == value) { @@ -50,33 +49,33 @@ class LayoutedGUIElement( } field = value if (!value) { - elementLayout.onClose() + element.onClose() } } override val activeWhenHidden: Boolean - get() = elementLayout.activeWhenHidden + get() = element.activeWhenHidden init { - elementLayout.cache.data = mesh.data + element.cache.data = mesh.data } override fun tick() { - elementLayout.tick() + element.tick() } override fun init() { - if (layout is Initializable) { - layout.init() + if (element is Initializable) { + element.init() } } override fun postInit() { - if (layout is Initializable) { - layout.postInit() + if (element is Initializable) { + element.postInit() } } - private fun createNewMesh() { + protected fun createNewMesh() { val mesh = this.mesh if (mesh.state == Mesh.MeshStates.LOADED) { mesh.unload() @@ -84,11 +83,10 @@ class LayoutedGUIElement( this.mesh = GUIMesh(renderWindow, guiRenderer.matrix, mesh.data) } - fun prepare() { - val layoutOffset = layout.layoutOffset - elementLayout.render(layoutOffset, mesh, null) + fun prepare(offset: Vec2i) { + element.render(offset, mesh, null) - val revision = elementLayout.cache.revision + val revision = element.cache.revision if (revision != lastRevision) { createNewMesh() this.mesh.load() @@ -96,82 +94,73 @@ class LayoutedGUIElement( } } - override fun draw() { - if (layout is Drawable) { - layout.draw() - } + open fun prepare() { + prepare(Vec2i.EMPTY) } + override fun draw() { + if (element is Drawable) { + element.draw() + } + } fun initMesh() { mesh.load() } - override fun onMouseMove(position: Vec2i): Boolean { - val offset = layout.layoutOffset - val size = elementLayout.size - val lastPosition = lastPosition - - if (position.isOutside(offset, offset + size)) { - if (lastPosition == INVALID_MOUSE_POSITION) { - return false - } - // move out - this.lastPosition = INVALID_MOUSE_POSITION - return elementLayout.onMouseLeave() - } - val delta = position - offset - val previousOutside = lastPosition == INVALID_MOUSE_POSITION - this.lastPosition = delta - - if (previousOutside) { - return elementLayout.onMouseEnter(delta, position) - } - - return elementLayout.onMouseMove(delta, position) + override fun onCharPress(char: Int): Boolean { + return element.onCharPress(char) } - override fun onCharPress(char: Int): Boolean { - return elementLayout.onCharPress(char) + override fun onMouseMove(position: Vec2i): Boolean { + return element.onMouseMove(position, position) } override fun onKeyPress(type: KeyChangeTypes, key: KeyCodes): Boolean { - val mouseButton = MouseButtons[key] ?: return elementLayout.onKey(key, type) + val mouseButton = MouseButtons[key] ?: return element.onKey(key, type) - val position = lastPosition - if (position == INVALID_MOUSE_POSITION) { - return false - } + val position = lastPosition ?: return false val mouseAction = MouseActions[type] ?: return false - return elementLayout.onMouseAction(position, mouseButton, mouseAction) + return element.onMouseAction(position, mouseButton, mouseAction) } override fun onScroll(scrollOffset: Vec2d): Boolean { - val position = lastPosition - if (lastPosition == INVALID_MOUSE_POSITION) { - return false + val position = lastPosition ?: return false + return element.onScroll(position, scrollOffset) + } + + override fun onDragMove(position: Vec2i, draggable: Dragged): Element? { + if (!dragged) { + dragged = true + element.onDragEnter(position, position, draggable) } - return elementLayout.onScroll(position, scrollOffset) + return element.onDragMove(position, position, draggable) + } + + override fun onDragLeave(draggable: Dragged): Element? { + dragged = false + return element.onDragLeave(draggable) + } + + override fun onDragSuccess(draggable: Dragged): Element? { + dragged = false + return element.onDragSuccess(draggable) } override fun onClose() { - elementLayout.onClose() - elementLayout.onMouseLeave() - lastPosition = INVALID_MOUSE_POSITION + element.onClose() + element.onMouseLeave() + lastPosition = null } override fun onOpen() { - elementLayout.onOpen() + element.onOpen() onMouseMove(guiRenderer.currentCursorPosition) } override fun onHide() { - elementLayout.onHide() - elementLayout.onMouseLeave() - } - - companion object { - private val INVALID_MOUSE_POSITION = Vec2i(-1, -1) + element.onHide() + element.onMouseLeave() } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/LayoutedGUIElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/LayoutedGUIElement.kt new file mode 100644 index 000000000..0c6f79db3 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/LayoutedGUIElement.kt @@ -0,0 +1,107 @@ +/* + * Minosoft + * Copyright (C) 2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.gui + +import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.minosoft.gui.rendering.gui.elements.Element +import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged +import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.isGreater +import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.isSmaller +import glm_.vec2.Vec2i + +class LayoutedGUIElement( + val layout: T, +) : GUIMeshElement(layout.unsafeCast()) { + protected var lastDragPosition: Vec2i? = null + + override fun prepare() { + prepare(layout.layoutOffset) + } + + private fun getOffset(position: Vec2i): Vec2i? { + val layoutOffset = layout.layoutOffset + val size = element.size + if (position isSmaller layoutOffset) { + return null + } + val offset = position - layoutOffset + if (offset isGreater size) { + return null + } + return offset + } + + override fun onMouseMove(position: Vec2i): Boolean { + val lastPosition = lastPosition + val offset = getOffset(position) + if (offset == null) { + if (lastPosition == null) { + return false + } + // move out + this.lastPosition = null + return element.onMouseLeave() + } + + val previousOutside = lastPosition == null + this.lastPosition = offset + + if (previousOutside) { + return element.onMouseEnter(offset, position) + } + + return element.onMouseMove(offset, position) + } + + override fun onDragMove(position: Vec2i, draggable: Dragged): Element? { + val lastDragPosition = lastDragPosition + val offset = getOffset(position) + if (offset == null) { + if (this.lastDragPosition == null) { + return null + } + // move out + this.lastDragPosition = null + return element.onDragLeave(draggable) + } + + val previousOutside = lastDragPosition == null + this.lastDragPosition = offset + + if (previousOutside) { + return element.onDragEnter(offset, position, draggable) + } + + return element.onDragMove(offset, position, draggable) + } + + override fun onDragLeave(draggable: Dragged): Element? { + var element: Element? = null + if (lastDragPosition != null) { + element = this.element.onDragLeave(draggable) + } + lastDragPosition = null + return element + } + + override fun onDragSuccess(draggable: Dragged): Element? { + var element: Element? = null + if (lastDragPosition != null) { + element = this.element.onDragSuccess(draggable) + } + lastDragPosition = null + return element + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/Dragged.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/Dragged.kt new file mode 100644 index 000000000..0130cb82e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/Dragged.kt @@ -0,0 +1,43 @@ +/* + * Minosoft + * Copyright (C) 2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.gui.dragged + +import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.elements.Element +import glm_.vec2.Vec2i + +abstract class Dragged(guiRenderer: GUIRenderer) : Element(guiRenderer) { + val visible: Boolean + get() = guiRenderer.dragged.element?.element === this + + + open fun onDragStart(position: Vec2i, target: Element?) = Unit + open fun onDragMove(position: Vec2i, target: Element?) = Unit + open fun onDragEnd(position: Vec2i, target: Element?) = Unit + open fun onDragSuccess(position: Vec2i, target: Element?) = Unit + + fun show() { + if (visible) { + return + } + guiRenderer.dragged.element = DraggedGUIElement(this) + } + + fun close() { + if (!visible) { + return + } + guiRenderer.dragged.element = null + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/DraggedGUIElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/DraggedGUIElement.kt new file mode 100644 index 000000000..429e73f4d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/DraggedGUIElement.kt @@ -0,0 +1,30 @@ +/* + * Minosoft + * Copyright (C) 2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.gui.dragged + +import de.bixilon.minosoft.gui.rendering.gui.gui.GUIMeshElement +import glm_.vec2.Vec2i + +class DraggedGUIElement(element: T) : GUIMeshElement(element) { + + override fun prepare() { + prepare(guiRenderer.currentCursorPosition - (element.size / 2)) + } + + override fun onMouseMove(position: Vec2i): Boolean { + val element = guiRenderer.gui.onDragMove(position, element) + this.element.onDragMove(position, element) + return element != null + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/DraggedManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/DraggedManager.kt new file mode 100644 index 000000000..e65e6aa18 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/DraggedManager.kt @@ -0,0 +1,103 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.gui.dragged + +import de.bixilon.kutil.time.TimeUtil +import de.bixilon.minosoft.config.key.KeyCodes +import de.bixilon.minosoft.gui.rendering.gui.GUIElementDrawer +import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable +import de.bixilon.minosoft.gui.rendering.input.InputHandler +import de.bixilon.minosoft.gui.rendering.system.window.CursorModes +import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes +import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition +import glm_.vec2.Vec2i + +class DraggedManager( + override val guiRenderer: GUIRenderer, +) : Initializable, InputHandler, GUIElementDrawer { + var element: DraggedGUIElement<*>? = null + set(value) { + if (field == value || field?.element == value?.element) { + return + } + val position = guiRenderer.currentCursorPosition + field?.element?.onDragEnd(position, null) // ToDo + field = value + element?.element?.onDragStart(position, null) // ToDo + applyCursor() + } + override var lastTickTime: Long = -1L + + override fun init() { + } + + override fun postInit() { + } + + fun onMatrixChange() { + element?.element?.forceSilentApply() + } + + private fun applyCursor() { + val window = guiRenderer.renderWindow.window + if (window.cursorMode == CursorModes.DISABLED) { + return + } + window.cursorMode = if (element == null) CursorModes.NORMAL else CursorModes.HIDDEN + } + + fun draw() { + val element = element ?: return + val time = TimeUtil.time + val tick = time - lastTickTime > ProtocolDefinition.TICK_TIME + if (tick) { + lastTickTime = time + } + if (!element.enabled) { + return + } + if (tick) { + element.tick() + + lastTickTime = time + } + + if (!element.skipDraw) { + element.draw() + } + element.prepare() + + guiRenderer.setup() + if (!element.enabled || element.mesh.data.isEmpty) { + return + } + element.mesh.draw() + } + + override fun onCharPress(char: Int): Boolean { + element?.onCharPress(char) ?: return false + return true + } + + override fun onMouseMove(position: Vec2i): Boolean { + element?.onMouseMove(position) ?: return false + return true + } + + override fun onKeyPress(type: KeyChangeTypes, key: KeyCodes): Boolean { + element?.onKeyPress(type, key) ?: return false + return true + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/elements/item/FloatingItem.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/elements/item/FloatingItem.kt new file mode 100644 index 000000000..2d28de642 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/dragged/elements/item/FloatingItem.kt @@ -0,0 +1,44 @@ +/* + * Minosoft + * Copyright (C) 2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.gui.dragged.elements.item + +import de.bixilon.minosoft.data.inventory.stack.ItemStack +import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.elements.items.ItemElement +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged +import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer +import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions +import glm_.vec2.Vec2i + +class FloatingItem( + guiRenderer: GUIRenderer, + val sourceId: Int, + val stack: ItemStack, + size: Vec2i = ItemElement.DEFAULT_SIZE, +) : Dragged(guiRenderer) { + private val itemElement = ItemElement(guiRenderer, size, stack, -1, null, this) + + init { + forceSilentApply() + _size = size + } + + override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { + itemElement.render(offset, consumer, options) + } + + override fun forceSilentApply() { + + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/Popper.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/Popper.kt similarity index 90% rename from src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/Popper.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/Popper.kt index 3d9d8a854..76d578aea 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/Popper.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/Popper.kt @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.gui.popper +package de.bixilon.minosoft.gui.rendering.gui.gui.popper import de.bixilon.minosoft.data.text.RGBColor import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer @@ -27,8 +27,9 @@ import glm_.vec2.Vec2i abstract class Popper( guiRenderer: GUIRenderer, position: Vec2i, + val background: Boolean = true, ) : Element(guiRenderer), LayoutedElement { - private val background = ColorElement(guiRenderer, Vec2i.EMPTY, color = RGBColor(10, 10, 20, 230)) + private val backgroundElement = ColorElement(guiRenderer, Vec2i.EMPTY, color = RGBColor(10, 10, 20, 230)) open var dead = false override var layoutOffset: Vec2i = EMPTY protected set @@ -42,12 +43,14 @@ abstract class Popper( } override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { - background.render(offset, consumer, options) + if (background) { + backgroundElement.render(offset, consumer, options) + } } override fun forceSilentApply() { calculateLayoutOffset() - background.size = size + backgroundElement.size = size cacheUpToDate = false } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/PopperManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/PopperManager.kt similarity index 96% rename from src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/PopperManager.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/PopperManager.kt index 77e51f559..3e40ac2eb 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/PopperManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/PopperManager.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2022 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -11,14 +11,14 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.gui.popper +package de.bixilon.minosoft.gui.rendering.gui.gui.popper import de.bixilon.kutil.time.TimeUtil import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.gui.rendering.gui.GUIElementDrawer import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.input.InputHandler import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/item/ItemInfoPopper.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/item/ItemInfoPopper.kt similarity index 96% rename from src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/item/ItemInfoPopper.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/item/ItemInfoPopper.kt index 84d0c96d3..1bb7015ce 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/item/ItemInfoPopper.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/item/ItemInfoPopper.kt @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.gui.popper.item +package de.bixilon.minosoft.gui.rendering.gui.gui.popper.item import de.bixilon.minosoft.data.inventory.stack.ItemStack import de.bixilon.minosoft.data.text.BaseComponent @@ -21,9 +21,9 @@ import de.bixilon.minosoft.data.text.TextComponent import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.popper.Popper import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions -import de.bixilon.minosoft.gui.rendering.gui.popper.Popper import glm_.vec2.Vec2i class ItemInfoPopper( diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/text/TextPopper.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/text/TextPopper.kt similarity index 93% rename from src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/text/TextPopper.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/text/TextPopper.kt index f2f6a6d9e..934dc5368 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/popper/text/TextPopper.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/popper/text/TextPopper.kt @@ -11,14 +11,14 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.gui.popper.text +package de.bixilon.minosoft.gui.rendering.gui.gui.popper.text import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.popper.Popper import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions -import de.bixilon.minosoft.gui.rendering.gui.popper.Popper import glm_.vec2.Vec2i class TextPopper( diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/ContainerScreen.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/ContainerScreen.kt index 32adab526..eba37bf91 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/ContainerScreen.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/ContainerScreen.kt @@ -39,6 +39,7 @@ abstract class ContainerScreen( private val containerBackground = AtlasImageElement(guiRenderer, background) protected val containerElement = ContainerItemsElement(guiRenderer, container, items).apply { parent = this@ContainerScreen } override var activeElement: Element? = null + override var activeDragElement: Element? = null override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { super.forceRender(offset, consumer, options) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/inventory/LocalInventoryScreen.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/inventory/LocalInventoryScreen.kt index 5ce6d49d8..236acc5f7 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/inventory/LocalInventoryScreen.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/inventory/LocalInventoryScreen.kt @@ -18,7 +18,7 @@ import de.bixilon.minosoft.config.key.KeyBinding import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.gui.GUIBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.util.KUtil.toResourceLocation class LocalInventoryScreen(guiRenderer: GUIRenderer) : InventoryScreen(guiRenderer, guiRenderer.connection.player.inventory) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/Menu.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/Menu.kt index 63a26033f..6c249b65d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/Menu.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/Menu.kt @@ -37,6 +37,7 @@ abstract class Menu( private var totalHeight = -1 override var activeElement: Element? = null + override var activeDragElement: Element? = null override fun forceSilentApply() { val elementWidth = maxOf(minOf(preferredElementWidth, size.x / 3), 0) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/debug/DebugMenu.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/debug/DebugMenu.kt index 3224fc509..7feaf6654 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/debug/DebugMenu.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/debug/DebugMenu.kt @@ -20,8 +20,8 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.input.button.ButtonElement import de.bixilon.minosoft.gui.rendering.gui.elements.spacer.SpacerElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement import de.bixilon.minosoft.gui.rendering.gui.gui.GUIBuilder +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.Menu -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.modding.event.EventInitiators import glm_.vec2.Vec2i import glm_.vec3.Vec3d diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/pause/PauseMenu.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/pause/PauseMenu.kt index b5d11827d..c73567378 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/pause/PauseMenu.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/pause/PauseMenu.kt @@ -21,9 +21,9 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.input.button.NeutralizedBu import de.bixilon.minosoft.gui.rendering.gui.elements.spacer.SpacerElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement import de.bixilon.minosoft.gui.rendering.gui.gui.GUIBuilder +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.Menu import de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.debug.DebugMenu -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.terminal.RunConfiguration import de.bixilon.minosoft.util.ShutdownManager import glm_.vec2.Vec2i diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt index 448a31184..3b5cc3d73 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt @@ -22,8 +22,8 @@ import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.gui.rendering.gui.GUIElementDrawer import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.bossbar.BossbarLayout import de.bixilon.minosoft.gui.rendering.gui.hud.elements.chat.ChatElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.chat.InternalChatElement @@ -76,7 +76,7 @@ class HUDManager( fun onMatrixChange() { for (element in hudElements.toSynchronizedMap().values) { if (element is LayoutedGUIElement<*>) { - element.elementLayout.forceApply() + element.element.forceApply() } element.apply() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/bossbar/BossbarLayout.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/bossbar/BossbarLayout.kt index cd3b43be8..6ac5f2ab9 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/bossbar/BossbarLayout.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/bossbar/BossbarLayout.kt @@ -20,9 +20,9 @@ import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.layout.RowLayout +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.modding.event.events.bossbar.* import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker import de.bixilon.minosoft.util.KUtil.toResourceLocation diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/AbstractChatElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/AbstractChatElement.kt index 5078f1160..a67711d25 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/AbstractChatElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/AbstractChatElement.kt @@ -30,6 +30,7 @@ abstract class AbstractChatElement(guiRenderer: GUIRenderer) : Element(guiRender protected val profile = connection.profiles.gui protected val messages = TextFlowElement(guiRenderer, 20000).apply { parent = this@AbstractChatElement } override var activeElement: Element? = null + override var activeDragElement: Element? = null override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { messages.render(offset + Vec2i(ChatElement.CHAT_INPUT_MARGIN, 0), consumer, options) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/ChatElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/ChatElement.kt index 1549f9569..8e28b265f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/ChatElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/ChatElement.kt @@ -24,9 +24,9 @@ import de.bixilon.minosoft.gui.rendering.font.Font import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.gui.GUIBuilder +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.gui.elements.input.TextInputElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/InternalChatElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/InternalChatElement.kt index e178ed323..4c2e50ed4 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/InternalChatElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/InternalChatElement.kt @@ -19,8 +19,8 @@ import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.gui.GUIBuilder +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.modding.event.events.InternalMessageReceiveEvent import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker import de.bixilon.minosoft.util.KUtil.toResourceLocation diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt index 3491fccc2..d96a83f02 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt @@ -25,9 +25,9 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments.Companion.getOffset import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.FadingTextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/BreakProgressHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/BreakProgressHUDElement.kt index 5c1fdbe7e..3fec8316c 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/BreakProgressHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/BreakProgressHUDElement.kt @@ -20,8 +20,8 @@ import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.renderer.Drawable diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt index 0f73233fc..e4d3497fc 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt @@ -20,9 +20,9 @@ import de.bixilon.minosoft.gui.rendering.camera.target.targets.BlockTarget import de.bixilon.minosoft.gui.rendering.camera.target.targets.EntityTarget import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.CustomHUDElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMesh import de.bixilon.minosoft.gui.rendering.system.base.BlendingFunctions import de.bixilon.minosoft.util.KUtil.toResourceLocation diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt index 2de88137b..c31d06309 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt @@ -35,9 +35,9 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.layout.grid.GridLayout import de.bixilon.minosoft.gui.rendering.gui.elements.spacer.LineSpacerElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.AutoTextElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/WorldInfoHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/WorldInfoHUDElement.kt index 002769c0c..1b2b6ae28 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/WorldInfoHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/WorldInfoHUDElement.kt @@ -19,8 +19,8 @@ import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.Pollable import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.util.KUtil.toResourceLocation import glm_.vec2.Vec2i diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/scoreboard/ScoreboardSideElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/scoreboard/ScoreboardSideElement.kt index 2b62e111f..0b4c9b960 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/scoreboard/ScoreboardSideElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/scoreboard/ScoreboardSideElement.kt @@ -28,9 +28,9 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments.Compa import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ColorElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.renderer.Drawable diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/tab/TabListElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/tab/TabListElement.kt index eb2e7a0e8..2a7f975c6 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/tab/TabListElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/tab/TabListElement.kt @@ -29,9 +29,9 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments.Compa import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ColorElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.renderer.Drawable diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/title/TitleElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/title/TitleElement.kt index 7b979aeaa..721a098df 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/title/TitleElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/title/TitleElement.kt @@ -20,9 +20,9 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments.Companion.getOffset import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.text.FadingTextElement +import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/DraggableElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/DraggableElement.kt new file mode 100644 index 000000000..d7f9ec364 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/DraggableElement.kt @@ -0,0 +1,26 @@ +/* + * Minosoft + * Copyright (C) 2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.input + +import de.bixilon.minosoft.gui.rendering.gui.elements.Element +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged +import glm_.vec2.Vec2i + +interface DraggableElement { + + fun onDragEnter(position: Vec2i, absolute: Vec2i, draggable: Dragged): Element? = null + fun onDragMove(position: Vec2i, absolute: Vec2i, draggable: Dragged): Element? = null + fun onDragLeave(draggable: Dragged): Element? = null + fun onDragSuccess(draggable: Dragged): Element? = null +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/DraggableHandler.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/DraggableHandler.kt new file mode 100644 index 000000000..a3e34dbb2 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/DraggableHandler.kt @@ -0,0 +1,25 @@ +/* + * Minosoft + * Copyright (C) 2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.input + +import de.bixilon.minosoft.gui.rendering.gui.elements.Element +import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged +import glm_.vec2.Vec2i + +interface DraggableHandler { + + fun onDragMove(position: Vec2i, draggable: Dragged): Element? = null + fun onDragLeave(draggable: Dragged): Element? = null + fun onDragSuccess(draggable: Dragged): Element? = null +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/InputElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/InputElement.kt index 1ea54d144..063d7f1d3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/InputElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/input/InputElement.kt @@ -27,6 +27,4 @@ interface InputElement : MouseInputElement { fun onKey(key: KeyCodes, type: KeyChangeTypes) = false fun onCharPress(char: Int) = false - - // ToDo: drag }