Search in sources :

Example 26 with Button

use of mcjty.lib.gui.widgets.Button in project RFToolsControl by McJty.

the class GuiCraftingStation method initButtons.

private void initButtons(Panel toplevel) {
    searchField = new TextField(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(5, 5, WIDTH - 46 - 10, 16));
    cancelButton = new Button(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(WIDTH - 46 - 5, 5, 46, 16)).setText("Cancel").setTooltips(TextFormatting.YELLOW + "Cancel request", "Cancel the currently selected", "crafting request").addButtonEvent((widget -> cancelRequest()));
    toplevel.addChild(cancelButton).addChild(searchField);
}
Also used : Button(mcjty.lib.gui.widgets.Button) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) TextField(mcjty.lib.gui.widgets.TextField)

Example 27 with Button

use of mcjty.lib.gui.widgets.Button in project RFToolsControl by McJty.

the class GuiTools method askSomething.

public static void askSomething(Minecraft mc, Gui gui, WindowManager windowManager, int x, int y, String title, String initialValue, Consumer<String> callback) {
    Panel ask = new Panel(mc, gui).setLayout(new VerticalLayout()).setFilledBackground(0xff666666, 0xffaaaaaa).setFilledRectThickness(1);
    ask.setBounds(new Rectangle(x, y, 100, 60));
    Window askWindow = windowManager.createModalWindow(ask);
    ask.addChild(new Label(mc, gui).setText(title));
    TextField input = new mcjty.lib.gui.widgets.TextField(mc, gui).addTextEnterEvent(((parent, newText) -> {
        windowManager.closeWindow(askWindow);
        callback.accept(newText);
    }));
    input.setText(initialValue);
    ask.addChild(input);
    Panel buttons = new Panel(mc, gui).setLayout(new HorizontalLayout()).setDesiredWidth(100).setDesiredHeight(18);
    buttons.addChild(new Button(mc, gui).setText("Ok").addButtonEvent((parent -> {
        windowManager.closeWindow(askWindow);
        callback.accept(input.getText());
    })));
    buttons.addChild(new Button(mc, gui).setText("Cancel").addButtonEvent((parent -> {
        windowManager.closeWindow(askWindow);
    })));
    ask.addChild(buttons);
}
Also used : Window(mcjty.lib.gui.Window) Window(mcjty.lib.gui.Window) java.awt(java.awt) Consumer(java.util.function.Consumer) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) TextField(mcjty.lib.gui.widgets.TextField) Gui(net.minecraft.client.gui.Gui) Panel(mcjty.lib.gui.widgets.Panel) Minecraft(net.minecraft.client.Minecraft) Button(mcjty.lib.gui.widgets.Button) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) Label(mcjty.lib.gui.widgets.Label) WindowManager(mcjty.lib.gui.WindowManager) Panel(mcjty.lib.gui.widgets.Panel) TextField(mcjty.lib.gui.widgets.TextField) Button(mcjty.lib.gui.widgets.Button) Label(mcjty.lib.gui.widgets.Label) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) TextField(mcjty.lib.gui.widgets.TextField) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout)

Example 28 with Button

use of mcjty.lib.gui.widgets.Button in project XNet by McJty.

the class GuiController method populateList.

