Search in sources :

Example 1 with CustomBiome

use of org.pepsoft.worldpainter.biomeschemes.CustomBiome in project WorldPainter by Captain-Chaos.

the class App method showGlobalOperations.

private void showGlobalOperations() {
    Set<Layer> allLayers = getAllLayers();
    List<Integer> allBiomes = new ArrayList<>();
    final int biomeCount = autoBiomeScheme.getBiomeCount();
    for (int biome = 0; biome < biomeCount; biome++) {
        if (autoBiomeScheme.isBiomePresent(biome)) {
            allBiomes.add(biome);
        }
    }
    if (customBiomeManager.getCustomBiomes() != null) {
        allBiomes.addAll(customBiomeManager.getCustomBiomes().stream().map(CustomBiome::getId).collect(Collectors.toList()));
    }
    FillDialog dialog = new FillDialog(App.this, dimension, allLayers.toArray(new Layer[allLayers.size()]), selectedColourScheme, allBiomes.toArray(new Integer[allBiomes.size()]), customBiomeManager, view, selectionState);
    dialog.setVisible(true);
}
Also used : CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) Paint(org.pepsoft.worldpainter.painting.Paint)

Example 2 with CustomBiome

use of org.pepsoft.worldpainter.biomeschemes.CustomBiome in project WorldPainter by Captain-Chaos.

the class App method setDimension.

