Search in sources :

Example 1 with ConfirmPopup

use of org.terasology.rendering.nui.layers.mainMenu.ConfirmPopup in project Terasology by MovingBlocks.

the class IdentityIOHelper method exportIdentities.

public void exportIdentities() {
    FilePickerPopup filePicker = nuiManager.pushScreen(FilePickerPopup.ASSET_URI, FilePickerPopup.class);
    filePicker.setTitle(exportPopupTitle);
    filePicker.setOkHandler(path -> {
        Runnable action = () -> {
            Map<PublicIdentityCertificate, ClientIdentity> identities = securityConfig.getAllIdentities();
            try (BufferedWriter writer = Files.newBufferedWriter(path, StandardOpenOption.CREATE)) {
                GSON.toJson(identities, MAP_TYPE, writer);
                nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage(exportPopupTitle, String.format(translationSystem.translate("${engine:menu#identity-export-ok}"), identities.size(), path.toString()));
            } catch (IOException | JsonIOException ex) {
                nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage(translationSystem.translate("${engine:menu#identity-export-fail}"), ex.toString());
            }
        };
        if (Files.exists(path)) {
            ConfirmPopup confirm = nuiManager.pushScreen(ConfirmPopup.ASSET_URI, ConfirmPopup.class);
            confirm.setMessage(exportPopupTitle, String.format(translationSystem.translate("${engine:menu#existing-file-warning}"), path.toString()));
            confirm.setOkHandler(action);
        } else {
            action.run();
        }
    });
}
Also used : ConfirmPopup(org.terasology.rendering.nui.layers.mainMenu.ConfirmPopup) MessagePopup(org.terasology.rendering.nui.layers.mainMenu.MessagePopup) FilePickerPopup(org.terasology.rendering.nui.layers.mainMenu.FilePickerPopup) Map(java.util.Map) BufferedWriter(java.io.BufferedWriter)

Example 2 with ConfirmPopup

use of org.terasology.rendering.nui.layers.mainMenu.ConfirmPopup in project Terasology by MovingBlocks.

the class AbstractEditorScreen method resetState.

/**
 * Resets the editor's state based on a specified {@link JsonTree}.
 *
 * @param node The {@link JsonTree} to reset the state from.
 */
protected void resetState(JsonTree node) {
    if (unsavedChangesPresent) {
        ConfirmPopup confirmPopup = getManager().pushScreen(ConfirmPopup.ASSET_URI, ConfirmPopup.class);
        confirmPopup.setMessage("Unsaved changes!", "It looks like you've been editing something!" + "\r\nAll unsaved changes will be lost. Continue anyway?");
        confirmPopup.setOkHandler(() -> {
            setUnsavedChangesPresent(false);
            deleteAutosave();
            resetStateInternal(node);
        });
    } else {
        resetStateInternal(node);
    }
}
Also used : ConfirmPopup(org.terasology.rendering.nui.layers.mainMenu.ConfirmPopup)

Example 3 with ConfirmPopup

use of org.terasology.rendering.nui.layers.mainMenu.ConfirmPopup in project Terasology by MovingBlocks.

the class SelectModulesScreen method startDownloadingNewestModulesRequiredFor.

private void startDownloadingNewestModulesRequiredFor(ModuleSelectionInfo moduleMetadata) {
    Set<Module> modulesToDownload;
    try {
        modulesToDownload = moduleManager.getInstallManager().getAllModulesToDownloadFor(moduleMetadata.getMetadata().getId());
    } catch (DependencyResolutionFailedException ex) {
        MessagePopup messagePopup = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
        messagePopup.setMessage("Error", ex.getMessage());
        return;
    }
    ConfirmPopup confirmPopup = getManager().pushScreen(ConfirmPopup.ASSET_URI, ConfirmPopup.class);
    confirmPopup.setMessage("Confirm Download", modulesToDownload.size() + " modules will be downloaded");
    confirmPopup.setOkHandler(() -> downloadModules(modulesToDownload));
}
Also used : ConfirmPopup(org.terasology.rendering.nui.layers.mainMenu.ConfirmPopup) DependencyResolutionFailedException(org.terasology.engine.module.DependencyResolutionFailedException) MessagePopup(org.terasology.rendering.nui.layers.mainMenu.MessagePopup) Module(org.terasology.module.Module)

Aggregations

ConfirmPopup (org.terasology.rendering.nui.layers.mainMenu.ConfirmPopup)3 MessagePopup (org.terasology.rendering.nui.layers.mainMenu.MessagePopup)2 BufferedWriter (java.io.BufferedWriter)1 Map (java.util.Map)1 DependencyResolutionFailedException (org.terasology.engine.module.DependencyResolutionFailedException)1 Module (org.terasology.module.Module)1 FilePickerPopup (org.terasology.rendering.nui.layers.mainMenu.FilePickerPopup)1