Skip to content

Commit 586b6e0

Browse files
committed
ConnectionLogOverlay Font Scaler
1 parent ab48ca0 commit 586b6e0

File tree

4 files changed

+106
-65
lines changed

4 files changed

+106
-65
lines changed

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

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ public final class TunnelHoleStairEspHack extends Hack
208208
private final ArrayList<AABB> bubbleColumnBoxes = new ArrayList<>();
209209
private final ArrayList<AABB> waterColumnBoxes = new ArrayList<>();
210210

211-
private int scanConfigHash;
212-
private int refreshTimerTicks;
213-
private Level activeLevel;
211+
private int scanConfigHash;
212+
private int refreshTimerTicks;
213+
private Level activeLevel;
214214

215215
public TunnelHoleStairEspHack()
216216
{
@@ -274,58 +274,57 @@ public String getRenderName()
274274
}
275275

276276
@Override
277-
protected void onEnable()
278-
{
279-
scanConfigHash = getScanConfigHash();
280-
refreshTimerTicks = 0;
281-
lastAreaSelection = area.getSelected();
282-
activeLevel = null;
283-
clearRuntimeState();
284-
EVENTS.add(UpdateListener.class, this);
285-
EVENTS.add(RenderListener.class, this);
286-
EVENTS.add(CameraTransformViewBobbingListener.class, this);
287-
EVENTS.add(PacketInputListener.class, this);
277+
protected void onEnable()
278+
{
279+
scanConfigHash = getScanConfigHash();
280+
refreshTimerTicks = 0;
281+
lastAreaSelection = area.getSelected();
282+
activeLevel = null;
283+
clearRuntimeState();
284+
EVENTS.add(UpdateListener.class, this);
285+
EVENTS.add(RenderListener.class, this);
286+
EVENTS.add(CameraTransformViewBobbingListener.class, this);
287+
EVENTS.add(PacketInputListener.class, this);
288288
}
289289

290290
@Override
291-
protected void onDisable()
292-
{
293-
EVENTS.remove(UpdateListener.class, this);
294-
EVENTS.remove(RenderListener.class, this);
295-
EVENTS.remove(CameraTransformViewBobbingListener.class, this);
296-
EVENTS.remove(PacketInputListener.class, this);
297-
activeLevel = null;
298-
clearRuntimeState();
299-
}
291+
protected void onDisable()
292+
{
293+
EVENTS.remove(UpdateListener.class, this);
294+
EVENTS.remove(RenderListener.class, this);
295+
EVENTS.remove(CameraTransformViewBobbingListener.class, this);
296+
EVENTS.remove(PacketInputListener.class, this);
297+
activeLevel = null;
298+
clearRuntimeState();
299+
}
300300

301-
@Override
302-
public void onUpdate()
303-
{
304-
if(MC.player == null || MC.level == null)
305-
{
306-
// Clear stale detections while disconnecting or switching worlds.
307-
if(activeLevel != null || !detectionsByChunk.isEmpty()
308-
|| !holeBoxes.isEmpty() || !tunnelBoxes.isEmpty()
309-
|| !stairBoxes.isEmpty() || !ladderBoxes.isEmpty()
310-
|| !bubbleColumnBoxes.isEmpty()
311-
|| !waterColumnBoxes.isEmpty())
312-
{
313-
activeLevel = null;
314-
clearRuntimeState();
315-
}
316-
return;
317-
}
318-
319-
if(activeLevel != MC.level)
320-
{
321-
activeLevel = MC.level;
322-
refreshTimerTicks = 0;
323-
lastAreaSelection = area.getSelected();
324-
scanConfigHash = getScanConfigHash();
325-
clearRuntimeState();
326-
}
327-
328-
ChunkAreaSetting.ChunkArea currentAreaSelection = area.getSelected();
301+
@Override
302+
public void onUpdate()
303+
{
304+
if(MC.player == null || MC.level == null)
305+
{
306+
// Clear stale detections while disconnecting or switching worlds.
307+
if(activeLevel != null || !detectionsByChunk.isEmpty()
308+
|| !holeBoxes.isEmpty() || !tunnelBoxes.isEmpty()
309+
|| !stairBoxes.isEmpty() || !ladderBoxes.isEmpty()
310+
|| !bubbleColumnBoxes.isEmpty() || !waterColumnBoxes.isEmpty())
311+
{
312+
activeLevel = null;
313+
clearRuntimeState();
314+
}
315+
return;
316+
}
317+
318+
if(activeLevel != MC.level)
319+
{
320+
activeLevel = MC.level;
321+
refreshTimerTicks = 0;
322+
lastAreaSelection = area.getSelected();
323+
scanConfigHash = getScanConfigHash();
324+
clearRuntimeState();
325+
}
326+
327+
ChunkAreaSetting.ChunkArea currentAreaSelection = area.getSelected();
329328

330329
if(currentAreaSelection != lastAreaSelection)
331330
{

src/main/java/net/wurstclient/other_features/ConnectionLogOverlayOtf.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@
88
package net.wurstclient.other_features;
99

1010
import net.wurstclient.settings.CheckboxSetting;
11+
import net.wurstclient.settings.SliderSetting;
12+
import net.wurstclient.settings.SliderSetting.ValueDisplay;
1113
import net.wurstclient.other_feature.OtherFeature;
1214

1315
public final class ConnectionLogOverlayOtf extends OtherFeature
1416
{
1517
private final CheckboxSetting showConnectionLog =
1618
new CheckboxSetting("Connection log overlay", true);
19+
private final SliderSetting fontScale = new SliderSetting("Font size", 0.7,
20+
0.5, 3.0, 0.05, ValueDisplay.DECIMAL);
1721

1822
public ConnectionLogOverlayOtf()
1923
{
2024
super("ConnectionLogOverlay",
2125
"description.wurst.other_feature.connection_log_overlay");
2226
addSetting(showConnectionLog);
27+
addSetting(fontScale);
2328
}
2429

2530
public CheckboxSetting getConnectionLogSetting()
@@ -31,4 +36,14 @@ public boolean isConnectionLogEnabled()
3136
{
3237
return showConnectionLog.isChecked();
3338
}
39+
40+
public double getFontScale()
41+
{
42+
return fontScale.getValue();
43+
}
44+
45+
public SliderSetting getFontScaleSetting()
46+
{
47+
return fontScale;
48+
}
3449
}

src/main/java/net/wurstclient/other_features/WurstOptionsOtf.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void linkAdditionalSettings(DisableOtf disableOtf,
6262
"Open the latest Wurst changelog in your browser.",
6363
changelogOtf::doPrimaryAction));
6464
addSetting(connectionLogOverlayOtf.getConnectionLogSetting());
65+
addSetting(connectionLogOverlayOtf.getFontScaleSetting());
6566
addSetting(noTelemetryOtf.getDisableTelemetrySetting());
6667
addSetting(noChatReportsOtf.getDisableSignaturesSetting());
6768
addSetting(forceAllowChatsOtf.getForceAllowChatsSetting());

src/main/java/net/wurstclient/util/ConnectionLogOverlay.java

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,32 @@ public static ConnectionLogOverlay getInstance()
5959

6060
public void render(GuiGraphics graphics)
6161
{
62-
if(!shouldRender())
63-
return;
64-
6562
Minecraft mc = WurstClient.MC;
6663
if(mc == null)
6764
return;
6865

66+
ConnectionLogOverlayOtf otf = getSettings();
67+
if(otf == null || !otf.isConnectionLogEnabled())
68+
return;
69+
6970
Font font = mc.font;
71+
double fontScale = otf.getFontScale();
7072
int scaledWidth = mc.getWindow().getGuiScaledWidth();
7173
List<String> visibleLines = getVisibleLines();
7274
if(visibleLines.isEmpty())
7375
return;
7476

7577
int availableWidth =
7678
Math.max(64, scaledWidth - HORIZONTAL_MARGIN * 2 - BOX_PADDING * 2);
79+
int availableUnscaledWidth =
80+
Math.max(60, (int)Math.floor(availableWidth / fontScale));
7781
List<FormattedCharSequence> split = new ArrayList<>();
7882
for(String line : visibleLines)
7983
{
8084
if(line == null)
8185
continue;
8286
List<FormattedCharSequence> fragments =
83-
font.split(Component.literal(line), availableWidth);
87+
font.split(Component.literal(line), availableUnscaledWidth);
8488
if(fragments.isEmpty())
8589
continue;
8690
split.addAll(fragments);
@@ -89,7 +93,9 @@ public void render(GuiGraphics graphics)
8993
if(split.isEmpty())
9094
return;
9195

92-
int maxLineWidth = split.stream().mapToInt(font::width).max().orElse(0);
96+
int maxLineWidth = split.stream()
97+
.mapToInt(line -> (int)Math.round(font.width(line) * fontScale))
98+
.max().orElse(0);
9399
if(maxLineWidth <= 0)
94100
return;
95101

@@ -98,8 +104,12 @@ public void render(GuiGraphics graphics)
98104
if(boxWidth <= 0)
99105
return;
100106

101-
int textHeight = split.size() * font.lineHeight
102-
+ Math.max(0, split.size() - 1) * LINE_SPACING;
107+
int scaledLineHeight =
108+
Math.max(1, (int)Math.round(font.lineHeight * fontScale));
109+
int scaledLineSpacing =
110+
Math.max(0, (int)Math.round(LINE_SPACING * fontScale));
111+
int textHeight = split.size() * scaledLineHeight
112+
+ Math.max(0, split.size() - 1) * scaledLineSpacing;
103113
int boxHeight = textHeight + BOX_PADDING * 2;
104114
if(boxHeight <= 0)
105115
return;
@@ -113,19 +123,35 @@ public void render(GuiGraphics graphics)
113123
int textY = y + BOX_PADDING;
114124
for(FormattedCharSequence line : split)
115125
{
116-
graphics.drawString(font, line, textX, textY, 0xFFFFFFFF, false);
117-
textY += font.lineHeight + LINE_SPACING;
126+
drawScaledLine(graphics, font, line, textX, textY, 0xFFFFFFFF,
127+
fontScale);
128+
textY += scaledLineHeight + scaledLineSpacing;
118129
}
119130
}
120131

121-
private boolean shouldRender()
132+
private ConnectionLogOverlayOtf getSettings()
122133
{
123134
if(!WurstClient.INSTANCE.isEnabled())
124-
return false;
135+
return null;
136+
137+
return WurstClient.INSTANCE.getOtfs().connectionLogOverlayOtf;
138+
}
139+
140+
private void drawScaledLine(GuiGraphics graphics, Font font,
141+
FormattedCharSequence line, int x, int y, int color, double scale)
142+
{
143+
if(Math.abs(scale - 1.0) < 1e-6)
144+
{
145+
graphics.drawString(font, line, x, y, color, false);
146+
return;
147+
}
125148

126-
ConnectionLogOverlayOtf otf =
127-
WurstClient.INSTANCE.getOtfs().connectionLogOverlayOtf;
128-
return otf != null && otf.isConnectionLogEnabled();
149+
graphics.pose().pushMatrix();
150+
graphics.pose().scale((float)scale);
151+
int sx = (int)Math.round(x / scale);
152+
int sy = (int)Math.round(y / scale);
153+
graphics.drawString(font, line, sx, sy, color, false);
154+
graphics.pose().popMatrix();
129155
}
130156

131157
private void registerAppender()

0 commit comments

Comments
 (0)