public void setDimension(final Dimension dimension) {
    Configuration config = Configuration.getInstance();
    if (this.dimension != null) {
        this.dimension.removePropertyChangeListener(this);
        Point viewPosition = view.getViewCentreInWorldCoords();
        if (viewPosition != null) {
            this.dimension.setLastViewPosition(viewPosition);
            // in sync
            if (world != null) {
                Dimension oppositeDimension = null;
                switch(this.dimension.getDim()) {
                    case DIM_NORMAL:
                        oppositeDimension = world.getDimension(DIM_NORMAL_CEILING);
                        break;
                    case DIM_NORMAL_CEILING:
                        oppositeDimension = world.getDimension(DIM_NORMAL);
                        break;
                    case DIM_NETHER:
                        oppositeDimension = world.getDimension(DIM_NETHER_CEILING);
                        break;
                    case DIM_NETHER_CEILING:
                        oppositeDimension = world.getDimension(DIM_NETHER);
                        break;
                    case DIM_END:
                        oppositeDimension = world.getDimension(DIM_END_CEILING);
                        break;
                    case DIM_END_CEILING:
                        oppositeDimension = world.getDimension(DIM_END);
                        break;
                }
                if (oppositeDimension != null) {
                    oppositeDimension.setLastViewPosition(viewPosition);
                }
            }
        }
        this.dimension.unregister();
        currentUndoManager.unregisterActions();
        currentUndoManager = null;
        // currently in use
        if (!paletteManager.isEmpty()) {
            List<CustomLayer> customLayers = new ArrayList<>();
            boolean visibleLayersChanged = false;
            for (Palette palette : paletteManager.clear()) {
                List<CustomLayer> paletteLayers = palette.getLayers();
                customLayers.addAll(paletteLayers);
                for (Layer layer : paletteLayers) {
                    if (hiddenLayers.contains(layer)) {
                        hiddenLayers.remove(layer);
                        visibleLayersChanged = true;
                    }
                    if (layer.equals(soloLayer)) {
                        soloLayer = null;
                        visibleLayersChanged = true;
                    }
                }
                dockingManager.removeFrame(palette.getDockableFrame().getKey());
            }
            if (visibleLayersChanged) {
                updateLayerVisibility();
            }
            layerSoloCheckBoxes.clear();
            this.dimension.setCustomLayers(customLayers);
        } else {
            this.dimension.setCustomLayers(Collections.EMPTY_LIST);
        }
        layersWithNoButton.clear();
        saveCustomBiomes();
    }
    this.dimension = dimension;
    if (dimension != null) {
        // NOI18N
        setTitle("WorldPainter - " + world.getName() + " - " + dimension.getName());
        viewSurfaceMenuItem.setSelected(dimension.getDim() == DIM_NORMAL);
        viewSurfaceCeilingMenuItem.setSelected(dimension.getDim() == DIM_NORMAL_CEILING);
        viewNetherMenuItem.setSelected(dimension.getDim() == DIM_NETHER);
        viewNetherCeilingMenuItem.setSelected(dimension.getDim() == DIM_NETHER_CEILING);
        viewEndMenuItem.setSelected(dimension.getDim() == DIM_END);
        viewEndCeilingMenuItem.setSelected(dimension.getDim() == DIM_END_CEILING);
        // neglected to do it automatically)
        if (dimension.isFixOverlayCoords()) {
            Toolkit.getDefaultToolkit().beep();
            if (showConfirmDialog(this, "This world was created in an older version of WorldPainter\n" + "in which the overlay offsets were not stored correctly.\n" + "Do you want WorldPainter to fix the offsets now?\n" + "\n" + "If you already manually fixed the offsets using version 1.9.0\n" + "or 1.9.1 of WorldPainter, say no. If you're unsure, say yes.", "Fix Overlay Offset?", YES_NO_OPTION, QUESTION_MESSAGE) != NO_OPTION) {
                dimension.setOverlayOffsetX(dimension.getOverlayOffsetX() + dimension.getLowestX() << TILE_SIZE_BITS);
                dimension.setOverlayOffsetY(dimension.getOverlayOffsetY() + dimension.getLowestY() << TILE_SIZE_BITS);
            }
            dimension.setFixOverlayCoords(false);
        }
        view.setDimension(dimension);
        view.moveTo(dimension.getLastViewPosition());
        setDimensionControlStates(world.getPlatform());
        if ((!"true".equals(System.getProperty("org.pepsoft.worldpainter.disableUndo"))) && config.isUndoEnabled()) {
            currentUndoManager = undoManagers.get(dimension.getDim());
            if (currentUndoManager == null) {
                currentUndoManager = new UndoManager(ACTION_UNDO, ACTION_REDO, Math.max(config.getUndoLevels() + 1, 2));
                undoManagers.put(dimension.getDim(), currentUndoManager);
                currentUndoManager.setStopAtClasses(PropertyChangeListener.class, Tile.Listener.class, Biome.class, BetterAction.class);
                dimension.register(currentUndoManager);
            } else {
                currentUndoManager.registerActions(ACTION_UNDO, ACTION_REDO);
            }
            dimension.armSavePoint();
        } else {
            // Still install an undo manager, because some operations depend
            // on one level of undo being available
            currentUndoManager = new UndoManager(2);
            currentUndoManager.setStopAtClasses(PropertyChangeListener.class, Tile.Listener.class, Biome.class, BetterAction.class);
            dimension.register(currentUndoManager);
            ACTION_UNDO.setEnabled(false);
            ACTION_REDO.setEnabled(false);
        }
        if (threeDeeFrame != null) {
            threeDeeFrame.setDimension(dimension);
        }
        // Add the custom object layers from the world
        StringBuilder warnings = new StringBuilder();
        for (CustomLayer customLayer : dimension.getCustomLayers()) {
            if (customLayer.isHide()) {
                layersWithNoButton.add(customLayer);
            } else {
                registerCustomLayer(customLayer, false);
            }
            if (customLayer instanceof CombinedLayer) {
                if (!((CombinedLayer) customLayer).restoreCustomTerrain()) {
                    if (warnings.length() == 0) {
                        warnings.append("The Custom Terrain for one or more Combined Layer could not be restored:\n\n");
                    }
                    warnings.append(customLayer.getName()).append('\n');
                } else {
                    // Check for a custom terrain type and if necessary make
                    // sure it has a button
                    Terrain terrain = ((CombinedLayer) customLayer).getTerrain();
                    if ((terrain != null) && terrain.isCustom() && (customMaterialButtons[terrain.getCustomTerrainIndex()] == null)) {
                        addButtonForNewCustomTerrain(terrain.getCustomTerrainIndex(), Terrain.getCustomMaterial(terrain.getCustomTerrainIndex()), false);
                    }
                }
            }
        }
        if (warnings.length() > 0) {
            warnings.append("\nThe Custom Terrain has been removed from the layer(s).");
            showMessageDialog(this, warnings.toString(), "Custom Terrain(s) Not Restored", ERROR_MESSAGE);
        }
        // Set action states
        ACTION_GRID.setSelected(view.isPaintGrid());
        ACTION_CONTOURS.setSelected(view.isDrawContours());
        ACTION_OVERLAY.setSelected(view.isDrawOverlay());
        // TODO: make this work correctly with undo/redo, and make "inside selection" ineffective when there is no selection, to avoid confusion
        // Set operation states
        // if (dimension.containsOneOf(SelectionChunk.INSTANCE, SelectionBlock.INSTANCE)) {
        // selectionState.setValue(true);
        // } else {
        // if (activeOperation instanceof CopySelectionOperation) {
        // deselectTool();
        // }
        // selectionState.setValue(false);
        // }
        // Load custom biomes. But first remove any that are now regular
        // biomes
        List<CustomBiome> customBiomes = dimension.getCustomBiomes();
        if (customBiomes != null) {
            for (Iterator<CustomBiome> i = customBiomes.iterator(); i.hasNext(); ) {
                CustomBiome customBiome = i.next();
                if (autoBiomeScheme.isBiomePresent(customBiome.getId())) {
                    i.remove();
                }
            }
            if (customBiomes.isEmpty()) {
                customBiomes = null;
            }
        }
        programmaticChange = true;
        try {
            customBiomeManager.setCustomBiomes(customBiomes);
        } finally {
            programmaticChange = false;
        }
        dimension.addPropertyChangeListener(this);
    } else {
        view.setDimension(null);
        // NOI18N
        setTitle("WorldPainter");
        // Clear action states
        ACTION_GRID.setSelected(false);
        ACTION_CONTOURS.setSelected(false);
        ACTION_OVERLAY.setSelected(false);
        // Close the 3D view
        if (threeDeeFrame != null) {
            threeDeeFrame.dispose();
            threeDeeFrame = null;
        }
        // Clear status bar
        locationLabel.setText(strings.getString("location-"));
        heightLabel.setText(" ");
        waterLabel.setText(" ");
        biomeLabel.setText(" ");
        materialLabel.setText(" ");
        // Deselect any current operation
        if (activeOperation != null) {
            deselectTool();
        }
        // TODO: make this work correctly with undo/redo, and make "inside selection" ineffective when there is no selection, to avoid confusion
        // Disable copy selection operation
        // selectionState.setValue(false);
        programmaticChange = true;
        try {
            customBiomeManager.setCustomBiomes(null);
        } finally {
            programmaticChange = false;
        }
    }
}
Also used : TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) UndoManager(org.pepsoft.util.undo.UndoManager) Terrain(org.pepsoft.worldpainter.Terrain) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome)

