Search in sources :

Example 6 with CircleButtonWidget

use of gregtech.api.terminal.gui.widgets.CircleButtonWidget in project GregTech by GregTechCEu.

the class TerminalDialogWidget method addConfirmButton.

public TerminalDialogWidget addConfirmButton(Consumer<Boolean> result) {
    addWidget(new CircleButtonWidget(WIDTH / 2 - 30, HEIGHT - 22, 12, 0, 24).setClickListener(cd -> {
        close();
        if (result != null)
            result.accept(true);
    }).setColors(0, 0, 0).setIcon(OK_NORMAL).setHoverIcon(OK_HOVER));
    addWidget(new CircleButtonWidget(WIDTH / 2 + 30, HEIGHT - 22, 12, 0, 24).setClickListener(cd -> {
        close();
        if (result != null)
            result.accept(false);
    }).setColors(0, 0, 0).setIcon(CANCEL_NORMAL).setHoverIcon(CANCEL_HOVER));
    return this;
}
Also used : CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget)

Example 7 with CircleButtonWidget

use of gregtech.api.terminal.gui.widgets.CircleButtonWidget in project GregTech by GregTechCEu.

the class TerminalDialogWidget method showFileDialog.

/**
 * Show FileDialog
 * @param dir root directory
 * @param isSelector select a file or save a file
 * @param result selected file or (saved)
 */
public static TerminalDialogWidget showFileDialog(TerminalOSWidget os, String title, File dir, boolean isSelector, Consumer<File> result) {
    Size size = os.getSize();
    TerminalDialogWidget dialog = new TerminalDialogWidget(os, 0, 0, size.width, size.height).setBackground(new ColorRectTexture(0x4f000000));
    if (!dir.isDirectory()) {
        if (!dir.mkdirs()) {
            return dialog.addInfo(I18n.format("terminal.dialog.error_path") + dir.getPath()).addOkButton(null);
        }
    }
    AtomicReference<File> selected = new AtomicReference<>();
    selected.set(dir);
    dialog.addWidget(new TreeListWidget<>(0, 0, 130, size.height, new FileTree(dir), node -> selected.set(node.getKey())).setNodeTexture(GuiTextures.BORDERED_BACKGROUND).canSelectNode(true).setLeafTexture(GuiTextures.SLOT_DARKENED));
    int x = 130 + (size.width - 133 - WIDTH) / 2;
    int y = (size.height - HEIGHT) / 2;
    dialog.addWidget(new ImageWidget(x, y, WIDTH, HEIGHT, DIALOG_BACKGROUND));
    dialog.addWidget(new CircleButtonWidget(x + WIDTH / 2 - 30, y + HEIGHT - 22, 12, 0, 24).setClickListener(cd -> {
        dialog.close();
        if (result != null)
            result.accept(selected.get());
    }).setColors(0, 0, 0).setIcon(OK_NORMAL).setHoverIcon(OK_HOVER));
    dialog.addWidget(new CircleButtonWidget(x + WIDTH / 2 + 30, y + HEIGHT - 22, 12, 0, 24).setClickListener(cd -> {
        dialog.close();
        if (result != null)
            result.accept(null);
    }).setColors(0, 0, 0).setIcon(CANCEL_NORMAL).setHoverIcon(CANCEL_HOVER));
    if (isSelector) {
        dialog.addWidget(new SimpleTextWidget(x + WIDTH / 2, y + HEIGHT / 2 - 5, "", -1, () -> {
            if (selected.get() != null) {
                return selected.get().toString();
            }
            return "terminal.dialog.no_file_selected";
        }, true).setWidth(WIDTH - 16));
    } else {
        dialog.addWidget(new TextFieldWidget(x + WIDTH / 2 - 38, y + HEIGHT / 2 - 10, 76, 20, new ColorRectTexture(0x4f000000), null, null).setTextResponder(res -> {
            File file = selected.get();
            if (file == null)
                return;
            if (file.isDirectory()) {
                selected.set(new File(file, res));
            } else {
                selected.set(new File(file.getParent(), res));
            }
        }, true).setTextSupplier(() -> {
            File file = selected.get();
            if (file != null && !file.isDirectory()) {
                return selected.get().getName();
            }
            return "";
        }, true).setMaxStringLength(Integer.MAX_VALUE).setValidator(s -> true));
    }
    dialog.addWidget(new CircleButtonWidget(x + 17, y + 15, 10, 1, 16).setClickListener(cd -> {
        File file = selected.get();
        if (file != null) {
            try {
                Desktop.getDesktop().open(file.isDirectory() ? file : file.getParentFile());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).setColors(0, 0xFFFFFFFF, 0).setHoverText("terminal.dialog.folder").setIcon(GuiTextures.ICON_LOAD));
    dialog.addWidget(new LabelWidget(x + WIDTH / 2, y + 11, title, -1).setXCentered(true));
    if (os.isRemote()) {
        os.menu.hideMenu();
    }
    return dialog.setClientSide();
}
Also used : IRenderContext(gregtech.api.gui.IRenderContext) Size(gregtech.api.util.Size) AnimaWidgetGroup(gregtech.api.terminal.gui.widgets.AnimaWidgetGroup) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) Widget(gregtech.api.gui.Widget) gregtech.api.gui.widgets(gregtech.api.gui.widgets) TreeListWidget(gregtech.api.terminal.gui.widgets.TreeListWidget) Predicate(java.util.function.Predicate) GlStateManager(net.minecraft.client.renderer.GlStateManager) ColorRectTexture(gregtech.api.gui.resources.ColorRectTexture) IOException(java.io.IOException) GuiTextures(gregtech.api.gui.GuiTextures) File(java.io.File) ColorWidget(gregtech.api.terminal.gui.widgets.ColorWidget) java.awt(java.awt) Consumer(java.util.function.Consumer) Position(gregtech.api.util.Position) List(java.util.List) TextureArea(gregtech.api.gui.resources.TextureArea) IInventory(net.minecraft.inventory.IInventory) IGuiTexture(gregtech.api.gui.resources.IGuiTexture) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) FileTree(gregtech.api.terminal.util.FileTree) PacketBuffer(net.minecraft.network.PacketBuffer) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) Size(gregtech.api.util.Size) ColorRectTexture(gregtech.api.gui.resources.ColorRectTexture) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) TreeListWidget(gregtech.api.terminal.gui.widgets.TreeListWidget) FileTree(gregtech.api.terminal.util.FileTree) File(java.io.File)

