Search in sources :

Example 1 with PlantLayer

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

the class App method createCustomLayerMenu.

private JPopupMenu createCustomLayerMenu(final String paletteName) {
    JPopupMenu customLayerMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem(strings.getString("add.a.custom.object.layer") + "...");
    menuItem.addActionListener(e -> {
        EditLayerDialog<Bo2Layer> dialog = new EditLayerDialog<>(App.this, Bo2Layer.class);
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            Bo2Layer layer = dialog.getLayer();
            if (paletteName != null) {
                layer.setPalette(paletteName);
            }
            registerCustomLayer(layer, true);
        }
    });
    customLayerMenu.add(menuItem);
    menuItem = new JMenuItem(strings.getString("add.a.custom.ground.cover.layer") + "...");
    menuItem.addActionListener(e -> {
        EditLayerDialog<GroundCoverLayer> dialog = new EditLayerDialog<>(App.this, GroundCoverLayer.class);
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            GroundCoverLayer layer = dialog.getLayer();
            if (paletteName != null) {
                layer.setPalette(paletteName);
            }
            registerCustomLayer(layer, true);
        }
    });
    customLayerMenu.add(menuItem);
    menuItem = new JMenuItem(strings.getString("add.a.custom.underground.pockets.layer") + "...");
    menuItem.addActionListener(e -> {
        UndergroundPocketsDialog dialog = new UndergroundPocketsDialog(App.this, MixedMaterial.create(Material.IRON_BLOCK), selectedColourScheme, world.getMaxHeight(), world.isExtendedBlockIds());
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            UndergroundPocketsLayer layer = dialog.getSelectedLayer();
            if (paletteName != null) {
                layer.setPalette(paletteName);
            }
            registerCustomLayer(layer, true);
        }
    });
    customLayerMenu.add(menuItem);
    menuItem = new JMenuItem("Add a custom cave/tunnel layer...");
    menuItem.addActionListener(e -> {
        final TunnelLayer layer = new TunnelLayer("Tunnels", 0x000000);
        final int baseHeight, waterLevel;
        final TileFactory tileFactory = dimension.getTileFactory();
        if (tileFactory instanceof HeightMapTileFactory) {
            baseHeight = (int) ((HeightMapTileFactory) tileFactory).getBaseHeight();
            waterLevel = ((HeightMapTileFactory) tileFactory).getWaterHeight();
            layer.setFloodWithLava(((HeightMapTileFactory) tileFactory).isFloodWithLava());
        } else {
            baseHeight = 58;
            waterLevel = 62;
        }
        TunnelLayerDialog dialog = new TunnelLayerDialog(App.this, layer, world.isExtendedBlockIds(), selectedColourScheme, dimension.getMaxHeight(), baseHeight, waterLevel);
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            if (paletteName != null) {
                layer.setPalette(paletteName);
            }
            registerCustomLayer(layer, true);
        }
    });
    customLayerMenu.add(menuItem);
    menuItem = new JMenuItem("Add a custom plants layer...");
    menuItem.addActionListener(e -> {
        EditLayerDialog<PlantLayer> dialog = new EditLayerDialog<>(App.this, PlantLayer.class);
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            PlantLayer layer = dialog.getLayer();
            if (paletteName != null) {
                layer.setPalette(paletteName);
            }
            registerCustomLayer(layer, true);
        }
    });
    customLayerMenu.add(menuItem);
    menuItem = new JMenuItem("Add a combined layer...");
    menuItem.addActionListener(e -> {
        EditLayerDialog<CombinedLayer> dialog = new EditLayerDialog<>(App.this, CombinedLayer.class);
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            // TODO: get saved layer
            CombinedLayer layer = dialog.getLayer();
            if (paletteName != null) {
                layer.setPalette(paletteName);
            }
            registerCustomLayer(layer, true);
        }
    });
    customLayerMenu.add(menuItem);
    List<Class<? extends CustomLayer>> allPluginLayers = new ArrayList<>();
    for (CustomLayerProvider layerProvider : WPPluginManager.getInstance().getPlugins(CustomLayerProvider.class)) {
        allPluginLayers.addAll(layerProvider.getCustomLayers());
    }
    if (!allPluginLayers.isEmpty()) {
        customLayerMenu.addSeparator();
        for (Class<? extends CustomLayer> customLayerClass : allPluginLayers) {
            menuItem = new JMenuItem("Add a " + customLayerClass.getSimpleName() + " layer...");
            menuItem.addActionListener(e -> {
                EditLayerDialog<CustomLayer> dialog = new EditLayerDialog<>(App.this, (Class<CustomLayer>) customLayerClass);
                dialog.setVisible(true);
                if (!dialog.isCancelled()) {
                    // TODO: get saved layer
                    CustomLayer layer = dialog.getLayer();
                    if (paletteName != null) {
                        layer.setPalette(paletteName);
                    }
                    registerCustomLayer(layer, true);
                }
            });
            customLayerMenu.add(menuItem);
        }
        customLayerMenu.addSeparator();
    }
    menuItem = new JMenuItem("Import custom layer(s) from file...");
    menuItem.addActionListener(e -> importLayers(paletteName));
    customLayerMenu.add(menuItem);
    menuItem = new JMenuItem("Import custom layer(s) from another world...");
    menuItem.addActionListener(e -> importCustomItemsFromWorld(CustomItemsTreeModel.ItemType.LAYER));
    customLayerMenu.add(menuItem);
    return customLayerMenu;
}
Also used : UndergroundPocketsDialog(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsDialog) TunnelLayerDialog(org.pepsoft.worldpainter.layers.tunnel.TunnelLayerDialog) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) CustomLayerProvider(org.pepsoft.worldpainter.plugins.CustomLayerProvider) Paint(org.pepsoft.worldpainter.painting.Paint)

