Gridarta Editor
SimpleIsoMapRenderer.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.renderer;
21 
22 import java.awt.Graphics2D;
23 import javax.swing.ImageIcon;
31 import org.jetbrains.annotations.NotNull;
32 
37 public class SimpleIsoMapRenderer<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractSimpleIsoMapRenderer<G, A, R> {
38 
42  private static final long serialVersionUID = 1L;
43 
47  private final int spawnPointTypeNo;
48 
52  @NotNull
54 
58  @NotNull
60 
64  @NotNull
65  private final ImageIcon unknownSquareIcon;
66 
76  public SimpleIsoMapRenderer(final int spawnPointTypeNo, @NotNull final MapModel<G, A, R> mapModel, @NotNull final MultiPositionData multiPositionData, @NotNull final IsoMapSquareInfo isoMapSquareInfo, @NotNull final ImageIcon unknownSquareIcon) {
77  super(mapModel, isoMapSquareInfo);
78  this.spawnPointTypeNo = spawnPointTypeNo;
79  this.multiPositionData = multiPositionData;
80  this.isoMapSquareInfo = isoMapSquareInfo;
81  this.unknownSquareIcon = unknownSquareIcon;
82  }
83 
84  @Override
85  protected void paint(@NotNull final Graphics2D graphics2D, final int xStart, final int yStart, @NotNull final G gameObject) {
86  final GameObject<G, A, R> head = gameObject.getHead();
87  final ImageIcon icon = "trans.101".equals(head.getFaceObjName()) ? unknownSquareIcon : head.getNormalImage();
88  final int yOffset = icon.getIconHeight() - isoMapSquareInfo.getYLen();
89  if (head.getMultiRefCount() > 0) {
90  // multi-part images have to be painted with correct offset
91  // TODO: This should be improved, especially regarding multi arch mobs inside spawn points.
92  final BaseObject<G, A, R, ?> tmpNode = gameObject.isMulti() ? gameObject : null;
93  final int x = xStart - multiPositionData.getXOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr());
94  final int y = yStart - yOffset + multiPositionData.getYOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr());
95  if (tmpNode != null && tmpNode.getArchetype().isLowestPart() || head.getArchetype().isLowestPart()) {
96  icon.paintIcon(this, graphics2D, x, y);
97  } else {
99  if (env != null && env.getTypeNo() == spawnPointTypeNo) {
100  icon.paintIcon(this, graphics2D, x, y);
101  }
102  }
103  } else {
104  int xOffset = 0;
105  if (icon.getIconWidth() > isoMapSquareInfo.getXLen()) {
106  xOffset = (icon.getIconWidth() - isoMapSquareInfo.getXLen()) / 2;
107  }
108  icon.paintIcon(this, graphics2D, xStart - xOffset, yStart - yOffset);
109  }
110 
111  // Paint first object (most likely a mob) in spawn points.
112  if (head.getTypeNo() == spawnPointTypeNo) {
113  final G mob = head.getFirst();
114  if (mob != null) {
115  paint(graphics2D, xStart, yStart, mob);
116  }
117  }
118  }
119 
120  @Override
121  public void closeNotify() {
122  }
123 
124 }
ImageIcon getNormalImage()
Returns the normal face for this GameObject.
T getHead()
Return the head part of a multi-part object.
Renders maps without MapGrid or validation errors.
static final long serialVersionUID
The serial version UID.
int getYOffset(final int shapeID, final int positionID)
Calculate the y-offset from the topmost pixel of the big face image and the default y-position (The d...
A MapModel reflects the data of a map.
Definition: MapModel.java:75
String getFaceObjName()
Returns the face name, can be from animation or face.
void paint(@NotNull final Graphics2D graphics2D, final int xStart, final int yStart, @NotNull final G gameObject)
G getContainerGameObject()
Returns the environment game object if this game object is in the inventory or.
int getMultiRefCount()
Returns the number of parts for multi-part heads.
int getYLen()
Returns the vertical size of a square.
Base package of all Gridarta classes.
G getFirst()
Return the first GameObject contained in this container.
Reflects a game object (object on a map).
Definition: GameObject.java:36
final MultiPositionData multiPositionData
The MultiPositionData to query for multi-part objects.
final ImageIcon unknownSquareIcon
The icon for unknown squares.
final IsoMapSquareInfo isoMapSquareInfo
The IsoMapSquareInfo to use.
GameObjects are the objects based on Archetypes found on maps.
SimpleIsoMapRenderer(final int spawnPointTypeNo, @NotNull final MapModel< G, A, R > mapModel, @NotNull final MultiPositionData multiPositionData, @NotNull final IsoMapSquareInfo isoMapSquareInfo, @NotNull final ImageIcon unknownSquareIcon)
Creates a new instance.
The MultiPositionData class stores an array of numbers which is required in order to calculate displa...
final int spawnPointTypeNo
The game object type number of spawn points.
Provides information about isometric map squares.
R getArchetype()
Returns the Archetype this GameObject is based on.
boolean isMulti()
Returns whether this Archetype is a multi-part object.
int getXOffset(final int shapeID, final int positionID)
Calculate the x-offset from the leftmost pixel of the big face image and the default x-position (The ...
int getXLen()
Returns the horizontal size of a square.
int getTypeNo()
Returns the type number of this Archetype.