|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.freecol.client.gui.GUI
public final class GUI
This class is responsible for drawing the map/background on the
Canvas
. In addition, the graphical state of the map (focus,
active unit..) is also a responsibility of this class.
Field Summary | |
---|---|
static int |
ALARM_OFFSET_X
|
static int |
ALARM_OFFSET_Y
|
boolean |
debugShowMission
|
boolean |
debugShowMissionInfo
|
boolean |
displayColonyValue
|
Player |
displayColonyValuePlayer
|
boolean |
displayCoordinates
|
static int |
FOREST_INDEX
|
static int |
MAX_OTHER_UNITS
|
static int |
MESSAGE_AGE
|
static int |
MESSAGE_COUNT
|
static int |
MISSION_OFFSET_X
|
static int |
MISSION_OFFSET_Y
|
static int |
OTHER_UNITS_OFFSET_X
|
static int |
OTHER_UNITS_OFFSET_Y
|
static int |
OTHER_UNITS_WIDTH
|
static int |
OVERLAY_INDEX
|
static int |
RUMOUR_OFFSET_X
|
static int |
RUMOUR_OFFSET_Y
|
static int |
STATE_OFFSET_X
|
static int |
STATE_OFFSET_Y
|
static int |
TEXT_OFFSET_X
|
static int |
TEXT_OFFSET_Y
|
static int |
UNIT_OFFSET
|
Constructor Summary | |
---|---|
GUI(FreeColClient freeColClient,
java.awt.Dimension size,
ImageLibrary lib)
The constructor to use. |
Method Summary | |
---|---|
void |
addMessage(GUIMessage message)
Adds a message to the list of messages that need to be displayed on the GUI. |
Map.Position |
convertToMapCoordinates(int x,
int y)
Converts the given screen coordinates to Map coordinates. |
java.awt.image.BufferedImage |
createStringImage(java.awt.Graphics2D g,
java.lang.String nameString,
java.awt.Color color,
int maxWidth,
int preferredFontSize)
Creates an image with a string of a given color and with a black border around the glyphs. |
java.awt.image.BufferedImage |
createStringImage(javax.swing.JComponent c,
java.lang.String nameString,
java.awt.Color color,
int maxWidth,
int preferredFontSize)
Creates an image with a string of a given color and with a black border around the glyphs. |
void |
display(java.awt.Graphics2D g)
Displays this GUI onto the given Graphics2D. |
void |
displayColonyTile(java.awt.Graphics2D g,
Map map,
Tile tile,
int x,
int y,
Colony colony)
Displays the given Tile onto the given
Graphics2D object at the location specified by the
coordinates. |
void |
displayOccupationIndicator(java.awt.Graphics g,
Unit unit,
int x,
int y)
|
void |
displayTerrain(java.awt.Graphics2D g,
Map map,
Tile tile,
int x,
int y)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. |
void |
displayTile(java.awt.Graphics2D g,
Map map,
Tile tile,
int x,
int y)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. |
void |
displayTile(java.awt.Graphics2D g,
Map map,
Tile tile,
int x,
int y,
boolean drawUnexploredBorders)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. |
void |
drawRoad(java.awt.Graphics2D g,
long seed,
int x1,
int y1,
int x2,
int y2)
Draws a road, between the given points, on the provided Graphics . |
void |
executeWithUnitOutForAnimation(Unit unit,
Tile sourceTile,
OutForAnimationCallback r)
Run some code with the given unit made invisible. |
void |
forceReposition()
Force the next screen repaint to reposition the tiles on the window. |
Unit |
getActiveUnit()
Gets the active unit. |
int |
getBreakingPoint(java.lang.String string)
Breaks a line between two words. |
TerrainCursor |
getCursor()
|
Map.Position |
getFocus()
Gets the focus of the map. |
PathNode |
getGotoPath()
Gets the path to be drawn on the map. |
int |
getHeight()
Returns the height of this GUI. |
float |
getMapScale()
Get the current scale of the map. |
GUIMessage |
getMessage(int index)
Gets the message at position 'index'. |
int |
getMessageCount()
Gets the amount of message that are currently being displayed on this GUI. |
Map.Position |
getSelectedTile()
Gets the selected tile. |
java.awt.Rectangle |
getTileBounds(int x,
int y)
Calculate the bounds of the rectangle containing a Tile on the screen, and return it. |
java.awt.Rectangle |
getTileBounds(Tile tile)
Calculate the bounds of the rectangle containing a Tile on the screen, and return it. |
int |
getTileHeight()
|
java.awt.Point |
getTilePosition(Tile t)
Gets the position of the given Tile on the drawn map. |
int |
getTileWidth()
|
Unit |
getUnitInFront(Tile unitTile)
Gets the unit that should be displayed on the given tile. |
java.awt.Point |
getUnitLabelPositionInTile(javax.swing.JLabel unitLabel,
java.awt.Point tileP)
Gets the position where a unitLabel located at tile should be drawn. |
java.awt.Point |
getUnitLabelPositionInTile(javax.swing.JLabel unitLabel,
Tile tile)
Gets the position where a unitLabel located at tile should be drawn. |
ViewMode |
getViewMode()
Get the View Mode object |
int |
getWidth()
Returns the width of this GUI. |
boolean |
isGotoStarted()
Checks if there is currently a goto operation on the mapboard. |
boolean |
isInGame()
Checks if the game has started. |
boolean |
isMapNearBottom(int y)
Returns 'true' if the Tile is near the bottom. |
boolean |
isMapNearLeft(int x,
int y)
Returns 'true' if the Tile is near the left. |
boolean |
isMapNearRight(int x,
int y)
Returns 'true' if the Tile is near the right. |
boolean |
isMapNearTop(int y)
Returns 'true' if the Tile is near the top. |
void |
moveTileCursor(Map.Direction direction)
|
boolean |
onScreen(int x,
int y)
Checks if the Tile/Units at the given coordinates are displayed on the screen (or, if the map is already displayed and the focus has been changed, whether they will be displayed on the screen the next time it'll be redrawn). |
boolean |
onScreen(Map.Position position)
Checks if the Tile/Units at the given coordinates are displayed on the screen (or, if the map is already displayed and the focus has been changed, whether they will be displayed on the screen the next time it'll be redrawn). |
boolean |
removeOldMessages()
Removes all the message that are older than MESSAGE_AGE. |
void |
restartBlinking()
|
void |
scaleMap(float delta)
Change the scale of the map by delta. |
void |
setActiveUnit(Unit activeUnit)
Sets the active unit. |
void |
setDisplayTileText(DisplayTileTextAction.DisplayText tileTextType)
Set the type of text drawn in the tiles. |
void |
setFocus(int x,
int y)
Sets the focus of the map. |
void |
setFocus(Map.Position focus)
Sets the focus of the map. |
void |
setFocusImmediately(Map.Position focus)
Sets the focus of the map and repaints the screen immediately. |
void |
setGotoPath(PathNode gotoPath)
Sets the path to be drawn on the map. |
void |
setInGame(boolean inGame)
Notifies this GUI that the game has started or ended. |
void |
setSelectedTile(Map.Position selectedTile)
Selects the tile at the specified position, without clearing the orders of the first unit contained. |
void |
setSelectedTile(Map.Position selectedTile,
boolean clearGoToOrders)
Selects the tile at the specified position. |
void |
setSize(java.awt.Dimension size)
|
void |
showColonyPanel(Map.Position selectedTile)
|
void |
startCursorBlinking()
Starts the unit-selection-cursor blinking animation. |
void |
startGoto()
Starts a goto operation on the mapboard. |
void |
stopBlinking()
|
void |
stopGoto()
Stops any ongoing goto operation on the mapboard. |
void |
updateGotoPathForActiveUnit()
Sets the path of the active unit to display it. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int UNIT_OFFSET
public static final int TEXT_OFFSET_X
public static final int TEXT_OFFSET_Y
public static final int STATE_OFFSET_X
public static final int STATE_OFFSET_Y
public static final int ALARM_OFFSET_X
public static final int ALARM_OFFSET_Y
public static final int RUMOUR_OFFSET_X
public static final int RUMOUR_OFFSET_Y
public static final int MISSION_OFFSET_X
public static final int MISSION_OFFSET_Y
public static final int OTHER_UNITS_OFFSET_X
public static final int OTHER_UNITS_OFFSET_Y
public static final int OTHER_UNITS_WIDTH
public static final int MAX_OTHER_UNITS
public static final int MESSAGE_COUNT
public static final int MESSAGE_AGE
public static final int OVERLAY_INDEX
public static final int FOREST_INDEX
public boolean displayCoordinates
public boolean displayColonyValue
public Player displayColonyValuePlayer
public boolean debugShowMission
public boolean debugShowMissionInfo
Constructor Detail |
---|
public GUI(FreeColClient freeColClient, java.awt.Dimension size, ImageLibrary lib)
freeColClient
- The main control class.size
- The size of the GUI (= the entire screen if the app is
displayed in full-screen).lib
- The library of images needed to display certain things
visually.Method Detail |
---|
public void executeWithUnitOutForAnimation(Unit unit, Tile sourceTile, OutForAnimationCallback r)
unit
- The unit to be hidden.r
- The code to be executed.public ViewMode getViewMode()
View Mode
object
public void startCursorBlinking()
public TerrainCursor getCursor()
public void setSize(java.awt.Dimension size)
public void moveTileCursor(Map.Direction direction)
public void setSelectedTile(Map.Position selectedTile)
selectedTile
- The Position
of the tile to be
selected.setSelectedTile(Map.Position, boolean)
public void setSelectedTile(Map.Position selectedTile, boolean clearGoToOrders)
Colony
on the Tile
the
Canvas.showColonyPanel(net.sf.freecol.common.model.Colony)
will be invoked.
true
selectedTile
will become the map focus.
selectedTile
- The Position
of the tile to be
selected.clearGoToOrders
- Use true
to clear goto orders of
the unit which is activated.getSelectedTile()
,
setActiveUnit(net.sf.freecol.common.model.Unit)
,
setFocus(Map.Position)
public void showColonyPanel(Map.Position selectedTile)
public void restartBlinking()
public void stopBlinking()
public Unit getUnitInFront(Tile unitTile)
unitTile
- The Tile
.
Unit
or null if no unit applies.public Map.Position getSelectedTile()
Position
of that tile.setSelectedTile(Map.Position)
public Unit getActiveUnit()
Unit
.setActiveUnit(net.sf.freecol.common.model.Unit)
public void setActiveUnit(Unit activeUnit)
setSelectedTile(Map.Position)
if
the selected tile is another tile than where the activeUnit
is located.
activeUnit
- The new active unit.setSelectedTile(Map.Position)
public Map.Position getFocus()
Position
of the center tile of the displayed
mapsetFocus(Map.Position)
public void setFocus(Map.Position focus)
focus
- The Position
of the center tile of the
displayed map.getFocus()
public void setFocusImmediately(Map.Position focus)
focus
- The Position
of the center tile of the
displayed map.getFocus()
public void setFocus(int x, int y)
x
- The x-coordinate of the center tile of the displayed map.y
- The x-coordinate of the center tile of the displayed map.getFocus()
public int getMessageCount()
public GUIMessage getMessage(int index)
index
- The index of the message to return.
public void addMessage(GUIMessage message)
message
- The message to add.public boolean removeOldMessages()
public int getWidth()
public int getHeight()
public void display(java.awt.Graphics2D g)
g
- The Graphics2D on which to display this GUI.public java.awt.image.BufferedImage createStringImage(java.awt.Graphics2D g, java.lang.String nameString, java.awt.Color color, int maxWidth, int preferredFontSize)
g
- A Graphics
-object for getting a
Font
.nameString
- The String
to make an image of.color
- The Color
to use when displaying the
nameString
.maxWidth
- The maximum width of the image. The size of the
Font
will be adjusted if the image gets larger
than this value.preferredFontSize
- The preferred font size.
public java.awt.image.BufferedImage createStringImage(javax.swing.JComponent c, java.lang.String nameString, java.awt.Color color, int maxWidth, int preferredFontSize)
c
- A JComponent
-object for getting a
Font
.nameString
- The String
to make an image of.color
- The Color
to use when displaying the
nameString
.maxWidth
- The maximum width of the image. The size of the
Font
will be adjusted if the image gets larger
than this value.preferredFontSize
- The preferred font size.
public void drawRoad(java.awt.Graphics2D g, long seed, int x1, int y1, int x2, int y2)
Graphics
. When you provide the same seed
you will get the same road.
g
- The Graphics
to draw the road upon.seed
- The seed of the random generator that is creating the road.x1
- The x-component of the first coordinate.y1
- The y-component of the first coordinate.x2
- The x-component of the second coordinate.y2
- The y-component of the second coordinate.public void displayColonyTile(java.awt.Graphics2D g, Map map, Tile tile, int x, int y, Colony colony)
Tile
onto the given
Graphics2D
object at the location specified by the
coordinates. The visualization of the Tile
also includes
information from the corresponding ColonyTile
from the
given Colony
.
g
- The Graphics2D
object on which to draw the
Tile
.map
- The Map
.tile
- The Tile
to draw.x
- The x-coordinate of the location where to draw the Tile (in
pixels).y
- The y-coordinate of the location where to draw the Tile (in
pixels).colony
- The Colony
to create the visualization of
the Tile
for. This object is also used to get
the ColonyTile
for the given Tile
.public void displayTerrain(java.awt.Graphics2D g, Map map, Tile tile, int x, int y)
displayTile(g, map, tile, x, y, true);
.
g
- The Graphics2D object on which to draw the Tile.map
- The map.tile
- The Tile to draw.x
- The x-coordinate of the location where to draw the Tile (in
pixels).y
- The y-coordinate of the location where to draw the Tile (in
pixels).public void displayTile(java.awt.Graphics2D g, Map map, Tile tile, int x, int y)
displayTile(g, map, tile, x, y, true);
.
g
- The Graphics2D object on which to draw the Tile.map
- The map.tile
- The Tile to draw.x
- The x-coordinate of the location where to draw the Tile (in
pixels).y
- The y-coordinate of the location where to draw the Tile (in
pixels).public void displayTile(java.awt.Graphics2D g, Map map, Tile tile, int x, int y, boolean drawUnexploredBorders)
g
- The Graphics2D object on which to draw the Tile.map
- The map.tile
- The Tile to draw.x
- The x-coordinate of the location where to draw the Tile (in
pixels).y
- The y-coordinate of the location where to draw the Tile (in
pixels).drawUnexploredBorders
- If true; draws border between explored and
unexplored terrain.public void stopGoto()
public void startGoto()
public boolean isGotoStarted()
true
if a goto operation is in progress.public void updateGotoPathForActiveUnit()
public void setGotoPath(PathNode gotoPath)
gotoPath
- The path that should be drawn on the map or
null
if no path should be drawn.public PathNode getGotoPath()
null
if no path should be drawn.public void setDisplayTileText(DisplayTileTextAction.DisplayText tileTextType)
tileTextType
- a DisplayText
valuepublic int getBreakingPoint(java.lang.String string)
string
- The line for which we should determine a breaking point.
-1
if there are none.public void displayOccupationIndicator(java.awt.Graphics g, Unit unit, int x, int y)
public java.awt.Point getUnitLabelPositionInTile(javax.swing.JLabel unitLabel, Tile tile)
unitLabel
- The unit label with the unit's image and occupation
indicator drawn.tile
- The tile where the unitLabel will be drawn over
public java.awt.Point getUnitLabelPositionInTile(javax.swing.JLabel unitLabel, java.awt.Point tileP)
unitLabel
- The unit label with the unit's image and occupation
indicator drawn.tileP
- The position of the Tile on the screen.
public void setInGame(boolean inGame)
inGame
- Indicates whether or not the game has started.public boolean isInGame()
setInGame(boolean)
public boolean onScreen(int x, int y)
x
- The x-coordinate of the Tile in question.y
- The y-coordinate of the Tile in question.
public boolean onScreen(Map.Position position)
position
- The position of the Tile in question.
public Map.Position convertToMapCoordinates(int x, int y)
x
- The x-coordinate in pixels.y
- The y-coordinate in pixels.
public boolean isMapNearTop(int y)
y
- The y-coordinate of a Tile.
public boolean isMapNearBottom(int y)
y
- The y-coordinate of a Tile.
public boolean isMapNearLeft(int x, int y)
x
- The x-coordinate of a Tile.y
- The y-coordinate of a Tile.
public boolean isMapNearRight(int x, int y)
x
- The x-coordinate of a Tile.y
- The y-coordinate of a Tile.
public float getMapScale()
float
valuepublic void scaleMap(float delta)
delta
- a float
valuepublic java.awt.Point getTilePosition(Tile t)
Tile
on the drawn map.
t
- The Tile
.
Tile
, or
null
if the Tile
is not drawn on
the mapboard.public java.awt.Rectangle getTileBounds(Tile tile)
tile
- The tile on the screen.
public java.awt.Rectangle getTileBounds(int x, int y)
x
- The x-coordinate of the Tiley
- The y-coordinate of the Tile
public void forceReposition()
public int getTileHeight()
public int getTileWidth()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |