aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-01-18 20:57:20 +0100
committerLinnea Gräf <nea@nea.moe>2024-01-18 20:57:20 +0100
commit7255bb655768c0b9a9e6a04e4e69eb264047ef1b (patch)
treed1d6ed0f390c91df575af06dfd347a12190d5248 /src
parente93dd76b0ff0dc52a0455023486d385730aed0fc (diff)
downloadfirmament-7255bb655768c0b9a9e6a04e4e69eb264047ef1b.tar.gz
firmament-7255bb655768c0b9a9e6a04e4e69eb264047ef1b.tar.bz2
firmament-7255bb655768c0b9a9e6a04e4e69eb264047ef1b.zip
Add grid snapping to inventory buttons
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt11
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt6
-rw-r--r--src/main/resources/assets/firmament/lang/en_us.json1
3 files changed, 15 insertions, 3 deletions
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
index 66be212..f4a8f14 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt
@@ -14,9 +14,12 @@ import me.shedaniel.math.Rectangle
import org.lwjgl.glfw.GLFW
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.widget.ButtonWidget
+import net.minecraft.client.util.InputUtil
import net.minecraft.text.Text
+import net.minecraft.util.math.MathHelper
import moe.nea.firmament.util.ClipboardUtils
import moe.nea.firmament.util.FragmentGuiScreen
+import moe.nea.firmament.util.MC
import moe.nea.firmament.util.MoulConfigUtils
class InventoryButtonEditor(
@@ -119,8 +122,12 @@ class InventoryButtonEditor(
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
+ 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)) {
+ offsetX = MathHelper.floor(offsetX / 20F) * 20
+ offsetY = MathHelper.floor(offsetY / 20F) * 20
+ }
buttons.add(InventoryButton(offsetX, offsetY, anchorRight, anchorBottom, null, null))
return true
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt
index 85e1d88..1fe222d 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt
@@ -23,7 +23,11 @@ object InventoryButtons : FirmamentFeature {
override val identifier: String
get() = "inventory-buttons"
- object TConfig : ManagedConfig(identifier) {}
+ object TConfig : ManagedConfig(identifier) {
+ val _openEditor by button("open-editor") {
+ openEditor()
+ }
+ }
object DConfig : DataHolder<Data>(serializer(), identifier, ::Data)
@Serializable
diff --git a/src/main/resources/assets/firmament/lang/en_us.json b/src/main/resources/assets/firmament/lang/en_us.json
index 897365f..2f3f4d9 100644
--- a/src/main/resources/assets/firmament/lang/en_us.json
+++ b/src/main/resources/assets/firmament/lang/en_us.json
@@ -73,6 +73,7 @@
"firmament.inventory-buttons.load-preset": "Load Preset",
"firmament.inventory-buttons.import-failed": "One of your buttons could only be imported partially",
"firmament.config.inventory-buttons": "Inventory buttons",
+ "firmament.config.inventory-buttons.open-editor": "Open Editor",
"firmament.waypoint.temporary": "Temporary Waypoint: %s",
"firmament.config.waypoints": "Waypoints",
"firmament.config.waypoints.temp-waypoint-duration": "Temporary Waypoint Duration",