- Added documentation to controllers

tags : #story[1245]
This commit is contained in:
Alistair McIntyre
2017-09-12 16:54:40 +12:00
parent 9dad88e56a
commit 7e9e96c091
13 changed files with 82 additions and 120 deletions
@@ -109,6 +109,9 @@ public class LobbyController implements Initializable {
initMapPreview();
}
/**
*
*/
private void refreshMapView(){
RaceXMLData raceData = ViewManager.getInstance().getGameClient().getCourseData();
List<Limit> border = raceData.getCourseLimit();
@@ -122,12 +125,8 @@ public class LobbyController implements Initializable {
gameView.updateCourse(marks, corners);
}
private void getPlayerColors() {
}
/**
*
* Initializes a top down preview of the race course map.
*/
private void initMapPreview() {
gameView = new GameView();
@@ -163,7 +162,7 @@ public class LobbyController implements Initializable {
}
/**
*
* Refreshes the list of players and their boats, as a series of VBox PlayerCell objects.
*/
private void refreshPlayerList() {
playerListVBox.getChildren().clear();
@@ -192,17 +191,11 @@ public class LobbyController implements Initializable {
}
}
/**
*
*/
private void leaveLobby() {
ViewManager.getInstance().getGameClient().stopGame();
ViewManager.getInstance().goToStartView();
}
/**
*
*/
public void disableReadyButton() {
this.beginRaceButton.setDisable(true);
this.beginRaceButton.setText("Waiting for host...");
@@ -18,7 +18,6 @@ import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import org.slf4j.Logger;
@@ -57,10 +56,14 @@ public class ServerListController implements Initializable, ServerListenerDelega
private Label noServersFound;
private Logger logger = LoggerFactory.getLogger(ServerListController.class);
// TODO: 12/09/17 ajm412: break this method down, its way too long.
@Override
public void initialize(URL location, ResourceBundle resources) {
serverListVBox.minWidthProperty().bind(serverListScrollPane.widthProperty());
// Set Event Bindings
connectButton.setOnMouseEntered(event -> Sounds.playHoverSound());
serverListHostButton.setOnMouseEntered(event -> Sounds.playHoverSound());
connectButton.setOnMouseReleased(event -> {
attemptToDirectConnect();
Sounds.playButtonClick();
@@ -103,8 +106,8 @@ public class ServerListController implements Initializable, ServerListenerDelega
noServersFound.setText("No Servers Found");
noServersFound.setStyle(
"-fx-font-size: 30px;"
+ "-fx-padding:50px;"
+ "-fx-text-fill: -fx-pp-dark-text-color;"
+ "-fx-padding:50px;"
+ "-fx-text-fill: -fx-pp-dark-text-color;"
);
serverListVBox.getChildren().add(noServersFound);
@@ -126,7 +129,7 @@ public class ServerListController implements Initializable, ServerListenerDelega
}
/**
*
* Validates the connection and attempts to connect to a given hostname and port number.
*/
private void attemptToDirectConnect() {
if (validateDirectConnection(serverHostName.getText(), serverPortNumber.getText())) {
@@ -135,10 +138,10 @@ public class ServerListController implements Initializable, ServerListenerDelega
}
/**
*
* @param hostName
* @param portNumber
* @return
* Checks if the hostName and portNumber are valid values to connect to.
* @param hostName host name to check.
* @param portNumber port number to check
* @return boolean value if host and port number are valid values
*/
private Boolean validateDirectConnection(String hostName, String portNumber) {
Boolean hostNameValid = ValidationTools.validateTextField(serverHostName);
@@ -148,7 +151,7 @@ public class ServerListController implements Initializable, ServerListenerDelega
}
/**
*
* Connects the user to a lobby via the Direct Connect form.
*/
private void DirectConnect() {
Sounds.playButtonClick();
@@ -156,8 +159,8 @@ public class ServerListController implements Initializable, ServerListenerDelega
}
/**
*
* @param servers
* Refreshes the list of available servers.
* @param servers A list of ServerDescription objects showing available servers.
*/
private void refreshServers(List<ServerDescription> servers) {
serverListVBox.getChildren().clear();
@@ -184,11 +187,6 @@ public class ServerListController implements Initializable, ServerListenerDelega
}
}
public void playButtonHoverSound(MouseEvent mouseEvent) {
Sounds.playHoverSound();
}
@Override
public void serverRemoved(List<ServerDescription> servers) {
Platform.runLater(() -> refreshServers(servers));
@@ -5,15 +5,11 @@ import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import seng302.gameServer.ServerDescription;
@@ -34,20 +30,21 @@ public class StartScreenController implements Initializable{
private List<ServerDescription> servers;
private GameClient gameClient;
/**
*
*/
private void setInitialDropShadow() {
DropShadow dropShadow = new DropShadow();
dropShadow.setRadius(10.0);
dropShadow.setOffsetX(3.0);
dropShadow.setOffsetY(4.0);
dropShadow.setColor(Color.color(0, 0, 0, 0.5));
headText.setEffect(dropShadow);
public void initialize(URL location, ResourceBundle resources) {
startBtn.setOnMousePressed(event -> {
startBtn.setText("LOADING...");
Sounds.playButtonClick();
});
startBtn.setOnMouseReleased(event -> goToServerBrowser());
startBtn.setOnMouseEntered(event -> Sounds.playHoverSound());
preloadServerListView();
}
/**
*
* Preloads the server list view to reduce load time between start screen and server list screen.
*/
private void preloadServerListView(){
try {
@@ -60,7 +57,7 @@ public class StartScreenController implements Initializable{
}
/**
*
* Changes the view to the Server Browser.
*/
private void goToServerBrowser() {
try {
@@ -70,40 +67,4 @@ public class StartScreenController implements Initializable{
}
}
public void initialize(URL location, ResourceBundle resources) {
startBtn.setOnMousePressed(event -> {
startBtn.setText("LOADING...");
Sounds.playButtonClick();
});
startBtn.setOnMouseReleased(event -> goToServerBrowser());
setInitialDropShadow();
preloadServerListView();
}
public void toggleMusic(ActionEvent actionEvent) {
Sounds.toggleMuteMusic();
Sounds.playButtonClick();
if (Sounds.isMusicMuted()) {
// muteMusicButton.setText("UnMute Music");
} else {
// muteMusicButton.setText("Mute Music");
}
}
public void toggleSounds(ActionEvent actionEvent) {
Sounds.toggleMuteEffects();
Sounds.playButtonClick();
if (Sounds.isSoundEffectsMuted()) {
// muteSoundsButton.setText("UnMute Sounds");
} else {
// muteSoundsButton.setText("Mute Sounds");
}
}
public void playButtonHoverSound(MouseEvent mouseEvent) {
Sounds.playHoverSound();
}
}
@@ -105,6 +105,12 @@ public class ViewManager {
});
}
/**
* Sets the decorator when a new one is created (and ideally the old one destroyed)
* Also allows injection of buttons into the decorator for custom functions.
*
* @param newDecorator The new JFXDecorator to handle the game window.
*/
private void setDecorator(JFXDecorator newDecorator) {
decorator = newDecorator;
@@ -152,6 +158,9 @@ public class ViewManager {
}
/**
* Determines if a PC has compatibility with the bonjour protocol for server detection.
*/
private void checkCompatibility() {
if (BonjourInstallChecker.isBonjourSupported()) {
BonjourInstallChecker.openInstallUrl();
@@ -209,6 +218,11 @@ public class ViewManager {
return playerList;
}
/**
* Change the view to the Lobby Screen
* @param disableReadyButton Boolean value so that clients can't try start a game.
* @return A LobbyController object for the Lobby Screen.
*/
public LobbyController goToLobby(Boolean disableReadyButton) {
FXMLLoader loader = loadFxml("/views/LobbyView.fxml");
@@ -226,6 +240,11 @@ public class ViewManager {
return loader.getController();
}
/**
* Sets up the view for the race. Creating a new decorator and destroying the old one.
* @return A RaceViewController for the race view screen.
*/
public RaceViewController loadRaceView() {
FXMLLoader loader = loadFxml("/views/RaceView.fxml");
@@ -277,6 +296,7 @@ public class ViewManager {
return loader.getController();
}
// TODO: 12/09/17 ajm412: Why is this here? is there no better way we can do this? Ideally inside the LobbyController.
public JFXDialog loadCustomizationDialog(StackPane parent, LobbyController lobbyController,
Color playerColor, String name) {
FXMLLoader dialog = loadFxml("/views/dialogs/BoatCustomizeDialog.fxml");
@@ -3,11 +3,9 @@ package seng302.visualiser.controllers.cells;
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import seng302.utilities.Sounds;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
import seng302.visualiser.fxObjects.assets_3D.BoatModel;
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
@@ -34,12 +32,13 @@ public class PlayerCell {
}
public void initialize() {
// Set Player Name
playerName.setText(name);
// Add Rotating Boat to Player Cell with players color on it.
Group group = new Group();
boatPane.getChildren().add(group);
BoatModel bo = ModelFactory.boatIconView(BoatMeshType.DINGHY, this.boatColor);
group.getChildren().add(bo.getAssets());
}
public Integer getPlayerId() {
@@ -53,8 +52,4 @@ public class PlayerCell {
public Color getBoatColor() {
return boatColor;
}
public void playButtonHoverSound(MouseEvent mouseEvent) {
Sounds.playHoverSound();
}
}
}
@@ -1,27 +1,15 @@
package seng302.visualiser.controllers.cells;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDecorator;
import com.sun.org.apache.bcel.internal.classfile.Unknown;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ResourceBundle;
import com.jfoenix.controls.JFXTextField;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.layout.VBox;
import seng302.gameServer.ServerDescription;
import seng302.utilities.Sounds;
import seng302.visualiser.GameClient;
import seng302.visualiser.controllers.ViewManager;
public class ServerCell implements Initializable {
@@ -29,6 +17,8 @@ public class ServerCell implements Initializable {
//--------FXML BEGIN--------//
//Layout
@FXML
private VBox serverCellVBox;
@FXML
private GridPane serverListCell;
//Server Information
@FXML
@@ -66,21 +56,21 @@ public class ServerCell implements Initializable {
serverPlayerCount.setText(currPlayerCount);
mapName.setText(mapNameString);
serverCellVBox.setOnMouseEntered(event -> Sounds.playHoverSound());
serverConnButton.setOnMouseReleased(event -> {
Sounds.playButtonClick();
joinServer();
});
}
/**
*
* Attempts to connect to the chosen server using the button on the serverCell.
*/
private void joinServer() {
System.out.println("Connecting to " + serverName.getText());
ViewManager.getInstance().getGameClient().runAsClient(hostName, portNumber);
}
public void playButtonHoverSound(MouseEvent mouseEvent) {
Sounds.playHoverSound();
}
}
@@ -4,17 +4,15 @@ import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXColorPicker;
import com.jfoenix.controls.JFXTextField;
import com.jfoenix.validation.RequiredFieldValidator;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import seng302.gameServer.messages.CustomizeRequestType;
import seng302.utilities.Sounds;
import seng302.visualiser.ClientToServerThread;
import java.net.URL;
import java.util.ResourceBundle;
import seng302.visualiser.controllers.LobbyController;
import seng302.visualiser.validators.FieldLengthValidator;
import seng302.visualiser.validators.ValidationTools;
@@ -56,7 +54,7 @@ public class BoatCustomizeController implements Initializable{
}
/**
*
* Attempts to submit a valid customization packet for boat name and boat color.
*/
private void submitCustomization() {
@@ -4,6 +4,8 @@ import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXSlider;
import com.jfoenix.controls.JFXTextField;
import com.jfoenix.validation.RequiredFieldValidator;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
@@ -12,9 +14,6 @@ import seng302.gameServer.ServerDescription;
import seng302.utilities.Sounds;
import seng302.visualiser.controllers.ViewManager;
import seng302.visualiser.validators.FieldLengthValidator;
import java.net.URL;
import java.util.ResourceBundle;
import seng302.visualiser.validators.ValidationTools;
public class ServerCreationController implements Initializable {
@@ -51,7 +50,7 @@ public class ServerCreationController implements Initializable {
}
/**
*
* Validates that a server has a valid name and creates the server.
*/
private void validateServerSettings() {
submitBtn.setText("CREATING...");
@@ -63,7 +62,7 @@ public class ServerCreationController implements Initializable {
}
/**
*
* Creates a server with a given set of details.
*/
private void createServer() {
ServerDescription serverDescription = ViewManager.getInstance().getGameClient()
@@ -75,7 +74,7 @@ public class ServerCreationController implements Initializable {
}
/**
*
* Updates a label as the user slides along the max players slider.
*/
private void updateMaxPlayerLabel() {
maxPlayersSlider.setValue(Math.floor(maxPlayersSlider.getValue()));