Search in sources :

Example 1 with DiceImageFactory

use of games.strategy.triplea.image.DiceImageFactory in project triplea by triplea-game.

the class HeadedUiContext method internalSetMapDir.

@Override
protected void internalSetMapDir(final String dir, final GameData data) {
    final Stopwatch stopWatch = new Stopwatch(logger, Level.FINE, "Loading UI Context");
    resourceLoader = ResourceLoader.getMapResourceLoader(dir);
    if (mapData != null) {
        mapData.close();
    }
    mapData = new MapData(resourceLoader);
    // DiceImageFactory needs loader and game data
    diceImageFactory = new DiceImageFactory(resourceLoader, data.getDiceSides());
    final double unitScale = getPreferencesMapOrSkin(dir).getDouble(UNIT_SCALE_PREF, mapData.getDefaultUnitScale());
    scale = getPreferencesMapOrSkin(dir).getDouble(MAP_SCALE_PREF, 1);
    if (scale < 1) {
        setDrawTerritoryBordersAgainToMedium();
    }
    unitImageFactory.setResourceLoader(resourceLoader, unitScale, mapData.getDefaultUnitWidth(), mapData.getDefaultUnitHeight(), mapData.getDefaultUnitCounterOffsetWidth(), mapData.getDefaultUnitCounterOffsetHeight());
    // TODO: separate scale for resources
    resourceImageFactory.setResourceLoader(resourceLoader);
    territoryEffectImageFactory.setResourceLoader(resourceLoader);
    flagIconImageFactory.setResourceLoader(resourceLoader);
    puImageFactory.setResourceLoader(resourceLoader);
    tileImageFactory.setMapDir(resourceLoader);
    tileImageFactory.setScale(scale);
    // load map data
    mapImage.loadMaps(resourceLoader);
    mapDir = dir;
    drawTerritoryEffects = mapData.useTerritoryEffectMarkers();
    // load the sounds in a background thread,
    // avoids the pause where sounds dont load right away
    // change the resource loader (this allows us to play sounds the map folder, rather than just default sounds)
    new Thread(() -> ClipPlayer.getInstance(resourceLoader), "Triplea sound loader").start();
    // load a new cursor
    cursor = Cursor.getDefaultCursor();
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    // URL's use "/" not "\"
    final URL cursorUrl = resourceLoader.getResource("misc" + "/" + "cursor.gif");
    if (cursorUrl != null) {
        try {
            final Image image = ImageIO.read(cursorUrl);
            if (image != null) {
                final Point hotSpot = new Point(mapData.getMapCursorHotspotX(), mapData.getMapCursorHotspotY());
                cursor = toolkit.createCustomCursor(image, hotSpot, data.getGameName() + " Cursor");
            }
        } catch (final Exception e) {
            ClientLogger.logQuietly("Failed to create cursor from: " + cursorUrl, e);
        }
    }
    stopWatch.done();
}
Also used : DiceImageFactory(games.strategy.triplea.image.DiceImageFactory) MapData(games.strategy.triplea.ui.mapdata.MapData) Stopwatch(games.strategy.triplea.util.Stopwatch) Toolkit(java.awt.Toolkit) Point(java.awt.Point) Image(java.awt.Image) MapImage(games.strategy.triplea.image.MapImage) URL(java.net.URL) BackingStoreException(java.util.prefs.BackingStoreException)

Aggregations

DiceImageFactory (games.strategy.triplea.image.DiceImageFactory)1 MapImage (games.strategy.triplea.image.MapImage)1 MapData (games.strategy.triplea.ui.mapdata.MapData)1 Stopwatch (games.strategy.triplea.util.Stopwatch)1 Image (java.awt.Image)1 Point (java.awt.Point)1 Toolkit (java.awt.Toolkit)1 URL (java.net.URL)1 BackingStoreException (java.util.prefs.BackingStoreException)1