Example 3 with CustomBiome

use of org.pepsoft.worldpainter.biomeschemes.CustomBiome 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 CustomBiome

use of org.pepsoft.worldpainter.biomeschemes.CustomBiome in project WorldPainter by Captain-Chaos.

the class App method importCustomItemsFromWorld.

private void importCustomItemsFromWorld(CustomItemsTreeModel.ItemType itemType) {
    File dir;
    Configuration config = Configuration.getInstance();
    if (lastSelectedFile != null) {
        dir = lastSelectedFile.getParentFile();
    } else if ((config != null) && (config.getWorldDirectory() != null)) {
        dir = config.getWorldDirectory();
    } else {
        dir = DesktopUtils.getDocumentsFolder();
    }
    File selectedFile = FileUtils.selectFileForOpen(this, "Select a WorldPainter world", dir, new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".world");
        }

        @Override
        public String getDescription() {
            return strings.getString("worldpainter.files.world");
        }
    });
    if (selectedFile != null) {
        if (!selectedFile.isFile()) {
            if (logger.isDebugEnabled()) {
                try {
                    logger.debug("Path not a file according to File.isFile(): \"" + selectedFile + "\" (directory: " + selectedFile.isDirectory() + "; length: " + selectedFile.length() + "; absolutePath: \"" + selectedFile.getAbsolutePath() + "\"; canonicalPath: \"" + selectedFile.getCanonicalPath() + "\")");
                } catch (IOException e) {
                    logger.debug("Path not a file according to File.isFile(): \"" + selectedFile + "\" (directory: " + selectedFile.isDirectory() + "; length: " + selectedFile.length() + "; absolutePath: \"" + selectedFile.getAbsolutePath() + "\")");
                    logger.warn("I/O error while trying to report canonical path of file: \"" + selectedFile + "\"", e);
                }
            }
            showMessageDialog(this, "The specified path does not exist or is not a file", "File Does Not Exist", ERROR_MESSAGE);
            return;
        }
        if (!selectedFile.canRead()) {
            showMessageDialog(this, "WorldPainter is not authorised to read the selected file", "Access Denied", ERROR_MESSAGE);
            return;
        }
        final World2 selectedWorld = ProgressDialog.executeTask(this, new ProgressTask<World2>() {

            @Override
            public String getName() {
                return strings.getString("loading.world");
            }

            @Override
            public World2 execute(ProgressReceiver progressReceiver) throws OperationCancelled {
                try {
                    WorldIO worldIO = new WorldIO();
                    worldIO.load(new FileInputStream(selectedFile));
                    World2 world = worldIO.getWorld();
                    return world;
                } catch (UnloadableWorldException e) {
                    logger.error("Could not load world from file " + selectedFile, e);
                    if (e.getMetadata() != null) {
                        logMetadataAsError(e.getMetadata());
                    }
                    reportUnloadableWorldException(e);
                    return null;
                } catch (IOException e) {
                    throw new RuntimeException("I/O error while loading world", e);
                }
            }

            private void appendMetadata(StringBuilder sb, Map<String, Object> metadata) {
                for (Map.Entry<String, Object> entry : metadata.entrySet()) {
                    switch(entry.getKey()) {
                        case World2.METADATA_KEY_WP_VERSION:
                            sb.append("Saved with WorldPainter ").append(entry.getValue());
                            String build = (String) metadata.get(World2.METADATA_KEY_WP_BUILD);
                            if (build != null) {
                                sb.append(" (").append(build).append(')');
                            }
                            sb.append('\n');
                            break;
                        case World2.METADATA_KEY_TIMESTAMP:
                            sb.append("Saved on ").append(SimpleDateFormat.getDateTimeInstance().format((Date) entry.getValue())).append('\n');
                            break;
                        case World2.METADATA_KEY_PLUGINS:
                            String[][] plugins = (String[][]) entry.getValue();
                            for (String[] plugin : plugins) {
                                sb.append("Plugin: ").append(plugin[0]).append(" (").append(plugin[1]).append(")\n");
                            }
                            break;
                    }
                }
            }

            private void logMetadataAsError(Map<String, Object> metadata) {
                StringBuilder sb = new StringBuilder("Metadata from world file:\n");
                appendMetadata(sb, metadata);
                logger.error(sb.toString());
            }

            private void reportUnloadableWorldException(UnloadableWorldException e) {
                try {
                    String text;
                    if (e.getMetadata() != null) {
                        StringBuilder sb = new StringBuilder("WorldPainter could not load the file. The cause may be one of:\n" + "\n" + "* The file is damaged or corrupted\n" + "* The file was created with a newer version of WorldPainter\n" + "* The file was created using WorldPainter plugins which you do not have\n" + "\n");
                        appendMetadata(sb, e.getMetadata());
                        text = sb.toString();
                    } else {
                        text = "WorldPainter could not load the file. The cause may be one of:\n" + "\n" + "* The file is not a WorldPainter world\n" + "* The file is damaged or corrupted\n" + "* The file was created with a newer version of WorldPainter\n" + "* The file was created using WorldPainter plugins which you do not have";
                    }
                    SwingUtilities.invokeAndWait(() -> showMessageDialog(App.this, text, strings.getString("file.damaged"), ERROR_MESSAGE));
                } catch (InterruptedException e2) {
                    throw new RuntimeException("Thread interrupted while reporting unloadable file " + selectedFile, e2);
                } catch (InvocationTargetException e2) {
                    throw new RuntimeException("Invocation target exception while reporting unloadable file " + selectedFile, e2);
                }
            }
        }, false);
        if (selectedWorld == null) {
            // The file was damaged
            return;
        }
        if (CustomItemsTreeModel.hasCustomItems(selectedWorld, itemType)) {
            ImportCustomItemsDialog dialog = new ImportCustomItemsDialog(this, selectedWorld, selectedColourScheme, itemType);
            dialog.setVisible(true);
            if (!dialog.isCancelled()) {
                StringBuilder errors = new StringBuilder();
                Set<CustomLayer> existingCustomLayers = null;
                boolean refreshView = false, showError = false;
                for (Object selectedItem : dialog.getSelectedItems()) {
                    if (selectedItem instanceof CustomLayer) {
                        if (existingCustomLayers == null) {
                            existingCustomLayers = getCustomLayers();
                        }
                        if (existingCustomLayers.contains(selectedItem)) {
                            errors.append("Custom Layer \"" + ((CustomLayer) selectedItem).getName() + "\" already exists\n");
                        } else {
                            registerCustomLayer((CustomLayer) selectedItem, false);
                        }
                    } else if (selectedItem instanceof MixedMaterial) {
                        MixedMaterial customMaterial = (MixedMaterial) selectedItem;
                        int index = findNextCustomTerrainIndex();
                        if (index == -1) {
                            errors.append("No free slots for Custom Terrain \"" + customMaterial.getName() + "\"\n");
                            showError = true;
                            continue;
                        }
                        customMaterial = MixedMaterialManager.getInstance().register(customMaterial);
                        addButtonForNewCustomTerrain(index, customMaterial, false);
                    } else if (selectedItem instanceof CustomBiome) {
                        CustomBiome customBiome = (CustomBiome) selectedItem;
                        if (!customBiomeManager.addCustomBiome(null, customBiome)) {
                            errors.append("ID already in use for Custom Biome " + customBiome.getId() + " (\"" + customBiome + "\")\n");
                            showError = true;
                        } else {
                            refreshView = true;
                        }
                    } else {
                        throw new InternalError("Unsupported custom item type " + selectedItem.getClass() + " encountered");
                    }
                }
                if (refreshView) {
                    view.refreshTiles();
                }
                if (errors.length() > 0) {
                    JOptionPane.showMessageDialog(App.this, "Not all items have been imported:\n\n" + errors, "Not All Items Imported", showError ? JOptionPane.ERROR_MESSAGE : JOptionPane.WARNING_MESSAGE);
                }
            }
        } else {
            String what;
            switch(itemType) {
                case ALL:
                    what = "layers, terrains or biomes";
                    break;
                case BIOME:
                    what = "biomes";
                    break;
                case LAYER:
                    what = "layers";
                    break;
                case TERRAIN:
                    what = "terrains";
                    break;
                default:
                    throw new InternalError();
            }
            showMessageDialog(this, "The selected world has no custom " + what + ".", "No Custom Items", WARNING_MESSAGE);
        }
    }
}
Also used : HistoryEntry(org.pepsoft.worldpainter.history.HistoryEntry) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) FileFilter(javax.swing.filechooser.FileFilter) ImportCustomItemsDialog(org.pepsoft.worldpainter.importing.ImportCustomItemsDialog) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with CustomBiome

