mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge remote-tracking branch 'origin/NewUI_merge' into story1266_3d_model_factory
# Conflicts: # src/main/java/seng302/visualiser/GameView3D.java
This commit is contained in:
@@ -44,7 +44,6 @@ import seng302.utilities.XMLGenerator;
|
||||
import seng302.utilities.XMLParser;
|
||||
import seng302.visualiser.controllers.FinishScreenViewController;
|
||||
import seng302.visualiser.controllers.LobbyController;
|
||||
import seng302.visualiser.controllers.LobbyController_old;
|
||||
import seng302.visualiser.controllers.RaceViewController;
|
||||
import seng302.visualiser.controllers.ViewManager;
|
||||
|
||||
@@ -201,23 +200,6 @@ public class GameClient {
|
||||
socketThread.addStreamObserver(this::parsePackets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a view of the lobby into the clients pane
|
||||
*
|
||||
* @return the lobby controller.
|
||||
*/
|
||||
private LobbyController_old loadLobby() {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(
|
||||
GameClient.class.getResource("/views/LobbyView.fxml"));
|
||||
try {
|
||||
holderPane.getChildren().clear();
|
||||
holderPane.getChildren().add(fxmlLoader.load());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fxmlLoader.getController();
|
||||
}
|
||||
|
||||
private void loadRaceView() {
|
||||
FXMLLoader fxmlLoader = loadFXMLToHolder("/views/RaceView.fxml");
|
||||
holderPane.getScene().setOnKeyPressed(this::keyPressed);
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package seng302.visualiser.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ColorPicker;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Stage;
|
||||
import seng302.gameServer.messages.CustomizeRequestType;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.ClientToServerThread;
|
||||
|
||||
public class CustomizationController_old {
|
||||
|
||||
@FXML
|
||||
private TextField nameField;
|
||||
|
||||
@FXML
|
||||
private ColorPicker boatColorPicker;
|
||||
|
||||
@FXML
|
||||
private Button customizeSubmit;
|
||||
|
||||
private LobbyController_old lc;
|
||||
private ClientToServerThread socketThread;
|
||||
private Stage windowStage;
|
||||
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
public void setServerThread(ClientToServerThread ctsThread) {
|
||||
this.socketThread = ctsThread;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void submitCustomization() {
|
||||
Sounds.playButtonClick();
|
||||
// System.out.println("Attempting to send");
|
||||
socketThread.sendCustomizationRequest(CustomizeRequestType.NAME, nameField.getText().getBytes());
|
||||
// TODO: 16/08/17 ajm412: Turn colors into byte array.
|
||||
Color color = boatColorPicker.getValue();
|
||||
|
||||
short red = (short) (color.getRed() * 255);
|
||||
short green = (short) (color.getGreen() * 255);
|
||||
short blue = (short) (color.getBlue() * 255);
|
||||
|
||||
byte[] colorArray = new byte[3];
|
||||
|
||||
colorArray[0] = (byte) red;
|
||||
colorArray[1] = (byte) green;
|
||||
colorArray[2] = (byte) blue;
|
||||
|
||||
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
|
||||
lc.setPlayersColor(color);
|
||||
windowStage.close();
|
||||
}
|
||||
|
||||
public void setLobbyController(LobbyController_old lc) {
|
||||
this.lc = lc;
|
||||
}
|
||||
|
||||
public void setStage(Stage stage) {
|
||||
this.windowStage = stage;
|
||||
}
|
||||
|
||||
public void setPlayerName(String name) {
|
||||
this.nameField.setText(name);
|
||||
}
|
||||
|
||||
public void setPlayerColor(Color playerColor) {
|
||||
this.boatColorPicker.setValue(playerColor);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import seng302.model.stream.xml.parser.RaceXMLData;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.GameView;
|
||||
import seng302.visualiser.controllers.cells.PlayerCell;
|
||||
import seng302.visualiser.controllers.dialogs.BoatCustomizeController;
|
||||
|
||||
public class LobbyController implements Initializable {
|
||||
|
||||
@@ -51,7 +52,6 @@ public class LobbyController implements Initializable {
|
||||
private Pane serverMap;
|
||||
//---------FXML END---------//
|
||||
|
||||
private List<LobbyController_old.LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
||||
private RaceState raceState;
|
||||
private JFXDialog customizationDialog;
|
||||
public Color playersColor;
|
||||
@@ -93,8 +93,8 @@ public class LobbyController implements Initializable {
|
||||
Integer playerId = ViewManager.getInstance().getGameClient().getServerThread().getClientId();
|
||||
String name = ViewManager.getInstance().getGameClient().getPlayerNames().get(playerId - 1);
|
||||
|
||||
Color playerColor = Colors.getColor( playerId - 1);
|
||||
customizationDialog = ViewManager.getInstance().loadCustomizationDialog(serverListMainStackPane, this, playerColor, name);
|
||||
playersColor = Colors.getColor(playerId - 1);
|
||||
customizationDialog = createCustomizeDialog();
|
||||
|
||||
customizeButton.setOnMouseReleased(event -> {
|
||||
Sounds.playButtonClick();
|
||||
@@ -109,6 +109,32 @@ public class LobbyController implements Initializable {
|
||||
initMapPreview();
|
||||
}
|
||||
|
||||
private JFXDialog createCustomizeDialog() {
|
||||
// TODO: 12/09/17 ajm412: Why is this here? is there no better way we can do this? Ideally inside the LobbyController.
|
||||
FXMLLoader dialog = new FXMLLoader(
|
||||
getClass().getResource("/views/dialogs/BoatCustomizeDialog.fxml"));
|
||||
|
||||
JFXDialog customizationDialog = null;
|
||||
|
||||
try {
|
||||
customizationDialog = new JFXDialog(serverListMainStackPane, dialog.load(),
|
||||
JFXDialog.DialogTransition.CENTER);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
BoatCustomizeController controller = dialog.getController();
|
||||
|
||||
controller.setParentController(this);
|
||||
controller.setPlayerColor(this.playersColor);
|
||||
|
||||
return customizationDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void refreshMapView(){
|
||||
RaceXMLData raceData = ViewManager.getInstance().getGameClient().getCourseData();
|
||||
List<Limit> border = raceData.getCourseLimit();
|
||||
@@ -122,12 +148,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 +185,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 +214,12 @@ 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...");
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
package seng302.visualiser.controllers;
|
||||
|
||||
import com.sun.media.jfxmedia.logging.Logger;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.model.Colors;
|
||||
import seng302.model.RaceState;
|
||||
import seng302.visualiser.ClientToServerThread;
|
||||
|
||||
/**
|
||||
* A class describing the actions of the lobby screen
|
||||
* Created by wmu16 on 10/07/17.
|
||||
*/
|
||||
public class LobbyController_old {
|
||||
|
||||
public enum CloseStatus {
|
||||
LEAVE,
|
||||
READY
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface LobbyCloseListener {
|
||||
void notify(CloseStatus exitCause);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private Text lobbyIpText;
|
||||
@FXML
|
||||
private Button readyButton;
|
||||
@FXML
|
||||
private Button customizeButton;
|
||||
@FXML
|
||||
private TextArea playerOneTxt;
|
||||
@FXML
|
||||
private TextArea playerTwoTxt;
|
||||
@FXML
|
||||
private TextArea playerThreeTxt;
|
||||
@FXML
|
||||
private TextArea playerFourTxt;
|
||||
@FXML
|
||||
private TextArea playerFiveTxt;
|
||||
@FXML
|
||||
private TextArea playerSixTxt;
|
||||
@FXML
|
||||
private TextArea playerSevenTxt;
|
||||
@FXML
|
||||
private TextArea playerEightTxt;
|
||||
@FXML
|
||||
private ImageView firstImageView;
|
||||
@FXML
|
||||
private ImageView secondImageView;
|
||||
@FXML
|
||||
private ImageView thirdImageView;
|
||||
@FXML
|
||||
private ImageView fourthImageView;
|
||||
@FXML
|
||||
private ImageView fifthImageView;
|
||||
@FXML
|
||||
private ImageView sixthImageView;
|
||||
@FXML
|
||||
private ImageView seventhImageView;
|
||||
@FXML
|
||||
private ImageView eighthImageView;
|
||||
@FXML
|
||||
private Text timeUntilStart;
|
||||
@FXML
|
||||
private Text courseNameText;
|
||||
|
||||
private List<ImageView> imageViews = new ArrayList<>();
|
||||
private List<TextArea> listViews = new ArrayList<>();
|
||||
private RaceState raceState;
|
||||
|
||||
private ClientToServerThread socketThread;
|
||||
|
||||
private Stage customizeStage;
|
||||
|
||||
private Color playersColor;
|
||||
|
||||
private int MAX_NUM_PLAYERS = 8;
|
||||
private Integer playerID;
|
||||
|
||||
private List<LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
||||
private ObservableList<String> players;
|
||||
|
||||
/**
|
||||
* Add all FXObjects to lists and initialize images.
|
||||
*/
|
||||
public void initialize() {
|
||||
Collections.addAll(listViews,
|
||||
playerOneTxt, playerTwoTxt, playerThreeTxt, playerFourTxt, playerFiveTxt, playerSixTxt,
|
||||
playerSevenTxt, playerEightTxt
|
||||
);
|
||||
Collections.addAll(imageViews,
|
||||
firstImageView, secondImageView, thirdImageView, fourthImageView,
|
||||
fifthImageView, sixthImageView, seventhImageView, eighthImageView
|
||||
);
|
||||
initialiseImageView();
|
||||
|
||||
timeUntilStart.setText("Waiting For Host...");
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates player names.
|
||||
*/
|
||||
private void updatePlayers() {
|
||||
//Update players if one added.
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
listViews.get(i).setText(players.get(i));
|
||||
if (playerID == (i + 1)) {
|
||||
listViews.get(i).setText(listViews.get(i).getText() + " (YOU)");
|
||||
}
|
||||
imageViews.get(i).setVisible(true);
|
||||
}
|
||||
//Update empty text fields if player left.
|
||||
for (int i = MAX_NUM_PLAYERS-1; i >= players.size(); i--) {
|
||||
listViews.get(i).setText("");
|
||||
imageViews.get(i).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all images and hides them till players join.
|
||||
*/
|
||||
private void initialiseImageView() {
|
||||
for (ImageView viewer : imageViews) {
|
||||
viewer.setImage(
|
||||
new Image(
|
||||
RaceViewController.class.getResourceAsStream(
|
||||
"/pics/sail.png")
|
||||
)
|
||||
);
|
||||
viewer.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void customize() {
|
||||
Parent root;
|
||||
try {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(LobbyController_old.class.getResource("/views/customizeView.fxml"));
|
||||
root = fxmlLoader.load();
|
||||
root.getStylesheets().add("/css/master.css");
|
||||
customizeStage = new Stage();
|
||||
customizeStage.setTitle("Customize Boat");
|
||||
customizeStage.setScene(new Scene(root, 700, 450));
|
||||
CustomizationController_old cc = fxmlLoader.getController();
|
||||
cc.setServerThread(this.socketThread);
|
||||
cc.setPlayerName(this.players.get(playerID - 1));
|
||||
|
||||
if (this.playersColor == null) {
|
||||
this.playersColor = Colors.getColor(playerID - 1);
|
||||
}
|
||||
|
||||
cc.setPlayerColor(this.playersColor);
|
||||
cc.setStage(customizeStage); // pass the stage through so it can be closed later.
|
||||
cc.setLobbyController(this);
|
||||
customizeStage.show();
|
||||
} catch (IOException e) {
|
||||
Logger.logMsg(4, "Failed to load Customization View from resources.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setSocketThread(ClientToServerThread thread) {
|
||||
this.socketThread = thread;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void leaveLobbyButtonPressed() {
|
||||
// TODO: 10/07/17 wmu16 - Finish function!
|
||||
GameState.setCurrentStage(GameStages.CANCELLED);
|
||||
// TODO: 20/07/17 wmu16 - Implement some way of terminating the game
|
||||
for (LobbyCloseListener readyListener : lobbyListeners)
|
||||
readyListener.notify(CloseStatus.LEAVE);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void readyButtonPressed() {
|
||||
GameState.setCurrentStage(GameStages.PRE_RACE);
|
||||
// Do countdown logic here
|
||||
|
||||
for (LobbyCloseListener readyListener : lobbyListeners)
|
||||
readyListener.notify(CloseStatus.READY);
|
||||
customizeButton.setDisable(true);
|
||||
}
|
||||
|
||||
public void setTitle (String title) {
|
||||
lobbyIpText.setText(title);
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName){
|
||||
courseNameText.setText(courseName);
|
||||
}
|
||||
|
||||
public void addCloseListener(LobbyCloseListener listener) {
|
||||
lobbyListeners.add(listener);
|
||||
}
|
||||
|
||||
public void setPlayerListSource (ObservableList<String> players) {
|
||||
this.players = players;
|
||||
players.addListener((ListChangeListener<? super String>) (lcl) ->
|
||||
Platform.runLater(this::updatePlayers)
|
||||
);
|
||||
Platform.runLater(this::updatePlayers);
|
||||
}
|
||||
|
||||
public void setPlayerID(Integer id) {
|
||||
playerID = id;
|
||||
}
|
||||
|
||||
public void updateRaceState(RaceState raceState){
|
||||
this.raceState = raceState;
|
||||
/*if (this.customizeStage != null) {
|
||||
this.customizeStage.close();
|
||||
}*/ // TODO: 17/08/17 ajm412: close the customization window if the host starts the game while customizing
|
||||
if (!customizeButton.isDisabled()) {
|
||||
customizeButton.setDisable(true);
|
||||
}
|
||||
timeUntilStart.setText("Starting in: " + raceState.getRaceTimeStr());
|
||||
}
|
||||
|
||||
public void disableReadyButton () {
|
||||
readyButton.setDisable(true);
|
||||
readyButton.setVisible(false);
|
||||
}
|
||||
|
||||
//TODO here newui
|
||||
public void setPlayersColor(Color playerColor) {
|
||||
this.playersColor = playerColor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
@@ -103,6 +105,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
private Label windDirectionLabel;
|
||||
@FXML
|
||||
private Label windSpeedLabel;
|
||||
@FXML
|
||||
private Label positionLabel, boatSpeedLabel, boatHeadingLabel;
|
||||
|
||||
//Race Data
|
||||
private Map<Integer, ClientYacht> participants;
|
||||
@@ -119,6 +123,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
private ImportantAnnotationsState importantAnnotations;
|
||||
private Polyline windArrow = new WindArrow(Color.LIGHTGRAY);
|
||||
private ObservableList<ClientYacht> selectionComboBoxList = FXCollections.observableArrayList();
|
||||
private ClientYacht player;
|
||||
|
||||
public void initialize() {
|
||||
Sounds.stopMusic();
|
||||
@@ -171,6 +176,19 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
rvAnchorPane.setOnMouseClicked((event) ->
|
||||
rvAnchorPane.requestFocus()
|
||||
);
|
||||
|
||||
//Makes the chat history non transparent when clicked on
|
||||
chatInput.focusedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
|
||||
Boolean newValue) {
|
||||
if (newValue) {
|
||||
chatHistory.increaseOpacity();
|
||||
} else {
|
||||
chatHistory.decreaseOpacity();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadRace (
|
||||
@@ -181,6 +199,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
this.courseData = raceData;
|
||||
this.markers = raceData.getCompoundMarks();
|
||||
this.raceState = raceState;
|
||||
this.player = player;
|
||||
|
||||
raceState.getPlayerPositions().addListener((ListChangeListener<ClientYacht>) c -> {
|
||||
while (c.next()) {
|
||||
@@ -410,6 +429,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Platform.runLater(() -> updatePosition());
|
||||
Platform.runLater(() -> updateBoatSpeed());
|
||||
Platform.runLater(() -> updateBoatHeading());
|
||||
Platform.runLater(() -> updateRaceTime());
|
||||
}
|
||||
}, 0, 1000);
|
||||
@@ -473,6 +495,52 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates player position with ordinal number up to 23rd position.
|
||||
*/
|
||||
private void updatePosition() {
|
||||
if (player.getPosition() == null) {
|
||||
positionLabel.setText("Position:\n-");
|
||||
} else {
|
||||
switch (player.getPosition()) {
|
||||
case 1:
|
||||
positionLabel.setText("Position:\n1st");
|
||||
break;
|
||||
case 2:
|
||||
positionLabel.setText("Position:\n2nd");
|
||||
break;
|
||||
case 3:
|
||||
positionLabel.setText("Position:\n3rd");
|
||||
break;
|
||||
case 21:
|
||||
positionLabel.setText("Position:\n21st");
|
||||
break;
|
||||
case 22:
|
||||
positionLabel.setText("Position:\n22nd");
|
||||
break;
|
||||
case 23:
|
||||
positionLabel.setText("Position:\n23rd");
|
||||
break;
|
||||
default:
|
||||
positionLabel.setText("Position:\n" + player.getPosition() + "th");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates boat speed value displayed on race view.
|
||||
*/
|
||||
private void updateBoatSpeed() {
|
||||
boatSpeedLabel.setText("Boat Speed:\n" + String.valueOf(player.getCurrentVelocity()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates boat heading value displayed on race view.
|
||||
*/
|
||||
private void updateBoatHeading() {
|
||||
boatHeadingLabel.setText(String.format("Boat Heading:\n%.1f°", player.getHeading()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the order of the yachts as from the StreamParser and sets them in the yacht order
|
||||
* section
|
||||
@@ -703,8 +771,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
|
||||
public boolean isChatInputFocused() {
|
||||
// return chatInput.focusedProperty().getValue();
|
||||
return false;
|
||||
return chatInput.focusedProperty().getValue();
|
||||
}
|
||||
|
||||
public String readChatInput() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package seng302.visualiser.controllers;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXDecorator;
|
||||
import com.jfoenix.controls.JFXDialog;
|
||||
import com.jfoenix.svg.SVGGlyph;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -16,7 +15,6 @@ import javafx.scene.Scene;
|
||||
import javafx.scene.SceneAntialiasing;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Stage;
|
||||
import org.slf4j.Logger;
|
||||
@@ -25,7 +23,6 @@ import seng302.gameServer.ServerAdvertiser;
|
||||
import seng302.utilities.BonjourInstallChecker;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.GameClient;
|
||||
import seng302.visualiser.controllers.dialogs.BoatCustomizeController;
|
||||
|
||||
public class ViewManager {
|
||||
|
||||
@@ -106,6 +103,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;
|
||||
|
||||
@@ -153,6 +156,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();
|
||||
@@ -210,6 +216,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");
|
||||
|
||||
@@ -227,6 +238,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,29 +293,4 @@ public class ViewManager {
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
|
||||
public JFXDialog loadCustomizationDialog(StackPane parent, LobbyController lobbyController,
|
||||
Color playerColor, String name) {
|
||||
FXMLLoader dialog = loadFxml("/views/dialogs/BoatCustomizeDialog.fxml");
|
||||
|
||||
JFXDialog customizationDialog = null;
|
||||
|
||||
try {
|
||||
customizationDialog = new JFXDialog(parent, dialog.load(),
|
||||
JFXDialog.DialogTransition.CENTER);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
BoatCustomizeController controller = dialog.getController();
|
||||
|
||||
controller.setParentController(lobbyController);
|
||||
controller.setPlayerColor(playerColor);
|
||||
controller.setPlayerName(name);
|
||||
controller.setServerThread(gameClient.getServerThread());
|
||||
controller.setPlayerColor(lobbyController.playersColor);
|
||||
|
||||
return customizationDialog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,18 +4,17 @@ 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.controllers.ViewManager;
|
||||
import seng302.visualiser.validators.FieldLengthValidator;
|
||||
import seng302.visualiser.validators.ValidationTools;
|
||||
|
||||
@@ -44,6 +43,8 @@ public class BoatCustomizeController implements Initializable{
|
||||
submitCustomization();
|
||||
});
|
||||
|
||||
socketThread = ViewManager.getInstance().getGameClient().getServerThread();
|
||||
|
||||
RequiredFieldValidator playerNameReqValidator = new RequiredFieldValidator();
|
||||
playerNameReqValidator.setMessage("Player name required.");
|
||||
|
||||
@@ -56,7 +57,7 @@ public class BoatCustomizeController implements Initializable{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Attempts to submit a valid customization packet for boat name and boat color.
|
||||
*/
|
||||
private void submitCustomization() {
|
||||
|
||||
@@ -88,10 +89,6 @@ public class BoatCustomizeController implements Initializable{
|
||||
this.colorPicker.setValue(playerColor);
|
||||
}
|
||||
|
||||
public void setServerThread(ClientToServerThread ctsThread) {
|
||||
this.socketThread = ctsThread;
|
||||
}
|
||||
|
||||
public void setParentController(LobbyController lobbyController){
|
||||
this.lobbyController = lobbyController;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ 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.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
@@ -12,9 +15,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 {
|
||||
@@ -48,10 +48,11 @@ public class ServerCreationController implements Initializable {
|
||||
Sounds.playButtonClick();
|
||||
validateServerSettings();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Validates that a server has a valid name and creates the server.
|
||||
*/
|
||||
private void validateServerSettings() {
|
||||
submitBtn.setText("CREATING...");
|
||||
@@ -63,7 +64,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 +76,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()));
|
||||
|
||||
@@ -24,10 +24,10 @@ public class ChatHistory extends ScrollPane {
|
||||
this.setMaxWidth(Double.MAX_VALUE);
|
||||
this.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
|
||||
this.setHbarPolicy(ScrollBarPolicy.NEVER);
|
||||
this.lookup(".scroll-pane").setStyle("-fx-background: rgba(255, 255, 255, 0.1); -fx-background-color: rgba(255, 255, 255, 0.1);");
|
||||
this.lookup(".scroll-pane").setStyle("-fx-background: rgba(135, 206, 235, 0.0); -fx-background-color: rgba(135, 206, 235, 0.0);");
|
||||
|
||||
this.textFlow.setStyle(
|
||||
"-fx-background: rgba(255, 255, 255, 0.1); -fx-background-color: rgba(255, 255, 255, 0.1); -fx-padding: 10px"
|
||||
"-fx-background: rgba(135, 206, 235, 0.0); -fx-background-color: rgba(135, 206, 235, 0.0); -fx-padding: 10px"
|
||||
);
|
||||
//This makes the window auto scroll.
|
||||
textFlow.getChildren().addListener((ListChangeListener<Node>) c ->
|
||||
@@ -71,6 +71,19 @@ public class ChatHistory extends ScrollPane {
|
||||
|
||||
}
|
||||
|
||||
public void increaseOpacity() {
|
||||
this.lookup(".scroll-pane").setStyle("-fx-background: rgba(255, 255, 255, 0.2); -fx-background-color: rgba(255, 255, 255, 0.2);");
|
||||
|
||||
this.textFlow.setStyle(
|
||||
"-fx-background: rgba(255, 255, 255, 0.2); -fx-background-color: rgba(255, 255, 255, 0.2); -fx-padding: 10px"
|
||||
);
|
||||
}
|
||||
|
||||
public void decreaseOpacity() {
|
||||
this.lookup(".scroll-pane").setStyle("-fx-background: rgba(135, 206, 235, 0.0); -fx-background-color: rgba(135, 206, 235, 0.0);");
|
||||
|
||||
this.textFlow.setStyle(
|
||||
"-fx-background: rgba(135, 206, 235, 0.0); -fx-background-color: rgba(135, 206, 235, 0.0); -fx-padding: 10px"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user