aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea
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/main/kotlin/moe/nea
parent47fbb25ab280b6af9496780672780db78fe36f27 (diff)
downloadFirmament-5f535b56d0009eefcf5d70f737dd70514802763f.tar.gz
Firmament-5f535b56d0009eefcf5d70f737dd70514802763f.tar.bz2
Firmament-5f535b56d0009eefcf5d70f737dd70514802763f.zip
Inventory buttons
Diffstat (limited to 'src/main/kotlin/moe/nea')
-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
2 files changed, 91 insertions, 1 deletions
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
+ }
+
+}