Skip to content

Commit

Permalink
Feature: Sound for match found (#3216)
Browse files Browse the repository at this point in the history
* - Added new sound to play when match is found notification is triggered.
- Added tests and fixed existing typo in test.

* - Prefs UI update for new sound
- Labels

* - Prefs UI update for new sound
- Labels and checkboxes. Added disabled+Selected 'Display Notification When Match Found' since it should always remain on.

* - Update AudioService to use the right file.
- Add new sound file

* - Using Audio file from existing issue.
- Removed superfluous check
- Added audioService mock to the test, making them pass.
- Renamed the preference to be more in line with the existing values.

* revert matchFoundSound.mp3 file to the more 'kind' beepbeepboop start sound.

* new, softer sound

---------

Co-authored-by: SimonB <[email protected]>
  • Loading branch information
DotNetSimon and Trenair committed Jun 28, 2024
1 parent 1fc2fbb commit ff1b47c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/faforever/client/audio/AudioService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/matchFoundSound.mp3";

private final AudioClipPlayer audioClipPlayer;
private final ThemeService themeService;
Expand All @@ -44,6 +45,7 @@ public class AudioService implements InitializingBean {
private AudioClip friendOfflineSound;
private AudioClip friendJoinsGameSound;
private AudioClip friendPlaysGameSound;
private AudioClip playMatchFoundSound;

private long lastPlayedSoundTime;

Expand All @@ -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(MATCH_FOUND_SOUND);
}

private AudioClip loadSound(String sound) throws IOException {
Expand Down Expand Up @@ -148,6 +151,15 @@ public void playFriendPlaysGameSound() {
playSound(friendPlaysGameSound);
}


public void playMatchFoundSound() {
if (!notificationPrefs.isMatchFoundSoundEnabled()) {
return;
}
playSound(playMatchFoundSound);
}


private void playSound(AudioClip audioClip) {
if (!playSounds.get()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 matchFoundSoundEnabled = new SimpleBooleanProperty(true);

public boolean isSoundsEnabled() {
return soundsEnabled.get();
Expand Down Expand Up @@ -285,6 +286,17 @@ public BooleanProperty afterGameReviewEnabledProperty() {
return afterGameReviewEnabled;
}

public void setMatchFoundSoundEnabled(boolean matchFoundSoundEnabled) {
this.matchFoundSoundEnabled.set(matchFoundSoundEnabled);
}

public boolean isMatchFoundSoundEnabled() {
return matchFoundSoundEnabled.get();
}
public BooleanProperty matchFoundSoundEnabledProperty() {
return matchFoundSoundEnabled;
}

public int getSilenceBetweenSounds() {
return silenceBetweenSounds.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public class SettingsController extends NodeController<Node> {
public CheckBox playFriendJoinsGameSoundCheckBox;
public CheckBox playFriendPlaysGameSoundCheckBox;
public CheckBox displayPmReceivedToastCheckBox;
public CheckBox displayMatchFoundNotificationCheckBox;
public CheckBox playMatchFoundSoundCheckBox;
public CheckBox playPmReceivedSoundCheckBox;
public CheckBox afterGameReviewCheckBox;
public CheckBox disableSteamStartCheckBox;
Expand Down Expand Up @@ -395,6 +397,9 @@ private void bindNotificationPreferences() {
.bindBidirectional(notificationPrefs.friendPlaysGameSoundEnabledProperty());
playPmReceivedSoundCheckBox.selectedProperty()
.bindBidirectional(notificationPrefs.privateMessageSoundEnabledProperty());
displayMatchFoundNotificationCheckBox.selectedProperty().setValue(true);
playMatchFoundSoundCheckBox.selectedProperty()
.bindBidirectional(notificationPrefs.matchFoundSoundEnabledProperty());
afterGameReviewCheckBox.selectedProperty().bindBidirectional(notificationPrefs.afterGameReviewEnabledProperty());
notifyOnAtMentionOnlyToggle.selectedProperty()
.bindBidirectional(notificationPrefs.notifyOnAtMentionOnlyEnabledProperty());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -110,6 +111,7 @@ public class TeamMatchmakingService implements InitializingBean {
private final MatchmakerMapper matchmakerMapper;
private final MatchmakerPrefs matchmakerPrefs;
private final GamePathHandler gamePathHandler;
private final AudioService audioService;

@Getter
private final PartyInfo party = new PartyInfo();
Expand Down Expand Up @@ -342,6 +344,8 @@ private void setTimedOutMatchingStatus(MatchmakerQueueInfo queue, MatchingStatus
}

private void notifyMatchFound() {
audioService.playMatchFoundSound();

notificationService.addNotification(
new TransientNotification(i18n.get("teammatchmaking.notification.matchFound.title"),
i18n.get("teammatchmaking.notification.matchFound.message")));
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/main/resources/theme/settings/settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,21 @@
GridPane.columnIndex="2" GridPane.halignment="CENTER"
GridPane.rowIndex="5" GridPane.valignment="CENTER"/>
<Label styleClass="setting-title"
text="%settings.notifications.afterGameReview"
text="%settings.notifications.matchFound"
GridPane.rowIndex="6"/>
<CheckBox fx:id="afterGameReviewCheckBox" mnemonicParsing="false"
<CheckBox fx:id="displayMatchFoundNotificationCheckBox" mnemonicParsing="false"
disable="true"
GridPane.columnIndex="1" GridPane.halignment="CENTER"
GridPane.rowIndex="6" GridPane.valignment="CENTER"/>
<CheckBox fx:id="playMatchFoundSoundCheckBox" mnemonicParsing="false"
GridPane.columnIndex="2" GridPane.halignment="CENTER"
GridPane.rowIndex="6" GridPane.valignment="CENTER"/>
<Label styleClass="setting-title"
text="%settings.notifications.afterGameReview"
GridPane.rowIndex="7"/>
<CheckBox fx:id="afterGameReviewCheckBox" mnemonicParsing="false"
GridPane.columnIndex="1" GridPane.halignment="CENTER"
GridPane.rowIndex="7" GridPane.valignment="CENTER"/>
</children>
</GridPane>
</children>
Expand Down
Binary file not shown.
13 changes: 12 additions & 1 deletion src/test/java/com/faforever/client/audio/AudioServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void setUp() throws Exception {
notificationPrefs.setFriendOnlineSoundEnabled(true);
notificationPrefs.setFriendPlaysGameSoundEnabled(true);
notificationPrefs.setFriendOfflineSoundEnabled(true);
notificationPrefs.setMatchFoundSoundEnabled(true);
notificationPrefs.setSilenceBetweenSounds(SILENCE_BETWEEN_SOUNDS);

instance.afterPropertiesSet();
Expand All @@ -67,6 +68,7 @@ public void testNoSoundsWhenOff() {
instance.playFriendOnlineSound();
instance.playFriendOfflineSound();
instance.playFriendPlaysGameSound();
instance.playMatchFoundSound();
instance.playInfoNotificationSound();
verify(audioClipPlayer, never()).playSound(any());
}
Expand All @@ -82,6 +84,7 @@ public void testNoSoundsWhenIndividuallyOff() {
notificationPrefs.setFriendOnlineSoundEnabled(false);
notificationPrefs.setFriendPlaysGameSoundEnabled(false);
notificationPrefs.setPrivateMessageSoundEnabled(false);
notificationPrefs.setMatchFoundSoundEnabled(false);
instance.playChatMentionSound();
instance.playPrivateMessageSound();
instance.playInfoNotificationSound();
Expand All @@ -92,6 +95,7 @@ public void testNoSoundsWhenIndividuallyOff() {
instance.playFriendOfflineSound();
instance.playFriendPlaysGameSound();
instance.playInfoNotificationSound();
instance.playMatchFoundSound();
verify(audioClipPlayer, never()).playSound(any());
}

Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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.builders.GameInfoBuilder;
import com.faforever.client.builders.GameLaunchMessageBuilder;
import com.faforever.client.builders.PartyInfoBuilder.PartyMemberBuilder;
Expand Down Expand Up @@ -119,6 +120,8 @@ public class TeamMatchmakingServiceTest extends ServiceTest {
private GameRunner gameRunner;
@Mock
private NavigationHandler navigationHandler;
@Mock
private AudioService audioService;
@Spy
private MatchmakerPrefs matchmakerPrefs = new MatchmakerPrefs();

Expand All @@ -141,7 +144,6 @@ public class TeamMatchmakingServiceTest extends ServiceTest {
private final TestPublisher<GameLaunchResponse> gameLaunchResponseTestPublisher = TestPublisher.create();
private final SimpleObjectProperty<ConnectionState> connectionState = new SimpleObjectProperty<>(
ConnectionState.DISCONNECTED);
;

@BeforeEach
public void setUp() throws Exception {
Expand Down

0 comments on commit ff1b47c

Please sign in to comment.