update dependencies and fix a small issue with GUI Scale

This commit is contained in:
Frederik Spirgi
2026-10-08 09:28:44 +02:00
parent cfccdd9b36
commit efb1b98868
4 changed files with 65 additions and 27 deletions
@@ -57,8 +57,9 @@ public class StatsScreen extends Screen {
private final Minecraft minecraft = Minecraft.getInstance();
private final Map<String, Button> plusButtons = new HashMap<>();
private int leftPos;
private int topPos;
private float uiScale = 1.0F;
private int uiLeft;
private int uiTop;
private String hoveredAttributeKey;
public StatsScreen() {
@@ -68,8 +69,10 @@ public class StatsScreen extends Screen {
@Override
protected void init() {
super.init();
leftPos = (width - WIDTH) / 2;
topPos = (height - HEIGHT) / 2;
uiScale = Math.min(1.0F, Math.min((width - 12.0F) / WIDTH, (height - 12.0F) / HEIGHT));
uiScale = Math.max(0.25F, uiScale);
uiLeft = Math.round((width - WIDTH * uiScale) / 2.0F);
uiTop = Math.round((height - HEIGHT * uiScale) / 2.0F);
plusButtons.clear();
clearWidgets();
@@ -77,8 +80,8 @@ public class StatsScreen extends Screen {
String attribute = ATTRIBUTES[index];
int column = index % 2;
int row = index / 2;
int cardX = leftPos + PADDING + column * (CARD_WIDTH + COLUMN_GAP);
int cardY = topPos + CARDS_TOP + row * (CARD_HEIGHT + CARD_GAP);
int cardX = PADDING + column * (CARD_WIDTH + COLUMN_GAP);
int cardY = CARDS_TOP + row * (CARD_HEIGHT + CARD_GAP);
Button plus = Button.builder(Component.literal("+"), button ->
PacketHandler.INSTANCE.sendToServer(new ServerboundSpendPointPacket(attribute)))
.bounds(cardX + CARD_WIDTH - 30, cardY + 5, 22, 18)
@@ -88,16 +91,23 @@ public class StatsScreen extends Screen {
}
addRenderableWidget(Button.builder(Component.translatable("gui.done"), button -> onClose())
.bounds(leftPos + WIDTH / 2 - 45, topPos + HEIGHT - 24, 90, 18)
.bounds(WIDTH / 2 - 45, HEIGHT - 24, 90, 18)
.build());
}
@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
renderBackground(graphics);
drawWindow(graphics);
hoveredAttributeKey = null;
int uiMouseX = (int) toUiX(mouseX);
int uiMouseY = (int) toUiY(mouseY);
graphics.pose().pushPose();
graphics.pose().translate(uiLeft, uiTop, 0.0F);
graphics.pose().scale(uiScale, uiScale, 1.0F);
drawWindow(graphics);
if (minecraft.player != null) {
minecraft.player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
drawProgression(graphics, stats.getAscendLevel(), stats.getMaxAscendLevel(),
@@ -107,11 +117,11 @@ public class StatsScreen extends Screen {
String attribute = ATTRIBUTES[index];
int column = index % 2;
int row = index / 2;
int cardX = leftPos + PADDING + column * (CARD_WIDTH + COLUMN_GAP);
int cardY = topPos + CARDS_TOP + row * (CARD_HEIGHT + CARD_GAP);
int cardX = PADDING + column * (CARD_WIDTH + COLUMN_GAP);
int cardY = CARDS_TOP + row * (CARD_HEIGHT + CARD_GAP);
int value = stats.getAttributeLevel(attribute);
boolean hovered = mouseX >= cardX && mouseX < cardX + CARD_WIDTH
&& mouseY >= cardY && mouseY < cardY + CARD_HEIGHT;
boolean hovered = uiMouseX >= cardX && uiMouseX < cardX + CARD_WIDTH
&& uiMouseY >= cardY && uiMouseY < cardY + CARD_HEIGHT;
drawAttributeCard(graphics, attribute, value, stats.getMaxAttributePoints(), cardX, cardY, hovered);
if (hovered) hoveredAttributeKey = attribute;
@@ -126,7 +136,8 @@ public class StatsScreen extends Screen {
});
}
super.render(graphics, mouseX, mouseY, partialTicks);
super.render(graphics, uiMouseX, uiMouseY, partialTicks);
graphics.pose().popPose();
if (hoveredAttributeKey != null) {
graphics.renderTooltip(font, ATTRIBUTE_TOOLTIPS.get(hoveredAttributeKey), mouseX, mouseY);
}
@@ -134,20 +145,20 @@ public class StatsScreen extends Screen {
private void drawWindow(GuiGraphics graphics) {
RenderSystem.enableBlend();
graphics.fill(leftPos - 6, topPos - 6, leftPos + WIDTH + 6, topPos + HEIGHT + 6, 0xCC090A0C);
graphics.fill(leftPos - 3, topPos - 3, leftPos + WIDTH + 3, topPos + HEIGHT + 3, BORDER);
graphics.fill(leftPos, topPos, leftPos + WIDTH, topPos + HEIGHT, BACKGROUND);
graphics.fill(leftPos, topPos, leftPos + WIDTH, topPos + 20, PANEL);
graphics.fill(leftPos, topPos + 20, leftPos + WIDTH, topPos + 21, BORDER);
graphics.fill(-6, -6, WIDTH + 6, HEIGHT + 6, 0xCC090A0C);
graphics.fill(-3, -3, WIDTH + 3, HEIGHT + 3, BORDER);
graphics.fill(0, 0, WIDTH, HEIGHT, BACKGROUND);
graphics.fill(0, 0, WIDTH, 20, PANEL);
graphics.fill(0, 20, WIDTH, 21, BORDER);
RenderSystem.disableBlend();
graphics.drawCenteredString(font, title, leftPos + WIDTH / 2, topPos + 6, PRIMARY_TEXT);
graphics.drawCenteredString(font, title, WIDTH / 2, 6, PRIMARY_TEXT);
}
private void drawProgression(GuiGraphics graphics, int level, int maxLevel, int xp, int xpNext,
int knowledge, int unspent) {
int panelX = leftPos + PADDING;
int panelY = topPos + 26;
int panelX = PADDING;
int panelY = 26;
int panelWidth = WIDTH - PADDING * 2;
graphics.fill(panelX, panelY, panelX + panelWidth, panelY + 45, PANEL);
@@ -203,4 +214,27 @@ public class StatsScreen extends Screen {
public boolean isPauseScreen() {
return false;
}
private double toUiX(double mouseX) {
return (mouseX - uiLeft) / uiScale;
}
private double toUiY(double mouseY) {
return (mouseY - uiTop) / uiScale;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
return super.mouseClicked(toUiX(mouseX), toUiY(mouseY), button);
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
return super.mouseReleased(toUiX(mouseX), toUiY(mouseY), button);
}
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) {
return super.mouseDragged(toUiX(mouseX), toUiY(mouseY), button, dragX / uiScale, dragY / uiScale);
}
}