From ec8ac1ccd32099f2836afd5c1bb04bbb1a00ca01 Mon Sep 17 00:00:00 2001 From: nicksettler Date: Mon, 15 Jul 2024 01:50:09 +0200 Subject: [PATCH] feat(fabrication): improve IC blueprint configuration * add dimensions selection for the blueprint * add specifying author of the blueprint * add configuring number of layers of the blueprint * minor UI changes --- .../projectred_fabrication/lang/en_us.json | 2 + .../fabrication/editor/EditorDataUtils.java | 4 + .../fabrication/editor/ICWorkbenchEditor.java | 76 +++++++-- .../editor/WorkbenchDimension.java | 32 ++++ .../fabrication/engine/BaseTileMap.java | 17 +- .../fabrication/gui/ICRenderNode.java | 2 +- .../gui/screen/ICWorkbenchCompileTab.java | 14 +- .../gui/screen/ICWorkbenchEditTab.java | 17 +- .../gui/screen/ICWorkbenchInfoTab.java | 146 ++++++++++++++++-- .../fabrication/init/FabricationUnlocal.java | 38 ++--- .../fabrication/item/ICBlueprintItem.java | 2 + .../fabrication/part/FabricatedGatePart.java | 14 +- 12 files changed, 305 insertions(+), 59 deletions(-) create mode 100644 fabrication/src/main/java/mrtjp/projectred/fabrication/editor/WorkbenchDimension.java diff --git a/fabrication/src/main/generated/assets/projectred_fabrication/lang/en_us.json b/fabrication/src/main/generated/assets/projectred_fabrication/lang/en_us.json index 76bce5331..9457b0d41 100644 --- a/fabrication/src/main/generated/assets/projectred_fabrication/lang/en_us.json +++ b/fabrication/src/main/generated/assets/projectred_fabrication/lang/en_us.json @@ -123,6 +123,7 @@ "projectred_fabrication.tooltip.io_types": "IO types", "projectred_fabrication.tooltip.left": "Left", "projectred_fabrication.tooltip.name": "Name", + "projectred_fabrication.tooltip.author": "by %s", "projectred_fabrication.tooltip.output_mask": "Output mask", "projectred_fabrication.tooltip.right": "Right", "projectred_fabrication.tooltip.size": "Size", @@ -132,6 +133,7 @@ "projectred_fabrication.ui.auto_compile_description": "Enable to auto-compile design on change", "projectred_fabrication.ui.auto_compile_disabled": "Disabled. Design is too complex", "projectred_fabrication.ui.blueprint_dim": "Dimensions", + "projectred_fabrication.ui.blueprint_title": "%s by %s", "projectred_fabrication.ui.blueprint_info": "Blueprint Info", "projectred_fabrication.ui.blueprint_layers": "Layers", "projectred_fabrication.ui.blueprint_name": "Name", diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/EditorDataUtils.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/EditorDataUtils.java index e9c472a4a..4f8558cbd 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/EditorDataUtils.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/EditorDataUtils.java @@ -16,8 +16,10 @@ public class EditorDataUtils { public static final String KEY_FORMAT = "format"; // int public static final String KEY_ACTIVE = "active"; // boolean public static final String KEY_IC_NAME = "ic_name"; // String + public static final String KEY_IC_AUTHOR = "ic_author"; // String public static final String KEY_TILE_MAP = "tile_map"; // CompoundTag public static final String KEY_TILE_COUNT = "tile_count"; // int + public static final String KEY_DIMENSIONS = "dimensions"; // int public static final String KEY_IS_BUILT = "is_built"; // boolean public static final String KEY_IO_SPEC = "io_spec"; @@ -82,7 +84,9 @@ public static CompoundTag createFabricationCopy(CompoundTag editorTag) { copy.putInt(KEY_COMPILE_FORMAT, editorTag.getInt(KEY_COMPILE_FORMAT)); copy.putBoolean(KEY_IS_BUILT, editorTag.getBoolean(KEY_IS_BUILT)); copy.putString(KEY_IC_NAME, editorTag.getString(KEY_IC_NAME)); + copy.putString(KEY_IC_AUTHOR, editorTag.getString(KEY_IC_AUTHOR)); copy.putInt(KEY_TILE_COUNT, editorTag.getInt(KEY_TILE_COUNT)); + copy.putString(KEY_DIMENSIONS, editorTag.getString(KEY_DIMENSIONS)); copy.put(KEY_IO_SPEC, editorTag.getCompound(KEY_IO_SPEC)); copy.putString(KEY_FLAT_MAP, editorTag.getString(KEY_FLAT_MAP)); return copy; diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/ICWorkbenchEditor.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/ICWorkbenchEditor.java index ef47e1609..2dd8e8b27 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/ICWorkbenchEditor.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/ICWorkbenchEditor.java @@ -20,27 +20,30 @@ import static mrtjp.projectred.fabrication.editor.EditorDataUtils.*; public class ICWorkbenchEditor implements ICEditorStateMachine.StateMachineCallback { - - public static final Style UNIFORM = Style.EMPTY.withFont(new ResourceLocation("minecraft", "uniform")); + public static final Style UNIFORM = Style.EMPTY.withFont(new ResourceLocation("minecraft", "uniform")); public static final Style UNIFORM_DARK_GRAY = UNIFORM.withColor(ChatFormatting.DARK_GRAY); - public static final Style UNIFORM_GRAY = UNIFORM.withColor(ChatFormatting.GRAY); - public static final Style UNIFORM_RED = UNIFORM.withColor(ChatFormatting.RED); - public static final Style UNIFORM_YELLOW = UNIFORM.withColor(ChatFormatting.YELLOW); + public static final Style UNIFORM_GRAY = UNIFORM.withColor(ChatFormatting.GRAY); + public static final Style UNIFORM_RED = UNIFORM.withColor(ChatFormatting.RED); + public static final Style UNIFORM_YELLOW = UNIFORM.withColor(ChatFormatting.YELLOW); public static final int EDITOR_FORMAT = 1; - private static final int STREAM_ID_GENERAL = 0; + private static final int STREAM_ID_GENERAL = 0; private static final int STREAM_ID_TILE_UPDATES = 1; - private static final int STREAM_ID_FSM = 2; + private static final int STREAM_ID_FSM = 2; // Server to client keys - private static final int KEY_ADD_TILE = 1; - private static final int KEY_REMOVE_TILE = 2; - private static final int KEY_SET_IC_NAME = 3; + private static final int KEY_ADD_TILE = 1; + private static final int KEY_REMOVE_TILE = 2; + private static final int KEY_SET_IC_NAME = 3; + private static final int KEY_SET_IC_AUTHOR = 4; + private static final int KEY_SET_IC_DIMENSIONS = 5; // Client to server keys - private static final int KEY_TOOL = 10; - private static final int KEY_CLIENT_SEND_IC_NAME = 11; + private static final int KEY_TOOL = 10; + private static final int KEY_CLIENT_SEND_IC_NAME = 11; + private static final int KEY_CLIENT_SEND_IC_AUTHOR = 12; + private static final int KEY_CLIENT_SEND_IC_DIMENSIONS = 13; private final IICWorkbenchEditorNetwork network; private final BaseTileMap tileMap = new BaseTileMap(this); @@ -51,6 +54,7 @@ public class ICWorkbenchEditor implements ICEditorStateMachine.StateMachineCallb private boolean isActive = false; private String icName = "untitled"; + private String icAuthor = ""; public ICWorkbenchEditor(IICWorkbenchEditorNetwork network) { this.network = network; @@ -61,6 +65,10 @@ public String getIcName() { return icName; } + public String getIcAuthor() { + return icAuthor; + } + public ArrayList getToolList() { return toolList; } @@ -87,6 +95,7 @@ public void save(CompoundTag tag) { tag.putInt(KEY_FORMAT, EDITOR_FORMAT); tag.putBoolean(KEY_ACTIVE, isActive); tag.putString(KEY_IC_NAME, icName); + tag.putString(KEY_IC_AUTHOR, icAuthor); CompoundTag tileMapTag = new CompoundTag(); tileMap.save(tileMapTag); @@ -98,6 +107,7 @@ public void save(CompoundTag tag) { public void load(CompoundTag tag) { isActive = tag.getBoolean(KEY_ACTIVE); icName = tag.getString(KEY_IC_NAME); + icAuthor = tag.getString(KEY_IC_AUTHOR); tileMap.load(tag.getCompound(KEY_TILE_MAP)); stateMachine.load(tag); } @@ -105,6 +115,7 @@ public void load(CompoundTag tag) { public void writeDesc(MCDataOutput out) { out.writeBoolean(isActive); out.writeString(icName); + out.writeString(icAuthor); tileMap.writeDesc(out); stateMachine.writeDesc(out); } @@ -112,6 +123,7 @@ public void writeDesc(MCDataOutput out) { public void readDesc(MCDataInput in) { isActive = in.readBoolean(); icName = in.readString(); + icAuthor = in.readString(); tileMap.readDesc(in); stateMachine.readDesc(in); } @@ -124,6 +136,7 @@ private void clear() { tileMap.removeAll(); stateMachine.reset(); icName = "untitled"; + icAuthor = ""; } public void readBlueprintTagAndActivate(@Nullable CompoundTag tag) { @@ -144,6 +157,7 @@ public void writeBlueprintTagAndDeactivate(CompoundTag tag) { // Save additional metadata for blueprints tileMap.getInterfaceSpec().saveTo(tag, KEY_IO_SPEC); tag.putInt(KEY_TILE_COUNT, tileMap.getTileCount()); + tag.putString(KEY_DIMENSIONS, tileMap.getDimensionsString()); tag.putBoolean(KEY_IS_BUILT, stateMachine.isSimulating()); // Deactivate editor @@ -199,6 +213,15 @@ private void readGeneralStream(MCDataInput in, int frameKey) { case KEY_SET_IC_NAME: icName = in.readString(); break; + case KEY_SET_IC_AUTHOR: + icAuthor = in.readString(); + break; + case KEY_SET_IC_DIMENSIONS: + tileMap.setBounds( + new TileCoord(in.readInt(), in.readInt(), in.readInt()), + new TileCoord(in.readInt(), in.readInt(), in.readInt()) + ); + break; case KEY_TOOL: toolList.get(in.readUByte()).readPacket(in); break; @@ -207,6 +230,23 @@ private void readGeneralStream(MCDataInput in, int frameKey) { icName = in.readString(); network.getBufferedStream(STREAM_ID_GENERAL, KEY_SET_IC_NAME).writeString(icName); break; + case KEY_CLIENT_SEND_IC_AUTHOR: + icAuthor = in.readString(); + network.getBufferedStream(STREAM_ID_GENERAL, KEY_SET_IC_AUTHOR).writeString(icAuthor); + break; + case KEY_CLIENT_SEND_IC_DIMENSIONS: + tileMap.setBounds( + new TileCoord(in.readInt(), in.readInt(), in.readInt()), + new TileCoord(in.readInt(), in.readInt(), in.readInt()) + ); + + TileCoord minBounds = tileMap.getMinBounds(); + TileCoord maxBounds = tileMap.getMaxBounds(); + + network.getBufferedStream(STREAM_ID_GENERAL, KEY_SET_IC_DIMENSIONS) + .writeInt(minBounds.x).writeInt(minBounds.y).writeInt(minBounds.z) + .writeInt(maxBounds.x).writeInt(maxBounds.y).writeInt(maxBounds.z); + break; default: LOGGER.error("Unknown key " + frameKey + " in general stream"); } @@ -315,6 +355,18 @@ public void sendNewICName(String name) { // Notifies server to set a new IC name network.getBufferedStream(STREAM_ID_GENERAL, KEY_CLIENT_SEND_IC_NAME).writeString(name); } + + public void sendNewICAuthor(String author) { + // Notifies server to set a new IC author + network.getBufferedStream(STREAM_ID_GENERAL, KEY_CLIENT_SEND_IC_AUTHOR).writeString(author); + } + + public void sendNewICDimensions(TileCoord minBounds, TileCoord maxBounds) { + // Notifies server to set new IC dimensions + MCDataOutput out = network.getBufferedStream(STREAM_ID_GENERAL, KEY_CLIENT_SEND_IC_DIMENSIONS); + out.writeInt(minBounds.x).writeInt(minBounds.y).writeInt(minBounds.z); + out.writeInt(maxBounds.x).writeInt(maxBounds.y).writeInt(maxBounds.z); + } //endregion //region State Machine callbacks diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/WorkbenchDimension.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/WorkbenchDimension.java new file mode 100644 index 000000000..342ad9a73 --- /dev/null +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/editor/WorkbenchDimension.java @@ -0,0 +1,32 @@ +package mrtjp.projectred.fabrication.editor; + +import mrtjp.fengine.TileCoord; + +public enum WorkbenchDimension { + SIXTEEN(new TileCoord(-8, 0, -8), new TileCoord(7, 0, 7), "16x16"), + TWENTY_FOUR(new TileCoord(-12, 0, -12), new TileCoord(11, 0, 11), "24x24"), + THIRTY_TWO(new TileCoord(-16, 0, -16), new TileCoord(15, 0, 15), "32x32"), + FORTY_EIGHT(new TileCoord(-24, 0, -24), new TileCoord(23, 0, 23), "48x48"); + + private final TileCoord minBounds; + private final TileCoord maxBounds; + private final String unlocalizedName; + + WorkbenchDimension(TileCoord minBounds, TileCoord maxBounds, String unlocalizedName) { + this.minBounds = minBounds; + this.maxBounds = maxBounds; + this.unlocalizedName = unlocalizedName; + } + + public TileCoord getMinBounds() { + return minBounds; + } + + public TileCoord getMaxBounds() { + return maxBounds; + } + + public String getUnlocalizedName() { + return unlocalizedName; + } +} diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/BaseTileMap.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/BaseTileMap.java index 36e4f2ec2..2922e6336 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/BaseTileMap.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/engine/BaseTileMap.java @@ -6,6 +6,7 @@ import mrtjp.fengine.tiles.FETile; import mrtjp.fengine.tiles.FETileMap; import mrtjp.projectred.fabrication.editor.ICWorkbenchEditor; +import mrtjp.projectred.fabrication.editor.WorkbenchDimension; import net.covers1624.quack.collection.FastStream; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -16,18 +17,14 @@ import static mrtjp.projectred.fabrication.editor.EditorDataUtils.saveTileCoord; public class BaseTileMap implements FETileMap { - - private static final TileCoord defaultMinBounds = new TileCoord(-8, 0, -8); - private static final TileCoord defaultMaxBounds = new TileCoord(7, 0, 7); - private final Map tileMap = new HashMap<>(); private final ICWorkbenchEditor editor; private final Set ioTiles = new HashSet<>(); private final Map> layerToTileMap = new HashMap<>(); - private TileCoord minBounds = defaultMinBounds; - private TileCoord maxBounds = defaultMaxBounds; + private TileCoord minBounds = WorkbenchDimension.SIXTEEN.getMinBounds(); + private TileCoord maxBounds = WorkbenchDimension.SIXTEEN.getMaxBounds(); public BaseTileMap(ICWorkbenchEditor editor) { this.editor = editor; @@ -49,6 +46,10 @@ public TileCoord getDimensions() { return maxBounds.subtract(minBounds).add(1, 1, 1); } + public String getDimensionsString() { + return String.format("%d x %d x %d", getDimensions().x, getDimensions().y, getDimensions().z); + } + public void setBounds(TileCoord minBounds, TileCoord maxBounds) { this.minBounds = minBounds; this.maxBounds = maxBounds; @@ -108,8 +109,8 @@ public void removeAll() { tileMap.clear(); layerToTileMap.clear(); - minBounds = defaultMinBounds; - maxBounds = defaultMaxBounds; + minBounds = WorkbenchDimension.SIXTEEN.getMinBounds(); + maxBounds = WorkbenchDimension.SIXTEEN.getMaxBounds(); } private void cacheType(TileCoord coord, BaseTile tile) { diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/ICRenderNode.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/ICRenderNode.java index 688d0dcca..b8b9570e4 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/ICRenderNode.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/ICRenderNode.java @@ -27,7 +27,7 @@ public class ICRenderNode extends ViewportRenderNode { private static final int CAMERA_ANIMATION_TIME_MS = 100; private static final int FOCUS_ANIMATION_TIME_MS = 400; private static final int ZOOM_DIST_MAX = 18; - private static final int ZOOM_DIST_MIN = 2; + private static final int ZOOM_DIST_MIN = 1; private final ICWorkbenchEditor editor; private final IICRenderNodeEventReceiver eventReceiver; diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchCompileTab.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchCompileTab.java index b857f604e..12753ccc4 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchCompileTab.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchCompileTab.java @@ -103,8 +103,20 @@ public void drawBack(GuiGraphics graphics, Point mouse, float partialFrame) { RenderSystem.setShaderTexture(0, TAB_BACKGROUND); graphics.blit(TAB_BACKGROUND, getFrame().x(), getFrame().y(), 0, 0, getFrame().width(), getFrame().height(), 512, 512); + String icName = editor.getIcName(); + String icAuthor = editor.getIcAuthor(); + // Blueprint name in top left corner - graphics.drawString(getRoot().getFontRenderer(), editor.getIcName(), getFrame().x() + 8, getFrame().y() + 6, EnumColour.GRAY.argb(), false); + graphics.drawString( + getRoot().getFontRenderer(), + !icAuthor.isEmpty() ? + Component.translatable(UL_BLUEPRINT_TITLE, icName, icAuthor).getString() : + icName, + getFrame().x() + 8, + getFrame().y() + 6, + EnumColour.GRAY.argb(), + false + ); // Progress bar RenderSystem.setShaderTexture(0, TAB_BACKGROUND); diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchEditTab.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchEditTab.java index c8ef89a27..f7b1c9e23 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchEditTab.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchEditTab.java @@ -10,6 +10,9 @@ import mrtjp.projectred.redui.AbstractGuiNode; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; + +import static mrtjp.projectred.fabrication.init.FabricationUnlocal.UL_BLUEPRINT_TITLE; public class ICWorkbenchEditTab extends AbstractGuiNode { @@ -80,8 +83,20 @@ public void drawBack(GuiGraphics graphics, Point mouse, float partialFrame) { graphics.blit(ICWorkbenchScreen.BACKGROUND, frame.x(), frame.y(), 0, 0, frame.width(), frame.height(), 512, 512); + String icName = editor.getIcName(); + String icAuthor = editor.getIcAuthor(); + // Blueprint name in top left corner - graphics.drawString(fontRenderer, editor.getIcName(), frame.x() + 8, frame.y() + 6, EnumColour.GRAY.argb(), false); + graphics.drawString( + fontRenderer, + !icAuthor.isEmpty() ? + Component.translatable(UL_BLUEPRINT_TITLE, icName, icAuthor).getString() : + icName, + frame.x() + 8, + frame.y() + 6, + EnumColour.GRAY.argb(), + false + ); } @Override diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchInfoTab.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchInfoTab.java index f444b3111..3581dcd9a 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchInfoTab.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/gui/screen/ICWorkbenchInfoTab.java @@ -4,6 +4,7 @@ import mrtjp.fengine.TileCoord; import mrtjp.projectred.fabrication.ProjectRedFabrication; import mrtjp.projectred.fabrication.editor.ICWorkbenchEditor; +import mrtjp.projectred.fabrication.editor.WorkbenchDimension; import mrtjp.projectred.fabrication.gui.ButtonArrayNode; import mrtjp.projectred.fabrication.gui.PipelineDiagramNode; import mrtjp.projectred.fabrication.gui.VerticalListNode; @@ -48,22 +49,24 @@ private void initSubNodes() { listNode.setSize(280, 198); addChild(listNode); + listNode.addTitleRow(Component.translatable(UL_BLUEPRINT_INFO)); + NameTextBox nameTextBox = new NameTextBox(); nameTextBox.setSize(80, 18); - - listNode.addTitleRow(Component.translatable(UL_BLUEPRINT_INFO)); listNode.addTextWithNodeRow(Component.translatable(UL_BLUEPRINT_NAME), nameTextBox); - listNode.addKeyValueRow(Component.translatable(UL_BLUEPRINT_OWNER), () -> Component.literal("//TODO")); - listNode.addKeyValueRow(Component.translatable(UL_BLUEPRINT_DIM), () -> { - TileCoord dimensions = editor.getTileMap().getDimensions(); - return Component.translatable(UL_DIMENSIONS_TILES, dimensions.x, dimensions.z); - }); + AuthorTextBox authorTextBox = new AuthorTextBox(); + authorTextBox.setSize(80, 18); + listNode.addTextWithNodeRow(Component.translatable(UL_BLUEPRINT_OWNER), authorTextBox); + + ButtonArrayNode dimensionButtons = createDimensionButtons(); + dimensionButtons.setGridSize(128, 18); + listNode.addTextWithNodeRow(Component.translatable(UL_BLUEPRINT_DIM), dimensionButtons); + + LayersTextBox layersTextBox = new LayersTextBox(); + layersTextBox.setSize(80, 18); + listNode.addTextWithNodeRow(Component.translatable(UL_BLUEPRINT_LAYERS), layersTextBox); - listNode.addKeyValueRow(Component.translatable(UL_BLUEPRINT_LAYERS), () -> { - TileCoord dimensions = editor.getTileMap().getDimensions(); - return Component.literal(String.valueOf(dimensions.y)); - }); listNode.addTitleRow(Component.translatable(UL_YIELD_CALCULATOR)); @@ -117,12 +120,63 @@ public void update() { public void drawBack(GuiGraphics graphics, Point mouse, float partialFrame) { graphics.blit(TAB_BACKGROUND, getFrame().x(), getFrame().y(), 0, 0, getFrame().width(), getFrame().height(), 512, 512); + String icName = editor.getIcName(); + String icAuthor = editor.getIcAuthor(); + // Blueprint name in top left corner - graphics.drawString(getRoot().getFontRenderer(), editor.getIcName(), getFrame().x() + 8, getFrame().y() + 6, EnumColour.GRAY.argb(), false); + graphics.drawString( + getRoot().getFontRenderer(), + !icAuthor.isEmpty() ? + Component.translatable(UL_BLUEPRINT_TITLE, icName, icAuthor).getString() : + icName, + getFrame().x() + 8, + getFrame().y() + 6, + EnumColour.GRAY.argb(), + false + ); + } + + private ButtonArrayNode createDimensionButtons() { + ButtonArrayNode.Listener listener = new ButtonArrayNode.Listener() { + @Override + public String getButtonText(int index) { + return WorkbenchDimension.values()[index].getUnlocalizedName(); + } + + @Override + public void onButtonClicked(int index) { + WorkbenchDimension dimension = WorkbenchDimension.values()[index]; + + editor.sendNewICDimensions( + new TileCoord(dimension.getMinBounds().x, editor.getTileMap().getMinBounds().y, dimension.getMinBounds().z), + new TileCoord(dimension.getMaxBounds().x, editor.getTileMap().getMaxBounds().y, dimension.getMaxBounds().z) + ); + } + + @Override + public boolean isButtonEnabled(int index) { + return true; + } + + @Override + public boolean isButtonSelected(int index) { + WorkbenchDimension dimension = WorkbenchDimension.values()[index]; + + TileCoord minBounds = editor.getTileMap().getMinBounds(); + TileCoord maxBounds = editor.getTileMap().getMaxBounds(); + + return minBounds.x == dimension.getMinBounds().x && + minBounds.z == dimension.getMinBounds().z && + maxBounds.x == dimension.getMaxBounds().x && + maxBounds.z == dimension.getMaxBounds().z; + } + }; + + return new ButtonArrayNode(listener, 1, WorkbenchDimension.values().length, 2); } private ButtonArrayNode createPipelineButtons() { - ButtonArrayNode.Listener listener = new ButtonArrayNode.Listener() { + ButtonArrayNode.Listener listener = new ButtonArrayNode.Listener() { @Override public String getButtonText(int index) { return LithographyPipeline.values()[index].getUnlocalizedName(); @@ -204,7 +258,6 @@ public boolean isButtonSelected(int index) { } private class NameTextBox extends TextBoxNode { - public NameTextBox() { super(editor.getIcName()); } @@ -231,4 +284,69 @@ protected void onReturnPressed() { editor.sendNewICName(getText()); } } + + private class AuthorTextBox extends TextBoxNode { + public AuthorTextBox() { + super(editor.getIcAuthor()); + } + + @Override + public void update() { + super.update(); + if (!getText().equals(editor.getIcAuthor()) && !isEditing()) { + setText(editor.getIcAuthor()); + } + } + + @Override + protected String getSuggestionString() { + return editor.getIcAuthor(); + } + + @Override + protected void onTextChanged() { + } + + @Override + protected void onReturnPressed() { + editor.sendNewICAuthor(getText()); + } + } + + private class LayersTextBox extends TextBoxNode { + public LayersTextBox() { + super(String.valueOf(editor.getTileMap().getDimensions().y)); + } + + @Override + public void update() { + super.update(); + if (!getText().equals(String.valueOf(editor.getTileMap().getDimensions().y)) && !isEditing()) { + setText(String.valueOf(editor.getTileMap().getDimensions().y)); + } + } + + @Override + protected String getSuggestionString() { + return String.valueOf(editor.getTileMap().getDimensions().y); + } + + @Override + protected void onTextChanged() { + setText(getText().replaceAll("[^0-9]", "")); + } + + @Override + protected void onReturnPressed() { + TileCoord minBounds = editor.getTileMap().getMinBounds(); + TileCoord maxBounds = editor.getTileMap().getMaxBounds(); + + int layers = Integer.parseInt(getText()); + + editor.sendNewICDimensions( + minBounds, + new TileCoord(maxBounds.x, layers - 1, maxBounds.z) + ); + } + } } diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/init/FabricationUnlocal.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/init/FabricationUnlocal.java index e4d990e4a..aad7f8806 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/init/FabricationUnlocal.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/init/FabricationUnlocal.java @@ -98,6 +98,7 @@ public class FabricationUnlocal { public static final String UL_BLUEPRINT_NAME = PREFIX + "ui.blueprint_name"; public static final String UL_BLUEPRINT_OWNER = PREFIX + "ui.blueprint_owner"; public static final String UL_BLUEPRINT_DIM = PREFIX + "ui.blueprint_dim"; + public static final String UL_BLUEPRINT_TITLE = PREFIX + "ui.blueprint_title"; public static final String UL_BLUEPRINT_LAYERS = PREFIX + "ui.blueprint_layers"; public static final String UL_COMPILE = PREFIX + "ui.compile"; public static final String UL_COMPILE_PROGRESS = PREFIX + "ui.compile_progress"; @@ -136,24 +137,25 @@ public class FabricationUnlocal { public static final String UL_TILEGROUP_MEMORY = PREFIX + "tilegroup.memory"; // Item tooltips - public static final String UL_SIZE = PREFIX + "tooltip.size"; - public static final String UL_DEFECT_CHANCE = PREFIX + "tooltip.defect_chance"; - public static final String UL_CORRUPTED_DISCARD = PREFIX + "tooltip.corrupted_discard"; //"Corrupted NBT data, please discard" - public static final String UL_NAME = PREFIX + "tooltip.name"; - public static final String UL_TILE_COUNT = PREFIX + "tooltip.tile_count"; - public static final String UL_IO_TYPES = PREFIX + "tooltip.io_types"; - public static final String UL_INPUT_MASK = PREFIX + "tooltip.input_mask"; - public static final String UL_OUTPUT_MASK = PREFIX + "tooltip.output_mask"; - public static final String UL_TOP = PREFIX + "tooltip.top"; - public static final String UL_RIGHT = PREFIX + "tooltip.right"; - public static final String UL_BOTTOM = PREFIX + "tooltip.bottom"; - public static final String UL_LEFT = PREFIX + "tooltip.left"; - public static final String UL_BUNDLED_INPUT = PREFIX + "tooltip.bundled_input"; - public static final String UL_BUNDLED_OUTPUT = PREFIX + "tooltip.bundled_output"; - public static final String UL_IO_NONE = PREFIX + "tooltip.io_none"; - public static final String UL_FAB_ERR_NOT_COMPILED = PREFIX + "tooltip.fab_err.not_compiled"; - public static final String UL_FAB_ERR_COMPILE_FORMAT = PREFIX + "tooltip.fab_err.compile_format"; - public static final String UL_FAB_ERR_GENERIC = PREFIX + "tooltip.fab_err.generic"; + public static final String UL_SIZE = PREFIX + "tooltip.size"; + public static final String UL_DEFECT_CHANCE = PREFIX + "tooltip.defect_chance"; + public static final String UL_CORRUPTED_DISCARD = PREFIX + "tooltip.corrupted_discard"; //"Corrupted NBT data, please discard" + public static final String UL_NAME = PREFIX + "tooltip.name"; + public static final String UL_AUTHOR = PREFIX + "tooltip.author"; + public static final String UL_TILE_COUNT = PREFIX + "tooltip.tile_count"; + public static final String UL_IO_TYPES = PREFIX + "tooltip.io_types"; + public static final String UL_INPUT_MASK = PREFIX + "tooltip.input_mask"; + public static final String UL_OUTPUT_MASK = PREFIX + "tooltip.output_mask"; + public static final String UL_TOP = PREFIX + "tooltip.top"; + public static final String UL_RIGHT = PREFIX + "tooltip.right"; + public static final String UL_BOTTOM = PREFIX + "tooltip.bottom"; + public static final String UL_LEFT = PREFIX + "tooltip.left"; + public static final String UL_BUNDLED_INPUT = PREFIX + "tooltip.bundled_input"; + public static final String UL_BUNDLED_OUTPUT = PREFIX + "tooltip.bundled_output"; + public static final String UL_IO_NONE = PREFIX + "tooltip.io_none"; + public static final String UL_FAB_ERR_NOT_COMPILED = PREFIX + "tooltip.fab_err.not_compiled"; + public static final String UL_FAB_ERR_COMPILE_FORMAT = PREFIX + "tooltip.fab_err.compile_format"; + public static final String UL_FAB_ERR_GENERIC = PREFIX + "tooltip.fab_err.generic"; // Interfaces public static final String UL_INTERFACE_NC = PREFIX + "interface.nc"; diff --git a/fabrication/src/main/java/mrtjp/projectred/fabrication/item/ICBlueprintItem.java b/fabrication/src/main/java/mrtjp/projectred/fabrication/item/ICBlueprintItem.java index 56dc816fe..02eec7548 100644 --- a/fabrication/src/main/java/mrtjp/projectred/fabrication/item/ICBlueprintItem.java +++ b/fabrication/src/main/java/mrtjp/projectred/fabrication/item/ICBlueprintItem.java @@ -66,7 +66,9 @@ public static void buildTooltip(@Nullable CompoundTag blueprintTag, List