use of de.gurkenlabs.litiengine.environment.tilemap.MapObjectType 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.MapObjectType in project litiengine by gurkenlabs.
the class MapComponent method renderBoundingBox.
private void renderBoundingBox(Graphics2D g, IMapObject mapObject, Color colorBoundingBoxFill, BasicStroke shapeStroke) {
MapObjectType type = MapObjectType.get(mapObject.getType());
Color fillColor = colorBoundingBoxFill;
if (type == MapObjectType.TRIGGER) {
fillColor = COLOR_TRIGGER_FILL;
} else if (type == MapObjectType.STATICSHADOW) {
fillColor = COLOR_SHADOW_FILL;
}
// render bounding boxes
g.setColor(fillColor);
// the color
if (type != MapObjectType.LIGHTSOURCE) {
Game.getRenderEngine().renderShape(g, mapObject.getBoundingBox());
}
Color borderColor = colorBoundingBoxFill;
if (type == MapObjectType.TRIGGER) {
borderColor = COLOR_TRIGGER_BORDER;
} else if (type == MapObjectType.LIGHTSOURCE) {
final String mapObjectColor = mapObject.getCustomProperty(MapObjectProperty.LIGHT_COLOR);
if (mapObjectColor != null && !mapObjectColor.isEmpty()) {
Color lightColor = Color.decode(mapObjectColor);
borderColor = new Color(lightColor.getRed(), lightColor.getGreen(), lightColor.getBlue(), 180);
}
} else if (type == MapObjectType.STATICSHADOW) {
borderColor = COLOR_SHADOW_BORDER;
} else if (type == MapObjectType.SPAWNPOINT) {
borderColor = COLOR_SPAWNPOINT;
}
g.setColor(borderColor);
Game.getRenderEngine().renderOutline(g, mapObject.getBoundingBox(), shapeStroke);
this.renderName(g, borderColor, mapObject);
}
use of de.gurkenlabs.litiengine.environment.tilemap.MapObjectType in project litiengine by gurkenlabs.
the class MapComponent method delete.
public void delete(final IMapObject mapObject) {
if (mapObject == null) {
return;
}
MapObjectType type = MapObjectType.get(mapObject.getType());
Game.getEnvironment().getMap().removeMapObject(mapObject.getId());
Game.getEnvironment().remove(mapObject.getId());
if (type == MapObjectType.STATICSHADOW || type == MapObjectType.LIGHTSOURCE) {
Game.getEnvironment().getAmbientLight().updateSection(mapObject.getBoundingBox());
}
if (mapObject.equals(this.getFocusedMapObject())) {
this.setFocus(null, true);
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.MapObjectType 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.MapObjectType in project litiengine by gurkenlabs.
the class MapObjectPanel method setControlValues.
@Override
protected void setControlValues(IMapObject mapObject) {
this.spinnerX.setValue((int) mapObject.getLocation().getX());
this.spinnerY.setValue((int) mapObject.getLocation().getY());
this.spinnerWidth.setValue((int) mapObject.getDimension().getWidth());
this.spinnerHeight.setValue((int) mapObject.getDimension().getHeight());
MapObjectType type = MapObjectType.get(mapObject.getType());
this.comboBoxType.setSelectedItem(type);
this.textFieldName.setText(mapObject.getName());
this.labelEntityID.setText(Integer.toString(mapObject.getId()));
this.comboBoxType.setEnabled(false);
this.tagPanel.bind(mapObject.getCustomProperty(MapObjectProperty.TAGS));
}
Aggregations