Crossfire JXClient, Trunk
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-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 
35 import java.awt.Color;
36 import java.awt.Dimension;
37 import java.awt.Graphics;
38 import java.awt.event.MouseEvent;
39 import org.jetbrains.annotations.NotNull;
40 import org.jetbrains.annotations.Nullable;
41 
48 public class GUIMap extends AbstractGUIMap {
49 
53  private static final long serialVersionUID = 1;
54 
58  @NotNull
60 
64  private final int tileSize;
65 
81  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, @NotNull final GuiFactory guiFactory) {
83  this.crossfireServerConnection = crossfireServerConnection;
85  }
86 
87  @Override
88  protected void paintSquareBackground(@NotNull final Graphics g, final int px, final int py, final boolean hasImage, @NotNull final CfMapSquare mapSquare) {
89  paintColoredSquare(g, Color.BLACK, px, py);
90  }
91 
92  @Override
93  protected void markPlayer(@NotNull final Graphics g, final int dx, final int dy) {
94  }
95 
96  @Override
97  public void mouseClicked(@NotNull final MouseEvent e) {
98  super.mouseClicked(e);
99 
100  if (!isEnabled()) {
101  return;
102  }
103 
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) {
115  }
116  }
117  break;
118 
119  case MouseEvent.BUTTON2:
120  case MouseEvent.BUTTON3:
121  break;
122  }
123  }
124 
125  @Nullable
126  @Override
128  return null;
129  }
130 
131  @Override
132  public void notifyOpen() {
133  }
134 
135  @Nullable
136  @Override
137  @SuppressWarnings("MethodDoesntCallSuperMethod")
138  public Dimension getPreferredSize() {
139  return new Dimension(getMapWidth()*tileSize, getMapHeight()*tileSize);
140  }
141 
146  public int getPreferredMapWidth() {
147  return MathUtils.divRoundUp(getWidth(), tileSize);
148  }
149 
154  public int getPreferredMapHeight() {
155  return MathUtils.divRoundUp(getHeight(), tileSize);
156  }
157 
158 }
com.realtime.crossfire.jxclient.gui.map.GUIMap.getPreferredSize
Dimension getPreferredSize()
Definition: GUIMap.java:138
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.server
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.util.MathUtils
Utility class for mathematical functions.
Definition: MathUtils.java:29
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
Definition: CrossfireServerConnection.java:37
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.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
The GUIElementListener to notify.
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.map.GUIMap.crossfireServerConnection
final CrossfireServerConnection crossfireServerConnection
The CrossfireServerConnection to monitor.
Definition: GUIMap.java:59
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.gui.map.GUIMap.getPreferredMapWidth
int getPreferredMapWidth()
Returns the minimal map width in squares needed to fill the map area.
Definition: GUIMap.java:146
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
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.GUIMap.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: GUIMap.java:88
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.GUIMap.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: GUIMap.java:53
com.realtime.crossfire.jxclient.gui.map.GUIMap.getPreferredMapHeight
int getPreferredMapHeight()
Returns the minimal map height in squares needed to fill the map area.
Definition: GUIMap.java:154
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.util
Definition: Codec.java:23
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.gui.map.GUIMap
Display the map view.
Definition: GUIMap.java:48
com.realtime.crossfire.jxclient.gui.gui.TooltipText
Information for displaying tooltips.
Definition: TooltipText.java:31
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Factory for creating Gui instances.
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.map.GUIMap.markPlayer
void markPlayer(@NotNull final Graphics g, final int dx, final int dy)
Paints the player location.
Definition: GUIMap.java:93
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.jxclient.gui.map.GUIMap.GUIMap
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, @NotNull final GuiFactory guiFactory)
Creates a new instance.
Definition: GUIMap.java:81
com.realtime.crossfire.jxclient.gui.map.GUIMap.getTooltip
TooltipText getTooltip()
Returns the current tooltip text.
Definition: GUIMap.java:127
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
com
com.realtime.crossfire.jxclient.gui.map.GUIMap.mouseClicked
void mouseClicked(@NotNull final MouseEvent e)
Will be called when the user has clicked (pressed+released) this element.
Definition: GUIMap.java:97
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.GUIMap.tileSize
final int tileSize
The size of one tile.
Definition: GUIMap.java:64
com.realtime.crossfire.jxclient.map.MapUpdaterState
Update a CfMap model from protocol commands.
Definition: MapUpdaterState.java:49
com.realtime.crossfire.jxclient.gui.map.GUIMap.notifyOpen
void notifyOpen()
Called each time the enclosing dialog is opened (or raised).
Definition: GUIMap.java:132
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.faces.SmoothFaces
Maintains smoothing information received from the Crossfire server.
Definition: SmoothFaces.java:33
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Listener for GUIElement related events.
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection.sendLookat
void sendLookat(final int dx, int dy)
Sends a "lookat" command to the server.
com.realtime.crossfire.jxclient.gui.map.SmoothingRenderer
Renderer for painting smoothed faces into map views.
Definition: SmoothingRenderer.java:42
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