mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 02:45:13 -04:00
gui: container: take item from container
This commit is contained in:
parent
c545dca618
commit
b1e5524f53
@ -12,7 +12,7 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.data.inventory
|
||||
|
||||
enum class InventoryActions(
|
||||
enum class ContainerClickActions(
|
||||
val mode: Int,
|
||||
val button: Int,
|
||||
val slot: Boolean,
|
@ -16,6 +16,8 @@ package de.bixilon.minosoft.gui.rendering.gui.elements.items
|
||||
import de.bixilon.kutil.collections.CollectionUtil.synchronizedMapOf
|
||||
import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedMap
|
||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.observe
|
||||
import de.bixilon.minosoft.data.inventory.ContainerClickActions
|
||||
import de.bixilon.minosoft.data.inventory.stack.ItemStack
|
||||
import de.bixilon.minosoft.data.registries.other.containers.Container
|
||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.atlas.Vec2iBinding
|
||||
@ -30,6 +32,7 @@ import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.isGreater
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.isSmaller
|
||||
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
|
||||
import glm_.vec2.Vec2i
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
|
||||
|
||||
@ -129,17 +132,29 @@ class ContainerItemsElement(
|
||||
|
||||
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean {
|
||||
val consumed = super<AbstractLayout>.onMouseAction(position, button, action)
|
||||
if (action != MouseActions.PRESS) {
|
||||
if (action != MouseActions.PRESS || (button != MouseButtons.LEFT && button != MouseButtons.RIGHT)) {
|
||||
return consumed
|
||||
}
|
||||
|
||||
val activeElement = activeElement
|
||||
val stack = activeElement?.stack
|
||||
val containerId = renderWindow.connection.player.containers.getKey(container) ?: return consumed
|
||||
var floatingItem = this.floatingItem
|
||||
if ((floatingItem != null && !floatingItem.visible) || stack?._valid != true) {
|
||||
if ((floatingItem != null && floatingItem.visible) || stack?._valid != true) {
|
||||
return consumed
|
||||
}
|
||||
floatingItem = FloatingItem(guiRenderer, activeElement.slotId, stack)
|
||||
val clickAction: ContainerClickActions
|
||||
val stackToFloat: ItemStack
|
||||
if (button == MouseButtons.LEFT) {
|
||||
stackToFloat = stack
|
||||
clickAction = ContainerClickActions.LEFT_MOUSE_CLICK
|
||||
} else {
|
||||
stackToFloat = stack.copy(count = maxOf(stack.item.count / 2, 1))
|
||||
clickAction = ContainerClickActions.RIGHT_MOUSE_CLICK
|
||||
stack.item.count = stack.item.count - stackToFloat.item.count
|
||||
}
|
||||
renderWindow.connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, activeElement.slotId, clickAction, container.createAction(), mapOf(activeElement.slotId to stack), stack))
|
||||
floatingItem = FloatingItem(guiRenderer, activeElement.slotId, stackToFloat)
|
||||
this.floatingItem = floatingItem
|
||||
floatingItem.show()
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
package de.bixilon.minosoft.gui.rendering.gui.elements.items
|
||||
|
||||
import de.bixilon.minosoft.config.key.KeyCodes
|
||||
import de.bixilon.minosoft.data.inventory.InventoryActions
|
||||
import de.bixilon.minosoft.data.inventory.ContainerClickActions
|
||||
import de.bixilon.minosoft.data.inventory.stack.ItemStack
|
||||
import de.bixilon.minosoft.data.registries.items.block.BlockItem
|
||||
import de.bixilon.minosoft.data.registries.other.containers.Container
|
||||
@ -164,13 +164,13 @@ class ItemElement(
|
||||
// ToDo
|
||||
when (key) {
|
||||
KeyCodes.KEY_Q -> {
|
||||
val action: InventoryActions
|
||||
val action: ContainerClickActions
|
||||
if (controlDown) {
|
||||
stack?.item?.count = 0
|
||||
action = InventoryActions.DROP_STACK
|
||||
action = ContainerClickActions.DROP_STACK
|
||||
} else {
|
||||
stack?.item?.decreaseCount()
|
||||
action = InventoryActions.DROP_ITEM
|
||||
action = ContainerClickActions.DROP_ITEM
|
||||
}
|
||||
renderWindow.connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, slotId, action, container.createAction(), mapOf(slotId to stack), stack))
|
||||
}
|
||||
|
@ -233,6 +233,10 @@ class GUIManager(
|
||||
}
|
||||
|
||||
fun pop() {
|
||||
if (guiRenderer.dragged.element != null) {
|
||||
guiRenderer.dragged.element = null
|
||||
return
|
||||
}
|
||||
val previous = elementOrder.removeFirstOrNull() ?: return
|
||||
previous.onClose()
|
||||
if (elementOrder.isEmpty()) {
|
||||
|
@ -33,9 +33,12 @@ class DraggedManager(
|
||||
return
|
||||
}
|
||||
val position = guiRenderer.currentCursorPosition
|
||||
field?.element?.onDragEnd(position, null) // ToDo
|
||||
val previous = field
|
||||
previous?.element?.onDragEnd(position, guiRenderer.gui.onDragLeave(previous.element))
|
||||
|
||||
field = value
|
||||
element?.element?.onDragStart(position, null) // ToDo
|
||||
guiRenderer.gui.onMouseMove(Vec2i(-1, -1)) // move mouse ot
|
||||
value?.element?.onDragStart(position, guiRenderer.gui.onDragMove(position, value.element))
|
||||
applyCursor()
|
||||
}
|
||||
override var lastTickTime: Long = -1L
|
||||
|
@ -12,7 +12,7 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.c2s.play.container
|
||||
|
||||
import de.bixilon.minosoft.data.inventory.InventoryActions
|
||||
import de.bixilon.minosoft.data.inventory.ContainerClickActions
|
||||
import de.bixilon.minosoft.data.inventory.stack.ItemStack
|
||||
import de.bixilon.minosoft.protocol.packets.c2s.PlayC2SPacket
|
||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||
@ -27,7 +27,7 @@ class ContainerClickC2SP(
|
||||
val containerId: Int,
|
||||
val revision: Int,
|
||||
val slot: Int,
|
||||
val action: InventoryActions,
|
||||
val action: ContainerClickActions,
|
||||
val actionId: Int,
|
||||
val next: Map<Int, ItemStack?>,
|
||||
val clickedItem: ItemStack?,
|
||||
|
Loading…
x
Reference in New Issue
Block a user