Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Sound for match found #3216

Merged
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 isMatchFoundSoundEnabled = new SimpleBooleanProperty(true);

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

public void setIsMatchFoundSoundEnabled(boolean isMatchFoundSoundEnabled) {
this.isMatchFoundSoundEnabled.set(isMatchFoundSoundEnabled);
}

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

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.isMatchFoundSoundEnabledProperty());
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 @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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")));
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.setIsMatchFoundSoundEnabled(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.setIsMatchFoundSoundEnabled(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));
}
}
Loading