use of org.pepsoft.worldpainter.biomeschemes.CustomBiome in project WorldPainter by Captain-Chaos.

the class BrushOptions method createObjectSelectionMenu.

private JPopupMenu createObjectSelectionMenu(final ObjectSelectionListener listener) {
    JMenuItem waterItem = new JMenuItem("Water");
    waterItem.addActionListener(e -> listener.objectSelected(DefaultFilter.WATER, "Water", null));
    JMenu popupMenu = new JMenu();
    popupMenu.add(waterItem);
    JMenuItem lavaItem = new JMenuItem("Lava");
    lavaItem.addActionListener(e -> listener.objectSelected(DefaultFilter.LAVA, "Lava", null));
    popupMenu.add(lavaItem);
    JMenuItem landItem = new JMenuItem("Land");
    landItem.addActionListener(e -> listener.objectSelected(DefaultFilter.LAND, "Land", null));
    popupMenu.add(landItem);
    JMenu terrainMenu = new JMenu("Terrain");
    JMenu customTerrainMenu = new JMenu("Custom");
    JMenu stainedClayTerrainMenu = new JMenu("Stained Clay");
    App app = App.getInstance();
    ColourScheme colourScheme = app.getColourScheme();
    for (Terrain terrain : Terrain.getConfiguredValues()) {
        final Terrain selectedTerrain = terrain;
        final String name = terrain.getName();
        final Icon icon = new ImageIcon(terrain.getIcon(colourScheme));
        JMenuItem menuItem = new JMenuItem(name, icon);
        menuItem.addActionListener(e -> listener.objectSelected(selectedTerrain, name, icon));
        if (terrain.isCustom()) {
            customTerrainMenu.add(menuItem);
        } else if (terrain.getName().endsWith(" Clay") && (terrain != Terrain.HARDENED_CLAY)) {
            stainedClayTerrainMenu.add(menuItem);
        } else {
            terrainMenu.add(menuItem);
        }
    }
    terrainMenu.add(stainedClayTerrainMenu);
    if (customTerrainMenu.getMenuComponentCount() > 0) {
        terrainMenu.add(customTerrainMenu);
    }
    popupMenu.add(terrainMenu);
    JMenu layerMenu = new JMenu("Layer");
    LayerManager.getInstance().getLayers().stream().filter(l -> !l.equals(Biome.INSTANCE)).forEach(l -> {
        JMenuItem menuItem = new JMenuItem(l.getName(), new ImageIcon(l.getIcon()));
        menuItem.addActionListener(e -> listener.objectSelected(l, l.getName(), new ImageIcon(l.getIcon())));
        layerMenu.add(menuItem);
    });
    Set<CustomLayer> customLayers = app.getCustomLayers();
    if (customLayers.size() > 15) {
        // If there are fifteen or more custom layers, split them by palette
        // and move them to separate submenus to try and conserve screen
        // space
        app.getCustomLayersByPalette().entrySet().stream().map((entry) -> {
            String palette = entry.getKey();
            JMenu paletteMenu = new JMenu(palette != null ? palette : "Hidden Layers");
            entry.getValue().forEach(l -> {
                JMenuItem menuItem = new JMenuItem(l.getName(), new ImageIcon(l.getIcon()));
                menuItem.addActionListener(e -> listener.objectSelected(l, l.getName(), new ImageIcon(l.getIcon())));
                paletteMenu.add(menuItem);
            });
            return paletteMenu;
        }).forEach(layerMenu::add);
    } else {
        customLayers.forEach(l -> {
            JMenuItem menuItem = new JMenuItem(l.getName(), new ImageIcon(l.getIcon()));
            menuItem.addActionListener(e -> listener.objectSelected(l, l.getName(), new ImageIcon(l.getIcon())));
            layerMenu.add(menuItem);
        });
    }
    popupMenu.add(layerMenu);
    final JMenu biomeMenu = new JMenu("Biome");
    final CustomBiomeManager customBiomeManager = app.getCustomBiomeManager();
    final BiomeHelper biomeHelper = new BiomeHelper(autoBiomeScheme, colourScheme, customBiomeManager);
    List<CustomBiome> customBiomes = customBiomeManager.getCustomBiomes();
    if ((customBiomes != null) && (!customBiomes.isEmpty())) {
        JMenu customBiomeMenu = new JMenu("Custom");
        for (CustomBiome customBiome : customBiomes) {
            final int selectedBiome = customBiome.getId();
            final String name = biomeHelper.getBiomeName(selectedBiome) + " (" + selectedBiome + ")";
            final Icon icon = biomeHelper.getBiomeIcon(selectedBiome);
            final JMenuItem menuItem = new JMenuItem(name, icon);
            menuItem.addActionListener(e -> listener.objectSelected(new DefaultFilter.LayerValue(Biome.INSTANCE, selectedBiome), name, icon));
            customBiomeMenu.add(menuItem);
        }
        biomeMenu.add(customBiomeMenu);
    }
    for (int i = 0; i < autoBiomeScheme.getBiomeCount(); i++) {
        if (autoBiomeScheme.isBiomePresent(i)) {
            final int selectedBiome = i;
            final String name = biomeHelper.getBiomeName(i) + " (" + selectedBiome + ")";
            final Icon icon = biomeHelper.getBiomeIcon(i);
            final JMenuItem menuItem = new JMenuItem(name, icon);
            menuItem.addActionListener(e -> listener.objectSelected(new DefaultFilter.LayerValue(Biome.INSTANCE, selectedBiome), name, icon));
            biomeMenu.add(menuItem);
        }
    }
    JMenu autoBiomeSubMenu = new JMenu("Auto Biomes");
    JMenuItem autoBiomesMenuItem = new JMenuItem("All Auto Biomes");
    autoBiomesMenuItem.addActionListener(e -> listener.objectSelected(DefaultFilter.AUTO_BIOMES, "All Auto Biomes", null));
    autoBiomeSubMenu.add(autoBiomesMenuItem);
    for (int autoBiome : Dimension.POSSIBLE_AUTO_BIOMES) {
        final int selectedBiome = -autoBiome;
        final String name = biomeHelper.getBiomeName(autoBiome);
        final Icon icon = biomeHelper.getBiomeIcon(autoBiome);
        final JMenuItem menuItem = new JMenuItem(name, icon);
        menuItem.addActionListener(e -> listener.objectSelected(new DefaultFilter.LayerValue(Biome.INSTANCE, selectedBiome), name, icon));
        autoBiomeSubMenu.add(menuItem);
    }
    biomeMenu.add(autoBiomeSubMenu);
    popupMenu.add(biomeMenu);
    JMenu annotationsMenu = new JMenu("Annotations");
    JMenuItem menuItem = new JMenuItem("All Annotations");
    menuItem.addActionListener(e -> listener.objectSelected(new DefaultFilter.LayerValue(Annotations.INSTANCE), "All Annotations", null));
    annotationsMenu.add(menuItem);
    for (int i = 1; i < 16; i++) {
        final int selectedColour = i, dataValue = selectedColour - ((selectedColour < 8) ? 1 : 0);
        final Icon icon = IconUtils.createScaledColourIcon(colourScheme.getColour(Constants.BLK_WOOL, dataValue));
        menuItem = new JMenuItem(Constants.COLOUR_NAMES[dataValue], icon);
        menuItem.addActionListener(e -> listener.objectSelected(new DefaultFilter.LayerValue(Annotations.INSTANCE, selectedColour), Constants.COLOUR_NAMES[dataValue] + " Annotations", icon));
        annotationsMenu.add(menuItem);
    }
    popupMenu.add(annotationsMenu);
    popupMenu = breakUpLongMenus(popupMenu, 25);
    JPopupMenu result = new JPopupMenu();
    Arrays.stream(popupMenu.getMenuComponents()).forEach(result::add);
    return result;
}
Also used : org.pepsoft.worldpainter(org.pepsoft.worldpainter) CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper) java.util(java.util) Logger(org.slf4j.Logger) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) IconUtils(org.pepsoft.util.IconUtils) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) LoggerFactory(org.slf4j.LoggerFactory) NumberEditor(javax.swing.JSpinner.NumberEditor) org.pepsoft.worldpainter.layers(org.pepsoft.worldpainter.layers) ActionEvent(java.awt.event.ActionEvent) Dimension(org.pepsoft.worldpainter.Dimension) java.awt(java.awt) List(java.util.List) ObservableBoolean(org.pepsoft.util.ObservableBoolean) Constants(org.pepsoft.minecraft.Constants) Filter(org.pepsoft.worldpainter.operations.Filter) LevelType(org.pepsoft.worldpainter.panels.DefaultFilter.LevelType) javax.swing(javax.swing) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper) CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager)

Aggregations

CustomBiome (org.pepsoft.worldpainter.biomeschemes.CustomBiome)6 ArrayList (java.util.ArrayList)2 CustomBiomeManager (org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager)2 GroundCoverLayer (org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)2 PlantLayer (org.pepsoft.worldpainter.layers.plants.PlantLayer)2 UndergroundPocketsLayer (org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer)2 TunnelLayer (org.pepsoft.worldpainter.layers.tunnel.TunnelLayer)2 java.awt (java.awt)1 ActionEvent (java.awt.event.ActionEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 java.util (java.util)1 List (java.util.List)1 javax.swing (javax.swing)1 NumberEditor (javax.swing.JSpinner.NumberEditor)1 FileFilter (javax.swing.filechooser.FileFilter)1 TreePath (javax.swing.tree.TreePath)1 Constants (org.pepsoft.minecraft.Constants)1 IconUtils (org.pepsoft.util.IconUtils)1 ObservableBoolean (org.pepsoft.util.ObservableBoolean)1 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)1