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-2023 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 : tmpNode).getArchetype().getMultiPartNr());
94  final int y = yStart - yOffset + multiPositionData.getYOffset(head.getArchetype().getMultiShapeID(), (tmpNode == null ? head : 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  final int xOffset = icon.getIconWidth() > isoMapSquareInfo.getXLen() ? (icon.getIconWidth() - isoMapSquareInfo.getXLen()) / 2 : 0;
105  icon.paintIcon(this, graphics2D, xStart - xOffset, yStart - yOffset);
106  }
107 
108  // Paint first object (most likely a mob) in spawn points.
109  if (head.getTypeNo() == spawnPointTypeNo) {
110  final G mob = head.getFirst();
111  if (mob != null) {
112  paint(graphics2D, xStart, yStart, mob);
113  }
114  }
115  }
116 
117  @Override
118  public void closeNotify() {
119  }
120 
121 }
net.sf.gridarta.gui.map.renderer.AbstractSimpleIsoMapRenderer
Abstract base class for ISO MapRenderers.
Definition: AbstractSimpleIsoMapRenderer.java:41
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.gui.map.renderer.AbstractSimpleIsoMapRenderer< G, A, R >::mapModel
final MapModel< G, A, R > mapModel
The MapModel to render.
Definition: AbstractSimpleIsoMapRenderer.java:58
net.sf.gridarta.model.gameobject.MultiPositionData.getXOffset
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 ...
Definition: MultiPositionData.java:161
net.sf.gridarta.model.baseobject.BaseObject.isMulti
boolean isMulti()
Returns whether this Archetype is a multi-part object.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.gameobject.IsoMapSquareInfo
Provides information about isometric map squares.
Definition: IsoMapSquareInfo.java:26
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer.paint
void paint(@NotNull final Graphics2D graphics2D, final int xStart, final int yStart, @NotNull final G gameObject)
Definition: SimpleIsoMapRenderer.java:85
net.sf
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: SimpleIsoMapRenderer.java:42
net.sf.gridarta.model.gameobject.MultiPositionData.getYOffset
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...
Definition: MultiPositionData.java:175
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.gameobject.IsoMapSquareInfo.getXLen
int getXLen()
Returns the horizontal size of a square.
Definition: IsoMapSquareInfo.java:66
net.sf.gridarta.model.gameobject.GameObject.getFirst
G getFirst()
Return the first GameObject contained in this container.
net.sf.gridarta.model.baseobject.BaseObject.getArchetype
R getArchetype()
Returns the Archetype this GameObject is based on.
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer.multiPositionData
final MultiPositionData multiPositionData
The MultiPositionData to query for multi-part objects.
Definition: SimpleIsoMapRenderer.java:53
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.baseobject.BaseObject.getNormalImage
ImageIcon getNormalImage()
Returns the normal face for this GameObject.
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer.SimpleIsoMapRenderer
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.
Definition: SimpleIsoMapRenderer.java:76
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model.baseobject.BaseObject.getHead
T getHead()
Return the head part of a multi-part object.
net.sf.gridarta.model.gameobject.IsoMapSquareInfo.getYLen
int getYLen()
Returns the vertical size of a square.
Definition: IsoMapSquareInfo.java:82
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer.closeNotify
void closeNotify()
Definition: SimpleIsoMapRenderer.java:118
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.baseobject.BaseObject.getFaceObjName
String getFaceObjName()
Returns the face name, can be from animation or face.
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer
Renders maps without MapGrid or validation errors.
Definition: SimpleIsoMapRenderer.java:37
net.sf.gridarta.model.gameobject.MultiPositionData
The MultiPositionData class stores an array of numbers which is required in order to calculate displa...
Definition: MultiPositionData.java:44
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.baseobject.BaseObject.getTypeNo
int getTypeNo()
Returns the type number of this Archetype.
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer.spawnPointTypeNo
final int spawnPointTypeNo
The game object type number of spawn points.
Definition: SimpleIsoMapRenderer.java:47
net.sf.gridarta.model.baseobject.BaseObject.getMultiRefCount
int getMultiRefCount()
Returns the number of parts for multi-part heads.
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer.isoMapSquareInfo
final IsoMapSquareInfo isoMapSquareInfo
The IsoMapSquareInfo to use.
Definition: SimpleIsoMapRenderer.java:59
net.sf.gridarta.gui.map.renderer.SimpleIsoMapRenderer.unknownSquareIcon
final ImageIcon unknownSquareIcon
The icon for unknown squares.
Definition: SimpleIsoMapRenderer.java:65
net.sf.gridarta.model.gameobject.GameObject.getContainerGameObject
G getContainerGameObject()
Returns the environment game object if this game object is in the inventory or.