Search in sources :

Example 6 with DynMapColourScheme

use of org.pepsoft.worldpainter.colourschemes.DynMapColourScheme 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)

Aggregations

DynMapColourScheme (org.pepsoft.worldpainter.colourschemes.DynMapColourScheme)6 JFrame (javax.swing.JFrame)3 File (java.io.File)2 Random (java.util.Random)2 ColourScheme (org.pepsoft.worldpainter.ColourScheme)2 AutoBiomeScheme (org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme)2 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ImageIcon (javax.swing.ImageIcon)1 JLabel (javax.swing.JLabel)1 Timer (javax.swing.Timer)1 UnsupportedLookAndFeelException (javax.swing.UnsupportedLookAndFeelException)1 RegionFile (org.pepsoft.minecraft.RegionFile)1 TiledImageViewer (org.pepsoft.util.swing.TiledImageViewer)1 org.pepsoft.worldpainter (org.pepsoft.worldpainter)1 Configuration (org.pepsoft.worldpainter.Configuration)1 HeightMapTileFactory (org.pepsoft.worldpainter.HeightMapTileFactory)1 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)1