Gridarta Editor
MapActions.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.map.mapactions;
21 
22 import java.awt.Frame;
23 import java.awt.Point;
24 import java.io.File;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Iterator;
29 import javax.swing.Action;
30 import javax.swing.filechooser.FileFilter;
58 import net.sf.gridarta.utils.Size2D;
59 import net.sf.japi.swing.action.ActionBuilder;
60 import net.sf.japi.swing.action.ActionBuilderFactory;
61 import net.sf.japi.swing.action.ActionMethod;
62 import net.sf.japi.swing.action.ToggleAction;
63 import org.jetbrains.annotations.NotNull;
64 import org.jetbrains.annotations.Nullable;
65 
70 public class MapActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> {
71 
75  @NotNull
76  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
77 
81  @NotNull
82  private final String[] directionsMap = { "North", "East", "South", "West", "NorthEast", "SouthEast", "SouthWest", "NorthWest", "Up", "Down" };
83 
87  @Nullable
88  private ToggleAction aGridVisible;
89 
93  @Nullable
94  private ToggleAction aSmoothing;
95 
99  @Nullable
100  private ToggleAction aDoubleFaces;
101 
105  @Nullable
106  private ToggleAction aTileShow;
107 
111  @Nullable
112  private ToggleAction aTileStretching;
113 
117  @Nullable
118  private Action aMapCreateView;
119 
123  @Nullable
124  private Action aMapProperties;
125 
129  @Nullable
130  private ToggleAction aAutoJoin;
131 
135  @Nullable
136  private Action aShrinkMapSize;
137 
141  @Nullable
142  private Action aEnterExit;
143 
147  @Nullable
148  private Action aNextExit;
149 
153  @Nullable
154  private Action aPrevExit;
155 
159  @Nullable
160  private Action aDeleteUnknownObjects;
161 
165  @NotNull
166  private final Action[] aDirections = new Action[directionsMap.length];
167 
171  @NotNull
172  private final Action[] aCreateTiles = new Action[directionsMap.length];
173 
177  @NotNull
178  private final Frame helpParent;
179 
183  @NotNull
185 
189  @NotNull
190  private final FileFilter mapFileFilter;
191 
195  @NotNull
197 
201  @NotNull
203 
207  @NotNull
209 
213  private final boolean allowRandomMapParameters;
214 
218  @NotNull
220 
224  @NotNull
226 
230  @NotNull
232 
236  @Nullable
238 
242  @NotNull
244 
248  @NotNull
250 
255  @NotNull
257 
258  @Override
259  public void gridVisibleChanged(final boolean gridVisible) {
260  updateActions();
261  }
262 
263  @Override
264  public void lightVisibleChanged(final boolean lightVisible) {
265  updateActions();
266  }
267 
268  @Override
269  public void smoothingChanged(final boolean smoothing) {
270  updateActions();
271  }
272 
273  @Override
274  public void tileStretchingChanged(final boolean tileStretchingChanged) {
275  updateActions();
276  }
277 
278  @Override
279  public void doubleFacesChanged(final boolean doubleFaces) {
280  updateActions();
281  }
282 
283  @Override
284  public void alphaTypeChanged(final int alphaType) {
285  // ignore
286  }
287 
288  @Override
289  public void editTypeChanged(final int editType) {
290  // ignore
291  }
292 
293  @Override
294  public void autojoinChanged(final boolean autojoin) {
295  updateActions();
296  }
297 
298  };
299 
304  @NotNull
306 
307  @Override
308  public void currentMapChanged(@Nullable final MapControl<G, A, R> mapControl) {
309  updateActions();
310  }
311 
312  @Override
313  public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) {
314  // ignore
315  }
316 
317  @Override
318  public void mapClosing(@NotNull final MapControl<G, A, R> mapControl) {
319  // ignore
320  }
321 
322  @Override
323  public void mapClosed(@NotNull final MapControl<G, A, R> mapControl) {
324  // ignore
325  }
326 
327  };
328 
332  @NotNull
334 
335  @Override
336  public void mapMetaChanged() {
337  updateActions();
338  }
339 
340  @Override
341  public void mapSizeChanged(@NotNull final Size2D mapSize) {
342  // ignore
343  }
344 
345  };
346 
363  public MapActions(@NotNull final Frame helpParent, @NotNull final MapManager<G, A, R> mapManager, @NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final ExitMatcher<G, A, R> exitMatcher, @NotNull final FileFilter mapFileFilter, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, final boolean allowRandomMapParameters, @NotNull final MapPropertiesDialogFactory<G, A, R> mapPropertiesDialogFactory, @NotNull final MapViewSettings mapViewSettings, @NotNull final MapViewsManager<G, A, R> mapViewsManager, @NotNull final EnterMap<G, A, R> enterMap, @NotNull final ProjectSettings projectSettings) {
364  this.helpParent = helpParent;
365  this.exitMatcher = exitMatcher;
366  this.mapFileFilter = mapFileFilter;
367  this.selectedSquareModel = selectedSquareModel;
368  this.enterMap = enterMap;
369  this.allowRandomMapParameters = allowRandomMapParameters;
370  this.mapPropertiesDialogFactory = mapPropertiesDialogFactory;
371  this.mapViewSettings = mapViewSettings;
372  this.mapViewsManager = mapViewsManager;
373  this.mapManager = mapManager;
374  this.projectSettings = projectSettings;
375  shrinkMapSizeDialogManager = new ShrinkMapSizeDialogManager<>(mapViewManager);
376  mapViewSettings.addMapViewSettingsListener(mapViewSettingsListener);
377  mapManager.addMapManagerListener(mapManagerListener);
378  }
379 
385  @ActionMethod
386  public boolean isGridVisible() {
387  return doGridVisible(false, false) && mapViewSettings.isGridVisible();
388  }
389 
396  @ActionMethod
397  public void setGridVisible(final boolean gridVisible) {
398  doGridVisible(true, gridVisible);
399  }
400 
406  @ActionMethod
407  public boolean isSmoothing() {
408  return doSmoothing(false, false) && mapViewSettings.isSmoothing();
409  }
410 
417  @ActionMethod
418  public void setSmoothing(final boolean smoothing) {
419  doSmoothing(true, smoothing);
420  }
421 
426  @ActionMethod
427  public boolean isDoubleFaces() {
428  return doDoubleFaces(false, false) && mapViewSettings.isDoubleFaces();
429  }
430 
436  @ActionMethod
437  public void setDoubleFaces(final boolean doubleFaces) {
438  doDoubleFaces(true, doubleFaces);
439  }
440 
446  @ActionMethod
447  public boolean isTileShow() {
448  return /*doTileShow(false, false) && */false; // XXX: not yet implemented
449  }
450 
456  @ActionMethod
457  public boolean isTileStretching() {
458  return doTileStretching(false, false) && mapViewSettings.isTileStretching();
459  }
460 
467  @ActionMethod
468  public void setTileStretching(final boolean tileStretching) {
469  doTileStretching(true, tileStretching);
470  }
471 
476  @ActionMethod
477  public void setTileShow(final boolean tileShow) {
478  doTileShow(true, tileShow);
479  }
480 
484  @ActionMethod
485  public void mapCreateView() {
486  doMapCreateView(true);
487  }
488 
492  @ActionMethod
493  public void mapProperties() {
494  doMapProperties(true);
495  }
496 
500  @ActionMethod
501  public void shrinkMapSize() {
502  doShrinkMapSize(true);
503  }
504 
510  @ActionMethod
511  public boolean isAutoJoin() {
512  return doAutoJoin(false, false) && mapViewSettings.isAutojoin();
513  }
514 
519  @ActionMethod
520  public void setAutoJoin(final boolean autoJoin) {
521  doAutoJoin(true, autoJoin);
522  }
523 
527  @ActionMethod
528  public void enterExit() {
529  doEnterExit(true);
530  }
531 
535  @ActionMethod
536  public void nextExit() {
537  doNextExit(true);
538  }
539 
543  @ActionMethod
544  public void prevExit() {
545  doPrevExit(true);
546  }
547 
553  private void selectExit(@NotNull final MapView<G, A, R> mapView, final int direction) {
554  final TopLevelGameObjectIterator<G, A, R> gameObjectIterator = new TopLevelGameObjectIterator<>(mapView.getMapControl().getMapModel(), mapView.getMapCursor().getLocation(), direction, true);
555  final Iterator<G> exitIterator = new FilterGameObjectIterator<>(gameObjectIterator, exitMatcher);
556  if (exitIterator.hasNext()) {
557  final G exit = exitIterator.next();
558  final MapSquare<G, A, R> mapSquare = exit.getMapSquare();
559  assert mapSquare != null;
560  mapView.setCursorLocation(mapSquare.getMapLocation());
561  }
562  }
563 
567  @ActionMethod
568  public void enterNorthMap() {
569  doEnterMap(true, Direction.NORTH);
570  }
571 
575  @ActionMethod
576  public void enterNorthEastMap() {
578  }
579 
583  @ActionMethod
584  public void enterEastMap() {
585  doEnterMap(true, Direction.EAST);
586  }
587 
591  @ActionMethod
592  public void enterSouthEastMap() {
594  }
595 
599  @ActionMethod
600  public void enterSouthMap() {
601  doEnterMap(true, Direction.SOUTH);
602  }
603 
607  @ActionMethod
608  public void enterSouthWestMap() {
610  }
611 
615  @ActionMethod
616  public void enterWestMap() {
617  doEnterMap(true, Direction.WEST);
618  }
619 
623  @ActionMethod
624  public void enterNorthWestMap() {
626  }
627 
631  @ActionMethod
632  public void enterUpMap() {
633  doEnterMap(true, Direction.UP);
634  }
635 
639  @ActionMethod
640  public void enterDownMap() {
641  doEnterMap(true, Direction.DOWN);
642  }
643 
647  @ActionMethod
648  public void createTileNorth() {
650  }
651 
655  @ActionMethod
656  public void createTileEast() {
657  doCreateTile(true, Direction.EAST);
658  }
659 
663  @ActionMethod
664  public void createTileSouth() {
666  }
667 
671  @ActionMethod
672  public void createTileWest() {
673  doCreateTile(true, Direction.WEST);
674  }
675 
679  @ActionMethod
680  public void createTileNorthEast() {
682  }
683 
687  @ActionMethod
688  public void createTileSouthEast() {
690  }
691 
695  @ActionMethod
696  public void createTileSouthWest() {
698  }
699 
703  @ActionMethod
704  public void createTileNorthWest() {
706  }
707 
711  @ActionMethod
712  public void createTileUp() {
713  doCreateTile(true, Direction.UP);
714  }
715 
719  @ActionMethod
720  public void createTileDown() {
721  doCreateTile(true, Direction.DOWN);
722  }
723 
727  @ActionMethod
728  public void deleteUnknownObjects() {
730  }
731 
738  public void enterMap(@NotNull final MapFile mapFile, @Nullable final Point destinationPoint) {
739  enterMap.enterMap(currentMapView, mapFile, destinationPoint, Direction.NORTH);
740  }
741 
745  private void updateActions() {
746  if (aGridVisible != null) {
747  //noinspection ConstantConditions
748  aGridVisible.setEnabled(doGridVisible(false, false));
749  //noinspection ConstantConditions
750  aGridVisible.setSelected(isGridVisible());
751  }
752  if (aSmoothing != null) {
753  //noinspection ConstantConditions
754  aSmoothing.setEnabled(doSmoothing(false, false));
755  //noinspection ConstantConditions
756  aSmoothing.setSelected(isSmoothing());
757  }
758  if (aDoubleFaces != null) {
759  //noinspection ConstantConditions
760  aDoubleFaces.setEnabled(doDoubleFaces(false, false));
761  //noinspection ConstantConditions
762  aDoubleFaces.setSelected(isDoubleFaces());
763  }
764  if (aTileShow != null) {
765  //noinspection ConstantConditions
766  aTileShow.setEnabled(doTileShow(false, false));
767  //noinspection ConstantConditions
768  aTileShow.setSelected(isTileShow());
769  }
770  if (aTileStretching != null) {
771  //noinspection ConstantConditions
772  aTileStretching.setEnabled(doTileStretching(false, false));
773  //noinspection ConstantConditions
774  aTileStretching.setSelected(isTileStretching());
775  }
776  if (aMapCreateView != null) {
777  //noinspection ConstantConditions
778  aMapCreateView.setEnabled(doMapCreateView(false));
779  }
780  if (aMapProperties != null) {
781  //noinspection ConstantConditions
782  aMapProperties.setEnabled(doMapProperties(false));
783  }
784  if (aAutoJoin != null) {
785  //noinspection ConstantConditions
786  aAutoJoin.setEnabled(doAutoJoin(false, false));
787  //noinspection ConstantConditions
788  aAutoJoin.setSelected(isAutoJoin());
789  }
790  if (aEnterExit != null) {
791  //noinspection ConstantConditions
792  aEnterExit.setEnabled(doEnterExit(false));
793  }
794  if (aNextExit != null) {
795  //noinspection ConstantConditions
796  aNextExit.setEnabled(doNextExit(false));
797  }
798  if (aPrevExit != null) {
799  //noinspection ConstantConditions
800  aPrevExit.setEnabled(doPrevExit(false));
801  }
802  if (aDeleteUnknownObjects != null) {
803  //noinspection ConstantConditions
804  aDeleteUnknownObjects.setEnabled(doDeleteUnknownObjects(false));
805  }
806  for (final Direction direction : Direction.values()) {
807  if (aDirections[direction.ordinal()] != null) {
808  aDirections[direction.ordinal()].setEnabled(doEnterMap(false, direction));
809  }
810  }
811  for (final Direction direction : Direction.values()) {
812  if (aCreateTiles[direction.ordinal()] != null) {
813  aCreateTiles[direction.ordinal()].setEnabled(doCreateTile(false, direction));
814  }
815  }
816  if (aShrinkMapSize != null) {
817  //noinspection ConstantConditions
818  aShrinkMapSize.setEnabled(doShrinkMapSize(false));
819  }
820  }
821 
830  private boolean doGridVisible(final boolean performAction, final boolean gridVisible) {
831  if (performAction) {
832  mapViewSettings.setGridVisible(gridVisible);
833  }
834 
835  return true;
836  }
837 
845  private boolean doSmoothing(final boolean performAction, final boolean smoothing) {
846  if (performAction) {
847  mapViewSettings.setSmoothing(smoothing);
848  }
849 
850  return true;
851  }
852 
860  private boolean doTileStretching(final boolean performAction, final boolean tileStretching) {
861  if (performAction) {
862  mapViewSettings.setTileStretching(tileStretching);
863  }
864 
865  return true;
866  }
867 
876  private boolean doDoubleFaces(final boolean performAction, final boolean doubleFaces) {
877  if (performAction) {
878  mapViewSettings.setDoubleFaces(doubleFaces);
879  }
880 
881  return true;
882  }
883 
892  private boolean doTileShow(final boolean performAction, final boolean tileShow) {
893  return false; // XXX: not yet implemented
894  }
895 
901  private boolean doMapCreateView(final boolean performAction) {
902  final MapView<G, A, R> mapView = currentMapView;
903  if (mapView == null) {
904  return false;
905  }
906 
907  if (performAction) {
908  mapViewsManager.newMapView(mapView.getMapControl(), mapView.getScrollPane().getViewport().getViewPosition(), null);
909  }
910 
911  return true;
912  }
913 
919  private boolean doMapProperties(final boolean performAction) {
920  final MapView<G, A, R> mapView = currentMapView;
921  if (mapView == null) {
922  return false;
923  }
924 
925  if (performAction) {
926  mapPropertiesDialogFactory.showDialog(mapView.getComponent(), helpParent, mapView.getMapControl().getMapModel(), mapFileFilter);
927  }
928 
929  return true;
930  }
931 
940  private boolean doAutoJoin(final boolean performAction, final boolean autoJoin) {
941  if (performAction) {
942  mapViewSettings.setAutojoin(autoJoin);
943  }
944 
945  return true;
946  }
947 
953  private boolean doEnterExit(final boolean performAction) {
954  final MapView<G, A, R> mapView = currentMapView;
955  if (mapView == null) {
956  return false;
957  }
958 
959  final GameObject<G, A, R> exit;
960  final GameObject<G, A, R> selectedExit = exitMatcher.getValidExit(selectedSquareModel.getSelectedGameObject());
961  if (selectedExit == null) {
962  final GameObject<G, A, R> cursorExit = exitMatcher.getValidExit(mapView.getMapControl().getMapModel(), mapView.getMapCursor().getLocation());
963  if (cursorExit == null) {
964  return false;
965  }
966 
967  exit = cursorExit;
968  } else {
969  exit = selectedExit;
970  }
971 
972  if (performAction) {
973  if (!enterMap.enterExit(mapView, exit, allowRandomMapParameters)) {
974  return false;
975  }
976  }
977 
978  return true;
979  }
980 
986  private boolean doNextExit(final boolean performAction) {
987  final MapView<G, A, R> mapView = currentMapView;
988  if (mapView == null) {
989  return false;
990  }
991 
992  if (performAction) {
993  selectExit(mapView, 1);
994  }
995 
996  return true;
997  }
998 
1004  private boolean doPrevExit(final boolean performAction) {
1005  final MapView<G, A, R> mapView = currentMapView;
1006  if (mapView == null) {
1007  return false;
1008  }
1009 
1010  if (performAction) {
1011  selectExit(mapView, -1);
1012  }
1013 
1014  return true;
1015  }
1016 
1022  private boolean doDeleteUnknownObjects(final boolean performAction) {
1023  final MapView<G, A, R> mapView = currentMapView;
1024  if (mapView == null) {
1025  return false;
1026  }
1027 
1028  if (performAction) {
1029  final MapControl<G, A, R> mapControl = mapView.getMapControl();
1030  final MapModel<G, A, R> mapModel = mapControl.getMapModel();
1031  final Collection<G> gameObjectsToDelete = new ArrayList<>();
1032  for (final Iterable<G> mapSquare : mapModel) {
1033  for (final G gameObject : mapSquare) {
1034  if (gameObject.isHead() && gameObject.hasUndefinedArchetype()) {
1035  gameObjectsToDelete.add(gameObject);
1036  }
1037  }
1038  }
1039  if (!gameObjectsToDelete.isEmpty()) {
1040  mapModel.beginTransaction("delete undefined objects");
1041  try {
1042  for (final G gameObject : gameObjectsToDelete) {
1043  mapModel.removeGameObject(gameObject, false);
1044  }
1045  } finally {
1046  mapModel.endTransaction();
1047  }
1048  }
1049  }
1050 
1051  return true;
1052  }
1053 
1060  public boolean doEnterMap(final boolean performAction, @NotNull final Direction direction) {
1061  final MapView<G, A, R> mapView = currentMapView;
1062  if (mapView == null) {
1063  return false;
1064  }
1065 
1066  final String path = mapView.getMapControl().getMapModel().getMapArchObject().getTilePath(direction);
1067  if (path.isEmpty()) {
1068  return false;
1069  }
1070 
1071  if (performAction) {
1072  if (!enterMap.enterMap(mapView, MapPathUtils.newMapPath(path), direction, null)) {
1073  return false;
1074  }
1075  }
1076 
1077  return true;
1078  }
1079 
1086  public boolean doCreateTile(final boolean performAction, @NotNull final Direction direction) {
1087  final MapView<G, A, R> mapView = currentMapView;
1088  if (mapView == null) {
1089  return false;
1090  }
1091 
1092  final MapModel<G, A, R> currentMapModel = mapView.getMapControl().getMapModel();
1093  final A currentMapArchObj = currentMapModel.getMapArchObject();
1094  final String path = currentMapArchObj.getTilePath(direction);
1095  if (!path.isEmpty()) {
1096  return false;
1097  }
1098 
1099  if (currentMapModel.getMapFile() == null) {
1100  return false;
1101  }
1102 
1103  final String newPath = currentMapArchObj.calculateTilePath(direction, currentMapModel.getMapFile());
1104  final MapFile mapFile = new MapFile(currentMapModel.getMapFile(), MapPathUtils.newMapPath(newPath));
1105 
1106  if (mapFile.getFile().isDirectory()) {
1107  return false;
1108  }
1109  if (mapFile.getFile().exists()) {
1110  return false;
1111  }
1112 
1113  if (performAction) {
1114  final File dir = mapFile.getFile().getParentFile();
1115  if (!dir.exists()) {
1116  if (!dir.mkdirs()) {
1117  ACTION_BUILDER.showMessageDialog(mapView.getComponent(), "createTileErrorMakeDirectories", dir.toString());
1118  return false;
1119  }
1120  }
1121 
1122  final A mapArchObject = currentMapArchObj.createClone();
1123 
1124  // Avoid cloning tile paths, as they will be incorrect anyway. In
1125  // Atrinik, automatic tile linking will take care of this issue.
1126  for (final Direction direction2 : Direction.values()) {
1127  mapArchObject.setTilePath(direction2, "");
1128  }
1129 
1130  final MapControl<G, A, R> mapControl = mapManager.newMap(null, mapArchObject, mapFile, true);
1131  try {
1132  mapControl.save();
1133  } catch (final IOException ex) {
1134  return false;
1135  } finally {
1136  mapManager.release(mapControl);
1137  }
1138 
1139  currentMapArchObj.calculateTilePaths(currentMapModel.getMapFile(), projectSettings.getMapsDirectory());
1140  doEnterMap(true, direction);
1141  }
1142 
1143  return true;
1144  }
1145 
1151  private boolean doShrinkMapSize(final boolean performAction) {
1152  final MapView<G, A, R> mapView = currentMapView;
1153  if (mapView == null) {
1154  return false;
1155  }
1156 
1157  if (performAction) {
1158  shrinkMapSizeDialogManager.showDialog(mapView);
1159  }
1160 
1161  return true;
1162  }
1163 
1164  @Override
1165  public void setAction(@NotNull final Action action, @NotNull final String name) {
1166  if (name.equals("mapCreateView")) {
1167  aMapCreateView = action;
1168  } else if (name.equals("mapProperties")) {
1169  aMapProperties = action;
1170  } else if (name.equals("autoJoin")) {
1171  aAutoJoin = (ToggleAction) action;
1172  } else if (name.equals("shrinkMapSize")) {
1173  aShrinkMapSize = action;
1174  } else if (name.equals("enterExit")) {
1175  aEnterExit = action;
1176  } else if (name.equals("nextExit")) {
1177  aNextExit = action;
1178  } else if (name.equals("prevExit")) {
1179  aPrevExit = action;
1180  } else if (name.equals("deleteUnknownObjects")) {
1181  aDeleteUnknownObjects = action;
1182  } else if (name.equals("gridVisible")) {
1183  aGridVisible = (ToggleAction) action;
1184  } else if (name.equals("smoothing")) {
1185  aSmoothing = (ToggleAction) action;
1186  } else if (name.equals("doubleFaces")) {
1187  aDoubleFaces = (ToggleAction) action;
1188  } else if (name.equals("tileShow")) {
1189  aTileShow = (ToggleAction) action;
1190  } else if (name.equals("tileStretching")) {
1191  aTileStretching = (ToggleAction) action;
1192  } else {
1193  int i;
1194  for (i = 0; i < directionsMap.length; i++) {
1195  if (name.equals("enter" + directionsMap[i] + "Map")) {
1196  aDirections[i] = action;
1197  break;
1198  }
1199 
1200  if (name.equals("createTile" + directionsMap[i])) {
1201  aCreateTiles[i] = action;
1202  break;
1203  }
1204  }
1205  if (i >= directionsMap.length) {
1206  throw new IllegalArgumentException();
1207  }
1208  }
1209  updateActions();
1210  }
1211 
1212  @Override
1213  public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
1214  if (currentMapView != null) {
1215  currentMapView.getMapControl().getMapModel().getMapArchObject().removeMapArchObjectListener(mapArchObjectListener);
1216  }
1217  currentMapView = mapView;
1218  if (currentMapView != null) {
1219  currentMapView.getMapControl().getMapModel().getMapArchObject().addMapArchObjectListener(mapArchObjectListener);
1220  }
1221  updateActions();
1222  }
1223 
1224  @Override
1225  public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
1226  // ignore
1227  }
1228 
1229  @Override
1230  public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
1231  // ignore
1232  }
1233 
1234  @Override
1235  public void mapCursorChangedPos(@NotNull final Point location) {
1236  updateActions();
1237  }
1238 
1239  @Override
1240  public void mapCursorChangedMode() {
1241  // ignore
1242  }
1243 
1244  @Override
1245  public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
1246  // ignore
1247  }
1248 
1249  @Override
1250  public void mapCursorChangedSize() {
1251  // ignore
1252  }
1253 
1254 }
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
void save()
Saves the map to a file.
void enterExit()
Try to load the map where the selected map-exit points to.
G getSelectedGameObject()
Returns the currently selected GameObject within this list (currently selected MapSquare).
JScrollPane getScrollPane()
Returns the JScrollPane of this map view.
final Frame helpParent
The parent frame for help windows.
boolean doPrevExit(final boolean performAction)
Executes the "prev exit" action.
Interface for listeners listening on map arch object changes.
ToggleAction aTileShow
Action for "tile show".
final ExitMatcher< G, A, R > exitMatcher
The ExitMatcher for selecting exit game objects.
boolean isGridVisible()
Action method for "grid visible".
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
final MapViewSettings mapViewSettings
The MapViewSettings instance to use.
void mapCreateView()
Action method for "create view".
A MapModel reflects the data of a map.
Definition: MapModel.java:75
A MapManager manages all opened maps.
Definition: MapManager.java:37
void release(@NotNull MapControl< G, A, R > mapControl)
Releases a MapControl instance.
boolean isAutojoin()
Returns whether "autojoin" is enabled.
Graphical User Interface of Gridarta.
boolean isTileStretching()
Action method for "tile-stretching".
MapControl< G, A, R > newMap(@Nullable List< G > objects, @NotNull A mapArchObject, @Nullable MapFile mapFile, boolean interactive)
Creates a new map control without view.
void enterEastMap()
Action method for entering the east map.
Settings that apply to a project.
Iterator for iterating over top-level game object of a map model.
ToggleAction aDoubleFaces
Action for "draw double faces".
void showDialog(@NotNull final MapView< G, A, R > mapView)
Shows a dialog to shrink the map size.
void setAutoJoin(final boolean autoJoin)
Action method for "autoJoin".
void setTileStretching(boolean tileStretching)
Sets the tile-stretching setting.
MapView< G, A, R > newMapView(@NotNull final MapControl< G, A, R > mapControl, @Nullable final Point viewPosition, @Nullable final Point centerSquare)
Creates a new map view.
boolean doEnterMap(final boolean performAction, @NotNull final Direction direction)
Executes the "enter map" action.
void setAutojoin(boolean autojoin)
Sets the "autojoin" state.
void setTileStretching(final boolean tileStretching)
Sets whether tile-stretching of the current map is active.
void enterDownMap()
Action method for entering the down map.
boolean isAutoJoin()
Action method for "autojoin".
void showDialog(@NotNull Component parent, @NotNull Frame helpParent, @NotNull MapModel< G, A, R > mapModel, @NotNull FileFilter mapFileFilter)
Show a dialog querying the user for map properties.
final MapArchObjectListener mapArchObjectListener
The MapArchObjectListener attached to currentMapView.
void enterSouthWestMap()
Action method for entering the south west map.
MapView< G, A, R > currentMapView
The current map view, or.
final FileFilter mapFileFilter
The Swing file filter to use.
void createTileDown()
Action method for creating down tiled map.
Action aNextExit
Action for "next exit".
void deleteUnknownObjects()
Deletes all game objects referencing unknown archetypes.
void mapProperties()
Action method for "map properties".
ToggleAction aTileStretching
Action for "tile-stretching visible".
boolean doAutoJoin(final boolean performAction, final boolean autoJoin)
Executes the "auto join" action.
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener which is attached to the current map if the current map is tracked...
MapControl< G, A, R > getMapControl()
Return the controller of this view.
final Action [] aDirections
Action for "enter xxx map".
boolean isSmoothing()
Returns the smoothing setting.
void enterNorthMap()
Action method for entering the north map.
void mapViewClosing(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view is to be closed.
MapActions(@NotNull final Frame helpParent, @NotNull final MapManager< G, A, R > mapManager, @NotNull final MapViewManager< G, A, R > mapViewManager, @NotNull final ExitMatcher< G, A, R > exitMatcher, @NotNull final FileFilter mapFileFilter, @NotNull final SelectedSquareModel< G, A, R > selectedSquareModel, final boolean allowRandomMapParameters, @NotNull final MapPropertiesDialogFactory< G, A, R > mapPropertiesDialogFactory, @NotNull final MapViewSettings mapViewSettings, @NotNull final MapViewsManager< G, A, R > mapViewsManager, @NotNull final EnterMap< G, A, R > enterMap, @NotNull final ProjectSettings projectSettings)
Create a new instance.
Point getLocation()
Get position of cursor.
Definition: MapCursor.java:226
MapModel< G, A, R > getMapModel()
Returns the map model.
final MapPropertiesDialogFactory< G, A, R > mapPropertiesDialogFactory
The MapPropertiesDialogFactory to use.
Base package of all Gridarta classes.
boolean doCreateTile(final boolean performAction, @NotNull final Direction direction)
Executes the "create tile" action.
boolean isTileShow()
Action method for "tile show".
final Action [] aCreateTiles
Action for "create tile xxx".
void setDoubleFaces(boolean doubleFaces)
Sets whether double faces should be drawn double height.
void mapCursorChangedSize()
Called whenever the map cursor&#39;s map grid size has changed.
Reflects a game object (object on a map).
Definition: GameObject.java:36
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.
Definition: EnterMap.java:179
An Iterator that filters another iterator according to a GameObjectMatcher.
ToggleAction aAutoJoin
Action for "autojoin".
boolean isGridVisible()
Get the visibility of the grid.
boolean doTileStretching(final boolean performAction, final boolean tileStretching)
Executes the "tile-stretching" action.
void setGridVisible(final boolean gridVisible)
Sets whether the grid of the current map should be visible.
void createTileNorthEast()
Action method for creating northeast tiled map.
A global editor action.
Interface for listeners listening to MapManager changes.
void enterMap(@NotNull final MapFile mapFile, @Nullable final Point destinationPoint)
Enters a map.
Selects valid exit game objects from maps.
void nextExit()
Select the next exit.
void createTileWest()
Action method for creating west tiled map.
Action aEnterExit
Action for "enter exit".
void createTileSouth()
Action method for creating south tiled map.
final ProjectSettings projectSettings
The ProjectSettings.
Interface for event listeners that are interested in changes on MapViewSettings.
void updateActions()
Update the actions&#39; state.
void enterNorthWestMap()
Action method for entering the north west map.
Container for settings that affect the rendering of maps.
void mapViewCreated(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view was created.
GameObjects are the objects based on Archetypes found on maps.
void enterUpMap()
Action method for entering the up map.
void mapCursorChangedMode()
This event handler is called when MapCursor changes mode (drag, select).
Action aMapProperties
Action for "map properties".
final SelectedSquareModel< G, A, R > selectedSquareModel
The SelectedSquareModel to use.
G getValidExit(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Point point)
Returns an exit game object on a given map square having exit information.
void createTileSouthEast()
Action method for creating southeast tiled map.
final boolean allowRandomMapParameters
Whether exit paths may point to random maps.
Point getMapLocation()
Returns the coordinate on the map.
Definition: MapSquare.java:124
Interface for listeners interested in events related to MapViewManager instances. ...
void setSmoothing(boolean smoothing)
Sets the smoothing setting.
Utility class for MapPath related functions.
Displays the contents of the currently selected map square.
Manages actions in the "map" menu.
Definition: MapActions.java:70
boolean isSmoothing()
Action method for "smoothing".
ToggleAction aGridVisible
Action for "grid visible".
Definition: MapActions.java:88
void createTileNorthWest()
Action method for creating northwest tiled map.
final MapViewSettingsListener mapViewSettingsListener
The MapViewSettingsListener attached to mapViewSettings.
Base classes for rendering maps.
void createTileUp()
Action method for creating up tiled map.
boolean doGridVisible(final boolean performAction, final boolean gridVisible)
Executes the "grid visible" action.
void enterSouthEastMap()
Action method for entering the south east map.
void createTileNorth()
Action method for creating north tiled map.
void mapCursorChangedGameObject(@Nullable final MapSquare< G, A, R > mapSquare, @Nullable final G gameObject)
Called whenever the selected game object has changed.
void setDoubleFaces(final boolean doubleFaces)
Sets whether double faces on the current map should be shown.
final MapManager< G, A, R > mapManager
The MapManager.
Action aDeleteUnknownObjects
Action for "delete unknown objects".
void activeMapViewChanged(@Nullable final MapView< G, A, R > mapView)
This event handler is called when the current map view has changed.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
void mapCursorChangedPos(@NotNull final Point location)
This event handler is called when MapCursor has moved.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
boolean doMapCreateView(final boolean performAction)
Executes the "map create view" action.
void enterSouthMap()
Action method for entering the south map.
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
Action aMapCreateView
Action for "create view".
boolean doDeleteUnknownObjects(final boolean performAction)
Executes the "delete unknown objects" action.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
MapFile getMapFile()
Returns the map file.
boolean doSmoothing(final boolean performAction, final boolean smoothing)
Executes the "smoothing" action.
File getFile()
Returns a File for this map file.
Definition: MapFile.java:102
void prevExit()
Select the previous exit.
void enterNorthEastMap()
Action method for entering the north east map.
Action aPrevExit
Action for "previous exit".
boolean doEnterExit(final boolean performAction)
Executes the "enter exit" action.
void shrinkMapSize()
Action method for "shrink map size".
final String [] directionsMap
Possible directions for "enter xxx map".
Definition: MapActions.java:82
final EnterMap< G, A, R > enterMap
The EnterMap instance to use.
File getMapsDirectory()
Returns the default maps directory.
static final ActionBuilder ACTION_BUILDER
Action Builder.
Definition: MapActions.java:76
void beginTransaction(@NotNull String name)
Starts a new transaction.
The model component of the selected square control.
boolean doTileShow(final boolean performAction, final boolean tileShow)
Executes the "tile show" action.
boolean doDoubleFaces(final boolean performAction, final boolean doubleFaces)
Executes the "double faces" action.
Component getComponent()
Returns the component associated with this MapView that can be used as parent for dialogs...
boolean doNextExit(final boolean performAction)
Executes the "next exit" action.
final ShrinkMapSizeDialogManager< G, A, R > shrinkMapSizeDialogManager
The ShrinkMapSizeDialogManager instance.
Interface for listeners listening to MapCursor related events.
boolean isDoubleFaces()
Action method for "double faces".
boolean doMapProperties(final boolean performAction)
Executes the "map properties" action.
void setSmoothing(final boolean smoothing)
Sets whether smoothing of the current map is active.
ToggleAction aSmoothing
Action for "smoothing".
Definition: MapActions.java:94
void createTileEast()
Action method for creating east tiled map.
boolean isTileStretching()
Returns the tile-stretching setting.
void createTileSouthWest()
Action method for creating southwest tiled map.
Action aShrinkMapSize
Action for "shrink map size".
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
void setGridVisible(boolean gridVisible)
Set the visibility of the grid.
boolean doShrinkMapSize(final boolean performAction)
Executes the "shrink map size" action.
The location of a map file with a map directory.
Definition: MapFile.java:31
void enterWestMap()
Action method for entering the west map.
void selectExit(@NotNull final MapView< G, A, R > mapView, final int direction)
Selects an exit square.
void setTileShow(final boolean tileShow)
Action method for "tile show".
boolean isDoubleFaces()
Get whether double faces are drawn double height.
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
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.
Definition: EnterMap.java:107