From 5f535b56d0009eefcf5d70f737dd70514802763f Mon Sep 17 00:00:00 2001 From: nea Date: Sat, 28 Oct 2023 03:36:11 +0200 Subject: Inventory buttons --- build.gradle.kts | 3 + gradle/libs.versions.toml | 2 + .../mixins/accessor/AccessorHandledScreen.java | 15 +++++ .../firmament/features/debug/DeveloperFeatures.kt | 23 +++++++- .../inventory/buttons/InventoryButtonEditor.kt | 69 ++++++++++++++++++++++ .../firmament/gui/button_editor_fragment.xml | 15 +++++ 6 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt create mode 100644 src/main/resources/assets/firmament/gui/button_editor_fragment.xml diff --git a/build.gradle.kts b/build.gradle.kts index 14a6900..1e8eeb6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -66,6 +66,7 @@ repositories { } maven("https://server.bbkr.space/artifactory/libs-release") maven("https://repo.nea.moe/releases") + maven("https://maven.notenoughupdates.org/releases") mavenLocal() } @@ -104,8 +105,10 @@ dependencies { modImplementation(libs.fabric.kotlin) modImplementation(libs.modmenu) modImplementation(libs.libgui) + modImplementation(libs.moulconfig) modCompileOnly(libs.explosiveenhancement) include(libs.libgui) + include(libs.moulconfig) annotationProcessor(libs.mixinextras) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index de0f5de..ae54887 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,6 +26,7 @@ mixinextras = "0.2.0-rc.5" jarvis = "1.1.1" nealisp = "1.0.0" explosiveenhancement = "1.2.1-1.20.x" +moulconfig = "2.2.1" [libraries] @@ -35,6 +36,7 @@ fabric_api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fab fabric_kotlin = { module = "net.fabricmc:fabric-language-kotlin", version.ref = "fabric_kotlin" } architectury = { module = "dev.architectury:architectury", version.ref = "architectury" } rei_api = { module = "me.shedaniel:RoughlyEnoughItems-api", version.ref = "rei" } +moulconfig = { module = "org.notenoughupdates.moulconfig:modern", version.ref = "moulconfig" } repoparser = { module = "moe.nea:neurepoparser", version.ref = "neurepoparser" } dbus_java_core = { module = "com.github.hypfvieh:dbus-java-core", version.ref = "dbus_java" } dbus_java_unixsocket = { module = "com.github.hypfvieh:dbus-java-transport-native-unixsocket", version.ref = "dbus_java" } 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