Search in sources :

Example 1 with AutoBiomeScheme

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

the class TileFactoryPreviewer method main.

public static void main(String[] args) {
    final long seed;
    if (args.length > 0) {
        seed = Long.parseLong(args[0]);
    } else {
        seed = new Random().nextLong();
    }
    // final ExperimentalTileFactory tileFactory = new ExperimentalTileFactory(DEFAULT_MAX_HEIGHT_2);
    // final HeightMapTileFactory tileFactory = TileFactoryFactory.createNoiseTileFactory(Terrain.GRASS, World2.DEFAULT_MAX_HEIGHT, 58, 62, false, true, 20.0f, 1.0);
    // HeightMap oceanFloor = new ConstantHeightMap(40f);
    // HeightMap continent;
    // //        continent = new NinePatchHeightMap(200, 100, 50, 58f);
    // continent = new NinePatchHeightMap(0, 1000, 50, 22f);
    // HeightMap hills = new ProductHeightMap(
    // new NoiseHeightMap(1.0f, 10f, 1),
    // new SumHeightMap(
    // new NoiseHeightMap(20.0f, 1.0f, 2),
    // new ConstantHeightMap(-5f)));
    // continent = new SumHeightMap(
    // new SumHeightMap(
    // oceanFloor,
    // continent),
    // hills);
    // HeightMap mountainsLimit = new NinePatchHeightMap(0, 1000, 200, 1f);
    // HeightMap mountains = new ProductHeightMap(
    // new ProductHeightMap(
    // new NoiseHeightMap(1.0f, 10f, 1),
    // mountainsLimit),
    // new NoiseHeightMap(256f, 5f, 4));
    // HeightMap heightMap = new MaximisingHeightMap(continent, mountains);
    // final HeightMapTileFactory tileFactory = new HeightMapTileFactory(seed, heightMap, 256, false, new FancyTheme(256, 62, heightMap));
    final HeightMapTileFactory tileFactory = TileFactoryFactory.createFancyTileFactory(seed, Terrain.GRASS, Constants.DEFAULT_MAX_HEIGHT_2, 62, 58, false, 20f, 1.0);
    // SortedMap<Integer, Terrain> terrainRanges = tileFactory.getTerrainRanges();
    // terrainRanges.clear();
    // terrainRanges.put( -1, Terrain.DIRT);
    // terrainRanges.put( 64, Terrain.GRASS);
    // terrainRanges.put(128, Terrain.ROCK);
    // terrainRanges.put(192, Terrain.DEEP_SNOW);
    // tileFactory.setTerrainRanges(terrainRanges);
    final org.pepsoft.worldpainter.TileProvider tileProvider = new org.pepsoft.worldpainter.TileProvider() {

        @Override
        public Rectangle getExtent() {
            // Tile factories are endless
            return null;
        }

        @Override
        public boolean isTilePresent(int x, int y) {
            // Tile factories are endless and have no holes
            return true;
        }

        @Override
        public Tile getTile(int x, int y) {
            Point coords = new Point(x, y);
            synchronized (cache) {
                Tile tile = cache.get(coords);
                if (tile == null) {
                    tile = tileFactory.createTile(x, y);
                    cache.put(coords, tile);
                }
                return tile;
            }
        }

        private final Map<Point, Tile> cache = new HashMap<>();
    };
    Terrain.setCustomMaterial(0, new MixedMaterial("Dirt/Gravel", new Row[] { new Row(Material.DIRT, 750, 1.0f), new Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f));
    Terrain.setCustomMaterial(1, new MixedMaterial("Stone/Gravel", new Row[] { new Row(Material.STONE, 750, 1.0f), new Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f));
    TiledImageViewer viewer = new TiledImageViewer();
    JFrame frame = new JFrame("TileFactory Previewer");
    viewer.setTileProvider(new WPTileProvider(tileProvider, new DynMapColourScheme("default", true), new AutoBiomeScheme(null), null, Collections.singleton((Layer) Biome.INSTANCE), true, 10, TileRenderer.LightOrigin.NORTHWEST, false, null));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(viewer, BorderLayout.CENTER);
    frame.setSize(1000, 800);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
Also used : AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) TiledImageViewer(org.pepsoft.util.swing.TiledImageViewer) Tile(org.pepsoft.worldpainter.Tile) Point(java.awt.Point) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) WPTileProvider(org.pepsoft.worldpainter.WPTileProvider) Random(java.util.Random) JFrame(javax.swing.JFrame) HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory) Row(org.pepsoft.worldpainter.MixedMaterial.Row) WPTileProvider(org.pepsoft.worldpainter.WPTileProvider) HashMap(java.util.HashMap) Map(java.util.Map) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 2 with AutoBiomeScheme

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

the class HeightMapEditor method installHeightMap.

