Search in sources :

Example 1 with Open1v1Event

use of com.faforever.client.main.event.Open1v1Event 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

UnreadPrivateMessageEvent (com.faforever.client.chat.event.UnreadPrivateMessageEvent)1 ClientProperties (com.faforever.client.config.ClientProperties)1 AbstractViewController (com.faforever.client.fx.AbstractViewController)1 Controller (com.faforever.client.fx.Controller)1 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)1 PlatformService (com.faforever.client.fx.PlatformService)1 WindowController (com.faforever.client.fx.WindowController)1 CLOSE (com.faforever.client.fx.WindowController.WindowButtonType.CLOSE)1 MAXIMIZE_RESTORE (com.faforever.client.fx.WindowController.WindowButtonType.MAXIMIZE_RESTORE)1 MINIMIZE (com.faforever.client.fx.WindowController.WindowButtonType.MINIMIZE)1 GamePathHandler (com.faforever.client.game.GamePathHandler)1 GameService (com.faforever.client.game.GameService)1 I18n (com.faforever.client.i18n.I18n)1 LoginController (com.faforever.client.login.LoginController)1 NavigateEvent (com.faforever.client.main.event.NavigateEvent)1 NavigationItem (com.faforever.client.main.event.NavigationItem)1 Open1v1Event (com.faforever.client.main.event.Open1v1Event)1 UnreadNewsEvent (com.faforever.client.news.UnreadNewsEvent)1 ImmediateNotification (com.faforever.client.notification.ImmediateNotification)1 ImmediateNotificationController (com.faforever.client.notification.ImmediateNotificationController)1