Search in sources :

Example 6 with Layer

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

the class TunnelFloorLayersTableModel method removeLayer.

public void removeLayer(int row) {
    Layer layer = layers.remove(row);
    settings.remove(layer);
    TableModelEvent event = new TableModelEvent(this, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE);
    for (TableModelListener listener : listeners) {
        listener.tableChanged(event);
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener) Layer(org.pepsoft.worldpainter.layers.Layer)

Example 7 with Layer

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

the class TunnelFloorLayersTableModel method setValueAt.

@Override
public void setValueAt(Object value, int row, int column) {
    Layer layer = layers.get(row);
    TunnelLayer.LayerSettings layerSettings = settings.get(layer);
    switch(column) {
        case COLUMN_INTENSITY:
            layerSettings.setIntensity(MathUtils.clamp(0, (Integer) value, 100));
            break;
        case COLUMN_VARIATION:
            layerSettings.setVariation((NoiseSettings) value);
            break;
        case COLUMN_MIN_LEVEL:
            layerSettings.setMinLevel(MathUtils.clamp(0, (Integer) value, layerSettings.getMaxLevel()));
            break;
        case COLUMN_MAX_LEVEL:
            layerSettings.setMaxLevel(MathUtils.clamp(layerSettings.getMinLevel(), (Integer) value, maxHeight - 1));
            break;
        default:
            throw new IndexOutOfBoundsException("column: " + column);
    }
}
Also used : Layer(org.pepsoft.worldpainter.layers.Layer)

Example 8 with Layer

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

the class TunnelLayerDialog method saveSettingsTo.

private void saveSettingsTo(TunnelLayer layer, boolean registerMaterials) {
    layer.setFloorLevel((Integer) spinnerFloorLevel.getValue());
    layer.setFloorMin((Integer) spinnerFloorMin.getValue());
    layer.setFloorMax((Integer) spinnerFloorMax.getValue());
    MixedMaterial floorMaterial = mixedMaterialSelectorFloor.getMaterial();
    if ((floorMaterial != null) && registerMaterials) {
        // Make sure the material is registered, in case it's new
        floorMaterial = MixedMaterialManager.getInstance().register(floorMaterial);
    }
    layer.setFloorMaterial(floorMaterial);
    if (radioButtonFloorFixedDepth.isSelected()) {
        layer.setFloorMode(Mode.CONSTANT_DEPTH);
    } else if (radioButtonFloorFixedLevel.isSelected()) {
        layer.setFloorMode(Mode.FIXED_HEIGHT);
    } else {
        layer.setFloorMode(Mode.INVERTED_DEPTH);
    }
    NoiseSettings floorNoiseSettings = noiseSettingsEditorFloor.getNoiseSettings();
    if (floorNoiseSettings.getRange() == 0) {
        layer.setFloorNoise(null);
    } else {
        layer.setFloorNoise(floorNoiseSettings);
    }
    layer.setRoofLevel((Integer) spinnerRoofLevel.getValue());
    layer.setRoofMin((Integer) spinnerRoofMin.getValue());
    layer.setRoofMax((Integer) spinnerRoofMax.getValue());
    MixedMaterial roofMaterial = mixedMaterialSelectorRoof.getMaterial();
    if ((roofMaterial != null) && registerMaterials) {
        // Make sure the material is registered, in case it's new
        roofMaterial = MixedMaterialManager.getInstance().register(roofMaterial);
    }
    layer.setRoofMaterial(roofMaterial);
    if (radioButtonRoofFixedDepth.isSelected()) {
        layer.setRoofMode(Mode.CONSTANT_DEPTH);
    } else if (radioButtonRoofFixedLevel.isSelected()) {
        layer.setRoofMode(Mode.FIXED_HEIGHT);
    } else {
        layer.setRoofMode(Mode.INVERTED_DEPTH);
    }
    NoiseSettings roofNoiseSettings = noiseSettingsEditorRoof.getNoiseSettings();
    if (roofNoiseSettings.getRange() == 0) {
        layer.setRoofNoise(null);
    } else {
        layer.setRoofNoise(roofNoiseSettings);
    }
    layer.setFloorWallDepth((Integer) spinnerWallFloorDepth.getValue());
    layer.setRoofWallDepth((Integer) spinnerWallRoofDepth.getValue());
    MixedMaterial wallMaterial = mixedMaterialSelectorWall.getMaterial();
    if ((wallMaterial != null) && registerMaterials) {
        // Make sure the material is registered, in case it's new
        wallMaterial = MixedMaterialManager.getInstance().register(wallMaterial);
    }
    layer.setWallMaterial(wallMaterial);
    layer.setName(textFieldName.getText().trim());
    layer.setColour(colourEditor1.getColour());
    layer.setRemoveWater(checkBoxRemoveWater.isSelected());
    layer.setFloodLevel(checkBoxFlood.isSelected() ? (Integer) spinnerFloodLevel.getValue() : 0);
    layer.setFloodWithLava(checkBoxFloodWithLava.isSelected());
    Map<Layer, TunnelLayer.LayerSettings> floorLayers = floorLayersTableModel.getLayers();
    layer.setFloorLayers(((floorLayers != null) && (!floorLayers.isEmpty())) ? floorLayers : null);
}
Also used : NoiseSettings(org.pepsoft.worldpainter.NoiseSettings) 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) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 9 with Layer

