aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/inventory
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/features/inventory')
-rw-r--r--src/main/kotlin/features/inventory/SaveCursorPosition.kt2
-rw-r--r--src/main/kotlin/features/inventory/SlotLocking.kt8
-rw-r--r--src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt53
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt43
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt51
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt16
6 files changed, 92 insertions, 81 deletions
diff --git a/src/main/kotlin/features/inventory/SaveCursorPosition.kt b/src/main/kotlin/features/inventory/SaveCursorPosition.kt
index 5a54aca..c523661 100644
--- a/src/main/kotlin/features/inventory/SaveCursorPosition.kt
+++ b/src/main/kotlin/features/inventory/SaveCursorPosition.kt
@@ -44,7 +44,7 @@ object SaveCursorPosition {
(lastPosition.middle.second - middleY).absoluteValue < 1
) {
InputUtil.setCursorParameters(
- MC.window.handle,
+ MC.window,
InputUtil.GLFW_CURSOR_NORMAL,
lastPosition.cursor.first,
lastPosition.cursor.second
diff --git a/src/main/kotlin/features/inventory/SlotLocking.kt b/src/main/kotlin/features/inventory/SlotLocking.kt
index 87edbe1..10c58cb 100644
--- a/src/main/kotlin/features/inventory/SlotLocking.kt
+++ b/src/main/kotlin/features/inventory/SlotLocking.kt
@@ -393,12 +393,12 @@ object SlotLocking {
hotX + sx, hotY + sy,
color(anyHovered)
)
- event.context.drawBorder(
+ event.context.drawStrokedRectangle(
hotbarSlot.x + sx,
hotbarSlot.y + sy,
16, 16, color(hotbarSlot in highlitSlots).color
)
- event.context.drawBorder(
+ event.context.drawStrokedRectangle( // TODO: 1.21.10
inventorySlot.x + sx,
inventorySlot.y + sy,
16, 16, color(inventorySlot in highlitSlots).color
@@ -416,7 +416,7 @@ object SlotLocking {
val sx = accScreen.x_Firmament
val sy = accScreen.y_Firmament
val (borderX, borderY) = draggingSlot.lineCenter()
- event.context.drawBorder(draggingSlot.x + sx, draggingSlot.y + sy, 16, 16, 0xFF00FF00u.toInt())
+ event.context.drawStrokedRectangle(draggingSlot.x + sx, draggingSlot.y + sy, 16, 16, 0xFF00FF00u.toInt()) // TODO: 1.21.10
if (hoveredSlot == null) {
event.context.drawLine(
borderX + sx, borderY + sy,
@@ -430,7 +430,7 @@ object SlotLocking {
hovX + sx, hovY + sy,
me.shedaniel.math.Color.ofOpaque(0x00FF00)
)
- event.context.drawBorder(
+ event.context.drawStrokedRectangle(
hoveredSlot.x + sx,
hoveredSlot.y + sy,
16, 16, 0xFF00FF00u.toInt()
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt
index ce074d8..d5d291c 100644
--- a/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt
+++ b/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt
@@ -9,9 +9,12 @@ import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import org.lwjgl.glfw.GLFW
import net.minecraft.client.MinecraftClient
+import net.minecraft.client.gui.Click
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.widget.ButtonWidget
+import net.minecraft.client.gui.widget.MultilineTextWidget
import net.minecraft.client.gui.widget.TextWidget
+import net.minecraft.client.input.KeyInput
import net.minecraft.client.util.InputUtil
import net.minecraft.text.Text
import net.minecraft.util.math.MathHelper
@@ -74,24 +77,20 @@ class InventoryButtonEditor(
override fun init() {
super.init()
addDrawableChild(
- TextWidget(
+ MultilineTextWidget(
lastGuiRect.minX,
25,
- lastGuiRect.width,
- 9,
Text.translatable("firmament.inventory-buttons.delete"),
MC.font
- ).alignCenter()
+ ).setCentered(true).setMaxWidth(lastGuiRect.width)
)
addDrawableChild(
- TextWidget(
+ MultilineTextWidget(
lastGuiRect.minX,
40,
- lastGuiRect.width,
- 9,
Text.translatable("firmament.inventory-buttons.info"),
MC.font
- ).alignCenter()
+ ).setCentered(true).setMaxWidth(lastGuiRect.width)
)
addDrawableChild(
ButtonWidget.builder(Text.translatable("firmament.inventory-buttons.reset")) {
@@ -216,27 +215,27 @@ class InventoryButtonEditor(
renderPopup(context, mouseX, mouseY, delta)
}
- override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
- if (super.keyPressed(keyCode, scanCode, modifiers)) return true
- if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
+ override fun keyPressed(input: KeyInput): Boolean {
+ if (super.keyPressed(input)) return true
+ if (input.keycode == GLFW.GLFW_KEY_ESCAPE) {
close()
return true
}
return false
}
- override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean {
- if (super.mouseReleased(mouseX, mouseY, button)) return true
- val clickedButton = buttons.firstOrNull { it.getBounds(lastGuiRect).contains(Point(mouseX, mouseY)) }
+ override fun mouseReleased(click: Click): Boolean {
+ if (super.mouseReleased(click)) return true
+ val clickedButton = buttons.firstOrNull { it.getBounds(lastGuiRect).contains(Point(click.x, click.y)) }
if (clickedButton != null && !justPerformedAClickAction) {
if (InputUtil.isKeyPressed(
- MC.window.handle,
+ MC.window,
InputUtil.GLFW_KEY_LEFT_CONTROL
)
) Editor(clickedButton).delete()
else createPopup(
MoulConfigUtils.loadGui("button_editor_fragment", Editor(clickedButton)),
- Point(mouseX, mouseY)
+ Point(click.x, click.y)
)
return true
}
@@ -245,14 +244,14 @@ class InventoryButtonEditor(
return false
}
- override fun mouseDragged(mouseX: Double, mouseY: Double, button: Int, deltaX: Double, deltaY: Double): Boolean {
- if (super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) return true
+ override fun mouseDragged(click: Click, offsetX: Double, offsetY: Double): Boolean {
+ if (super.mouseDragged(click, offsetX, offsetY)) return true
- if (initialDragMousePosition.distanceSquared(Vec2f(mouseX.toFloat(), mouseY.toFloat())) >= 4 * 4) {
+ if (initialDragMousePosition.distanceSquared(Vec2f(click.x.toFloat(), click.y.toFloat())) >= 4 * 4) {
initialDragMousePosition = Vec2f(-10F, -10F)
lastDraggedButton?.let { dragging ->
justPerformedAClickAction = true
- val (anchorRight, anchorBottom, offsetX, offsetY) = getCoordsForMouse(mouseX.toInt(), mouseY.toInt())
+ val (anchorRight, anchorBottom, offsetX, offsetY) = getCoordsForMouse(click.x.toInt(), click.y.toInt())
?: return true
dragging.x = offsetX
dragging.y = offsetY
@@ -287,7 +286,7 @@ class InventoryButtonEditor(
val anchorBottom = my > lastGuiRect.maxY
var offsetX = mx - if (anchorRight) lastGuiRect.maxX else lastGuiRect.minX
var offsetY = my - if (anchorBottom) lastGuiRect.maxY else lastGuiRect.minY
- if (InputUtil.isKeyPressed(MC.window.handle, InputUtil.GLFW_KEY_LEFT_SHIFT)) {
+ if (InputUtil.isKeyPressed(MC.window, InputUtil.GLFW_KEY_LEFT_SHIFT)) {
offsetX = MathHelper.floor(offsetX / 20F) * 20
offsetY = MathHelper.floor(offsetY / 20F) * 20
}
@@ -297,16 +296,16 @@ class InventoryButtonEditor(
return anchoredCoords
}
- override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
- if (super.mouseClicked(mouseX, mouseY, button)) return true
- val clickedButton = buttons.firstOrNull { it.getBounds(lastGuiRect).contains(Point(mouseX, mouseY)) }
+ override fun mouseClicked(click: Click, doubled: Boolean): Boolean {
+ if (super.mouseClicked(click, doubled)) return true
+ val clickedButton = buttons.firstOrNull { it.getBounds(lastGuiRect).contains(click.x, click.y) }
if (clickedButton != null) {
lastDraggedButton = clickedButton
- initialDragMousePosition = Vec2f(mouseX.toFloat(), mouseY.toFloat())
+ initialDragMousePosition = Vec2f(click.y.toFloat(), click.y.toFloat())
return true
}
- val mx = mouseX.toInt()
- val my = mouseY.toInt()
+ val mx = click.x.toInt()
+ val my = click.y.toInt()
val (anchorRight, anchorBottom, offsetX, offsetY) = getCoordsForMouse(mx, my) ?: return true
buttons.add(InventoryButton(offsetX, offsetY, anchorRight, anchorBottom, null, null))
justPerformedAClickAction = true
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
index e4d4e42..a4199c9 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
@@ -3,8 +3,11 @@ package moe.nea.firmament.features.inventory.storageoverlay
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import net.minecraft.client.MinecraftClient
+import net.minecraft.client.gui.Click
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen
+import net.minecraft.client.input.CharInput
+import net.minecraft.client.input.KeyInput
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.screen.slot.Slot
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
@@ -60,39 +63,41 @@ class StorageOverlayCustom(
return false
}
- override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean {
- return overview.mouseReleased(mouseX, mouseY, button)
+ override fun mouseReleased(click: Click): Boolean {
+ return overview.mouseReleased(click)
}
- override fun mouseDragged(mouseX: Double, mouseY: Double, button: Int, deltaX: Double, deltaY: Double): Boolean {
- return overview.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)
+ override fun mouseDragged(click: Click, offsetX: Double, offsetY: Double): Boolean {
+ return overview.mouseDragged(click, offsetX, offsetY)
}
- override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
- return overview.keyReleased(keyCode, scanCode, modifiers)
+ override fun keyReleased(input: KeyInput): Boolean {
+ return overview.keyReleased(input)
}
- override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
- return overview.keyPressed(keyCode, scanCode, modifiers)
+ override fun keyPressed(input: KeyInput): Boolean {
+ return overview.keyPressed(input)
}
- override fun charTyped(chr: Char, modifiers: Int): Boolean {
- return overview.charTyped(chr, modifiers)
+ override fun charTyped(input: CharInput): Boolean {
+ return overview.charTyped(input)
}
- override fun mouseClick(mouseX: Double, mouseY: Double, button: Int): Boolean {
- return overview.mouseClicked(mouseX, mouseY, button, (handler as? StorageBackingHandle.Page)?.storagePageSlot)
+ override fun mouseClick(click: Click, doubled: Boolean): Boolean {
+ return overview.mouseClicked(click, doubled, (handler as? StorageBackingHandle.Page)?.storagePageSlot)
}
override fun render(drawContext: DrawContext, delta: Float, mouseX: Int, mouseY: Int) {
overview.drawBackgrounds(drawContext)
- overview.drawPages(drawContext,
- mouseX,
- mouseY,
- delta,
- (handler as? StorageBackingHandle.Page)?.storagePageSlot,
- screen.screenHandler.slots.take(screen.screenHandler.rows * 9).drop(9),
- Point((screen as AccessorHandledScreen).x_Firmament, screen.y_Firmament))
+ overview.drawPages(
+ drawContext,
+ mouseX,
+ mouseY,
+ delta,
+ (handler as? StorageBackingHandle.Page)?.storagePageSlot,
+ screen.screenHandler.slots.take(screen.screenHandler.rows * 9).drop(9),
+ Point((screen as AccessorHandledScreen).x_Firmament, screen.y_Firmament)
+ )
overview.drawScrollBar(drawContext)
overview.drawControls(drawContext, mouseX, mouseY)
}
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
index c7ca6e4..d2fff9c 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
@@ -13,9 +13,12 @@ import io.github.notenoughupdates.moulconfig.observer.Property
import java.util.TreeSet
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
+import net.minecraft.client.gui.Click
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.gui.screen.ingame.HandledScreen
+import net.minecraft.client.input.CharInput
+import net.minecraft.client.input.KeyInput
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot
import net.minecraft.text.Text
@@ -307,11 +310,11 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
get() = guiContext.focusedElement == knobStub
set(value) = knobStub.setFocus(value)
- override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
- return mouseClicked(mouseX, mouseY, button, null)
+ override fun mouseClicked(click: Click, doubled: Boolean): Boolean {
+ return mouseClicked(click, doubled, null)
}
- override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean {
+ override fun mouseReleased(click: Click): Boolean {
if (knobGrabbed) {
knobGrabbed = false
return true
@@ -320,30 +323,32 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
controlComponent,
measurements.controlX, measurements.controlY,
CONTROL_WIDTH, CONTROL_HEIGHT,
- mouseX.toInt(), mouseY.toInt(),
- MouseEvent.Click(button, false)
+ click.x.toInt(), click.y.toInt(),
+ MouseEvent.Click(click.button(), false)
)
) return true
- return super.mouseReleased(mouseX, mouseY, button)
+ return super.mouseReleased(click)
}
- override fun mouseDragged(mouseX: Double, mouseY: Double, button: Int, deltaX: Double, deltaY: Double): Boolean {
+ override fun mouseDragged(click: Click, offsetX: Double, offsetY: Double): Boolean {
if (knobGrabbed) {
val sbRect = getScrollBarRect()
- val percentage = (mouseY - sbRect.getY()) / sbRect.getHeight()
+ val percentage = (click.x - sbRect.getY()) / sbRect.getHeight()
scroll = (getMaxScroll() * percentage).toFloat()
mouseScrolled(0.0, 0.0, 0.0, 0.0)
return true
}
- return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)
+ return super.mouseDragged(click, offsetX, offsetY)
}
- fun mouseClicked(mouseX: Double, mouseY: Double, button: Int, activePage: StoragePageSlot?): Boolean {
+ fun mouseClicked(click: Click, doubled: Boolean, activePage: StoragePageSlot?): Boolean {
guiContext.setFocusedElement(null) // Blur all elements. They will be refocused by clickMCComponentInPlace if in doubt, and we don't have any double click components.
+ val mouseX = click.x
+ val mouseY = click.y
if (getScrollPanelInner().contains(mouseX, mouseY)) {
- val data = StorageOverlay.Data.data ?: StorageData()
+ val data = StorageOverlay.Data.data
layoutedForEach(data) { rect, page, _ ->
- if (rect.contains(mouseX, mouseY) && activePage != page && button == 0) {
+ if (rect.contains(mouseX, mouseY) && activePage != page && click.button() == 0) {
page.navigateTo()
return true
}
@@ -363,53 +368,53 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
measurements.controlX, measurements.controlY,
CONTROL_WIDTH, CONTROL_HEIGHT,
mouseX.toInt(), mouseY.toInt(),
- MouseEvent.Click(button, true)
+ MouseEvent.Click(click.button(), true)
)
) return true
return false
}
- override fun charTyped(chr: Char, modifiers: Int): Boolean {
+ override fun charTyped(input: CharInput): Boolean {
if (typeMCComponentInPlace(
controlComponent,
measurements.controlX, measurements.controlY,
CONTROL_WIDTH, CONTROL_HEIGHT,
- KeyboardEvent.CharTyped(chr)
+ KeyboardEvent.CharTyped(input.asString().first()) // TODO: i dont like this .first()
)
) {
return true
}
- return super.charTyped(chr, modifiers)
+ return super.charTyped(input)
}
- override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
+ override fun keyReleased(input: KeyInput): Boolean {
if (typeMCComponentInPlace(
controlComponent,
measurements.controlX, measurements.controlY,
CONTROL_WIDTH, CONTROL_HEIGHT,
- KeyboardEvent.KeyPressed(keyCode, scanCode, false)
+ KeyboardEvent.KeyPressed(input.keycode, input.scancode, false)
)
) {
return true
}
- return super.keyReleased(keyCode, scanCode, modifiers)
+ return super.keyReleased(input)
}
override fun shouldCloseOnEsc(): Boolean {
return this === MC.screen // Fixes this UI closing the handled screen on Escape press.
}
- override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
+ override fun keyPressed(input: KeyInput): Boolean {
if (typeMCComponentInPlace(
controlComponent,
measurements.controlX, measurements.controlY,
CONTROL_WIDTH, CONTROL_HEIGHT,
- KeyboardEvent.KeyPressed(keyCode, scanCode, true)
+ KeyboardEvent.KeyPressed(input.keycode, input.scancode, true)
)
) {
return true
}
- return super.keyPressed(keyCode, scanCode, modifiers)
+ return super.keyPressed(input)
}
@@ -506,7 +511,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
val name = inventory.title
val pageHeight = inv.rows * SLOT_SIZE + 8 + textRenderer.fontHeight
if (slots != null && StorageOverlay.TConfig.outlineActiveStoragePage)
- context.drawBorder(
+ context.drawStrokedRectangle(
x,
y + 3 + textRenderer.fontHeight,
PAGE_WIDTH,
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
index 65d7e8c..a55b5ac 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
@@ -5,8 +5,10 @@ package moe.nea.firmament.features.inventory.storageoverlay
import org.lwjgl.glfw.GLFW
import kotlin.math.max
import net.minecraft.block.Blocks
+import net.minecraft.client.gui.Click
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.Screen
+import net.minecraft.client.input.KeyInput
import net.minecraft.item.Item
import net.minecraft.item.Items
import net.minecraft.text.Text
@@ -72,10 +74,10 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
lastRenderedHeight = totalHeight + currentMaxHeight
}
- override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
+ override fun mouseClicked(click: Click, doubled: Boolean): Boolean {
layoutedForEach { (k, p), x, y ->
- val rx = mouseX - x
- val ry = mouseY - y
+ val rx = click.x - x
+ val ry = click.y - y
if (rx in (0.0..pageWidth.toDouble()) && ry in (0.0..getStorePageHeight(p).toDouble())) {
close()
StorageOverlay.lastStorageOverlay = this
@@ -83,7 +85,7 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
return true
}
}
- return super.mouseClicked(mouseX, mouseY, button)
+ return super.mouseClicked(click, doubled)
}
fun getStorePageHeight(page: StorageData.StorageInventory): Int {
@@ -127,9 +129,9 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
}
}
- override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
- if (keyCode == GLFW.GLFW_KEY_ESCAPE)
+ override fun keyPressed(input: KeyInput): Boolean {
+ if (input.keycode == GLFW.GLFW_KEY_ESCAPE)
isClosing = true
- return super.keyPressed(keyCode, scanCode, modifiers)
+ return super.keyPressed(input)
}
}