mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-13 22:34:11 +01:00
Added ComputerScreen
- ComputerScreen shows that tile entity currently has computers attached and therefore cannot be controlled manually
This commit is contained in:
parent
9afdcaded7
commit
94e3ed44ad
7 changed files with 178 additions and 50 deletions
|
@ -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!"
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Component> displayTitle;
|
||||
private final RenderWindowFunction additional;
|
||||
private final Screen previousScreen;
|
||||
private final Supplier<Boolean> hasAttachedComputer;
|
||||
|
||||
private AbstractSimiWidget computerWidget;
|
||||
private IconButton confirmButton;
|
||||
|
||||
public ComputerScreen(Component title, @Nullable RenderWindowFunction additional, Screen previousScreen, Supplier<Boolean> hasAttachedComputer) {
|
||||
this(title, () -> title, additional, previousScreen, hasAttachedComputer);
|
||||
}
|
||||
|
||||
public ComputerScreen(Component title, Supplier<Component> displayTitle, @Nullable RenderWindowFunction additional, Screen previousScreen, Supplier<Boolean> 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Instruction> instructions;
|
||||
private BlockPos pos;
|
||||
private final boolean hasAttachedComputer;
|
||||
|
||||
private Vector<Vector<ScrollInput>> 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)
|
||||
.<GuiGameElement.GuiRenderBuilder>at(x + background.width + 6, y + background.height - 56, -200)
|
||||
.<GuiGameElement.GuiRenderBuilder>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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
;
|
||||
|
||||
|
|
BIN
src/main/resources/assets/create/textures/gui/computer.png
Normal file
BIN
src/main/resources/assets/create/textures/gui/computer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1,016 B |
Loading…
Reference in a new issue