use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.
the class MapSelectionPanel method initLayerControl.
private void initLayerControl() {
if (mapList.getSelectedIndex() == -1 && this.model.size() > 0) {
this.mapList.setSelectedIndex(0);
}
if (EditorScreen.instance().getMapComponent().getMaps().isEmpty()) {
layerModel.clear();
return;
}
Map map = EditorScreen.instance().getMapComponent().getMaps().get(mapList.getSelectedIndex());
this.lastSelection = listObjectLayers.getSelectedIndex();
layerModel.clear();
for (IMapObjectLayer layer : map.getMapObjectLayers()) {
String layerName = layer.getName();
int layerSize = layer.getMapObjects().size();
JCheckBox newBox = new JCheckBox(layerName + " (" + layerSize + ")");
if (layer.getColor() != null) {
final String cacheKey = map.getFileName() + layer.getName();
if (!ImageCache.IMAGES.containsKey(cacheKey)) {
BufferedImage img = ImageProcessing.getCompatibleImage(10, 10);
Graphics2D g = (Graphics2D) img.getGraphics();
g.setColor(layer.getColor());
g.fillRect(0, 0, 9, 9);
g.setColor(Color.BLACK);
g.drawRect(0, 0, 9, 9);
g.dispose();
ImageCache.IMAGES.put(cacheKey, img);
}
newBox.setIcon(new ImageIcon(ImageCache.IMAGES.get(cacheKey)));
}
newBox.setSelected(true);
layerModel.addElement(newBox);
}
int start = 0;
int end = mapList.getModel().getSize() - 1;
if (end >= 0) {
listObjectLayers.setSelectionInterval(start, end);
this.selectLayer(this.lastSelection);
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.
the class MapComponent method handleMouseReleased.
private void handleMouseReleased(ComponentMouseEvent e) {
if (!this.hasFocus()) {
return;
}
this.dragPoint = null;
this.dragLocationMapObjects.clear();
this.dragSizeMapObject = null;
switch(this.currentEditMode) {
case EDITMODE_CREATE:
if (this.newObjectArea == null) {
break;
}
IMapObject mo = this.createNewMapObject(EditorScreen.instance().getMapObjectPanel().getObjectType());
this.newObjectArea = null;
this.setFocus(mo, !Input.keyboard().isPressed(KeyEvent.VK_SHIFT));
EditorScreen.instance().getMapObjectPanel().bind(mo);
this.setEditMode(EDITMODE_EDIT);
break;
case EDITMODE_MOVE:
if (this.isMoving) {
this.isMoving = false;
for (IMapObject selected : this.getSelectedMapObjects()) {
UndoManager.instance().mapObjectChanged(selected);
}
UndoManager.instance().endOperation();
}
break;
case EDITMODE_EDIT:
if (this.isMoving || this.isTransforming) {
this.isMoving = false;
this.isTransforming = false;
UndoManager.instance().mapObjectChanged(this.getFocusedMapObject());
}
if (this.startPoint == null) {
return;
}
Rectangle2D rect = this.getCurrentMouseSelectionArea(false);
boolean somethingIsFocused = false;
boolean currentObjectFocused = false;
for (IMapObjectLayer layer : Game.getEnvironment().getMap().getMapObjectLayers()) {
if (layer == null || !EditorScreen.instance().getMapSelectionPanel().isVisibleMapObjectLayer(layer.getName())) {
continue;
}
for (IMapObject mapObject : layer.getMapObjects()) {
if (mapObject == null) {
continue;
}
MapObjectType type = MapObjectType.get(mapObject.getType());
if (type == MapObjectType.PATH) {
continue;
}
if (!GeometricUtilities.intersects(rect, mapObject.getBoundingBox())) {
continue;
}
if (this.getFocusedMapObject() != null && mapObject.getId() == this.getFocusedMapObject().getId()) {
currentObjectFocused = true;
continue;
}
if (somethingIsFocused) {
if (rect.getWidth() == 0 && rect.getHeight() == 0) {
break;
}
this.setSelection(mapObject, false);
continue;
}
this.setFocus(mapObject, !Input.keyboard().isPressed(KeyEvent.VK_SHIFT));
EditorScreen.instance().getMapObjectPanel().bind(mapObject);
somethingIsFocused = true;
}
}
if (!somethingIsFocused && !currentObjectFocused) {
this.setFocus(null, true);
EditorScreen.instance().getMapObjectPanel().bind(null);
}
break;
default:
break;
}
this.startPoint = null;
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.
the class MapPropertyPanel method bind.
public void bind(IMap map) {
this.dataSource = map;
if (map == null) {
return;
}
this.setControlValues(map);
for (IMapObjectLayer layer : map.getMapObjectLayers()) {
this.model.addRow(new Object[] { layer.getName(), layer.getColor() != null ? "#" + Integer.toHexString(layer.getColor().getRGB()).substring(2) : null });
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.
the class MapComponent method renderMapObjectBounds.
private void renderMapObjectBounds(Graphics2D g) {
// render all entities
for (final IMapObjectLayer layer : Game.getEnvironment().getMap().getMapObjectLayers()) {
if (layer == null) {
continue;
}
if (!EditorScreen.instance().getMapSelectionPanel().isVisibleMapObjectLayer(layer.getName())) {
continue;
}
Color colorBoundingBoxFill;
if (layer.getColor() != null) {
colorBoundingBoxFill = new Color(layer.getColor().getRed(), layer.getColor().getGreen(), layer.getColor().getBlue(), 15);
} else {
colorBoundingBoxFill = DEFAULT_COLOR_BOUNDING_BOX_FILL;
}
for (final IMapObject mapObject : layer.getMapObjects()) {
if (mapObject == null) {
continue;
}
MapObjectType type = MapObjectType.get(mapObject.getType());
final BasicStroke shapeStroke = new BasicStroke(1f / Game.getCamera().getRenderScale());
// render spawn points
if (type == MapObjectType.SPAWNPOINT) {
g.setColor(COLOR_SPAWNPOINT);
Game.getRenderEngine().renderShape(g, new Rectangle2D.Double(mapObject.getBoundingBox().getCenterX() - 1, mapObject.getBoundingBox().getCenterY() - 1, 2, 2));
} else if (type == MapObjectType.PATH) {
if (mapObject.getPolyline() == null || mapObject.getPolyline().getPoints().isEmpty()) {
continue;
}
// found the path for the rat
final Path2D path = MapUtilities.convertPolylineToPath(mapObject);
if (path == null) {
continue;
}
g.setColor(COLOR_LANE);
Game.getRenderEngine().renderOutline(g, path, shapeStroke);
Point2D start = new Point2D.Double(mapObject.getLocation().getX(), mapObject.getLocation().getY());
Game.getRenderEngine().renderShape(g, new Ellipse2D.Double(start.getX() - 1, start.getY() - 1, 3, 3));
Game.getRenderEngine().renderText(g, "#" + mapObject.getId() + "(" + mapObject.getName() + ")", start.getX(), start.getY() - 5);
}
if (type != MapObjectType.COLLISIONBOX) {
this.renderBoundingBox(g, mapObject, colorBoundingBoxFill, shapeStroke);
}
this.renderCollisionBox(g, mapObject, shapeStroke);
}
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.
the class Environment method loadFromMap.
@Override
public void loadFromMap(final int mapId) {
for (final IMapObjectLayer layer : this.getMap().getMapObjectLayers()) {
Optional<IMapObject> opt = layer.getMapObjects().stream().filter(mapObject -> mapObject.getType() != null && !mapObject.getType().isEmpty() && mapObject.getId() == mapId).findFirst();
if (opt.isPresent()) {
IMapObject mapObject = opt.get();
this.addMapObject(mapObject);
break;
}
}
}
Aggregations