Search in sources :

Example 1 with Connection

use of mcjty.rftoolscontrol.logic.Connection in project RFToolsControl by McJty.

the class GuiProgrammer method handleConnectorHighlight.

private void handleConnectorHighlight(int finalX, int finalY, IIcon iIcon, int dx, int dy) {
    if (prevHighlightConnector != null) {
        IconHolder h = getHolder(prevHighlightConnector.getX(), prevHighlightConnector.getY());
        if (h.getIcon() != null) {
            h.getIcon().removeOverlay("H");
        }
        prevHighlightConnector = null;
    }
    if (iIcon == null) {
        return;
    }
    iIcon.removeOverlay("H");
    Connection connection = getConnectionHandle(dx, dy);
    if (connection != null) {
        iIcon.addOverlay(HIGHLIGHT_ICONS.get(connection));
        prevHighlightConnector = new GridPos(finalX, finalY);
    }
}
Also used : GridPos(mcjty.rftoolscontrol.logic.grid.GridPos) Connection(mcjty.rftoolscontrol.logic.Connection)

Example 2 with Connection

use of mcjty.rftoolscontrol.logic.Connection in project RFToolsControl by McJty.

the class GuiProgrammer method makeGridInstance.

private ProgramCardInstance makeGridInstance(boolean selectionOnly) {
    ProgramCardInstance instance = ProgramCardInstance.newInstance();
    for (int x = 0; x < GRID_WIDTH; x++) {
        for (int y = 0; y < GRID_HEIGHT; y++) {
            IconHolder holder = getHolder(x, y);
            IIcon icon = holder.getIcon();
            if (icon != null) {
                if (selectionOnly && !icon.hasOverlay("S")) {
                    continue;
                }
                String operandId = icon.getID();
                GridInstance.Builder builder = GridInstance.builder(operandId);
                for (Connection connection : Connection.values()) {
                    if (icon.hasOverlay(connection.getId())) {
                        if (connection.isPrimary()) {
                            builder.primaryConnection(connection);
                        } else {
                            builder.secondaryConnection(connection);
                        }
                    }
                }
                Opcode opcode = Opcodes.OPCODES.get(operandId);
                Map<String, Object> data = icon.getData();
                for (ParameterDescription description : opcode.getParameters()) {
                    ParameterValue value = data == null ? null : (ParameterValue) data.get(description.getName());
                    if (value == null) {
                        value = ParameterValue.constant(null);
                    }
                    Parameter parameter = Parameter.builder().type(description.getType()).value(value).build();
                    builder.parameter(parameter);
                }
                instance.putGridInstance(x, y, builder.build());
            }
        }
    }
    return instance;
}
Also used : ParameterValue(mcjty.rftoolscontrol.api.parameters.ParameterValue) IIcon(mcjty.lib.gui.icons.IIcon) Connection(mcjty.rftoolscontrol.logic.Connection) Opcode(mcjty.rftoolscontrol.api.code.Opcode) ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) GridInstance(mcjty.rftoolscontrol.logic.grid.GridInstance) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription)

Example 3 with Connection

use of mcjty.rftoolscontrol.logic.Connection in project RFToolsControl by McJty.

the class GuiProgrammer method gridIconClicked.

private void gridIconClicked(IIcon icon, int x, int y, int dx, int dy) {
    if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) {
        long time = System.currentTimeMillis();
        boolean doubleclick = false;
        if (prevTime != -1L && time - prevTime < 250L) {
            doubleclick = true;
        }
        prevTime = time;
        if (icon.hasOverlay("S")) {
            if (doubleclick) {
                // Reverse because first click also did something
                selectSequence(new GridPos(x, y), new HashSet<>(), true);
            } else {
                icon.removeOverlay("S");
            }
        } else {
            if (doubleclick) {
                // Reverse because first click also did something
                selectSequence(new GridPos(x, y), new HashSet<>(), false);
            } else {
                icon.addOverlay(selectionIcon);
            }
        }
        return;
    }
    clearSelection();
    long time = System.currentTimeMillis();
    boolean doubleclick = !GeneralConfiguration.doubleClickToChangeConnector;
    if (prevTime != -1L && time - prevTime < 250L) {
        doubleclick = true;
    }
    prevTime = time;
    if (doubleclick) {
        Connection connection = getConnectionHandle(dx, dy);
        if (connection != null) {
            handleIconOverlay(icon, connection);
        }
    }
}
Also used : GridPos(mcjty.rftoolscontrol.logic.grid.GridPos) Connection(mcjty.rftoolscontrol.logic.Connection)

Example 4 with Connection

use of mcjty.rftoolscontrol.logic.Connection 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

Connection (mcjty.rftoolscontrol.logic.Connection)4 Opcode (mcjty.rftoolscontrol.api.code.Opcode)2 GridPos (mcjty.rftoolscontrol.logic.grid.GridPos)2 IIcon (mcjty.lib.gui.icons.IIcon)1 Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)1 ParameterDescription (mcjty.rftoolscontrol.api.parameters.ParameterDescription)1 ParameterValue (mcjty.rftoolscontrol.api.parameters.ParameterValue)1 GridInstance (mcjty.rftoolscontrol.logic.grid.GridInstance)1 ProgramCardInstance (mcjty.rftoolscontrol.logic.grid.ProgramCardInstance)1