Skip to content

Commit

Permalink
Merge branch 'main' into fix-misc-docs-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gamma-delta authored Sep 10, 2024
2 parents 8cea4f1 + cdfe88c commit 43707c2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())

Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -157,6 +159,11 @@ public boolean invertAbacusScrollDirection() {
public double gridSnapThreshold() {
return gridSnapThreshold;
}

@Override
public boolean clickingTogglesDrawing() {
return clickingTogglesDrawing;
}
}

@Config(name = "server")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 43707c2

Please sign in to comment.