Search in sources :

Example 6 with ParameterDescription

use of mcjty.rftoolscontrol.api.parameters.ParameterDescription in project RFToolsControl by McJty.

the class GuiProgrammer method createValuePanel.

private Panel createValuePanel(ParameterDescription parameter, IIcon icon, IconHolder iconHolder, String tempDefault, boolean constantOnly) {
    Label<?> label = (Label<?>) new Label(mc, this).setText(StringUtils.capitalize(parameter.getName()) + ":").setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setDesiredHeight(13).setLayoutHint(new PositionalLayout.PositionalHint(0, 0, 53, 13));
    List<String> description = new ArrayList<>(parameter.getDescription());
    if (parameter.isOptional()) {
        description.set(description.size() - 1, description.get(description.size() - 1) + TextFormatting.GOLD + " [Optional]");
    }
    if (tempDefault != null && !tempDefault.isEmpty()) {
        description.add(TextFormatting.BLUE + tempDefault);
    }
    String[] tooltips = description.toArray(new String[description.size()]);
    TextField field = new TextField(mc, this).setText(tempDefault).setTooltips(tooltips).setDesiredHeight(13).setEditable(false).setLayoutHint(new PositionalLayout.PositionalHint(0, 12, 68, 13));
    Button button = new Button(mc, this).setText("...").setDesiredHeight(13).setTooltips(tooltips).addButtonEvent(w -> openValueEditor(icon, iconHolder, parameter, field, constantOnly)).setLayoutHint(new PositionalLayout.PositionalHint(58, 0, 11, 13));
    return new Panel(mc, this).setLayout(new PositionalLayout()).addChild(label).addChild(field).addChild(button).setDesiredWidth(68);
}
Also used : GenericGuiContainer(mcjty.lib.container.GenericGuiContainer) ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) GeneralConfiguration(mcjty.rftoolscontrol.config.GeneralConfiguration) OpcodeCategory(mcjty.rftoolscontrol.api.code.OpcodeCategory) Opcode(mcjty.rftoolscontrol.api.code.Opcode) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription) ParameterEditors(mcjty.rftoolscontrol.logic.editors.ParameterEditors) Keyboard(org.lwjgl.input.Keyboard) StringUtils(org.apache.commons.lang3.StringUtils) StyleConfig(mcjty.lib.base.StyleConfig) Panel(mcjty.lib.gui.widgets.Panel) Pair(org.apache.commons.lang3.tuple.Pair) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) ParameterEditor(mcjty.rftoolscontrol.logic.editors.ParameterEditor) Clipboard(java.awt.datatransfer.Clipboard) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ParameterTypeTools(mcjty.rftoolscontrol.logic.registry.ParameterTypeTools) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) List(java.util.List) Button(mcjty.lib.gui.widgets.Button) IIcon(mcjty.lib.gui.icons.IIcon) Connection(mcjty.rftoolscontrol.logic.Connection) TextField(mcjty.lib.gui.widgets.TextField) java.util(java.util) mcjty.lib.gui.widgets(mcjty.lib.gui.widgets) ParameterValue(mcjty.rftoolscontrol.api.parameters.ParameterValue) DataFlavor(java.awt.datatransfer.DataFlavor) HorizontalAlignment(mcjty.lib.gui.layout.HorizontalAlignment) OpcodeOutput(mcjty.rftoolscontrol.api.code.OpcodeOutput) Label(mcjty.lib.gui.widgets.Label) Window(mcjty.lib.gui.Window) GridInstance(mcjty.rftoolscontrol.logic.grid.GridInstance) ItemStack(net.minecraft.item.ItemStack) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) ProgramValidator(mcjty.rftoolscontrol.logic.compiled.ProgramValidator) GuiTools(mcjty.rftoolscontrol.gui.GuiTools) Logging(mcjty.lib.varia.Logging) ProgramCardItem(mcjty.rftoolscontrol.items.ProgramCardItem) StringSelection(java.awt.datatransfer.StringSelection) RFToolsControl(mcjty.rftoolscontrol.RFToolsControl) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) RFToolsCtrlMessages(mcjty.rftoolscontrol.network.RFToolsCtrlMessages) GridPos(mcjty.rftoolscontrol.logic.grid.GridPos) SelectionEvent(mcjty.lib.gui.events.SelectionEvent) Opcodes(mcjty.rftoolscontrol.logic.registry.Opcodes) TextFormatting(net.minecraft.util.text.TextFormatting) IOException(java.io.IOException) WindowManager(mcjty.lib.gui.WindowManager) java.awt(java.awt) Slot(net.minecraft.inventory.Slot) ResourceLocation(net.minecraft.util.ResourceLocation) ImageIcon(mcjty.lib.gui.icons.ImageIcon) ClickType(net.minecraft.inventory.ClickType) Label(mcjty.lib.gui.widgets.Label) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) Panel(mcjty.lib.gui.widgets.Panel) Button(mcjty.lib.gui.widgets.Button) TextField(mcjty.lib.gui.widgets.TextField)

