From 94e3ed44ad1deaa383c8da61928f67697dc13273 Mon Sep 17 00:00:00 2001 From: caelwarner Date: Wed, 26 Oct 2022 16:57:12 -0700 Subject: [PATCH] Added ComputerScreen - ComputerScreen shows that tile entity currently has computers attached and therefore cannot be controlled manually --- .../resources/assets/create/lang/en_us.json | 5 +- .../compat/computercraft/ComputerScreen.java | 96 +++++++++++++++++ .../sequencer/SequencedGearshiftScreen.java | 98 ++++++++++-------- .../station/AbstractStationScreen.java | 20 +++- .../edgePoint/station/StationScreen.java | 2 + .../create/foundation/gui/AllGuiTextures.java | 7 +- .../assets/create/textures/gui/computer.png | Bin 0 -> 1016 bytes 7 files changed, 178 insertions(+), 50 deletions(-) create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/ComputerScreen.java create mode 100644 src/main/resources/assets/create/textures/gui/computer.png diff --git a/src/generated/resources/assets/create/lang/en_us.json b/src/generated/resources/assets/create/lang/en_us.json index f29227a7a..f76d0b162 100644 --- a/src/generated/resources/assets/create/lang/en_us.json +++ b/src/generated/resources/assets/create/lang/en_us.json @@ -1748,6 +1748,9 @@ "create.contraption.minecart_contraption_too_big": "This Cart Contraption seems too big to pick up", "create.contraption.minecart_contraption_illegal_pickup": "A mystical force is binding this Cart Contraption to the world", + "create.gui.attached_computer.controlled": "This device is being controlled by a computer", + "create.gui.attached_computer.hint": "To use device manually, disconnect all computers and modems", + "_": "->------------------------] Subtitles [------------------------<-", @@ -3027,4 +3030,4 @@ "_": "Thank you for translating Create!" -} \ No newline at end of file +} diff --git a/src/main/java/com/simibubi/create/compat/computercraft/ComputerScreen.java b/src/main/java/com/simibubi/create/compat/computercraft/ComputerScreen.java new file mode 100644 index 000000000..2d55a2554 --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/ComputerScreen.java @@ -0,0 +1,96 @@ +package com.simibubi.create.compat.computercraft; + +import java.util.function.Supplier; + +import javax.annotation.Nullable; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.simibubi.create.compat.Mods; +import com.simibubi.create.foundation.gui.AbstractSimiScreen; +import com.simibubi.create.foundation.gui.AllGuiTextures; +import com.simibubi.create.foundation.gui.AllIcons; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.AbstractSimiWidget; +import com.simibubi.create.foundation.gui.widget.ElementWidget; +import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.utility.Lang; + +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; + +public class ComputerScreen extends AbstractSimiScreen { + + private final AllGuiTextures background = AllGuiTextures.COMPUTER; + + private final Supplier displayTitle; + private final RenderWindowFunction additional; + private final Screen previousScreen; + private final Supplier hasAttachedComputer; + + private AbstractSimiWidget computerWidget; + private IconButton confirmButton; + + public ComputerScreen(Component title, @Nullable RenderWindowFunction additional, Screen previousScreen, Supplier hasAttachedComputer) { + this(title, () -> title, additional, previousScreen, hasAttachedComputer); + } + + public ComputerScreen(Component title, Supplier displayTitle, @Nullable RenderWindowFunction additional, Screen previousScreen, Supplier hasAttachedComputer) { + super(title); + this.displayTitle = displayTitle; + this.additional = additional; + this.previousScreen = previousScreen; + this.hasAttachedComputer = hasAttachedComputer; + } + + @Override + public void tick() { + if (!hasAttachedComputer.get()) + minecraft.setScreen(previousScreen); + + super.tick(); + } + + @Override + protected void init() { + setWindowSize(background.width, background.height); + super.init(); + + int x = guiLeft; + int y = guiTop; + + Mods.COMPUTERCRAFT.executeIfInstalled(() -> () -> { + computerWidget = new ElementWidget(x + 33, y + 38) + .showingElement(GuiGameElement.of(Mods.COMPUTERCRAFT.getBlock("computer_advanced"))); + computerWidget.getToolTip().add(Lang.translate("gui.attached_computer.hint").component()); + addRenderableWidget(computerWidget); + }); + + confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); + confirmButton.withCallback(this::onClose); + addRenderableWidget(confirmButton); + } + + + + @Override + protected void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks) { + int x = guiLeft; + int y = guiTop; + + background.render(ms, x, y, this); + + font.draw(ms, displayTitle.get(), x + background.width / 2.0F - font.width(displayTitle.get()) / 2.0F, y + 4, 0x442000); + font.drawWordWrap(Lang.translate("gui.attached_computer.controlled").component(), x + 55, y + 32, 111, 0x7A7A7A); + + if (additional != null) + additional.render(ms, mouseX, mouseY, partialTicks, x, y, background); + } + + @FunctionalInterface + public interface RenderWindowFunction { + + void render(PoseStack ms, int mouseX, int mouseY, float partialTicks, int guiLeft, int guiTop, AllGuiTextures background); + + } + +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java index f4d7e1923..1cf8e7259 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java @@ -4,6 +4,7 @@ import java.util.Vector; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; +import com.simibubi.create.compat.computercraft.ComputerScreen; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; @@ -15,7 +16,6 @@ import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Lang; -import net.minecraft.core.BlockPos; import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; @@ -25,24 +25,26 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { private final ItemStack renderedItem = AllBlocks.SEQUENCED_GEARSHIFT.asStack(); private final AllGuiTextures background = AllGuiTextures.SEQUENCER; private IconButton confirmButton; + private SequencedGearshiftTileEntity te; private ListTag compareTag; private Vector instructions; - private BlockPos pos; - private final boolean hasAttachedComputer; private Vector> inputs; public SequencedGearshiftScreen(SequencedGearshiftTileEntity te) { super(Lang.translateDirect("gui.sequenced_gearshift.title")); this.instructions = te.instructions; - this.pos = te.getBlockPos(); - this.hasAttachedComputer = te.computerBehaviour.hasAttachedComputer(); + this.te = te; compareTag = Instruction.serializeAll(instructions); } @Override protected void init() { + if (te.computerBehaviour.hasAttachedComputer()) + minecraft.setScreen(new ComputerScreen(title, this::renderAdditional, + this, te.computerBehaviour::hasAttachedComputer)); + setWindowSize(background.width, background.height); setWindowOffset(-20, 0); super.init(); @@ -51,13 +53,11 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { int y = guiTop; inputs = new Vector<>(5); - if (!hasAttachedComputer) { - for (int row = 0; row < inputs.capacity(); row++) - inputs.add(new Vector<>(3)); + for (int row = 0; row < inputs.capacity(); row++) + inputs.add(new Vector<>(3)); - for (int row = 0; row < instructions.size(); row++) - initInputsOfRow(row, x, y); - } + for (int row = 0; row < instructions.size(); row++) + initInputsOfRow(row, x, y); confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); @@ -131,6 +131,15 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { modifier.setState(instruction.speedModifier.ordinal()); } + @Override + public void tick() { + super.tick(); + + if (te.computerBehaviour.hasAttachedComputer()) + minecraft.setScreen(new ComputerScreen(title, this::renderAdditional, + this, te.computerBehaviour::hasAttachedComputer)); + } + @Override protected void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks) { int x = guiLeft; @@ -138,42 +147,42 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { background.render(ms, x, y, this); - if (hasAttachedComputer) { - for (int row = 0; row < instructions.capacity(); row++) { - AllGuiTextures toDraw = AllGuiTextures.SEQUENCER_EMPTY; - int yOffset = toDraw.height * row; + for (int row = 0; row < instructions.capacity(); row++) { + AllGuiTextures toDraw = AllGuiTextures.SEQUENCER_EMPTY; + int yOffset = toDraw.height * row; - toDraw.render(ms, x, y + 14 + yOffset, this); - } - - } else { - for (int row = 0; row < instructions.capacity(); row++) { - AllGuiTextures toDraw = AllGuiTextures.SEQUENCER_EMPTY; - int yOffset = toDraw.height * row; - if (row >= instructions.size()) { - toDraw.render(ms, x, y + 14 + yOffset, this); - continue; - } - - Instruction instruction = instructions.get(row); - SequencerInstructions def = instruction.instruction; - def.background.render(ms, x, y + 14 + yOffset, this); - - label(ms, 36, yOffset - 3, Lang.translateDirect(def.translationKey)); - if (def.hasValueParameter) { - String text = def.formatValue(instruction.value); - int stringWidth = font.width(text); - label(ms, 90 + (12 - stringWidth / 2), yOffset - 3, Components.literal(text)); - } - if (def.hasSpeedParameter) - label(ms, 127, yOffset - 3, instruction.speedModifier.label); - } + toDraw.render(ms, x, y + 14 + yOffset, this); } - drawCenteredString(ms, font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); + for (int row = 0; row < instructions.capacity(); row++) { + AllGuiTextures toDraw = AllGuiTextures.SEQUENCER_EMPTY; + int yOffset = toDraw.height * row; + if (row >= instructions.size()) { + toDraw.render(ms, x, y + 14 + yOffset, this); + continue; + } + Instruction instruction = instructions.get(row); + SequencerInstructions def = instruction.instruction; + def.background.render(ms, x, y + 14 + yOffset, this); + + label(ms, 36, yOffset - 3, Lang.translateDirect(def.translationKey)); + if (def.hasValueParameter) { + String text = def.formatValue(instruction.value); + int stringWidth = font.width(text); + label(ms, 90 + (12 - stringWidth / 2), yOffset - 3, Components.literal(text)); + } + if (def.hasSpeedParameter) + label(ms, 127, yOffset - 3, instruction.speedModifier.label); + } + + renderAdditional(ms, mouseX, mouseY, partialTicks, x, y, background); + drawCenteredString(ms, font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); + } + + private void renderAdditional(PoseStack ms, int mouseX, int mouseY, float partialTicks, int guiLeft, int guiTop, AllGuiTextures background) { GuiGameElement.of(renderedItem) - .at(x + background.width + 6, y + background.height - 56, -200) + .at(guiLeft + background.width + 6, guiTop + background.height - 56, 100) .scale(5) .render(ms); } @@ -183,13 +192,10 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { } public void sendPacket() { - if (hasAttachedComputer) - return; - ListTag serialized = Instruction.serializeAll(instructions); if (serialized.equals(compareTag)) return; - AllPackets.channel.sendToServer(new ConfigureSequencedGearshiftPacket(pos, serialized)); + AllPackets.channel.sendToServer(new ConfigureSequencedGearshiftPacket(te.getBlockPos(), serialized)); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/AbstractStationScreen.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/AbstractStationScreen.java index ed32075ae..a1d5ea049 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/AbstractStationScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/AbstractStationScreen.java @@ -7,6 +7,7 @@ import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.CreateClient; +import com.simibubi.create.compat.computercraft.ComputerScreen; import com.simibubi.create.content.logistics.trains.entity.Carriage; import com.simibubi.create.content.logistics.trains.entity.Train; import com.simibubi.create.content.logistics.trains.entity.TrainIconType; @@ -15,6 +16,7 @@ import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.utility.Components; import net.minecraft.world.level.block.state.properties.BlockStateProperties; @@ -39,6 +41,10 @@ public abstract class AbstractStationScreen extends AbstractSimiScreen { @Override protected void init() { + if (te.computerBehaviour.hasAttachedComputer()) + minecraft.setScreen(new ComputerScreen(title, () -> Components.literal(station.name), + this::renderAdditional, this, te.computerBehaviour::hasAttachedComputer)); + setWindowSize(background.width, background.height); super.init(); clearWidgets(); @@ -71,17 +77,29 @@ public abstract class AbstractStationScreen extends AbstractSimiScreen { return w; } + @Override + public void tick() { + super.tick(); + + if (te.computerBehaviour.hasAttachedComputer()) + minecraft.setScreen(new ComputerScreen(title, () -> Components.literal(station.name), + this::renderAdditional, this, te.computerBehaviour::hasAttachedComputer)); + } + @Override protected void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks) { int x = guiLeft; int y = guiTop; background.render(ms, x, y, this); + renderAdditional(ms, mouseX, mouseY, partialTicks, x, y, background); + } + private void renderAdditional(PoseStack ms, int mouseX, int mouseY, float partialTicks, int guiLeft, int guiTop, AllGuiTextures background) { ms.pushPose(); TransformStack msr = TransformStack.cast(ms); msr.pushPose() - .translate(x + background.width + 4, y + background.height + 4, 100) + .translate(guiLeft + background.width + 4, guiTop + background.height + 4, 100) .scale(40) .rotateX(-22) .rotateY(63); diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationScreen.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationScreen.java index d646c1d24..64de0a12f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationScreen.java @@ -343,6 +343,8 @@ public class StationScreen extends AbstractStationScreen { @Override public void removed() { super.removed(); + if (nameBox == null || trainNameBox == null) + return; AllPackets.channel .sendToServer(StationEditPacket.configure(te.getBlockPos(), switchingToAssemblyMode, nameBox.getValue())); Train train = displayedTrain.get(); diff --git a/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java b/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java index 53f9571e8..71946bbe2 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java @@ -163,7 +163,7 @@ public enum AllGuiTextures implements ScreenElement { SPEECH_TOOLTIP_BACKGROUND("widgets", 0, 24, 8, 8), SPEECH_TOOLTIP_COLOR("widgets", 8, 24, 8, 8), - + TRAIN_HUD_SPEED_BG("widgets", 0, 190, 182, 5), TRAIN_HUD_SPEED("widgets", 0, 185, 182, 5), TRAIN_HUD_THROTTLE("widgets", 0, 195, 182, 5), @@ -175,7 +175,10 @@ public enum AllGuiTextures implements ScreenElement { TRAIN_PROMPT("widgets", 0, 230, 256, 16), // PlacementIndicator - PLACEMENT_INDICATOR_SHEET("placement_indicator", 0, 0, 16, 256); + PLACEMENT_INDICATOR_SHEET("placement_indicator", 0, 0, 16, 256), + + // ComputerCraft + COMPUTER("computer", 200, 102); ; diff --git a/src/main/resources/assets/create/textures/gui/computer.png b/src/main/resources/assets/create/textures/gui/computer.png new file mode 100644 index 0000000000000000000000000000000000000000..293bedad784f171501f1983784abcf863ba62ae0 GIT binary patch literal 1016 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5D>38$lZxy-8q?;K+f|3pAc6d z{r~^}M~@!exN-BwjT_gmUq5r^%%_97$BrG_v17-QB}*1BUc7&n%Y+FNy1ToZnwlyq zDoRR9^7Hf4($d1i!$U(u9UL6uj2JB~En^KCVhtE#fJmRg+}u1`pCMY0Aqt3e8KQI; zB6S!%^~EE#86tp4iy<6{G#LyG3|zED_4M@YHH7Wdg>BS@t<{9ARD~>6fJo3nS`oN+#hRG+_7|fh9KU{vh z{rl>?&(*(cqIT_^>9>47cX@fdSN#5|`~GX(z5ie5kJg`gfA9agr6nGCn5oH||AXF^ zC?=l6QvIwR`~`)Ed}s6zK4F;q=g%+yE5|E&pX)Pisq1T&H)YNEE5mNDbATy}bHn>| z`NeAD9|~H&iBxQ6jj^w>vEo0gx8UvLcbgcvH^5Lv7322M$ZW=2kq2_WI<1qk{T7wY zy&}$|nh|IUCYlxHP!@VMs-aA*z+{hF2BTO47+tu+)EBUr+rn*k_)B}&zspy!UJ+XG zwOHm4(4G~_2cEWX(0g5RI-uYs9d3@9zXff`dYdd7&r}=IWDX{bt>Io(;;l) z^z(gg=_gs8*d^x8{Tjr5gwNm&kYeGV5T}sT@F@I2al;cPM&^?3OgzjYh4EYm z#!bDS*E27<=c5tSkW>5bIm1cwU@p;w@A?P7%=SFW7jXFO7AN)!-+aKopOC}t+<|