Aggregations

CircleButtonWidget (gregtech.api.terminal.gui.widgets.CircleButtonWidget)7 Position (gregtech.api.util.Position)4 IRenderContext (gregtech.api.gui.IRenderContext)3 Widget (gregtech.api.gui.Widget)3 TerminalDialogWidget (gregtech.api.terminal.os.TerminalDialogWidget)3 TerminalTheme (gregtech.api.terminal.os.TerminalTheme)3 ItemStack (net.minecraft.item.ItemStack)3 GuiTextures (gregtech.api.gui.GuiTextures)2 ColorRectTexture (gregtech.api.gui.resources.ColorRectTexture)2 gregtech.api.gui.widgets (gregtech.api.gui.widgets)2 WidgetGroup (gregtech.api.gui.widgets.WidgetGroup)2 ColorWidget (gregtech.api.terminal.gui.widgets.ColorWidget)2 RectButtonWidget (gregtech.api.terminal.gui.widgets.RectButtonWidget)2 TerminalOSWidget (gregtech.api.terminal.os.TerminalOSWidget)2 Size (gregtech.api.util.Size)2 Consumer (java.util.function.Consumer)2 GlStateManager (net.minecraft.client.renderer.GlStateManager)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 MachineItemBlock (gregtech.api.block.machines.MachineItemBlock)1 ModularUIContainer (gregtech.api.gui.impl.ModularUIContainer)1