Example 7 with ParameterDescription

use of mcjty.rftoolscontrol.api.parameters.ParameterDescription in project RFToolsControl by McJty.

the class GridInstance method readFromJson.

public static GridInstance readFromJson(JsonElement element) {
    JsonObject gridObject = element.getAsJsonObject();
    String id = gridObject.get("id").getAsString();
    GridInstance.Builder builder = GridInstance.builder(id);
    if (gridObject.has("primary")) {
        String primary = gridObject.get("primary").getAsString();
        builder.primaryConnection(Connection.getConnection(primary));
    }
    if (gridObject.has("secondary")) {
        String secondary = gridObject.get("secondary").getAsString();
        builder.secondaryConnection(Connection.getConnection(secondary));
    }
    Opcode opcode = Opcodes.OPCODES.get(id);
    if (opcode == null) {
        // Sanity check in case an opcode got removed
        return null;
    }
    List<ParameterDescription> parameters = opcode.getParameters();
    JsonArray parameterArray = gridObject.get("parameters").getAsJsonArray();
    for (int i = 0; i < parameterArray.size(); i++) {
        JsonObject parObject = parameterArray.get(i).getAsJsonObject();
        Parameter parameter = ParameterTools.readFromJson(parObject);
        if (parameter.getParameterType() != parameters.get(i).getType()) {
            // Sanity check
            builder.parameter(Parameter.builder().type(parameters.get(i).getType()).value(ParameterValue.constant(null)).build());
        } else {
            builder.parameter(parameter);
        }
    }
    return builder.build();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Opcode(mcjty.rftoolscontrol.api.code.Opcode) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription)

Example 8 with ParameterDescription

use of mcjty.rftoolscontrol.api.parameters.ParameterDescription in project RFToolsControl by McJty.

the class GridInstance method readFromNBT.

public static GridInstance readFromNBT(NBTTagCompound tag) {
    String opcodeid = tag.getString("id");
    GridInstance.Builder builder = GridInstance.builder(opcodeid);
    if (tag.hasKey("prim")) {
        builder.primaryConnection(Connection.getConnection(tag.getString("prim")));
    }
    if (tag.hasKey("sec")) {
        builder.secondaryConnection(Connection.getConnection(tag.getString("sec")));
    }
    Opcode opcode = Opcodes.OPCODES.get(opcodeid);
    if (opcode == null) {
        // Sanity check in case an opcode got removed
        return null;
    }
    List<ParameterDescription> parameters = opcode.getParameters();
    NBTTagList parList = tag.getTagList("pars", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < parList.tagCount(); i++) {
        NBTTagCompound parTag = (NBTTagCompound) parList.get(i);
        Parameter parameter = ParameterTools.readFromNBT(parTag);
        if (parameter.getParameterType() != parameters.get(i).getType()) {
            // Sanity check
            builder.parameter(Parameter.builder().type(parameters.get(i).getType()).value(ParameterValue.constant(null)).build());
        } else {
            builder.parameter(parameter);
        }
    }
    return builder.build();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Opcode(mcjty.rftoolscontrol.api.code.Opcode) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription)

Example 9 with ParameterDescription

use of mcjty.rftoolscontrol.api.parameters.ParameterDescription in project RFToolsControl by McJty.

