public class MapCursor<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
extends java.lang.Object
MapGrid
which will change it flags depending on MapCursor
movement/selection. There are three different states for MapCursor: Constructor and Description |
---|
MapCursor(MapGrid mapGrid,
MapModel<G,A,R> mapModel)
Construct a MapCursor.
|
Modifier and Type | Method and Description |
---|---|
void |
addMapCursorListener(MapCursorListener<G,A,R> listener)
Register a MapCursorListener.
|
void |
beginTransaction()
Start a new transaction.
|
void |
deactivate()
Cursor gets deactivated.
|
boolean |
deleteSelectedGameObject(boolean performAction,
boolean autoJoin)
Deletes the selected game object.
|
void |
dragRelease()
Leave drag mode and undo pre-selection.
|
void |
dragSelect(SelectionMode selectionMode,
boolean forceSelect)
Leave drag mode and select pre-selection using selectionMode.
|
void |
dragStart()
Set cursor to drag mode when it is active.
|
boolean |
dragTo(java.awt.Point p)
When in drag mode and the point is on the map cursor is moved to this
position.
|
void |
endTransaction()
End a transaction.
|
java.awt.Dimension |
getDragOffset()
Get offset from start position of dragging.
|
G |
getGameObject()
Returns the selected
GameObject . |
java.awt.Point |
getLocation()
Get position of cursor.
|
boolean |
goTo(boolean performAction,
Direction dir)
Moves the cursor one square relative to current position.
|
boolean |
insertGameObject(boolean performAction,
BaseObject<G,A,R,?> gameObject,
boolean insertAtEnd,
boolean join)
Inserts a
GameObject before the selected game object. |
boolean |
isDragging()
Returns whether the cursor is currently being dragged.
|
boolean |
isOnGrid(java.awt.Point p)
Check if point is on grid.
|
void |
removeMapCursorListener(MapCursorListener<G,A,R> listener)
Remove a MapCursorListener.
|
boolean |
selectAbove(boolean performAction)
Moves the selected
GameObject . |
boolean |
selectBelow(boolean performAction)
Moves the selected
GameObject . |
void |
setGameObject(G gameObject)
Sets the selected
GameObject . |
void |
setLocation(java.awt.Point p)
Move cursor to a new location.
|
boolean |
setLocationSafe(java.awt.Point p)
Move cursor to a new location.
|
void |
setMapSquare(MapSquare<G,A,R> mapSquare)
Sets the selected
MapSquare . |
@NotNull public java.awt.Point getLocation()
public void setLocation(@NotNull java.awt.Point p)
p
- the new locationpublic boolean setLocationSafe(@Nullable java.awt.Point p)
p
- New location. If p == null
nothing happenstrue
if cursor position changedpublic void dragStart()
public boolean dragTo(@Nullable java.awt.Point p)
MapGrid
changes pre-selection accordingly.p
- new coordinatestrue
when dragging position changed successfullypublic void dragRelease()
public void dragSelect(@NotNull SelectionMode selectionMode, boolean forceSelect)
selectionMode
- Mode how to change selection stateforceSelect
- whether to force selection, regardless of the selected
areaSelectionMode
public final void deactivate()
@Nullable public java.awt.Dimension getDragOffset()
null
when not in drag modepublic boolean isOnGrid(@Nullable java.awt.Point p)
p
- Coordinates of pointtrue
if p != null
and point is on gridpublic boolean goTo(boolean performAction, @NotNull Direction dir)
performAction
- whether the action should be performeddir
- the directiontrue
if cursor really movedpublic boolean isDragging()
true
if dragging is active, otherwise false
.public void addMapCursorListener(@NotNull MapCursorListener<G,A,R> listener)
listener
- MapCursorListener to registerpublic void removeMapCursorListener(@NotNull MapCursorListener<G,A,R> listener)
listener
- MapCursorListener to remove@Nullable public G getGameObject()
GameObject
.null
if the map cursor is not
active or if the selected map square is emptypublic void setGameObject(@Nullable G gameObject)
GameObject
. If the game object is not on a map
or not on the map this cursor is attached to, the cursor is unchanged.gameObject
- the selected game objectpublic void setMapSquare(@Nullable MapSquare<G,A,R> mapSquare)
MapSquare
. If the map square does not belong to
the map this cursor is attached to, the cursor is unchanged.mapSquare
- the selected map squarepublic final void beginTransaction()
endTransaction()
.public final void endTransaction()
public boolean selectAbove(boolean performAction)
GameObject
. Does nothing if no game object is
selected.performAction
- whether the action should be performedpublic boolean selectBelow(boolean performAction)
GameObject
. Does nothing if no game object is
selected.performAction
- whether the action should be performedpublic boolean insertGameObject(boolean performAction, @NotNull BaseObject<G,A,R,?> gameObject, boolean insertAtEnd, boolean join)
GameObject
before the selected game object. Does
nothing if no game object is selected.performAction
- whether the action should be performedgameObject
- the game object to insertinsertAtEnd
- whether to ignore the selected game object and insert
at the endjoin
- if set, auto-joining is supportedpublic boolean deleteSelectedGameObject(boolean performAction, boolean autoJoin)
performAction
- whether the action should be performedautoJoin
- whether to preform auto-joining