Crossfire JXClient, Trunk
AbstractGUIMap.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 
41 import java.awt.Color;
42 import java.awt.Dimension;
43 import java.awt.Graphics;
44 import java.awt.Graphics2D;
45 import java.awt.GraphicsConfiguration;
46 import java.awt.GraphicsDevice;
47 import java.awt.GraphicsEnvironment;
48 import java.awt.Image;
49 import java.awt.Transparency;
50 import java.awt.image.BufferedImage;
51 import java.util.ArrayDeque;
52 import java.util.Deque;
53 import java.util.HashMap;
54 import java.util.Map;
55 import java.util.Set;
56 import javax.swing.ImageIcon;
57 import org.jetbrains.annotations.NotNull;
58 import org.jetbrains.annotations.Nullable;
59 
65 public abstract class AbstractGUIMap extends AbstractGUIElement {
66 
70  private static final long serialVersionUID = 1;
71 
76  private final boolean avoidCopyArea;
77 
81  @NotNull
83 
87  @NotNull
89 
94  @Nullable
96 
101  @NotNull
103 
112  @NotNull
113  private final Object bufferedImageSync = new Object();
114 
119  @Nullable
120  private transient BufferedImage bufferedImage;
121 
125  private boolean clearMapPending = true;
126 
130  @NotNull
131  private final Deque<Long> scrollMapPending = new ArrayDeque<>();
132 
136  private int mapWidth;
137 
141  private int mapHeight;
142 
146  private final int tileSize;
147 
151  private int playerX;
152 
156  private int playerY;
157 
161  private int offsetX;
162 
166  private int offsetY;
167 
172  private int displayMinX;
173 
178  private int displayMaxX;
179 
184  private int displayMinY;
185 
190  private int displayMaxY;
191 
196  private int displayMinOffsetX;
197 
202  private int displayMaxOffsetX;
203 
208  private int displayMinOffsetY;
209 
214  private int displayMaxOffsetY;
215 
220  @NotNull
221  private final Map<Color, Image> images = new HashMap<>();
222 
226  @NotNull
227  private final MapListener mapListener = new MapListener() {
228 
229  @Override
230  public void mapChanged(@NotNull final CfMap map, @NotNull final Set<CfMapSquare> changedSquares) {
231  assert Thread.holdsLock(map);
232  synchronized (bufferedImageSync) {
233  final int x0 = map.getOffsetX();
234  final int y0 = map.getOffsetY();
235  final Graphics2D g = createBufferGraphics(map);
236  try {
237  for (CfMapSquare mapSquare : changedSquares) {
238  final int x = mapSquare.getX()+x0;
239  if (displayMinX <= x && x < displayMaxX) {
240  final int y = mapSquare.getY()+y0;
241  if (displayMinY <= y && y < displayMaxY) {
242  redrawSquare(g, mapSquare, map, x, y);
243  }
244  }
245  }
246  markPlayer(g, 0, 0);
247  } finally {
248  g.dispose();
249  }
250  }
251  setChanged();
252  }
253 
254  };
255 
259  @NotNull
260  private final NewmapListener newmapListener = () -> {
261  synchronized (bufferedImageSync) {
262  clearMapPending = true;
263  scrollMapPending.clear();
264  }
265  setChanged();
266  };
267 
272  private void clearMap(@NotNull final Graphics2D g) {
274  g.fillRect(0, 0, getWidth(), getHeight());
275  }
276 
280  @NotNull
281  private final MapScrollListener mapscrollListener = (dx, dy) -> {
282  synchronized (bufferedImageSync) {
283  scrollMapPending.offerLast(((long)dx<<32)|(dy&0xFFFFFFFFL));
284  }
285  setChanged();
286  };
287 
291  @NotNull
292  private final MapSizeListener mapSizeListener = (mapWidth1, mapHeight1) -> {
293  setMapSize(mapWidth1, mapHeight1);
294  redrawAll();
295  };
296 
312  protected AbstractGUIMap(final boolean avoidCopyArea, @NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final MapUpdaterState mapUpdaterState, @NotNull final FacesProvider facesProvider, @Nullable final SmoothingRenderer smoothingRenderer, @NotNull final DarknessColors darknessColors, @NotNull final GuiFactory guiFactory) {
314  this.avoidCopyArea = avoidCopyArea;
315  this.smoothingRenderer = smoothingRenderer;
316  this.darknessColors = darknessColors;
318  assert tileSize > 0;
319  this.mapUpdaterState = mapUpdaterState;
320  this.facesProvider = facesProvider;
321  this.mapUpdaterState.addMapSizeListener(mapSizeListener);
322  this.mapUpdaterState.addCrossfireMapListener(mapListener);
323  this.mapUpdaterState.addCrossfireNewmapListener(newmapListener);
324  this.mapUpdaterState.addCrossfireMapScrollListener(mapscrollListener);
325  setMapSize(this.mapUpdaterState.getMapWidth(), this.mapUpdaterState.getMapHeight());
326  }
327 
328  @Override
329  public void dispose() {
330  super.dispose();
335  }
336 
340  private void redrawAll() {
341  final CfMap map = mapUpdaterState.getMap();
342  //noinspection SynchronizationOnLocalVariableOrMethodParameter
343  synchronized (map) {
344  //noinspection NestedSynchronizedStatement
345  synchronized (bufferedImageSync) {
346  final Graphics g = createBufferGraphics(map);
347  try {
349  markPlayer(g, 0, 0);
350  } finally {
351  g.dispose();
352  }
353  }
354  }
355  }
356 
362  private void redrawAllUnlessDirty(@NotNull final Graphics g, @NotNull final CfMap map) {
363  synchronized (bufferedImageSync) {
365  }
366  }
367 
377  private void redrawTiles(@NotNull final Graphics g, @NotNull final CfMap map, final int x0, final int y0, final int x1, final int y1) {
378  for (int x = x0; x < x1; x++) {
379  for (int y = y0; y < y1; y++) {
380  final CfMapSquare mapSquare = map.getMapSquare(x, y);
381  redrawSquare(g, mapSquare, map, x, y);
382  }
383  }
384  }
385 
395  private void redrawTilesUnlessDirty(@NotNull final Graphics g, @NotNull final CfMap map, final int x0, final int y0, final int x1, final int y1) {
396  for (int x = x0; x < x1; x++) {
397  for (int y = y0; y < y1; y++) {
398  redrawSquareUnlessDirty(g, map, x, y);
399  }
400  }
401  }
402 
412  private void redrawSquareUnlessDirty(@NotNull final Graphics g, @NotNull final CfMap map, final int x, final int y) {
413  final CfMapSquare mapSquare = map.getMapSquareUnlessDirty(x, y);
414  if (mapSquare != null) {
415  redrawSquare(g, mapSquare, map, x, y);
416  }
417  }
418 
427  protected void redrawSquare(@NotNull final Graphics g, @NotNull final CfMapSquare mapSquare, @NotNull final CfMap map, final int x, final int y) {
428  redrawSquare(g, x, y, mapSquare, map);
429  synchronized (bufferedImageSync) {
430  if (x < 0 || y < 0 || x >= mapWidth || y >= mapHeight || mapSquare.isFogOfWar()) {
432  }
433  final int darkness = mapSquare.getDarkness();
434  if (darkness < CfMapSquare.DARKNESS_FULL_BRIGHT) {
436  }
437  }
438  }
439 
448  private void redrawSquare(@NotNull final Graphics g, final int x, final int y, @NotNull final CfMapSquare mapSquare, @NotNull final CfMap map) {
449  final int px;
450  final int py;
451  synchronized (bufferedImageSync) {
452  px = offsetX+x*tileSize;
453  py = offsetY+y*tileSize;
454  }
455  final int mapSquareX = mapSquare.getX();
456  final int mapSquareY = mapSquare.getY();
457  boolean foundSquare = false;
458  for (int layer = 0; layer < Map2.NUM_LAYERS; layer++) {
459  final CfMapSquare headMapSquare = mapSquare.getHeadMapSquare(layer);
460  if (headMapSquare != null) {
461  final Face headFace = headMapSquare.getFace(layer);
462  assert headFace != null; // getHeadMapSquare() would have been cleared in this case
463  final int dx = headMapSquare.getX()-mapSquareX;
464  final int dy = headMapSquare.getY()-mapSquareY;
465  assert dx > 0 || dy > 0;
466  if (!foundSquare) {
467  foundSquare = true;
468  paintSquareBackground(g, px, py, true, mapSquare);
469  }
470  paintImage(g, headFace, px, py, tileSize*dx, tileSize*dy);
471  }
472 
473  final Face face = mapSquare.getFace(layer);
474  if (face != null) {
475  if (!foundSquare) {
476  foundSquare = true;
477  paintSquareBackground(g, px, py, true, mapSquare);
478  }
479  paintImage(g, face, px, py, 0, 0);
480  }
481  /* If there is at least one square on a layer, we want to draw smoothing for all layers above it. */
482  if (foundSquare && smoothingRenderer != null) {
483  smoothingRenderer.paintSmooth(g, x, y, px, py, layer, map, tileSize);
484  }
485  }
486  if (!foundSquare) {
487  paintSquareBackground(g, px, py, false, mapSquare);
488  }
489  }
490 
499  protected abstract void paintSquareBackground(@NotNull final Graphics g, final int px, final int py, final boolean hasImage, @NotNull final CfMapSquare mapSquare);
500 
510  private void paintImage(@NotNull final Graphics g, @NotNull final Face face, final int px, final int py, final int offsetX, final int offsetY) {
511  final ImageIcon imageIcon = facesProvider.getImageIcon(face.getFaceNum(), null);
512  final int sx = imageIcon.getIconWidth()-offsetX;
513  final int sy = imageIcon.getIconHeight()-offsetY;
514  g.drawImage(imageIcon.getImage(), px, py, px+tileSize, py+tileSize, sx-tileSize, sy-tileSize, sx, sy, null);
515  }
516 
523  protected abstract void markPlayer(@NotNull final Graphics g, final int dx, final int dy);
524 
525  @Override
526  @SuppressWarnings("MethodDoesntCallSuperMethod")
527  public void paintComponent(@NotNull final Graphics g) {
528  synchronized (bufferedImageSync) {
529  g.drawImage(bufferedImage, 0, 0, null);
530  }
531  }
532 
538  private void setMapSize(final int mapWidth, final int mapHeight) {
539  synchronized (bufferedImageSync) {
540  this.mapWidth = mapWidth;
541  this.mapHeight = mapHeight;
542 
543  final int nX = MathUtils.divRoundUp(playerX, tileSize);
545  assert -tileSize < displayMinOffsetX && displayMinOffsetX <= 0;
546  assert (playerX-displayMinOffsetX)%tileSize == 0;
547  displayMinX = (mapWidth-1)/2-nX;
548  final int tilesX = MathUtils.divRoundUp(getWidth()-displayMinOffsetX, tileSize);
549  displayMaxX = displayMinX+tilesX;
550  assert (displayMaxX-displayMinX)*tileSize >= getWidth();
551  assert (displayMaxX-displayMinX)*tileSize-getWidth() < 2*tileSize;
554 
555  final int nY = MathUtils.divRoundUp(playerY, tileSize);
557  assert -tileSize < displayMinOffsetY && displayMinOffsetY <= 0;
558  assert (playerY-displayMinOffsetY)%tileSize == 0;
559  displayMinY = (mapHeight-1)/2-nY;
560  final int tilesY = MathUtils.divRoundUp(getHeight()-displayMinOffsetY, tileSize);
561  displayMaxY = displayMinY+tilesY;
562  assert (displayMaxY-displayMinY)*tileSize >= getHeight();
563  assert (displayMaxY-displayMinY)*tileSize-getHeight() < 2*tileSize;
566  }
567 
568  final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
569  final GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
570  final GraphicsConfiguration graphicsConfiguration = graphicsDevice.getDefaultConfiguration();
571  synchronized (bufferedImageSync) {
572  bufferedImage = graphicsConfiguration.createCompatibleImage(Math.max(1, getWidth()), Math.max(1, getHeight()), Transparency.TRANSLUCENT);
573  }
574  redrawAll();
575  }
576 
581  public int getPlayerX() {
582  synchronized (bufferedImageSync) {
583  return playerX;
584  }
585  }
586 
591  public int getPlayerY() {
592  synchronized (bufferedImageSync) {
593  return playerY;
594  }
595  }
596 
601  public int getOffsetX() {
602  synchronized (bufferedImageSync) {
603  return offsetX;
604  }
605  }
606 
611  public int getOffsetY() {
612  synchronized (bufferedImageSync) {
613  return offsetY;
614  }
615  }
616 
617  @Override
618  public void setBounds(final int x, final int y, final int width, final int height) {
619  super.setBounds(x, y, width, height);
620  final int mapWidth;
621  final int mapHeight;
622  synchronized (bufferedImageSync) {
623  playerX = width/2-tileSize/2;
624  playerY = height/2-tileSize/2;
625  mapWidth = this.mapWidth;
626  mapHeight = this.mapHeight;
627  }
628  setMapSize(mapWidth, mapHeight);
629  redrawAll();
630  }
631 
639  private void updateScrolledMap(@NotNull final Graphics g, @NotNull final CfMap map, final int dx, final int dy) {
640  if (avoidCopyArea || Math.abs(dx)*tileSize >= getWidth() || Math.abs(dy)*tileSize >= getHeight()) {
641  redrawAllUnlessDirty(g, map);
642  } else {
643  final int x = Math.max(dx, 0);
644  final int w = dx > 0 ? -dx : dx;
645  final int y = Math.max(dy, 0);
646  final int h = dy > 0 ? -dy : dy;
647  g.copyArea(x*tileSize, y*tileSize, getWidth()+w*tileSize, getHeight()+h*tileSize, -dx*tileSize, -dy*tileSize);
648 
649  synchronized (bufferedImageSync) {
650  if (dx > 0) {
651  final int ww = (displayMaxOffsetX == 0 ? 0 : 1)+dx;
653  } else if (dx < 0) {
654  final int ww = (displayMinOffsetX == 0 ? 0 : 1)-dx;
656  }
657  if (dy > 0) {
658  final int hh = (displayMaxOffsetY == 0 ? 0 : 1)+dy;
660  } else if (dy < 0) {
661  final int hh = (displayMinOffsetY == 0 ? 0 : 1)-dy;
663  }
664  }
665  }
666  }
667 
675  protected void paintColoredSquare(@NotNull final Graphics g, @NotNull final Color color, final int x, final int y) {
676  Image image = images.get(color);
677  if (image == null) {
678  final BufferedImage tmp = new BufferedImage(tileSize, tileSize, color.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB);
679  final Graphics g2 = tmp.createGraphics();
680  try {
681  g2.setColor(color);
682  g2.fillRect(0, 0, tileSize, tileSize);
683  } finally {
684  g2.dispose();
685  }
686  image = tmp;
687  images.put(color, image);
688  }
689  g.drawImage(image, x, y, tileSize, tileSize, null);
690  }
691 
696  protected int getMapWidth() {
697  synchronized (bufferedImageSync) {
698  return mapWidth;
699  }
700  }
701 
706  protected int getMapHeight() {
707  synchronized (bufferedImageSync) {
708  return mapHeight;
709  }
710  }
711 
719  @NotNull
720  private Graphics2D createBufferGraphics(@NotNull final CfMap map) {
721  assert Thread.holdsLock(bufferedImageSync);
722  assert bufferedImage != null;
723  final Graphics2D graphics = bufferedImage.createGraphics();
724  if (clearMapPending) {
725  clearMapPending = false;
726  clearMap(graphics);
727  }
728  while (true) {
729  final Long scrollMap = scrollMapPending.pollFirst();
730  if (scrollMap == null) {
731  break;
732  }
733  final long tmp = scrollMap;
734  final int dx = (int)(tmp>>32);
735  final int dy = (int)tmp;
736  updateScrolledMap(graphics, map, dx, dy);
737  markPlayer(graphics, dx, dy);
738  }
739  return graphics;
740  }
741 
742  @Nullable
743  @Override
744  @SuppressWarnings("MethodDoesntCallSuperMethod")
745  public Dimension getMinimumSize() {
746  return new Dimension(tileSize, tileSize);
747  }
748 
749 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.dispose
void dispose()
Releases all allocated resources.
Definition: AbstractGUIMap.java:329
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.map.NewmapListener
Interface for listeners interested in received "newmap" messages.
Definition: NewmapListener.java:31
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.paintSquareBackground
abstract 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.
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.AbstractGUIMap.redrawAllUnlessDirty
void redrawAllUnlessDirty(@NotNull final Graphics g, @NotNull final CfMap map)
Redraws all non-dirty tiles.
Definition: AbstractGUIMap.java:362
com.realtime.crossfire.jxclient.map.MapListener
Interface for listeners interested in changes within CfMap instances.
Definition: MapListener.java:34
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.displayMaxOffsetX
int displayMaxOffsetX
The number of pixels that are visible in the rightmost visible tile.
Definition: AbstractGUIMap.java:202
com.realtime.crossfire.jxclient.faces.Face
A.
Definition: Face.java:37
com.realtime.crossfire.jxclient.util.MathUtils.mod
static int mod(final int numerator, final int denominator)
Calculates the remainder of.
Definition: MathUtils.java:56
com.realtime.crossfire.jxclient.faces.FacesProvider.getSize
int getSize()
Returns the size of faces in pixels.
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.tileSize
final int tileSize
The size of one tile.
Definition: AbstractGUIMap.java:146
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.mapscrollListener
final MapScrollListener mapscrollListener
The MapScrollListener registered to receive map_scroll commands.
Definition: AbstractGUIMap.java:281
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.gui.map.AbstractGUIMap.clearMap
void clearMap(@NotNull final Graphics2D g)
Blanks the map display.
Definition: AbstractGUIMap.java:272
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.displayMaxY
int displayMaxY
The tile y coordinate where map drawing ends.
Definition: AbstractGUIMap.java:190
com.realtime.crossfire.jxclient.util.MathUtils
Utility class for mathematical functions.
Definition: MathUtils.java:29
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.paintComponent
void paintComponent(@NotNull final Graphics g)
Definition: AbstractGUIMap.java:527
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.DarknessColors.getDarknessColor
Color getDarknessColor(final int darkness)
Returns an overlay color for a darkness value.
Definition: DarknessColors.java:67
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.mapSizeListener
final MapSizeListener mapSizeListener
The MapSizeListener registered to detect map size changes.
Definition: AbstractGUIMap.java:292
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setChanged
void setChanged()
Records that the contents have changed and must be repainted.
Definition: AbstractGUIElement.java:223
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.gui.map.AbstractGUIMap.mapHeight
int mapHeight
The map height in squares.
Definition: AbstractGUIMap.java:141
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
Abstract base class for GUI elements to be shown in Guis.
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.map.MapUpdaterState.removeCrossfireMapListener
void removeCrossfireMapListener(@NotNull final MapListener listener)
Removes a listener to notify about changed map squares.
Definition: MapUpdaterState.java:165
com.realtime.crossfire.jxclient.map.MapUpdaterState.removeMapSizeListener
void removeMapSizeListener(@NotNull final MapSizeListener listener)
Removes a listener to be notified about map size changes.
Definition: MapUpdaterState.java:213
com.realtime.crossfire.jxclient.map.CfMapSquare.getHeadMapSquare
CfMapSquare getHeadMapSquare(final int layer)
Returns the map square of the head of a multi-square object.
Definition: CfMapSquare.java:307
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.AbstractGUIMap.getOffsetY
int getOffsetY()
Returns the y offset for drawing the square at coordinate 0 of the map.
Definition: AbstractGUIMap.java:611
com.realtime.crossfire.jxclient.gui.map.DarknessColors
Utility class for converting darkness values into colors.
Definition: DarknessColors.java:34
com.realtime.crossfire.jxclient.map.CfMapSquare.DARKNESS_FULL_BRIGHT
static final int DARKNESS_FULL_BRIGHT
The darkness value for a full bright square.
Definition: CfMapSquare.java:60
com.realtime.crossfire.jxclient.gui.map.DarknessColors.FOG_OF_WAR_COLOR
static final Color FOG_OF_WAR_COLOR
The color to use for overlaying fog-of-war tiles.
Definition: DarknessColors.java:46
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.gui.map.AbstractGUIMap.offsetY
int offsetY
The y offset for drawing the square at coordinate 0 of the map.
Definition: AbstractGUIMap.java:166
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.playerX
int playerX
The x offset of the tile representing the player.
Definition: AbstractGUIMap.java:151
com.realtime.crossfire.jxclient.map.MapScrollListener
Interface for listeners interested on map scrolled events.
Definition: MapScrollListener.java:31
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.protocol
Definition: MagicMap.java:23
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.gui.map.AbstractGUIMap.getMinimumSize
Dimension getMinimumSize()
Definition: AbstractGUIMap.java:745
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.playerY
int playerY
The y offset of the tile representing the player.
Definition: AbstractGUIMap.java:156
com.realtime.crossfire.jxclient.faces.FacesProvider.getImageIcon
ImageIcon getImageIcon(int faceNum, @Nullable AtomicBoolean returnIsUnknownImage)
Returns the face for a face ID.
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.redrawTilesUnlessDirty
void redrawTilesUnlessDirty(@NotNull final Graphics g, @NotNull final CfMap map, final int x0, final int y0, final int x1, final int y1)
Redraws a rectangular area of non-dirty tiles.
Definition: AbstractGUIMap.java:395
com.realtime.crossfire.jxclient.gui.gui.GUIElement
Interface defining an abstract GUI element.
Definition: GUIElement.java:33
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.redrawSquareUnlessDirty
void redrawSquareUnlessDirty(@NotNull final Graphics g, @NotNull final CfMap map, final int x, final int y)
Redraws one square if it is not dirty.
Definition: AbstractGUIMap.java:412
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.setMapSize
void setMapSize(final int mapWidth, final int mapHeight)
Sets the map size.
Definition: AbstractGUIMap.java:538
com.realtime.crossfire.jxclient.map.MapUpdaterState.getMap
CfMap getMap()
Returns the current map instance.
Definition: MapUpdaterState.java:406
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.offsetX
int offsetX
The x offset for drawing the square at coordinate 0 of the map.
Definition: AbstractGUIMap.java:161
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.createBufferGraphics
Graphics2D createBufferGraphics(@NotNull final CfMap map)
Returns a Graphics instance for painting into bufferedImage.
Definition: AbstractGUIMap.java:720
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: AbstractGUIMap.java:70
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.displayMinY
int displayMinY
The tile y coordinate where map drawing starts.
Definition: AbstractGUIMap.java:184
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.newmapListener
final NewmapListener newmapListener
The NewmapListener registered to receive newmap commands.
Definition: AbstractGUIMap.java:260
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.protocol.Map2
Interface defining constants for the "map2" Crossfire protocol message.
Definition: Map2.java:29
com.realtime.crossfire.jxclient.map.CfMapSquare.getFace
Face getFace(final int layer)
Returns the face of a layer.
Definition: CfMapSquare.java:278
com.realtime.crossfire.jxclient.gui.map.SmoothingRenderer.paintSmooth
void paintSmooth(@NotNull final Graphics graphics, final int x, final int y, final int px, final int py, final int layer, @NotNull final CfMap map, final int tileSize)
Draw the smoothing information at given position of map, for a given limit smoothlevel,...
Definition: SmoothingRenderer.java:176
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.smoothingRenderer
final SmoothingRenderer smoothingRenderer
The SmoothingRenderer to use or.
Definition: AbstractGUIMap.java:95
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.AbstractGUIMap
AbstractGUIMap(final boolean avoidCopyArea, @NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final MapUpdaterState mapUpdaterState, @NotNull final FacesProvider facesProvider, @Nullable final SmoothingRenderer smoothingRenderer, @NotNull final DarknessColors darknessColors, @NotNull final GuiFactory guiFactory)
Creates a new instance.
Definition: AbstractGUIMap.java:312
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.AbstractGUIMap.updateScrolledMap
void updateScrolledMap(@NotNull final Graphics g, @NotNull final CfMap map, final int dx, final int dy)
Updates the map display after the map contents have scrolled.
Definition: AbstractGUIMap.java:639
com.realtime.crossfire.jxclient.gui.map.DarknessColors.BLACK_AND_FOG_OF_WAR_COLOR
static final Color BLACK_AND_FOG_OF_WAR_COLOR
The combined color or Color#BLACK and FOG_OF_WAR_COLOR.
Definition: DarknessColors.java:52
com.realtime.crossfire.jxclient.map.MapSizeListener
Listener for clients interested in map size changes.
Definition: MapSizeListener.java:31
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.util
Definition: Codec.java:23
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.redrawSquare
void redrawSquare(@NotNull final Graphics g, final int x, final int y, @NotNull final CfMapSquare mapSquare, @NotNull final CfMap map)
Redraws one layer of a square.
Definition: AbstractGUIMap.java:448
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.bufferedImageSync
final Object bufferedImageSync
Synchronizes access to bufferedImage, clearMapPending, scrollMapPending, playerX, playerY,...
Definition: AbstractGUIMap.java:113
com.realtime.crossfire.jxclient.map.CfMapSquare.getY
int getY()
Returns the absolute map y-coordinate of this square.
Definition: CfMapSquare.java:146
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.mapListener
final MapListener mapListener
The MapListener registered to receive map updates.
Definition: AbstractGUIMap.java:227
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.redrawAll
void redrawAll()
Redraws the complete map view.
Definition: AbstractGUIMap.java:340
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Factory for creating Gui instances.
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.markPlayer
abstract void markPlayer(@NotNull final Graphics g, final int dx, final int dy)
Paints the player location.
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.map.AbstractGUIMap.setBounds
void setBounds(final int x, final int y, final int width, final int height)
Definition: AbstractGUIMap.java:618
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.redrawTiles
void redrawTiles(@NotNull final Graphics g, @NotNull final CfMap map, final int x0, final int y0, final int x1, final int y1)
Redraws a rectangular area of tiles.
Definition: AbstractGUIMap.java:377
com.realtime.crossfire.jxclient.map.CfMapSquare.getX
int getX()
Returns the absolute map x-coordinate of this square.
Definition: CfMapSquare.java:138
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.mapWidth
int mapWidth
The map width in squares.
Definition: AbstractGUIMap.java:136
com.realtime.crossfire
com.realtime.crossfire.jxclient.util.MathUtils.divRoundUp
static int divRoundUp(final int numerator, final int denominator)
Returns the quotient of two values, rounded up to the nearest integer.
Definition: MathUtils.java:67
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Manages the tooltip display.
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.bufferedImage
transient BufferedImage bufferedImage
An BufferedImage having the size of this component.
Definition: AbstractGUIMap.java:120
com.realtime
com.realtime.crossfire.jxclient.map.MapUpdaterState.removeCrossfireNewmapListener
void removeCrossfireNewmapListener(@NotNull final NewmapListener listener)
Removes a listener to notify about cleared maps.
Definition: MapUpdaterState.java:181
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.scrollMapPending
final Deque< Long > scrollMapPending
Pending map scrolls.
Definition: AbstractGUIMap.java:131
com
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.displayMaxOffsetY
int displayMaxOffsetY
The number of pixels that are visible in the bottommost visible tile.
Definition: AbstractGUIMap.java:214
com.realtime.crossfire.jxclient.protocol.Map2.NUM_LAYERS
int NUM_LAYERS
The total number of map layers to display.
Definition: Map2.java:34
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.displayMinX
int displayMinX
The tile x coordinate where map drawing starts.
Definition: AbstractGUIMap.java:172
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.gui.map.AbstractGUIMap.displayMinOffsetX
int displayMinOffsetX
The distance the leftmost visible tile reaches outside the map window.
Definition: AbstractGUIMap.java:196
com.realtime.crossfire.jxclient.map.MapUpdaterState
Update a CfMap model from protocol commands.
Definition: MapUpdaterState.java:49
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.clearMapPending
boolean clearMapPending
Whether the map area should be blanked.
Definition: AbstractGUIMap.java:125
com.realtime.crossfire.jxclient.faces.FacesProvider
Interface for face providers.
Definition: FacesProvider.java:34
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.mapUpdaterState
final MapUpdaterState mapUpdaterState
The MapUpdaterState instance to display.
Definition: AbstractGUIMap.java:82
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.paintImage
void paintImage(@NotNull final Graphics g, @NotNull final Face face, final int px, final int py, final int offsetX, final int offsetY)
Paints a face into a tile.
Definition: AbstractGUIMap.java:510
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.displayMaxX
int displayMaxX
The tile x coordinate where map drawing ends.
Definition: AbstractGUIMap.java:178
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.images
final Map< Color, Image > images
Maps Color to an image filled with this color with a size of one square.
Definition: AbstractGUIMap.java:221
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.displayMinOffsetY
int displayMinOffsetY
The distance the topmost visible tile reaches outside the map window.
Definition: AbstractGUIMap.java:208
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Listener for GUIElement related events.
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.gui.map.SmoothingRenderer
Renderer for painting smoothed faces into map views.
Definition: SmoothingRenderer.java:42
com.realtime.crossfire.jxclient.map.MapUpdaterState.removeCrossfireMapScrollListener
void removeCrossfireMapScrollListener(@NotNull final MapScrollListener listener)
Removes a listener to notify about scrolled maps.
Definition: MapUpdaterState.java:197
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.avoidCopyArea
final boolean avoidCopyArea
Whether map scrolling is done by copying pixel areas.
Definition: AbstractGUIMap.java:76
com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap.getOffsetX
int getOffsetX()
Returns the x offset for drawing the square at coordinate 0 of the map.
Definition: AbstractGUIMap.java:601