Crossfire JXClient, Trunk  R20561
GUIMap.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 
32 import java.awt.Color;
33 import java.awt.Dimension;
34 import java.awt.Graphics;
35 import java.awt.event.MouseEvent;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
38 
45 public class GUIMap extends AbstractGUIMap {
46 
50  private static final long serialVersionUID = 1;
51 
55  @NotNull
57 
61  private final int tileSize;
62 
77  public GUIMap(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 CrossfireServerConnection crossfireServerConnection, @NotNull final SmoothFaces smoothFaces, @NotNull final DarknessColors darknessColors) {
78  super(avoidCopyArea, tooltipManager, elementListener, name, mapUpdaterState, facesProvider, new SmoothingRenderer(smoothFaces, facesProvider), darknessColors);
79  this.crossfireServerConnection = crossfireServerConnection;
80  tileSize = facesProvider.getSize();
81  }
82 
86  @Override
87  protected void paintSquareBackground(@NotNull final Graphics g, final int px, final int py, final boolean hasImage, @NotNull final CfMapSquare mapSquare) {
88  paintColoredSquare(g, Color.BLACK, px, py);
89  }
90 
94  @Override
95  protected void markPlayer(@NotNull final Graphics g, final int dx, final int dy) {
96  }
97 
101  @Override
102  public void mouseClicked(@NotNull final MouseEvent e) {
103  super.mouseClicked(e);
104  switch (e.getButton()) {
105  case MouseEvent.BUTTON1:
106  final int dx1 = e.getX()-getOffsetX();
107  final int dy1 = e.getY()-getOffsetY();
108  if (dx1 >= 0 && dy1 >= 0) {
109  final int mapWidth = getMapWidth();
110  final int mapHeight = getMapHeight();
111  final int dx2 = dx1/tileSize-mapWidth/2;
112  final int dy2 = dy1/tileSize-mapHeight/2;
113  if (dx2 < mapWidth && dy2 < mapHeight) {
114  crossfireServerConnection.sendLookat(dx2, dy2);
115  }
116  }
117  break;
118 
119  case MouseEvent.BUTTON2:
120  case MouseEvent.BUTTON3:
121  break;
122  }
123  }
124 
128  @Nullable
129  @Override
130  public Dimension getPreferredSize() {
131  return new Dimension(getMapWidth()*tileSize, getMapHeight()*tileSize);
132  }
133 
138  public int getPreferredMapWidth() {
139  return MathUtils.divRoundUp(getWidth(), tileSize);
140  }
141 
146  public int getPreferredMapHeight() {
147  return MathUtils.divRoundUp(getHeight(), tileSize);
148  }
149 
150 }
GUIMap(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 CrossfireServerConnection crossfireServerConnection, @NotNull final SmoothFaces smoothFaces, @NotNull final DarknessColors darknessColors)
Creates a new instance.
Definition: GUIMap.java:77
final TooltipManager tooltipManager
The TooltipManager to update.
Represents a square in a CfMap.
void markPlayer(@NotNull final Graphics g, final int dx, final int dy)
Definition: GUIMap.java:95
final boolean avoidCopyArea
Whether map scrolling is done by copying pixel areas.
int getOffsetY()
Returns the y offset for drawing the square at coordinate 0 of the map.
int getMapHeight()
Returns the map height in squares.
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 mouseClicked(@NotNull final MouseEvent e)
Will be called when the user has clicked (pressed+released) this element.This event will be delivered...
Definition: GUIMap.java:102
final int tileSize
The size of one tile.
Definition: GUIMap.java:61
Utility class for mathematical functions.
Definition: MathUtils.java:28
int getMapWidth()
Returns the map width in squares.
final FacesProvider facesProvider
The FacesProvider for looking up faces.
int getOffsetX()
Returns the x offset for drawing the square at coordinate 0 of the map.
Update a CfMap model from protocol commands.
final MapUpdaterState mapUpdaterState
The MapUpdaterState instance to display.
final DarknessColors darknessColors
The DarknessColors instance for converting darkness values into colors.
static int divRoundUp(final int numerator, final int denominator)
Returns the quotient of two values, rounded up to the nearest integer.
Definition: MathUtils.java:66
void paintColoredSquare(@NotNull final Graphics g, @NotNull final Color color, final int x, final int y)
Fills a square with one Color.
Renderer for painting smoothed faces into map views.
Utility class for converting darkness values into colors.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
final CrossfireServerConnection crossfireServerConnection
The CrossfireServerConnection to monitor.
Definition: GUIMap.java:56
void paintSquareBackground(@NotNull final Graphics g, final int px, final int py, final boolean hasImage, @NotNull final CfMapSquare mapSquare)
Definition: GUIMap.java:87
void sendLookat(final int dx, int dy)
Sends a "lookat" command to the server.
int getPreferredMapWidth()
Returns the minimal map width in squares needed to fill the map area.
Definition: GUIMap.java:138
Maintains smoothing information received from the Crossfire server.
int getPreferredMapHeight()
Returns the minimal map height in squares needed to fill the map area.
Definition: GUIMap.java:146
static final long serialVersionUID
The serial version UID.
Definition: GUIMap.java:50