private void populateList() {
    if (!listsReady()) {
        return;
    }
    if (!needsRefresh) {
        return;
    }
    needsRefresh = false;
    connectorList.removeChildren();
    int sel = connectorList.getSelected();
    BlockPos prevPos = null;
    String selectedText = searchBar.getText().trim().toLowerCase();
    for (ConnectedBlockClientInfo connectedBlock : fromServer_connectedBlocks) {
        SidedPos sidedPos = connectedBlock.getPos();
        BlockPos coordinate = sidedPos.getPos();
        String name = connectedBlock.getName();
        String blockUnlocName = connectedBlock.getBlockUnlocName();
        String blockName = I18n.format(blockUnlocName).trim();
        int color = StyleConfig.colorTextInListNormal;
        Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout().setHorizontalMargin(0).setSpacing(0));
        if (!selectedText.isEmpty()) {
            if (blockName.toLowerCase().contains(selectedText)) {
                panel.setFilledBackground(0xffddeeaa);
            }
        }
        BlockRender br;
        if (coordinate.equals(prevPos)) {
            br = new BlockRender(mc, this);
        } else {
            br = new BlockRender(mc, this).setRenderItem(connectedBlock.getConnectedBlock());
            prevPos = coordinate;
        }
        br.setUserObject("block");
        panel.addChild(br);
        if (!name.isEmpty()) {
            br.setTooltips(TextFormatting.GREEN + "Connector: " + TextFormatting.WHITE + name, TextFormatting.GREEN + "Block: " + TextFormatting.WHITE + blockName, TextFormatting.GREEN + "Position: " + TextFormatting.WHITE + BlockPosTools.toString(coordinate), TextFormatting.WHITE + "(doubleclick to highlight)");
        } else {
            br.setTooltips(TextFormatting.GREEN + "Block: " + TextFormatting.WHITE + blockName, TextFormatting.GREEN + "Position: " + TextFormatting.WHITE + BlockPosTools.toString(coordinate), TextFormatting.WHITE + "(doubleclick to highlight)");
        }
        panel.addChild(new Label(mc, this).setText(sidedPos.getSide().getName().substring(0, 1).toUpperCase()).setColor(color).setDesiredWidth(18));
        for (int i = 0; i < MAX_CHANNELS; i++) {
            Button but = new Button(mc, this).setDesiredWidth(14);
            ChannelClientInfo info = fromServer_channels.get(i);
            if (info != null) {
                ConnectorClientInfo clientInfo = findClientInfo(info, sidedPos);
                if (clientInfo != null) {
                    IndicatorIcon icon = clientInfo.getConnectorSettings().getIndicatorIcon();
                    if (icon != null) {
                        but.setImage(icon.getImage(), icon.getU(), icon.getV(), icon.getIw(), icon.getIh());
                    }
                    String indicator = clientInfo.getConnectorSettings().getIndicator();
                    but.setText(indicator != null ? indicator : "");
                }
            }
            int finalI = i;
            but.addButtonEvent(parent -> {
                selectConnectorEditor(sidedPos, finalI);
            });
            panel.addChild(but);
        }
        connectorList.addChild(panel);
    }
    connectorList.setSelected(sel);
}
Also used : Label(mcjty.lib.gui.widgets.Label) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Panel(mcjty.lib.gui.widgets.Panel) ConnectedBlockClientInfo(mcjty.xnet.clientinfo.ConnectedBlockClientInfo) ChannelClientInfo(mcjty.xnet.clientinfo.ChannelClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) Button(mcjty.lib.gui.widgets.Button) BlockPos(net.minecraft.util.math.BlockPos) IndicatorIcon(mcjty.xnet.api.gui.IndicatorIcon) ConnectorClientInfo(mcjty.xnet.clientinfo.ConnectorClientInfo)

Example 29 with Button

use of mcjty.lib.gui.widgets.Button in project XNet by McJty.

the class GuiController method refreshChannelEditor.

private void refreshChannelEditor() {
    if (!listsReady()) {
        return;
    }
    if (editingChannel != -1 && showingChannel != editingChannel) {
        showingChannel = editingChannel;
        channelButtons[editingChannel].setPressed(true);
        channelEditPanel.removeChildren();
        if (channelButtons[editingChannel].isPressed()) {
            ChannelClientInfo info = fromServer_channels.get(editingChannel);
            if (info != null) {
                ChannelEditorPanel editor = new ChannelEditorPanel(channelEditPanel, mc, this, editingChannel);
                editor.label("Channel " + (editingChannel + 1)).shift(5).toggle(TAG_ENABLED, "Enable processing on this channel", info.isEnabled()).shift(5).text(TAG_NAME, "Channel name", info.getChannelName(), 65);
                info.getChannelSettings().createGui(editor);
                Button remove = new Button(mc, this).setText("x").setTextOffset(0, -1).setTooltips("Remove this channel").setLayoutHint(new PositionalLayout.PositionalHint(151, 1, 9, 10)).addButtonEvent(parent -> removeChannel());
                channelEditPanel.addChild(remove);
                editor.setState(info.getChannelSettings());
            } else {
                ChoiceLabel type = new ChoiceLabel(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(5, 12, 95, 14));
                for (IChannelType channelType : XNet.xNetApi.getChannels().values()) {
                    // Show names?
                    type.addChoices(channelType.getID());
                }
                Button create = new Button(mc, this).setText("Create").setLayoutHint(new PositionalLayout.PositionalHint(100, 12, 53, 14)).addButtonEvent(parent -> createChannel(type.getCurrentChoice()));
                channelEditPanel.addChild(type).addChild(create);
            }
        }
    } else if (showingChannel != -1 && editingChannel == -1) {
        showingChannel = -1;
        channelEditPanel.removeChildren();
    }
}
Also used : ChannelClientInfo(mcjty.xnet.clientinfo.ChannelClientInfo) Button(mcjty.lib.gui.widgets.Button) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) IChannelType(mcjty.xnet.api.channels.IChannelType)

