Search in sources :

Example 1 with TransientNotification

use of com.faforever.client.notification.TransientNotification in project downlords-faf-client by FAForever.

the class FriendJoinedGameNotifierTest method onFriendJoinedGame.

@Test
public void onFriendJoinedGame() throws Exception {
    Game game = GameBuilder.create().defaultValues().title("My Game").get();
    Player player = PlayerBuilder.create("junit").id(1).game(game).get();
    when(notification.isFriendJoinsGameToastEnabled()).thenReturn(true);
    when(i18n.get("friend.joinedGameNotification.title", "junit", "My Game")).thenReturn("junit joined My Game");
    when(i18n.get("friend.joinedGameNotification.action")).thenReturn("Click to join");
    instance.onFriendJoinedGame(new FriendJoinedGameEvent(player, game));
    ArgumentCaptor<TransientNotification> captor = ArgumentCaptor.forClass(TransientNotification.class);
    verify(notificationService).addNotification(captor.capture());
    TransientNotification notification = captor.getValue();
    assertThat(notification.getTitle(), is("junit joined My Game"));
    assertThat(notification.getText(), is("Click to join"));
    assertThat(notification.getImage(), notNullValue());
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) Game(com.faforever.client.game.Game) FriendJoinedGameEvent(com.faforever.client.player.event.FriendJoinedGameEvent) Test(org.junit.Test)

Example 2 with TransientNotification

use of com.faforever.client.notification.TransientNotification in project downlords-faf-client by FAForever.

the class AchievementUnlockedNotifierTest method newlyUnlocked.

@Test
public void newlyUnlocked() throws Exception {
    AchievementDefinition achievementDefinition = new AchievementDefinition();
    achievementDefinition.setType(AchievementType.STANDARD);
    achievementDefinition.setName("Test Achievement");
    when(achievementService.getImage(achievementDefinition, UNLOCKED)).thenReturn(mock(Image.class));
    triggerUpdatedAchievementsMessage(achievementDefinition, true);
    verify(audioService).playAchievementUnlockedSound();
    ArgumentCaptor<TransientNotification> notificationCaptor = ArgumentCaptor.forClass(TransientNotification.class);
    verify(notificationService).addNotification(notificationCaptor.capture());
    TransientNotification notification = notificationCaptor.getValue();
    assertThat(notification.getImage(), notNullValue());
    assertThat(notification.getTitle(), is("Achievement unlocked"));
    assertThat(notification.getText(), is("Test Achievement"));
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) Image(javafx.scene.image.Image) AchievementDefinition(com.faforever.client.api.dto.AchievementDefinition) Test(org.junit.Test)

Example 3 with TransientNotification

use of com.faforever.client.notification.TransientNotification in project downlords-faf-client by FAForever.

the class AchievementUnlockedNotifier method notifyAboutUnlockedAchievement.

private void notifyAboutUnlockedAchievement(AchievementDefinition achievementDefinition) {
    if (lastSoundPlayed < System.currentTimeMillis() - 1000) {
        audioService.playAchievementUnlockedSound();
        lastSoundPlayed = System.currentTimeMillis();
    }
    notificationService.addNotification(new TransientNotification(i18n.get("achievement.unlockedTitle"), achievementDefinition.getName(), achievementService.getImage(achievementDefinition, AchievementState.UNLOCKED)));
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification)

Example 4 with TransientNotification

use of com.faforever.client.notification.TransientNotification in project downlords-faf-client by FAForever.

the class OnGameFullNotifier method onGameFull.

