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);
}
}
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);
}
}
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);
}
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);
}
}
}
}
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);
}
}
Aggregations