Example 2 with PlantLayer

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

the class TunnelLayerDialog method newFloorLayer.

private void newFloorLayer() {
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem item = new JMenuItem("Custom Objects Layer");
    item.addActionListener(e -> {
        EditLayerDialog<Bo2Layer> dialog = new EditLayerDialog(TunnelLayerDialog.this, Bo2Layer.class);
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            Bo2Layer newLayer = dialog.getLayer();
            newLayer.setHide(true);
            floorLayersTableModel.addLayer(newLayer);
        }
    });
    popupMenu.add(item);
    item = new JMenuItem("Custom Ground Cover Layer");
    item.addActionListener(e -> {
        EditLayerDialog<GroundCoverLayer> dialog = new EditLayerDialog(TunnelLayerDialog.this, GroundCoverLayer.class);
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            GroundCoverLayer newLayer = dialog.getLayer();
            newLayer.setHide(true);
            floorLayersTableModel.addLayer(newLayer);
        }
    });
    popupMenu.add(item);
    item = new JMenuItem("Custom Plants Layer");
    item.addActionListener(e -> {
        EditLayerDialog<PlantLayer> dialog = new EditLayerDialog(TunnelLayerDialog.this, PlantLayer.class);
        dialog.setVisible(true);
        if (!dialog.isCancelled()) {
            PlantLayer newLayer = dialog.getLayer();
            newLayer.setHide(true);
            floorLayersTableModel.addLayer(newLayer);
        }
    });
    popupMenu.add(item);
    popupMenu.show(buttonNewFloorLayer, buttonNewFloorLayer.getWidth(), 0);
}
Also used : PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) Bo2Layer(org.pepsoft.worldpainter.layers.Bo2Layer) EditLayerDialog(org.pepsoft.worldpainter.layers.EditLayerDialog)

Example 3 with PlantLayer

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

the class App method createCustomLayerButton.

