Give overlay +/- and Clear the vanilla button look and click.
Build / build (push) Failing after 29s
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:
@@ -12,9 +12,12 @@ import net.minecraft.client.DeltaTracker;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.components.WidgetSprites;
|
||||||
import net.minecraft.client.gui.screens.ChatScreen;
|
import net.minecraft.client.gui.screens.ChatScreen;
|
||||||
|
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
|
|
||||||
@@ -23,8 +26,14 @@ public final class PlayOverlay {
|
|||||||
private static final int WIDTH = 156;
|
private static final int WIDTH = 156;
|
||||||
private static final int LINE = 12;
|
private static final int LINE = 12;
|
||||||
private static final int PAD = 6;
|
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 final List<Hit> HITS = new ArrayList<>();
|
||||||
|
private static double mouseX;
|
||||||
|
private static double mouseY;
|
||||||
|
|
||||||
private PlayOverlay() {}
|
private PlayOverlay() {}
|
||||||
|
|
||||||
@@ -41,12 +50,18 @@ public final class PlayOverlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Font font = minecraft.font;
|
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 x = graphics.guiWidth() - WIDTH - MARGIN;
|
||||||
int y = MARGIN;
|
int y = MARGIN;
|
||||||
int goalLines = snapshot.goals().size();
|
int goalLines = snapshot.goals().size();
|
||||||
int missingLines = Math.max(3, snapshot.missing().size());
|
int missingLines = Math.max(3, snapshot.missing().size());
|
||||||
int header = LINE + 4;
|
int header = LINE + 4;
|
||||||
int footer = LINE + 10;
|
int footer = 22;
|
||||||
int height = PAD + header + goalLines * LINE + 6 + missingLines * LINE + footer + PAD;
|
int height = PAD + header + goalLines * LINE + 6 + missingLines * LINE + footer + PAD;
|
||||||
|
|
||||||
graphics.fill(x, y, x + WIDTH, y + height, 0xE0101010);
|
graphics.fill(x, y, x + WIDTH, y + height, 0xE0101010);
|
||||||
@@ -79,12 +94,10 @@ public final class PlayOverlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String clear = "X Clear Items";
|
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 clearX = x + (WIDTH - clearWidth) / 2;
|
||||||
int clearY = y + height - PAD - LINE;
|
int clearY = y + height - PAD - 16;
|
||||||
graphics.fill(clearX, clearY - 2, clearX + clearWidth, clearY + LINE, 0xFF3A3A3A);
|
drawMcButton(graphics, font, clearX, clearY, clearWidth, 16, clear, Kind.CLEAR, null);
|
||||||
graphics.drawCenteredString(font, clear, x + WIDTH / 2, clearY, 0xFFFFFF);
|
|
||||||
HITS.add(new Hit(clearX, clearY - 2, clearX + clearWidth, clearY + LINE, Kind.CLEAR, null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,6 +119,9 @@ public final class PlayOverlay {
|
|||||||
case MINUS -> PlannerSession.get().decrement(hit.item);
|
case MINUS -> PlannerSession.get().decrement(hit.item);
|
||||||
case CLEAR -> PlannerSession.get().clear();
|
case CLEAR -> PlannerSession.get().clear();
|
||||||
}
|
}
|
||||||
|
Minecraft.getInstance()
|
||||||
|
.getSoundManager()
|
||||||
|
.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,9 +130,9 @@ public final class PlayOverlay {
|
|||||||
|
|
||||||
private static void drawGoalRow(GuiGraphics graphics, Font font, Goal goal, int panelX, int y) {
|
private static void drawGoalRow(GuiGraphics graphics, Font font, Goal goal, int panelX, int y) {
|
||||||
int plusX = panelX + PAD;
|
int plusX = panelX + PAD;
|
||||||
int minusX = plusX + 11;
|
int minusX = plusX + 12;
|
||||||
drawButton(graphics, font, plusX, y, "+", Kind.PLUS, goal.targetItem());
|
drawMcButton(graphics, font, plusX, y, 11, 11, "+", Kind.PLUS, goal.targetItem());
|
||||||
drawButton(graphics, font, minusX, y, "-", Kind.MINUS, goal.targetItem());
|
drawMcButton(graphics, font, minusX, y, 11, 11, "-", Kind.MINUS, goal.targetItem());
|
||||||
|
|
||||||
String name = displayName(goal.targetItem()).toUpperCase();
|
String name = displayName(goal.targetItem()).toUpperCase();
|
||||||
String qty = Integer.toString(goal.quantity());
|
String qty = Integer.toString(goal.quantity());
|
||||||
@@ -126,11 +142,11 @@ public final class PlayOverlay {
|
|||||||
graphics.drawString(font, qty, qtyX, y, 0xFFFFFF, false);
|
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) {
|
private static void drawMcButton(
|
||||||
int w = 9;
|
GuiGraphics graphics, Font font, int x, int y, int w, int h, String label, Kind kind, ItemId item) {
|
||||||
int h = 9;
|
boolean hovered = mouseX >= x && mouseX < x + w && mouseY >= y && mouseY < y + h;
|
||||||
graphics.fill(x, y, x + w, y + h, 0xFF4A4A4A);
|
graphics.blitSprite(BUTTON.get(true, hovered), x, y, w, h);
|
||||||
graphics.drawCenteredString(font, label, x + w / 2, y, 0xFFFFFF);
|
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));
|
HITS.add(new Hit(x, y, x + w, y + h, kind, item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user