Skip to content

Commit

Permalink
Make item pipe priorities clearer (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Sep 13, 2024
1 parent e3cd152 commit 3f61a81
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ protected void init() {

addNetworkFluidButton();
addConnectionTypeButton(148, 22, menu.iface);
addPriorityWidgets(33, 42, menu.iface, "transfer", 0);
addPriorityWidgets(33, 42, menu.iface, 0, () -> {
List<Component> lines = new ArrayList<>();

MIText priorityText = MIText.PriorityTransfer;
lines.add(priorityText.text(menu.iface.getPriority(0)));

MIText priorityTextHelp = MIText.PriorityTransferHelp;
lines.add(priorityTextHelp.text().setStyle(TextHelper.GRAY_TEXT));

return lines;
}, () -> true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -66,44 +67,24 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
renderTooltip(guiGraphics, mouseX, mouseY);
}

protected void addPriorityWidgets(int startX, int startY, PriorityInterface priority, String tooltipType, int channel) {
Supplier<List<Component>> tooltip = () -> {
List<Component> lines = new ArrayList<>();

MIText priorityText = switch (tooltipType) {
case "transfer" -> MIText.PriorityTransfer;
case "insert" -> MIText.PriorityInsert;
case "extract" -> MIText.PriorityExtract;
default -> throw new IllegalArgumentException("tooltipType : " + tooltipType + " must be either transfer, insert or extract");
};

MIText priorityTextHelp = switch (tooltipType) {
case "transfer" -> MIText.PriorityTransferHelp;
case "insert" -> MIText.PriorityInsertHelp;
case "extract" -> MIText.PriorityExtractHelp;
default -> throw new IllegalArgumentException("tooltipTypeHelp : " + tooltipType + " must be either transfer, insert or extract");
};

lines.add(priorityText.text(priority.getPriority(channel)));
lines.add(priorityTextHelp.text().setStyle(TextHelper.GRAY_TEXT));
return lines;
};
addPriorityButton(startX, startY, 20, 12, "--", -10, priority, channel, tooltip);
addPriorityButton(startX + 22, startY, 12, 0, "-", -1, priority, channel, tooltip);
addPriorityButton(startX + 62, startY, 12, 0, "+", +1, priority, channel, tooltip);
addPriorityButton(startX + 76, startY, 20, 12, "++", +10, priority, channel, tooltip);
protected void addPriorityWidgets(int startX, int startY, PriorityInterface priority, int channel, Supplier<List<Component>> tooltip,
BooleanSupplier isEnabled) {
addPriorityButton(startX, startY, 20, 12, "--", -10, priority, channel, tooltip, isEnabled);
addPriorityButton(startX + 22, startY, 12, 0, "-", -1, priority, channel, tooltip, isEnabled);
addPriorityButton(startX + 62, startY, 12, 0, "+", +1, priority, channel, tooltip, isEnabled);
addPriorityButton(startX + 76, startY, 20, 12, "++", +10, priority, channel, tooltip, isEnabled);
addRenderableWidget(
new PriorityDisplay(startX + 34 + this.leftPos, startY + this.topPos, 28, 12, Component.literal(""), tooltip,
() -> priority.getPriority(channel),
font));
font, isEnabled));
}

private void addPriorityButton(int x, int y, int width, int u, String text, int delta, PriorityInterface priority,
int channel, Supplier<List<Component>> priorityTooltip) {
int channel, Supplier<List<Component>> priorityTooltip, BooleanSupplier isEnabled) {
addRenderableWidget(new PriorityButton(x + this.leftPos, y + this.topPos, width, u, text, button -> {
priority.incrementPriority(channel, delta);
new IncrementPriorityPacket(menu.containerId, channel, delta).sendToServer();
}, priorityTooltip));
}, priorityTooltip, isEnabled));
}