Example 30 with Button

use of mcjty.lib.gui.widgets.Button in project XNet by McJty.

the class GuiController method refreshConnectorEditor.

private void refreshConnectorEditor() {
    if (!listsReady()) {
        return;
    }
    if (editingConnector != null && !editingConnector.equals(showingConnector)) {
        showingConnector = editingConnector;
        connectorEditPanel.removeChildren();
        ChannelClientInfo info = fromServer_channels.get(editingChannel);
        if (info != null) {
            ConnectorClientInfo clientInfo = findClientInfo(info, editingConnector);
            if (clientInfo != null) {
                EnumFacing side = clientInfo.getPos().getSide();
                SidedConsumer sidedConsumer = new SidedConsumer(clientInfo.getConsumerId(), side.getOpposite());
                ConnectorClientInfo connectorInfo = info.getConnectors().get(sidedConsumer);
                Button remove = new Button(mc, this).setText("x").setTextOffset(0, -1).setTooltips("Remove this connector").setLayoutHint(new PositionalLayout.PositionalHint(151, 1, 9, 10)).addButtonEvent(parent -> removeConnector(editingConnector));
                ConnectorEditorPanel editor = new ConnectorEditorPanel(connectorEditPanel, mc, this, editingChannel, editingConnector);
                connectorInfo.getConnectorSettings().createGui(editor);
                connectorEditPanel.addChild(remove);
                editor.setState(connectorInfo.getConnectorSettings());
            } else {
                Button create = new Button(mc, this).setText("Create").setLayoutHint(new PositionalLayout.PositionalHint(85, 20, 60, 14)).addButtonEvent(parent -> createConnector(editingConnector));
                connectorEditPanel.addChild(create);
            }
        }
    } else if (showingConnector != null && editingConnector == null) {
        showingConnector = null;
        connectorEditPanel.removeChildren();
    }
}
Also used : ChannelClientInfo(mcjty.xnet.clientinfo.ChannelClientInfo) Button(mcjty.lib.gui.widgets.Button) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) EnumFacing(net.minecraft.util.EnumFacing) ConnectorClientInfo(mcjty.xnet.clientinfo.ConnectorClientInfo)

Aggregations

Button (mcjty.lib.gui.widgets.Button)30 Panel (mcjty.lib.gui.widgets.Panel)27 Window (mcjty.lib.gui.Window)24 Label (mcjty.lib.gui.widgets.Label)24 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)17 VerticalLayout (mcjty.lib.gui.layout.VerticalLayout)17 PositionalLayout (mcjty.lib.gui.layout.PositionalLayout)15 java.awt (java.awt)14 TextField (mcjty.lib.gui.widgets.TextField)14 mcjty.lib.gui.widgets (mcjty.lib.gui.widgets)13 ResourceLocation (net.minecraft.util.ResourceLocation)11 GenericGuiContainer (mcjty.lib.container.GenericGuiContainer)10 List (java.util.List)9 RFTools (mcjty.rftools.RFTools)9 HorizontalAlignment (mcjty.lib.gui.layout.HorizontalAlignment)8 Argument (mcjty.lib.network.Argument)8 RFToolsMessages (mcjty.rftools.network.RFToolsMessages)8 StyleConfig (mcjty.lib.base.StyleConfig)7 GenericEnergyStorageTileEntity (mcjty.lib.entity.GenericEnergyStorageTileEntity)7 IOException (java.io.IOException)6