Search in sources :

Example 1 with ParameterEditor

use of mcjty.rftoolscontrol.logic.editors.ParameterEditor in project RFToolsControl by McJty.

the class GuiProgrammer method openValueEditor.

private void openValueEditor(IIcon icon, IconHolder iconHolder, ParameterDescription parameter, TextField field, boolean constantOnly) {
    ParameterEditor editor = ParameterEditors.getEditor(parameter.getType());
    Panel editPanel;
    if (editor != null) {
        editPanel = new Panel(mc, this).setLayout(new PositionalLayout()).setFilledRectThickness(1);
        Map<String, Object> data = icon.getData() == null ? Collections.emptyMap() : icon.getData();
        editor.build(mc, this, editPanel, o -> {
            icon.addData(parameter.getName(), o);
            field.setText(ParameterTypeTools.stringRepresentation(parameter.getType(), o));
        });
        editor.writeValue((ParameterValue) data.get(parameter.getName()));
        if (constantOnly) {
            editor.constantOnly();
        }
    } else {
        return;
    }
    Panel panel = new Panel(mc, this).setLayout(new VerticalLayout()).setFilledBackground(0xff666666, 0xffaaaaaa).setFilledRectThickness(1);
    panel.setBounds(new Rectangle(50, 25, 200, 60 + editor.getHeight()));
    Window modalWindow = getWindowManager().createModalWindow(panel);
    panel.addChild(new Label(mc, this).setText(StringUtils.capitalize(parameter.getName()) + ":"));
    panel.addChild(editPanel);
    panel.addChild(new Button(mc, this).addButtonEvent(w -> {
        getWindowManager().closeWindow(modalWindow);
        window.setTextFocus(iconHolder);
    }).setText("Close"));
    editor.initialFocus(modalWindow);
    editor.setOnClose(() -> window.setTextFocus(iconHolder));
}
Also used : Window(mcjty.lib.gui.Window) Panel(mcjty.lib.gui.widgets.Panel) Button(mcjty.lib.gui.widgets.Button) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) Label(mcjty.lib.gui.widgets.Label) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) ParameterEditor(mcjty.rftoolscontrol.logic.editors.ParameterEditor)

Example 2 with ParameterEditor

use of mcjty.rftoolscontrol.logic.editors.ParameterEditor 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)

Aggregations

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 ParameterEditor (mcjty.rftoolscontrol.logic.editors.ParameterEditor)2 Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)1 ParameterType (mcjty.rftoolscontrol.api.parameters.ParameterType)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1