@Subscribe
public void onGameFull(GameFullEvent event) {
    executor.execute(() -> {
        platformService.startFlashingWindow(faWindowTitle);
        while (gameService.isGameRunning() && !platformService.isWindowFocused(faWindowTitle)) {
            noCatch(() -> sleep(500));
        }
        platformService.stopFlashingWindow(faWindowTitle);
    });
    Game currentGame = gameService.getCurrentGame();
    if (currentGame == null) {
        throw new ProgrammingError("Got a GameFull notification but player is not in a game");
    }
    if (platformService.isWindowFocused(faWindowTitle)) {
        return;
    }
    notificationService.addNotification(new TransientNotification(i18n.get("game.full"), i18n.get("game.full.action"), mapService.loadPreview(currentGame.getMapFolderName(), PreviewSize.SMALL), v -> platformService.focusWindow(faWindowTitle)));
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) ClientProperties(com.faforever.client.config.ClientProperties) GameService(com.faforever.client.game.GameService) GameFullEvent(com.faforever.client.fa.relay.event.GameFullEvent) ProgrammingError(com.faforever.client.util.ProgrammingError) Executor(java.util.concurrent.Executor) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) PlatformService(com.faforever.client.fx.PlatformService) TransientNotification(com.faforever.client.notification.TransientNotification) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) Component(org.springframework.stereotype.Component) PostConstruct(javax.annotation.PostConstruct) Thread.sleep(java.lang.Thread.sleep) Subscribe(com.google.common.eventbus.Subscribe) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) Game(com.faforever.client.game.Game) Game(com.faforever.client.game.Game) ProgrammingError(com.faforever.client.util.ProgrammingError) Subscribe(com.google.common.eventbus.Subscribe)

Example 5 with TransientNotification

use of com.faforever.client.notification.TransientNotification in project downlords-faf-client by FAForever.

the class MainController method onMatchmakerMessage.

