Search in sources :

Example 6 with Parameter

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

the class GuiProgrammer method loadGridInstance.

private void loadGridInstance(Map.Entry<GridPos, GridInstance> entry, int x, int y) {
    GridInstance gridInstance = entry.getValue();
    IIcon icon = ICONS.get(gridInstance.getId());
    if (icon == null) {
        // Ignore missing icon
        Logging.logError("Opcode with id '" + gridInstance.getId() + "' is missing!");
        return;
    }
    icon = icon.clone();
    if (gridInstance.getPrimaryConnection() != null) {
        icon.addOverlay(CONNECTION_ICONS.get(gridInstance.getPrimaryConnection()));
    }
    if (gridInstance.getSecondaryConnection() != null) {
        icon.addOverlay(CONNECTION_ICONS.get(gridInstance.getSecondaryConnection()));
    }
    Opcode opcode = Opcodes.OPCODES.get(icon.getID());
    List<Parameter> parameters = gridInstance.getParameters();
    for (int i = 0; i < parameters.size(); i++) {
        String name = opcode.getParameters().get(i).getName();
        icon.addData(name, parameters.get(i).getParameterValue());
    }
    loading = true;
    getHolder(x, y).setIcon(icon);
    loading = false;
}
Also used : GridInstance(mcjty.rftoolscontrol.logic.grid.GridInstance) IIcon(mcjty.lib.gui.icons.IIcon) Opcode(mcjty.rftoolscontrol.api.code.Opcode) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter)

Example 7 with Parameter

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

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

the class Commands method handleDebugCommand.

private static void handleDebugCommand(ProcessorTileEntity processor, String[] splitted) {
    List<CpuCore> cores = processor.getCpuCores();
    String sub = splitted[1].toLowerCase();
    if ("debug".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int core = Integer.parseInt(splitted[2]);
                cores.get(core).setDebug(true);
                processor.log(TextFormatting.YELLOW + "Debug mode for core: " + core);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            for (CpuCore core : cores) {
                core.setDebug(true);
            }
            processor.log(TextFormatting.YELLOW + "Debug mode for all cores");
        }
    } else if ("resume".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int core = Integer.parseInt(splitted[2]);
                cores.get(core).setDebug(false);
                processor.log(TextFormatting.YELLOW + "Resume core: " + core);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            for (CpuCore core : cores) {
                core.setDebug(false);
            }
            processor.log(TextFormatting.YELLOW + "Resume all cores");
        }
    } else if ("info".equals(sub)) {
        for (int i = 0; i < cores.size(); i++) {
            CpuCore core = cores.get(i);
            if (core.isDebug()) {
                RunningProgram program = core.getProgram();
                if (program == null) {
                    processor.log("Core " + i + ": " + "not running");
                } else {
                    showCurrent(processor, i, program);
                }
            }
        }
    } else if ("last".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int i = Integer.parseInt(splitted[2]);
                CpuCore core = cores.get(i);
                if (core.hasProgram()) {
                    Parameter value = core.getProgram().getLastValue();
                    if (value == null || value.getParameterValue() == null) {
                        processor.log(TextFormatting.YELLOW + "Last value not set");
                    } else {
                        ParameterType type = value.getParameterType();
                        processor.log(TextFormatting.YELLOW + "Last " + type.getName() + ": " + TypeConverters.convertToString(value));
                    }
                } else {
                    processor.log(TextFormatting.YELLOW + "No program!");
                }
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            int i = 0;
            for (CpuCore core : cores) {
                if (core.hasProgram()) {
                    Parameter value = core.getProgram().getLastValue();
                    if (value == null || value.getParameterValue() == null) {
                        processor.log(TextFormatting.YELLOW + "" + i + ": Last value not set");
                    } else {
                        ParameterType type = value.getParameterType();
                        processor.log(TextFormatting.YELLOW + "" + i + ": Last " + type.getName() + ": " + TypeConverters.convertToString(value));
                    }
                }
                i++;
            }
        }
    } else if ("step".equals(sub) || "s".equals(sub)) {
        int cnt = 0;
        for (CpuCore core : cores) {
            if (core.isDebug()) {
                cnt++;
            }
        }
        int c = 0;
        if (cnt == 0) {
            processor.log(TextFormatting.RED + "Not debugging");
            return;
        } else if (cnt > 1) {
            if (splitted.length <= 2) {
                processor.log(TextFormatting.RED + "Missing core number");
                return;
            }
            try {
                c = Integer.parseInt(splitted[2]);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        }
        CpuCore core = cores.get(c);
        RunningProgram program = core.getProgram();
        if (program == null) {
            processor.log(TextFormatting.RED + "Core " + c + ": " + "not running");
            return;
        }
        core.step(processor);
        showCurrent(processor, c, program);
    } else {
        processor.log("Unknown 'db' command!");
    }
}
Also used : ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType) CpuCore(mcjty.rftoolscontrol.logic.running.CpuCore) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) RunningProgram(mcjty.rftoolscontrol.logic.running.RunningProgram)