the class CompiledCard method compile.

public static CompiledCard compile(ProgramCardInstance cardInstance) {
    if (cardInstance == null) {
        return null;
    }
    CompiledCard card = new CompiledCard();
    Map<GridPos, GridInstance> gridInstances = cardInstance.getGridInstances();
    // First find the indices of all compiled grid instances
    Map<GridPos, Integer> posToIndex = new HashMap<>();
    for (Map.Entry<GridPos, GridInstance> entry : gridInstances.entrySet()) {
        GridPos location = entry.getKey();
        posToIndex.put(location, posToIndex.size());
    }
    // Index of a dummy stop opcode that we can use to go too in case there is no real connection
    int stopIdx = posToIndex.size();
    for (Map.Entry<GridPos, GridInstance> entry : gridInstances.entrySet()) {
        GridPos location = entry.getKey();
        GridInstance grid = entry.getValue();
        String id = grid.getId();
        Opcode opcode = Opcodes.OPCODES.get(id);
        GridPos primaryOutput = grid.getPrimaryConnection() != null ? grid.getPrimaryConnection().offset(location) : null;
        GridPos secondaryOutput = grid.getSecondaryConnection() != null ? grid.getSecondaryConnection().offset(location) : null;
        CompiledOpcode.Builder opcodeBuilder = CompiledOpcode.builder().opcode(opcode);
        opcodeBuilder.grid(location.getX(), location.getY());
        if (primaryOutput != null && posToIndex.containsKey(primaryOutput)) {
            opcodeBuilder.primaryIndex(posToIndex.get(primaryOutput));
        } else {
            opcodeBuilder.primaryIndex(stopIdx);
        }
        if (secondaryOutput != null && posToIndex.containsKey(secondaryOutput)) {
            opcodeBuilder.secondaryIndex(posToIndex.get(secondaryOutput));
        } else {
            opcodeBuilder.secondaryIndex(stopIdx);
        }
        List<ParameterDescription> parameters = opcode.getParameters();
        boolean single = false;
        for (int i = 0; i < grid.getParameters().size(); i++) {
            Parameter parameter = grid.getParameters().get(i);
            if (i < parameters.size() && "single".equals(parameters.get(i).getName())) {
                single = TypeConverters.convertToBool(parameter);
            }
            opcodeBuilder.parameter(parameter);
        }
        if (opcode.isEvent()) {
            card.events.putIfAbsent(opcode, new ArrayList<>());
            card.events.get(opcode).add(new CompiledEvent(card.opcodes.size(), single));
        }
        card.opcodes.add(opcodeBuilder.build());
    }
    card.opcodes.add(CompiledOpcode.builder().opcode(Opcodes.DO_STOP_OR_RESUME).build());
    for (Opcode opcode : Opcodes.OPCODES.values()) {
        if (!card.events.containsKey(opcode)) {
            card.events.put(opcode, Collections.emptyList());
        }
    }
    return card;
}
Also used : Opcode(mcjty.rftoolscontrol.api.code.Opcode) GridInstance(mcjty.rftoolscontrol.logic.grid.GridInstance) GridPos(mcjty.rftoolscontrol.logic.grid.GridPos) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription)

Aggregations

Opcode (mcjty.rftoolscontrol.api.code.Opcode)9 ParameterDescription (mcjty.rftoolscontrol.api.parameters.ParameterDescription)9 Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)6 ParameterValue (mcjty.rftoolscontrol.api.parameters.ParameterValue)4 GridInstance (mcjty.rftoolscontrol.logic.grid.GridInstance)4 IIcon (mcjty.lib.gui.icons.IIcon)3 GridPos (mcjty.rftoolscontrol.logic.grid.GridPos)3 Panel (mcjty.lib.gui.widgets.Panel)2 Connection (mcjty.rftoolscontrol.logic.Connection)2 ProgramCardInstance (mcjty.rftoolscontrol.logic.grid.ProgramCardInstance)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 java.awt (java.awt)1 Clipboard (java.awt.datatransfer.Clipboard)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 StringSelection (java.awt.datatransfer.StringSelection)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 java.util (java.util)1 List (java.util.List)1