Give overlay +/- and Clear the vanilla button look and click.
Build / build (push) Failing after 29s

Same HUD hit-testing, widget/button sprites plus UI_BUTTON_CLICK. Not a Screen rewrite.
This commit is contained in:
Stephen Fasciani
2026-09-08 05:07:58 -04:00
parent 3f3d8bff50
commit 6007d62dfa
@@ -12,9 +12,12 @@ import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
@@ -23,8 +26,14 @@ public final class PlayOverlay {
private static final int WIDTH = 156;
private static final int LINE = 12;
private static final int PAD = 6;
private static final WidgetSprites BUTTON = new WidgetSprites(
ResourceLocation.withDefaultNamespace("widget/button"),
ResourceLocation.withDefaultNamespace("widget/button_disabled"),
ResourceLocation.withDefaultNamespace("widget/button_highlighted"));
private static final List<Hit> HITS = new ArrayList<>();
private static double mouseX;
private static double mouseY;
private PlayOverlay() {}
@@ -41,12 +50,18 @@ public final class PlayOverlay {
}
Font font = minecraft.font;
mouseX = minecraft.mouseHandler.xpos()
* minecraft.getWindow().getGuiScaledWidth()
/ minecraft.getWindow().getScreenWidth();
mouseY = minecraft.mouseHandler.ypos()
* minecraft.getWindow().getGuiScaledHeight()
/ minecraft.getWindow().getScreenHeight();
int x = graphics.guiWidth() - WIDTH - MARGIN;
int y = MARGIN;
int goalLines = snapshot.goals().size();
int missingLines = Math.max(3, snapshot.missing().size());
int header = LINE + 4;
int footer = LINE + 10;
int footer = 22;
int height = PAD + header + goalLines * LINE + 6 + missingLines * LINE + footer + PAD;
graphics.fill(x, y, x + WIDTH, y + height, 0xE0101010);
@@ -79,12 +94,10 @@ public final class PlayOverlay {
}
String clear = "X Clear Items";
int clearWidth = font.width(clear) + 10;
int clearWidth = Math.max(font.width(clear) + 16, 80);
int clearX = x + (WIDTH - clearWidth) / 2;
int clearY = y + height - PAD - LINE;
graphics.fill(clearX, clearY - 2, clearX + clearWidth, clearY + LINE, 0xFF3A3A3A);
graphics.drawCenteredString(font, clear, x + WIDTH / 2, clearY, 0xFFFFFF);
HITS.add(new Hit(clearX, clearY - 2, clearX + clearWidth, clearY + LINE, Kind.CLEAR, null));
int clearY = y + height - PAD - 16;
drawMcButton(graphics, font, clearX, clearY, clearWidth, 16, clear, Kind.CLEAR, null);
}
/**
@@ -106,6 +119,9 @@ public final class PlayOverlay {
case MINUS -> PlannerSession.get().decrement(hit.item);
case CLEAR -> PlannerSession.get().clear();
}
Minecraft.getInstance()
.getSoundManager()
.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
return true;
}
}
@@ -114,9 +130,9 @@ public final class PlayOverlay {
private static void drawGoalRow(GuiGraphics graphics, Font font, Goal goal, int panelX, int y) {
int plusX = panelX + PAD;
int minusX = plusX + 11;
drawButton(graphics, font, plusX, y, "+", Kind.PLUS, goal.targetItem());
drawButton(graphics, font, minusX, y, "-", Kind.MINUS, goal.targetItem());
int minusX = plusX + 12;
drawMcButton(graphics, font, plusX, y, 11, 11, "+", Kind.PLUS, goal.targetItem());
drawMcButton(graphics, font, minusX, y, 11, 11, "-", Kind.MINUS, goal.targetItem());
String name = displayName(goal.targetItem()).toUpperCase();
String qty = Integer.toString(goal.quantity());
@@ -126,11 +142,11 @@ public final class PlayOverlay {
graphics.drawString(font, qty, qtyX, y, 0xFFFFFF, false);
}
private static void drawButton(GuiGraphics graphics, Font font, int x, int y, String label, Kind kind, ItemId item) {
int w = 9;
int h = 9;
graphics.fill(x, y, x + w, y + h, 0xFF4A4A4A);
graphics.drawCenteredString(font, label, x + w / 2, y, 0xFFFFFF);
private static void drawMcButton(
GuiGraphics graphics, Font font, int x, int y, int w, int h, String label, Kind kind, ItemId item) {
boolean hovered = mouseX >= x && mouseX < x + w && mouseY >= y && mouseY < y + h;
graphics.blitSprite(BUTTON.get(true, hovered), x, y, w, h);
graphics.drawCenteredString(font, label, x + w / 2, y + (h - 8) / 2, hovered ? 0xFFFFA0 : 0xFFFFFF);
HITS.add(new Hit(x, y, x + w, y + h, kind, item));
}