Example 9 with Parameter

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

the class GuiProcessor method openValueEditor.

private void openValueEditor(int varIdx) {
    if (fromServer_vars == null || varIdx > fromServer_vars.size()) {
        return;
    }
    if (fromServer_vars.get(varIdx) == null) {
        GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, "Variable is not defined!");
        return;
    }
    Parameter parameter = fromServer_vars.get(varIdx);
    if (parameter == null) {
        GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, "Variable is not defined!");
        return;
    }
    ParameterType type = parameter.getParameterType();
    ParameterEditor editor = ParameterEditors.getEditor(type);
    Panel editPanel;
    if (editor != null) {
        editPanel = new Panel(mc, this).setLayout(new PositionalLayout()).setFilledRectThickness(1);
        editor.build(mc, this, editPanel, o -> {
            NBTTagCompound tag = new NBTTagCompound();
            ParameterTypeTools.writeToNBT(tag, type, o);
            RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketVariableToServer(tileEntity.getPos(), varIdx, tag));
        });
        editor.writeValue(parameter.getParameterValue());
        editor.constantOnly();
    } else {
        return;
    }
    Panel panel = new Panel(mc, this).setLayout(new VerticalLayout()).setFilledBackground(0xff666666, 0xffaaaaaa).setFilledRectThickness(1);
    panel.setBounds(new Rectangle(50, 50, 200, 60 + editor.getHeight()));
    Window modalWindow = getWindowManager().createModalWindow(panel);
    panel.addChild(new Label(mc, this).setText("Var " + varIdx + ":"));
    panel.addChild(editPanel);
    panel.addChild(new Button(mc, this).addButtonEvent(w -> {
        getWindowManager().closeWindow(modalWindow);
    }).setText("Close"));
}
Also used : Window(mcjty.lib.gui.Window) Panel(mcjty.lib.gui.widgets.Panel) ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType) Button(mcjty.lib.gui.widgets.Button) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Label(mcjty.lib.gui.widgets.Label) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) ParameterEditor(mcjty.rftoolscontrol.logic.editors.ParameterEditor)

Example 10 with Parameter

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

the class VariableClientScreenModule method render.

@Override
public void render(IModuleRenderHelper renderHelper, FontRenderer fontRenderer, int currenty, ModuleDataVariable screenData, ModuleRenderInfo renderInfo) {
    if (labelCache == null) {
        labelCache = renderHelper.createTextRenderHelper().align(textAlign);
    }
    GlStateManager.disableLighting();
    int xoffset;
    if (!line.isEmpty()) {
        labelCache.setup(line, 160, renderInfo);
        labelCache.renderText(0, currenty, color, renderInfo);
        xoffset = 7 + 40;
    } else {
        xoffset = 7;
    }
    if (screenData != null) {
        Parameter parameter = screenData.getParameter();
        if (parameter != null && parameter.getParameterValue() != null) {
            String str = TypeConverters.convertToString(parameter);
            renderHelper.renderText(xoffset, currenty, varcolor, renderInfo, str);
        }
    }
}
Also used : Parameter(mcjty.rftoolscontrol.api.parameters.Parameter)

Aggregations

Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)15 Opcode (mcjty.rftoolscontrol.api.code.Opcode)7 ParameterDescription (mcjty.rftoolscontrol.api.parameters.ParameterDescription)6 GridInstance (mcjty.rftoolscontrol.logic.grid.GridInstance)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 IIcon (mcjty.lib.gui.icons.IIcon)3 GridPos (mcjty.rftoolscontrol.logic.grid.GridPos)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 Window (mcjty.lib.gui.Window)2 PositionalLayout (mcjty.lib.gui.layout.PositionalLayout)2 VerticalLayout (mcjty.lib.gui.layout.VerticalLayout)2 Button (mcjty.lib.gui.widgets.Button)2 Label (mcjty.lib.gui.widgets.Label)2 Panel (mcjty.lib.gui.widgets.Panel)2 ParameterType (mcjty.rftoolscontrol.api.parameters.ParameterType)2 ParameterValue (mcjty.rftoolscontrol.api.parameters.ParameterValue)2 Connection (mcjty.rftoolscontrol.logic.Connection)2 ParameterEditor (mcjty.rftoolscontrol.logic.editors.ParameterEditor)2 ProgramCardInstance (mcjty.rftoolscontrol.logic.grid.ProgramCardInstance)2