public class NewGameMenu extends Screen implements PlayfieldGenerator.GeneratorProgressListener, TextField.TextChangeListener, TextField.FocusLossListener
Modifier and Type | Class and Description |
---|---|
private class |
NewGameMenu.ButtonAssembly
Assembly of three mutually exclusive buttons.
|
protected class |
NewGameMenu.PlayerPanel
Panel to configure a new AI or human player.
|
Modifier and Type | Field and Description |
---|---|
private static int[] |
COVERAGE_VALUES
Raw coverage values associated with the density buttons.
|
private NewGameMenu.ButtonAssembly |
density
Configuration for the playfield density.
|
private PlayfieldGenerator |
gen
The playfield generator being configured.
|
private static int |
MAX_WIDTH
Maximum width used by the boxes.
|
protected NewGameMenu.PlayerPanel |
p1
Configuration for player 1.
|
protected NewGameMenu.PlayerPanel |
p2
Configuration for player 2.
|
protected NewGameMenu.PlayerPanel |
p3
Configuration for player 3.
|
protected NewGameMenu.PlayerPanel |
p4
Configuration for player 4.
|
private double |
progress
Playfield generation progress (0~1).
|
private static int[] |
RANGE_VALUES_MAX
Raw maximum range values associated with the object size buttons.
|
private static int[] |
RANGE_VALUES_MIN
Raw minimum range values associated with the object size buttons.
|
private static int[] |
SCALING_VALUES
Raw scaling values associated with the spacing buttons.
|
private TextField |
seed
Text field showing the game seed.
|
protected boolean |
showDecomp
Whether to show the vertical decomposition
from the start of the game.
|
private NewGameMenu.ButtonAssembly |
size
Configuration for the playfield object size.
|
private NewGameMenu.ButtonAssembly |
spacing
Configuration for the playfield spacing.
|
private java.awt.geom.Path2D |
start
Bounds of the start button.
|
private static double |
START_HEIGHT
Height of the start button.
|
private boolean |
started
Whether the start button was clicked.
|
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
Constructor and Description |
---|
NewGameMenu(ConvexMerger context)
Constructs a new new game menu with the given game context.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
canStart()
Checks if enough players are configured to start (at least 1).
|
private int |
findClosest(int[] values,
int value)
Finds the index of the element in the array
closest to the given value.
|
protected java.lang.String |
getButtonMessage()
Gets the status message to display on the start button.
|
protected java.lang.String |
getLeftButtonText()
Gets the text for the bottom left button.
|
protected java.lang.String |
getMenuTitle()
Gets the title of this menu.
|
protected java.lang.String |
getRightButtonText()
Gets the text for the bottom right button.
|
void |
handleKeyPressed(java.awt.event.KeyEvent event)
Handles a key press event.
|
void |
handleKeyReleased(java.awt.event.KeyEvent e)
Handles a key release event.
|
protected void |
handleLeftButtonClick()
Handles the bottom left button being clicked.
|
void |
handleMouseRelease(java.awt.geom.Point2D loc,
int width,
int height)
Handles a mouse button release on this screen.
|
protected void |
handleRightButtonClick()
Handles the bottom right button being clicked.
|
protected void |
handleStart(java.util.List<Player> players,
PlayfieldGenerator gen)
Handles the start of the actual game given the
player and playfield generator configuration.
|
protected boolean |
isLeftButtonEnabled()
Checks if the bottom left button is enabled.
|
protected boolean |
isRightButtonEnabled()
Checks if the bottom right button is enabled.
|
void |
onFocusLost()
Called when the text field loses user focus.
|
void |
onTextChange(java.lang.String text)
Called when the text field content changes.
|
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.
|
void |
reset()
Resets this menu keeping the selected options
but resetting that the game was started.
|
void |
update(double progress)
Updates the current progress.
|
computeBox, drawBox, drawButton, drawTitle, drawTitledBox, fillText, getContext, getMaxWidth, handleMouseDrag, handleMouseMove, handleMousePress, render, renderMainInterface, renderMenuTitle, switchScene
private static final int MAX_WIDTH
private static final double START_HEIGHT
private static final int[] RANGE_VALUES_MIN
private static final int[] RANGE_VALUES_MAX
private static final int[] COVERAGE_VALUES
private static final int[] SCALING_VALUES
protected NewGameMenu.PlayerPanel p1
protected NewGameMenu.PlayerPanel p2
protected NewGameMenu.PlayerPanel p3
protected NewGameMenu.PlayerPanel p4
private java.awt.geom.Path2D start
private NewGameMenu.ButtonAssembly size
private NewGameMenu.ButtonAssembly density
private NewGameMenu.ButtonAssembly spacing
private double progress
private boolean started
protected boolean showDecomp
private TextField seed
private PlayfieldGenerator gen
public NewGameMenu(ConvexMerger context)
context
- The game context.public void reset()
protected boolean canStart()
protected java.lang.String getButtonMessage()
protected void render(java.awt.Graphics2D g, int width, int height, java.awt.geom.Point2D mouseLoc)
Screen
protected java.lang.String getMenuTitle()
protected void handleStart(java.util.List<Player> players, PlayfieldGenerator gen)
players
- The participating players.gen
- The playfield generator to use.private int findClosest(int[] values, int value)
values
- The list of elements to compare to.value
- The target value.public void onFocusLost()
TextField.FocusLossListener
onFocusLost
in interface TextField.FocusLossListener
public void onTextChange(java.lang.String text)
TextField.TextChangeListener
onTextChange
in interface TextField.TextChangeListener
text
- The next text field content.public void handleKeyReleased(java.awt.event.KeyEvent e)
Screen
handleKeyReleased
in class Screen
e
- The key release event.public void handleMouseRelease(java.awt.geom.Point2D loc, int width, int height)
Screen
handleMouseRelease
in class Screen
loc
- The location that was clicked.width
- The width of the screen.height
- The height of the screen.public void handleKeyPressed(java.awt.event.KeyEvent event)
Screen
handleKeyPressed
in class Screen
event
- The key press event.public void update(double progress)
PlayfieldGenerator.GeneratorProgressListener
update
in interface PlayfieldGenerator.GeneratorProgressListener
progress
- A progress value between 0 and 1 where
0 means no progress and 1 means done.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 handleLeftButtonClick()
Screen
handleLeftButtonClick
in class Screen
protected void handleRightButtonClick()
Screen
handleRightButtonClick
in class Screen