// PaletteManager.ButtonProvider
@Override
public List<Component> createCustomLayerButton(final CustomLayer layer) {
    final List<Component> buttonComponents = createLayerButton(layer, '\0');
    final JToggleButton button = (JToggleButton) buttonComponents.get(2);
    button.setToolTipText(button.getToolTipText() + "; right-click for options");
    button.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        private void showPopup(MouseEvent e) {
            JPopupMenu popup = new JPopupMenu();
            JMenuItem menuItem = new JMenuItem(strings.getString("edit") + "...");
            menuItem.addActionListener(e1 -> edit());
            popup.add(menuItem);
            menuItem = new JMenuItem(strings.getString("remove") + "...");
            menuItem.addActionListener(e1 -> remove());
            popup.add(menuItem);
            menuItem = new JMenuItem("Export to file...");
            menuItem.addActionListener(e1 -> exportLayer(layer));
            popup.add(menuItem);
            JMenu paletteMenu = new JMenu("Move to palette");
            for (final Palette palette : paletteManager.getPalettes()) {
                menuItem = new JMenuItem(palette.getName());
                menuItem.addActionListener(e1 -> moveLayerToPalette(layer, palette));
                if (palette.contains(layer)) {
                    menuItem.setEnabled(false);
                }
                paletteMenu.add(menuItem);
            }
            menuItem = new JMenuItem("New palette...");
            menuItem.addActionListener(e1 -> createNewLayerPalette(layer));
            paletteMenu.add(menuItem);
            popup.add(paletteMenu);
            List<Action> actions = layer.getActions();
            if (actions != null) {
                for (Action action : actions) {
                    action.putValue(CustomLayer.KEY_DIMENSION, dimension);
                    popup.add(new JMenuItem(action));
                }
            }
            popup.show(button, e.getX(), e.getY());
        }

        private void edit() {
            int previousColour = layer.getColour();
            WorldPainterDialog dialog;
            if ((layer instanceof Bo2Layer) || (layer instanceof GroundCoverLayer) || (layer instanceof CombinedLayer) || (layer instanceof PlantLayer)) {
                dialog = new EditLayerDialog<Layer>(App.this, layer);
            } else if (layer instanceof UndergroundPocketsLayer) {
                dialog = new UndergroundPocketsDialog(App.this, (UndergroundPocketsLayer) layer, selectedColourScheme, dimension.getMaxHeight(), world.isExtendedBlockIds());
            } else if (layer instanceof TunnelLayer) {
                final int baseHeight, waterLevel;
                final TileFactory tileFactory = dimension.getTileFactory();
                if (tileFactory instanceof HeightMapTileFactory) {
                    baseHeight = (int) ((HeightMapTileFactory) tileFactory).getBaseHeight();
                    waterLevel = ((HeightMapTileFactory) tileFactory).getWaterHeight();
                } else {
                    baseHeight = 58;
                    waterLevel = 62;
                }
                dialog = new TunnelLayerDialog(App.this, (TunnelLayer) layer, world.isExtendedBlockIds(), selectedColourScheme, dimension.getMaxHeight(), baseHeight, waterLevel);
            } else {
                throw new RuntimeException("Don't know how to edit " + layer.getName());
            }
            dialog.setVisible(true);
            if (!dialog.isCancelled()) {
                button.setText(layer.getName());
                button.setToolTipText(layer.getName() + ": " + layer.getDescription() + "; right-click for options");
                int newColour = layer.getColour();
                boolean viewRefreshed = false;
                if (newColour != previousColour) {
                    button.setIcon(new ImageIcon(layer.getIcon()));
                    view.refreshTilesForLayer(layer, false);
                    viewRefreshed = true;
                }
                dimension.setDirty(true);
                if (layer instanceof CombinedLayer) {
                    updateHiddenLayers();
                }
                if ((layer instanceof TunnelLayer) && (!viewRefreshed)) {
                    view.refreshTilesForLayer(layer, false);
                }
            }
        }

        private void remove() {
            if (showConfirmDialog(App.this, MessageFormat.format(strings.getString("are.you.sure.you.want.to.remove.the.0.layer"), layer.getName()), MessageFormat.format(strings.getString("confirm.0.removal"), layer.getName()), YES_NO_OPTION) == YES_OPTION) {
                deleteCustomLayer(layer);
                // Doesn't happen automatically for some reason; Swing bug?
                App.this.validate();
            }
        }
    });
    return buttonComponents;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) UI_SCALE(org.pepsoft.util.GUIUtils.UI_SCALE) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) TunnelLayerDialog(org.pepsoft.worldpainter.layers.tunnel.TunnelLayerDialog) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) Paint(org.pepsoft.worldpainter.painting.Paint) DockableFrame(com.jidesoft.docking.DockableFrame) org.pepsoft.worldpainter.painting(org.pepsoft.worldpainter.painting) SET_SPAWN_POINT(org.pepsoft.worldpainter.Platform.Capability.SET_SPAWN_POINT) BiomeSchemeManager(org.pepsoft.worldpainter.biomeschemes.BiomeSchemeManager) Timer(javax.swing.Timer) Void(java.lang.Void) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) InfoPanel(org.pepsoft.worldpainter.panels.InfoPanel) KeyEvent(java.awt.event.KeyEvent) AffineTransform(java.awt.geom.AffineTransform) Box(javax.swing.Box) InvocationTargetException(java.lang.reflect.InvocationTargetException) Direction(org.pepsoft.minecraft.Direction) org.pepsoft.worldpainter.operations(org.pepsoft.worldpainter.operations) Brush(org.pepsoft.worldpainter.brushes.Brush) PropertyChangeListener(java.beans.PropertyChangeListener) SymmetricBrush(org.pepsoft.worldpainter.brushes.SymmetricBrush) EmptyBorder(javax.swing.border.EmptyBorder) GZIPOutputStream(java.util.zip.GZIPOutputStream) CustomItemsTreeModel(org.pepsoft.worldpainter.importing.CustomItemsTreeModel) GardenOfEdenOperation(org.pepsoft.worldpainter.gardenofeden.GardenOfEdenOperation) java.util(java.util) SimpleDateFormat(java.text.SimpleDateFormat) DOCK_SIDE_WEST(com.jidesoft.docking.DockContext.DOCK_SIDE_WEST) BrushOptions(org.pepsoft.worldpainter.panels.BrushOptions) AffineTransformOp(java.awt.image.AffineTransformOp) MapImportDialog(org.pepsoft.worldpainter.importing.MapImportDialog) com.jidesoft.docking(com.jidesoft.docking) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush) BetterAction(org.pepsoft.worldpainter.util.BetterAction) ScriptRunner(org.pepsoft.worldpainter.tools.scripts.ScriptRunner) BevelBorder(javax.swing.border.BevelBorder) FileFilter(javax.swing.filechooser.FileFilter) CustomLayerProvider(org.pepsoft.worldpainter.plugins.CustomLayerProvider) java.awt(java.awt) RemoteJCheckBox(org.pepsoft.util.swing.RemoteJCheckBox) LayoutUtils(org.pepsoft.worldpainter.util.LayoutUtils) WPPluginManager(org.pepsoft.worldpainter.plugins.WPPluginManager) RespawnPlayerDialog(org.pepsoft.worldpainter.tools.RespawnPlayerDialog) URL(java.net.URL) EventVO(org.pepsoft.worldpainter.vo.EventVO) PropertyVetoException(java.beans.PropertyVetoException) TiledImageViewerContainer(org.pepsoft.util.swing.TiledImageViewerContainer) FLUIDS_AS_LAYER(org.pepsoft.worldpainter.TileRenderer.FLUIDS_AS_LAYER) CustomBiomeListener(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager.CustomBiomeListener) PlatformManager(org.pepsoft.worldpainter.plugins.PlatformManager) Material(org.pepsoft.minecraft.Material) BackupUtil(org.pepsoft.worldpainter.util.BackupUtil) BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush) UndergroundPocketsDialog(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsDialog) ImageIO(javax.imageio.ImageIO) WorldHistoryDialog(org.pepsoft.worldpainter.history.WorldHistoryDialog) BufferedImage(java.awt.image.BufferedImage) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) Collectors(java.util.stream.Collectors) JideLabel(com.jidesoft.swing.JideLabel) ProgressTask(org.pepsoft.util.swing.ProgressTask) List(java.util.List) Constants(org.pepsoft.minecraft.Constants) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) org.pepsoft.worldpainter.selection(org.pepsoft.worldpainter.selection) java.awt.event(java.awt.event) BIOMES(org.pepsoft.worldpainter.Platform.Capability.BIOMES) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) org.pepsoft.util(org.pepsoft.util) NonNls(org.jetbrains.annotations.NonNls) org.pepsoft.worldpainter.layers(org.pepsoft.worldpainter.layers) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) BufferedImageOp(java.awt.image.BufferedImageOp) ThreeDeeFrame(org.pepsoft.worldpainter.threedeeview.ThreeDeeFrame) MessageFormat(java.text.MessageFormat) VoidRenderer(org.pepsoft.worldpainter.layers.renderers.VoidRenderer) UndoManager(org.pepsoft.util.undo.UndoManager) UsageVO(org.pepsoft.worldpainter.vo.UsageVO) PropertyChangeEvent(java.beans.PropertyChangeEvent) Constants(org.pepsoft.worldpainter.Constants) TERRAIN_AS_LAYER(org.pepsoft.worldpainter.TileRenderer.TERRAIN_AS_LAYER) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) AttributeKeyVO(org.pepsoft.worldpainter.vo.AttributeKeyVO) MalformedURLException(java.net.MalformedURLException) BiomesViewerFrame(org.pepsoft.worldpainter.tools.BiomesViewerFrame) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) HistoryEntry(org.pepsoft.worldpainter.history.HistoryEntry) JOptionPane(javax.swing.JOptionPane) Terrain(org.pepsoft.worldpainter.Terrain) DOCK_SIDE_EAST(com.jidesoft.docking.DockContext.DOCK_SIDE_EAST) URLEncoder(java.net.URLEncoder) java.io(java.io) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) WritableRaster(java.awt.image.WritableRaster) ImportMaskDialog(org.pepsoft.worldpainter.importing.ImportMaskDialog) ImportCustomItemsDialog(org.pepsoft.worldpainter.importing.ImportCustomItemsDialog) javax.swing(javax.swing) BetterAction(org.pepsoft.worldpainter.util.BetterAction) UndergroundPocketsDialog(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsDialog) List(java.util.List) java.awt.event(java.awt.event) TunnelLayerDialog(org.pepsoft.worldpainter.layers.tunnel.TunnelLayerDialog) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)

Aggregations

GroundCoverLayer (org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)2 PlantLayer (org.pepsoft.worldpainter.layers.plants.PlantLayer)2 com.jidesoft.docking (com.jidesoft.docking)1 DOCK_SIDE_EAST (com.jidesoft.docking.DockContext.DOCK_SIDE_EAST)1 DOCK_SIDE_WEST (com.jidesoft.docking.DockContext.DOCK_SIDE_WEST)1 DockableFrame (com.jidesoft.docking.DockableFrame)1 JideLabel (com.jidesoft.swing.JideLabel)1 java.awt (java.awt)1 java.awt.event (java.awt.event)1 KeyEvent (java.awt.event.KeyEvent)1 AffineTransform (java.awt.geom.AffineTransform)1 AffineTransformOp (java.awt.image.AffineTransformOp)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedImageOp (java.awt.image.BufferedImageOp)1 WritableRaster (java.awt.image.WritableRaster)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyVetoException (java.beans.PropertyVetoException)1 java.io (java.io)1 Void (java.lang.Void)1