From 106315a2ded20d8a1fad4f59fbaa487755bcb6d6 Mon Sep 17 00:00:00 2001 From: SimonB Date: Tue, 25 Jun 2024 15:33:37 +0100 Subject: [PATCH 1/7] - Added new sound to play when match is found notification is triggered. - Added tests and fixed existing typo in test. --- .../com/faforever/client/audio/AudioService.java | 12 ++++++++++++ .../client/preferences/NotificationPrefs.java | 9 +++++++++ .../teammatchmaking/TeamMatchmakingService.java | 8 ++++++++ .../faforever/client/audio/AudioServiceTest.java | 13 ++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/faforever/client/audio/AudioService.java b/src/main/java/com/faforever/client/audio/AudioService.java index a07846a341..0840bde9c4 100644 --- a/src/main/java/com/faforever/client/audio/AudioService.java +++ b/src/main/java/com/faforever/client/audio/AudioService.java @@ -27,6 +27,7 @@ public class AudioService implements InitializingBean { private static final String FRIEND_OFFLINE_SOUND = "theme/sounds/friendOfflineSound.mp3"; private static final String FRIEND_JOINS_GAME_SOUND = "theme/sounds/friendJoinsGameSound.mp3"; private static final String FRIEND_PLAYS_GAME_SOUND = "theme/sounds/friendPlaysGameSound.mp3"; + private static final String MATCH_FOUND_SOUND = "theme/sounds/friendPlaysGameSound.mp3"; private final AudioClipPlayer audioClipPlayer; private final ThemeService themeService; @@ -44,6 +45,7 @@ public class AudioService implements InitializingBean { private AudioClip friendOfflineSound; private AudioClip friendJoinsGameSound; private AudioClip friendPlaysGameSound; + private AudioClip playMatchFoundSound; private long lastPlayedSoundTime; @@ -65,6 +67,7 @@ private void loadSounds() throws IOException { friendOfflineSound = loadSound(FRIEND_OFFLINE_SOUND); friendJoinsGameSound = loadSound(FRIEND_JOINS_GAME_SOUND); friendPlaysGameSound = loadSound(FRIEND_PLAYS_GAME_SOUND); + playMatchFoundSound = loadSound(FRIEND_PLAYS_GAME_SOUND); } private AudioClip loadSound(String sound) throws IOException { @@ -148,6 +151,15 @@ public void playFriendPlaysGameSound() { playSound(friendPlaysGameSound); } + + public void playMatchFoundSound() { + if (!notificationPrefs.isMatchFoundSoundEnabled()) { + return; + } + playSound(friendPlaysGameSound); + } + + private void playSound(AudioClip audioClip) { if (!playSounds.get()) { return; diff --git a/src/main/java/com/faforever/client/preferences/NotificationPrefs.java b/src/main/java/com/faforever/client/preferences/NotificationPrefs.java index 838760bf11..0a541776cc 100644 --- a/src/main/java/com/faforever/client/preferences/NotificationPrefs.java +++ b/src/main/java/com/faforever/client/preferences/NotificationPrefs.java @@ -32,6 +32,7 @@ public class NotificationPrefs { private final IntegerProperty toastDisplayTime = new SimpleIntegerProperty(5000); private final IntegerProperty silenceBetweenSounds = new SimpleIntegerProperty(30000); private final BooleanProperty afterGameReviewEnabled = new SimpleBooleanProperty(true); + private final BooleanProperty isMatchFoundSoundEnabled = new SimpleBooleanProperty(true); public boolean isSoundsEnabled() { return soundsEnabled.get(); @@ -285,6 +286,14 @@ public BooleanProperty afterGameReviewEnabledProperty() { return afterGameReviewEnabled; } + public void setIsMatchFoundSoundEnabled(boolean isMatchFoundSoundEnabled) { + this.isMatchFoundSoundEnabled.set(isMatchFoundSoundEnabled); + } + + public boolean isMatchFoundSoundEnabled() { + return isMatchFoundSoundEnabled.get(); + } + public int getSilenceBetweenSounds() { return silenceBetweenSounds.get(); } diff --git a/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java b/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java index 00b6a0ae8a..625d80668a 100644 --- a/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java +++ b/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java @@ -1,6 +1,7 @@ package com.faforever.client.teammatchmaking; import com.faforever.client.api.FafApiAccessor; +import com.faforever.client.audio.AudioService; import com.faforever.client.chat.ChatService; import com.faforever.client.domain.server.MatchmakerQueueInfo; import com.faforever.client.domain.server.PartyInfo; @@ -29,6 +30,7 @@ import com.faforever.client.player.PlayerService; import com.faforever.client.player.ServerStatus; import com.faforever.client.preferences.MatchmakerPrefs; +import com.faforever.client.preferences.NotificationPrefs; import com.faforever.client.preferences.PreferencesService; import com.faforever.client.remote.FafServerAccessor; import com.faforever.client.user.LoginService; @@ -110,6 +112,8 @@ public class TeamMatchmakingService implements InitializingBean { private final MatchmakerMapper matchmakerMapper; private final MatchmakerPrefs matchmakerPrefs; private final GamePathHandler gamePathHandler; + private final AudioService audioService; + private final NotificationPrefs notificationPrefs; @Getter private final PartyInfo party = new PartyInfo(); @@ -342,6 +346,10 @@ private void setTimedOutMatchingStatus(MatchmakerQueueInfo queue, MatchingStatus } private void notifyMatchFound() { + if (notificationPrefs.isMatchFoundSoundEnabled()) { + audioService.playMatchFoundSound(); + } + notificationService.addNotification( new TransientNotification(i18n.get("teammatchmaking.notification.matchFound.title"), i18n.get("teammatchmaking.notification.matchFound.message"))); diff --git a/src/test/java/com/faforever/client/audio/AudioServiceTest.java b/src/test/java/com/faforever/client/audio/AudioServiceTest.java index 960652e03b..eb90520dd5 100644 --- a/src/test/java/com/faforever/client/audio/AudioServiceTest.java +++ b/src/test/java/com/faforever/client/audio/AudioServiceTest.java @@ -49,6 +49,7 @@ public void setUp() throws Exception { notificationPrefs.setFriendOnlineSoundEnabled(true); notificationPrefs.setFriendPlaysGameSoundEnabled(true); notificationPrefs.setFriendOfflineSoundEnabled(true); + notificationPrefs.setIsMatchFoundSoundEnabled(true); notificationPrefs.setSilenceBetweenSounds(SILENCE_BETWEEN_SOUNDS); instance.afterPropertiesSet(); @@ -67,6 +68,7 @@ public void testNoSoundsWhenOff() { instance.playFriendOnlineSound(); instance.playFriendOfflineSound(); instance.playFriendPlaysGameSound(); + instance.playMatchFoundSound(); instance.playInfoNotificationSound(); verify(audioClipPlayer, never()).playSound(any()); } @@ -82,6 +84,7 @@ public void testNoSoundsWhenIndividuallyOff() { notificationPrefs.setFriendOnlineSoundEnabled(false); notificationPrefs.setFriendPlaysGameSoundEnabled(false); notificationPrefs.setPrivateMessageSoundEnabled(false); + notificationPrefs.setIsMatchFoundSoundEnabled(false); instance.playChatMentionSound(); instance.playPrivateMessageSound(); instance.playInfoNotificationSound(); @@ -92,6 +95,7 @@ public void testNoSoundsWhenIndividuallyOff() { instance.playFriendOfflineSound(); instance.playFriendPlaysGameSound(); instance.playInfoNotificationSound(); + instance.playMatchFoundSound(); verify(audioClipPlayer, never()).playSound(any()); } @@ -164,9 +168,16 @@ public void testPlayFriendPlaysGameSound() { } @Test - public void testPlayFriendJoinsGamSound() { + public void testPlayFriendJoinsGameSound() { instance.playFriendJoinsGameSound(); verify(audioClipPlayer).playSound(any(AudioClip.class)); } + + @Test + public void testMatchFoundSoundPlays() { + instance.playMatchFoundSound(); + + verify(audioClipPlayer).playSound(any(AudioClip.class)); + } } From d622700b018320c3b7181ed1b4d77e87b91b65d1 Mon Sep 17 00:00:00 2001 From: SimonB Date: Tue, 25 Jun 2024 15:33:53 +0100 Subject: [PATCH 2/7] - Prefs UI update for new sound - Labels --- .../client/preferences/ui/SettingsController.java | 2 ++ src/main/resources/i18n/messages.properties | 1 + src/main/resources/theme/settings/settings.fxml | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/faforever/client/preferences/ui/SettingsController.java b/src/main/java/com/faforever/client/preferences/ui/SettingsController.java index 1a9b651a32..63ffd52904 100644 --- a/src/main/java/com/faforever/client/preferences/ui/SettingsController.java +++ b/src/main/java/com/faforever/client/preferences/ui/SettingsController.java @@ -140,6 +140,8 @@ public class SettingsController extends NodeController { public CheckBox playFriendJoinsGameSoundCheckBox; public CheckBox playFriendPlaysGameSoundCheckBox; public CheckBox displayPmReceivedToastCheckBox; + public CheckBox displayMatchFoundSoundCheckBox; + public CheckBox playMatchFoundSoundCheckBox; public CheckBox playPmReceivedSoundCheckBox; public CheckBox afterGameReviewCheckBox; public CheckBox disableSteamStartCheckBox; diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index a106dea2a3..9b217afa3d 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -451,6 +451,7 @@ settings.notifications.toastPosition = Toast position settings.notifications.toastScreen = Screen settings.notifications.playSound = Play sound settings.notifications.pmReceived = PM received +settings.notifications.matchFound = Match Found settings.notifications.ranked1v1 = Ranked 1v1 available settings.sounds = Sounds settings.sounds.enable = Enable Sounds diff --git a/src/main/resources/theme/settings/settings.fxml b/src/main/resources/theme/settings/settings.fxml index 95b15b14e2..992aea89f7 100644 --- a/src/main/resources/theme/settings/settings.fxml +++ b/src/main/resources/theme/settings/settings.fxml @@ -596,8 +596,17 @@ GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="5" GridPane.valignment="CENTER"/>