Skip to content

Commit

Permalink
Highlight devices missing a channel on the network status screen
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Mar 11, 2024
1 parent 0f1a638 commit 00b9b1d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/main/java/appeng/client/gui/AEBaseScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,13 @@ public void drawTooltipWithHeader(GuiGraphics guiGraphics, int x, int y, List<Co
if (i == 0) {
formattedLines.add(lines.get(i).copy().withStyle(s -> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX
final int viewEnd = viewStart + COLUMNS * ROWS;

List<Component> tooltip = null;
List<MachineGroup> machines = status.getGroupedMachines();
List<MachineGroup> 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);

Expand All @@ -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());
Expand All @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/appeng/menu/me/networktool/MachineGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ static MachineGroup read(FriendlyByteBuf data) {
}

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() {
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/appeng/menu/me/networktool/MachineGroupKey.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
20 changes: 15 additions & 5 deletions src/main/java/appeng/menu/me/networktool/NetworkStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<AEItemKey, MachineGroup> groupedMachines = new HashMap<>();
Map<MachineGroupKey, MachineGroup> 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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 00b9b1d

Please sign in to comment.