From 939f6939d0481ff3e2fdb1172b833dd10c8058d9 Mon Sep 17 00:00:00 2001 From: code-explorer786 <68312688+code-explorer786@users.noreply.github.com> Date: Fri, 28 Jun 2024 20:42:46 +0700 Subject: [PATCH] Jump curve coloring See #general-programming in the Mindustry Discord server: https://discord.com/channels/391020510269669376/663854113418641429/1256146387834372106 Co-authored-by: Ilya246 --- core/assets/bundles/bundle.properties | 1 + core/src/mindustry/logic/LCanvas.java | 17 ++++++++++++++++- .../ui/dialogs/SettingsMenuDialog.java | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 22a9289eed..ec0655afd5 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -1226,6 +1226,7 @@ setting.playerchat.name = Display Player Bubble Chat setting.showweather.name = Show Weather Graphics setting.hidedisplays.name = Hide Logic Displays setting.dynamicjumpheights.name = Dynamic Jump Heights +setting.coloredjumps.name = Colored Jumps setting.macnotch.name = Adapt interface to display notch setting.macnotch.description = Restart required to apply changes steam.friendsonly = Friends Only diff --git a/core/src/mindustry/logic/LCanvas.java b/core/src/mindustry/logic/LCanvas.java index baba9bc617..e065a343bc 100644 --- a/core/src/mindustry/logic/LCanvas.java +++ b/core/src/mindustry/logic/LCanvas.java @@ -26,6 +26,7 @@ public class LCanvas extends Table{ //ew static variables static LCanvas canvas; private static boolean dynamicJumpHeights = false; + private static boolean coloredJumps = false; public DragLayout statements; public ScrollPane pane; @@ -112,6 +113,7 @@ public class LCanvas extends Table{ jumps = statements.jumps; dynamicJumpHeights = Core.settings.getBool("dynamicjumpheights", false); + coloredJumps = Core.settings.getBool("coloredjumps", false); pane = pane(t -> { t.center(); @@ -204,6 +206,7 @@ public class LCanvas extends Table{ public Group jumps = new WidgetGroup(); private Seq processedJumps = new Seq(); public boolean updateJumpHeights = true; + private Rand rand = new Rand(); { setTransform(true); @@ -264,6 +267,16 @@ public class LCanvas extends Table{ updateJumpHeights = false; } + if(coloredJumps){ + jumps.getChildren().each(e -> { + if(!(e instanceof JumpCurve e2) || e2.button.to.get() == null) return; + int idx = e2.button.to.get().index; + if(dragging != null && idx >= dragging.index) idx += 1; + rand.setSeed((long) idx); + Color.HSVtoRGB(rand.random(0.0f, 360.0f), rand.random(80.0f, 90.0f), 100.0f, e2.button.defaultColor); + }); + } + if(parent != null) parent.invalidateHierarchy();//don't invalid self if(parent != null && parent instanceof Table){ @@ -533,7 +546,7 @@ public class LCanvas extends Table{ public static class JumpButton extends ImageButton{ Color hoverColor = Pal.place; - Color defaultColor = Color.white; + Color defaultColor = new Color(Color.white); Prov to; boolean selecting; float mx, my; @@ -673,6 +686,7 @@ public class LCanvas extends Table{ public void drawCurve(float x, float y, float x2, float y2){ Lines.stroke(4f, button.color); Draw.alpha(parentAlpha); + Draw.color(button.color); // exponential smoothing uiHeight = Mathf.lerp(100f + 100f * (float) predHeight, uiHeight, dynamicJumpHeights ? Mathf.pow(0.9f, Time.delta) : 0); @@ -698,6 +712,7 @@ public class LCanvas extends Table{ x2 + uiHeight, y2, x2, y2, Math.max(18, (int)(Mathf.dst(x, y, x2, y2) / 6))); + Draw.reset(); } public void prepareHeight(){ diff --git a/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java b/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java index 04d2d93e61..78d1a4c241 100644 --- a/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java +++ b/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java @@ -504,6 +504,7 @@ public class SettingsMenuDialog extends BaseDialog{ } graphics.checkPref("dynamicjumpheights", true); + graphics.checkPref("coloredjumps", true); } public void exportData(Fi file) throws IOException{