Search in sources :

Example 1 with BiomeHelper

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

the class BrushOptions method setFilter.

public void setFilter(DefaultFilter filter) {
    if (filter == null) {
        checkBoxInSelection.setSelected(false);
        checkBoxOutsideSelection.setSelected(false);
        checkBoxAbove.setSelected(false);
        checkBoxBelow.setSelected(false);
        checkBoxReplace.setSelected(false);
        checkBoxExceptOn.setSelected(false);
        checkBoxAboveSlope.setSelected(false);
        checkBoxBelowSlope.setSelected(false);
    } else {
        checkBoxInSelection.setSelected(filter.inSelection);
        checkBoxOutsideSelection.setSelected(filter.outsideSelection);
        checkBoxAbove.setSelected(filter.levelType == LevelType.ABOVE || filter.levelType == LevelType.BETWEEN || filter.levelType == LevelType.OUTSIDE);
        if (filter.aboveLevel >= 0) {
            spinnerAbove.setValue(filter.aboveLevel);
        }
        checkBoxBelow.setSelected(filter.levelType == LevelType.BELOW || filter.levelType == LevelType.BETWEEN || filter.levelType == LevelType.OUTSIDE);
        if (filter.belowLevel >= 0) {
            spinnerBelow.setValue(filter.belowLevel);
        }
        checkBoxAboveSlope.setSelected(filter.checkSlope && filter.slopeIsAbove);
        checkBoxBelowSlope.setSelected(filter.checkSlope && (!filter.slopeIsAbove));
        if (filter.degrees >= 0) {
            spinnerSlope.setValue(filter.degrees);
        }
        checkBoxReplace.setSelected(filter.onlyOnObjectType != null);
        checkBoxExceptOn.setSelected(filter.exceptOnObjectType != null);
        final App app = App.getInstance();
        if (filter.onlyOnObjectType != null) {
            switch(filter.onlyOnObjectType) {
                case BIOME:
                    int biome = filter.onlyOnValue;
                    BiomeHelper biomeHelper = new BiomeHelper(autoBiomeScheme, app.getColourScheme(), app.getCustomBiomeManager());
                    onlyOn = biome;
                    buttonReplace.setText(biomeHelper.getBiomeName(biome));
                    buttonReplace.setIcon(biomeHelper.getBiomeIcon(biome));
                    break;
                case BIT_LAYER:
                case INT_LAYER_ANY:
                    Layer layer = filter.onlyOnLayer;
                    onlyOn = layer;
                    buttonReplace.setText(layer.getName());
                    buttonReplace.setIcon(new ImageIcon(layer.getIcon()));
                    break;
                case TERRAIN:
                    Terrain terrain = filter.onlyOnTerrain;
                    ColourScheme colourScheme = app.getColourScheme();
                    onlyOn = terrain;
                    buttonReplace.setText(terrain.getName());
                    buttonReplace.setIcon(new ImageIcon(terrain.getIcon(colourScheme)));
                    break;
                case WATER:
                    onlyOn = DefaultFilter.WATER;
                    buttonReplace.setText("Water");
                    buttonReplace.setIcon(null);
                    break;
                case LAND:
                    onlyOn = DefaultFilter.LAND;
                    buttonReplace.setText("Land");
                    buttonReplace.setIcon(null);
                    break;
                case ANNOTATION:
                    int selectedColour = filter.onlyOnValue, dataValue = selectedColour - ((selectedColour < 8) ? 1 : 0);
                    onlyOn = new DefaultFilter.LayerValue(Annotations.INSTANCE, selectedColour);
                    buttonReplace.setText(Constants.COLOUR_NAMES[dataValue] + " Annotations");
                    buttonReplace.setIcon(IconUtils.createScaledColourIcon(app.getColourScheme().getColour(Constants.BLK_WOOL, dataValue)));
                    break;
                case ANNOTATION_ANY:
                    onlyOn = new DefaultFilter.LayerValue(Annotations.INSTANCE);
                    buttonReplace.setText("All Annotations");
                    buttonReplace.setIcon(null);
                    break;
            }
        }
        if (filter.exceptOnObjectType != null) {
            switch(filter.exceptOnObjectType) {
                case BIOME:
                    int biome = filter.exceptOnValue;
                    BiomeHelper biomeHelper = new BiomeHelper(autoBiomeScheme, app.getColourScheme(), app.getCustomBiomeManager());
                    exceptOn = biome;
                    buttonExceptOn.setText(biomeHelper.getBiomeName(biome));
                    buttonExceptOn.setIcon(biomeHelper.getBiomeIcon(biome));
                    break;
                case BIT_LAYER:
                case INT_LAYER_ANY:
                    Layer layer = filter.exceptOnLayer;
                    exceptOn = layer;
                    buttonExceptOn.setText(layer.getName());
                    buttonExceptOn.setIcon(new ImageIcon(layer.getIcon()));
                    break;
                case TERRAIN:
                    Terrain terrain = filter.exceptOnTerrain;
                    ColourScheme colourScheme = app.getColourScheme();
                    exceptOn = terrain;
                    buttonExceptOn.setText(terrain.getName());
                    buttonExceptOn.setIcon(new ImageIcon(terrain.getIcon(colourScheme)));
                    break;
                case WATER:
                    exceptOn = DefaultFilter.WATER;
                    buttonExceptOn.setText("Water");
                    buttonExceptOn.setIcon(null);
                    break;
                case LAND:
                    exceptOn = DefaultFilter.LAND;
                    buttonExceptOn.setText("Land");
                    buttonExceptOn.setIcon(null);
                    break;
                case ANNOTATION:
                    int selectedColour = filter.exceptOnValue, dataValue = selectedColour - ((selectedColour < 8) ? 1 : 0);
                    exceptOn = new DefaultFilter.LayerValue(Annotations.INSTANCE, selectedColour);
                    buttonExceptOn.setText(Constants.COLOUR_NAMES[dataValue] + " Annotations");
                    buttonExceptOn.setIcon(IconUtils.createScaledColourIcon(app.getColourScheme().getColour(Constants.BLK_WOOL, dataValue)));
                    break;
                case ANNOTATION_ANY:
                    exceptOn = new DefaultFilter.LayerValue(Annotations.INSTANCE);
                    buttonExceptOn.setText("All Annotations");
                    buttonExceptOn.setIcon(null);
                    break;
            }
        }
    }
    setControlStates();
}
Also used : BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper)

Example 2 with BiomeHelper

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

BiomeHelper (org.pepsoft.worldpainter.biomeschemes.BiomeHelper)2 java.awt (java.awt)1 ActionEvent (java.awt.event.ActionEvent)1 java.util (java.util)1 List (java.util.List)1 javax.swing (javax.swing)1 NumberEditor (javax.swing.JSpinner.NumberEditor)1 Constants (org.pepsoft.minecraft.Constants)1 IconUtils (org.pepsoft.util.IconUtils)1 ObservableBoolean (org.pepsoft.util.ObservableBoolean)1 org.pepsoft.worldpainter (org.pepsoft.worldpainter)1 Dimension (org.pepsoft.worldpainter.Dimension)1 AutoBiomeScheme (org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme)1 CustomBiome (org.pepsoft.worldpainter.biomeschemes.CustomBiome)1 CustomBiomeManager (org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager)1 org.pepsoft.worldpainter.layers (org.pepsoft.worldpainter.layers)1 Filter (org.pepsoft.worldpainter.operations.Filter)1 LevelType (org.pepsoft.worldpainter.panels.DefaultFilter.LevelType)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1