From e78bd9cce6680d6638fef41661daa723b470d789 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 3 Jul 2025 12:45:26 +0200 Subject: [PATCH] add crosshair customization --- client/src/main/java/client/Client.java | 12 +++++++++--- client/src/main/java/client/gui/Gui.java | 10 +++++++++- .../main/java/client/gui/options/GuiGraphics.java | 5 +++++ .../src/main/java/client/gui/options/GuiStyle.java | 3 +-- client/src/main/java/client/vars/ColorVar.java | 10 ++++++++-- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index 0750d823..e5cbab63 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -481,6 +481,12 @@ public class Client implements IThreadListener { public int downfallRange = 4; @Variable(name = "draw_rain_particle_range", category = CVarCategory.RENDER, min = 0, max = 25, display = "Regen-Partikel-Radius") public int rainParticleRange = 10; + @Variable(name = "crosshair_size", category = CVarCategory.GUI, min = 0, max = 32, display = "Größe des Fadenkreuzes") + public int crosshairSize = 10; + @Variable(name = "crosshair_color_notarget", type = IntType.COLOR, category = CVarCategory.GUI, display = "Fadenkreuz-Farbe (ohne Ziel)") + public int crosshairColorBase = 0xffcfcfcf; + @Variable(name = "crosshair_color_target", type = IntType.COLOR, category = CVarCategory.GUI, display = "Fadenkreuz-Farbe (mit Ziel)") + public int crosshairColorTarget = 0xffffffff; @Variable(name = "tic_target", category = CVarCategory.SYSTEM, min = 1.0f, max = 1200.0f, callback = TickFunction.class, display = "Tickrate") public float tpsTarget = 20.0f; @@ -942,9 +948,9 @@ public class Client implements IThreadListener { if(this.drawDebug) { this.renderWorldDirections((float)this.tick_fraction); } - else { - Drawing.drawRect(this.fb_x / 2 - 1, this.fb_y / 2 - 16, 2, 32, this.pointed != null && this.pointed.type != ObjectType.MISS ? 0xffffffff : 0xffcfcfcf); - Drawing.drawRect(this.fb_x / 2 - 16, this.fb_y / 2 - 1, 32, 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? 0xffffffff : 0xffcfcfcf); + else if(this.crosshairSize > 0) { + Drawing.drawRect(this.fb_x / 2 - 1, this.fb_y / 2 - this.crosshairSize, 2, this.crosshairSize * 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? this.crosshairColorTarget : this.crosshairColorBase); + Drawing.drawRect(this.fb_x / 2 - this.crosshairSize, this.fb_y / 2 - 1, this.crosshairSize * 2, 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? this.crosshairColorTarget : this.crosshairColorBase); } } if(this.world != null && this.open == null) { diff --git a/client/src/main/java/client/gui/Gui.java b/client/src/main/java/client/gui/Gui.java index b8e4fbf5..0c05f342 100644 --- a/client/src/main/java/client/gui/Gui.java +++ b/client/src/main/java/client/gui/Gui.java @@ -8,8 +8,11 @@ import client.Client; import client.gui.element.Dropdown; import client.gui.element.Dropdown.Handle; import client.gui.element.Element; +import client.gui.element.Field; import client.renderer.Drawing; import client.renderer.GlState; +import client.vars.CVar; +import client.vars.ColorVar; import client.window.Bind; import client.window.Button; import client.window.Keysym; @@ -182,7 +185,12 @@ public abstract class Gui { } protected Element addSelector(String cvar, int x, int y, int w, int h) { - return this.add(this.gm.getVar(cvar).selector(x, y, w, h)); + CVar cv = this.gm.getVar(cvar); + if(cv instanceof ColorVar color) { + this.add(color.label(x, y, w)); + return this.add(color.editor(x, y, w, h)); + } + return this.add(cv.selector(x, y, w, h)); } public void draw() { diff --git a/client/src/main/java/client/gui/options/GuiGraphics.java b/client/src/main/java/client/gui/options/GuiGraphics.java index 88a0658b..64f78dc8 100644 --- a/client/src/main/java/client/gui/options/GuiGraphics.java +++ b/client/src/main/java/client/gui/options/GuiGraphics.java @@ -7,6 +7,11 @@ public class GuiGraphics extends GuiOptions { public void init(int width, int height) { this.addSelector("draw_downfall_range", 0, 0, 240, 0); this.addSelector("draw_rain_particle_range", 242, 0, 240, 0); + + this.addSelector("crosshair_size", 0, 20, 240, 0); + + this.addSelector("crosshair_color_notarget", 0, 70, 240, 0); + this.addSelector("crosshair_color_target", 242, 70, 240, 0); super.init(width, height); } diff --git a/client/src/main/java/client/gui/options/GuiStyle.java b/client/src/main/java/client/gui/options/GuiStyle.java index 45d82323..5f5021a5 100644 --- a/client/src/main/java/client/gui/options/GuiStyle.java +++ b/client/src/main/java/client/gui/options/GuiStyle.java @@ -41,8 +41,7 @@ public class GuiStyle extends GuiOptions implements DropdownCallback, Bu protected Element addSelector(String cvar, int x, int y, int w, int h) { CVar cv = this.gm.getVar(cvar); if(cv instanceof ColorVar color) { - if(!color.getDisplay().isEmpty()) - this.add(color.label(x, y, w)); + this.add(color.label(x, y, w)); if(this.gm.style != Style.CUSTOM) return this.add(new Field(x, y, w, h, color.getFieldValue(this.gm.style))); else diff --git a/client/src/main/java/client/vars/ColorVar.java b/client/src/main/java/client/vars/ColorVar.java index be15febf..f97ffe22 100644 --- a/client/src/main/java/client/vars/ColorVar.java +++ b/client/src/main/java/client/vars/ColorVar.java @@ -46,8 +46,14 @@ public class ColorVar extends IntVar { public client.gui.element.Field editor(int x, int y, int w, int h) { return new client.gui.element.Field(x, y, w, h, this.alpha ? 8 : 6, new FieldCallback() { public void use(client.gui.element.Field elem, FieldAction value) { - if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) - ColorVar.this.parse(elem.getText()); + if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) { + if(!ColorVar.this.parse(elem.getText())) + elem.setText(ColorVar.this.format()); + } + else if(value == FieldAction.FUNCTION) { + ColorVar.this.parse(ColorVar.this.getDefault()); + elem.setText(ColorVar.this.format()); + } } }, this.format()); }