mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Added button sounds on hover, click and in the lobby
- Started playing start & lobby sounds - Started playing button hover & click sounds Tags: #story[1249]
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package seng302.utilities;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
public class BonjourInstallChecker {
|
||||
private static String INSTALL_URL = "https://support.apple.com/kb/DL999?locale=en_US";
|
||||
private static String[] INSTALL_DIRECTORIES = {"C:/Program Files/Bonjour", "C:/Program Files (x86)/Bonjour"};
|
||||
|
||||
private static Boolean isWindows(){
|
||||
return System.getProperty("os.name").startsWith("Windows");
|
||||
}
|
||||
|
||||
private static Boolean isBonjourInstalled(){
|
||||
for (String dir : INSTALL_DIRECTORIES){
|
||||
File file = new File(dir);
|
||||
|
||||
if (file.isDirectory()){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean isBonjourSupported(){
|
||||
if (isWindows()){
|
||||
return isBonjourInstalled();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void openInstallUrl(){
|
||||
Runtime rt = Runtime.getRuntime();
|
||||
|
||||
try {
|
||||
rt.exec("rundll32 url.dll,FileProtocolHandler " + INSTALL_URL);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.model.Colors;
|
||||
import seng302.model.RaceState;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.controllers.cells.PlayerCell;
|
||||
|
||||
public class LobbyController implements Initializable {
|
||||
@@ -45,7 +46,7 @@ public class LobbyController implements Initializable {
|
||||
private List<LobbyController_old.LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
||||
private RaceState raceState;
|
||||
private JFXDialog customizationDialog;
|
||||
private Color playersColor;
|
||||
public Color playersColor;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
@@ -56,6 +57,15 @@ public class LobbyController implements Initializable {
|
||||
|
||||
leaveLobbyButton.setOnMouseReleased(event -> leaveLobby());
|
||||
beginRaceButton.setOnMouseReleased(event -> beginRace());
|
||||
leaveLobbyButton.setOnMouseReleased(event -> {
|
||||
Sounds.playButtonClick();
|
||||
leaveLobby();
|
||||
});
|
||||
|
||||
beginRaceButton.setOnMouseReleased(event -> {
|
||||
Sounds.playButtonClick();
|
||||
beginRace();
|
||||
});
|
||||
|
||||
Platform.runLater(() -> {
|
||||
serverName.setText(ViewManager.getInstance().getProperty("serverName"));
|
||||
@@ -73,9 +83,16 @@ public class LobbyController implements Initializable {
|
||||
Color playerColor = Colors.getColor( playerId - 1);
|
||||
customizationDialog = ViewManager.getInstance().loadCustomizationDialog(serverListMainStackPane, this, playerColor, name);
|
||||
|
||||
customizeButton.setOnMouseReleased(event -> customizationDialog.show());
|
||||
customizeButton.setOnMouseReleased(event -> {
|
||||
Sounds.playButtonClick();
|
||||
customizationDialog.show();
|
||||
});
|
||||
});
|
||||
|
||||
leaveLobbyButton.setOnMouseEntered(e -> Sounds.playHoverSound());
|
||||
customizeButton.setOnMouseEntered(e -> Sounds.playHoverSound());
|
||||
beginRaceButton.setOnMouseEntered(e -> Sounds.playHoverSound());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +142,7 @@ public class LobbyController implements Initializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void disableReadyButton() {
|
||||
public void disableReadyButton() {
|
||||
this.beginRaceButton.setDisable(true);
|
||||
this.beginRaceButton.setText("Waiting for host...");
|
||||
}
|
||||
|
||||
@@ -21,11 +21,13 @@ 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;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seng302.gameServer.ServerDescription;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.ServerListener;
|
||||
import seng302.visualiser.ServerListenerDelegate;
|
||||
import seng302.visualiser.controllers.cells.ServerCell;
|
||||
@@ -63,7 +65,10 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
||||
serverListVBox.minWidthProperty().bind(serverListScrollPane.widthProperty());
|
||||
|
||||
// Set Event Bindings
|
||||
connectButton.setOnMouseReleased(event -> attemptToDirectConnect());
|
||||
connectButton.setOnMouseReleased(event -> {
|
||||
attemptToDirectConnect();
|
||||
Sounds.playButtonClick();
|
||||
});
|
||||
for (JFXTextField textField : Arrays.asList(serverHostName, serverPortNumber)) {
|
||||
// Event for pressing enter to submit direct connection
|
||||
textField.setOnKeyPressed(event -> {
|
||||
@@ -114,7 +119,10 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
||||
try {
|
||||
JFXDialog dialog = new JFXDialog(serverListMainStackPane, dialogContent.load(),
|
||||
DialogTransition.CENTER);
|
||||
serverListHostButton.setOnAction(action -> dialog.show());
|
||||
serverListHostButton.setOnAction(action -> {
|
||||
dialog.show();
|
||||
Sounds.playButtonClick();
|
||||
});
|
||||
} catch (IOException e) {
|
||||
logger.warn("Could not create Server Creation Dialog.");
|
||||
}
|
||||
@@ -147,6 +155,7 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
||||
*
|
||||
*/
|
||||
private void DirectConnect() {
|
||||
Sounds.playButtonClick();
|
||||
ViewManager.getInstance().getGameClient().runAsClient(serverHostName.getText(), Integer.parseInt(serverPortNumber.getText()));
|
||||
}
|
||||
|
||||
@@ -179,6 +188,11 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
||||
}
|
||||
}
|
||||
|
||||
public void playButtonHoverSound(MouseEvent mouseEvent) {
|
||||
Sounds.playHoverSound();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serverRemoved(List<ServerDescription> servers) {
|
||||
Platform.runLater(() -> refreshServers(servers));
|
||||
|
||||
@@ -52,13 +52,6 @@ public class StartScreenController implements Initializable{
|
||||
//// gameClient = new GameClient(holder);
|
||||
// }
|
||||
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
startBtn.setOnMousePressed(event -> startBtn.setText("LOADING..."));
|
||||
startBtn.setOnMouseReleased(event -> goToServerBrowser());
|
||||
|
||||
setInitialDropShadow();
|
||||
preloadServerListView();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -96,6 +89,18 @@ 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();
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
package seng302.visualiser.controllers;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.visualiser.GameClient;
|
||||
|
||||
/**
|
||||
* A Class describing the actions of the start screen controller
|
||||
* Created by wmu16 on 10/07/17.
|
||||
*/
|
||||
public class StartScreenController_old implements Initializable {
|
||||
|
||||
@FXML
|
||||
private TextField ipTextField;
|
||||
|
||||
@FXML
|
||||
private AnchorPane holder;
|
||||
|
||||
GameClient gameClient;
|
||||
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
}
|
||||
|
||||
/**
|
||||
* ATTEMPTS TO:
|
||||
* Sets up a new game state with your IP address as designated as the host.
|
||||
* Starts a thread to listen for incoming connections.
|
||||
* Starts a client to server thread and connects to own ip.
|
||||
* Switches to the lobby screen
|
||||
*/
|
||||
@FXML
|
||||
public void hostButtonPressed() {
|
||||
gameClient = new GameClient(holder);
|
||||
//gameClient.runAsHost(getLocalHostIp(), 4942);
|
||||
}
|
||||
|
||||
/**
|
||||
* ATTEMPTS TO:
|
||||
* Connect to an ip address and port using the ip and port specified on start screen.
|
||||
* Starts a Client To Server Thread to maintain connection to host.
|
||||
* Switch view to lobby view.
|
||||
*/
|
||||
@FXML
|
||||
public void connectButtonPressed() {
|
||||
// TODO: 10/07/17 wmu16 - Finish function
|
||||
gameClient = new GameClient(holder);
|
||||
gameClient.runAsClient(ipTextField.getText().trim().toLowerCase(), 4942);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the local host ip address and sets this ip to ClientState.
|
||||
* Only runs by the host.
|
||||
*
|
||||
* @return the localhost ip address
|
||||
*/
|
||||
private String getLocalHostIp() {
|
||||
String ipAddress = null;
|
||||
try {
|
||||
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||
while (e.hasMoreElements()) {
|
||||
NetworkInterface ni = e.nextElement();
|
||||
if (ni.isLoopback())
|
||||
continue;
|
||||
if(ni.isPointToPoint())
|
||||
continue;
|
||||
if(ni.isVirtual())
|
||||
continue;
|
||||
|
||||
Enumeration<InetAddress> addresses = ni.getInetAddresses();
|
||||
while(addresses.hasMoreElements()) {
|
||||
InetAddress address = addresses.nextElement();
|
||||
if(address instanceof Inet4Address) { // skip all ipv6
|
||||
ipAddress = address.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (ipAddress == null) {
|
||||
System.out.println("[HOST] Cannot obtain local host ip address.");
|
||||
}
|
||||
// ClientState.setHostIp(ipAddress);
|
||||
return ipAddress;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import javafx.stage.Stage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seng302.gameServer.ServerAdvertiser;
|
||||
import seng302.utilities.BonjourInstallChecker;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.GameClient;
|
||||
import seng302.visualiser.controllers.dialogs.BoatCustomizeController;
|
||||
|
||||
@@ -77,6 +79,16 @@ public class ViewManager {
|
||||
|
||||
decorator.setOnCloseButtonAction(this::closeAll);
|
||||
|
||||
// TODO Platform.runLater(this::checkCompatibility);
|
||||
|
||||
Sounds.stopMusic();
|
||||
Sounds.playMenuMusic();
|
||||
}
|
||||
|
||||
private void checkCompatibility() {
|
||||
if(BonjourInstallChecker.isBonjourSupported()){
|
||||
BonjourInstallChecker.openInstallUrl();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeAll() {
|
||||
@@ -159,6 +171,8 @@ public class ViewManager {
|
||||
decorator.getScene().setOnKeyPressed(gameClient::keyPressed);
|
||||
decorator.getScene().setOnKeyReleased(gameClient::keyReleased);
|
||||
|
||||
Sounds.stopMusic();
|
||||
Sounds.playRaceMusic();
|
||||
return loader.getController();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@ package seng302.visualiser.controllers.cells;
|
||||
import javafx.fxml.FXML;
|
||||
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 seng302.utilities.Sounds;
|
||||
|
||||
public class PlayerCell {
|
||||
|
||||
@@ -24,4 +26,8 @@ public class PlayerCell {
|
||||
public void initialize() {
|
||||
playerName.setText(name);
|
||||
}
|
||||
|
||||
public void playButtonHoverSound(MouseEvent mouseEvent) {
|
||||
Sounds.playHoverSound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@ 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 seng302.gameServer.ServerDescription;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.GameClient;
|
||||
import seng302.visualiser.controllers.ViewManager;
|
||||
|
||||
@@ -64,7 +66,10 @@ public class ServerCell implements Initializable {
|
||||
serverPlayerCount.setText(currPlayerCount);
|
||||
mapName.setText(mapNameString);
|
||||
|
||||
serverConnButton.setOnMouseReleased(event -> joinServer());
|
||||
serverConnButton.setOnMouseReleased(event -> {
|
||||
Sounds.playButtonClick();
|
||||
joinServer();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,4 +80,7 @@ public class ServerCell implements Initializable {
|
||||
ViewManager.getInstance().getGameClient().runAsClient(hostName, portNumber);
|
||||
}
|
||||
|
||||
public void playButtonHoverSound(MouseEvent mouseEvent) {
|
||||
Sounds.playHoverSound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ 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;
|
||||
@@ -39,6 +40,7 @@ public class BoatCustomizeController implements Initializable{
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
submitBtn.setOnMouseReleased(event -> {
|
||||
Sounds.playButtonClick();
|
||||
submitCustomization();
|
||||
});
|
||||
|
||||
@@ -49,6 +51,8 @@ public class BoatCustomizeController implements Initializable{
|
||||
playerNameLengthValidator.setMessage("Player name too long.");
|
||||
|
||||
boatName.setValidators(playerNameLengthValidator, playerNameReqValidator);
|
||||
|
||||
submitBtn.setOnMouseEntered(e -> Sounds.playHoverSound());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,9 @@ import com.jfoenix.validation.RequiredFieldValidator;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import seng302.gameServer.ServerDescription;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.controllers.ViewManager;
|
||||
import seng302.visualiser.validators.FieldLengthValidator;
|
||||
|
||||
@@ -43,6 +45,11 @@ public class ServerCreationController implements Initializable {
|
||||
serverName.setValidators(fieldLengthValidator, fieldRequiredValidator);
|
||||
|
||||
submitBtn.setOnMouseReleased(event -> validateServerSettings());
|
||||
submitBtn.setOnMouseClicked(event -> submitBtn.setText("CREATING..."));
|
||||
submitBtn.setOnMouseReleased(event -> {
|
||||
Sounds.playButtonClick();
|
||||
validateServerSettings();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,4 +83,9 @@ public class ServerCreationController implements Initializable {
|
||||
maxPlayersSlider.setValue(Math.floor(maxPlayersSlider.getValue()));
|
||||
maxPlayersLabel.setText(String.format("YOU SELECTED: %.0f", maxPlayersSlider.getValue()));
|
||||
}
|
||||
|
||||
public void playButtonHoverSound(MouseEvent mouseEvent) {
|
||||
Sounds.playHoverSound();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user