aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-10-28 03:36:11 +0200
committernea <nea@nea.moe>2023-11-04 00:39:05 +0100
commit5f535b56d0009eefcf5d70f737dd70514802763f (patch)
tree78e8246e30e8504baaac9fd73ad0a0543d028748 /src
parent47fbb25ab280b6af9496780672780db78fe36f27 (diff)
downloadfirmament-5f535b56d0009eefcf5d70f737dd70514802763f.tar.gz
firmament-5f535b56d0009eefcf5d70f737dd70514802763f.tar.bz2
firmament-5f535b56d0009eefcf5d70f737dd70514802763f.zip
Inventory buttons
Diffstat (limited to 'src')
-rw-r--r--src/main/java/moe/nea/firmament/mixins/accessor/AccessorHandledScreen.java15
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt23
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt69
-rw-r--r--src/main/resources/assets/firmament/gui/button_editor_fragment.xml15
4 files changed, 121 insertions, 1 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/accessor/AccessorHandledScreen.java b/src/main/java/moe/nea/firmament/mixins/accessor/AccessorHandledScreen.java
index c42f819..b14717d 100644
--- a/src/main/java/moe/nea/firmament/mixins/accessor/AccessorHandledScreen.java
+++ b/src/main/java/moe/nea/firmament/mixins/accessor/AccessorHandledScreen.java
@@ -6,6 +6,7 @@
package moe.nea.firmament.mixins.accessor;
+import me.shedaniel.math.Rectangle;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.screen.slot.Slot;
import org.jetbrains.annotations.Nullable;
@@ -17,4 +18,18 @@ public interface AccessorHandledScreen {
@Accessor("focusedSlot")
@Nullable
Slot getFocusedSlot_Firmament();
+
+ @Accessor("backgroundWidth")
+ int getBackgroundWidth_Firmament();
+
+ @Accessor("backgroundHeight")
+ int getBackgroundHeight_Firmament();
+
+ @Accessor("x")
+ int getX_Firmament();
+
+ @Accessor("y")
+ int getY_Firmament();
+
+
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt b/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt
index e045fa8..abb2e64 100644
--- a/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt
@@ -8,6 +8,7 @@ package moe.nea.firmament.features.debug
import java.nio.file.Path
import java.util.concurrent.CompletableFuture
+import me.shedaniel.math.Rectangle
import org.lwjgl.glfw.GLFW
import kotlin.io.path.absolute
import kotlin.io.path.exists
@@ -20,10 +21,12 @@ import net.minecraft.util.Formatting
import moe.nea.firmament.Firmament
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
import moe.nea.firmament.features.FirmamentFeature
+import moe.nea.firmament.features.inventory.buttons.InventoryButtonEditor
import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.keybindings.IKeyBinding
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
import moe.nea.firmament.util.MC
+import moe.nea.firmament.util.ScreenUtil
import moe.nea.firmament.util.TimeMark
import moe.nea.firmament.util.iterate
import moe.nea.firmament.util.skyBlockId
@@ -64,8 +67,21 @@ object DeveloperFeatures : FirmamentFeature {
return reloadFuture.thenCompose { client.reloadResources() }
}
+ fun AccessorHandledScreen.getRectangle(): Rectangle {
+ return Rectangle(
+ getX_Firmament(),
+ getY_Firmament(),
+ getBackgroundWidth_Firmament(),
+ getBackgroundHeight_Firmament()
+ )
+ }
+
override fun onLoad() {
HandledScreenKeyPressedEvent.subscribe {
+ if (it.matches(IKeyBinding.ofKeyCode(GLFW.GLFW_KEY_J))) {
+ it.screen as AccessorHandledScreen
+ ScreenUtil.setScreenLater(InventoryButtonEditor(it.screen.getRectangle()))
+ }
if (it.matches(IKeyBinding.ofKeyCode(GLFW.GLFW_KEY_K))) {
it.screen as AccessorHandledScreen
val focussedSlot = it.screen.focusedSlot_Firmament ?: return@subscribe
@@ -78,7 +94,12 @@ object DeveloperFeatures : FirmamentFeature {
).setStyle(
Style.EMPTY.withColor(Formatting.AQUA)
.withClickEvent(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ident))
- .withHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("firmament.debug.skyblockid.copy")))
+ .withHoverEvent(
+ HoverEvent(
+ HoverEvent.Action.SHOW_TEXT,
+ Text.translatable("firmament.debug.skyblockid.copy")
+ )
+ )
)
)
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt
new file mode 100644
index 0000000..ff3469d
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt
@@ -0,0 +1,69 @@
+package moe.nea.firmament.features.inventory.buttons
+
+import io.github.moulberry.moulconfig.xml.Bind
+import me.shedaniel.math.Dimension
+import me.shedaniel.math.Point
+import me.shedaniel.math.Rectangle
+import net.minecraft.client.gui.DrawContext
+import net.minecraft.client.gui.screen.Screen
+import net.minecraft.text.Text
+
+class InventoryButtonEditor(
+ val lastGuiRect: Rectangle,
+) : Screen(Text.literal("")) {
+ class Editor {
+ @field:Bind
+ var
+ }
+
+ data class Button(
+ val x: Int,
+ val y: Int,
+ val anchorRight: Boolean,
+ val anchorBottom: Boolean,
+ val icon: String?,
+ val command: String?,
+ ) {
+ fun isValid() = !icon.isNullOrBlank() && !command.isNullOrBlank()
+
+ fun getPosition(guiRect: Rectangle): Point {
+ return Point(
+ (if (anchorRight) guiRect.maxX else guiRect.minX) + x,
+ (if (anchorBottom) guiRect.maxY else guiRect.minY) + y,
+ )
+ }
+
+ fun getBounds(guiRect: Rectangle): Rectangle {
+ return Rectangle(getPosition(guiRect), Dimension(18, 18))
+ }
+ }
+
+ val buttons = mutableListOf<Button>()
+ override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
+ super.render(context, mouseX, mouseY, delta)
+
+ context.fill(lastGuiRect.minX, lastGuiRect.minY, lastGuiRect.maxX, lastGuiRect.maxY, -1)
+
+ for (button in buttons) {
+ val buttonPosition = button.getPosition(lastGuiRect)
+ context.fill(
+ buttonPosition.x, buttonPosition.y,
+ buttonPosition.x + 18, buttonPosition.y + 18,
+ 0xFF00FF00.toInt()
+ )
+ }
+ }
+
+ override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
+ if (lastGuiRect.contains(mouseX, mouseY)) return true
+ val mx = mouseX.toInt()
+ val my = mouseY.toInt()
+ val anchorRight = mx > lastGuiRect.maxX
+ val anchorBottom = my > lastGuiRect.maxY
+ val offsetX = mx - if (anchorRight) lastGuiRect.maxX else lastGuiRect.minX
+ val offsetY = my - if (anchorBottom) lastGuiRect.maxY else lastGuiRect.minY
+ buttons.add(Button(offsetX, offsetY, anchorRight, anchorBottom, null, null))
+ return true
+ }
+
+}
diff --git a/src/main/resources/assets/firmament/gui/button_editor_fragment.xml b/src/main/resources/assets/firmament/gui/button_editor_fragment.xml
new file mode 100644
index 0000000..954401a
--- /dev/null
+++ b/src/main/resources/assets/firmament/gui/button_editor_fragment.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<Root xmlns="http://notenoughupdates.org/moulconfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://notenoughupdates.org/moulconfig https://raw.githubusercontent.com/NotEnoughUpdates/MoulConfig/master/MoulConfig.xsd">
+ <Panel>
+ <Column>
+ <Text text="Icon"/>
+ <TextField value="@icon" width="180"/>
+ <Text text="Command"/>
+ <Row>
+ <Text text="/"/>
+ <TextField value="@command" width="180"/>
+ </Row>
+ </Column>
+ </Panel>
+</Root>