private void onMatchmakerMessage(MatchmakerMessage message) {
    if (message.getQueues() == null || gameService.gameRunningProperty().get() || !preferencesService.getPreferences().getNotification().getLadder1v1ToastEnabled() || !playerService.getCurrentPlayer().isPresent()) {
        return;
    }
    Player currentPlayer = playerService.getCurrentPlayer().get();
    int deviationFor80PercentQuality = (int) (ratingBeta / 2.5f);
    int deviationFor75PercentQuality = (int) (ratingBeta / 1.25f);
    float leaderboardRatingDeviation = currentPlayer.getLeaderboardRatingDeviation();
    Function<MatchmakerMessage.MatchmakerQueue, List<RatingRange>> ratingRangesSupplier;
    if (leaderboardRatingDeviation <= deviationFor80PercentQuality) {
        ratingRangesSupplier = MatchmakerMessage.MatchmakerQueue::getBoundary80s;
    } else if (leaderboardRatingDeviation <= deviationFor75PercentQuality) {
        ratingRangesSupplier = MatchmakerMessage.MatchmakerQueue::getBoundary75s;
    } else {
        return;
    }
    float leaderboardRatingMean = currentPlayer.getLeaderboardRatingMean();
    boolean showNotification = false;
    for (MatchmakerMessage.MatchmakerQueue matchmakerQueue : message.getQueues()) {
        if (!Objects.equals("ladder1v1", matchmakerQueue.getQueueName())) {
            continue;
        }
        List<RatingRange> ratingRanges = ratingRangesSupplier.apply(matchmakerQueue);
        for (RatingRange ratingRange : ratingRanges) {
            if (ratingRange.getMin() <= leaderboardRatingMean && leaderboardRatingMean <= ratingRange.getMax()) {
                showNotification = true;
                break;
            }
        }
    }
    if (!showNotification) {
        return;
    }
    notificationService.addNotification(new TransientNotification(i18n.get("ranked1v1.notification.title"), i18n.get("ranked1v1.notification.message"), uiService.getThemeImage(UiService.LADDER_1V1_IMAGE), event -> eventBus.post(new Open1v1Event())));
}
Also used : StageStyle(javafx.stage.StageStyle) MINIMIZE(com.faforever.client.fx.WindowController.WindowButtonType.MINIMIZE) GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) PseudoClass(javafx.css.PseudoClass) Open1v1Event(com.faforever.client.main.event.Open1v1Event) InvalidationListener(javafx.beans.InvalidationListener) NavigateEvent(com.faforever.client.main.event.NavigateEvent) WindowController(com.faforever.client.fx.WindowController) MAXIMIZE_RESTORE(com.faforever.client.fx.WindowController.WindowButtonType.MAXIMIZE_RESTORE) PlayerService(com.faforever.client.player.PlayerService) Path(java.nio.file.Path) Pane(javafx.scene.layout.Pane) ClientProperties(com.faforever.client.config.ClientProperties) SettingsController(com.faforever.client.preferences.ui.SettingsController) LoggedOutEvent(com.faforever.client.user.event.LoggedOutEvent) LoginController(com.faforever.client.login.LoginController) Rectangle2D(javafx.geometry.Rectangle2D) Platform.runLater(javafx.application.Platform.runLater) Collection(java.util.Collection) UpdateApplicationBadgeEvent(com.faforever.client.ui.tray.event.UpdateApplicationBadgeEvent) PersistentNotificationsController(com.faforever.client.notification.PersistentNotificationsController) TransientNotificationsController(com.faforever.client.notification.TransientNotificationsController) AbstractViewController(com.faforever.client.fx.AbstractViewController) Screen(javafx.stage.Screen) Observable(javafx.beans.Observable) NavigationItem(com.faforever.client.main.event.NavigationItem) Platform(javafx.application.Platform) Objects(java.util.Objects) Player(com.faforever.client.player.Player) StageHolder(com.faforever.client.ui.StageHolder) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ToggleButton(javafx.scene.control.ToggleButton) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) ObservableList(javafx.collections.ObservableList) Bounds(javafx.geometry.Bounds) PreferencesService(com.faforever.client.preferences.PreferencesService) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) AnchorLocation(javafx.stage.PopupWindow.AnchorLocation) SplashScreen(com.install4j.api.launcher.SplashScreen) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) PlatformService(com.faforever.client.fx.PlatformService) TransientNotification(com.faforever.client.notification.TransientNotification) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) GamePathHandler(com.faforever.client.game.GamePathHandler) NotificationService(com.faforever.client.notification.NotificationService) ClientUpdateService(com.faforever.client.update.ClientUpdateService) Subscribe(com.google.common.eventbus.Subscribe) Labeled(javafx.scene.control.Labeled) Modality(javafx.stage.Modality) Controller(com.faforever.client.fx.Controller) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) CLOSE(com.faforever.client.fx.WindowController.WindowButtonType.CLOSE) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) PersistentNotification(com.faforever.client.notification.PersistentNotification) Popup(javafx.stage.Popup) UnreadPrivateMessageEvent(com.faforever.client.chat.event.UnreadPrivateMessageEvent) ActionEvent(javafx.event.ActionEvent) ToggleGroup(javafx.scene.control.ToggleGroup) Component(org.springframework.stereotype.Component) UnreadNewsEvent(com.faforever.client.news.UnreadNewsEvent) RatingRange(com.faforever.client.remote.domain.RatingRange) Stage(javafx.stage.Stage) Severity(com.faforever.client.notification.Severity) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) WindowPrefs(com.faforever.client.preferences.WindowPrefs) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) Cache(com.google.common.cache.Cache) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) ImmediateNotificationController(com.faforever.client.notification.ImmediateNotificationController) Collections(java.util.Collections) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) Player(com.faforever.client.player.Player) Open1v1Event(com.faforever.client.main.event.Open1v1Event) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) TransientNotification(com.faforever.client.notification.TransientNotification) RatingRange(com.faforever.client.remote.domain.RatingRange) List(java.util.List) ObservableList(javafx.collections.ObservableList)

Aggregations

TransientNotification (com.faforever.client.notification.TransientNotification)9 I18n (com.faforever.client.i18n.I18n)5 NotificationService (com.faforever.client.notification.NotificationService)5 EventBus (com.google.common.eventbus.EventBus)5 Subscribe (com.google.common.eventbus.Subscribe)5 Inject (javax.inject.Inject)5 Component (org.springframework.stereotype.Component)4 AudioService (com.faforever.client.audio.AudioService)3 ClientProperties (com.faforever.client.config.ClientProperties)3 PlatformService (com.faforever.client.fx.PlatformService)3 Game (com.faforever.client.game.Game)3 NavigateEvent (com.faforever.client.main.event.NavigateEvent)3 NavigationItem (com.faforever.client.main.event.NavigationItem)3 PreferencesService (com.faforever.client.preferences.PreferencesService)3 IdenticonUtil (com.faforever.client.util.IdenticonUtil)3 NoCatch.noCatch (com.github.nocatch.NoCatch.noCatch)3 PostConstruct (javax.annotation.PostConstruct)3 Controller (com.faforever.client.fx.Controller)2 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)2 GameService (com.faforever.client.game.GameService)2