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();
A factory for creating MapModel instances.
int getMapX()
Returns the x coordinate on the map.
boolean isPointValid(@Nullable Point pos)
Checks whether the given coordinate is within map bounds.
A MapModel reflects the data of a map.
final MapViewSettings mapViewSettings
The map view settings instance.
Graphical User Interface of Gridarta.
Utility class for mathematical functions.
final MapModel< G, A, R > mapModel
Internal map model to store the cut / copied game objects.
void endTransaction()
End a transaction.
void copyNCut(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec, @NotNull final CopyMode copyMode)
copyNCut implements clear, cut and copy in one function (since they are so similar).
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)
Create the copy buffer.
void clear(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executing the Clear command.
Interface for listeners listening on MapModel events.
Factory for creating MapArchObject instances.
boolean isEditType(int editType)
Get information on the current state of edit type.
void cut(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executing the Cut command.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
final InsertionModeSet< G, A, R > insertionModeSet
The InsertionModeSet to use.
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< G, A, R > insertionMode)
Inserts a BaseObject to a map.
Base package of all Gridarta classes.
void pasteTiled(@NotNull final MapView< G, A, R > mapView, @NotNull final Iterable< MapSquare< G, A, R >> selectedSquares, @NotNull final Point origin)
Executing the Paste Tiled command.
Reflects a game object (object on a map).
Abstract factory for creating GameObject instances.
void addMapModelListener(@NotNull final MapModelListener< G, A, R > listener)
Adds a MapModelListener to be notified about changes of the cut/copied game objects.
final GameObjectFactory< G, A, R > gameObjectFactory
The GameObjectFactory to use.
Container for settings that affect the rendering of maps.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
InsertionMode< G, A, R > getTopmostInsertionMode()
Returns the "topmost" insertion mode.
GameObjects are the objects based on Archetypes found on maps.
int getWidth()
Returns the width of the area.
void removeMapModelListener(@NotNull final MapModelListener< G, A, R > listener)
Removes a MapModelListener to be notified about changes of the cut/copied game objects.
List< G > getAllGameObjects()
Return all game objects.
Base classes for rendering maps.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
A map view consists of a map grid and a map cursor, and is attached to a map control.
boolean isEmpty()
Returns whether the map is empty.
void beginTransaction(@NotNull String name)
Starts a new transaction.
List< G > getAllGameObjects()
Returns all game objects.
int getHeight()
Returns the height of the area.
Common base implementation of CopyBuffer.
void paste(@NotNull final MapView< G, A, R > mapView, @NotNull final Point startLocation)
Executing the Paste command.
Interface for MapArchObjects.
The class Size2D represents a 2d rectangular area.
void copy(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executing the Copy command.
static int mod(final int numerator, final int denominator)
Calculates the remainder of.