Search in sources :

Example 1 with ParameterValue

use of mcjty.rftoolscontrol.api.parameters.ParameterValue 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 2 with ParameterValue

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

the class GuiProgrammer method getIconTooltipGrid.

private List<String> getIconTooltipGrid(int x, int y) {
    IconHolder holder = getHolder(x, y);
    IIcon icon = holder.getIcon();
    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.add(description.get(0) + TextFormatting.WHITE + " [" + x + "," + y + "]");
            Map<String, Object> data = icon.getData() == null ? Collections.emptyMap() : icon.getData();
            for (ParameterDescription parameter : opcode.getParameters()) {
                String name = parameter.getName();
                ParameterValue value = (ParameterValue) data.get(name);
                if (value != null) {
                    tooltips.add(TextFormatting.BLUE + "Par " + name + ": " + ParameterTypeTools.stringRepresentation(parameter.getType(), value));
                } else {
                    tooltips.add(TextFormatting.BLUE + "Par " + name + ": NULL");
                }
            }
        } else {
            tooltips.add(description.get(0));
            tooltips.add("<Shift for more info>");
        }
        return tooltips;
    }
    return Collections.emptyList();
}
Also used : ParameterValue(mcjty.rftoolscontrol.api.parameters.ParameterValue) IIcon(mcjty.lib.gui.icons.IIcon) Opcode(mcjty.rftoolscontrol.api.code.Opcode) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription)

Example 3 with ParameterValue

use of mcjty.rftoolscontrol.api.parameters.ParameterValue 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)

Aggregations

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