Skip to content

Commit

Permalink
Add "clear all" button to logic workbench, see #2
Browse files Browse the repository at this point in the history
  • Loading branch information
malte0811 committed Mar 29, 2022
1 parent 17d2223 commit 2dd6128
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import malte0811.controlengineering.controlpanels.PanelComponents;
import malte0811.controlengineering.gui.logic.LogicDesignScreen;
import malte0811.controlengineering.gui.misc.BusSignalSelector;
import malte0811.controlengineering.gui.misc.ConfirmScreen;
import malte0811.controlengineering.gui.misc.DataProviderScreen;
import malte0811.controlengineering.gui.panel.PanelDesignScreen;
import malte0811.controlengineering.gui.widget.ColorSelector;
Expand Down Expand Up @@ -137,7 +138,11 @@ private void addGuiStrings() {
add(IOSymbol.SIGNAL_KEY, "%d signal on line %d");
add(ConstantSymbol.INPUT_KEY, "Signal strength: %d");

add(LogicDesignScreen.COMPONENTS_KEY, "Components");
add(LogicDesignScreen.COMPONENTS_KEY, "Add");
add(LogicDesignScreen.COMPONENTS_TOOLTIP, "Add new components");
add(LogicDesignScreen.CLEAR_ALL_KEY, "Clear");
add(LogicDesignScreen.CLEAR_ALL_TOOLTIP, "Remove all components and wires");
add(LogicDesignScreen.CLEAR_ALL_MESSAGE, "Clear entire schematic?");
add(LogicDesignScreen.DRC_INFO_KEY, "Highlight floating input pins");
add(LogicDesignScreen.PIN_KEY, "Pin: %d");

Expand Down Expand Up @@ -179,6 +184,9 @@ private void addGuiStrings() {
add(RSRemapperBlockEntity.GRAY_KEY, "Gray");

add(PCBStackItem.FOR_USE_IN_KEY, "For use in a %s");

add(ConfirmScreen.CANCEL_KEY, "Cancel");
add(ConfirmScreen.OK_KEY, "Ok");
}

private void addManualStrings() {
Expand Down
2 changes: 1 addition & 1 deletion src/generated/resources/.cache/cache
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ c3cb573a3eeb21d07089b6cef3357171fd2fd668 assets/controlengineering/blockstates/p
f1d76c448b8d589a513a83edc36d1cfb0d293b0c assets/controlengineering/blockstates/panel_designer.json
3aa2a61bcbaa3028d86461f12186d18e7d0f378d assets/controlengineering/blockstates/rs_remapper.json
ad19fd784b5aca259a0c8d3799bed9319da7676d assets/controlengineering/blockstates/sequencer.json
d2f1c03c00c045513f3f2477000e4d50bf2a61d5 assets/controlengineering/lang/en_us.json
a3049291c5e8390e0461a090c25fe17d03233410 assets/controlengineering/lang/en_us.json
fe84748161d011430486978e6647b33f6f68bd57 assets/controlengineering/models/block/bus_interface_obj.json
d39d3b4213f70aa5588ed0dd327a19e43e79aae4 assets/controlengineering/models/block/bus_relay_obj.json
c819943077b485ede8f1af0e3bbd4863e91f3c5f assets/controlengineering/models/block/combined_keypunch.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@
"controlengineering.gui.analogVsDigital": "Net would connect an analog source to digital sinks",
"controlengineering.gui.blue": "Blue: %d",
"controlengineering.gui.busRef": "%d signal on line %d",
"controlengineering.gui.cancel": "Cancel",
"controlengineering.gui.clearAll": "Clear",
"controlengineering.gui.clearAll.tooltip": "Remove all components and wires",
"controlengineering.gui.clearAll.warning": "Clear entire schematic?",
"controlengineering.gui.component_ingredients": "Ingredients",
"controlengineering.gui.components": "Components",
"controlengineering.gui.components": "Add",
"controlengineering.gui.components.tooltip": "Add new components",
"controlengineering.gui.cycle": "Net would form a cycle",
"controlengineering.gui.done": "Done",
"controlengineering.gui.drcOn": "Highlight floating input pins",
Expand All @@ -56,6 +61,7 @@
"controlengineering.gui.needMoreTubes": "%d vacuum tubes are required",
"controlengineering.gui.needMoreWires": "%d wires are required",
"controlengineering.gui.no_loopback": "Remote transmission",
"controlengineering.gui.ok": "Ok",
"controlengineering.gui.panel_back_height": "Back height",
"controlengineering.gui.panel_front_height": "Front height",
"controlengineering.gui.pin": "Pin: %d",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import malte0811.controlengineering.blockentity.logic.LogicCabinetBlockEntity;
import malte0811.controlengineering.blockentity.logic.LogicWorkbenchBlockEntity.AvailableIngredients;
import malte0811.controlengineering.gui.StackedScreen;
import malte0811.controlengineering.gui.misc.ConfirmScreen;
import malte0811.controlengineering.gui.widget.SmallCheckbox;
import malte0811.controlengineering.items.IEItemRefs;
import malte0811.controlengineering.logic.schematic.ConnectedPin;
Expand Down Expand Up @@ -46,6 +47,10 @@

public class LogicDesignScreen extends StackedScreen implements MenuAccess<LogicDesignMenu> {
public static final String COMPONENTS_KEY = ControlEngineering.MODID + ".gui.components";
public static final String COMPONENTS_TOOLTIP = ControlEngineering.MODID + ".gui.components.tooltip";
public static final String CLEAR_ALL_KEY = ControlEngineering.MODID + ".gui.clearAll";
public static final String CLEAR_ALL_TOOLTIP = ControlEngineering.MODID + ".gui.clearAll.tooltip";
public static final String CLEAR_ALL_MESSAGE = ControlEngineering.MODID + ".gui.clearAll.warning";
public static final String DRC_INFO_KEY = ControlEngineering.MODID + ".gui.drcOn";
public static final String PIN_KEY = ControlEngineering.MODID + ".gui.pin";

Expand Down Expand Up @@ -80,15 +85,19 @@ protected void init() {
super.init();
if (!container.readOnly) {
addRenderableWidget(new Button(
TOTAL_BORDER, TOTAL_BORDER, 20, 20, new TextComponent("C"),
TOTAL_BORDER, TOTAL_BORDER, 40, 20, new TranslatableComponent(COMPONENTS_KEY),
btn -> minecraft.setScreen(new CellSelectionScreen(s -> {
placingSymbol = new PlacingSymbol(s, Vec2d.ZERO);
resetAfterPlacingSymbol = false;
})),
makeTooltip(COMPONENTS_KEY)
makeTooltip(COMPONENTS_TOOLTIP)
));
addRenderableWidget(new Button(
TOTAL_BORDER, TOTAL_BORDER + 20, 40, 20, new TranslatableComponent(CLEAR_ALL_KEY),
this::handleClearAll, makeTooltip(CLEAR_ALL_TOOLTIP)
));
addRenderableWidget(new SmallCheckbox(
TOTAL_BORDER, TOTAL_BORDER + 20, 20, 20, new TextComponent("DRC"), errorsShown,
TOTAL_BORDER, TOTAL_BORDER + 40, 20, 20, new TextComponent("DRC"), errorsShown,
newState -> {
errorsShown = newState;
updateErrors();
Expand All @@ -102,6 +111,12 @@ protected void init() {
);
}

private void handleClearAll(Button $) {
Minecraft.getInstance().setScreen(new ConfirmScreen(
new TranslatableComponent(CLEAR_ALL_MESSAGE), () -> runAndSendToServer(new ClearAll())
));
}

private Button.OnTooltip makeTooltip(String key) {
return ($, transform, x, y) -> this.renderTooltip(transform, new TranslatableComponent(key), x, y);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package malte0811.controlengineering.gui.misc;

import com.mojang.blaze3d.vertex.PoseStack;
import malte0811.controlengineering.ControlEngineering;
import malte0811.controlengineering.gui.StackedScreen;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;

import javax.annotation.Nonnull;

public class ConfirmScreen extends StackedScreen {
public static final String OK_KEY = ControlEngineering.MODID + ".gui.ok";
public static final String CANCEL_KEY = ControlEngineering.MODID + ".gui.cancel";

private final Runnable onOk;

public ConfirmScreen(Component message, Runnable onOk) {
super(message);
this.onOk = onOk;
}

protected void init() {
super.init();
addRenderableWidget(new Button(
this.width / 2 - 155, 110,
150, 20,
new TranslatableComponent(OK_KEY),
$ -> {
onOk.run();
onClose();
}
));
addRenderableWidget(new Button(
this.width / 2 - 155 + 160, 110,
150, 20,
new TranslatableComponent(CANCEL_KEY), $ -> onClose()
));
}

@Override
protected void renderForeground(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) {
drawCenteredString(matrixStack, this.font, this.title, this.width / 2, 90, -1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,9 @@ public int getWireLength() {
public int getSolderAmount() {
return getTotalCost(CellCost::getSolderAmount);
}

public void clear() {
symbols.clear();
nets.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package malte0811.controlengineering.network.logic;

import malte0811.controlengineering.logic.schematic.Schematic;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.Level;

import java.util.function.Consumer;

public class ClearAll extends LogicSubPacket {
public ClearAll() {}

public ClearAll(FriendlyByteBuf buffer) {}

@Override
protected void write(FriendlyByteBuf out) {}

@Override
public boolean process(Schematic applyTo, Consumer<Schematic> replace, Level level) {
applyTo.clear();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static void init() {
register(AddSymbol.class, AddSymbol::new);
register(AddWire.class, AddWire::new);
register(Delete.class, Delete::new);
register(ClearAll.class, ClearAll::new);
}

private static <T extends LogicSubPacket>
Expand Down

0 comments on commit 2dd6128

Please sign in to comment.