Search in sources :

Example 6 with Opcode

use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.

the class GuiProgrammer method tryConnectToThis.

private void tryConnectToThis(int x, int y, IIcon icon, Connection connection) {
    if (x < 0 || x >= GRID_WIDTH) {
        return;
    }
    if (y < 0 || y >= GRID_HEIGHT) {
        return;
    }
    IconHolder holder = getHolder(x, y);
    IIcon sourceIcon = holder.getIcon();
    if (sourceIcon != null) {
        Opcode opcode = Opcodes.OPCODES.get(sourceIcon.getID());
        if (opcode.getOpcodeOutput() == OpcodeOutput.NONE) {
            return;
        } else if (opcode.getOpcodeOutput() == OpcodeOutput.SINGLE) {
            int cnt = countConnections(sourceIcon);
            if (cnt == 0) {
                sourceIcon.addOverlay(CONNECTION_ICONS.get(connection));
            }
        } else if (opcode.getOpcodeOutput() == OpcodeOutput.YESNO) {
            int cnt = countPrimaryConnections(sourceIcon);
            if (cnt == 0) {
                sourceIcon.addOverlay(CONNECTION_ICONS.get(connection));
            } else {
                cnt = countSecondaryConnections(sourceIcon);
                if (cnt == 0) {
                    sourceIcon.addOverlay(CONNECTION_ICONS.get(connection.getOpposite()));
                }
            }
        }
    }
}
Also used : IIcon(mcjty.lib.gui.icons.IIcon) Opcode(mcjty.rftoolscontrol.api.code.Opcode)

Example 7 with Opcode

use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.

the class GuiProgrammer method initIcons.

private void initIcons() {
    if (ICONS.isEmpty()) {
        for (Map.Entry<String, Opcode> entry : Opcodes.OPCODES.entrySet()) {
            String id = entry.getKey();
            Opcode opcode = entry.getValue();
            ResourceLocation iconResource = icons;
            if (opcode.getIconResource() != null) {
                iconResource = new ResourceLocation(opcode.getIconResource());
            }
            ICONS.put(id, new ImageIcon(id).setDimensions(ICONSIZE, ICONSIZE).setImage(iconResource, opcode.getIconU() * ICONSIZE, opcode.getIconV() * ICONSIZE));
        }
    }
}
Also used : ImageIcon(mcjty.lib.gui.icons.ImageIcon) ResourceLocation(net.minecraft.util.ResourceLocation) Opcode(mcjty.rftoolscontrol.api.code.Opcode)

Example 8 with Opcode

use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.

the class GuiProgrammer method getIconTooltip.

private List<String> getIconTooltip(IIcon icon) {
    if (icon != null) {
        Opcode opcode = Opcodes.OPCODES.get(icon.getID());
        List<String> description = opcode.getDescription();
        List<String> tooltips = new ArrayList<>();
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
            tooltips.addAll(description);
            for (ParameterDescription parameter : opcode.getParameters()) {
                boolean first = true;
                for (int i = 0; i < parameter.getDescription().size(); i++) {
                    String s = parameter.getDescription().get(i);
                    if (first) {
                        s = TextFormatting.BLUE + "Par '" + parameter.getName() + "': " + s;
                        first = false;
                    } else {
                        s = TextFormatting.BLUE + "      " + s;
                    }
                    if (parameter.isOptional() && i == parameter.getDescription().size() - 1) {
                        s += TextFormatting.GOLD + " [Optional]";
                    }
                    tooltips.add(s);
                }
            }
            tooltips.add(TextFormatting.YELLOW + "Result: " + opcode.getOutputDescription());
        } else {
            tooltips.add(description.get(0));
            tooltips.add("<Shift for more info>");
        }
        return tooltips;
    }
    return Collections.emptyList();
}
Also used : Opcode(mcjty.rftoolscontrol.api.code.Opcode) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription)

Example 9 with Opcode

use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.

the class GuiProgrammer method setEditorPanel.

