Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 33 additions & 41 deletions src/main/java/dsns/betterhud/BetterHUDGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,48 +79,31 @@ public void onHudRender(

for (CustomText text : topLeftText) {
drawString(drawContext, text, x, y);

y +=
(client.font.lineHeight - 1) +
(verticalPadding * 2) +
lineHeight;
y += scaledElementHeight(text) + lineHeight;
}

y = client.getWindow().getGuiScaledHeight() - verticalMargin;

for (CustomText text : bottomLeftList) {
y -= (client.font.lineHeight - 1) + (verticalPadding * 2);
y -= scaledElementHeight(text);
drawString(drawContext, text, x, y);
y -= lineHeight;
}

y = verticalMargin;
for (CustomText text : topRightText) {
int offset =
(client.font.width(text.text) - 1) +
(horizontalPadding * 2) +
horizontalMargin;
int offset = scaledElementWidth(text) + horizontalMargin;
x = client.getWindow().getGuiScaledWidth() - offset;
drawString(drawContext, text, x, y);

y +=
(client.font.lineHeight - 1) +
(verticalPadding * 2) +
lineHeight;
y += scaledElementHeight(text) + lineHeight;
}

y = client.getWindow().getGuiScaledHeight() - verticalMargin;
for (CustomText text : bottomRightText) {
int offset =
(client.font.width(text.text) - 1) +
(horizontalPadding * 2) +
horizontalMargin;
int offset = scaledElementWidth(text) + horizontalMargin;
x = client.getWindow().getGuiScaledWidth() - offset;

y -= (client.font.lineHeight - 1) + (verticalPadding * 2);

y -= scaledElementHeight(text);
drawString(drawContext, text, x, y);

y -= lineHeight;
}

Expand All @@ -130,17 +113,15 @@ public void onHudRender(

int maxX =
client.getWindow().getGuiScaledWidth() -
(horizontalPadding * 2) -
(client.font.width(text.text) - 1);
scaledElementWidth(text);
int maxY =
client.getWindow().getGuiScaledHeight() -
(verticalPadding * 2) -
(client.font.lineHeight - 1);
scaledElementHeight(text);

int scaledX = (int) (xPercent * maxX);
int scaledY = (int) (yPercent * maxY);
int posX = (int) (xPercent * maxX);
int posY = (int) (yPercent * maxY);

drawString(drawContext, text, scaledX, scaledY);
drawString(drawContext, text, posX, posY);
}
}

Expand All @@ -150,23 +131,34 @@ private void drawString(
int x,
int y
) {
drawContext.fill(
x,
y,
x +
(client.font.width(text.text) - 1) +
(horizontalPadding * 2),
y + (client.font.lineHeight - 1) + (verticalPadding * 2),
text.backgroundColor
);
var poses = drawContext.pose();
poses.pushMatrix();
poses.translate((float) x, (float) y);
poses.scale(text.scale, text.scale);

int w = (client.font.width(text.text) - 1) + (horizontalPadding * 2);
int h = (client.font.lineHeight - 1) + (verticalPadding * 2);

drawContext.fill(0, 0, w, h, text.backgroundColor);
drawContext.text(
client.font,
text.text,
x + horizontalPadding,
y + verticalPadding,
horizontalPadding,
verticalPadding,
text.color,
true
);

poses.popMatrix();
}

private int scaledElementWidth(CustomText text) {
int w = (client.font.width(text.text) - 1) + (horizontalPadding * 2);
return (int) (w * text.scale);
}

private int scaledElementHeight(CustomText text) {
int h = (client.font.lineHeight - 1) + (verticalPadding * 2);
return (int) (h * text.scale);
}
}
8 changes: 8 additions & 0 deletions src/main/java/dsns/betterhud/ModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
.build()
);
} else if (setting.getType().equals("double")) {
double min = Double.parseDouble(
setting.getPossibleValues()[0]
);
double max = Double.parseDouble(
setting.getPossibleValues()[1]
);
category.addEntry(
entryBuilder
.startDoubleField(
Expand All @@ -99,6 +105,8 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
setting.getDefaultValue()
)
)
.setMin(min)
.setMax(max)
.setSaveConsumer(value ->
setting.setValue(String.valueOf(value))
)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dsns/betterhud/util/CustomText.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class CustomText {
public String text;
public int color; // colors are in ARGB format
public int backgroundColor; // colors are in ARGB format
public float scale = 1.0f;
public boolean customPosition = false;
public int customX = 0;
public int customY = 0;
Expand All @@ -21,6 +22,7 @@ public CustomText(String text, ModSettings settings) {
settings.getSetting("Text Color").getColorValue(),
settings.getSetting("Background Color").getColorValue()
);
this.scale = (float) settings.getSetting("Scale").getDoubleValue();
}

public CustomText(String text, int color, ModSettings settings) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dsns/betterhud/util/ModSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public ModSettings() {
settings.put("Custom Position", Setting.createBooleanSetting(false));
settings.put("Custom X", Setting.createIntegerSetting(0, 0, 100));
settings.put("Custom Y", Setting.createIntegerSetting(0, 0, 100));
settings.put("Scale", Setting.createDoubleSetting(1.0, 0.5, 3.0));
settings.put("Text Color", Setting.createColorSetting(0xffffffff));
settings.put(
"Background Color",
Expand Down