Gridarta Editor
MoveSquarePrevAction.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.action;
21 
27 import net.sf.japi.swing.action.ActionMethod;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
36 public class MoveSquarePrevAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractMoveSquareAction<G, A, R> {
37 
41  @NotNull
43 
49  public MoveSquarePrevAction(@NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, @Nullable final MapManager<G, A, R> mapManager) {
50  super(selectedSquareModel, mapManager);
51  this.selectedSquareModel = selectedSquareModel;
52  }
53 
57  @ActionMethod
58  public void moveSquarePrev() {
59  doAction(true);
60  }
61 
62  @Override
63  protected boolean doAction(final boolean performAction, @Nullable final G gameObject) {
64  if (gameObject == null || !gameObject.isHead()) {
65  return false;
66  }
67 
68  G prevGameObject = gameObject.getPrev();
69  if (prevGameObject == null) {
70  prevGameObject = gameObject.getContainerGameObject();
71  if (prevGameObject == null) {
72  return false;
73  }
74  } else if (performAction) {
75  while (true) {
76  final G tmp = prevGameObject.getFirst();
77  if (tmp == null) {
78  break;
79  }
80  prevGameObject = tmp;
81  }
82  }
83 
84  if (performAction) {
85  selectedSquareModel.setSelectedGameObject(prevGameObject);
86  }
87 
88  return true;
89  }
90 
91 }
A MapManager manages all opened maps.
Definition: MapManager.java:37
Graphical User Interface of Gridarta.
MoveSquarePrevAction(@NotNull final SelectedSquareModel< G, A, R > selectedSquareModel, @Nullable final MapManager< G, A, R > mapManager)
Creates a new instance.
final SelectedSquareModel< G, A, R > selectedSquareModel
The SelectedSquareModel that is updated.
An net.sf.gridarta.utils.EditorAction that selects the previous game object in the SelectedSquareMode...
boolean doAction(final boolean performAction, @Nullable final G gameObject)
Base package of all Gridarta classes.
Abstract base class for actions that move the selected game object in the SelectedSquareModel.
Reflects a game object (object on a map).
Definition: GameObject.java:36
void moveSquarePrev()
Action method that selects the previous game object.
GameObjects are the objects based on Archetypes found on maps.
Displays the contents of the currently selected map square.
void setSelectedGameObject(@Nullable final G gameObject)
Sets the currently selected GameObject.
The model component of the selected square control.