use of org.pepsoft.worldpainter.plugins.CustomLayerProvider 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;
}
Aggregations