protected int connectionTypeForward(ConnectionTypeInterface connectionType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import aztech.modern_industrialization.client.DynamicTooltip;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
Expand All @@ -36,15 +37,20 @@

class PriorityButton extends Button {
private final int u;
private final BooleanSupplier isEnabled;

public PriorityButton(int x, int y, int width, int u, String message, OnPress onPress, Supplier<List<Component>> tooltipSupplier) {
public PriorityButton(int x, int y, int width, int u, String message, OnPress onPress, Supplier<List<Component>> tooltipSupplier,
BooleanSupplier isEnabled) {
super(x, y, width, 12, Component.literal(message), onPress, Button.DEFAULT_NARRATION);
this.u = u;
this.isEnabled = isEnabled;
setTooltip(new DynamicTooltip(tooltipSupplier));
}

@Override
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
this.active = this.isEnabled.getAsBoolean();

Minecraft minecraftClient = Minecraft.getInstance();
Font font = minecraftClient.font;
int v = this.isHoveredOrFocused() ? 40 + this.height : 40;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import aztech.modern_industrialization.client.DynamicTooltip;
import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -36,14 +37,17 @@
class PriorityDisplay extends AbstractWidget {
private final Supplier<Integer> priorityGetter;
private final Font textRenderer;
private final BooleanSupplier isEnabled;

public PriorityDisplay(int x, int y, int width, int height, Component message, Supplier<List<Component>> tooltipSupplier,
Supplier<Integer> priorityGetter,
Font textRenderer) {
Font textRenderer,
BooleanSupplier isEnabled) {
super(x, y, width, height, message);
setTooltip(new DynamicTooltip(tooltipSupplier));
this.priorityGetter = priorityGetter;
this.textRenderer = textRenderer;
this.isEnabled = isEnabled;
this.active = false;
}

Expand All @@ -60,6 +64,6 @@ protected void updateWidgetNarration(NarrationElementOutput narrationElementOutp
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
FormattedCharSequence orderedText = getMessage().getVisualOrderText();
guiGraphics.drawString(textRenderer, orderedText, this.getX() + this.width / 2 - textRenderer.width(orderedText) / 2,
this.getY() + (this.height - 8) / 2, 4210752, false);
this.getY() + (this.height - 8) / 2, isEnabled.getAsBoolean() ? 0x404040 : 0x707070, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,37 @@ protected void init() {
return lines;
}));
addConnectionTypeButton(148, 22, menu.pipeInterface);
addPriorityWidgets(35, 72, menu.pipeInterface, "insert", 0);
addPriorityWidgets(35, 86, menu.pipeInterface, "extract", 1);

addPriorityWidgets(35, 72, menu.pipeInterface, 0, makePriorityWidgetTooltip(0, true), () -> menu.pipeInterface.getConnectionType() != 2);
addPriorityWidgets(35, 86, menu.pipeInterface, 1, makePriorityWidgetTooltip(1, false), () -> menu.pipeInterface.getConnectionType() != 0);
}

private Supplier<List<Component>> makePriorityWidgetTooltip(int channel, boolean insert) {
return () -> {
List<Component> lines = new ArrayList<>();

MIText priorityText = insert ? MIText.PriorityInsert : MIText.PriorityExtract;
lines.add(priorityText.text(menu.pipeInterface.getPriority(channel)));

if (insert && menu.pipeInterface.getConnectionType() == 2) {
lines.add(MIText.PriorityNotApplicable.text(
MIText.PipeConnectionTooltipExtractOnly.text().setStyle(MITooltips.HIGHLIGHT_STYLE),
MIText.PipeConnectionOut.text().setStyle(MITooltips.HIGHLIGHT_STYLE))
.setStyle(TextHelper.GRAY_TEXT));
} else if (!insert && menu.pipeInterface.getConnectionType() == 0) {
lines.add(MIText.PriorityNotApplicable.text(
MIText.PipeConnectionTooltipInsertOnly.text().setStyle(MITooltips.HIGHLIGHT_STYLE),
MIText.PipeConnectionIn.text().setStyle(MITooltips.HIGHLIGHT_STYLE))
.setStyle(TextHelper.GRAY_TEXT));
} else {
lines.add(MIText.PriorityItemHelp.text(
MIText.PipeConnectionOut.text().setStyle(MITooltips.HIGHLIGHT_STYLE),
MIText.PipeConnectionIn.text().setStyle(MITooltips.HIGHLIGHT_STYLE))
.setStyle(TextHelper.GRAY_TEXT));
}

return lines;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1652,9 +1652,9 @@
"text.modern_industrialization.PipeHelp1": "Can be instantly retrieved by pressing %s with any Wrench.",
"text.modern_industrialization.PipeHelp2": "Use %s + %s to connect directly the pipe to the target block.",
"text.modern_industrialization.PriorityExtract": "Extract priority: %d",
"text.modern_industrialization.PriorityExtractHelp": "Lower priorities first, only into higher priorities.",
"text.modern_industrialization.PriorityInsert": "Insert priority: %d",
"text.modern_industrialization.PriorityInsertHelp": "Higher priorities first.",
"text.modern_industrialization.PriorityItemHelp": "Items only move from lower extract (%s) priorities to equal or higher insert (%s) priorities. Greater differences take precedence.",
"text.modern_industrialization.PriorityNotApplicable": "Not applicable in %s mode (%s).",
"text.modern_industrialization.PriorityTransfer": "Transfer priority: %d",
"text.modern_industrialization.PriorityTransferHelp": "Pipes will interact with higher priorities first.",
"text.modern_industrialization.Progress": "Progress: %s",
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/aztech/modern_industrialization/MIText.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ public enum MIText {
PipeHelp1("Can be instantly retrieved by pressing %s with any Wrench."),
PipeHelp2("Use %s + %s to connect directly the pipe to the target block."),
PriorityExtract("Extract priority: %d"),
PriorityExtractHelp("Lower priorities first, only into higher priorities."),
PriorityInsert("Insert priority: %d"),
PriorityInsertHelp("Higher priorities first."),
PriorityItemHelp(
"Items only move from lower extract (%s) priorities to equal or higher insert (%s) priorities. Greater differences take precedence."),
PriorityNotApplicable("Not applicable in %s mode (%s)."),
PriorityTransfer("Transfer priority: %d"),
PriorityTransferHelp("Pipes will interact with higher priorities first."),
Progress("Progress: %s"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public class MITooltips {
public static final PriorityQueue<TooltipAttachment> TOOLTIPS = new PriorityQueue<>();

public static final Style DEFAULT_STYLE = Style.EMPTY.withColor(TextColor.fromRgb(0xa9a9a9)).withItalic(false);
public static final Style NUMBER_TEXT = Style.EMPTY.withColor(TextColor.fromRgb(0xffde7d)).withItalic(false);
public static final Style HIGHLIGHT_STYLE = Style.EMPTY.withColor(TextColor.fromRgb(0xffde7d)).withItalic(false);
public static final Style NUMBER_TEXT = HIGHLIGHT_STYLE;

private static final Map<Class<?>, Style> DEFAULT_ARGUMENT_STYLE = new HashMap<>();

Expand Down

0 comments on commit 3f61a81

Please sign in to comment.