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();
}
Aggregations