From: <aki...@us...> - 2013-01-03 20:10:44
|
Revision: 9205 http://gridarta.svn.sourceforge.net/gridarta/?rev=9205&view=rev Author: akirschbaum Date: 2013-01-03 20:10:36 +0000 (Thu, 03 Jan 2013) Log Message: ----------- Do not disable map cursor in "enter xyz map". Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/src/app/net/sf/gridarta/gui/map/mapactions/EnterMap.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2012-09-08 14:46:36 UTC (rev 9204) +++ trunk/atrinik/ChangeLog 2013-01-03 20:10:36 UTC (rev 9205) @@ -1,3 +1,7 @@ +2013-01-03 Andreas Kirschbaum + + * Do not disable map cursor in "enter xyz map". + 2012-09-08 Andreas Kirschbaum * Fix ClassCastException when iconifying map views. Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2012-09-08 14:46:36 UTC (rev 9204) +++ trunk/crossfire/ChangeLog 2013-01-03 20:10:36 UTC (rev 9205) @@ -1,3 +1,7 @@ +2013-01-03 Andreas Kirschbaum + + * Do not disable map cursor in "enter xyz map". + 2012-09-08 Andreas Kirschbaum * Fix ClassCastException when iconifying map views. Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2012-09-08 14:46:36 UTC (rev 9204) +++ trunk/daimonin/ChangeLog 2013-01-03 20:10:36 UTC (rev 9205) @@ -1,3 +1,7 @@ +2013-01-03 Andreas Kirschbaum + + * Do not disable map cursor in "enter xyz map". + 2012-09-08 Andreas Kirschbaum * Fix ClassCastException when iconifying map views. Modified: trunk/src/app/net/sf/gridarta/gui/map/mapactions/EnterMap.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapactions/EnterMap.java 2012-09-08 14:46:36 UTC (rev 9204) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/EnterMap.java 2013-01-03 20:10:36 UTC (rev 9205) @@ -41,6 +41,7 @@ import net.sf.gridarta.model.mappathnormalizer.MapPathNormalizer; import net.sf.gridarta.model.mappathnormalizer.RelativePathOnUnsavedMapException; import net.sf.gridarta.model.mappathnormalizer.SameMapException; +import net.sf.gridarta.utils.Size2D; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; import org.jetbrains.annotations.NotNull; @@ -110,7 +111,7 @@ * @param path path to map that should be loaded * @param direction the direction to go * @param destinationPoint the desired destination point on the map (pass - * 0|0 if unknown, and note that the point gets modified) + * <code>null</code> if unknown, and note that the point gets modified) * @return whether the destination map has been entered */ public boolean enterMap(@NotNull final MapView<G, A, R> mapView, @NotNull final String path, @NotNull final Direction direction, @Nullable final Point destinationPoint) { @@ -159,6 +160,10 @@ showLocation(newMapView, destinationPoint); } else if (mapView != null) { newMapView.getScrollPane().getViewport().setViewPosition(calculateNewViewPosition(mapView.getScrollPane(), newMapView.getScrollPane(), direction)); + final Point newCursorLocation = calculateNewCursorLocation(mapView, newMapView, direction); + if (newCursorLocation != null) { + newMapView.getMapCursor().setLocation(newCursorLocation); + } } if (mapView != null && ACTION_BUILDER.showOnetimeConfirmDialog(parent, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, "enterExitClose") == JOptionPane.YES_OPTION) { @@ -269,4 +274,53 @@ return scrollTo.getLocation(); } + /** + * Calculate the map cursor location for the new viewport. + * @param oldMapView the old map view + * @param newMapView the new map view + * @param direction the direction to scroll + * @return the new map cursor location + * @noinspection TypeMayBeWeakened + */ + @Nullable + private Point calculateNewCursorLocation(@Nullable final MapView<G, A, R> oldMapView, @NotNull final MapView<G, A, R> newMapView, @NotNull final Direction direction) { + if (oldMapView == null) { + return null; + } + final Point oldCursorLocation = oldMapView.getMapCursor().getLocation(); + if (oldCursorLocation == null) { + return null; + } + + final Size2D mapSize = newMapView.getMapControl().getMapModel().getMapArchObject().getMapSize(); + switch (direction) { + case SOUTH: + return new Point(oldCursorLocation.x, 0); + + case NORTH: + return new Point(oldCursorLocation.x, mapSize.getHeight() - 1); + + case EAST: + return new Point(0, oldCursorLocation.y); + + case WEST: + return new Point(mapSize.getWidth() - 1, oldCursorLocation.y); + + case NORTH_EAST: + return new Point(0, mapSize.getHeight() - 1); + + case SOUTH_EAST: + return new Point(0, 0); + + case SOUTH_WEST: + return new Point(mapSize.getWidth() - 1, 0); + + case NORTH_WEST: + return new Point(mapSize.getWidth() - 1, mapSize.getHeight() - 1); + + default: + throw new AssertionError(); + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |