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;
}
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();
}
Aggregations