20 package net.sf.gridarta.gui.map.mapactions;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.awt.Point;
25 import java.awt.Rectangle;
26 import java.io.IOException;
27 import javax.swing.JOptionPane;
28 import javax.swing.JScrollPane;
43 import net.
sf.japi.swing.action.ActionBuilder;
44 import net.
sf.japi.swing.action.ActionBuilderFactory;
45 import org.jetbrains.annotations.NotNull;
46 import org.jetbrains.annotations.Nullable;
58 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
93 this.directionMap = directionMap.clone();
110 mapFile = mapView.getMapControl().getMapModel().getMapFile(mapPath);
113 if (destinationPoint != null) {
118 ACTION_BUILDER.showMessageDialog(parent,
"enterExitNotSaved", mapPath);
121 return enterMap(mapView, mapFile, destinationPoint, direction);
137 }
catch (
final IOException ex) {
142 if (destinationPoint != null) {
144 }
else if (mapView != null) {
149 if (mapView != null && ACTION_BUILDER.showOnetimeConfirmDialog(parent, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
"enterExitClose") == JOptionPane.YES_OPTION) {
163 final Point point2 = point.x == -1 && point.y == -1 ? mapView.getMapControl().getMapModel().getMapArchObject().getEnter() : point;
164 if (!mapView.getMapControl().getMapModel().getMapArchObject().isPointValid(point2)) {
165 ACTION_BUILDER.showMessageDialog(parent,
"enterExitOutside");
168 mapView.setCursorLocation(point2);
182 mapLocation =
new MapLocation(exit, allowRandomMapParameters);
184 ACTION_BUILDER.showMessageDialog(parent,
"enterExitRandomDestination", ex.getMessage());
201 final Dimension newViewSize = newMapView.getViewport().getViewSize();
202 final Rectangle oldViewRectangle = oldMapView.getViewport().getViewRect();
204 final Rectangle scrollTo;
205 switch (directionMap[direction.ordinal()]) {
207 scrollTo =
new Rectangle(oldViewRectangle.x, 0, oldViewRectangle.width, oldViewRectangle.height);
211 scrollTo =
new Rectangle(oldViewRectangle.x, newViewSize.height - oldViewRectangle.height, oldViewRectangle.width, oldViewRectangle.height);
215 scrollTo =
new Rectangle(0, oldViewRectangle.y, oldViewRectangle.width, oldViewRectangle.height);
219 scrollTo =
new Rectangle(newViewSize.width - oldViewRectangle.width, oldViewRectangle.y, oldViewRectangle.width, oldViewRectangle.height);
223 scrollTo =
new Rectangle(0, newViewSize.height - oldViewRectangle.height, oldViewRectangle.width, oldViewRectangle.height);
227 scrollTo =
new Rectangle(0, 0, oldViewRectangle.width, oldViewRectangle.height);
231 scrollTo =
new Rectangle(newViewSize.width - oldViewRectangle.width, 0, oldViewRectangle.width, oldViewRectangle.height);
235 scrollTo =
new Rectangle(newViewSize.width - oldViewRectangle.width, newViewSize.height - oldViewRectangle.height, oldViewRectangle.width, oldViewRectangle.height);
240 scrollTo =
new Rectangle(oldViewRectangle.x, oldViewRectangle.y, oldViewRectangle.width, oldViewRectangle.height);
244 throw new AssertionError();
247 if (scrollTo.x + scrollTo.width > newViewSize.width) {
248 scrollTo.x = newViewSize.width - scrollTo.width;
250 if (scrollTo.x < 0) {
253 if (scrollTo.y + scrollTo.height > newViewSize.height) {
254 scrollTo.y = newViewSize.height - scrollTo.height;
256 if (scrollTo.y < 0) {
259 return scrollTo.getLocation();
272 return new Point((oldCursorLocation.x + direction.getDx() + mapSize.getWidth()) % mapSize.getWidth(), (oldCursorLocation.y + direction.getDy() + mapSize.getHeight()) % mapSize.getHeight());
EnterMap(@NotNull final Component parent, @NotNull final Direction[] directionMap, @NotNull final FileControl< G, A, R > fileControl, @NotNull final MapViewsManager< G, A, R > mapViewsManager)
Creates a new instance.
JScrollPane getScrollPane()
Returns the JScrollPane of this map view.
Exception thrown if the destination path points to the source map.
void closeMapView(@NotNull final MapView< G, A, R > mapView)
Invoked when the user wants to close a map view.
Graphical User Interface of Gridarta.
static Point calculateNewCursorLocation(@NotNull final Point oldCursorLocation, @NotNull final Size2D mapSize, @NotNull final Direction direction)
Calculate the map cursor location for the new viewport.
Exception thrown if a game object does not specify a valid exit path.
void showLocation(@NotNull final MapView< G, A, R > mapView, @NotNull final Point point)
Scrolls a map view to make a give tile visible.
final Direction [] directionMap
Maps map relative direction to map window direction.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
Represents a maps directory local map path.
Stores all existing MapViews.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
MapModel< G, A, R > getMapModel()
Returns the map model.
void setLocation(@NotNull final Point p)
Move cursor to a new location.
Base package of all Gridarta classes.
Point calculateNewViewPosition(@NotNull final JScrollPane oldMapView, @NotNull final JScrollPane newMapView, @NotNull final Direction direction)
Calculate the view position for the new viewport.
Reflects a game object (object on a map).
boolean enterExit(@NotNull final MapView< G, A, R > mapView, @NotNull final GameObject< G, A, R > exit, final boolean allowRandomMapParameters)
Opens the map an exit game object points to.
void reportLoadError(@Nullable File file, @NotNull String message)
MapView< G, A, R > openMapFileWithView(@NotNull final MapFile mapFile, @Nullable final Point viewPosition, @Nullable final Point centerSquare)
Load a map file and create a map view.
MapPath getMapPath()
Returns the map path.
GameObjects are the objects based on Archetypes found on maps.
final Component parent
The component for showing dialog boxes.
Base classes for rendering maps.
boolean enterMap(@Nullable final MapView< G, A, R > mapView, @NotNull final MapFile mapFile, @Nullable final Point destinationPoint, @NotNull final Direction direction)
Enters a map.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
Exception thrown if an operation is attempted on an unsaved map.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Represents a location on a map consisting of a map path and a map coordinate.
final FileControl< G, A, R > fileControl
The FileControl.
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
Helper class for entering maps.
Point getMapCoordinate()
Returns the map coordinate.
The location of a map file with a map directory.
Interface for MapArchObjects.
The class Size2D represents a 2d rectangular area.
boolean enterMap(@NotNull final MapView< G, A, R > mapView, @NotNull final MapPath mapPath, @NotNull final Direction direction, @Nullable final Point destinationPoint)
Enters a map wanted.