private void setEditorPanel(IconHolder iconHolder, IIcon icon) {
    String id = icon.getID();
    Opcode opcode = Opcodes.OPCODES.get(id);
    Map<String, Object> data = icon.getData() == null ? Collections.emptyMap() : icon.getData();
    clearEditorPanel();
    for (ParameterDescription parameter : opcode.getParameters()) {
        String name = parameter.getName();
        ParameterValue value = (ParameterValue) data.get(name);
        Panel panel;
        if (value != null) {
            panel = createValuePanel(parameter, icon, iconHolder, ParameterTypeTools.stringRepresentation(parameter.getType(), value), opcode.isEvent());
        } else {
            panel = createValuePanel(parameter, icon, iconHolder, "", opcode.isEvent());
        }
        editorList.addChild(panel);
    }
}
Also used : Panel(mcjty.lib.gui.widgets.Panel) ParameterValue(mcjty.rftoolscontrol.api.parameters.ParameterValue) Opcode(mcjty.rftoolscontrol.api.code.Opcode) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription)

Example 10 with Opcode

use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.

the class GuiProgrammer method handleIconOverlay.

private void handleIconOverlay(IIcon icon, Connection connection) {
    Opcode opcode = Opcodes.OPCODES.get(icon.getID());
    if (opcode.getOpcodeOutput() == OpcodeOutput.NONE) {
        return;
    }
    if (opcode.getOpcodeOutput() == OpcodeOutput.SINGLE) {
        boolean has = icon.hasOverlay(connection.getId());
        for (Connection c : Connection.values()) {
            icon.removeOverlay(c.getId());
        }
        if (!has) {
            if (!icon.hasOverlay(connection.getId())) {
                icon.addOverlay(CONNECTION_ICONS.get(connection));
            }
        }
    } else {
        if (icon.hasOverlay(connection.getId())) {
            icon.removeOverlay(Connection.DOWN_NEG.getId());
            icon.removeOverlay(Connection.UP_NEG.getId());
            icon.removeOverlay(Connection.LEFT_NEG.getId());
            icon.removeOverlay(Connection.RIGHT_NEG.getId());
            icon.removeOverlay(connection.getId());
            icon.addOverlay(CONNECTION_ICONS.get(connection.getOpposite()));
        } else if (icon.hasOverlay(connection.getOpposite().getId())) {
            icon.removeOverlay(connection.getOpposite().getId());
        } else {
            if (connection.isPrimary()) {
                icon.removeOverlay(Connection.DOWN.getId());
                icon.removeOverlay(Connection.UP.getId());
                icon.removeOverlay(Connection.LEFT.getId());
                icon.removeOverlay(Connection.RIGHT.getId());
            } else {
                icon.removeOverlay(Connection.DOWN_NEG.getId());
                icon.removeOverlay(Connection.UP_NEG.getId());
                icon.removeOverlay(Connection.LEFT_NEG.getId());
                icon.removeOverlay(Connection.RIGHT_NEG.getId());
            }
            icon.addOverlay(CONNECTION_ICONS.get(connection));
        }
    }
}
Also used : Connection(mcjty.rftoolscontrol.logic.Connection) Opcode(mcjty.rftoolscontrol.api.code.Opcode)

Aggregations

Opcode (mcjty.rftoolscontrol.api.code.Opcode)14 ParameterDescription (mcjty.rftoolscontrol.api.parameters.ParameterDescription)8 Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)6 IIcon (mcjty.lib.gui.icons.IIcon)4 GridInstance (mcjty.rftoolscontrol.logic.grid.GridInstance)4 ParameterValue (mcjty.rftoolscontrol.api.parameters.ParameterValue)3 Panel (mcjty.lib.gui.widgets.Panel)2 Connection (mcjty.rftoolscontrol.logic.Connection)2 GridPos (mcjty.rftoolscontrol.logic.grid.GridPos)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 List (java.util.List)1 ImageIcon (mcjty.lib.gui.icons.ImageIcon)1 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 ProgramCardInstance (mcjty.rftoolscontrol.logic.grid.ProgramCardInstance)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Pair (org.apache.commons.lang3.tuple.Pair)1