Gridarta Editor
IsoPickmapRenderer.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.Graphics;
23 import java.awt.Graphics2D;
24 import java.awt.Point;
25 import javax.swing.Icon;
37 import org.jetbrains.annotations.NotNull;
38 
43 public class IsoPickmapRenderer<G extends DefaultIsoGameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractIsoMapRenderer<G, A, R> {
44 
48  private static final long serialVersionUID = 1L;
49 
53  @NotNull
54  private final Point point = new Point();
55 
70  public IsoPickmapRenderer(final int spawnPointTypeNo, @NotNull final MapViewSettings mapViewSettings, @NotNull final MapModel<G, A, R> mapModel, @NotNull final MapGrid mapGrid, @NotNull final MultiPositionData multiPositionData, @NotNull final IsoMapSquareInfo isoMapSquareInfo, @NotNull final GridMapSquarePainter gridMapSquarePainter, @NotNull final GameObjectParser<G, A, R> gameObjectParser, @NotNull final Icon unknownSquareIcon) {
71  super(spawnPointTypeNo, mapViewSettings, mapModel, mapGrid, 0, isoMapSquareInfo.getYLen(), multiPositionData, isoMapSquareInfo, gridMapSquarePainter, gameObjectParser, unknownSquareIcon);
72  setBackground(CommonConstants.BG_COLOR);
73  }
74 
75  @Override
76  protected void clearBackground(@NotNull final Graphics g) {
77  g.setColor(getBackground());
78  g.fillRect(0, 0, getWidth(), getHeight());
79  }
80 
81  @Override
82  protected void paintSquare(@NotNull final Graphics2D g, final int x, final int y, @NotNull final MapSquare<G, A, R> square) {
83  point.setLocation(square.getMapX(), square.getMapY());
84  final int[] yOffsets = tileStretchingOffsets(point, foundSubLayers);
85  int highestSubLayer = 0;
86  for (int subLayer = 0; subLayer < yOffsets.length; subLayer++) {
87  if (yOffsets[subLayer] < yOffsets[highestSubLayer]) {
88  highestSubLayer = subLayer;
89  }
90  }
91  for (final G node : square) {
92  final G head = node.getHead();
93  final int subLayer;
94  if (head.getAttributeInt(DefaultIsoGameObject.LAYER) == 0) {
95  subLayer = highestSubLayer;
96  } else {
97  subLayer = head.getAttributeInt(DefaultIsoGameObject.SUB_LAYER);
98  }
99  paintGameObjectIfVisible(g, x, y + yOffsets[subLayer], node);
100  }
101  }
102 
103  @Override
104  protected boolean isGameObjectVisible(@NotNull final G gameObject) {
105  return true;
106  }
107 
108 }
int [] tileStretchingOffsets( @NotNull final Point point, final boolean[] foundSubLayers)
Calculates the tile stretching Y offset.
final MultiPositionData multiPositionData
The MultiPositionData instance to query for multi-part objects.
A MapRenderer that renders isometric squares.
A MapModel reflects the data of a map.
Definition: MapModel.java:75
Reading and writing of maps, handling of paths.
static final String LAYER
The name of the "layer" attribute.
Interface for classes that read or write GameObject instances.
Class with constants used in Gridarta and derivates.
static final Color BG_COLOR
Background Color (for the Panels).
final int spawnPointTypeNo
The game object type number of spawn points.
Base package of all Gridarta classes.
final MapViewSettings mapViewSettings
The MapViewSettings instance to use.
final IsoMapSquareInfo isoMapSquareInfo
The IsoMapSquareInfo to use.
final Point point
Used for calculations in paintSquare.
static final String SUB_LAYER
The name of the "sub_layer" attribute.
Container for settings that affect the rendering of maps.
GameObjects are the objects based on Archetypes found on maps.
IsoPickmapRenderer(final int spawnPointTypeNo, @NotNull final MapViewSettings mapViewSettings, @NotNull final MapModel< G, A, R > mapModel, @NotNull final MapGrid mapGrid, @NotNull final MultiPositionData multiPositionData, @NotNull final IsoMapSquareInfo isoMapSquareInfo, @NotNull final GridMapSquarePainter gridMapSquarePainter, @NotNull final GameObjectParser< G, A, R > gameObjectParser, @NotNull final Icon unknownSquareIcon)
Creates a new instance.
void paintGameObjectIfVisible( @NotNull final Graphics2D g, final int xStart, final int yStart, @NotNull final G gameObject)
Paints a single game object if it is visible according to current editor settings.
The MultiPositionData class stores an array of numbers which is required in order to calculate displa...
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
Definition: MapGrid.java:45
final Icon unknownSquareIcon
The Icon drawn into squares without game objects.
Provides information about isometric map squares.
final boolean [] foundSubLayers
Boolean array for tileStretchingOffsets to avoid allocating lots of arrays.
void paintSquare(@NotNull final Graphics2D g, final int x, final int y, @NotNull final MapSquare< G, A, R > square)
boolean isGameObjectVisible(@NotNull final G gameObject)
Default implementation for GameObject implementing classes.
static final long serialVersionUID
Serial Version UID.
A AbstractIsoMapRenderer to render map files.
final GridMapSquarePainter gridMapSquarePainter
The GridMapSquarePainter to use.