 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.model.mapcursor;
22 import java.awt.Dimension;
23 import java.awt.Point;
24 import java.awt.Rectangle;
25 import java.awt.geom.Rectangle2D;
26 import java.util.Collection;
27 import java.util.concurrent.CopyOnWriteArrayList;
40 import org.jetbrains.annotations.NotNull;
41 import org.jetbrains.annotations.Nullable;
65 private final Point
pos;
165 private final Collection<MapCursorListener<G, A, R>>
listenerList =
new CopyOnWriteArrayList<>();
179 pos =
fixPoint(
new Point(mapArchObject.getEnterX(), mapArchObject.getEnterY()));
183 public void mapGridChanged(@NotNull
final MapGridEvent e) {
188 public void mapGridResized(@NotNull
final MapGridEvent e) {
190 final int newWidth = newSize.
getWidth();
191 final int newHeight = newSize.
getHeight();
194 mapRec.setSize(newWidth, newHeight);
228 return new Point(
pos);
239 final Point effectivePoint =
fixPoint(p);
240 if (!
pos.equals(effectivePoint)) {
241 pos.setLocation(effectivePoint);
257 final boolean hasChanged;
259 if (p !=
null &&
mapRec.contains(p)) {
299 public boolean dragTo(@Nullable
final Point p) {
303 final Point oldPos =
new Point(
pos);
380 return p !=
null &&
mapRec.contains(p);
389 public boolean goTo(
final boolean performAction, @NotNull
final Direction dir) {
390 if (dir.getDx() == 0 && dir.getDy() == 0) {
450 this.gameObject =
null;
521 listener.mapCursorChangedMode();
529 if (changedGameObject) {
536 listener.mapCursorChangedSize();
552 }
catch (
final IndexOutOfBoundsException ignored) {
579 if (newGameObject ==
null) {
606 if (newGameObject ==
null) {
636 if (insertedGameObject !=
null) {
639 this.gameObject = insertedGameObject;
660 if (gameObject ==
null) {
665 if (mapSquare ==
null) {
674 if (nextGameObject ==
null) {
677 if (nextGameObject !=
null) {
679 final G invGameObject = nextGameObject.getFirst();
680 if (invGameObject ==
null) {
683 nextGameObject = invGameObject;
688 this.gameObject = nextGameObject;
707 return mapRec.contains(p) ? p :
new Point(Math.max(Math.min(p.x,
mapRec.width - 1), 0), Math.max(Math.min(p.y,
mapRec.height - 1), 0));
G insertArchToMap(@NotNull BaseObject< G, A, R, ?> templateBaseObject, @Nullable G nextGameObject, @NotNull Point pos, boolean join)
Insert a game object to the map at a specified position.
void addMapGridListener(@NotNull final MapGridListener listener)
Registers a MapGridListener.
int getMapY()
Returns the y coordinate on the map.
int getWidth()
Returns the width of the area.
A MapModel reflects the data of a map.
final MapModel< G, A, R > mapModel
The MapModel of this cursor.
final Point tmpPoint
Temporary point used in some methods.
void endTransaction()
Ends a transaction.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
G getLast(@NotNull final GameObjectMatcher gameObjectMatcher)
Returns the last occurrence of a matching game object.
int getMapX()
Returns the x coordinate on the map.
Base package of all Gridarta classes.
final void deactivate()
Cursor gets deactivated.
G getFirst(@NotNull final GameObjectMatcher gameObjectMatcher)
Returns the first occurrence of a matching game object.
void endTransaction()
End a transaction.
void dragSelect(@NotNull final SelectionMode selectionMode, final boolean forceSelect)
Leave drag mode and select pre-selection using selectionMode.
final Rectangle mapRec
Used to test if coordinates are on the map.
final Point dragStart
Position where dragging has started.
void beginTransaction(@NotNull String name)
Starts a new transaction.
void updatePreSelect(@NotNull final Point start, @NotNull final Point oldEnd, @NotNull final Point newEnd)
Update the pre-selection rectangle.
G getGameObject()
Returns the selected GameObject.
final Collection< MapCursorListener< G, A, R > > listenerList
The MapCursorListeners to inform of changes.
MapSquare< G, A, R > mapSquare
The selected MapSquare.
final Point transactionPos
The value of pos at the start of the outermost map cursor transaction.
void unSetCursor(@NotNull final Point pos)
Un-highlights the given cursor position.
Reflects a game object (object on a map).
void setGameObject(@Nullable final G gameObject)
Sets the selected GameObject.
boolean deleteSelectedGameObject(final boolean performAction, final boolean autoJoin)
Deletes the selected game object.
G gameObject
The selected GameObject.
boolean transactionDragging
The value of dragging at the start of the outermost map cursor transaction.
boolean setLocationSafe(@Nullable final Point p)
Move cursor to a new location.
final Dimension dragOffset
Offset of dragging.
void beginTransaction()
Starts a new transaction.
boolean dragTo(@Nullable final Point p)
When in drag mode and the point is on the map cursor is moved to this position.
GameObjects are the objects based on Archetypes found on maps.
int getHeight()
Returns the height of the area.
boolean goTo(final boolean performAction, @NotNull final Direction dir)
Moves the cursor one square relative to current position.
int transactionDepth
The nesting level of map cursor transactions.
Point fixPoint(@NotNull final Point p)
Returns a valid location that is on the map.
void selectMapSquare()
Selects the map square on the current map location.
boolean isDragging()
Returns whether the cursor is currently being dragged.
void selectTopmostGameObject()
Selects the last (top-most) GameObject on the current map square.
Interface for MapArchObjects.
boolean insertGameObject(final boolean performAction, @NotNull final BaseObject< G, A, R, ?> gameObject, final boolean insertAtEnd, final boolean join)
Inserts a GameObject before the selected game object.
void removeGameObject(@NotNull G gameObject, boolean join)
Delete an existing GameObject from the map.
boolean selectAbove(final boolean performAction)
Moves the selected GameObject.
MapCursor(@NotNull final MapGrid mapGrid, @NotNull final MapModel< G, A, R > mapModel)
Construct a MapCursor.
Point getLocation()
Get position of cursor.
Modes that describe how squares get selected.
void removeMapCursorListener(@NotNull final MapCursorListener< G, A, R > listener)
Remove a MapCursorListener.
MapCursor provides methods to move and drag on map.
void setLocation(@NotNull final Point p)
Move cursor to a new location.
boolean isOnGrid(@Nullable final Point p)
Check if point is on grid.
final void beginTransaction()
Start a new transaction.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
void addMapCursorListener(@NotNull final MapCursorListener< G, A, R > listener)
Register a MapCursorListener.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
Size2D getGridSize()
Returns a Size2D with the dimension of this grid.
void setMapSquare(@Nullable final MapSquare< G, A, R > mapSquare)
Sets the selected MapSquare.
boolean dragging
Gets set to.
void dragStart()
Set cursor to drag mode when it is active.
boolean selectBelow(final boolean performAction)
Moves the selected GameObject.
Interface for listeners listening to MapGridEvents.
void preSelect(@NotNull final Point start, @NotNull final Point end)
Rectangle defined by two points gets preselected.
void unPreSelect(@NotNull final Point start, @NotNull final Point end)
Pre-selection of rectangle defined by points gets deleted.
G transactionGameObject
The value of gameObject at the start of the outermost map cursor transaction.
final MapGrid mapGrid
Grid where cursor is bound to.
void selectArea(@NotNull final Point pos1, @NotNull final Point pos2, @NotNull final SelectionMode selectionMode)
Selects or deselects all squares in an area.
void setCursor(@NotNull final Point pos)
Highlights the given cursor position.
This event is created by MapGrid.
final Point pos
Current cursor position.
MapSquare< G, A, R > transactionMapSquare
The value of mapSquare at the start of the outermost map cursor transaction.
The class Size2D represents a 2d rectangular area.
void unSelect()
Clears all selection and pre-selection flags from the grid.
Dimension getDragOffset()
Get offset from start position of dragging.
void dragRelease()
Leave drag mode and undo pre-selection.
final Rectangle2D transactionMapRec
The value of mapRec at the start of the outermost map cursor transaction.
final void endTransaction()
End a transaction.