use of org.pepsoft.worldpainter.layers.Layer 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 10 with Layer

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

the class DimensionPainter method fill.

/**
 * Flood fill an area of the dimension with the current paint. The area to be flooded is the area where the type of
 * paint has the same value as where the fill is started. If the value is already the same as the configured paint,
 * nothing happens. If the operation takes more than two seconds a modal dialog is shown to the user with an
 * indeterminate progress bar.
 *
 * @param x The X coordinate to start the flood fill.
 * @param y The Y coordinate to start the flood fill.
 * @param parent The window to use as parent for the modal dialog shown if the operation takes more than two
 *               seconds.
 */
public void fill(Dimension dimension, final int x, final int y, Window parent) {
    AbstractDimensionPaintFillMethod fillMethod;
    if (paint instanceof LayerPaint) {
        final Layer layer = ((LayerPaint) paint).getLayer();
        switch(layer.getDataSize()) {
            case BIT:
            case BIT_PER_CHUNK:
                if (undo) {
                    fillMethod = new UndoDimensionPaintFillMethod("Removing " + layer, dimension, paint) {

                        @Override
                        public boolean isBoundary(int x, int y) {
                            return !dimension.getBitLayerValueAt(layer, x, y);
                        }
                    };
                } else {
                    fillMethod = new DimensionPaintFillMethod("Applying " + layer, dimension, paint) {

                        @Override
                        public boolean isBoundary(int x, int y) {
                            return dimension.getBitLayerValueAt(layer, x, y);
                        }
                    };
                }
                break;
            case NIBBLE:
            case BYTE:
                if (paint instanceof DiscreteLayerPaint) {
                    final int fillValue = dimension.getLayerValueAt(layer, x, y);
                    if (undo) {
                        fillMethod = new UndoDimensionPaintFillMethod("Removing " + layer, dimension, paint) {

                            @Override
                            public boolean isBoundary(int x, int y) {
                                return dimension.getLayerValueAt(layer, x, y) != fillValue;
                            }

                            @Override
                            boolean isFilled(int x, int y) {
                                return dimension.getLayerValueAt(layer, x, y) == layer.getDefaultValue();
                            }
                        };
                    } else {
                        fillMethod = new DimensionPaintFillMethod("Applying " + layer, dimension, paint) {

                            @Override
                            public boolean isBoundary(int x, int y) {
                                return dimension.getLayerValueAt(layer, x, y) != fillValue;
                            }

                            @Override
                            boolean isFilled(int x, int y) {
                                return dimension.getLayerValueAt(layer, x, y) == ((DiscreteLayerPaint) paint).getValue();
                            }
                        };
                    }
                } else {
                    if (undo) {
                        fillMethod = new UndoDimensionPaintFillMethod("Removing " + layer, dimension, paint) {

                            @Override
                            public boolean isBoundary(int x, int y) {
                                return dimension.getLayerValueAt(layer, x, y) == 0;
                            }
                        };
                    } else {
                        fillMethod = new DimensionPaintFillMethod("Applying " + layer, dimension, paint) {

                            @Override
                            public boolean isBoundary(int x, int y) {
                                return dimension.getLayerValueAt(layer, x, y) >= targetValue;
                            }

                            final int targetValue = 1 + (int) ((layer.getDataSize() == Layer.DataSize.NIBBLE) ? (paint.getBrush().getLevel() * 14 + 0.5f) : (paint.getBrush().getLevel() * 254 + 0.5f));
                        };
                    }
                }
                break;
            default:
                throw new IllegalArgumentException("Don't know how to fill with layer with data size " + layer.getDataSize());
        }
    } else if (paint instanceof TerrainPaint) {
        final Terrain terrainToFill = dimension.getTerrainAt(x, y);
        if (undo) {
            fillMethod = new UndoDimensionPaintFillMethod("Removing " + terrainToFill, dimension, paint) {

                @Override
                public boolean isBoundary(int x, int y) {
                    return dimension.getTerrainAt(x, y) != terrainToFill;
                }

                @Override
                boolean isFilled(int x, int y) {
                    return dimension.getTerrainAt(x, y) == ((TerrainPaint) paint).getTerrain();
                }
            };
        } else {
            fillMethod = new DimensionPaintFillMethod("Applying " + ((TerrainPaint) paint).getTerrain(), dimension, paint) {

                @Override
                public boolean isBoundary(int x, int y) {
                    return dimension.getTerrainAt(x, y) != terrainToFill;
                }

                @Override
                boolean isFilled(int x, int y) {
                    return dimension.getTerrainAt(x, y) == ((TerrainPaint) paint).getTerrain();
                }
            };
        }
    } else if (paint instanceof PaintFactory.NullPaint) {
        return;
    } else {
        throw new IllegalArgumentException("Don't know how to fill with paint " + paint);
    }
    if (!fillMethod.isFilled(x, y)) {
        GeneralQueueLinearFloodFiller filler = new GeneralQueueLinearFloodFiller(fillMethod);
        filler.floodFill(x, y, parent);
    }
}
Also used : Layer(org.pepsoft.worldpainter.layers.Layer) Terrain(org.pepsoft.worldpainter.Terrain)

Aggregations

Layer (org.pepsoft.worldpainter.layers.Layer)34 CustomLayer (org.pepsoft.worldpainter.layers.CustomLayer)9 Map (java.util.Map)8 ProgressReceiver (org.pepsoft.util.ProgressReceiver)7 HashMap (java.util.HashMap)6 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)5 ExporterSettings (org.pepsoft.worldpainter.layers.exporters.ExporterSettings)5 Point (java.awt.Point)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SubProgressReceiver (org.pepsoft.util.SubProgressReceiver)4 TILE_SIZE (org.pepsoft.worldpainter.Constants.TILE_SIZE)4 Biome (org.pepsoft.worldpainter.layers.Biome)4 Bo2Layer (org.pepsoft.worldpainter.layers.Bo2Layer)4 CombinedLayer (org.pepsoft.worldpainter.layers.CombinedLayer)4 GroundCoverLayer (org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)4 PlantLayer (org.pepsoft.worldpainter.layers.plants.PlantLayer)4 File (java.io.File)3 Arrays (java.util.Arrays)3 BitSet (java.util.BitSet)3