From c8dc448a523637b7b1acc48ff159bb06524f1d78 Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Tue, 12 Sep 2017 18:11:32 +1200 Subject: [PATCH] Added tests for sounds and modified the transparency for the chat history window. #story[1245] --- src/main/java/seng302/utilities/Sounds.java | 9 ++++--- .../controllers/RaceViewController.java | 15 +++++++++++ .../dialogs/ServerCreationController.java | 2 ++ .../visualiser/fxObjects/ChatHistory.java | 17 +++++++++++-- .../java/seng302/utilities/SoundsTest.java | 25 +++++++++++++++++++ src/test/java/steps/SendChatSteps.java | 12 +++++++-- 6 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 src/test/java/seng302/utilities/SoundsTest.java diff --git a/src/main/java/seng302/utilities/Sounds.java b/src/main/java/seng302/utilities/Sounds.java index b0bd2209..944fa93f 100644 --- a/src/main/java/seng302/utilities/Sounds.java +++ b/src/main/java/seng302/utilities/Sounds.java @@ -26,7 +26,9 @@ public class Sounds { } } - public static void setMutes() { + + + static void setMutes() { if (soundPlayer != null) { soundPlayer.setMute(soundEffectsMuted); } @@ -49,14 +51,14 @@ public class Sounds { toggleMuteMusic(); } - public static void toggleMuteMusic() { + static void toggleMuteMusic() { musicMuted = !musicMuted; if (musicPlayer != null) { musicPlayer.setMute(musicMuted); } } - public static void toggleMuteEffects() { + static void toggleMuteEffects() { soundEffectsMuted = !soundEffectsMuted; if (soundPlayer != null) { soundPlayer.setMute(soundEffectsMuted); @@ -188,5 +190,4 @@ public class Sounds { } } - } diff --git a/src/main/java/seng302/visualiser/controllers/RaceViewController.java b/src/main/java/seng302/visualiser/controllers/RaceViewController.java index 87235ca7..15a81311 100644 --- a/src/main/java/seng302/visualiser/controllers/RaceViewController.java +++ b/src/main/java/seng302/visualiser/controllers/RaceViewController.java @@ -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; @@ -171,6 +173,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() { + @Override + public void changed(ObservableValue observable, Boolean oldValue, + Boolean newValue) { + if (newValue) { + chatHistory.increaseOpacity(); + } else { + chatHistory.decreaseOpacity(); + } + } + }); } public void loadRace ( diff --git a/src/main/java/seng302/visualiser/controllers/dialogs/ServerCreationController.java b/src/main/java/seng302/visualiser/controllers/dialogs/ServerCreationController.java index ffa64356..df424567 100644 --- a/src/main/java/seng302/visualiser/controllers/dialogs/ServerCreationController.java +++ b/src/main/java/seng302/visualiser/controllers/dialogs/ServerCreationController.java @@ -6,6 +6,7 @@ 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; @@ -47,6 +48,7 @@ public class ServerCreationController implements Initializable { Sounds.playButtonClick(); validateServerSettings(); }); + } /** diff --git a/src/main/java/seng302/visualiser/fxObjects/ChatHistory.java b/src/main/java/seng302/visualiser/fxObjects/ChatHistory.java index 87e920a0..13f6f185 100644 --- a/src/main/java/seng302/visualiser/fxObjects/ChatHistory.java +++ b/src/main/java/seng302/visualiser/fxObjects/ChatHistory.java @@ -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) 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" + ); + } } diff --git a/src/test/java/seng302/utilities/SoundsTest.java b/src/test/java/seng302/utilities/SoundsTest.java new file mode 100644 index 00000000..efd22fa7 --- /dev/null +++ b/src/test/java/seng302/utilities/SoundsTest.java @@ -0,0 +1,25 @@ +package seng302.utilities; + +import static org.junit.Assert.assertEquals; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Used to test the muting functionality of the sounds util + * Created by kre39 on 12/09/17. + */ +public class SoundsTest { + + @Test + public void testMutes() throws Exception { + Sounds.setMutes(); + Assert.assertFalse(Sounds.isMusicMuted()); + Assert.assertFalse(Sounds.isSoundEffectsMuted()); + Sounds.toggleAllSounds(); + Sounds.toggleMuteEffects(); + Sounds.toggleMuteMusic(); + Assert.assertFalse(Sounds.isMusicMuted()); + Assert.assertFalse(Sounds.isSoundEffectsMuted()); + } +} diff --git a/src/test/java/steps/SendChatSteps.java b/src/test/java/steps/SendChatSteps.java index e9e1ff2e..b447217c 100644 --- a/src/test/java/steps/SendChatSteps.java +++ b/src/test/java/steps/SendChatSteps.java @@ -43,8 +43,11 @@ public class SendChatSteps { ie.printStackTrace(); } mst.startGame(); - Thread.sleep(200); - } + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } } @When("^the first client has sent the message \"([^\"]*)\"$") @@ -54,6 +57,11 @@ public class SendChatSteps { @Then("^the other client should receive the message \"([^\"]*)\"$") public void the_other_client_should_receive_the_message(String arg1) throws Throwable { + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } Object[] packets = host.getPacketQueue().toArray(); Pair message = StreamParser.extractChatterText((StreamPacket) packets[packets.length - 1]); Assert.assertEquals("[time_prefix] " + arg1, message.getValue());