Gridarta Editor
SimpleFlatMapRenderer.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.var.crossfire.gui.map.renderer;
21 
22 import java.awt.Color;
23 import java.awt.Graphics;
24 import java.awt.Point;
25 import java.awt.Rectangle;
26 import java.awt.image.BufferedImage;
27 import javax.swing.ImageIcon;
32 import net.sf.gridarta.utils.Size2D;
37 import org.jetbrains.annotations.NotNull;
38 
43 public class SimpleFlatMapRenderer extends AbstractMapRenderer<GameObject, MapArchObject, Archetype> {
44 
48  private static final long serialVersionUID = 1L;
49 
54  @NotNull
56 
60  @NotNull
62 
67  @NotNull
68  private final Point offset = new Point();
69 
73  @NotNull
75 
83  super(mapModel, null);
84  this.mapModel = mapModel;
85  this.resourceIcons = resourceIcons;
86  this.smoothingRenderer = smoothingRenderer;
87  }
88 
89  @Override
90  public boolean getSquareLocationAt(@NotNull final Point point, @NotNull final Point retPoint) {
91  throw new IllegalStateException("unsupported operation");
92  }
93 
94  @NotNull
95  @Override
96  public Size2D getImageSize() {
97  final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
98  return new Size2D(mapSize.getWidth() * IGUIConstants.SQUARE_WIDTH, mapSize.getHeight() * IGUIConstants.SQUARE_HEIGHT);
99  }
100 
101  @NotNull
102  @Override
103  public BufferedImage getFullImage() {
104  final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
105  final int viewWidth = mapSize.getWidth() * IGUIConstants.SQUARE_WIDTH;
106  final int viewHeight = mapSize.getHeight() * IGUIConstants.SQUARE_HEIGHT;
107  final BufferedImage image = new BufferedImage(viewWidth, viewHeight, BufferedImage.TYPE_INT_ARGB);
108  final Graphics g = image.getGraphics();
109  try {
110  paintComponent(g);
111  } finally {
112  g.dispose();
113  }
114  return image;
115  }
116 
117  @Override
118  public void forceRepaint() {
119  throw new IllegalStateException("unsupported operation");
120  }
121 
122  @Override
123  protected void paintComponent(@NotNull final Graphics g) {
124  final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
125  g.setColor(Color.white);
126  g.fillRect(0, 0, mapSize.getWidth() * IGUIConstants.SQUARE_WIDTH, mapSize.getHeight() * IGUIConstants.SQUARE_HEIGHT);
127  final Point point = new Point();
128  for (point.y = 0; point.y < mapSize.getHeight(); point.y++) {
129  for (point.x = 0; point.x < mapSize.getWidth(); point.x++) {
130  paintSquare(g, point);
131  }
132  }
133  }
134 
140  private void paintSquare(@NotNull final Graphics graphics, @NotNull final Point point) {
141  if (mapModel.getMapSquare(point).isEmpty()) {
143  return;
144  }
145 
146  int layer = -1;
147  for (final BaseObject<?, ?, ?, ?> node : mapModel.getMapSquare(point)) {
148  if (node.getAttributeInt(GameObject.INVISIBLE, true) == 0) {
149  layer++;
150  }
151  final ImageIcon img = node.getNormalImage();
152  if (!node.isMulti() || (img.getIconWidth() == IGUIConstants.SQUARE_WIDTH && img.getIconHeight() == IGUIConstants.SQUARE_HEIGHT)) {
153  offset.x = 0;
154  offset.y = 0;
155  } else {
156  // this is an oversized image, so it must be shifted
157  offset.x = IGUIConstants.SQUARE_WIDTH * (node.getArchetype().getMultiX() - node.getMinX());
158  offset.y = IGUIConstants.SQUARE_HEIGHT * (node.getArchetype().getMultiY() - node.getMinY());
159  }
161  if (node.getAttributeInt(GameObject.SMOOTHLEVEL, true) > 0) {
162  smoothingRenderer.paintSmooth(graphics, point, node.getAttributeInt(GameObject.SMOOTHLEVEL, true), layer, false, 0, 0);
163  }
164  }
165  if (layer > -1) {
166  smoothingRenderer.paintSmooth(graphics, point, 1, layer + 1, true, 0, 0);
167  }
168  }
169 
170  @Override
171  public void closeNotify() {
172  }
173 
174  @NotNull
175  @Override
176  public Rectangle getSquareBounds(@NotNull final Point p) {
177  throw new IllegalStateException("unsupported operation");
178  }
179 
180 }
net.sf.gridarta.utils.Size2D.getWidth
int getWidth()
Returns the width of the area.
Definition: Size2D.java:96
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.getSquareBounds
Rectangle getSquareBounds(@NotNull final Point p)
Returns coordinates, length and width of map square.
Definition: SimpleFlatMapRenderer.java:176
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: SimpleFlatMapRenderer.java:48
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.var.crossfire.model.archetype
Definition: Archetype.java:20
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.offset
final Point offset
Temporary variable.
Definition: SimpleFlatMapRenderer.java:68
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.getSquareLocationAt
boolean getSquareLocationAt(@NotNull final Point point, @NotNull final Point retPoint)
Returns the map location at the given point.
Definition: SimpleFlatMapRenderer.java:90
net.sf
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.gui.map.renderer
Definition: AbstractIsoMapRenderer.java:20
net.sf.gridarta.utils.ResourceIcons.SQUARE_EMPTY
static final String SQUARE_EMPTY
Definition: ResourceIcons.java:80
net.sf.gridarta.var
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.gui.map.renderer.AbstractMapRenderer
Abstract base class for classes implementing MapRenderer.
Definition: AbstractMapRenderer.java:45
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.paintComponent
void paintComponent(@NotNull final Graphics g)
Definition: SimpleFlatMapRenderer.java:123
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.paintSquare
void paintSquare(@NotNull final Graphics graphics, @NotNull final Point point)
Paint one square.
Definition: SimpleFlatMapRenderer.java:140
net.sf.gridarta.var.crossfire.IGUIConstants
Defines common UI constants used in different dialogs and all used icon files.
Definition: IGUIConstants.java:30
net
net.sf.gridarta.utils.Size2D.getHeight
int getHeight()
Returns the height of the area.
Definition: Size2D.java:104
net.sf.gridarta.var.crossfire.model.archetype.Archetype
Implements Crossfire archetypes.
Definition: Archetype.java:30
net.sf.gridarta.var.crossfire.model.maparchobject.MapArchObject
MapArchObject contains the specific meta data about a map that is stored in the map-arch,...
Definition: MapArchObject.java:39
net.sf.gridarta.var.crossfire
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
net.sf.gridarta.var.crossfire.model
net.sf.gridarta.var.crossfire.IGUIConstants.SQUARE_WIDTH
int SQUARE_WIDTH
The width of a square in pixels.
Definition: IGUIConstants.java:35
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.resourceIcons
final ResourceIcons resourceIcons
The ResourceIcons for creating icons.
Definition: SimpleFlatMapRenderer.java:61
net.sf.gridarta.var.crossfire.gui.map.renderer.SmoothingRenderer.paintSmooth
void paintSmooth(@NotNull final Graphics graphics, @NotNull final Point pos, final int level, final int firstLayer, final boolean allLayers, final int borderOffsetX, final int borderOffsetY)
Draw the smoothing information at given position of map, for a given limit smoothlevel,...
Definition: SmoothingRenderer.java:110
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.closeNotify
void closeNotify()
Must be called when this renderer is not used anymore.
Definition: SimpleFlatMapRenderer.java:171
net.sf.gridarta.var.crossfire.model.gameobject.GameObject.SMOOTHLEVEL
static final String SMOOTHLEVEL
The name of the "smoothlevel" attribute.
Definition: GameObject.java:70
net.sf.gridarta.utils.ResourceIcons.getResourceIcon
ImageIcon getResourceIcon(@NotNull final String iconName)
Returns the image icon for the given icon name.
Definition: ResourceIcons.java:168
net.sf.gridarta.var.crossfire.model.gameobject.GameObject.INVISIBLE
static final String INVISIBLE
The name of the "invisible" attribute.
Definition: GameObject.java:64
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.var.crossfire.gui.map.renderer.SmoothingRenderer
Renderer for smoothed faces as used by Crossfire.
Definition: SmoothingRenderer.java:42
net.sf.gridarta.var.crossfire.model.maparchobject
Definition: DefaultMapArchObjectFactory.java:20
net.sf.gridarta.gui.map
Base classes for rendering maps.
Definition: AbstractPerMapDialogManager.java:20
net.sf.gridarta.var.crossfire.model.gameobject
Handles the Crossfire variants of GameObjects and Archetypes.
Definition: DefaultGameObjectFactory.java:20
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.forceRepaint
void forceRepaint()
Repaint the view because some view parameters may have changed.
Definition: SimpleFlatMapRenderer.java:118
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.getImageSize
Size2D getImageSize()
Returns the size of an image of the entire map view in pixels.
Definition: SimpleFlatMapRenderer.java:96
net.sf.gridarta.var.crossfire.model.gameobject.GameObject
Handles the Crossfire GameObjects.
Definition: GameObject.java:41
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.mapModel
final MapModel< GameObject, MapArchObject, Archetype > mapModel
The map model to render.
Definition: SimpleFlatMapRenderer.java:55
net.sf.gridarta.utils.ResourceIcons
Creates ImageIcon instances from resources.
Definition: ResourceIcons.java:46
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer
Renders maps without MapGrid.
Definition: SimpleFlatMapRenderer.java:43
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.SimpleFlatMapRenderer
SimpleFlatMapRenderer(@NotNull final MapModel< GameObject, MapArchObject, Archetype > mapModel, @NotNull final ResourceIcons resourceIcons, @NotNull final SmoothingRenderer smoothingRenderer)
Creates a new instance.
Definition: SimpleFlatMapRenderer.java:82
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.getFullImage
BufferedImage getFullImage()
Returns an image of the entire map view.
Definition: SimpleFlatMapRenderer.java:103
net.sf.gridarta.var.crossfire.gui.map.renderer.SimpleFlatMapRenderer.smoothingRenderer
final SmoothingRenderer smoothingRenderer
The SmoothingRenderer for rendering smoothed faces.
Definition: SimpleFlatMapRenderer.java:74
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.var.crossfire.IGUIConstants.SQUARE_HEIGHT
int SQUARE_HEIGHT
The height of a square in pixels.
Definition: IGUIConstants.java:40