use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapComponent method setupKeyboardControls.
private void setupKeyboardControls() {
Input.keyboard().onKeyReleased(KeyEvent.VK_ADD, e -> {
if (this.isSuspended() || !this.isVisible()) {
return;
}
if (Input.keyboard().isPressed(KeyEvent.VK_CONTROL)) {
this.zoomIn();
}
});
Input.keyboard().onKeyReleased(KeyEvent.VK_SUBTRACT, e -> {
if (this.isSuspended() || !this.isVisible()) {
return;
}
if (Input.keyboard().isPressed(KeyEvent.VK_CONTROL)) {
this.zoomOut();
}
});
Input.keyboard().onKeyPressed(KeyEvent.VK_SPACE, e -> this.centerCameraOnFocus());
Input.keyboard().onKeyPressed(KeyEvent.VK_CONTROL, e -> {
if (this.currentEditMode == EDITMODE_EDIT) {
this.setEditMode(EDITMODE_MOVE);
}
});
Input.keyboard().onKeyReleased(KeyEvent.VK_CONTROL, e -> this.setEditMode(EDITMODE_EDIT));
Input.keyboard().onKeyReleased(KeyEvent.VK_Z, e -> {
if (Input.keyboard().isPressed(KeyEvent.VK_CONTROL)) {
UndoManager.instance().undo();
}
});
Input.keyboard().onKeyReleased(KeyEvent.VK_Y, e -> {
if (Input.keyboard().isPressed(KeyEvent.VK_CONTROL)) {
UndoManager.instance().redo();
}
});
Input.keyboard().onKeyPressed(KeyEvent.VK_DELETE, e -> {
if (this.isSuspended() || !this.isVisible() || this.getFocusedMapObject() == null) {
return;
}
if (Game.getScreenManager().getRenderComponent().hasFocus() && this.currentEditMode == EDITMODE_EDIT) {
this.delete();
}
});
Input.keyboard().onKeyReleased(e -> {
if (e.getKeyCode() != KeyEvent.VK_RIGHT && e.getKeyCode() != KeyEvent.VK_LEFT && e.getKeyCode() != KeyEvent.VK_UP && e.getKeyCode() != KeyEvent.VK_DOWN) {
return;
}
// if one of the move buttons is still pressed, don't end the operation
if (Input.keyboard().isPressed(KeyEvent.VK_RIGHT) || Input.keyboard().isPressed(KeyEvent.VK_LEFT) || Input.keyboard().isPressed(KeyEvent.VK_UP) || Input.keyboard().isPressed(KeyEvent.VK_DOWN)) {
return;
}
if (this.isMovingWithKeyboard) {
for (IMapObject selected : this.getSelectedMapObjects()) {
UndoManager.instance().mapObjectChanged(selected);
}
UndoManager.instance().endOperation();
this.isMovingWithKeyboard = false;
}
});
Input.keyboard().onKeyPressed(KeyEvent.VK_RIGHT, e -> {
if (!Game.getScreenManager().getRenderComponent().hasFocus()) {
return;
}
this.beforeKeyPressed();
this.handleEntityDrag(1, 0);
this.afterKeyPressed();
});
Input.keyboard().onKeyPressed(KeyEvent.VK_LEFT, e -> {
if (!Game.getScreenManager().getRenderComponent().hasFocus()) {
return;
}
this.beforeKeyPressed();
this.handleEntityDrag(-1, 0);
this.afterKeyPressed();
});
Input.keyboard().onKeyPressed(KeyEvent.VK_UP, e -> {
if (!Game.getScreenManager().getRenderComponent().hasFocus()) {
return;
}
this.beforeKeyPressed();
this.handleEntityDrag(0, -1);
this.afterKeyPressed();
});
Input.keyboard().onKeyPressed(KeyEvent.VK_DOWN, e -> {
if (!Game.getScreenManager().getRenderComponent().hasFocus()) {
return;
}
this.beforeKeyPressed();
this.handleEntityDrag(0, 1);
this.afterKeyPressed();
});
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapComponent method renderSelection.
private void renderSelection(Graphics2D g) {
for (IMapObject mapObject : this.getSelectedMapObjects()) {
if (mapObject.equals(this.getFocusedMapObject())) {
continue;
}
Stroke stroke = new BasicStroke(1 / Game.getCamera().getRenderScale());
g.setColor(COLOR_SELECTION_BORDER);
Game.getRenderEngine().renderOutline(g, mapObject.getBoundingBox(), stroke);
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapComponent method beforeKeyPressed.
private void beforeKeyPressed() {
if (!this.isMovingWithKeyboard) {
UndoManager.instance().beginOperation();
for (IMapObject selected : this.getSelectedMapObjects()) {
UndoManager.instance().mapObjectChanging(selected);
}
this.isMovingWithKeyboard = true;
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapComponent method handleSelectedEntitiesDrag.
private void handleSelectedEntitiesDrag() {
if (!this.isMoving) {
this.isMoving = true;
UndoManager.instance().beginOperation();
for (IMapObject selected : this.getSelectedMapObjects()) {
UndoManager.instance().mapObjectChanging(selected);
}
}
IMapObject minX = null;
IMapObject minY = null;
for (IMapObject selected : this.getSelectedMapObjects()) {
if (minX == null || selected.getX() < minX.getX()) {
minX = selected;
}
if (minY == null || selected.getY() < minY.getY()) {
minY = selected;
}
}
if (minX == null || minY == null || (!Input.keyboard().isPressed(KeyEvent.VK_CONTROL) && this.currentEditMode != EDITMODE_MOVE)) {
return;
}
if (this.dragPoint == null) {
this.dragPoint = Input.mouse().getMapLocation();
return;
}
if (!this.dragLocationMapObjects.containsKey(minX)) {
this.dragLocationMapObjects.put(minX, new Point2D.Double(minX.getX(), minX.getY()));
}
if (!this.dragLocationMapObjects.containsKey(minY)) {
this.dragLocationMapObjects.put(minY, new Point2D.Double(minY.getX(), minY.getY()));
}
Point2D dragLocationMapObjectMinX = this.dragLocationMapObjects.get(minX);
Point2D dragLocationMapObjectMinY = this.dragLocationMapObjects.get(minY);
double deltaX = Input.mouse().getMapLocation().getX() - this.dragPoint.getX();
int newX = this.snapX(dragLocationMapObjectMinX.getX() + deltaX);
int snappedDeltaX = newX - minX.getX();
double deltaY = Input.mouse().getMapLocation().getY() - this.dragPoint.getY();
int newY = this.snapY(dragLocationMapObjectMinY.getY() + deltaY);
int snappedDeltaY = newY - minY.getY();
if (snappedDeltaX == 0 && snappedDeltaY == 0) {
return;
}
this.handleEntityDrag(snappedDeltaX, snappedDeltaY);
if (this.getSelectedMapObjects().stream().anyMatch(x -> MapObjectType.get(x.getType()) == MapObjectType.STATICSHADOW || MapObjectType.get(x.getType()) == MapObjectType.LIGHTSOURCE)) {
Game.getEnvironment().getAmbientLight().updateSection(MapObject.getBounds2D(this.getSelectedMapObjects()));
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapComponent method renderFocus.
private void renderFocus(Graphics2D g) {
// render the focus and the transform rects
final Rectangle2D focus = this.getFocus();
final IMapObject focusedMapObject = this.getFocusedMapObject();
if (focus != null && focusedMapObject != null) {
Stroke stroke = new BasicStroke(1 / Game.getCamera().getRenderScale(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 4, new float[] { 1f, 1f }, Game.getLoop().getTicks() / 15);
g.setColor(Color.BLACK);
Game.getRenderEngine().renderOutline(g, focus, stroke);
Stroke whiteStroke = new BasicStroke(1 / Game.getCamera().getRenderScale(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 4, new float[] { 1f, 1f }, Game.getLoop().getTicks() / 15 - 1f);
g.setColor(Color.WHITE);
Game.getRenderEngine().renderOutline(g, focus, whiteStroke);
// render transform rects
if (!Input.keyboard().isPressed(KeyEvent.VK_CONTROL)) {
Stroke transStroke = new BasicStroke(1 / Game.getCamera().getRenderScale());
for (Rectangle2D trans : this.transformRects.values()) {
g.setColor(COLOR_TRANSFORM_RECT_FILL);
Game.getRenderEngine().renderShape(g, trans);
g.setColor(Color.BLACK);
Game.getRenderEngine().renderOutline(g, trans, transStroke);
}
}
// render transform rects
if (!Input.keyboard().isPressed(KeyEvent.VK_CONTROL)) {
Stroke transStroke = new BasicStroke(1 / Game.getCamera().getRenderScale());
for (Rectangle2D trans : this.transformRects.values()) {
g.setColor(COLOR_TRANSFORM_RECT_FILL);
Game.getRenderEngine().renderShape(g, trans);
g.setColor(Color.BLACK);
Game.getRenderEngine().renderOutline(g, trans, transStroke);
}
}
}
if (focusedMapObject != null) {
Point2D loc = Game.getCamera().getViewPortLocation(new Point2D.Double(focusedMapObject.getX() + focusedMapObject.getDimension().getWidth() / 2, focusedMapObject.getY()));
g.setFont(Program.TEXT_FONT.deriveFont(Font.BOLD, 15f));
g.setColor(Color.WHITE);
String id = "#" + focusedMapObject.getId();
RenderEngine.drawText(g, id, loc.getX() * Game.getCamera().getRenderScale() - g.getFontMetrics().stringWidth(id) / 2.0, loc.getY() * Game.getCamera().getRenderScale() - (5 * this.currentTransformRectSize));
}
}
Aggregations