Skip to content

Commit b91c004

Browse files
committed
Custom Fonts
1 parent 1d24e3d commit b91c004

67 files changed

Lines changed: 390 additions & 222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/net/wurstclient/WurstClient.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import net.wurstclient.navigator.Navigator;
3838
import net.wurstclient.other_feature.OtfList;
3939
import net.wurstclient.other_feature.OtherFeature;
40+
import net.wurstclient.font.WurstFontManager;
4041
import net.wurstclient.settings.SettingsFile;
4142
import net.wurstclient.update.ProblematicResourcePackDetector;
4243
import net.wurstclient.update.WurstUpdater;
@@ -61,6 +62,7 @@ public enum WurstClient
6162
private HackList hax;
6263
private CmdList cmds;
6364
private OtfList otfs;
65+
private WurstFontManager fontManager;
6466
private SettingsFile settingsFile;
6567
private Path settingsProfileFolder;
6668
private KeybindList keybinds;
@@ -102,6 +104,10 @@ public void initialize()
102104

103105
otfs = new OtfList();
104106

107+
fontManager =
108+
new WurstFontManager(wurstFolder, otfs.uiFontOtf.getFontSetting(),
109+
otfs.uiFontOtf.getFontScaleSetting());
110+
105111
Path settingsFile = wurstFolder.resolve("settings.json");
106112
settingsProfileFolder = wurstFolder.resolve("settings");
107113
this.settingsFile = new SettingsFile(settingsFile, hax, cmds, otfs);
@@ -247,6 +253,16 @@ public OtfList getOtfs()
247253
return otfs;
248254
}
249255

