Crossfire JXClient, Trunk  R20561
GUIMiniMap.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.map;
23 
30 import java.awt.Color;
31 import java.awt.Dimension;
32 import java.awt.Graphics;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
35 
41 public class GUIMiniMap extends AbstractGUIMap {
42 
46  private static final long serialVersionUID = 1;
47 
51  @NotNull
53 
57  private final int width;
58 
62  private final int height;
63 
67  private final int tileSize;
68 
72  @NotNull
73  private static final Color[] TILE_COLORS = {
74  Color.BLACK,
75  Color.WHITE,
76  Color.BLUE,
77  Color.RED,
78  Color.GREEN,
79  Color.YELLOW,
80  Color.PINK,
81  Color.GRAY,
82  Color.ORANGE,
83  Color.CYAN,
84  Color.MAGENTA,
85  Color.DARK_GRAY,
86  Color.DARK_GRAY,
87  Color.DARK_GRAY,
88  Color.DARK_GRAY,
89  Color.DARK_GRAY,
90  };
91 
106  public GUIMiniMap(final boolean avoidCopyArea, @NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final MapUpdaterState mapUpdaterState, @NotNull final FacesProvider facesProvider, @NotNull final DarknessColors darknessColors, final int width, final int height) {
107  super(avoidCopyArea, tooltipManager, elementListener, name, mapUpdaterState, facesProvider, null, darknessColors);
108  this.mapUpdaterState = mapUpdaterState;
109  this.width = width;
110  this.height = height;
111  tileSize = facesProvider.getSize();
112  }
113 
117  @Override
118  protected void paintSquareBackground(@NotNull final Graphics g, final int px, final int py, final boolean hasImage, @NotNull final CfMapSquare mapSquare) {
119  final Color color;
120  if (hasImage) {
121  color = Color.BLACK;
122  } else {
123  final int colorIndex = mapSquare.getColor();
124  color = 0 <= colorIndex && colorIndex < TILE_COLORS.length ? TILE_COLORS[colorIndex] : Color.BLACK;
125  }
126  paintColoredSquare(g, color, px, py);
127  }
128 
132  @Override
133  protected void markPlayer(@NotNull final Graphics g, final int dx, final int dy) {
134  if (dx != 0 || dy != 0) {
135  final int playerOffsetX = (getMapWidth()-1)/2;
136  final int playerOffsetY = (getMapHeight()-1)/2;
137  final int mapSquareX = playerOffsetX-dx;
138  final int mapSquareY = playerOffsetY-dy;
139  final CfMap map = mapUpdaterState.getMap();
140  //noinspection SynchronizationOnLocalVariableOrMethodParameter
141  synchronized (map) {
142  redrawSquare(g, map.getMapSquare(mapSquareX, mapSquareY), map, mapSquareX, mapSquareY);
143  }
144  }
145  g.setColor(Color.RED);
146  g.fillRect(getPlayerX(), getPlayerY(), tileSize, tileSize);
147  }
148 
152  @Nullable
153  @Override
154  public Dimension getPreferredSize() {
155  return new Dimension(width*tileSize, height*tileSize);
156  }
157 
158 }
static final long serialVersionUID
The serial version UID.
Definition: GUIMiniMap.java:46
final TooltipManager tooltipManager
The TooltipManager to update.
Represents a square in a CfMap.
final boolean avoidCopyArea
Whether map scrolling is done by copying pixel areas.
CfMap getMap()
Returns the current map instance.
Represents a map (as seen by the client).
Definition: CfMap.java:45
static final Color [] TILE_COLORS
The colors for displaying magic map data.
Definition: GUIMiniMap.java:73
GUIMiniMap(final boolean avoidCopyArea, @NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final MapUpdaterState mapUpdaterState, @NotNull final FacesProvider facesProvider, @NotNull final DarknessColors darknessColors, final int width, final int height)
Creates a new instance.
int getMapHeight()
Returns the map height in squares.
CfMapSquare getMapSquare(final int x, final int y)
Returns a map square.
Definition: CfMap.java:668
Implements the map model which is shown in the map and magic map views.
Definition: CfMap.java:22
Manages image information ("faces") needed to display the map view, items, and spell icons...
Abstract base class for GUIElements that display map views.
final GUIElementListener elementListener
The GUIElementListener to notify.
void redrawSquare(@NotNull final Graphics g, @NotNull final CfMapSquare mapSquare, @NotNull final CfMap map, final int x, final int y)
Redraws one square.
void markPlayer(@NotNull final Graphics g, final int dx, final int dy)
final int width
The map width in squares.
Definition: GUIMiniMap.java:57
int getPlayerY()
Returns the y offset of the tile representing the player.
int getMapWidth()
Returns the map width in squares.
final MapUpdaterState mapUpdaterState
The MapUpdaterState instance to use.
Definition: GUIMiniMap.java:52
final FacesProvider facesProvider
The FacesProvider for looking up faces.
int getPlayerX()
Returns the x offset of the tile representing the player.
Update a CfMap model from protocol commands.
final int tileSize
The size of one tile.
Definition: GUIMiniMap.java:67
final DarknessColors darknessColors
The DarknessColors instance for converting darkness values into colors.
final int height
The map height in squares.
Definition: GUIMiniMap.java:62
void paintSquareBackground(@NotNull final Graphics g, final int px, final int py, final boolean hasImage, @NotNull final CfMapSquare mapSquare)
void paintColoredSquare(@NotNull final Graphics g, @NotNull final Color color, final int x, final int y)
Fills a square with one Color.
Utility class for converting darkness values into colors.