Skip to content

Commit 86381ef

Browse files
committed
Improved waypoint label handling
1 parent 12dea51 commit 86381ef

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

src/main/java/net/wurstclient/clickgui/screens/WaypointEditScreen.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public final class WaypointEditScreen extends Screen
4343
private TextFieldWidget zField;
4444
private ButtonWidget colorButton;
4545
private ColorSetting colorSetting;
46+
// Draft values to preserve user input across color picker navigation
47+
private String draftName;
48+
private String draftX;
49+
private String draftY;
50+
private String draftZ;
4651

4752
private int dimIndex;
4853
private ButtonWidget dimButton;
@@ -79,7 +84,8 @@ protected void init()
7984
yName = y;
8085
nameField = new TextFieldWidget(client.textRenderer, x, y, 300, 20,
8186
Text.literal(""));
82-
nameField.setText(waypoint.getName() == null ? "" : waypoint.getName());
87+
String baseName = waypoint.getName() == null ? "" : waypoint.getName();
88+
nameField.setText(draftName != null ? draftName : baseName);
8389
addDrawableChild(nameField);
8490
setFocused(nameField);
8591
// increased gap to avoid XYZ labels overlapping name field
@@ -90,15 +96,15 @@ protected void init()
9096
yXYZ = y;
9197
xField = new TextFieldWidget(client.textRenderer, x, y, 95, 20,
9298
Text.literal(""));
93-
xField.setText(Integer.toString(p.getX()));
99+
xField.setText(draftX != null ? draftX : Integer.toString(p.getX()));
94100
addDrawableChild(xField);
95101
yField = new TextFieldWidget(client.textRenderer, x + 102, y, 95, 20,
96102
Text.literal(""));
97-
yField.setText(Integer.toString(p.getY()));
103+
yField.setText(draftY != null ? draftY : Integer.toString(p.getY()));
98104
addDrawableChild(yField);
99105
zField = new TextFieldWidget(client.textRenderer, x + 204, y, 96, 20,
100106
Text.literal(""));
101-
zField.setText(Integer.toString(p.getZ()));
107+
zField.setText(draftZ != null ? draftZ : Integer.toString(p.getZ()));
102108
addDrawableChild(zField);
103109
y += 28;
104110

@@ -190,6 +196,12 @@ protected void init()
190196
Text.literal(
191197
"Pick color (#" + toHex6(colorSetting.getColorI()) + ")"),
192198
b -> {
199+
// Preserve current edits so they survive re-init after
200+
// returning
201+
draftName = nameField.getText();
202+
draftX = xField.getText();
203+
draftY = yField.getText();
204+
draftZ = zField.getText();
193205
client.setScreen(new EditColorScreen(this, colorSetting));
194206
}).dimensions(x, y, 300 - 24, 20).build();
195207
addDrawableChild(colorButton);

src/main/java/net/wurstclient/hacks/WaypointsHack.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ public final class WaypointsHack extends Hack implements RenderListener,
4747
private long lastDeathCreatedMs;
4848

4949
private final SliderSetting textRenderDistance = new SliderSetting(
50-
"Text render distance", 127, 16, 1024, 1, ValueDisplay.INTEGER);
50+
"Text render distance", 127, 0, 2000, 1, ValueDisplay.INTEGER);
51+
private final CheckboxSetting alwaysRenderText =
52+
new CheckboxSetting("Always render text", false);
5153
private final SliderSetting fadeDistance = new SliderSetting(
5254
"Waypoint fade distance", 20, 0, 100, 1, ValueDisplay.INTEGER);
5355
private final SliderSetting maxDeathPositions = new SliderSetting(
5456
"Max death positions", 4, 0, 20, 1, ValueDisplay.INTEGER);
5557
private final SliderSetting labelScale = new SliderSetting("Label scale",
56-
2.0, 0.5, 15.0, 0.1, ValueDisplay.DECIMAL);
58+
2.0, 0.5, 10.0, 0.1, ValueDisplay.DECIMAL);
5759
private final CheckboxSetting chatOnDeath =
5860
new CheckboxSetting("Chat", true);
5961
private final CheckboxSetting createDeathWaypoints =
@@ -72,6 +74,7 @@ public WaypointsHack()
7274
"Manage waypoints", this.manager));
7375

7476
addSetting(textRenderDistance);
77+
addSetting(alwaysRenderText);
7578
addSetting(fadeDistance);
7679
addSetting(maxDeathPositions);
7780
addSetting(chatOnDeath);
@@ -162,27 +165,44 @@ public void onRender(MatrixStack matrices, float partialTicks)
162165

163166
// labels near distance
164167
double dist = Math.sqrt(distSq);
165-
if(dist <= textRenderDistance.getValue())
168+
if(alwaysRenderText.isChecked()
169+
|| dist <= textRenderDistance.getValue())
166170
{
167171
String title = w.getName() == null ? "" : w.getName();
168172
String icon = iconChar(w.getIcon());
169173
if(!icon.isEmpty())
170174
title = icon + (title.isEmpty() ? "" : " " + title);
171175
String distanceText = (int)dist + " blocks";
172176
double baseY = wp.getY() + 1.2;
177+
double lx = wp.getX() + 0.5;
178+
double ly = baseY;
179+
double lz = wp.getZ() + 0.5;
180+
// If always-render is on, anchor the label along the ray from
181+
// the
182+
// camera to the waypoint, to keep it within a stable render
183+
// range.
184+
if(alwaysRenderText.isChecked())
185+
{
186+
Vec3d cam = RenderUtils.getCameraPos();
187+
Vec3d target = new Vec3d(lx, ly, lz);
188+
Vec3d dir = target.subtract(cam);
189+
double len = dir.length();
190+
if(len > 1e-3)
191+
{
192+
double anchor = Math.min(len, 12.0);
193+
Vec3d anchored = cam.add(dir.multiply(anchor / len));
194+
lx = anchored.x;
195+
ly = anchored.y;
196+
lz = anchored.z;
197+
}
198+
}
173199
float scale = (float)labelScale.getValue();
174-
// Compensate for distance so on-screen size stays roughly
175-
// constant
176-
double compensate = Math.max(1.0, Math.sqrt(distSq) * 0.1);
177-
scale *= (float)compensate;
178200
// Keep a constant 10px separation using local pixel offset
179201
float sepPx = 10.0f;
180-
drawWorldLabel(matrices, title, wp.getX() + 0.5, baseY,
181-
wp.getZ() + 0.5, applyFade(w.getColor(), distSq), scale,
182-
-sepPx);
183-
drawWorldLabel(matrices, distanceText, wp.getX() + 0.5, baseY,
184-
wp.getZ() + 0.5, applyFade(w.getColor(), distSq),
185-
(float)(scale * 0.9f), 0f);
202+
drawWorldLabel(matrices, title, lx, ly, lz,
203+
applyFade(w.getColor(), distSq), scale, -sepPx);
204+
drawWorldLabel(matrices, distanceText, lx, ly, lz,
205+
applyFade(w.getColor(), distSq), (float)(scale * 0.9f), 0f);
186206
}
187207
}
188208
}

0 commit comments

Comments
 (0)