From 1290f43312ad6ef8ade76f255a13a7ce0c7cb179 Mon Sep 17 00:00:00 2001 From: BlackYps Date: Mon, 19 Aug 2024 19:27:56 +0200 Subject: [PATCH 1/3] Improve log messages --- .../client/teammatchmaking/TeamMatchmakingService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java b/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java index 947ddc387f..cf2ca36c84 100644 --- a/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java +++ b/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java @@ -398,7 +398,7 @@ public CompletableFuture joinQueues() { } if (!Objects.equals(party.getOwner(), playerService.getCurrentPlayer())) { - log.debug("Not party owner cannot join queues"); + log.debug("Not party owner, cannot join queues"); notificationService.addImmediateWarnNotification("teammatchmaking.notification.notPartyOwner.message"); return CompletableFuture.completedFuture(false); } @@ -423,7 +423,7 @@ public CompletableFuture joinQueues() { public void leaveQueues() { if (!Objects.equals(party.getOwner(), playerService.getCurrentPlayer())) { - log.debug("Not party owner cannot join queues"); + log.debug("Not party owner, cannot leave queues"); notificationService.addImmediateWarnNotification("teammatchmaking.notification.notPartyOwner.message"); return; } From 0f79f6fa66f811164ed473bd321719cc2afc5815 Mon Sep 17 00:00:00 2001 From: BlackYps Date: Mon, 19 Aug 2024 22:03:26 +0200 Subject: [PATCH 2/3] search notification message WIP --- .../domain/server/MatchmakerQueueInfo.java | 12 +++++++ .../TeamMatchmakingService.java | 24 +++++++++++++ .../ui/statusbar/StatusBarController.java | 36 +++++++++++++++++++ src/main/resources/i18n/messages.properties | 1 + .../resources/theme/statusbar/status_bar.fxml | 5 +++ 5 files changed, 78 insertions(+) diff --git a/src/main/java/com/faforever/client/domain/server/MatchmakerQueueInfo.java b/src/main/java/com/faforever/client/domain/server/MatchmakerQueueInfo.java index be77e83dfe..67d9ca1895 100644 --- a/src/main/java/com/faforever/client/domain/server/MatchmakerQueueInfo.java +++ b/src/main/java/com/faforever/client/domain/server/MatchmakerQueueInfo.java @@ -10,10 +10,13 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import lombok.EqualsAndHashCode; import lombok.ToString; import java.time.OffsetDateTime; +import java.util.List; @EqualsAndHashCode(onlyExplicitlyIncluded = true) @ToString(callSuper = true, onlyExplicitlyIncluded = true) @@ -30,6 +33,7 @@ public class MatchmakerQueueInfo { private final BooleanProperty selected = new SimpleBooleanProperty(true); private final ObjectProperty matchingStatus = new SimpleObjectProperty<>(); private final ObjectProperty leaderboard = new SimpleObjectProperty<>(); + private final ObservableList activeRatingGroups = FXCollections.observableArrayList(); public Integer getId() { return id.get(); @@ -138,4 +142,12 @@ public void setSelected(boolean selected) { public BooleanProperty selectedProperty() { return selected; } + + public ObservableList getActiveRatingGroups() { + return activeRatingGroups; + } + + public void setActiveRatingGroups(List activeRatingGroups) { + this.activeRatingGroups.setAll(activeRatingGroups); + } } diff --git a/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java b/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java index cf2ca36c84..1f1380f86e 100644 --- a/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java +++ b/src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingService.java @@ -3,6 +3,7 @@ import com.faforever.client.api.FafApiAccessor; import com.faforever.client.audio.AudioService; import com.faforever.client.chat.ChatService; +import com.faforever.client.domain.api.Leaderboard; import com.faforever.client.domain.server.MatchmakerQueueInfo; import com.faforever.client.domain.server.PartyInfo; import com.faforever.client.domain.server.PartyInfo.PartyMember; @@ -27,6 +28,7 @@ import com.faforever.client.notification.PersistentNotification; import com.faforever.client.notification.Severity; import com.faforever.client.notification.TransientNotification; +import com.faforever.client.player.LeaderboardRating; import com.faforever.client.player.PlayerService; import com.faforever.client.player.ServerStatus; import com.faforever.client.preferences.MatchmakerPrefs; @@ -121,6 +123,7 @@ public class TeamMatchmakingService implements InitializingBean { private final ObservableList queues = JavaFxUtil.attachListToMap( FXCollections.synchronizedObservableList(FXCollections.observableArrayList( queue -> new Observable[]{queue.selectedProperty(), queue.matchingStatusProperty()})), nameToQueue); + private final FilteredList queuesWithPotentialMatches = new FilteredList<>(queues, this::queueHasPotentialMatch); private final FilteredList selectedQueues = new FilteredList<>(queues, MatchmakerQueueInfo::isSelected); private final FilteredList validQueues = new FilteredList<>(selectedQueues); @@ -247,6 +250,27 @@ public void afterPropertiesSet() throws Exception { partyMembersNotReady.bind(playersInGame.emptyProperty().map(empty -> !empty)); } + public ObservableList getQueuesWithPotentialMatches() { + return queuesWithPotentialMatches; + } + + private boolean queueHasPotentialMatch(MatchmakerQueueInfo queue) { + LeaderboardRating rating = playerService.getCurrentPlayer().getLeaderboardRatings().get(queue.getLeaderboard().technicalName()); + return queue.getActiveRatingGroups() + .stream() + .anyMatch(activeRating -> couldMatch(activeRating, rating, queue.getLeaderboard())); + } + + private static boolean couldMatch(Integer otherRating, LeaderboardRating rating, Leaderboard leaderboard) { + log.info("triggered"); + // 1v1 uses a different way of matching people. + if (Objects.equals(leaderboard.technicalName(), "ladder_1v1")) { + return Math.abs(otherRating - rating.mean()) < 100; + } else { + return Math.abs(otherRating - rating.mean() - 3 * rating.deviation()) < 100; + } + } + private void sendFactions() { sendFactionSelection(matchmakerPrefs.getFactions()); } diff --git a/src/main/java/com/faforever/client/ui/statusbar/StatusBarController.java b/src/main/java/com/faforever/client/ui/statusbar/StatusBarController.java index 536f508d0e..bc75162ee6 100644 --- a/src/main/java/com/faforever/client/ui/statusbar/StatusBarController.java +++ b/src/main/java/com/faforever/client/ui/statusbar/StatusBarController.java @@ -1,6 +1,7 @@ package com.faforever.client.ui.statusbar; import com.faforever.client.chat.ChatService; +import com.faforever.client.domain.server.MatchmakerQueueInfo; import com.faforever.client.fx.FxApplicationThreadExecutor; import com.faforever.client.fx.JavaFxUtil; import com.faforever.client.fx.NodeController; @@ -8,6 +9,7 @@ import com.faforever.client.i18n.I18n; import com.faforever.client.net.ConnectionState; import com.faforever.client.task.TaskService; +import com.faforever.client.teammatchmaking.TeamMatchmakingService; import com.faforever.client.update.Version; import com.faforever.client.user.LoginService; import com.google.common.base.Strings; @@ -16,6 +18,7 @@ import javafx.concurrent.Worker; import javafx.css.PseudoClass; import javafx.scene.Node; +import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.MenuButton; import javafx.scene.control.ProgressBar; @@ -27,6 +30,7 @@ import org.springframework.stereotype.Component; import java.util.Collection; +import java.util.List; @Component @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @@ -39,6 +43,7 @@ public class StatusBarController extends NodeController { private final I18n i18n; private final ChatService chatService; private final TaskService taskService; + private final TeamMatchmakingService teamMatchmakingService; private final FxApplicationThreadExecutor fxApplicationThreadExecutor; public Label chatConnectionStatusIcon; @@ -50,6 +55,11 @@ public class StatusBarController extends NodeController { public Label taskProgressLabel; public Label versionLabel; public HBox root; + public HBox messagePane; + public Label messageText; + public Button joinButton; + + private MatchmakerQueueInfo queueToJoin; @Override protected void onInitialize() { @@ -100,6 +110,17 @@ protected void onInitialize() { setCurrentWorkerInStatusBar(runningWorkers.iterator().next()); } }); + + JavaFxUtil.addListener(teamMatchmakingService.getQueuesWithPotentialMatches(), (Observable observable) -> { + // Can't we use the observable list directly? Why do we have to make the call again? + List queues = teamMatchmakingService.getQueuesWithPotentialMatches(); + if (queues.isEmpty()) { + queueToJoin = null; + } else { + queueToJoin = queues.getFirst(); + } + showJoinQueueButton(); + }); } @Override @@ -135,6 +156,21 @@ private void setCurrentWorkerInStatusBar(Worker worker) { }); } + private void showJoinQueueButton() { + if (queueToJoin == null) { + messagePane.setVisible(false); + return; + } + messagePane.setVisible(true); + messageText.setText(i18n.get("teammatchmaking.notification.queueMatchPotential", queueToJoin.getTeamSize())); + } + + public void onJoinQueueClicked() { + queueToJoin.setSelected(true); + teamMatchmakingService.joinQueues(); + //switch tab to matchmaker + } + public void onFafReconnectClicked() { loginService.reconnectToLobby(); } diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index 9b217afa3d..02d537020d 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -997,6 +997,7 @@ teammatchmaking.notification.gameAlreadyRunning.title = Already in game teammatchmaking.notification.gameAlreadyRunning.message = You cannot join matchmaking while you're in game teammatchmaking.notification.hostIsOffline.title = Host is offline teammatchmaking.notification.hostIsOffline.message = You cannot accept party invitation while the host is offline +teammatchmaking.notification.queueMatchPotential = Someone near your skill level is searching for a {0,number,#}v{0,number,#} match. Click here to join the queue as well teammatchmaking.playerTitle = Playing matchmaking as\: teammatchmaking.partyTitle = Your party\: teammatchmaking.queueTitle = Join one or more queues when you are ready\: diff --git a/src/main/resources/theme/statusbar/status_bar.fxml b/src/main/resources/theme/statusbar/status_bar.fxml index acbecde697..12562f962b 100644 --- a/src/main/resources/theme/statusbar/status_bar.fxml +++ b/src/main/resources/theme/statusbar/status_bar.fxml @@ -1,6 +1,7 @@ + @@ -28,6 +29,10 @@ + +