From b0434aa542a0e32f02e07b69ef1eff76cabea2bc Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Tue, 12 Mar 2024 00:55:44 +0100 Subject: [PATCH] Highlight devices missing a channel on the network status screen --- .../java/appeng/client/gui/AEBaseScreen.java | 8 +++++- .../me/networktool/NetworkStatusScreen.java | 12 +++++++- .../menu/me/networktool/MachineGroup.java | 22 ++++++++++----- .../menu/me/networktool/MachineGroupKey.java | 28 +++++++++++++++++++ .../menu/me/networktool/NetworkStatus.java | 20 +++++++++---- 5 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 src/main/java/appeng/menu/me/networktool/MachineGroupKey.java diff --git a/src/main/java/appeng/client/gui/AEBaseScreen.java b/src/main/java/appeng/client/gui/AEBaseScreen.java index 917d727e9cd..cdd2298c0b8 100644 --- a/src/main/java/appeng/client/gui/AEBaseScreen.java +++ b/src/main/java/appeng/client/gui/AEBaseScreen.java @@ -393,7 +393,13 @@ public void drawTooltipWithHeader(GuiGraphics guiGraphics, int x, int y, List s.withColor(ChatFormatting.WHITE))); } else { - formattedLines.add(lines.get(i)); + formattedLines.add(lines.get(i).copy().withStyle(s -> { + if (s.getColor() != null) { + return s; + } else { + return s.withColor(ChatFormatting.GRAY); + } + })); } } drawTooltip(guiGraphics, x, y, formattedLines); diff --git a/src/main/java/appeng/client/gui/me/networktool/NetworkStatusScreen.java b/src/main/java/appeng/client/gui/me/networktool/NetworkStatusScreen.java index b7be5c76d73..6adedfe8c4f 100644 --- a/src/main/java/appeng/client/gui/me/networktool/NetworkStatusScreen.java +++ b/src/main/java/appeng/client/gui/me/networktool/NetworkStatusScreen.java @@ -87,7 +87,10 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX final int viewEnd = viewStart + COLUMNS * ROWS; List tooltip = null; - List machines = status.getGroupedMachines(); + List machines = new ArrayList<>(status.getGroupedMachines()); + // Sort anything with a classifier to the front + machines.sort(MachineGroup.COMPARATOR); + for (int i = viewStart; i < Math.min(viewEnd, machines.size()); i++) { MachineGroup entry = machines.get(i); @@ -98,6 +101,10 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX int itemX = cellX + CELL_WIDTH - 17; int itemY = cellY + 1; + if (entry.isMissingChannel()) { + guiGraphics.fill(cellX, cellY, cellX + CELL_WIDTH, cellY + CELL_HEIGHT, 0xffff5555); + } + drawMachineCount(guiGraphics, itemX, cellY, entry.getCount()); AEKeyRendering.drawInGui(Minecraft.getInstance(), guiGraphics, itemX, itemY, entry.getDisplay()); @@ -106,6 +113,9 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX if (isHovering(cellX, cellY, CELL_WIDTH, CELL_HEIGHT, mouseX, mouseY)) { tooltip = new ArrayList<>(); tooltip.add(entry.getDisplay().getDisplayName()); + if (entry.isMissingChannel()) { + tooltip.add(GuiText.NoChannel.text().withStyle(ChatFormatting.RED)); + } tooltip.add(GuiText.Installed.text(entry.getCount())); if (entry.getIdlePowerUsage() > 0) { diff --git a/src/main/java/appeng/menu/me/networktool/MachineGroup.java b/src/main/java/appeng/menu/me/networktool/MachineGroup.java index 06d5c9beb26..61fa5ec8cd7 100644 --- a/src/main/java/appeng/menu/me/networktool/MachineGroup.java +++ b/src/main/java/appeng/menu/me/networktool/MachineGroup.java @@ -23,15 +23,19 @@ import appeng.api.stacks.AEItemKey; /** - * Represents the status of machines grouped by their {@link IGridBlock#getMachineRepresentation() item representation}. + * Represents the status of machines grouped by their {@linkplain IGridNode#getVisualRepresentation() item representation}. */ public class MachineGroup { + public static final Comparator COMPARATOR = Comparator.comparing(MachineGroup::isMissingChannel) + .thenComparingInt(MachineGroup::getCount) + .reversed(); + /** - * The item stack used for grouping machines together, which is also used for showing the group in the UI. + * The key used for grouping machines together, which is also used for showing the group in the UI. * - * @see IGridBlock#getMachineRepresentation() + * @see IGridNode#getVisualRepresentation() */ - private final AEItemKey display; + private final MachineGroupKey key; /** * Summed up idle power usage of this machine group in AE/t. @@ -51,20 +55,24 @@ public class MachineGroup { * Reads back a machine group previously {@link #write(FriendlyByteBuf) written}. */ static MachineGroup read(FriendlyByteBuf data) { - MachineGroup entry = new MachineGroup(AEItemKey.fromPacket(data)); + MachineGroup entry = new MachineGroup(MachineGroupKey.fromPacket(data)); entry.idlePowerUsage = data.readDouble(); entry.count = data.readVarInt(); return entry; } void write(FriendlyByteBuf data) { - display.writeToPacket(data); + key.write(data); data.writeDouble(idlePowerUsage); data.writeVarInt(count); } public AEItemKey getDisplay() { - return display; + return key.display(); + } + + public boolean isMissingChannel() { + return key.missingChannel(); } public double getIdlePowerUsage() { diff --git a/src/main/java/appeng/menu/me/networktool/MachineGroupKey.java b/src/main/java/appeng/menu/me/networktool/MachineGroupKey.java new file mode 100644 index 00000000000..b40a45aeb14 --- /dev/null +++ b/src/main/java/appeng/menu/me/networktool/MachineGroupKey.java @@ -0,0 +1,28 @@ +package appeng.menu.me.networktool; + + +import appeng.api.stacks.AEItemKey; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +/** + * The information by which machines are grouped together. + */ +record MachineGroupKey(AEItemKey display, boolean missingChannel) { + + public static MachineGroupKey fromPacket(FriendlyByteBuf data) { + var display = AEItemKey.fromPacket(data); + var missingChannel = data.readBoolean(); + return new MachineGroupKey(display, missingChannel); + + } + + public void write(FriendlyByteBuf data) { + display.writeToPacket(data); + data.writeBoolean(missingChannel); + } + +} diff --git a/src/main/java/appeng/menu/me/networktool/NetworkStatus.java b/src/main/java/appeng/menu/me/networktool/NetworkStatus.java index 00d2b3e5c8e..da71dbea0b7 100644 --- a/src/main/java/appeng/menu/me/networktool/NetworkStatus.java +++ b/src/main/java/appeng/menu/me/networktool/NetworkStatus.java @@ -62,14 +62,14 @@ public static NetworkStatus fromGrid(IGrid grid) { status.channelsUsed = grid.getPathingService().getUsedChannels(); // This is essentially a groupBy machineRepresentation + count, sum(idlePowerUsage) - Map groupedMachines = new HashMap<>(); + Map groupedMachines = new HashMap<>(); for (var machineClass : grid.getMachineClasses()) { for (IGridNode machine : grid.getMachineNodes(machineClass)) { - var ais = machine.getVisualRepresentation(); - if (ais != null) { - MachineGroup group = groupedMachines.get(ais); + var key = getKey(machine); + if (key != null) { + MachineGroup group = groupedMachines.get(key); if (group == null) { - groupedMachines.put(ais, group = new MachineGroup(ais)); + groupedMachines.put(key, group = new MachineGroup(key)); } group.setCount(group.getCount() + 1); @@ -82,6 +82,16 @@ public static NetworkStatus fromGrid(IGrid grid) { return status; } + @Nullable + private static MachineGroupKey getKey(IGridNode machine) { + var visualRepresentation = machine.getVisualRepresentation(); + if (visualRepresentation == null) { + return null; + } + + return new MachineGroupKey(visualRepresentation, !machine.meetsChannelRequirements()); + } + public double getAveragePowerInjection() { return averagePowerInjection; }