256+
public WurstFontManager getFontManager()
257+
{
258+
return fontManager;
259+
}
260+
261+
public net.minecraft.client.gui.Font getUiFont()
262+
{
263+
return fontManager.getFont();
264+
}
265+
250266
public Feature getFeatureByName(String name)
251267
{
252268
Hack hack = getHax().getHackByName(name);

src/main/java/net/wurstclient/altmanager/screens/AltManagerScreen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import net.wurstclient.clickgui.widgets.MultiSelectEntryListWidget;
5555
import net.wurstclient.mixinterface.IMinecraftClient;
5656
import net.wurstclient.util.MultiProcessingUtils;
57+
import net.wurstclient.util.WurstFont;
5758
import net.wurstclient.util.json.JsonException;
5859
import net.wurstclient.util.json.JsonUtils;
5960
import net.wurstclient.util.json.WsonObject;
@@ -628,7 +629,7 @@ public void renderContent(GuiGraphics context, int mouseX, int mouseY,
628629
AltRenderer.drawAltFace(context, alt.getName(), x + 1, y + 1, 24,
629630
24, selected);
630631

631-
Font tr = minecraft.font;
632+
Font tr = WurstFont.get();
632633

633634
// name / email
634635
context.drawString(tr, "Name: " + alt.getDisplayName(), x + 31,

src/main/java/net/wurstclient/clickgui/ClickGui.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import net.wurstclient.hacks.ClickGuiHack;
3939
import net.wurstclient.hacks.TooManyHaxHack;
4040
import net.wurstclient.settings.Setting;
41+
import net.wurstclient.util.WurstFont;
4142
import net.wurstclient.util.RenderUtils;
4243
import net.wurstclient.util.json.JsonUtils;
4344

@@ -155,6 +156,7 @@ public void init()
155156
uiSettings.add(new FeatureButton(WURST.getOtfs().wurstLogoOtf));
156157
uiSettings.add(new FeatureButton(WURST.getOtfs().hackListOtf));
157158
uiSettings.add(new FeatureButton(WURST.getOtfs().keybindManagerOtf));
159+
uiSettings.add(new FeatureButton(WURST.getOtfs().uiFontOtf));
158160
ClickGuiHack clickGuiHack = WURST.getHax().clickGuiHack;
159161
uiSettings.add(clickGuiHack.getIsolateWindowsSetting().getComponent());
160162
Stream<Setting> settings =
@@ -762,7 +764,7 @@ public void renderTooltip(GuiGraphics context, int mouseX, int mouseY)
762764
return;
763765

764766
String[] lines = tooltip.split("\n");
765-
Font tr = MC.font;
767+
Font tr = WurstFont.get();
766768

767769
int tw = 0;
768770
int th = lines.length * tr.lineHeight;
@@ -1009,7 +1011,7 @@ private void renderWindow(GuiGraphics context, Window window, int mouseX,
10091011
context.fill(x1, y1, x3, y3, titleBgColor);
10101012

10111013
// window title
1012-
Font tr = MC.font;
1014+
Font tr = WurstFont.get();
10131015
String title = tr.substrByWidth(
10141016
net.minecraft.network.chat.Component.literal(window.getTitle()),
10151017
x3 - x1).getString();

src/main/java/net/wurstclient/clickgui/ComboBoxPopup.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
import net.wurstclient.WurstClient;
1414
import net.wurstclient.settings.EnumSetting;
1515
import net.wurstclient.util.RenderUtils;
16+
import net.wurstclient.util.WurstFont;
1617

1718
public final class ComboBoxPopup<T extends Enum<T>> extends Popup
1819
{
1920
private static final ClickGui GUI = WurstClient.INSTANCE.getGui();
20-
private static final Font TR = WurstClient.MC.font;
21+
22+
private static Font getFont()
23+
{
24+
return WurstFont.get();
25+
}
26+
2127
private static final int ROW_HEIGHT = 11;
2228
private static final int MAX_VISIBLE_ROWS = 8;
2329

@@ -122,7 +128,7 @@ public void render(GuiGraphics context, int mouseX, int mouseY)
122128
GUI.getBgColor(), GUI.getOpacity() * (hValue ? 1.5F : 1)));
123129

124130
context.guiRenderState.up();
125-
context.drawString(TR, value.toString(), x1 + 2, yi1 + 2,
131+
context.drawString(getFont(), value.toString(), x1 + 2, yi1 + 2,
126132
GUI.getTxtColor(), false);
127133

128134
drawn++;

src/main/java/net/wurstclient/clickgui/StringDropdownPopup.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
import net.wurstclient.WurstClient;
1515
import net.wurstclient.settings.StringDropdownSetting;
1616
import net.wurstclient.util.RenderUtils;
17+
import net.wurstclient.util.WurstFont;
1718

1819
public final class StringDropdownPopup extends Popup
1920
{
2021
private static final ClickGui GUI = WurstClient.INSTANCE.getGui();
21-
private static final Font TR = WurstClient.MC.font;
22+
23+
private static Font getFont()
24+
{
25+
return WurstFont.get();
26+
}
27+
2228
private static final int ROW_HEIGHT = 11;
2329
private static final int MAX_VISIBLE_ROWS = 8;
2430

@@ -123,8 +129,8 @@ public void render(GuiGraphics context, int mouseX, int mouseY)
123129
GUI.getBgColor(), GUI.getOpacity() * (hValue ? 1.5F : 1)));
124130

125131
context.guiRenderState.up();
126-
context.drawString(TR, value, x1 + 2, yi1 + 2, GUI.getTxtColor(),
127-
false);
132+
context.drawString(getFont(), value, x1 + 2, yi1 + 2,
133+
GUI.getTxtColor(), false);
128134

129135
drawn++;
130136
}

src/main/java/net/wurstclient/clickgui/Window.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.client.gui.Font;
1212
import net.minecraft.util.Mth;
1313
import net.wurstclient.WurstClient;
14+
import net.wurstclient.util.WurstFont;
1415

1516
public class Window
1617
{
@@ -159,7 +160,7 @@ public final void pack()
159160
maxChildWidth = c.getDefaultWidth();
160161
maxChildWidth += 4;
161162

162-
Font tr = WurstClient.MC.font;
163+
Font tr = WurstFont.get();
163164
int titleBarWidth = tr.width(title) + 4;
164165
if(minimizable)
165166
titleBarWidth += 11;

src/main/java/net/wurstclient/clickgui/components/AbstractListEditButton.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@
1515
import net.wurstclient.clickgui.Component;
1616
import net.wurstclient.settings.Setting;
1717
import net.wurstclient.util.RenderUtils;
18+
import net.wurstclient.util.WurstFont;
1819

1920
public abstract class AbstractListEditButton extends Component
2021
{
2122
private static final ClickGui GUI = WURST.getGui();
22-
private static final Font TR = MC.font;
23+
24+
private static Font getFont()
25+
{
26+
return WurstFont.get();
27+
}
2328

2429
private final String buttonText = "Edit...";
25-
private final int buttonWidth = TR.width(buttonText);
30+
31+
private int getButtonWidth()
32+
{
33+
return getFont().width(buttonText);
34+
}
2635

2736
protected abstract void openScreen();
2837

@@ -37,6 +46,7 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton,
3746
if(mouseButton != GLFW.GLFW_MOUSE_BUTTON_LEFT)
3847
return;
3948

49+
int buttonWidth = getButtonWidth();
4050
if(mouseX < getX() + getWidth() - buttonWidth - 4)
4151
return;
4252

@@ -49,6 +59,7 @@ public void render(GuiGraphics context, int mouseX, int mouseY,
4959
{
5060
int x1 = getX();
5161
int x2 = x1 + getWidth();
62+
int buttonWidth = getButtonWidth();
5263
int x3 = x2 - buttonWidth - 4;
5364
int y1 = getY();
5465
int y2 = y1 + getHeight();
@@ -71,8 +82,9 @@ public void render(GuiGraphics context, int mouseX, int mouseY,
7182
// text
7283
int txtColor = GUI.getTxtColor();
7384
context.guiRenderState.up();
74-
context.drawString(TR, getText(), x1, y1 + 2, txtColor, false);
75-
context.drawString(TR, buttonText, x3 + 2, y1 + 2, txtColor, false);
85+
context.drawString(getFont(), getText(), x1, y1 + 2, txtColor, false);
86+
context.drawString(getFont(), buttonText, x3 + 2, y1 + 2, txtColor,
87+
false);
7688
}
7789

7890
private int getFillColor(boolean hovering)
@@ -84,7 +96,8 @@ private int getFillColor(boolean hovering)
8496
@Override
8597
public int getDefaultWidth()
8698
{
87-
return TR.width(getText()) + buttonWidth + 6;
99+
int buttonWidth = getButtonWidth();
100+
return getFont().width(getText()) + buttonWidth + 6;
88101
}
89102

90103
@Override

src/main/java/net/wurstclient/clickgui/components/BlockComponent.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@
2020
import net.wurstclient.clickgui.screens.EditBlockScreen;
2121
import net.wurstclient.settings.BlockSetting;
2222
import net.wurstclient.util.RenderUtils;
23+
import net.wurstclient.util.WurstFont;
2324

2425
public final class BlockComponent extends Component
2526
{
2627
private static final ClickGui GUI = WURST.getGui();
27-
private static final Font TR = MC.font;
28+
29+
private static Font getFont()
30+
{
31+
return WurstFont.get();
32+
}
33+
2834
private static final int BLOCK_WIDTH = 24;
2935

3036
private final BlockSetting setting;
@@ -84,7 +90,8 @@ else if(hBlock)
8490

8591
// text
8692
String name = setting.getName() + ":";
87-
context.drawString(TR, name, x1, y1 + 2, GUI.getTxtColor(), false);
93+
context.drawString(getFont(), name, x1, y1 + 2, GUI.getTxtColor(),
94+
false);
8895

8996
// block
9097
ItemStack stack = new ItemStack(setting.getBlock());
@@ -127,7 +134,7 @@ private String getBlockTooltip()
127134
@Override
128135
public int getDefaultWidth()
129136
{
130-
return TR.width(setting.getName() + ":") + BLOCK_WIDTH + 4;
137+
return getFont().width(setting.getName() + ":") + BLOCK_WIDTH + 4;
131138
}
132139

133140
@Override

src/main/java/net/wurstclient/clickgui/components/ButtonComponent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.client.input.MouseButtonEvent;
1313
import net.wurstclient.clickgui.Component;
1414
import net.wurstclient.util.RenderUtils;
15+
import net.wurstclient.util.WurstFont;
1516

1617
public final class ButtonComponent extends Component
1718
{
@@ -48,14 +49,14 @@ public void render(GuiGraphics context, int mouseX, int mouseY,
4849
int color = RenderUtils.toIntColor(WURST.getGui().getBgColor(),
4950
WURST.getGui().getOpacity() * (hover ? 1.2F : 1.0F));
5051
context.fill(x1, y1, x2, y2, color);
51-
context.drawCenteredString(MC.font, text, (x1 + x2) / 2, y1 + 2,
52+
context.drawCenteredString(WurstFont.get(), text, (x1 + x2) / 2, y1 + 2,
5253
WURST.getGui().getTxtColor());
5354
}
5455

5556
@Override
5657
public int getDefaultWidth()
5758
{
58-
return MC.font.width(text) + 8;
59+
return WurstFont.get().width(text) + 8;
5960
}
6061

6162
@Override

src/main/java/net/wurstclient/clickgui/components/CheckboxComponent.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
import net.wurstclient.clickgui.Component;
1717
import net.wurstclient.settings.CheckboxSetting;
1818
import net.wurstclient.util.RenderUtils;
19+
import net.wurstclient.util.WurstFont;
1920

2021
public final class CheckboxComponent extends Component
2122
{
2223
private static final ClickGui GUI = WURST.getGui();
23-
private static final Font TR = MC.font;
24+
25+
private static Font getFont()
26+
{
27+
return WurstFont.get();
28+
}
29+
2430
private static final int BOX_SIZE = 11;
2531

2632
private final CheckboxSetting setting;
@@ -84,7 +90,8 @@ public void render(GuiGraphics context, int mouseX, int mouseY,
8490

8591
// text
8692
String name = setting.getName();
87-
context.drawString(TR, name, x3 + 2, y1 + 2, GUI.getTxtColor(), false);
93+
context.drawString(getFont(), name, x3 + 2, y1 + 2, GUI.getTxtColor(),
94+
false);
8895
}
8996

9097
private int getFillColor(boolean hovering)
@@ -108,7 +115,7 @@ private String getTooltip()
108115
@Override
109116
public int getDefaultWidth()
110117
{
111-
return BOX_SIZE + TR.width(setting.getName()) + 2;
118+
return BOX_SIZE + getFont().width(setting.getName()) + 2;
112119
}
113120

114121
@Override

0 commit comments

Comments
 (0)