public final class GamePanel extends Screen implements GameStateListener
Modifier and Type | Field and Description |
---|---|
private MessageDialog |
activeDialog
Currently showing feedback dialog.
|
private java.util.List<Animation> |
animations
List of global animations for the game, these are
rendered after all convex objects.
|
private static double |
BUTTON_HEIGHT
Dialog yes/no button height.
|
private static double |
DIALOG_HEIGHT
Message dialog height.
|
private static double |
DIALOG_WIDTH
Message dialog width.
|
private java.util.List<java.awt.geom.Line2D> |
helperLines
Currently showing merge helper lines.
|
private static int |
ICON_TEXT_SPACING
Number of pixels between the player icon and the text.
|
private static int |
PLAYER_TEXT_OFFSET
Number of pixels from the left text border to the player info.
|
private java.awt.geom.Path2D |
quitNo
Quit dialog no button.
|
private java.awt.geom.Path2D |
quitYes
Quit dialog yes button.
|
private ResultOverlay |
resultOverlay
Result overlay.
|
private boolean |
showCallipers
True if the callipers for merges should be rendered.
|
private boolean |
showCentroids
True if the centroid of objects objects should be rendered.
|
private GameState |
state
The game state to visualise.
|
BOTTOM_OFFSET, BOX_HEADER_HEIGHT, BOX_INSETS, BOX_SPACING, BOX_TEXT_OFFSET, SIDE_OFFSET, SPACING, TOP_MIDDLE_OFFSET, TOP_MIDDLE_TEXT_OFFSET, TOP_MIDDLE_WIDTH, TOP_OFFSET, TOP_SIDE_TRIANGLE, TOP_SPACE
Modifier | Constructor and Description |
---|---|
protected |
GamePanel(ConvexMerger context,
GameState state)
Constructs a new game panel with the given game context.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Called when the game is aborted (forcefully terminated).
|
void |
addAnimation(Animation animation)
Adds a new global animation to the game, this animation is
rendered after all convex objects.
|
void |
claim(Player player,
ConvexObject obj)
Called when a player claims a new object.
|
void |
end()
Called when the game ends.
|
protected java.lang.String |
getLeftButtonText()
Gets the text for the bottom left button.
|
protected java.lang.String |
getRightButtonText()
Gets the text for the bottom right button.
|
void |
handleKeyReleased(java.awt.event.KeyEvent e)
Handles a key release event.
|
protected void |
handleLeftButtonClick()
Handles the bottom left button being clicked.
|
void |
handleMouseDrag(java.awt.geom.Point2D loc,
int width,
int height)
Handles a mouse move on this screen.
|
void |
handleMouseMove(java.awt.geom.Point2D loc,
int width,
int height)
Handles a mouse move on this screen.
|
void |
handleMousePress(java.awt.geom.Point2D point,
int width,
int height)
Handles a mouse button press on this screen.
|
void |
handleMouseRelease(java.awt.geom.Point2D point,
int width,
int height)
Handles a mouse button release on this screen.
|
protected void |
handleRightButtonClick()
Handles the bottom right button being clicked.
|
protected boolean |
isLeftButtonEnabled()
Checks if the bottom left button is enabled.
|
protected boolean |
isRightButtonEnabled()
Checks if the bottom right button is enabled.
|
void |
merge(Player player,
ConvexObject source,
ConvexObject target,
ConvexObject result,
java.util.List<ConvexObject> absorbed)
Called when a player performs a merge.
|
protected void |
render(java.awt.Graphics2D g,
int width,
int height,
java.awt.geom.Point2D mouseLoc)
Renders the content of this screen with the given graphics.
|
private void |
renderInterface(java.awt.Graphics2D g,
int width,
int height)
Renders the user interface with the given graphics.
|
private void |
renderPlayfield(java.awt.Graphics2D g,
int width,
int height)
Renders the playfield with the given graphics.
|
void |
setMessage(MessageDialog message)
Sets the active display message for the game.
|
private java.awt.geom.Point2D |
translateToGameSpace(double x,
double y,
int width,
int height)
Translates the given point from window coordinate space
to game coordinate space.
|
computeBox, drawBox, drawButton, drawTitle, drawTitledBox, fillText, getContext, getMaxWidth, handleKeyPressed, render, renderMainInterface, renderMenuTitle, switchScene
private static final int ICON_TEXT_SPACING
private static final int PLAYER_TEXT_OFFSET
private static final double DIALOG_WIDTH
private static final double DIALOG_HEIGHT
private static final double BUTTON_HEIGHT
private GameState state
private boolean showCentroids
private boolean showCallipers
private MessageDialog activeDialog
private java.util.List<java.awt.geom.Line2D> helperLines
private ResultOverlay resultOverlay
private java.awt.geom.Path2D quitYes
private java.awt.geom.Path2D quitNo
private java.util.List<Animation> animations
protected GamePanel(ConvexMerger context, GameState state)
context
- The game context.state
- The game state to visualise.protected void render(java.awt.Graphics2D g, int width, int height, java.awt.geom.Point2D mouseLoc)
Screen
public void setMessage(MessageDialog message)
message
- The new message to display or
null
to clear the current message.public void addAnimation(Animation animation)
animation
- The animation to add.private void renderInterface(java.awt.Graphics2D g, int width, int height)
g
- The graphics context to use.width
- The width of the screen.height
- The height of the screen.private void renderPlayfield(java.awt.Graphics2D g, int width, int height)
g
- The graphics context to use.width
- The width of the screen.height
- The height of the screen.private java.awt.geom.Point2D translateToGameSpace(double x, double y, int width, int height)
x
- The x coordinate of the point to translate.y
- The y coordinate of the point to translate.width
- The width of the screen.height
- The height of the screen.protected void handleLeftButtonClick()
Screen
handleLeftButtonClick
in class Screen
public void handleMousePress(java.awt.geom.Point2D point, int width, int height)
Screen
handleMousePress
in class Screen
point
- The location that was clicked.width
- The width of the screen.height
- The height of the screen.public void handleMouseRelease(java.awt.geom.Point2D point, int width, int height)
Screen
handleMouseRelease
in class Screen
point
- The location that was clicked.width
- The width of the screen.height
- The height of the screen.public void handleMouseDrag(java.awt.geom.Point2D loc, int width, int height)
Screen
handleMouseDrag
in class Screen
loc
- The current cursor location.width
- The width of the screen.height
- The height of the screen.public void handleMouseMove(java.awt.geom.Point2D loc, int width, int height)
Screen
handleMouseMove
in class Screen
loc
- The current cursor location.width
- The width of the screen.height
- The height of the screen.public void handleKeyReleased(java.awt.event.KeyEvent e)
Screen
handleKeyReleased
in class Screen
e
- The key release event.protected boolean isLeftButtonEnabled()
Screen
isLeftButtonEnabled
in class Screen
protected boolean isRightButtonEnabled()
Screen
isRightButtonEnabled
in class Screen
protected java.lang.String getLeftButtonText()
Screen
getLeftButtonText
in class Screen
protected java.lang.String getRightButtonText()
Screen
getRightButtonText
in class Screen
protected void handleRightButtonClick()
Screen
handleRightButtonClick
in class Screen
public void claim(Player player, ConvexObject obj)
GameStateListener
claim
in interface GameStateListener
player
- The player that made the claim.obj
- The object that was claimed.public void merge(Player player, ConvexObject source, ConvexObject target, ConvexObject result, java.util.List<ConvexObject> absorbed) throws java.lang.InterruptedException
GameStateListener
merge
in interface GameStateListener
player
- The player that performed the merge.source
- The object the merge was started from.target
- The target object of the merge.result
- The object resulting from the merge.absorbed
- The objects absorbed in the merge.java.lang.InterruptedException
- When the player was
interrupted while making its move. Signalling
that the game was aborted.public void end()
GameStateListener
end
in interface GameStateListener
public void abort()
GameStateListener
abort
in interface GameStateListener