 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.copybuffer;
22 import java.awt.Point;
23 import java.awt.Rectangle;
24 import java.util.Collection;
25 import java.util.HashSet;
26 import java.util.List;
42 import org.jetbrains.annotations.NotNull;
86 public CopyBuffer(@NotNull
final MapViewSettings mapViewSettings, @NotNull
final GameObjectFactory<G, A, R> gameObjectFactory, @NotNull
final MapArchObjectFactory<A> mapArchObjectFactory, @NotNull
final MapModelFactory<G, A, R> mapModelFactory, @NotNull
final InsertionModeSet<G, A, R> insertionModeSet) {
88 final A mapArchObject = mapArchObjectFactory.newMapArchObject(
false);
89 mapArchObject.setMapName(
"cb");
90 mapModel = mapModelFactory.newMapModel(mapArchObject);
150 copyMode.prepare(
mapModel,
new Size2D(selectedRec.width, selectedRec.height));
155 final Collection<G> gameObjectsToDelete =
new HashSet<>();
156 final Point pos =
new Point();
158 square.getMapLocation(pos, -selectedRec.x, -selectedRec.y);
159 for (
final G gameObject : square) {
185 final Point pos =
new Point();
187 square.getMapLocation(pos);
188 pos.translate(startLocation.x, startLocation.y);
191 if (!gameObject.isMulti()) {
199 square.getMapLocation(pos);
200 pos.translate(startLocation.x, startLocation.y);
203 if (gameObject.isMulti()) {
221 final Point sourcePoint =
new Point();
222 final Point destinationPoint =
new Point();
228 sourcePoint.x =
MathUtils.
mod(destinationMapSquare.getMapX() - origin.x, mapModelSize.
getWidth());
232 if (!gameObject.isMulti()) {
233 destinationPoint.x = destinationMapSquare.
getMapX();
234 destinationPoint.y = destinationMapSquare.getMapY();
241 sourcePoint.x =
MathUtils.
mod(destinationMapSquare.getMapX() - origin.x, mapModelSize.
getWidth());
245 if (gameObject.isMulti()) {
246 destinationPoint.x = destinationMapSquare.
getMapX();
247 destinationPoint.y = destinationMapSquare.getMapY();
InsertionMode getTopmostInsertionMode()
Returns the "topmost" insertion mode.
int getWidth()
Returns the width of the area.
A MapModel reflects the data of a map.
Abstract factory for creating GameObject instances.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
boolean isEmpty()
Returns whether this copy buffer contains any game objects.
G insertBaseObject(@NotNull BaseObject< G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode insertionMode)
Inserts a BaseObject to a map.
int getMapX()
Returns the x coordinate on the map.
boolean isEmpty()
Returns whether the map is empty.
Base package of all Gridarta classes.
void endTransaction()
End a transaction.
boolean isPointValid(@Nullable Point pos)
Checks whether the given coordinate is within map bounds.
void beginTransaction(@NotNull String name)
Starts a new transaction.
Utility class for mathematical functions.
A factory for creating MapModel instances.
Reflects a game object (object on a map).
Container for settings that affect the rendering of maps.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
List< G > getAllGameObjects()
Returns all game objects.
Graphical User Interface of Gridarta.
GameObjects are the objects based on Archetypes found on maps.
void addMapModelListener(@NotNull final MapModelListener< G, A, R > listener)
Adds a MapModelListener to be notified about changes of the cut/copied game objects.
int getHeight()
Returns the height of the area.
final MapViewSettings mapViewSettings
The map view settings instance.
void removeMapModelListener(@NotNull final MapModelListener< G, A, R > listener)
Removes a MapModelListener to be notified about changes of the cut/copied game objects.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
Interface for MapArchObjects.
boolean isEditType(int editType)
Get information on the current state of edit type.
void copy(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executes the Copy command.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Common base implementation of CopyBuffer.
void cut(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executes the Cut command.
Interface for listeners listening on MapModel events.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
void paste(@NotNull final MapView< G, A, R > mapView, @NotNull final Point startLocation)
Executes the Paste command.
final MapModel< G, A, R > mapModel
Internal map model to store the cut / copied game objects.
final GameObjectFactory< G, A, R > gameObjectFactory
The GameObjectFactory to use.
final InsertionModeSet< G, A, R > insertionModeSet
The InsertionModeSet to use.
Base classes for rendering maps.
CopyBuffer(@NotNull final MapViewSettings mapViewSettings, @NotNull final GameObjectFactory< G, A, R > gameObjectFactory, @NotNull final MapArchObjectFactory< A > mapArchObjectFactory, @NotNull final MapModelFactory< G, A, R > mapModelFactory, @NotNull final InsertionModeSet< G, A, R > insertionModeSet)
Creates a new instance.
static int mod(final int numerator, final int denominator)
Calculates the remainder of.
The class Size2D represents a 2d rectangular area.
List< G > getAllGameObjects()
Returns all game objects.
void copyNCut(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec, @NotNull final CopyMode copyMode)
Implements clear, cut and copy in one function (since they are so similar).
void pasteTiled(@NotNull final MapView< G, A, R > mapView, @NotNull final Iterable< MapSquare< G, A, R >> selectedSquares, @NotNull final Point origin)
Executes the Paste Tiled command.
Factory for creating MapArchObject instances.
void clear(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executes the Clear command.