Class MapCursor<G extends GameObject<G,​A,​R>,​A extends MapArchObject<A>,​R extends Archetype<G,​A,​R>>


  • public class MapCursor<G extends GameObject<G,​A,​R>,​A extends MapArchObject<A>,​R extends Archetype<G,​A,​R>>
    extends java.lang.Object
    MapCursor provides methods to move and drag on map. The MapCursor is bound to a MapGrid which will change it flags depending on MapCursor movement/selection.

    There are three different states for MapCursor:

    • Deactivated
    • On the map
    • Dragging
    When coordinates or state of MapCursor changes an event is fired.
    • Constructor Detail

      • MapCursor

        public MapCursor​(@NotNull
                         @NotNull MapGrid mapGrid,
                         @NotNull
                         @NotNull MapModel<G,​A,​R> mapModel)
        Construct a MapCursor. The cursor will be deactivated after construction.
        Parameters:
        mapGrid - Cursor is bound to this grid
        mapModel - the map model of this cursor
    • Method Detail

      • getLocation

        @NotNull
        public @NotNull java.awt.Point getLocation()
        Get position of cursor.
        Returns:
        coordinates of cursor
      • setLocation

        public void setLocation​(@NotNull
                                @NotNull java.awt.Point p)
        Move cursor to a new location. If new location is not on map, the nearest valid location is chosen.
        Parameters:
        p - the new location
      • setLocationSafe

        public boolean setLocationSafe​(@Nullable
                                       @Nullable java.awt.Point p)
        Move cursor to a new location. If new location is not on map, cursor does not change.
        Parameters:
        p - the new location; if p == null nothing happens
        Returns:
        true if cursor position changed
      • dragStart

        public void dragStart()
        Set cursor to drag mode when it is active.
      • dragTo

        public boolean dragTo​(@Nullable
                              @Nullable java.awt.Point p)
        When in drag mode and the point is on the map cursor is moved to this position. MapGrid changes pre-selection accordingly.
        Parameters:
        p - new coordinates
        Returns:
        true when dragging position changed successfully
      • dragRelease

        public void dragRelease()
        Leave drag mode and undo pre-selection.
      • dragSelect

        public void dragSelect​(@NotNull
                               @NotNull SelectionMode selectionMode,
                               boolean forceSelect)
        Leave drag mode and select pre-selection using selectionMode.
        Parameters:
        selectionMode - Mode how to change selection state
        forceSelect - whether to force selection, regardless of the selected area
        See Also:
        SelectionMode
      • deactivate

        public final void deactivate()
        Cursor gets deactivated. All selections get lost.
      • getDragOffset

        @Nullable
        public @Nullable java.awt.Dimension getDragOffset()
        Get offset from start position of dragging.
        Returns:
        offset or null when not in drag mode
      • isOnGrid

        public boolean isOnGrid​(@Nullable
                                @Nullable java.awt.Point p)
        Check if point is on grid.
        Parameters:
        p - Coordinates of point
        Returns:
        true if p != null and point is on grid
      • goTo

        public boolean goTo​(boolean performAction,
                            @NotNull
                            @NotNull Direction dir)
        Moves the cursor one square relative to current position.
        Parameters:
        performAction - whether the action should be performed
        dir - the direction
        Returns:
        true if cursor really moved
      • isDragging

        public boolean isDragging()
        Returns whether the cursor is currently being dragged.
        Returns:
        true if dragging is active, otherwise false.
      • addMapCursorListener

        public void addMapCursorListener​(@NotNull
                                         @NotNull MapCursorListener<G,​A,​R> listener)
        Register a MapCursorListener.
        Parameters:
        listener - MapCursorListener to register
      • removeMapCursorListener

        public void removeMapCursorListener​(@NotNull
                                            @NotNull MapCursorListener<G,​A,​R> listener)
        Remove a MapCursorListener.
        Parameters:
        listener - MapCursorListener to remove
      • getGameObject

        @Nullable
        public G getGameObject()
        Returns the selected GameObject.
        Returns:
        the selected game object or null if the map cursor is not active or if the selected map square is empty
      • setGameObject

        public void setGameObject​(@Nullable
                                  G gameObject)
        Sets the selected GameObject. If the game object is not on a map or not on the map this cursor is attached to, the cursor is unchanged.
        Parameters:
        gameObject - the selected game object
      • setMapSquare

        public void setMapSquare​(@Nullable
                                 @Nullable MapSquare<G,​A,​R> mapSquare)
        Sets the selected MapSquare. If the map square does not belong to the map this cursor is attached to, the cursor is unchanged.
        Parameters:
        mapSquare - the selected map square
      • beginTransaction

        public final void beginTransaction()
        Start a new transaction. Transactions may be nested. Transactions serve the purpose of firing events to the views when more changes are known to come before the view is really required to update. Each invocation of this function requires its own invocation of endTransaction().
      • endTransaction

        public final void endTransaction()
        End a transaction. Invoking this method will reduce the transaction depth by 1.

        If the last transaction is ended, the changes are committed.

      • selectAbove

        public boolean selectAbove​(boolean performAction)
        Moves the selected GameObject. Does nothing if no game object is selected.
        Parameters:
        performAction - whether the action should be performed
        Returns:
        whether the action was or can be performed
      • selectBelow

        public boolean selectBelow​(boolean performAction)
        Moves the selected GameObject. Does nothing if no game object is selected.
        Parameters:
        performAction - whether the action should be performed
        Returns:
        whether the action was or can be performed
      • insertGameObject

        public boolean insertGameObject​(boolean performAction,
                                        @NotNull
                                        @NotNull BaseObject<G,​A,​R,​?> gameObject,
                                        boolean insertAtEnd,
                                        boolean join)
        Inserts a GameObject before the selected game object. Does nothing if no game object is selected.
        Parameters:
        performAction - whether the action should be performed
        gameObject - the game object to insert
        insertAtEnd - whether to ignore the selected game object and insert at the end
        join - if set, auto-joining is supported
        Returns:
        whether the action was or can be performed
      • deleteSelectedGameObject

        public boolean deleteSelectedGameObject​(boolean performAction,
                                                boolean autoJoin)
        Deletes the selected game object. Does nothing if no game object is selected.
        Parameters:
        performAction - whether the action should be performed
        autoJoin - whether to preform auto-joining
        Returns:
        whether the action was or can be performed