Crossfire JXClient, Trunk
GUIMapDirections.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 
32 import java.awt.BasicStroke;
33 import java.awt.Color;
34 import java.awt.Graphics;
35 import java.awt.Graphics2D;
36 import java.awt.Shape;
37 import java.awt.Stroke;
38 import java.awt.geom.Line2D;
39 import org.jetbrains.annotations.NotNull;
40 import org.jetbrains.annotations.Nullable;
41 
46 public class GUIMapDirections extends AbstractGUIElement {
47 
51  private static final long serialVersionUID = 1;
52 
56  private static final int @NotNull [] DX = {0, 1, 1, 1, 0, -1, -1, -1,};
57 
61  private static final int @NotNull [] DY = {-1, -1, 0, 1, 1, 1, 0, -1,};
62 
66  @NotNull
68 
72  private final int tileSize;
73 
83  public GUIMapDirections(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final FacesProvider facesProvider, @NotNull final PendingDirections pendingDirections, @NotNull final GuiFactory guiFactory) {
85  this.pendingDirections = pendingDirections;
86  tileSize = facesProvider.getSize();
87  }
88 
89  @Override
90  protected void paintComponent(@NotNull final Graphics g) {
91  super.paintComponent(g);
92 
93  final Graphics2D g2 = (Graphics2D)g;
94 
95  final int x0 = getWidth()/2;
96  final int y0 = getHeight()/2;
97  final Stroke s1 = new BasicStroke(5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
98  final Stroke s2 = new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
99  int x1 = x0;
100  int y1 = y0;
101  boolean showRunDirection = true;
102  for (final int direction : pendingDirections.getPendingDirections()) {
103  final int dx = DX[direction];
104  final int dy = DY[direction];
105  final int x2 = x1+tileSize*dx;
106  final int y2 = y1+tileSize*dy;
107  final Shape line = new Line2D.Float(x1, y1, x2, y2);
108  g.setColor(Color.black);
109  g2.setStroke(s1);
110  g2.draw(line);
111  g.setColor(Color.green);
112  g2.setStroke(s2);
113  g2.draw(line);
114  x1 = x2;
115  y1 = y2;
116  showRunDirection = false;
117  }
118  if (showRunDirection) {
119  final int direction = pendingDirections.getRunDirection();
120  if (direction != -1) {
121  final int dx = DX[direction];
122  final int dy = DY[direction];
123  final int x2 = x1+tileSize*dx;
124  final int y2 = y1+tileSize*dy;
125  final Shape line = new Line2D.Float(x1, y1, x2, y2);
126  g.setColor(Color.black);
127  g2.setStroke(s1);
128  g2.draw(line);
129  g.setColor(Color.green);
130  g2.setStroke(s2);
131  g2.draw(line);
132  }
133  }
134  }
135 
136  @Nullable
137  @Override
139  return null;
140  }
141 
142  @Override
143  public void notifyOpen() {
144  }
145 
146 }
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
Definition: FacesProvider.java:34
com.realtime.crossfire.jxclient.map
Definition: CfMap.java:23
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.serialVersionUID
static final long serialVersionUID
Definition: GUIMapDirections.java:51
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.tileSize
final int tileSize
Definition: GUIMapDirections.java:72
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.paintComponent
void paintComponent(@NotNull final Graphics g)
Definition: GUIMapDirections.java:90
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.GUIMapDirections
GUIMapDirections(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final FacesProvider facesProvider, @NotNull final PendingDirections pendingDirections, @NotNull final GuiFactory guiFactory)
Definition: GUIMapDirections.java:83
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.getTooltip
TooltipText getTooltip()
Definition: GUIMapDirections.java:138
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.DX
static final int[] DX
Definition: GUIMapDirections.java:56
com.realtime.crossfire.jxclient.faces
Definition: AbstractFaceQueue.java:23
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections
Definition: GUIMapDirections.java:46
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.notifyOpen
void notifyOpen()
Definition: GUIMapDirections.java:143
com.realtime.crossfire.jxclient.map.PendingDirections.getPendingDirections
Iterable< @NotNull Integer > getPendingDirections()
Definition: PendingDirections.java:72
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.DY
static final int[] DY
Definition: GUIMapDirections.java:61
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.map.PendingDirections
Definition: PendingDirections.java:40
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.gui.map.GUIMapDirections.pendingDirections
final PendingDirections pendingDirections
Definition: GUIMapDirections.java:67
com.realtime.crossfire.jxclient.gui.gui.TooltipText
Definition: TooltipText.java:31
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.guiFactory
final GuiFactory guiFactory
Definition: AbstractGUIElement.java:48
com.realtime.crossfire.jxclient.map.PendingDirections.getRunDirection
int getRunDirection()
Definition: PendingDirections.java:82
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