|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Canvas soc.client.SOCBoardPanel
public class SOCBoardPanel
This is a component that can display a Settlers of Catan Board. It can be used in an applet or an application. It loads gifs from a directory named "images" in the same directory as this class.
The main drawing methods are drawBoardEmpty(Graphics)
for hexes and ports,
and drawBoard(Graphics)
for placed pieces like settlements and the robber.
The board background color is set in SOCPlayerInterface
.
Since all areas outside the board boundaries are filled with
water hex tiles, this color is only a fallback; it's briefly visible
at window creation while the hexes are loading and rendering.
When the mouse is over the game board, a tooltip shows information
such as a hex's resource, a piece's owner, a port's ratio, or the
number under the robber. See hoverTip
.
During game play, moving the mouse over the board shows ghosted roads,
settlements, cities, and ships at locations the player can build.
See: hilight
, SOCBoardPanel.BoardToolTip.hoverRoadID
.
Right-click to build, or use the SOCBuildingPanel
's buttons.
Before the game begins, the boardpanel is full of water hexes.
You can show a short message text of 1 or 2 lines by calling
setSuperimposedText(String, String)
.
During game play, you can show a short 1-line message text in the
top-center part of the panel by calling setSuperimposedTopText(String)
.
This panel's minimum width and height in pixels is getMinimumSize()
.
To set its size, call setSize(int, int)
or setBounds(int, int, int, int)
;
these methods will set a flag to rescale board graphics if needed.
If the game has 6 players but not SOCGame.hasSeaBoard
, the board is also
rotated 90 degrees clockwise. Pixel coordinates can be transformed between
actual (scaled/rotated) and unscaled/un-rotated "internal" coordinates with
scaleFromActualX(int)
, scaleFromActualY(int)
,
scaleToActualX(int)
, scaleToActualY(int)
.
loadImages(Component, boolean)
and rescaleCoordinateArrays()
setSize(..)
which calls rescaleBoard(int, int)
rescaleBoard(int, int)
scales hex images, calls
renderBorderedHex(Image, Image, Color)
and renderPortImages()
paint(Graphics)
calls drawBoard(Graphics)
drawBoard(..)
calls drawBoardEmpty(Graphics)
which renders into a buffer image
drawBoard(..)
draws the placed pieces over the buffered board image from drawBoardEmpty(..)
Nested Class Summary | |
---|---|
protected class |
SOCBoardPanel.BoardPanelSendBuildTask
Used for the delay between sending a build-request message, and receiving a game-state message. |
private class |
SOCBoardPanel.BoardPopupMenu
This class creates a popup menu on the board, to trade or build or cancel building. |
protected class |
SOCBoardPanel.BoardToolTip
(tooltip) Hover text for info on pieces/parts of the board. |
private class |
SOCBoardPanel.ConfirmAttackPirateFortressDialog
Modal dialog to confirm the player wants to attack the pirate fortress and end their turn. |
private class |
SOCBoardPanel.ConfirmPlaceShipDialog
For scenario _SC_FTRI , modal dialog to confirm placing a ship
at an edge with a "gift" trade port. |
protected static class |
SOCBoardPanel.DelayedRepaint
With a recent board resize, one or more rescaled images still hasn't been completed after 7 seconds. |
private class |
SOCBoardPanel.MoveRobberConfirmDialog
Modal dialog to confirm moving the robber next to our own settlement or city. |
(package private) static class |
SOCBoardPanel.ResourceTradeAllMenu
Menu for right-click on 3-for-1 port to trade all resource types with bank/port. |
Nested classes/interfaces inherited from class java.awt.Canvas |
---|
java.awt.Canvas.AccessibleAWTCanvas |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
private static java.awt.Color |
ARROW_COLOR
Current-player arrow color: cyan: r=106,g=183,b=183 |
private static java.awt.Color |
ARROW_COLOR_PLACING
Player arrow color when game is over, and during SOCGame.SPECIAL_BUILDING phase of the 6-player game. |
private static int |
ARROW_SZ
Current-player arrow fits in a 37 x 37 square. |
private static int[] |
arrowXL
Current-player arrow, left-pointing. |
private static int[] |
arrowXR
Current-player arrow, right-pointing. |
private static int[] |
arrowY
Current-player arrow, y-coordinates: same whether pointing left or right. |
private SOCBoard |
board
The board in the game |
private static int |
BOARDHEIGHT_VISUAL_MIN
When isLargeBoard ,
Minimum visual SOCBoard.getBoardHeight() = 17 for
enough height for SOCHandPanel s to left and right. |
private static int |
BOARDWIDTH_VISUAL_MIN
When isLargeBoard ,
Minimum visual SOCBoard.getBoardWidth() = 18 for good-looking aspect ratio, and
enough width for SOCBuildingPanel contents below. |
private java.awt.Image |
buffer
offscreen buffer of everything (board, pieces, hovering pieces, tooltip), to prevent flicker. |
protected static int |
BUILD_REQUEST_MAX_DELAY_SEC
for popup-menu build request, network send maximum delay (seconds) |
protected SOCBoardPanel.BoardPanelSendBuildTask |
buildReqTimerTask
For right-click build menu; used for fallback part of client-server-client communication of a build request. |
private static int[] |
cityX
city |
private static int[] |
cityY
|
static int |
CONSIDER_LM_CITY
|
static int |
CONSIDER_LM_ROAD
|
static int |
CONSIDER_LM_SETTLEMENT
|
static int |
CONSIDER_LT_CITY
|
static int |
CONSIDER_LT_ROAD
|
static int |
CONSIDER_LT_SETTLEMENT
|
private boolean |
debugShowCoordsTooltip
Debugging flag where board item tooltip includes the item's coordinates. |
(package private) boolean[] |
debugShowPotentials
For debugging, flags to show player 0's potential/legal coordinate sets. |
private static int |
deltaX
How many pixels to move over for a new hex. |
private static int[] |
DELTAX_FACING
x-offset to move over 1 hex, for each port facing direction (1-6). |
private static int |
deltaY
How many pixels to drop for each row of hexes. |
private static int[] |
DELTAY_FACING
y-offset to move over 1 hex, for each port facing direction (1-6). |
private static java.awt.Image[] |
dice
Dice number pictures (for the arrow; the hex dice numbers use Graphics.drawString ). |
private static java.awt.Color[] |
DICE_NUMBER_CIRCLE_COLORS
Dice number circle background colors on hexes. |
private static int |
DICE_NUMBER_CIRCLE_DIAMETER
Diameter and font size (unscaled internal-pixels) for dice number circles on hexes. |
private static int |
DICE_NUMBER_FONTPOINTS
Diameter and font size (unscaled internal-pixels) for dice number circles on hexes. |
private static int |
DICE_SZ
Dice number graphic size in pixels; fits in a 25 x 25 square. |
private java.awt.FontMetrics |
diceNumberCircleFM
FontMetrics of diceNumberCircleFont . |
private java.awt.Font |
diceNumberCircleFont
Font of dice-number circles appearing on hexes, and dice numbers on cloth villages. |
private static int[] |
downRoadX
road looks like "\" along lower-left edge of hex |
private static int[] |
downRoadY
|
private long |
drawnEmptyAt
Time of start of board repaint, as returned by System.currentTimeMillis() . |
private int[] |
edgeMap
Map grid sectors (from unscaled on-screen coordinates) to hex edges. |
private java.awt.Image |
emptyBoardBuffer
offscreen buffer of board without any pieces placed, to prevent flicker. |
private static int[] |
fortressX
Fortress polygon for scenario SC_PIRI. |
private static int[] |
fortressY
Fortress polygon for scenario SC_PIRI. |
private SOCGame |
game
The game which this board is a part of |
private static int |
GAME_FORMING
|
private static int |
GAME_OVER
|
private static int |
HALF_HEXHEIGHT
Half of HEXHEIGHT , in unscaled internal pixels, for use with various board graphics. |
private static int |
halfdeltaX
Each row moves a half hex over horizontally, compared to the row above/below it. |
private static int |
halfdeltaY
How many pixels for half a hex's height. |
private boolean |
hasCalledSetSize
Ensure that super.setSize is called at least once. |
private static java.awt.Color[] |
HEX_BORDER_COLORS
Border colors for hex rendering. |
private static int |
HEX_PORT_CIRCLE_DIA
Diameter for rendering the hex port graphics' clear middle circle in renderPortImages() . |
private static int[] |
hexCornersX
hex corners, clockwise from top-center, as located in waterHex.gif, hexBorder.gif, and other hex graphics: (27,0) (54,16) (54,46) (27,62) (0,46) (0,16). |
private static int[] |
hexCornersY
hex corners, clockwise from top-center. |
private static int[] |
hexCornersY_RotatedOffset
Offset to add to hexCornersY [] coordinates when used as (y,x) on rotated board. |
private static java.awt.Image[] |
hexes
Hex images - shared unscaled original-resolution from IMAGEDIR 's GIF files. |
private static int |
HEXHEIGHT
hex size, in unscaled internal-pixels: 55 wide, 64 tall. |
private int[] |
hexIDtoNum
Translate hex ID to hex number to get coords. |
private int[] |
hexMap
Map grid sectors (from unscaled on-screen coordinates) to hexes. |
private static int |
HEXWIDTH
hex size, in unscaled internal-pixels: 55 wide, 64 tall. |
private int[] |
hexX
hex coordinates for drawing pieces on the board. |
private static int[] |
hexX_6pl
hex coordinates for drawing the 6-player board, or null. |
private static int |
HEXX_OFF_6PL
In 6-player mode, the offset of hexX_6pl , hexY_6pl
from hexX_st , hexY_st in unscaled board coordinates. |
private static int[] |
hexX_st
hex coordinates for drawing the standard board. |
private int[] |
hexY
hex coordinates for drawing pieces on the board. |
private static int[] |
hexY_6pl
hex coordinates for drawing the 6-player board, or null. |
private static int |
HEXY_OFF_6PL
In 6-player mode, the offset of hexX_6pl , hexY_6pl
from hexX_st , hexY_st in unscaled board coordinates. |
private static int |
HEXY_OFF_6PL_FIND
In 6-player mode, subtract this instead of HEXY_OFF_6PL
in findEdge(int, int, boolean) , findHex(int, int) , findNode(int, int) . |
private static int |
HEXY_OFF_SLOPE_HEIGHT
The vertical offset for A-nodes vs Y-nodes along a road; the height of the sloped top/bottom hex edges. |
private static int[] |
hexY_st
|
private int |
hilight
Edge or node being pointed to. |
private boolean |
hilightIsShip
If hilighting an edge, is the hilight a ship and not a road? |
static int |
HOVER_OFFSET_X_FOR_INIT_PLACE
During initial-piece placement, the tooltip is moved this far over to make room. |
static int |
HOVER_OFFSET_X_FOR_ROBBER
During robber placement, the tooltip is moved this far over to make room. |
private SOCBoardPanel.BoardToolTip |
hoverTip
(tooltip) Hover text for info on pieces/parts of the board. |
private static java.lang.String |
IMAGEDIR
Hex and port graphics are in this directory. |
private boolean[] |
inactiveHexNums
Hex numbers which aren't drawn, or null. |
private int |
initstlmt
This holds the coord of the last stlmt placed in the initial phase. |
protected boolean |
is6player
The board is configured for 6-player layout (and is isRotated );
set in constructor by checking SOCBoard.getBoardEncodingFormat()
<= SOCBoard.BOARD_ENCODING_6PLAYER and SOCGame.maxPlayers > 4. |
protected boolean |
isLargeBoard
The board is configured Large-Board Format (up to 127x127, oriented like 4-player not 6-player); set in constructor by checking SOCBoard.getBoardEncodingFormat() . |
protected boolean |
isRotated
The board is visually rotated 90 degrees clockwise (6-player: game opt PL > 4) compared to the internal coordinates. |
protected boolean |
isScaled
The board is currently scaled larger than panelMinBW x panelMinBH pixels. |
protected boolean |
isScaledOrRotated
Convenience flag - The board is rotated and/or scaled up . |
private java.awt.Dimension |
minSize
Minimum required width and height, as determined by options and isRotated . |
private int |
mode
Modes of interaction; for correlation to game state, see updateMode() . |
private static int |
MOVE_SHIP
Move a previously-placed ship on the large sea board. |
private int |
moveShip_fromEdge
During MOVE_SHIP mode, the edge coordinate
from which we're moving the ship. |
private boolean |
moveShip_isWarship
During MOVE_SHIP mode, true if the ship being moved
is a warship in scenario option _SC_PIRI . |
private int |
moveShip_toEdge
During MOVE_SHIP mode, the edge coordinate to which we're
moving the ship, 0 otherwise. |
private int[] |
nodeMap
Map grid sectors (from unscaled on-screen coordinates) to hex nodes. |
private static int |
NONE
BoardPanel's mode s. |
private SOCPlayer |
otherPlayer
When in "consider" mode, this is the player we're talking to |
protected int |
panelMarginX
Scaled (actual) panel margin on left, in pixels, for narrow boards, if board's unscaled width is less than panelMinBW . |
protected int |
panelMinBH
panelMinBW and panelMinBH are the minimum width and height, in board-internal coordinates (not rotated or scaled). |
protected int |
panelMinBW
panelMinBW and panelMinBH are the minimum width and height, in board-internal coordinates (not rotated or scaled). |
private static int |
PANELPAD_LBOARD_RT
When isLargeBoard , padding on right-hand side, in internal coordinates (like panelMinBW ). |
static int |
PANELX
size of the whole panel, internal-pixels "scale". |
static int |
PANELY
size of the whole panel, internal-pixels "scale". |
private static int |
PLACE_CITY
|
private static int |
PLACE_FREE_ROAD_OR_SHIP
Place a free road or ship on the large sea board. |
private static int |
PLACE_INIT_ROAD
Place an initial road or ship. |
private static int |
PLACE_INIT_SETTLEMENT
Place an initial settlement, or just hover at a port. |
private static int |
PLACE_PIRATE
Move the pirate ship. |
private static int |
PLACE_ROAD
Place a road, or place a free road when not isLargeBoard . |
private static int |
PLACE_ROBBER
Place the robber, or just hover at a hex. |
private static int |
PLACE_SETTLEMENT
|
private static int |
PLACE_SHIP
Place a ship on the large sea board. |
private SOCPlayer |
player
The player that is using this interface. |
private SOCPlayerInterface |
playerInterface
the player interface that this board is a part of |
private int |
playerNumber
player number of our player if in a game, or -1. |
protected static int |
POPUP_MENU_IGNORE_MS
for popup-menu build request, length of time after popup to ignore further mouse-clicks. |
private SOCBoardPanel.BoardPopupMenu |
popupMenu
Context menu for build/cancel-build |
private long |
popupMenuSystime
Tracks last menu-popup time. |
private static int[][] |
portArrowsX
For port hexes, the triangular arrowheads towards port settlement nodes: Array of shapes' X coordinates. |
private static int[][] |
portArrowsY
For port hexes, the triangular arrowheads towards port settlement nodes: Array of shapes' Y coordinates. |
private int |
ptrOldX
Previous pointer coordinates for interface; the mouse was at this location when hilight was last determined in mouseMoved(MouseEvent) . |
private int |
ptrOldY
Previous pointer coordinates for interface; the mouse was at this location when hilight was last determined in mouseMoved(MouseEvent) . |
private static int |
RESCALE_MAX_RETRY_MS
For repaint when retrying a failed rescale-image, the 7-second maximum time (in millis) after which no more retries will be done. |
private static int |
RESCALE_RETRY_DELAY_MS
For repaint when retrying a failed rescale-image, the 3-second delay (in millis) before which SOCBoardPanel.DelayedRepaint will call repaint(). |
protected java.awt.Color[] |
robberGhostFill
Cached colors, for use for robber's "ghost" (previous position) when moving the robber. |
protected java.awt.Color[] |
robberGhostOutline
Cached colors, for use for robber's "ghost" (previous position) when moving the robber. |
private static int[] |
robberX
robber polygon. |
private static int[] |
robberY
|
private static java.awt.Color[] |
ROTAT_HEX_BORDER_COLORS
Border colors for hex rendering when isRotated . |
private static java.awt.Image[] |
rotatHexes
Hex images - rotated board; from IMAGEDIR /rotat's GIF files. |
private static int[] |
ROW_START_HEXNUM
Hex numbers of start of each row of hexes in the board coordinates. |
private static int |
SC_FTRI_PLACE_PORT
In scenario option _SC_FTRI game state SOCGame.PLACING_INV_ITEM ,
boardpanel mode to place a port next to player's coastal settlement/city. |
private int[] |
scaledArrowXL
Current-player arrow, left-pointing and right-pointing. |
private int[] |
scaledArrowXR
Current-player arrow, left-pointing and right-pointing. |
private int[] |
scaledArrowY
Current-player arrow, left-pointing and right-pointing. |
protected long |
scaledAt
Time of last request to resize and repaint, as returned by System.currentTimeMillis() . |
private int[] |
scaledCityX
city |
private int[] |
scaledCityY
city |
private int[] |
scaledDownRoadX
road looks like "\" |
private int[] |
scaledDownRoadY
road looks like "\" |
private int[] |
scaledFortressX
fortress (scenario _SC_PIRI) |
private int[] |
scaledFortressY
fortress (scenario _SC_PIRI) |
private int[] |
scaledHexCornersX
hex corner coordinates, as scaled to current board size. |
private int[] |
scaledHexCornersY
hex corner coordinates, as scaled to current board size. |
private java.awt.Image[] |
scaledHexes
Hex images - private scaled copy, if isScaled . |
private boolean[] |
scaledHexFail
Hex/port images - Per-image flag to check if rescaling failed, if isScaled . |
protected boolean |
scaledMissedImage
Flag used while drawing a scaled board. |
protected int |
scaledPanelX
actual size on-screen, not internal-pixels size ( panelMinBW , panelMinBH ) |
protected int |
scaledPanelY
actual size on-screen, not internal-pixels size ( panelMinBW , panelMinBH ) |
private int[][] |
scaledPortArrowsX
For port hexes, the triangular arrowheads towards port settlement nodes. |
private int[][] |
scaledPortArrowsY
For port hexes, the triangular arrowheads towards port settlement nodes. |
private boolean[] |
scaledPortFail
Hex/port images - Per-image flag to check if rescaling failed, if isScaled . |
private java.awt.Image[] |
scaledPorts
Port images - private copy, rotated and/or scaled if necessary. |
private int[] |
scaledRobberX
robber |
private int[] |
scaledRobberY
robber |
private int[] |
scaledSettlementX
settlement |
private int[] |
scaledSettlementY
settlement |
private int[] |
scaledShipX
ship |
private int[] |
scaledShipY
ship |
private int[] |
scaledUpRoadX
road looks like "/" |
private int[] |
scaledUpRoadY
road looks like "/" |
private int[] |
scaledVertRoadX
Coordinate arrays for drawing the playing pieces. |
private int[] |
scaledVertRoadY
Coordinate arrays for drawing the playing pieces. |
private int[] |
scaledVillageX
village (scenario _SC_CLVI) |
private int[] |
scaledVillageY
village (scenario _SC_CLVI) |
private int[] |
scaledWarshipX
warship (scenario _SC_PIRI) |
private int[] |
scaledWarshipY
warship (scenario _SC_PIRI) |
private static int[] |
settlementX
settlement |
private static int[] |
settlementY
|
private static int[] |
shipX
Ship. |
private static int[] |
shipY
Ship. |
private static SOCStringManager |
strings
i18n text strings |
private int |
superText_des
Width, height of superText1 and superText2 if known, or 0. |
private int |
superText_h
Width, height of superText1 and superText2 if known, or 0. |
private static int |
SUPERTEXT_INSET
Pixel spacing around superText1 , superText2 , superTextTop |
private static int |
SUPERTEXT_PADDING_HORIZ
Pixel spacing around superText1 , superText2 , superTextTop |
private java.lang.String |
superText1
Text to be displayed as 2 lines superimposed over center of the board graphic (during game setup). |
private int |
superText1_w
Width, height of superText1 and superText2 if known, or 0. |
private java.lang.String |
superText2
Text to be displayed as 2 lines superimposed over center of the board graphic (during game setup). |
private int |
superText2_w
Width, height of superText1 and superText2 if known, or 0. |
private int |
superTextBox_h
Width, height of superText1 and superText2 if known, or 0. |
private int |
superTextBox_w
Width, height of superText1 and superText2 if known, or 0. |
private int |
superTextBox_x
Width, height of superText1 and superText2 if known, or 0. |
private int |
superTextBox_y
Width, height of superText1 and superText2 if known, or 0. |
private java.lang.String |
superTextTop
Text to be displayed as 1 line superimposed over the top-center of the board graphic (during game play). |
private int |
superTextTop_h
Width, height of superTextTop if known, or 0. |
private int |
superTextTop_w
Width, height of superTextTop if known, or 0. |
private int |
superTextTopBox_h
Width, height of superTextTop if known, or 0. |
private int |
superTextTopBox_w
Width, height of superTextTop if known, or 0. |
private int |
superTextTopBox_x
Width, height of superTextTop if known, or 0. |
private static int |
TURN_STARTING
|
private static int[] |
upRoadX
road looks like "/" along upper-left edge of hex |
private static int[] |
upRoadY
|
private static int[] |
vertRoadX
road looks like "|" along left edge of hex |
private static int[] |
vertRoadY
|
private static int[] |
villageX
village polygon. |
private static int[] |
villageY
village polygon. |
private static int[] |
warshipX
Warship for scenario SC_PIRI. |
private static int[] |
warshipY
Warship for scenario SC_PIRI. |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
SOCBoardPanel(SOCPlayerInterface pi)
create a new board panel in a game interface. |
Method Summary | |
---|---|
protected void |
clearModeAndHilight(int ptype)
Set board mode to NONE , no hilight, usually from a piece-placement mode. |
protected void |
doBoardMenuPopup(int x,
int y)
Bring up the popup menu; called from mousePressed. |
private void |
drawArrow(java.awt.Graphics g,
int pnum,
int diceResult)
draw the arrow that shows whose turn it is. |
private void |
drawBoard_SC_FTRI_placePort(java.awt.Graphics g)
Scenario game option _SC_FTRI : In board mode SC_FTRI_PLACE_PORT ,
draw the possible coastal edges where the port can be placed, and if the hilight cursor is at
such an edge, draw the port semi-transparently and a solid hilight line at the edge. |
private void |
drawBoard(java.awt.Graphics g)
Draw the whole board, including pieces and tooltip ( hilight , hoverTip ) if applicable. |
private void |
drawBoardEmpty_drawDebugShowPotentialRoad(java.awt.Graphics g,
int x,
int y,
int r,
int c,
boolean isVert,
java.awt.Color co,
int offset)
Draw around one potential/legal road edge, for drawBoardEmpty_drawDebugShowPotentials(Graphics) . |
private void |
drawBoardEmpty_drawDebugShowPotentials(java.awt.Graphics g)
If any bit in debugShowPotentials [] is set, besides 8,
draw it on the board. |
private void |
drawBoardEmpty_drawPiratePath(java.awt.Graphics g,
int[] ppath)
For the _SC_PIRI game scenario on SOCBoardLarge ,
draw the path that the pirate fleet takes around the board. |
private void |
drawBoardEmpty_specialEdges(java.awt.Graphics g)
For the _SC_FTRI game scenario on SOCBoardLarge ,
draw markers at all Special Edges for the players to reach and be rewarded. |
private void |
drawBoardEmpty_specialNodes(java.awt.Graphics g,
java.lang.String partKey,
java.awt.Color color)
For a game scenario on SOCBoardLarge , draw markers at a set of Special Nodes for the players
to reach and be rewarded, retrieved with SOCBoardLarge.getAddedLayoutPart(String) . |
private void |
drawBoardEmpty(java.awt.Graphics g)
Draw the whole board (water, hexes, ports, numbers) but no placed pieces. |
private void |
drawCity(java.awt.Graphics g,
int nodeNum,
int pn,
boolean isHilight)
draw a city |
private void |
drawFortress(java.awt.Graphics g,
SOCFortress fo,
int pn,
boolean isHilight)
Draw a pirate fortress, for scenario SC_PIRI. |
private void |
drawHex(java.awt.Graphics g,
int hexNum)
Draw a board tile by its hex number (v1 or v2 board encoding). |
private void |
drawHex(java.awt.Graphics g,
int x,
int y,
int hexType,
int portFacing,
int hexNum)
Draw a land, water, or port hex tile at a given location. |
private void |
drawMarker(java.awt.Graphics g,
int x,
int y,
java.awt.Color color,
int val)
Draw a marker (village symbol) centered at a final (x,y) coordinate. |
private void |
drawPorts_LargeBoard(java.awt.Graphics g)
Draw the ports for the large board . |
private void |
drawPortsRing(java.awt.Graphics g)
for the 6-player board (if is6player ), draw the ring of surrounding water/ports. |
private void |
drawRoadOrShip(java.awt.Graphics g,
int edgeNum,
int pn,
boolean isHilight,
boolean isRoadNotShip,
boolean isWarship)
draw a road or ship along an edge. |
private void |
drawRobber(java.awt.Graphics g,
int hexID,
boolean fullNotGhost,
boolean fillNotOutline)
Draw the robber. |
private void |
drawSeaEdgeLine(java.awt.Graphics g,
int edge)
For drawing the player's permitted sea edges for ships, draw a line covering the middle 60% of this edge on the board (leaves out 20% on each end). |
private void |
drawSeaEdgeLines(java.awt.Graphics g,
java.awt.Color co,
java.util.Collection<java.lang.Integer> lse)
Draw a dotted line with some thickness at each of these sea edge coordinates. |
private void |
drawSettlement(java.awt.Graphics g,
int nodeNum,
int pn,
boolean isHilight,
boolean outlineOnly)
draw a settlement |
private void |
drawSettlementOrCity(java.awt.Graphics g,
int nodeNum,
int pn,
boolean isHilight,
boolean outlineOnly,
boolean isCity)
draw a settlement or city; they have the same logic for determining (x,y) from nodeNum. |
private void |
drawSuperText(java.awt.Graphics g)
Draw superText1 , superText2 ; if necessary, calculate superText1_w and other fields. |
private void |
drawSuperTextTop(java.awt.Graphics g)
Draw superTextTop ; if necessary, calculate superTextTop_w and other fields. |
private void |
drawVillage(java.awt.Graphics g,
SOCVillage v)
Draw a cloth trade village (used in some scenarios in the large sea board). |
private int |
findEdge(int x,
int y,
boolean checkCoastal)
given a pixel on the board, find the edge that contains it |
private int |
findHex(int x,
int y)
given a pixel on the board, find the hex that contains it |
private int |
findNode(int x,
int y)
given a pixel on the board, find the node that contains it |
void |
flushBoardLayoutAndRepaint()
Clear the board layout (as rendered in the empty-board buffer) and trigger a repaint. |
void |
flushBoardLayoutAndRepaintIfDebugShowPotentials()
Clear the board layout (as rendered in the empty-board buffer) and trigger a repaint, only if we're showing potential/legal settlements/roads/cities for debug purposes. |
java.awt.Dimension |
getMinimumSize()
Minimum required width and height, as determined by options and isRotated() . |
(package private) int |
getPlayerNumber()
Get our player number. |
java.awt.Dimension |
getPreferredSize()
DOCUMENT ME! |
static java.awt.image.BufferedImage |
getScaledImageUp(java.awt.Image src,
int w,
int h)
Scale up an image with decent quality. |
java.awt.Color |
hexColor(int hexType)
Hex color for a hex resource type |
private void |
initCoordMappings()
During the constructor, initialize the board-coordinate to screen-coordinate mappings: edgeMap , nodeMap , hexMap ,
hexIDtoNum , hexX , hexY ,
inactiveHexNums . |
private void |
initEdgeMapAux(int x1,
int y1,
int x2,
int y2,
int startHex)
Initialize edgeMap 's valid edges across 1 row of hexes,
for use by findEdge(int, int, boolean) . |
private void |
initHexIDtoNumAux(int begin,
int end,
int num)
|
private void |
initHexMapAux(int x1,
int y1,
int x2,
int y2,
int startHex)
|
private void |
initNodeMapAux(int x1,
int y1,
int x2,
int y2,
int startHex)
Within nodeMap , set the node coordinates within a rectangular section
from (x1,y1) to (x2,y2) covering all nodes of one horizontal row of hexes. |
boolean |
isRotated()
Is the board currently rotated 90 degrees clockwise? If so, the minimum size swaps PANELX and PANELY . |
boolean |
isScaled()
Is the board currently scaled larger than PANELX x PANELY pixels?
If so, use scaleToActualX(int) , scaleFromActualY(int) ,
etc to convert between internal and actual screen pixel coordinates. |
private static void |
loadHexesAndImages(java.awt.Image[] newHexes,
java.lang.String imageDir,
java.awt.MediaTracker tracker,
java.awt.Toolkit tk,
java.lang.Class<?> clazz,
boolean wantsRotated)
Load hex and other related images from either normal, or rotated, resource location. |
private static void |
loadImages(java.awt.Component c,
boolean wantsRotated)
Load the images for the board: hexes , rotatHexes , and dice . |
void |
mouseClicked(java.awt.event.MouseEvent evt)
DOCUMENT ME! |
void |
mouseDragged(java.awt.event.MouseEvent e)
DOCUMENT ME! |
void |
mouseEntered(java.awt.event.MouseEvent e)
Handle Events |
void |
mouseExited(java.awt.event.MouseEvent e)
Mouse has left the panel; hide tooltip and any hovering piece. |
void |
mouseMoved(java.awt.event.MouseEvent e)
Based on the board's current mode , update the hovering 'hilight' piece (hilight }. |
void |
mousePressed(java.awt.event.MouseEvent e)
DOCUMENT ME! |
void |
mouseReleased(java.awt.event.MouseEvent e)
DOCUMENT ME! |
private int[] |
nodeToXY(int nodeNum)
Calculate the on-screen coordinates of a node. |
void |
paint(java.awt.Graphics g)
Redraw the board using double buffering. |
void |
pieceValueUpdated(SOCPlayingPiece piece)
A playing piece's value was updated: _SC_CLVI village cloth count, or
_SC_PIRI pirate fortress strength. |
void |
popupClearBuildRequest()
player decided to not build something, so cancel the TimerTask
that's waiting to tell the server what they wanted to build. |
boolean |
popupExpectingBuildRequest()
If the client has used the board popup menu to request building a piece, this method is used in client network-receive message treatment. |
void |
popupFireBuildingRequest()
Have received gamestate placing message; send the building request in reply. |
void |
popupSetBuildRequest(int coord,
int ptype)
|
private java.awt.Image |
renderBorderedHex(java.awt.Image hex,
java.awt.Image hexBorder,
java.awt.Color borderColor)
Render a border around the edge of this hex, returning a new image. |
private void |
renderPortImages()
Based on the waterHex image, render the 6 port images (1 per "facing" rotation), each with arrows in its 2 settlement directions. |
private void |
rescaleBoard(int newW,
int newH)
Set the board fields to a new size, rescale graphics if needed. |
private void |
rescaleCoordinateArrays()
Scale coordinate arrays for drawing pieces (from internal coordinates to actual on-screen pixels), or (if not isScaled) point to static arrays. |
int[] |
rotateScaleCopyYToActualX(int[] yorig,
int width,
boolean rescale)
Copy and rotate this array of y-coordinates, optionally also rescaling. |
int[] |
scaleCopyToActualX(int[] xorig)
Rescale to actual screen coordinates - Create a copy of array, and scale the copy's elements as X coordinates. |
int[] |
scaleCopyToActualY(int[] yorig)
Rescale to actual screen coordinates - Create a copy of array, and scale the copy's elements as Y coordinates. |
int |
scaleFromActualX(int x)
Convert an x-coordinate from actual-scaled to internal-scaled coordinates. |
int |
scaleFromActualY(int y)
Convert a y-coordinate from actual-scaled to internal-scaled coordinates. |
int |
scaleToActualX(int x)
Scale x-coordinate from internal to actual screen-pixel coordinates. |
void |
scaleToActualX(int[] xa)
Scale x-array from internal to actual screen-pixel coordinates. |
int |
scaleToActualY(int y)
Scale y-coordinate from internal to actual screen-pixel coordinates. |
void |
scaleToActualY(int[] ya)
Scale y-array from internal to actual screen-pixel coordinates. |
void |
setBounds(int x,
int y,
int w,
int h)
Set the board to a new location and size, rescale graphics and repaint if needed. |
(package private) void |
setDebugShowCoordsFlag(boolean setOn)
Set or clear the debug flag where the board item tooltip includes the item's coordinates. |
(package private) void |
setDebugShowPotentialsFlag(int pieceType,
boolean setPotential,
boolean setOn)
Set or clear a debug flag to show player 0's potential/legal coordinate sets. |
void |
setMode(int m)
Set the interaction mode, for debugging purposes. |
void |
setModeMoveShip(int edge)
Set the interaction mode to "move ship"; the player must now click where they want the ship to be moved. |
void |
setOtherPlayer(SOCPlayer op)
set the other player |
void |
setPlayer()
set the player that is using this board panel to be the client's player in this game. |
(package private) void |
setPlayer(SOCPlayer pl)
Temporarily change the player that is using this board panel. |
void |
setSize(java.awt.Dimension sz)
Set the board to a new size, rescale graphics and repaint if needed. |
void |
setSize(int newW,
int newH)
Set the board to a new size, rescale graphics and repaint if needed. |
void |
setSuperimposedText(java.lang.String text1,
java.lang.String text2)
Text to be displayed as 2 lines superimposed over the center of the board graphic (during game setup). |
void |
setSuperimposedTopText(java.lang.String text)
Text to be displayed as 1 lines superimposed over the top center of the board graphic (during game play). |
private void |
tryMoveShipToEdge()
Check and move ship from moveShip_fromEdge to moveShip_toEdge . |
void |
update(java.awt.Graphics g)
Overriden so the peer isn't painted, which clears background. |
protected void |
updateHoverTipToMode()
Update hoverTip based on mode when it changes;
called from updateMode() . |
void |
updateMode()
update the type of interaction mode, and trigger a repaint. |
Methods inherited from class java.awt.Canvas |
---|
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final SOCStringManager strings
private static java.lang.String IMAGEDIR
hexes
, rotatHexes
,
scaledHexes
, and scaledPorts
arrays.
public static final int PANELX
panelMinBW
and panelMinBH
instead.
For minimum acceptable size in on-screen pixels,
call getMinimumSize()
instead of using PANELX and PANELY directly.
For actual current size in screen pixels, see
scaledPanelX
scaledPanelY
;
If isRotated()
, the minimum size swaps PANELX
and PANELY
.
If 6-player board or Large/Sea Board, the minimum size is larger.
Left/top margins for isLargeBoard
: 0 for x, halfdeltaY
for y.
public static final int PANELY
panelMinBW
and panelMinBH
instead.
For minimum acceptable size in on-screen pixels,
call getMinimumSize()
instead of using PANELX and PANELY directly.
For actual current size in screen pixels, see
scaledPanelX
scaledPanelY
;
If isRotated()
, the minimum size swaps PANELX
and PANELY
.
If 6-player board or Large/Sea Board, the minimum size is larger.
Left/top margins for isLargeBoard
: 0 for x, halfdeltaY
for y.
private static final int BOARDWIDTH_VISUAL_MIN
isLargeBoard
,
Minimum visual SOCBoard.getBoardWidth()
= 18 for good-looking aspect ratio, and
enough width for SOCBuildingPanel
contents below.
private static final int BOARDHEIGHT_VISUAL_MIN
isLargeBoard
,
Minimum visual SOCBoard.getBoardHeight()
= 17 for
enough height for SOCHandPanel
s to left and right.
private static final int PANELPAD_LBOARD_RT
isLargeBoard
, padding on right-hand side, in internal coordinates (like panelMinBW
).
private static final int deltaY
private static final int deltaX
private static final int halfdeltaX
deltaX
,
halfdeltaY
,
Constant Field Valuesprivate static final int halfdeltaY
isLargeBoard
.
deltaY
,
halfdeltaX
,
HALF_HEXHEIGHT
,
Constant Field Valuesprivate static final int[] DELTAX_FACING
SOCBoard.FACING_E
etc.
DELTAY_FACING
private static final int[] DELTAY_FACING
DELTAX_FACING
private static final int[] hexX_st
hexX_6pl
private static final int[] hexY_st
private static int[] hexX_6pl
hexX_st
is HEXX_OFF_6PL
,
and the offset from hexY_st
is HEXY_OFF_6PL
.
hexX
private static int[] hexY_6pl
hexX_st
is HEXX_OFF_6PL
,
and the offset from hexY_st
is HEXY_OFF_6PL
.
hexX
private static final int HEXX_OFF_6PL
hexX_6pl
, hexY_6pl
from hexX_st
, hexY_st
in unscaled board coordinates.
Remember that x and y are swapped on-screen, because the board is rotated.
private static final int HEXY_OFF_6PL
hexX_6pl
, hexY_6pl
from hexX_st
, hexY_st
in unscaled board coordinates.
Remember that x and y are swapped on-screen, because the board is rotated.
private static final int HEXY_OFF_6PL_FIND
HEXY_OFF_6PL
in findEdge(int, int, boolean)
, findHex(int, int)
, findNode(int, int)
.
private static final int HEXY_OFF_SLOPE_HEIGHT
hexCornersY
,
Constant Field Valuesprivate static final int HEX_PORT_CIRCLE_DIA
renderPortImages()
.
The border drawn around the clear circle is also based on this.
portArrowsX
,
Constant Field Valuesprivate static final int[] vertRoadX
private static final int[] vertRoadY
private static final int[] upRoadX
private static final int[] upRoadY
private static final int[] downRoadX
private static final int[] downRoadY
private static final int[] settlementX
private static final int[] settlementY
private static final int[] cityX
private static final int[] cityY
private static final int[] shipX
HALF_HEXHEIGHT
).
warshipX
private static final int[] shipY
HALF_HEXHEIGHT
).
warshipX
private static final int[] warshipX
HALF_HEXHEIGHT
).
Design is based on the normal ship (shipX
, shipY
)
with a second sail and a taller hull.
private static final int[] warshipY
HALF_HEXHEIGHT
).
Design is based on the normal ship (shipX
, shipY
)
with a second sail and a taller hull.
private static final int[] fortressX
private static final int[] fortressY
private static final int[] villageX
drawVillage(Graphics, SOCVillage)
, and as a
generic marker in drawMarker(Graphics, int, int, Color, int)
.
private static final int[] villageY
drawVillage(Graphics, SOCVillage)
, and as a
generic marker in drawMarker(Graphics, int, int, Color, int)
.
private static final int[] robberX
private static final int[] robberY
private static final int[][] portArrowsX
portArrowsY
.
First index is the shape number, second index is coordinates within the shape, clockwise from tip.
Shape numbers are 0-5, for the 6 facing directions numbered the same way as
SOCBoard#getAdjacentNodeToHex(int)
: clockwise from top (northern point of hex),
0 is north, 1 is northeast, etc, 5 is northwest.
HEX_PORT_CIRCLE_DIA
private static final int[][] portArrowsY
portArrowsX
.
private static final int[] arrowXL
rescaleCoordinateArrays()
)
arrowY
,
ARROW_SZ
private static int[] arrowXR
arrowXL
in rescaleCoordinateArrays()
.
private static final int[] arrowY
private static final int ARROW_SZ
arrowXL
,
Constant Field Valuesprivate static final java.awt.Color ARROW_COLOR
ARROW_COLOR_PLACING
private static final java.awt.Color ARROW_COLOR_PLACING
SOCGame.SPECIAL_BUILDING
phase of the 6-player game.
The game-over color was added in 1.1.09. Previously, ARROW_COLOR
was used.
private static final java.awt.Color[] HEX_BORDER_COLORS
hexes
.
Used in rescaleBoard(int, int)
with mask hexBorder.gif
.
ROTAT_HEX_BORDER_COLORS
private static final java.awt.Color[] ROTAT_HEX_BORDER_COLORS
isRotated
.
Same indexes as rotatHexes
.
Used in rescaleBoard(int, int)
with mask hexBorder.gif
.
HEX_BORDER_COLORS
private static final int RESCALE_RETRY_DELAY_MS
SOCBoardPanel.DelayedRepaint
will call repaint().
This constant was introduced in v1.1.20, previously the value was hardcoded.
scaledMissedImage
,
RESCALE_MAX_RETRY_MS
,
Constant Field Valuesprivate static final int RESCALE_MAX_RETRY_MS
This constant was introduced in v1.1.20, previously the value was hardcoded.
scaledMissedImage
,
RESCALE_RETRY_DELAY_MS
,
Constant Field Valuesprivate static final int NONE
mode
s. NONE is normal gameplay, or not the client's turn.
For correlation to game state, see updateMode()
.
If a mode is added, please also update clearModeAndHilight(int)
.
If a piece or item hovers in this mode with the mouse cursor, update
SOCBoardPanel.BoardToolTip.handleHover(int, int)
.
If the player clicks to place or interact in the new mode, update mouseClicked(MouseEvent)
.
See hilight
and SOCBoardPanel.BoardToolTip
.
private static final int PLACE_ROAD
isLargeBoard
.
PLACE_FREE_ROAD_OR_SHIP
,
Constant Field Valuesprivate static final int PLACE_SETTLEMENT
private static final int PLACE_CITY
private static final int PLACE_ROBBER
PLACE_PIRATE
,
Constant Field Valuesprivate static final int PLACE_INIT_SETTLEMENT
SOCBoardPanel.BoardToolTip.hoverIsPort
,
Constant Field Valuesprivate static final int PLACE_INIT_ROAD
public static final int CONSIDER_LM_SETTLEMENT
public static final int CONSIDER_LM_ROAD
public static final int CONSIDER_LM_CITY
public static final int CONSIDER_LT_SETTLEMENT
public static final int CONSIDER_LT_ROAD
public static final int CONSIDER_LT_CITY
private static final int PLACE_SHIP
private static final int PLACE_FREE_ROAD_OR_SHIP
isLargeBoard
, use PLACE_ROAD
instead.
private static final int MOVE_SHIP
moveShip_fromEdge
and moveShip_isWarship
.
private static final int PLACE_PIRATE
PLACE_ROBBER
,
Constant Field Valuesprivate static final int SC_FTRI_PLACE_PORT
_SC_FTRI
game state SOCGame.PLACING_INV_ITEM
,
boardpanel mode to place a port next to player's coastal settlement/city.
private static final int TURN_STARTING
private static final int GAME_FORMING
private static final int GAME_OVER
public static final int HOVER_OFFSET_X_FOR_INIT_PLACE
public static final int HOVER_OFFSET_X_FOR_ROBBER
protected static int BUILD_REQUEST_MAX_DELAY_SEC
protected static int POPUP_MENU_IGNORE_MS
private static final int SUPERTEXT_INSET
superText1
, superText2
, superTextTop
private static final int SUPERTEXT_PADDING_HORIZ
superText1
, superText2
, superTextTop
private static final int HEXWIDTH
downRoadX
, etc)
are plotted against a hex of this size.
deltaX
,
deltaY
,
HALF_HEXHEIGHT
,
Constant Field Valuesprivate static final int HEXHEIGHT
downRoadX
, etc)
are plotted against a hex of this size.
deltaX
,
deltaY
,
HALF_HEXHEIGHT
,
Constant Field Valuesprivate static final int HALF_HEXHEIGHT
HEXHEIGHT
, in unscaled internal pixels, for use with various board graphics.
Also == halfdeltaY
+ 9.
private static final int DICE_NUMBER_CIRCLE_DIAMETER
private static final int DICE_NUMBER_FONTPOINTS
private static final java.awt.Color[] DICE_NUMBER_CIRCLE_COLORS
Index: Dice: Color: 0 2, 12 yellow 1 3, 11 2 4, 10 orange 3 5, 9 4 6, 8 red
private java.awt.Dimension minSize
isRotated
.
Set in constructor based on PANELX
, PANELY
.
Used by getMinimumSize()
.
panelMinBW
private boolean hasCalledSetSize
protected boolean is6player
isRotated
);
set in constructor by checking SOCBoard.getBoardEncodingFormat()
<= SOCBoard.BOARD_ENCODING_6PLAYER
and SOCGame.maxPlayers
> 4.
The entire coordinate system is land, except the rightmost hexes are unused
(7D-DD-D7 row).
The 6-player mode uses hexX_6pl
instead of hexX_st
for coordinates.
When isLargeBoard
, this field is false even if the game has 5 or 6 players.
The is6player flag is about the hex layout on the board, not the number of players.
inactiveHexNums
,
isLargeBoard
protected final boolean isLargeBoard
SOCBoard.getBoardEncodingFormat()
.
The coordinate system is an arbitrary land/water mixture.
When isLargeBoard, isRotated()
is false even if the game has 5 or 6 players.
is6player
protected boolean isRotated
Use this for rotation:
panelMinBH
-y, x)
panelMinBW
-x)
scaled
, go in this order:
Rotate clockwise, then scale up; Scale down, then rotate counterclockwise.
When calculating position at which to draw an image or polygon,
remember that rotation changes which corner is considered (0,0),
and the image is offset from that corner. (For example, drawHex(Graphics, int)
subtracts HEXHEIGHT from x, after rotation but before scaling.)
When isLargeBoard
, isRotated is false even if the game has 5 or 6 players.
isScaledOrRotated
protected boolean isScaledOrRotated
rotated
and/or scaled up
.
Check both of those flags when transforming between screen coordinates
and internal coordinates. Go in this order:
Rotate clockwise, then scale up; Scale down, then rotate counterclockwise.
protected int scaledPanelX
panelMinBW
, panelMinBH
)
protected int scaledPanelY
panelMinBW
, panelMinBH
)
protected final int panelMinBW
PANELX
, PANELY
for 6-player board
and the large board
.
Differs from minSize
because minSize takes isRotated
into account,
so minSize isn't suitable for use in rescaling formulas.
protected final int panelMinBH
PANELX
, PANELY
for 6-player board
and the large board
.
Differs from minSize
because minSize takes isRotated
into account,
so minSize isn't suitable for use in rescaling formulas.
protected int panelMarginX
panelMinBW
.
Used only when isLargeBoard
and not isRotated
, otherwise 0.
Never less than 0.
protected boolean isScaled
panelMinBW
x panelMinBH
pixels.
Use scaleToActualX(int)
, scaleFromActualX(int)
,
etc to convert between internal and actual screen pixel coordinates.
When the board is also rotated
, go in this order:
Rotate clockwise, then scale up; Scale down, then rotate counterclockwise.
When this flag is set true, also sets scaledAt
.
isScaledOrRotated
,
scaledAt
,
rescaleBoard(int, int)
protected long scaledAt
System.currentTimeMillis()
.
Used with scaledMissedImage
.
drawnEmptyAt
protected boolean scaledMissedImage
drawHex(Graphics, int)
, checked in drawBoard(Graphics)
.
scaledHexFail
,
scaledAt
,
drawnEmptyAt
private long drawnEmptyAt
System.currentTimeMillis()
.
Used in drawBoardEmpty(Graphics)
with scaledMissedImage
.
scaledAt
private boolean debugShowCoordsTooltip
setDebugShowCoordsFlag(boolean)
, from
SOCPlayerInterface debug command =*= showcoords
or =*= hidecoords
.
SOCBoardPanel.BoardToolTip.setHoverText(String, int)
boolean[] debugShowPotentials
drawBoardEmpty(Graphics)
.
Currently implemented only for the sea board layout (SOCBoardLarge
).
Stored in same order as piece types:
Changed via setDebugShowPotentialsFlag(int, boolean, boolean)
with
SOCPlayerInterface debug command =*= show: n
or =*= hide: n
,
where n
is an index shown above or all
.
Has package-level visibility, for use by SOCPlayerInterface.updateAtPutPiece(int, int, int, boolean, int)
.
private java.awt.Font diceNumberCircleFont
private java.awt.FontMetrics diceNumberCircleFM
diceNumberCircleFont
.
Used in hex and village dice numbers.
private int[] hexIDtoNum
isLargeBoard
.
private boolean[] inactiveHexNums
6-player board
,
the rightmost line of hexes (7D-DD-D7) are skipped.
Indicate this to drawBoard(Graphics)
.
private int[] hexX
hexX_st
or hexX_6pl
,
and hexY_st
or hexY_6pl
,
depending on is6player
flag.
Null when isLargeBoard
, because of its simpler
coordinate encoding. In that case, calculate (x,y) with:
private int[] hexY
hexX_st
or hexX_6pl
,
and hexY_st
or hexY_6pl
,
depending on is6player
flag.
Null when isLargeBoard
, because of its simpler
coordinate encoding. In that case, calculate (x,y) with:
private static java.awt.Image[] hexes
IMAGEDIR
's GIF files.
Image references are copied to scaledHexes
from here.
Also contains hexBorder.gif
, and miscPort.gif
for drawing 3:1 ports' base image.
For indexes, see loadHexesAndImages(Image[], String, MediaTracker, Toolkit, Class, boolean)
.
scaledPorts
stores the 6 per-facing port overlays from renderPortImages()
.
scaledHexes
,
rotatHexes
private static java.awt.Image[] rotatHexes
IMAGEDIR
/rotat's GIF files.
Images from here are copied and/or scaled to scaledHexes
/scaledPorts
.
hexes
private java.awt.Image[] scaledHexes
isScaled
. Otherwise points to static copies,
either hexes
or rotatHexes
scaledHexFail
private java.awt.Image[] scaledPorts
renderPortImages()
.
miscPort.gif
is in hexes
along with the land hex images used for 2:1 ports.
scaledPortFail
private boolean[] scaledHexFail
isScaled
.
scaledHexes
,
drawHex(Graphics, int)
private boolean[] scaledPortFail
isScaled
.
scaledHexes
,
drawHex(Graphics, int)
private static java.awt.Image[] dice
Graphics.drawString
).
DICE_SZ
private static final int DICE_SZ
dice
,
Constant Field Valuesprivate int[] scaledVertRoadX
private int[] scaledVertRoadY
private int[] scaledUpRoadX
private int[] scaledUpRoadY
private int[] scaledDownRoadX
private int[] scaledDownRoadY
private int[] scaledSettlementX
private int[] scaledSettlementY
private int[] scaledCityX
private int[] scaledCityY
private int[] scaledShipX
private int[] scaledShipY
private int[] scaledFortressX
private int[] scaledFortressY
private int[] scaledVillageX
private int[] scaledVillageY
private int[] scaledWarshipX
private int[] scaledWarshipY
private int[] scaledRobberX
private int[] scaledRobberY
private int[][] scaledPortArrowsX
portArrowsX
,
rescaleCoordinateArrays()
private int[][] scaledPortArrowsY
portArrowsX
,
rescaleCoordinateArrays()
private int[] scaledArrowXL
rescaleCoordinateArrays()
private int[] scaledArrowXR
rescaleCoordinateArrays()
private int[] scaledArrowY
rescaleCoordinateArrays()
private static final int[] hexCornersX
hexCornersY_RotatedOffset
[].
hexCornersY
private static final int[] hexCornersY
hexCornersX
,
hexCornersY_RotatedOffset
,
HEXY_OFF_SLOPE_HEIGHT
private static final int[] hexCornersY_RotatedOffset
hexCornersY
[] coordinates when used as (y,x) on rotated board.
private int[] scaledHexCornersX
hexCornersX
,
rescaleCoordinateArrays()
private int[] scaledHexCornersY
hexCornersX
,
rescaleCoordinateArrays()
private int ptrOldX
hilight
was last determined in mouseMoved(MouseEvent)
.
private int ptrOldY
hilight
was last determined in mouseMoved(MouseEvent)
.
private SOCBoardPanel.BoardToolTip hoverTip
hilight
private SOCBoardPanel.BoardPopupMenu popupMenu
private long popupMenuSystime
protected SOCBoardPanel.BoardPanelSendBuildTask buildReqTimerTask
SOCBoardPanel.popupExpectingBuildRequest SOCPlayerInterface.updateAtGameState SOCBoardPanel.popupFireBuildingRequest
private java.lang.String superText1
setSuperimposedText(String, String)
private java.lang.String superText2
setSuperimposedText(String, String)
private int superText1_w
superText1
and superText2
if known, or 0.
Calculated in drawSuperText(Graphics)
.
private int superText_h
superText1
and superText2
if known, or 0.
Calculated in drawSuperText(Graphics)
.
private int superText_des
superText1
and superText2
if known, or 0.
Calculated in drawSuperText(Graphics)
.
private int superText2_w
superText1
and superText2
if known, or 0.
Calculated in drawSuperText(Graphics)
.
private int superTextBox_x
superText1
and superText2
if known, or 0.
Calculated in drawSuperText(Graphics)
.
private int superTextBox_y
superText1
and superText2
if known, or 0.
Calculated in drawSuperText(Graphics)
.
private int superTextBox_w
superText1
and superText2
if known, or 0.
Calculated in drawSuperText(Graphics)
.
private int superTextBox_h
superText1
and superText2
if known, or 0.
Calculated in drawSuperText(Graphics)
.
private java.lang.String superTextTop
setSuperimposedTopText(String)
private int superTextTop_w
superTextTop
if known, or 0.
Calculated in drawSuperTextTop(Graphics)
.
Y-position of top of this textbox is SUPERTEXT_INSET
.
private int superTextTop_h
superTextTop
if known, or 0.
Calculated in drawSuperTextTop(Graphics)
.
Y-position of top of this textbox is SUPERTEXT_INSET
.
private int superTextTopBox_x
superTextTop
if known, or 0.
Calculated in drawSuperTextTop(Graphics)
.
Y-position of top of this textbox is SUPERTEXT_INSET
.
private int superTextTopBox_w
superTextTop
if known, or 0.
Calculated in drawSuperTextTop(Graphics)
.
Y-position of top of this textbox is SUPERTEXT_INSET
.
private int superTextTopBox_h
superTextTop
if known, or 0.
Calculated in drawSuperTextTop(Graphics)
.
Y-position of top of this textbox is SUPERTEXT_INSET
.
private int hilight
During PLACE_INIT_ROAD
, this can be either a road or a ship.
Along coastal edges it could be either one.
Default to road:
Check player
.isPotentialRoad(hilight)
first, then .isPotentialShip
.
Player can right-click to build an initial ship along a coastal edge.
Hilight is drawn in drawBoard(Graphics)
. Value updated in mouseMoved(MouseEvent)
.
Cleared in clearModeAndHilight(int)
.
hoverTip
private boolean hilightIsShip
hilight
a ship and not a road?
private int moveShip_fromEdge
MOVE_SHIP
mode, the edge coordinate
from which we're moving the ship. 0 otherwise.
The hovering "move-to" location under the mouse pointer is hilight
and then (at left-click to select destination, or right-click to show the menu)
is moveShip_toEdge
.
moveShip_isWarship
private int moveShip_toEdge
MOVE_SHIP
mode, the edge coordinate to which we're
moving the ship, 0 otherwise. While choosing a location to move to,
the hovering ship under the mouse pointer is hilight
, but
when the menu appears (on Windows at least) hilight becomes 0.
tryMoveShipToEdge()
,
moveShip_fromEdge
private boolean moveShip_isWarship
MOVE_SHIP
mode, true if the ship being moved
is a warship in scenario option _SC_PIRI
.
moveShip_fromEdge
private int[] edgeMap
The edge coordinate number at grid (x,y) is in edgeMap[x + (y * 15)]. If edgeMap[x,y] == 0, it's not a valid edge coordinate.
On the 4-player board, row 0 is the top of the topmost row of water hexes. Here are the grid (x,y) values for the edges of the top-left land hex on the 4-player board, and to the right and down; its top is in y=3 of this grid:
^ ^ (4,3) (5,3) (6,3) (7,3) | | (4,4) (6,4) (4,5) (6,5) | | (3,6) (4,6) (5,6) (6,6) (7,6) v v | | (5,7) (7,7) (5,8) (7,8)
The 6-player board is similar to the 4-player layout, but its top-left land hex edges start at (3,0) instead of (4,3), and it is visually rotated 90 degrees on screen, but not rotated in this coordinate system, versus the 4-player board.
Note: For the 6-player board, edge 0x00 is a valid edge that can be built on. It is marked here as -1, since a value of 0 marks an invalid edge in this map.
In 6-player mode
, there is an extra ring of water/port hexes
on the outside, which isn't within the coordinate system. So this grid is
shifted +1 column, +3 rows.
Not used when isLargeBoard
.
findEdge(int, int, boolean)
,
initEdgeMapAux(int, int, int, int, int)
private int[] nodeMap
The node number at grid (x,y) is nodeMap[x + (y * 15)].
In 6-player mode
, there is an extra ring of water/port hexes
on the outside, which isn't within the coordinate system. So this grid appears
shifted +1 column, +3 rows on screen, to account for the outside ring.
In 4-player mode, here are the nodeMap coordinates (x,y) for the left end of the topmost row of water hexes:
(4,0) (6,0) / \ / \ (3,1) (5,1) (3,2) (5,2) (3,3) (5,3) / \ / \ / (3,4) (6,4)Not used when
isLargeBoard
.
findNode(int, int)
,
initNodeMapAux(int, int, int, int, int)
private int[] hexMap
isLargeBoard
.
findHex(int, int)
private SOCGame game
private SOCBoard board
private SOCPlayer player
playerNumber
private int playerNumber
player
if in a game, or -1.
private SOCPlayer otherPlayer
private java.awt.Image buffer
emptyBoardBuffer
private java.awt.Image emptyBoardBuffer
flushBoardLayoutAndRepaint()
to clear the buffered copy.
buffer
private int mode
updateMode()
.
For tooltip's mode, see SOCBoardPanel.BoardToolTip.hoverMode
.
private int initstlmt
private SOCPlayerInterface playerInterface
protected java.awt.Color[] robberGhostFill
ColorSquare
,
drawRobber(Graphics, int, boolean, boolean)
protected java.awt.Color[] robberGhostOutline
ColorSquare
,
drawRobber(Graphics, int, boolean, boolean)
private static final int[] ROW_START_HEXNUM
SOCBoardLarge
).
Constructor Detail |
---|
public SOCBoardPanel(SOCPlayerInterface pi)
getMinimumSize()
to read it.
pi
- the player interface that spawned usMethod Detail |
---|
private void initCoordMappings()
edgeMap
, nodeMap
, hexMap
,
hexIDtoNum
, hexX
, hexY
,
inactiveHexNums
.
Not used when isLargeBoard
.
private final void initEdgeMapAux(int x1, int y1, int x2, int y2, int startHex)
edgeMap
's valid edges across 1 row of hexes,
for use by findEdge(int, int, boolean)
.
For details of edgeMap
's layout and usage, see its javadoc.
For more details of the initialization algorithm used in this
method, see comments within
initNodeMapAux(int, int, int, int, int)
.
Not applicable when isLargeBoard
.
x1
- Leftmost x-value to init within edgeMap; the x-value
of the row's leftmost vertical edgey1
- Topmost y-value to init within edgeMap; the y-value of
the upper angled edges of the hex (angled "/" and "\")x2
- Rightmost x-value to init; the x-value of the
row's rightmost vertical edgey2
- Bottommost y-value to init; the y-value of
the lower angled edges of the hex (angled "\" and "/"),
should be y1 + 3.startHex
- Hex coordinate of row's first valid hex;
this row's edgeMap
[x,y] values will be set to
edge coordinates offset from startHex.private final void initHexMapAux(int x1, int y1, int x2, int y2, int startHex)
private final void initNodeMapAux(int x1, int y1, int x2, int y2, int startHex)
nodeMap
, set the node coordinates within a rectangular section
from (x1,y1) to (x2,y2) covering all nodes of one horizontal row of hexes.
The grid maps graphical coordinates to the board coordinate system.
Each row of hexes covers 5 rows here. For instance, hex 0x35 has its top-center
point (node) in row 6, and its bottom-center point in row 10.
All 6 nodes of each hex in range will be initialized within nodeMap
.
For node coordinates, see RST dissertation figure A2. For hex coordinates, see figure A1.
initEdgeMapAux(int, int, int, int, int)
uses a similar structure.
Not applicable when isLargeBoard
.
x1
- Starting x-coordinate within nodeMap
's index;
should correspond to left edge of startHexy1
- Starting y-coordinate within nodeMap
's index;
should correspond to top point of startHexx2
- Ending x-coordinate; should correspond to right edge of the last hex in the
row of hexes being initialized. Each hex is 2 units wide in the grid.y2
- Ending y-coordinate; should correspond to bottom point of startHex,
and thus should be y1 + 4.startHex
- Starting hex ID (0x-coordinate of first hex in this row), to use with nodeMap[x1, y1].private final void initHexIDtoNumAux(int begin, int end, int num)
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class java.awt.Component
public java.awt.Dimension getMinimumSize()
isRotated()
.
Minimum size is set in the constructor.
On the classic 4-player and 6-player boards, the size is based on PANELX
and PANELY
.
When SOCGame.hasSeaBoard
, the size is based on SOCBoard.getBoardWidth()
and .getBoardHeight()
.
getMinimumSize
in class java.awt.Component
public void setSize(int newW, int newH) throws java.lang.IllegalArgumentException
setSize
in class java.awt.Component
newW
- New width in pixels, no less than getMinimumSize()
.widthnewH
- New height in pixels, no less than getMinimumSize()
.height
java.lang.IllegalArgumentException
- if newW or newH is too small but not 0.
During initial layout, the layoutmanager may make calls to setSize(0,0);
such a call is passed to super without scaling graphics.public void setSize(java.awt.Dimension sz) throws java.lang.IllegalArgumentException
setSize
in class java.awt.Component
sz
- New size in pixels, no less than panelMinBW
wide by panelMinBH
tall
java.lang.IllegalArgumentException
- if sz is too small but not 0.
During initial layout, the layoutmanager may make calls to setSize(0,0);
such a call is passed to super without scaling graphics.public void setBounds(int x, int y, int w, int h) throws java.lang.IllegalArgumentException
SOCPlayerInterface.doLayout()
.
setBounds
in class java.awt.Component
x
- New location's x-coordinatey
- new location's y-coordinatew
- New width in pixels, no less than PANELX
(or if rotated, PANELY
})h
- New height in pixels, no less than PANELY
(or if rotated, PANELX
)
java.lang.IllegalArgumentException
- if w or h is too small but not 0.
During initial layout, the layoutmanager may make calls to setBounds(0,0,0,0);
such a call is passed to super without scaling graphics.public void pieceValueUpdated(SOCPlayingPiece piece)
_SC_CLVI
village cloth count, or
_SC_PIRI
pirate fortress strength.
Repaint that piece (if needed) on the board.
piece
- Piece that was updated, includes its new valuepublic void flushBoardLayoutAndRepaint()
SOCPlayerInterface.updateAtNewBoard()
public void flushBoardLayoutAndRepaintIfDebugShowPotentials()
private void rescaleBoard(int newW, int newH) throws java.lang.IllegalArgumentException
isScaledOrRotated
, scaledPanelX
, and other fields.
Calls renderBorderedHex(Image, Image, Color)
and renderPortImages()
.
newW
- New width in pixels, no less than PANELX
(or if rotated, PANELY
})newH
- New height in pixels, no less than PANELY
(or if rotated, PANELX
)
java.lang.IllegalArgumentException
- if newW or newH is too small but not 0.
During initial layout, the layoutmanager may cause calls to rescaleBoard(0,0);
such a call is ignored, no rescaling of graphics is done.private java.awt.Image renderBorderedHex(java.awt.Image hex, java.awt.Image hexBorder, java.awt.Color borderColor)
hex
- Un-bordered hex imagehexBorder
- Hex border pixel mask from hexBorder.gif
,
or null
to draw vector borderborderColor
- Color to paint the rendered border,
from HEX_BORDER_COLORS
or ROTAT_HEX_BORDER_COLORS
private void renderPortImages()
scaledPorts
, starting from waterHex.gif
previously loaded
into scaledHexes
[0].
Before calling this method, call rescaleCoordinateArrays()
.
private void rescaleCoordinateArrays()
rescaleBoard(int, int)
.
public int[] scaleCopyToActualX(int[] xorig)
xorig
- Int array to be scaled; each member is an x-coordinate.
scaleToActualX(int[])
,
rotateScaleCopyYToActualX(int[], int, boolean)
public int[] scaleCopyToActualY(int[] yorig)
yorig
- Int array to be scaled; each member is a y-coordinate.
scaleToActualY(int[])
public int[] rotateScaleCopyYToActualX(int[] yorig, int width, boolean rescale)
yorig
- Array to copy and rotate, not nullwidth
- Width to rotate againstrescale
- Should we also rescale, same formula as scaleCopyToActualX(int[])
?
public static final java.awt.image.BufferedImage getScaledImageUp(java.awt.Image src, int w, int h)
Image.getScaledInstance(int, int, int)
.
Calls
Graphics2D.drawImage
(src, 0, 0, w, h, null)
using RenderingHints.VALUE_INTERPOLATION_BICUBIC
.
For more info see the Java2D team blog 2007 post "The Perils of Image.getScaledInstance()" by ChrisAdamson.
src
- Source image to scale up; assumes is transparent, not opaque.w
- Scale up to this widthh
- Scale up to this height
void setDebugShowCoordsFlag(boolean setOn)
setOn
- SOCBoardPanel.BoardToolTip.setHoverText(String, int)
void setDebugShowPotentialsFlag(int pieceType, boolean setPotential, boolean setOn)
SOCBoardLarge
).
pieceType
- Piece type; 0=road, 1=settle, 2=city, 3=ship;
Use 8 for land hexes, 9 for nodes on board. Or, -1 for all.
See debugShowPotentials
javadoc for all values.setPotential
- If true, show/hide the potential set, not the legal setsetOn
- If true, set the flag; if false, clear itpublic void paint(java.awt.Graphics g)
Component.repaint()
instead.
See drawBoard(Graphics)
for related painting methods.
To protect against bugs, paint contains a try-catch that will print stack traces to the player chat print area.
paint
in class java.awt.Canvas
public void update(java.awt.Graphics g)
Component.repaint()
instead.
update
in class java.awt.Canvas
private final void drawHex(java.awt.Graphics g, int hexNum)
SOCBoard.getHexLayout()
and hexNum
.
Not used if isLargeBoard
.
When isLargeBoard
, call drawHex(Graphics, int, int, int, int, int)
instead.
g
- graphicshexNum
- hex location number (0-36)private final void drawHex(java.awt.Graphics g, int x, int y, int hexType, int portFacing, int hexNum)
g
- graphicsx
- board-graphics x-coordinate to draw at; upper-left corner of hexy
- board-graphics y-coordinate to draw at; upper-left corner of hexhexType
- hex type, as in SOCBoard.getHexTypeFromCoord(int)
;
also the index into hexes
.
If drawing a port (portFacing != -1),
hexType is SOCBoard.getPortTypeFromNodeCoord(int)
,
such as SOCBoard.SHEEP_PORT
or SOCBoard.MISC_PORT
.portFacing
- port facing (1-6), or -1 for no port: the edge of the port's hex
touching land, which contains 2 nodes where player can build a
port settlement/city. Valid range is
SOCBoard.FACING_NE
to SOCBoard.FACING_NW
.hexNum
- hex location number (0-36) to look up its dice number,
or -1 if this isn't a valid hex number or if the dice number shouldn't be drawn.
When isLargeBoard
, pass in the hex coordinate as hexNum.private final void drawRobber(java.awt.Graphics g, int hexID, boolean fullNotGhost, boolean fillNotOutline)
The pirate ship (if any) is drawn via
drawRoadOrShip(Graphics, int, int, boolean, boolean, boolean)
.
g
- Graphics contexthexID
- Board hex encoded positionfullNotGhost
- Draw with normal colors, not faded-out "ghost"
(as during PLACE_ROBBER movement)fillNotOutline
- Fill the robber, not just outline
(as for previous robber position)private final void drawRoadOrShip(java.awt.Graphics g, int edgeNum, int pn, boolean isHilight, boolean isRoadNotShip, boolean isWarship)
g
- graphicsedgeNum
- Edge number of this road or ship; accepts -1 for edgeNum 0x00.
For the pirate ship in the middle of a hex, edgeNum
can be a hex coordinate, and pn must be -2 or -3.pn
- Player number, or -1 for a white outline or fill color (depending on isHilight)
or -2 for the black pirate ship, -3 for the previous-pirate outline.isHilight
- Is this the hilight for showing a potential placement?isRoadNotShip
- True to draw a road; false to draw a ship if isLargeBoard
isWarship
- True to draw a war ship (not normal ship) if isLargeBoard
, for scenario _SC_PIRIprivate final void drawSettlement(java.awt.Graphics g, int nodeNum, int pn, boolean isHilight, boolean outlineOnly)
private final void drawCity(java.awt.Graphics g, int nodeNum, int pn, boolean isHilight)
private final void drawSettlementOrCity(java.awt.Graphics g, int nodeNum, int pn, boolean isHilight, boolean outlineOnly, boolean isCity)
outlineOnly
- If set for settlement, draw only the outline, not the filled polygon. Ignored when isCity
.private void drawSeaEdgeLines(java.awt.Graphics g, java.awt.Color co, java.util.Collection<java.lang.Integer> lse)
player
.
Calls drawSeaEdgeLine(Graphics, int)
.
g
- Graphicsco
- Color for lines, or null
to use SOCPlayerInterface.getPlayerColor(int)
;
if null
, client must have an active playerNumber
.lse
- Set of edge coordinates, or nullprivate final void drawSeaEdgeLine(java.awt.Graphics g, int edge)
edge
- Edge coordinateprivate final void drawFortress(java.awt.Graphics g, SOCFortress fo, int pn, boolean isHilight)
fo
- Fortresspn
- Player number, for fortress colorisHilight
- Use hilight/ghosted player color?private void drawVillage(java.awt.Graphics g, SOCVillage v)
v.getCloth()
is depleted to 0, those are light gray to show how close the game is to
an end-game condition.
Same logic for determining (x,y) from v.getCoordinates()
node as drawSettlementOrCity(Graphics, int, int, boolean, boolean, boolean)
.
v
- Villageprivate final void drawMarker(java.awt.Graphics g, int x, int y, java.awt.Color color, int val)
x
- Marker center x, must be already scaled and/or rotatedy
- Marker center x, must be already scaled and/or rotatedcolor
- Color to fill the markerval
- Value to show on the marker, or -1 for noneprivate final void drawArrow(java.awt.Graphics g, int pnum, int diceResult)
g
- Graphicspnum
- Current player number.
Player positions are clockwise from top-left:
diceResult
- Roll result to show, if rolled.
To show, diceResult must be at least 2,
and gamestate not SOCGame.PLAY.private final void drawPortsRing(java.awt.Graphics g)
is6player
), draw the ring of surrounding water/ports.
This is outside the coordinate system, and doesn't have hex numbers,
and so can't be drawn in the standard drawHex loop.
drawPorts_LargeBoard(Graphics)
private final void drawPorts_LargeBoard(java.awt.Graphics g)
large board
.
These can occur anywhere on the board.
drawPortsRing(Graphics)
private void drawBoard(java.awt.Graphics g)
hilight
, hoverTip
) if applicable.
The basic board without pieces is drawn just once, then buffered.
If the board layout changes (at start of game, for example),
call flushBoardLayoutAndRepaint()
to clear the buffered copy.
drawBoardEmpty(Graphics)
private final void drawBoard_SC_FTRI_placePort(java.awt.Graphics g)
_SC_FTRI
: In board mode SC_FTRI_PLACE_PORT
,
draw the possible coastal edges where the port can be placed, and if the hilight
cursor is at
such an edge, draw the port semi-transparently and a solid hilight line at the edge.
private void drawBoardEmpty(java.awt.Graphics g)
fog hex
reveal, for example),
call flushBoardLayoutAndRepaint()
to clear the buffered copy.
For scenario option _SC_CLVI
,
drawBoardEmpty draws the board's SOCVillage
s.
If panelMarginX
!= 0, do not translate g
before calling.
This method will internally translate.
g
- Graphics, typically from emptyBoardBuffer
SOCPlayerInterface.updateAtNewBoard()
private final void drawBoardEmpty_drawPiratePath(java.awt.Graphics g, int[] ppath)
_SC_PIRI
game scenario on SOCBoardLarge
,
draw the path that the pirate fleet takes around the board.
ppath
- Path of hex coordinatesprivate final void drawBoardEmpty_specialEdges(java.awt.Graphics g)
_SC_FTRI
game scenario on SOCBoardLarge
,
draw markers at all Special Edges for the players to reach and be rewarded.
Each marker's color will be determined by its edge's type, such as SOCBoardLarge.SPECIAL_EDGE_DEV_CARD
.
Unknown types will be drawn gray.
private final void drawBoardEmpty_specialNodes(java.awt.Graphics g, java.lang.String partKey, java.awt.Color color)
SOCBoardLarge
, draw markers at a set of Special Nodes for the players
to reach and be rewarded, retrieved with SOCBoardLarge.getAddedLayoutPart(String)
.
partKey
- Key string for the added layout part, for SOCBoardLarge.getAddedLayoutPart(String)
color
- Color to fill the markersprivate void drawBoardEmpty_drawDebugShowPotentials(java.awt.Graphics g) throws java.lang.IllegalStateException
debugShowPotentials
[] is set, besides 8,
draw it on the board. Shows potential/legal placement locations for player 0.
(debugShowPotentials[8] is drawn in the per-hex loop
of drawBoardEmpty(Graphics)
).
Note: Currently implemented only for isLargeBoard
only for now (TODO).
java.lang.IllegalStateException
- if ! isLargeBoard; temporary restrictionprivate final void drawBoardEmpty_drawDebugShowPotentialRoad(java.awt.Graphics g, int x, int y, int r, int c, boolean isVert, java.awt.Color co, int offset)
drawBoardEmpty_drawDebugShowPotentials(Graphics)
.
(x,y) is the center of the edge.
For large board only for now (TODO).
g
- Graphicsx
- Pixel x-coordinate of center of this edgey
- Pixel y-coordinate of center of this edger
- Board row coordinate of this edgec
- Board column coordinate of this edgeisVert
- Is this edge vertical (running north-south), not diagonal?co
- Color to draw the edgeoffset
- Approx pixel offset, outwards parallel to roadprivate void drawSuperText(java.awt.Graphics g)
superText1
, superText2
; if necessary, calculate superText1_w
and other fields.
private void drawSuperTextTop(java.awt.Graphics g)
superTextTop
; if necessary, calculate superTextTop_w
and other fields.
private final int[] nodeToXY(int nodeNum)
nodeNum
- Node coordinate
public void scaleToActualX(int[] xa)
This method only scales; does not translate to right by panelMarginX
.
xa
- Int array to be scaled; each member is an x-coordinate.scaleToActualX(int)
,
scaleCopyToActualX(int[])
public void scaleToActualY(int[] ya)
ya
- Int array to be scaled; each member is an y-coordinate.scaleToActualY(int)
,
scaleCopyToActualY(int[])
public final int scaleToActualX(int x)
This method only scales; does not translate to right by panelMarginX
.
x
- x-coordinate to be scaledscaleToActualY(int)
,
scaleFromActualX(int)
public final int scaleToActualY(int y)
y
- y-coordinate to be scaledscaleToActualX(int)
,
scaleFromActualY(int)
public final int scaleFromActualX(int x)
This method only scales; does not translate to left by panelMarginX
.
x
- x-coordinate to be scaledpublic final int scaleFromActualY(int y)
y
- y-coordinate to be scaledpublic boolean isScaled()
PANELX
x PANELY
pixels?
If so, use scaleToActualX(int)
, scaleFromActualY(int)
,
etc to convert between internal and actual screen pixel coordinates.
isRotated()
public boolean isRotated()
PANELX
and PANELY
.
isScaled()
public void updateMode()
updateHoverTipToMode()
and
(for 6-player board's Special Building Phase) updates top-center text.
For Game Option "N7"
,
updates the top-center countdown of rounds.
For the Free Placement debug mode
,
indicates that in the top center.
protected void updateHoverTipToMode()
hoverTip
based on mode
when it changes;
called from updateMode()
. Might or might not repaint board:
Calls SOCBoardPanel.BoardToolTip.setOffsetX(int)
or SOCBoardPanel.BoardToolTip.setHoverText(String, int)
.
protected void clearModeAndHilight(int ptype)
NONE
, no hilight, usually from a piece-placement mode.
Calls updateHoverTipToMode()
and repaints the board.
ptype
- Piece type to clear, like SOCPlayingPiece.ROAD
, or -1 for robber.
Used to avoid race condition during initial placement,
where server has already replied with mode for another piece type,
and board has already set mode to place that piece type.
If ptype doesn't match the board's current mode/piece type,
board's mode is not changed to NONE.public void setPlayer()
void setPlayer(SOCPlayer pl)
SOCGame.debugFreePlacement
mode.
pl
- Player to set, or null to change back to the client playergetPlayerNumber()
int getPlayerNumber()
SOCGame.debugFreePlacement
, the temporary
player set by setPlayer(SOCPlayer)
.
public void setOtherPlayer(SOCPlayer op)
op
- the other playerpublic void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
e
- DOCUMENT ME!public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
e
- DOCUMENT ME!public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged
in interface java.awt.event.MouseMotionListener
e
- DOCUMENT ME!public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
e
- MouseEventpublic void mouseMoved(java.awt.event.MouseEvent e)
mode
, update the hovering 'hilight' piece (hilight
}.
Trigger a Component.repaint()
if the mouse moved or the hilight changes.
mouseMoved
in interface java.awt.event.MouseMotionListener
public void mouseClicked(java.awt.event.MouseEvent evt)
mouseClicked
in interface java.awt.event.MouseListener
evt
- DOCUMENT ME!protected void doBoardMenuPopup(int x, int y)
x
- x-coordinate of click, actual screen pixels (not unscaled internal)y
- y-coordinate of click, actual screen pixels (not unscaled internal)public boolean popupExpectingBuildRequest()
public void popupSetBuildRequest(int coord, int ptype)
public void popupClearBuildRequest()
TimerTask
that's waiting to tell the server what they wanted to build.
public void popupFireBuildingRequest()
private final void tryMoveShipToEdge()
moveShip_fromEdge
to moveShip_toEdge
.
Also sets moveShip_fromEdge
= 0, moveShip_toEdge
= 0,
calls clearModeAndHilight
(SOCPlayingPiece.SHIP
).
Called from mouse click or popup menu.
Note that if moveShip_toEdge
!= 0, then SOCGame.canMoveShip
(playerNumber
, moveShip_fromEdge
, moveShip_toEdge
) has probably already been called.
In scenario _SC_FTRI
, checks if a gift port would be claimed by
placing a ship there. If so, confirms with the user first with SOCBoardPanel.ConfirmPlaceShipDialog
.
SOCBoardPanel.BoardPopupMenu.tryMoveShipFromHere()
public void setSuperimposedText(java.lang.String text1, java.lang.String text2) throws java.lang.IllegalArgumentException
PANELX
pixels).
Will trigger a repaint.
text1
- Line 1 (or only line) of text, or nulltext2
- Line 2 of text, or null; must be null if text1 is null
java.lang.IllegalArgumentException
- if text1 null, text2 non-nullsetSuperimposedTopText(String)
public void setSuperimposedTopText(java.lang.String text)
PANELX
pixels).
Will trigger a repaint.
text
- Line of text, or nullsetSuperimposedText(String, String)
private final int findEdge(int x, int y, boolean checkCoastal)
Note: For the 6-player board, edge 0x00 is a valid edge that can be built on. It is found here as -1, since a value of 0 marks an invalid edge.
Note: For SOCBoardLarge
, the 'sea' side of a coastal edge
is returned as the negative value of its edge coordinate, if checkCoastal
is set.
x
- x coordinate, in unscaled board, not actual pixels;
use scaleFromActualX(int)
to converty
- y coordinate, in unscaled board, not actual pixelscheckCoastal
- If true, check for coastal edges for ship placement:
Mouse could be over the land half or the sea half of the edge's graphical area.
Return positive edge coordinate for land, negative edge for sea.
Ignored unless isLargeBoard
.
Returns positive edge for non-coastal sea edges.
checkCoastal
.private final int findNode(int x, int y)
x
- x coordinate, in unscaled board, not actual pixels;
use scaleFromActualX(int)
to converty
- y coordinate, in unscaled board, not actual pixels
private final int findHex(int x, int y)
x
- x coordinate, in unscaled board, not actual pixels;
use scaleFromActualX(int)
to converty
- y coordinate, in unscaled board, not actual pixels
public void setMode(int m)
m
- mode, such as CONSIDER_LM_SETTLEMENT
or CONSIDER_LT_CITY
updateMode()
,
setModeMoveShip(int)
,
SOCPlayerInterface.doLocalCommand(String)
public void setModeMoveShip(int edge)
edge
- Edge coordinate of our player's ship we're moving.
Not checked for validity.tryMoveShipToEdge()
private static void loadImages(java.awt.Component c, boolean wantsRotated)
hexes
, rotatHexes
, and dice
.
Loads all hex types, up through SOCBoardLarge.FOG_HEX
,
because hexes
is static for all boards and all game options.
c
- Our component, to load image resource files with getToolkit and getResourcewantsRotated
- True for the 6-player non-sea board
(v2 encoding SOCBoard.BOARD_ENCODING_6PLAYER
), false otherwise.
The large board (v3 encoding)'s fog-hex and gold-hex images have no rotated version,
because that board layout is never rotated.private static final void loadHexesAndImages(java.awt.Image[] newHexes, java.lang.String imageDir, java.awt.MediaTracker tracker, java.awt.Toolkit tk, java.lang.Class<?> clazz, boolean wantsRotated)
Before v1.1.20, this method was called loadHexesPortsImages(..)
.
newHexes
- Array to store hex images and 3:1 port image into; hexes
or rotatHexes
imageDir
- Location for Class.getResource(String)
: normal or rotated IMAGEDIR
tracker
- Track image loading progress heretk
- Toolkit to load image from resourceclazz
- Class for getResourcewantsRotated
- True for rotated, false otherwise;
some hex types (goldHex, fogHex) aren't available in rotated versions,
because their board layout is never rotated.
This parameter isn't about whether the current board is rotated,
but about whether this image directory's contents are rotated.renderPortImages()
public final java.awt.Color hexColor(int hexType)
hexType
- hexType value, as in SOCBoard.DESERT_HEX
, SOCBoard.WOOD_HEX
,
SOCBoard.WATER_HEX
.
Same value and meaning as those in SOCBoard.getHexTypeFromCoord(int)
ColorSquare.WATER
if hexType not recognized.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |