aboutsummaryrefslogtreecommitdiff
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
parent47fbb25ab280b6af9496780672780db78fe36f27 (diff)
downloadfirmament-5f535b56d0009eefcf5d70f737dd70514802763f.tar.gz
firmament-5f535b56d0009eefcf5d70f737dd70514802763f.tar.bz2
firmament-5f535b56d0009eefcf5d70f737dd70514802763f.zip
Inventory buttons
-rw-r--r--build.gradle.kts3
-rw-r--r--gradle/libs.versions.toml2
-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
6 files changed, 126 insertions, 1 deletions
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<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>