private void installHeightMap(boolean updateTreeModel) {
    switch(viewMode) {
        case HEIGHT_MAP:
            if (tiledImageViewer1.getTileProviderCount() == 0) {
                tiledImageViewer1.setTileProvider(new HeightMapTileProvider(focusHeightMap));
            } else {
                tiledImageViewer1.replaceTileProvider(0, new HeightMapTileProvider(focusHeightMap));
            }
            tiledImageViewer1.setGridColour(Color.GRAY);
            break;
        case TERRAIN:
            TileFactory tileFactory = new HeightMapTileFactory(seed, focusHeightMap, Constants.DEFAULT_MAX_HEIGHT_2, false, theme);
            synchronized (tileCache) {
                tileCache.clear();
            }
            final org.pepsoft.worldpainter.TileProvider tileProvider = new org.pepsoft.worldpainter.TileProvider() {

                @Override
                public Rectangle getExtent() {
                    // Tile factories are endless
                    return null;
                }

                @Override
                public boolean isTilePresent(int x, int y) {
                    // Tile factories are endless and have no holes
                    return true;
                }

                @Override
                public Tile getTile(int x, int y) {
                    Point coords = new Point(x, y);
                    Tile tile;
                    synchronized (tileCache) {
                        tile = tileCache.get(coords);
                        if (tile == RENDERING) {
                            do {
                                try {
                                    tileCache.wait();
                                    tile = tileCache.get(coords);
                                } catch (InterruptedException e) {
                                    throw new RuntimeException("Thread interrupted while waiting for tile to be rendered");
                                }
                            } while (tileCache.get(coords) == RENDERING);
                        }
                        if (tile == null) {
                            tileCache.put(coords, RENDERING);
                        }
                    }
                    if (tile == null) {
                        tile = tileFactory.createTile(x, y);
                        synchronized (tileCache) {
                            tileCache.put(coords, tile);
                            tileCache.notifyAll();
                        }
                    }
                    return tile;
                }
            };
            if (tiledImageViewer1.getTileProviderCount() == 0) {
                tiledImageViewer1.setTileProvider(0, new WPTileProvider(tileProvider, new DynMapColourScheme("default", true), new AutoBiomeScheme(null), null, Collections.singleton((Layer) Biome.INSTANCE), false, 10, TileRenderer.LightOrigin.NORTHWEST, false, null));
            } else {
                tiledImageViewer1.replaceTileProvider(0, new WPTileProvider(tileProvider, new DynMapColourScheme("default", true), new AutoBiomeScheme(null), null, Collections.singleton((Layer) Biome.INSTANCE), false, 10, TileRenderer.LightOrigin.NORTHWEST, false, null));
            }
            tiledImageViewer1.setGridColour(Color.BLACK);
            break;
    }
    if (updateTreeModel) {
        treeModel = new HeightMapTreeModel(rootHeightMap);
        jTree1.setModel(treeModel);
    }
}
Also used : AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) HeightMapTreeModel(org.pepsoft.worldpainter.heightMaps.gui.HeightMapTreeModel) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) HeightMapTileProvider(org.pepsoft.worldpainter.heightMaps.gui.HeightMapTileProvider) HeightMapTileProvider(org.pepsoft.worldpainter.heightMaps.gui.HeightMapTileProvider) org.pepsoft.worldpainter(org.pepsoft.worldpainter)

Example 3 with AutoBiomeScheme

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

the class BrushOptions method initialiseIfNecessary.

private void initialiseIfNecessary() {
    if (!initialised) {
        // Prevent the intensity being changed when somebody tries to type a
        // value:
        Action nullAction = new AbstractAction("Do nothing") {

            @Override
            public void actionPerformed(ActionEvent e) {
            // Do nothing
            }

            private static final long serialVersionUID = 1L;
        };
        getActionMap().put("doNothing", nullAction);
        InputMap inputMap = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        App app = App.getInstance();
        inputMap.put(app.ACTION_INTENSITY_10_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_20_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_30_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_40_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_50_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_60_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_70_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_80_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_90_PERCENT.getAcceleratorKey(), "doNothing");
        inputMap.put(app.ACTION_INTENSITY_100_PERCENT.getAcceleratorKey(), "doNothing");
        autoBiomeScheme = new AutoBiomeScheme(null);
        initialised = true;
    }
}
Also used : AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) ActionEvent(java.awt.event.ActionEvent)

Example 4 with AutoBiomeScheme

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

AutoBiomeScheme (org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme)4 ActionEvent (java.awt.event.ActionEvent)2 org.pepsoft.worldpainter (org.pepsoft.worldpainter)2 DynMapColourScheme (org.pepsoft.worldpainter.colourschemes.DynMapColourScheme)2 java.awt (java.awt)1 Point (java.awt.Point)1 java.util (java.util)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 javax.swing (javax.swing)1 JFrame (javax.swing.JFrame)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 TiledImageViewer (org.pepsoft.util.swing.TiledImageViewer)1 Dimension (org.pepsoft.worldpainter.Dimension)1 HeightMapTileFactory (org.pepsoft.worldpainter.HeightMapTileFactory)1