Search in sources :

Example 1 with CustomLayer

use of org.pepsoft.worldpainter.layers.CustomLayer in project WorldPainter by Captain-Chaos.

the class ExportWorldDialog method export.

private void export() {
    // Check for errors
    if (!new File(fieldDirectory.getText().trim()).isDirectory()) {
        fieldDirectory.requestFocusInWindow();
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(this, "The selected output directory does not exist or is not a directory.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (fieldName.getText().trim().isEmpty()) {
        fieldName.requestFocusInWindow();
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(this, "You have not specified a name for the map.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if ((!radioButtonExportEverything.isSelected()) && ((selectedTiles == null) || selectedTiles.isEmpty())) {
        radioButtonExportEverything.requestFocusInWindow();
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(this, "No tiles have been selected for export.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    // Check for warnings
    StringBuilder sb = new StringBuilder("<html>Please confirm that you want to export the world<br>notwithstanding the following warnings:<br><ul>");
    boolean showWarning = false;
    Generator generator = Generator.values()[comboBoxGenerator.getSelectedIndex()];
    if ((!radioButtonExportSelection.isSelected()) || (selectedDimension == DIM_NORMAL)) {
        // The surface dimension is going to be exported
        if ((generator == Generator.FLAT) && (surfacePropertiesEditor.isPopulateSelected() || world.getDimension(DIM_NORMAL).getAllLayers(true).contains(Populate.INSTANCE))) {
            sb.append("<li>The Superflat world type is selected and Populate is in use.<br>Minecraft will <em>not</em> populate any chunks for Superflat maps.");
            showWarning = true;
        }
    }
    if (radioButtonExportSelection.isSelected()) {
        if (selectedDimension == DIM_NORMAL) {
            boolean spawnInSelection = false;
            Point spawnPoint = world.getSpawnPoint();
            for (Point tile : selectedTiles) {
                if ((spawnPoint.x >= (tile.x << 7)) && (spawnPoint.x < ((tile.x + 1) << 7)) && (spawnPoint.y >= (tile.y << 7)) && (spawnPoint.y < ((tile.y + 1) << 7))) {
                    spawnInSelection = true;
                    break;
                }
            }
            if (!spawnInSelection) {
                sb.append("<li>The spawn point is not inside the selected area.");
                showWarning = true;
            }
        }
        String dim;
        switch(selectedDimension) {
            case DIM_NORMAL:
                dim = "Surface";
                break;
            case DIM_NETHER:
                dim = "Nether";
                break;
            case DIM_END:
                dim = "End";
                break;
            default:
                throw new InternalError();
        }
        sb.append("<li>A tile selection is active! Only " + selectedTiles.size() + " tiles of the<br>" + dim + " dimension are going to be exported.");
        showWarning = showWarning || (!disableTileSelectionWarning);
    }
    int disabledLayerCount = 0;
    for (Dimension dimension : world.getDimensions()) {
        for (CustomLayer customLayer : dimension.getCustomLayers()) {
            if (!customLayer.isExport()) {
                disabledLayerCount++;
            }
        }
    }
    if (disabledLayerCount > 0) {
        if (disabledLayerCount == 1) {
            sb.append("<li>There are disabled custom layers!<br>One layer is not going to be exported.");
        } else {
            sb.append("<li>There are disabled custom layers!<br>" + disabledLayerCount + " layers are not going to be exported.");
        }
        showWarning = showWarning || (!disableDisabledLayersWarning);
    }
    sb.append("</ul>Do you want to continue with the export?</html>");
    if (showWarning && (JOptionPane.showConfirmDialog(this, sb.toString(), "Review Warnings", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION)) {
        return;
    }
    File baseDir = new File(fieldDirectory.getText().trim());
    String name = fieldName.getText().trim();
    if (!surfacePropertiesEditor.saveSettings()) {
        jTabbedPane1.setSelectedIndex(0);
        return;
    }
    if (world.getDimension(DIM_NETHER) != null) {
        if (!netherPropertiesEditor.saveSettings()) {
            jTabbedPane1.setSelectedIndex(2);
            return;
        }
    }
    if (world.getDimension(DIM_END) != null) {
        if (!endPropertiesEditor.saveSettings()) {
            jTabbedPane1.setSelectedIndex(4);
            return;
        }
    }
    if (world.getDimension(DIM_NORMAL_CEILING) != null) {
        if (!surfaceCeilingPropertiesEditor.saveSettings()) {
            jTabbedPane1.setSelectedIndex(1);
            return;
        }
    }
    if (world.getDimension(DIM_NETHER_CEILING) != null) {
        if (!netherCeilingPropertiesEditor.saveSettings()) {
            jTabbedPane1.setSelectedIndex(3);
            return;
        }
    }
    if (world.getDimension(DIM_END_CEILING) != null) {
        if (!endCeilingPropertiesEditor.saveSettings()) {
            jTabbedPane1.setSelectedIndex(5);
            return;
        }
    }
    Platform platform = (Platform) comboBoxMinecraftVersion.getSelectedItem();
    world.setPlatform(platform);
    world.setCreateGoodiesChest(checkBoxGoodies.isSelected());
    world.setGameType((GameType) comboBoxGameType.getSelectedItem());
    world.setAllowCheats(checkBoxAllowCheats.isSelected());
    if (!endlessBorder) {
        world.setGenerator(generator);
        world.setMapFeatures(checkBoxMapFeatures.isSelected());
        if ((generatorOptions != null) && (!generatorOptions.trim().isEmpty())) {
            world.setGeneratorOptions(generatorOptions.trim());
        } else {
            world.setGeneratorOptions(null);
        }
    }
    world.setPlatform((Platform) comboBoxMinecraftVersion.getSelectedItem());
    if (radioButtonExportEverything.isSelected()) {
        world.setDimensionsToExport(null);
        world.setTilesToExport(null);
    } else {
        world.setDimensionsToExport(Collections.singleton(selectedDimension));
        world.setTilesToExport(selectedTiles);
    }
    world.setDifficulty(comboBoxDifficulty.getSelectedIndex());
    fieldDirectory.setEnabled(false);
    fieldName.setEnabled(false);
    buttonSelectDirectory.setEnabled(false);
    buttonExport.setEnabled(false);
    buttonCancel.setEnabled(false);
    surfacePropertiesEditor.setEnabled(false);
    netherPropertiesEditor.setEnabled(false);
    endPropertiesEditor.setEnabled(false);
    checkBoxGoodies.setEnabled(false);
    comboBoxGameType.setEnabled(false);
    checkBoxAllowCheats.setEnabled(false);
    comboBoxGenerator.setEnabled(false);
    comboBoxMinecraftVersion.setEnabled(false);
    radioButtonExportEverything.setEnabled(false);
    radioButtonExportSelection.setEnabled(false);
    labelSelectTiles.setForeground(null);
    labelSelectTiles.setCursor(null);
    checkBoxMapFeatures.setEnabled(false);
    comboBoxDifficulty.setEnabled(false);
    Configuration config = Configuration.getInstance();
    if (config != null) {
        config.setExportDirectory(world.getPlatform(), baseDir);
    }
    ExportProgressDialog dialog = new ExportProgressDialog(this, world, baseDir, name);
    view.setInhibitUpdates(true);
    try {
        dialog.setVisible(true);
    } finally {
        view.setInhibitUpdates(false);
    }
    ok();
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) File(java.io.File)

Example 2 with CustomLayer

use of org.pepsoft.worldpainter.layers.CustomLayer in project WorldPainter by Captain-Chaos.

the class TunnelLayerDialog method editFloorLayer.

private void editFloorLayer() {
    int selectedRow = tableFloorLayers.getSelectedRow();
    if (selectedRow != -1) {
        Layer layer = floorLayersTableModel.getLayer(selectedRow);
        if (layer instanceof CustomLayer) {
            EditLayerDialog<Layer> dialog = new EditLayerDialog<>(this, layer);
            dialog.setVisible(true);
            if (!dialog.isCancelled()) {
                floorLayersTableModel.layerChanged(selectedRow);
            }
        }
    }
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) Bo2Layer(org.pepsoft.worldpainter.layers.Bo2Layer) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) Layer(org.pepsoft.worldpainter.layers.Layer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) EditLayerDialog(org.pepsoft.worldpainter.layers.EditLayerDialog)

Example 3 with CustomLayer

use of org.pepsoft.worldpainter.layers.CustomLayer in project WorldPainter by Captain-Chaos.

the class CustomItemsTreeModel method getSelectedItems.

public List<Object> getSelectedItems(TreePath[] selectedTreePaths) {
    ArrayList<Object> selectedItems = new ArrayList<>();
    for (TreePath selectedPath : selectedTreePaths) {
        Object object = selectedPath.getLastPathComponent();
        if (object == ROOT) {
            selectedItems.addAll(customTerrains);
            selectedItems.addAll(customLayers);
            selectedItems.addAll(customBiomes);
        } else if (object == TERRAINS) {
            selectedItems.addAll(customTerrains);
        } else if (object == LAYERS) {
            selectedItems.addAll(customLayers);
        } else if (object == BIOMES) {
            selectedItems.addAll(customBiomes);
        } else if ((object instanceof CustomLayer) || (object instanceof MixedMaterial) || (object instanceof CustomBiome)) {
            selectedItems.add(object);
        } else {
            throw new InternalError("Unknown node type " + object.getClass() + " (\"" + object + "\") encountered");
        }
    }
    return selectedItems;
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) TreePath(javax.swing.tree.TreePath) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) ArrayList(java.util.ArrayList) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 4 with CustomLayer

use of org.pepsoft.worldpainter.layers.CustomLayer in project WorldPainter by Captain-Chaos.

the class AbstractWorldExporter method setupDimensionForExport.

@NotNull
private Map<Layer, LayerExporter> setupDimensionForExport(Dimension dimension) {
    // Gather all layers used on the map
    final Map<Layer, LayerExporter> exporters = new HashMap<>();
    Set<Layer> allLayers = dimension.getAllLayers(false);
    allLayers.addAll(dimension.getMinimumLayers());
    // If there are combined layers, apply them and gather any newly
    // added layers, recursively
    boolean done;
    do {
        done = true;
        for (Layer layer : new HashSet<>(allLayers)) {
            if ((layer instanceof CombinedLayer) && ((CombinedLayer) layer).isExport()) {
                // Apply the combined layer
                Set<Layer> addedLayers = ((CombinedLayer) layer).apply(dimension);
                // Remove the combined layer from the list
                allLayers.remove(layer);
                // Add any layers it might have added
                allLayers.addAll(addedLayers);
                // Signal that we have to go around at least once more,
                // in case any of the newly added layers are themselves
                // combined layers
                done = false;
            }
        }
    } while (!done);
    // Remove layers which have been excluded for export
    allLayers.removeIf(layer -> (layer instanceof CustomLayer) && (!((CustomLayer) layer).isExport()));
    // Load all layer settings into the exporters
    for (Layer layer : allLayers) {
        @SuppressWarnings("unchecked") LayerExporter exporter = layer.getExporter();
        if (exporter != null) {
            exporter.setSettings(dimension.getLayerSettings(layer));
            exporters.put(layer, exporter);
        }
    }
    return exporters;
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) CombinedLayer(org.pepsoft.worldpainter.layers.CombinedLayer) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) CombinedLayer(org.pepsoft.worldpainter.layers.CombinedLayer) Layer(org.pepsoft.worldpainter.layers.Layer) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CustomLayer

use of org.pepsoft.worldpainter.layers.CustomLayer in project WorldPainter by Captain-Chaos.

the class AbstractWorldExporter method exportRegion.

protected final ExportResults exportRegion(MinecraftWorld minecraftWorld, Dimension dimension, Dimension ceiling, Platform platform, Point regionCoords, boolean tileSelection, Map<Layer, LayerExporter> exporters, Map<Layer, LayerExporter> ceilingExporters, ChunkFactory chunkFactory, ChunkFactory ceilingChunkFactory, ProgressReceiver progressReceiver) throws OperationCancelled, IOException {
    if (progressReceiver != null) {
        progressReceiver.setMessage("Exporting region " + regionCoords.x + "," + regionCoords.y + " of " + dimension.getName());
    }
    int lowestTileX = (regionCoords.x << 2) - 1;
    int highestTileX = lowestTileX + 5;
    int lowestTileY = (regionCoords.y << 2) - 1;
    int highestTileY = lowestTileY + 5;
    Map<Point, Tile> tiles = new HashMap<>(), ceilingTiles = new HashMap<>();
    for (int tileX = lowestTileX; tileX <= highestTileX; tileX++) {
        for (int tileY = lowestTileY; tileY <= highestTileY; tileY++) {
            Point tileCoords = new Point(tileX, tileY);
            Tile tile = dimension.getTile(tileCoords);
            if ((tile != null) && ((!tileSelection) || dimension.getWorld().getTilesToExport().contains(tileCoords))) {
                tiles.put(tileCoords, tile);
            }
            if (ceiling != null) {
                tile = ceiling.getTile(tileCoords);
                if ((tile != null) && ((!tileSelection) || dimension.getWorld().getTilesToExport().contains(tileCoords))) {
                    ceilingTiles.put(tileCoords, tile);
                }
            }
        }
    }
    Set<Layer> allLayers = new HashSet<>(), allCeilingLayers = new HashSet<>();
    for (Tile tile : tiles.values()) {
        allLayers.addAll(tile.getLayers());
    }
    // Add layers that have been configured to be applied everywhere
    Set<Layer> minimumLayers = dimension.getMinimumLayers(), ceilingMinimumLayers = (ceiling != null) ? ceiling.getMinimumLayers() : null;
    allLayers.addAll(minimumLayers);
    // Remove layers which have been excluded for export
    allLayers.removeIf(layer -> (layer instanceof CustomLayer) && (!((CustomLayer) layer).isExport()));
    List<Layer> secondaryPassLayers = new ArrayList<>(), ceilingSecondaryPassLayers = new ArrayList<>();
    for (Layer layer : allLayers) {
        LayerExporter exporter = layer.getExporter();
        if (exporter instanceof SecondPassLayerExporter) {
            secondaryPassLayers.add(layer);
        }
    }
    Collections.sort(secondaryPassLayers);
    // Set up export of ceiling
    if (ceiling != null) {
        for (Tile tile : ceilingTiles.values()) {
            allCeilingLayers.addAll(tile.getLayers());
        }
        allCeilingLayers.addAll(ceilingMinimumLayers);
        // Remove layers which have been excluded for export
        allCeilingLayers.removeIf(layer -> (layer instanceof CustomLayer) && (!((CustomLayer) layer).isExport()));
        for (Layer layer : allCeilingLayers) {
            LayerExporter exporter = layer.getExporter();
            if (exporter instanceof SecondPassLayerExporter) {
                ceilingSecondaryPassLayers.add(layer);
            }
        }
        Collections.sort(ceilingSecondaryPassLayers);
    }
    long t1 = System.currentTimeMillis();
    // First pass. Create terrain and apply layers which don't need access
    // to neighbouring chunks
    ExportResults exportResults = firstPass(minecraftWorld, dimension, regionCoords, tiles, tileSelection, exporters, chunkFactory, false, (progressReceiver != null) ? new SubProgressReceiver(progressReceiver, 0.0f, ((ceiling != null) ? 0.225f : 0.45f)) : null);
    ExportResults ceilingExportResults = null;
    if (ceiling != null) {
        // First pass for the ceiling. Create terrain and apply layers which
        // don't need access to neighbouring chunks
        ceilingExportResults = firstPass(minecraftWorld, ceiling, regionCoords, ceilingTiles, tileSelection, ceilingExporters, ceilingChunkFactory, true, (progressReceiver != null) ? new SubProgressReceiver(progressReceiver, 0.225f, 0.225f) : null);
    }
    if (exportResults.chunksGenerated || ((ceiling != null) && ceilingExportResults.chunksGenerated)) {
        // Second pass. Apply layers which need information from or apply
        // changes to neighbouring chunks
        long t2 = System.currentTimeMillis();
        List<Fixup> myFixups = secondPass(secondaryPassLayers, dimension, minecraftWorld, exporters, tiles.values(), regionCoords, (progressReceiver != null) ? new SubProgressReceiver(progressReceiver, 0.45f, (ceiling != null) ? 0.05f : 0.1f) : null);
        if ((myFixups != null) && (!myFixups.isEmpty())) {
            exportResults.fixups = myFixups;
        }
        if (ceiling != null) {
            // Second pass for ceiling. Apply layers which need information
            // from or apply changes to neighbouring chunks. Fixups are not
            // supported for the ceiling for now. TODO: implement
            secondPass(ceilingSecondaryPassLayers, ceiling, new InvertedWorld(minecraftWorld, ceiling.getMaxHeight() - ceiling.getCeilingHeight()), ceilingExporters, ceilingTiles.values(), regionCoords, (progressReceiver != null) ? new SubProgressReceiver(progressReceiver, 0.4f, 0.05f) : null);
        }
        // Post processing. Fix covered grass blocks, things like that
        long t3 = System.currentTimeMillis();
        PlatformManager.getInstance().getPostProcessor(platform).postProcess(minecraftWorld, new Rectangle(regionCoords.x << 9, regionCoords.y << 9, 512, 512), (progressReceiver != null) ? new SubProgressReceiver(progressReceiver, 0.55f, 0.1f) : null);
        // Third pass. Calculate lighting
        long t4 = System.currentTimeMillis();
        lightingPass(minecraftWorld, regionCoords, (progressReceiver != null) ? new SubProgressReceiver(progressReceiver, 0.65f, 0.35f) : null);
        long t5 = System.currentTimeMillis();
        if ("true".equalsIgnoreCase(System.getProperty("org.pepsoft.worldpainter.devMode"))) {
            String timingMessage = (t2 - t1) + ", " + (t3 - t2) + ", " + (t4 - t3) + ", " + (t5 - t4) + ", " + (t5 - t1);
            // System.out.println("Export timing: " + timingMessage);
            synchronized (TIMING_FILE_LOCK) {
                try (PrintWriter out = new PrintWriter(new FileOutputStream("exporttimings.csv", true))) {
                    out.println(timingMessage);
                }
            }
        }
    }
    return exportResults;
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) Tile(org.pepsoft.worldpainter.Tile) SubProgressReceiver(org.pepsoft.util.SubProgressReceiver) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) CombinedLayer(org.pepsoft.worldpainter.layers.CombinedLayer) Layer(org.pepsoft.worldpainter.layers.Layer) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

CustomLayer (org.pepsoft.worldpainter.layers.CustomLayer)8 Layer (org.pepsoft.worldpainter.layers.Layer)5 Bo2Layer (org.pepsoft.worldpainter.layers.Bo2Layer)3 GroundCoverLayer (org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)3 PlantLayer (org.pepsoft.worldpainter.layers.plants.PlantLayer)3 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)2 CombinedLayer (org.pepsoft.worldpainter.layers.CombinedLayer)2 EditLayerDialog (org.pepsoft.worldpainter.layers.EditLayerDialog)2 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 javax.swing (javax.swing)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1