From b7fdf7b6f9d6da153a6991d380dd770ab6545c52 Mon Sep 17 00:00:00 2001 From: Skye Date: Fri, 23 Aug 2024 06:47:24 +0000 Subject: [PATCH] Add option to have click toggle drawing instead of dragging --- .../petrak/hexcasting/api/mod/HexConfig.java | 3 +++ .../hexcasting/client/gui/GuiSpellcasting.kt | 26 +++++++++++++++++++ .../hexcasting/lang/en_us.flatten.json5 | 4 +++ .../hexcasting/fabric/FabricHexConfig.java | 7 +++++ .../hexcasting/forge/ForgeHexConfig.java | 9 +++++++ 5 files changed, 49 insertions(+) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java index 105994f61d..6f17226b16 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java @@ -47,10 +47,13 @@ public interface ClientConfigAccess { double gridSnapThreshold(); + boolean clickingTogglesDrawing(); + boolean DEFAULT_CTRL_TOGGLES_OFF_STROKE_ORDER = false; boolean DEFAULT_INVERT_SPELLBOOK_SCROLL = false; boolean DEFAULT_INVERT_ABACUS_SCROLL = false; double DEFAULT_GRID_SNAP_THRESHOLD = 0.5; + boolean DEFAULT_CLICKING_TOGGLES_DRAWING = false; } public interface ServerConfigAccess { diff --git a/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt b/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt index a039b5264b..0a9f66cd2b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt +++ b/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt @@ -131,7 +131,16 @@ class GuiSpellcasting constructor( if (super.mouseClicked(mxOut, myOut, pButton)) { return true } + if (HexConfig.client().clickingTogglesDrawing()) { + return if (this.drawState is PatternDrawState.BetweenPatterns) + drawStart(mxOut, myOut) + else + drawEnd() + } + return drawStart(mxOut, myOut) + } + private fun drawStart(mxOut: Double, myOut: Double): Boolean { val mx = Mth.clamp(mxOut, 0.0, this.width.toDouble()) val my = Mth.clamp(myOut, 0.0, this.height.toDouble()) if (this.drawState is PatternDrawState.BetweenPatterns) { @@ -156,11 +165,23 @@ class GuiSpellcasting constructor( return false } + override fun mouseMoved(mxOut: Double, myOut: Double) { + super.mouseMoved(mxOut, myOut) + + if (HexConfig.client().clickingTogglesDrawing() && this.drawState !is PatternDrawState.BetweenPatterns) + drawMove(mxOut, myOut) + } + override fun mouseDragged(mxOut: Double, myOut: Double, pButton: Int, pDragX: Double, pDragY: Double): Boolean { if (super.mouseDragged(mxOut, myOut, pButton, pDragX, pDragY)) { return true } + if (HexConfig.client().clickingTogglesDrawing()) + return false + return drawMove(mxOut, myOut) + } + private fun drawMove(mxOut: Double, myOut: Double): Boolean { val mx = Mth.clamp(mxOut, 0.0, this.width.toDouble()) val my = Mth.clamp(myOut, 0.0, this.height.toDouble()) @@ -237,7 +258,12 @@ class GuiSpellcasting constructor( if (super.mouseReleased(mx, my, pButton)) { return true } + if (HexConfig.client().clickingTogglesDrawing()) + return false + return drawEnd() + } + private fun drawEnd(): Boolean { when (this.drawState) { PatternDrawState.BetweenPatterns -> {} is PatternDrawState.JustStarted -> { diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 index ea81041b3f..b63c1cd359 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 @@ -300,6 +300,10 @@ "": "Grid Snap Threshold", "@Tooltip": "When using a staff, the distance from one dot you have to go to snap to the next dot, where 0.5 means 50% of the way (0.5-1)", }, + clickingTogglesDrawing: { + "": "Clicking Toggles Drawing", + "@Tooltip": "Whether you click to start and stop drawing instead of clicking and dragging to draw", + }, }, server: { diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java index 7622e7cf8f..4680f8c1a1 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java @@ -132,6 +132,8 @@ public static final class Client implements HexConfig.ClientConfigAccess, Config private boolean invertAbacusScrollDirection = DEFAULT_INVERT_SPELLBOOK_SCROLL; @ConfigEntry.Gui.Tooltip private double gridSnapThreshold = DEFAULT_GRID_SNAP_THRESHOLD; + @ConfigEntry.Gui.Tooltip + private boolean clickingTogglesDrawing = DEFAULT_CLICKING_TOGGLES_DRAWING; @Override public void validatePostLoad() throws ValidationException { @@ -157,6 +159,11 @@ public boolean invertAbacusScrollDirection() { public double gridSnapThreshold() { return gridSnapThreshold; } + + @Override + public boolean clickingTogglesDrawing() { + return clickingTogglesDrawing; + } } @Config(name = "server") diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java index 507d1fece7..bf219312fc 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java @@ -82,6 +82,7 @@ public static class Client implements HexConfig.ClientConfigAccess { private static ForgeConfigSpec.BooleanValue invertSpellbookScrollDirection; private static ForgeConfigSpec.BooleanValue invertAbacusScrollDirection; private static ForgeConfigSpec.DoubleValue gridSnapThreshold; + private static ForgeConfigSpec.BooleanValue clickingTogglesDrawing; public Client(ForgeConfigSpec.Builder builder) { ctrlTogglesOffStrokeOrder = builder.comment( @@ -98,6 +99,9 @@ public Client(ForgeConfigSpec.Builder builder) { "When using a staff, the distance from one dot you have to go to snap to the next dot, where 0.5 " + "means 50% of the way.") .defineInRange("gridSnapThreshold", DEFAULT_GRID_SNAP_THRESHOLD, 0.5, 1.0); + clickingTogglesDrawing = builder.comment( + "Whether you click to start and stop drawing instead of clicking and dragging") + .define("clickingTogglesDrawing", DEFAULT_CLICKING_TOGGLES_DRAWING); } @Override @@ -119,6 +123,11 @@ public boolean ctrlTogglesOffStrokeOrder() { public double gridSnapThreshold() { return gridSnapThreshold.get(); } + + @Override + public boolean clickingTogglesDrawing() { + return clickingTogglesDrawing.get(); + } } public static class Server implements HexConfig.ServerConfigAccess {