Crossfire JXClient, Trunk
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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.gui.map;
24 
33 import java.awt.Color;
34 import java.awt.Dimension;
35 import java.awt.Graphics;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
38 
44 public class GUIMiniMap extends AbstractGUIMap {
45 
49  private static final long serialVersionUID = 1;
50 
54  @NotNull
56 
60  private final int width;
61 
65  private final int height;
66 
70  private final int tileSize;
71 
75  @NotNull
76  private static final Color @NotNull [] TILE_COLORS = { //
77  Color.BLACK, //
78  Color.WHITE, //
79  Color.BLUE, //
80  Color.RED, //
81  Color.GREEN, //
82  Color.YELLOW, //
83  Color.PINK, //
84  Color.GRAY, //
85  Color.ORANGE, //
86  Color.CYAN, //
87  Color.MAGENTA, //
88  Color.DARK_GRAY, //
89  Color.DARK_GRAY, //
90  Color.DARK_GRAY, //
91  Color.DARK_GRAY, //
92  Color.DARK_GRAY, //
93  };
94 
110  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, @NotNull final GuiFactory guiFactory) {
112  this.mapUpdaterState = mapUpdaterState;
113  this.width = width;
114  this.height = height;
116  }
117 
118  @Override
119  protected void paintSquareBackground(@NotNull final Graphics g, final int px, final int py, final boolean hasImage, @NotNull final CfMapSquare mapSquare) {
120  final Color color;
121  if (hasImage) {
122  color = Color.BLACK;
123  } else {
124  final int colorIndex = mapSquare.getColor();
125  color = 0 <= colorIndex && colorIndex < TILE_COLORS.length ? TILE_COLORS[colorIndex] : Color.BLACK;
126  }
127  paintColoredSquare(g, color, px, py);
128  }
129 
130  @Override
131  protected void markPlayer(@NotNull final Graphics g, final int dx, final int dy) {
132  if (dx != 0 || dy != 0) {
133  final int playerOffsetX = (getMapWidth()-1)/2;
134  final int playerOffsetY = (getMapHeight()-1)/2;
135  final CfMap map = mapUpdaterState.getMap();
136  //noinspection SynchronizationOnLocalVariableOrMethodParameter
137  synchronized (map) {
138  redrawSquare(g, map.getMapSquare(playerOffsetX-dx, playerOffsetY-dy), map, playerOffsetX-dx, playerOffsetY-dy);
139  }
140  }
141  g.setColor(Color.RED);
142  g.fillRect(getPlayerX(), getPlayerY(), tileSize, tileSize);
143  }
144 
145  @Nullable
146  @Override
147  @SuppressWarnings("MethodDoesntCallSuperMethod")
148  public Dimension getPreferredSize() {
149  return new Dimension(width*tileSize, height*tileSize);
150  }
151 
152  @Override
153  public void notifyOpen() {
154  }
155 
156  @Nullable
157  @Override
159  return null;
160  }
161 
162 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getPlayerX
int getPlayerX()
Returns the x offset of the tile representing the player.
Definition: AbstractGUIMap.java:581
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.TILE_COLORS
static final Color[] TILE_COLORS
The colors for displaying magic map data.
Definition: GUIMiniMap.java:76
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.tileSize
final int tileSize
The size of one tile.
Definition: GUIMiniMap.java:70
com.realtime.crossfire.jxclient.faces.FacesProvider.getSize
int getSize()
Returns the size of faces in pixels.
com.realtime.crossfire.jxclient.map
Implements the map model which is shown in the map and magic map views.
Definition: CfMap.java:23
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getMapWidth
int getMapWidth()
Returns the map width in squares.
Definition: AbstractGUIMap.java:696
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.markPlayer
void markPlayer(@NotNull final Graphics g, final int dx, final int dy)
Paints the player location.
Definition: GUIMiniMap.java:131
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.notifyOpen
void notifyOpen()
Called each time the enclosing dialog is opened (or raised).
Definition: GUIMiniMap.java:153
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: GUIMiniMap.java:49
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getPlayerY
int getPlayerY()
Returns the y offset of the tile representing the player.
Definition: AbstractGUIMap.java:591
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.paintColoredSquare
void paintColoredSquare(@NotNull final Graphics g, @NotNull final Color color, final int x, final int y)
Fills a square with one Color.
Definition: AbstractGUIMap.java:675
com.realtime.crossfire.jxclient.map.CfMap
Represents a map (as seen by the client).
Definition: CfMap.java:46
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
The GUIElementListener to notify.
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.map.DarknessColors
Utility class for converting darkness values into colors.
Definition: DarknessColors.java:34
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.mapUpdaterState
final MapUpdaterState mapUpdaterState
The MapUpdaterState instance to use.
Definition: GUIMiniMap.java:55
com.realtime.crossfire.jxclient.faces
Manages image information ("faces") needed to display the map view, items, and spell icons.
Definition: AbstractFaceQueue.java:23
com.realtime.crossfire.jxclient.map.CfMap.getMapSquare
CfMapSquare getMapSquare(final int x, final int y)
Returns a map square.
Definition: CfMap.java:664
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.GUIMiniMap
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, @NotNull final GuiFactory guiFactory)
Creates a new instance.
Definition: GUIMiniMap.java:110
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap
Abstract base class for GUIElements that display map views.
Definition: AbstractGUIMap.java:65
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.darknessColors
final DarknessColors darknessColors
The DarknessColors instance for converting darkness values into colors.
Definition: AbstractGUIMap.java:102
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.facesProvider
final FacesProvider facesProvider
The FacesProvider for looking up faces.
Definition: AbstractGUIMap.java:88
com.realtime.crossfire.jxclient.map.MapUpdaterState.getMap
CfMap getMap()
Returns the current map instance.
Definition: MapUpdaterState.java:406
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.width
final int width
The map width in squares.
Definition: GUIMiniMap.java:60
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.guiFactory
final GuiFactory guiFactory
The global GuiFactory instance.
Definition: AbstractGUIElement.java:48
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.paintSquareBackground
void paintSquareBackground(@NotNull final Graphics g, final int px, final int py, final boolean hasImage, @NotNull final CfMapSquare mapSquare)
Paints the background of a map square.
Definition: GUIMiniMap.java:119
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.redrawSquare
void redrawSquare(@NotNull final Graphics g, @NotNull final CfMapSquare mapSquare, @NotNull final CfMap map, final int x, final int y)
Redraws one square.
Definition: AbstractGUIMap.java:427
com.realtime.crossfire.jxclient.gui.gui.TooltipText
Information for displaying tooltips.
Definition: TooltipText.java:31
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.getPreferredSize
Dimension getPreferredSize()
Definition: GUIMiniMap.java:148
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Factory for creating Gui instances.
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.name
final String name
The name of this element.
Definition: AbstractGUIElement.java:77
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Manages the tooltip display.
Definition: TooltipManager.java:33
com.realtime
com
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.height
final int height
The map height in squares.
Definition: GUIMiniMap.java:65
com.realtime.crossfire.jxclient.map.CfMapSquare
Represents a square in a CfMap.
Definition: CfMapSquare.java:40
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipManager
final TooltipManager tooltipManager
The TooltipManager to update.
Definition: AbstractGUIElement.java:83
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getMapHeight
int getMapHeight()
Returns the map height in squares.
Definition: AbstractGUIMap.java:706
com.realtime.crossfire.jxclient.map.MapUpdaterState
Update a CfMap model from protocol commands.
Definition: MapUpdaterState.java:49
com.realtime.crossfire.jxclient.faces.FacesProvider
Interface for face providers.
Definition: FacesProvider.java:34
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.getTooltip
TooltipText getTooltip()
Returns the current tooltip text.
Definition: GUIMiniMap.java:158
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap
Displays a small map view.
Definition: GUIMiniMap.java:44
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Listener for GUIElement related events.
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.avoidCopyArea
final boolean avoidCopyArea
Whether map scrolling is done by copying pixel areas.
Definition: AbstractGUIMap.java:76