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.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)
Definition: GUIMiniMap.java:110
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.name
final String name
Definition: AbstractGUIElement.java:77
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.faces.FacesProvider.getSize
int getSize()
com.realtime.crossfire.jxclient.faces.FacesProvider
Definition: FacesProvider.java:34
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getPlayerX
int getPlayerX()
Definition: AbstractGUIMap.java:581
com.realtime.crossfire.jxclient.map
Definition: CfMap.java:23
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.darknessColors
final DarknessColors darknessColors
Definition: AbstractGUIMap.java:102
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.width
final int width
Definition: GUIMiniMap.java:60
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap
Definition: GUIMiniMap.java:44
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.map.CfMap
Definition: CfMap.java:46
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)
Definition: AbstractGUIMap.java:427
com.realtime.crossfire.jxclient.faces
Definition: AbstractFaceQueue.java:23
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.facesProvider
final FacesProvider facesProvider
Definition: AbstractGUIMap.java:88
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap
Definition: AbstractGUIMap.java:65
com.realtime.crossfire.jxclient.gui.map.DarknessColors
Definition: DarknessColors.java:34
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.getTooltip
TooltipText getTooltip()
Definition: GUIMiniMap.java:158
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)
Definition: GUIMiniMap.java:119
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.markPlayer
void markPlayer(@NotNull final Graphics g, final int dx, final int dy)
Definition: GUIMiniMap.java:131
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.getPreferredSize
Dimension getPreferredSize()
Definition: GUIMiniMap.java:148
com.realtime.crossfire.jxclient.map.MapUpdaterState
Definition: MapUpdaterState.java:49
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.avoidCopyArea
final boolean avoidCopyArea
Definition: AbstractGUIMap.java:76
com.realtime.crossfire.jxclient.map.CfMap.getMapSquare
CfMapSquare getMapSquare(final int x, final int y)
Definition: CfMap.java:664
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.serialVersionUID
static final long serialVersionUID
Definition: GUIMiniMap.java:49
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.tileSize
final int tileSize
Definition: GUIMiniMap.java:70
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getPlayerY
int getPlayerY()
Definition: AbstractGUIMap.java:591
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.notifyOpen
void notifyOpen()
Definition: GUIMiniMap.java:153
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getMapWidth
int getMapWidth()
Definition: AbstractGUIMap.java:696
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.gui.gui.TooltipText
Definition: TooltipText.java:31
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.TILE_COLORS
static final Color[] TILE_COLORS
Definition: GUIMiniMap.java:76
com.realtime
com
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.paintColoredSquare
void paintColoredSquare(@NotNull final Graphics g, @NotNull final Color color, final int x, final int y)
Definition: AbstractGUIMap.java:675
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.height
final int height
Definition: GUIMiniMap.java:65
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.guiFactory
final GuiFactory guiFactory
Definition: AbstractGUIElement.java:48
com.realtime.crossfire.jxclient.gui.map.GUIMiniMap.mapUpdaterState
final MapUpdaterState mapUpdaterState
Definition: GUIMiniMap.java:55
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getMapHeight
int getMapHeight()
Definition: AbstractGUIMap.java:706
com.realtime.crossfire.jxclient.map.CfMapSquare
Definition: CfMapSquare.java:40
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipManager
final TooltipManager tooltipManager
Definition: AbstractGUIElement.java:83
com.realtime.crossfire.jxclient.map.MapUpdaterState.getMap
CfMap getMap()
Definition: MapUpdaterState.java:406