diff --git a/src/client/java/aztech/modern_industrialization/pipes/fluid/FluidPipeScreen.java b/src/client/java/aztech/modern_industrialization/pipes/fluid/FluidPipeScreen.java index b4b96c80a..915a9e34a 100644 --- a/src/client/java/aztech/modern_industrialization/pipes/fluid/FluidPipeScreen.java +++ b/src/client/java/aztech/modern_industrialization/pipes/fluid/FluidPipeScreen.java @@ -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 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 diff --git a/src/client/java/aztech/modern_industrialization/pipes/gui/PipeScreen.java b/src/client/java/aztech/modern_industrialization/pipes/gui/PipeScreen.java index a7d03d671..c6f00d529 100644 --- a/src/client/java/aztech/modern_industrialization/pipes/gui/PipeScreen.java +++ b/src/client/java/aztech/modern_industrialization/pipes/gui/PipeScreen.java @@ -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; @@ -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> tooltip = () -> { - List 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> 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> priorityTooltip) { + int channel, Supplier> 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) { diff --git a/src/client/java/aztech/modern_industrialization/pipes/gui/PriorityButton.java b/src/client/java/aztech/modern_industrialization/pipes/gui/PriorityButton.java index 2b5f9f61e..23c616aff 100644 --- a/src/client/java/aztech/modern_industrialization/pipes/gui/PriorityButton.java +++ b/src/client/java/aztech/modern_industrialization/pipes/gui/PriorityButton.java @@ -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; @@ -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> tooltipSupplier) { + public PriorityButton(int x, int y, int width, int u, String message, OnPress onPress, Supplier> 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; diff --git a/src/client/java/aztech/modern_industrialization/pipes/gui/PriorityDisplay.java b/src/client/java/aztech/modern_industrialization/pipes/gui/PriorityDisplay.java index 05a5f4b24..1f86e6df5 100644 --- a/src/client/java/aztech/modern_industrialization/pipes/gui/PriorityDisplay.java +++ b/src/client/java/aztech/modern_industrialization/pipes/gui/PriorityDisplay.java @@ -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; @@ -36,14 +37,17 @@ class PriorityDisplay extends AbstractWidget { private final Supplier priorityGetter; private final Font textRenderer; + private final BooleanSupplier isEnabled; public PriorityDisplay(int x, int y, int width, int height, Component message, Supplier> tooltipSupplier, Supplier 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; } @@ -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); } } diff --git a/src/client/java/aztech/modern_industrialization/pipes/item/ItemPipeScreen.java b/src/client/java/aztech/modern_industrialization/pipes/item/ItemPipeScreen.java index f5bd5a5cb..3fcc2ec24 100644 --- a/src/client/java/aztech/modern_industrialization/pipes/item/ItemPipeScreen.java +++ b/src/client/java/aztech/modern_industrialization/pipes/item/ItemPipeScreen.java @@ -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> makePriorityWidgetTooltip(int channel, boolean insert) { + return () -> { + List 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; + }; } /** diff --git a/src/generated/resources/assets/modern_industrialization/lang/en_us.json b/src/generated/resources/assets/modern_industrialization/lang/en_us.json index a0d3dfd9c..4cca5302a 100644 --- a/src/generated/resources/assets/modern_industrialization/lang/en_us.json +++ b/src/generated/resources/assets/modern_industrialization/lang/en_us.json @@ -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", diff --git a/src/main/java/aztech/modern_industrialization/MIText.java b/src/main/java/aztech/modern_industrialization/MIText.java index aba14c5a3..d9624b9b4 100644 --- a/src/main/java/aztech/modern_industrialization/MIText.java +++ b/src/main/java/aztech/modern_industrialization/MIText.java @@ -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"), diff --git a/src/main/java/aztech/modern_industrialization/MITooltips.java b/src/main/java/aztech/modern_industrialization/MITooltips.java index 2050638d4..d2f91c18d 100644 --- a/src/main/java/aztech/modern_industrialization/MITooltips.java +++ b/src/main/java/aztech/modern_industrialization/MITooltips.java @@ -68,7 +68,8 @@ public class MITooltips { public static final PriorityQueue 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, Style> DEFAULT_ARGUMENT_STYLE = new HashMap<>();