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

Add indicator when someone in your rating range is searching in matchmaker #3235

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -30,6 +33,7 @@ public class MatchmakerQueueInfo {
private final BooleanProperty selected = new SimpleBooleanProperty(true);
private final ObjectProperty<MatchingStatus> matchingStatus = new SimpleObjectProperty<>();
private final ObjectProperty<Leaderboard> leaderboard = new SimpleObjectProperty<>();
private final ObservableList<Integer> activeRatingGroups = FXCollections.observableArrayList();

public Integer getId() {
return id.get();
Expand Down Expand Up @@ -138,4 +142,12 @@ public void setSelected(boolean selected) {
public BooleanProperty selectedProperty() {
return selected;
}

public ObservableList<Integer> getActiveRatingGroups() {
return activeRatingGroups;
}

public void setActiveRatingGroups(List<Integer> activeRatingGroups) {
this.activeRatingGroups.setAll(activeRatingGroups);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -120,7 +122,8 @@ public class TeamMatchmakingService implements InitializingBean {
@Getter
private final ObservableList<MatchmakerQueueInfo> queues = JavaFxUtil.attachListToMap(
FXCollections.synchronizedObservableList(FXCollections.observableArrayList(
queue -> new Observable[]{queue.selectedProperty(), queue.matchingStatusProperty()})), nameToQueue);
queue -> new Observable[]{queue.selectedProperty(), queue.matchingStatusProperty(), queue.getActiveRatingGroups()})), nameToQueue);
private final FilteredList<MatchmakerQueueInfo> queuesWithPotentialMatches = new FilteredList<>(queues, this::queueHasPotentialMatch);
private final FilteredList<MatchmakerQueueInfo> selectedQueues = new FilteredList<>(queues,
MatchmakerQueueInfo::isSelected);
private final FilteredList<MatchmakerQueueInfo> validQueues = new FilteredList<>(selectedQueues);
Expand Down Expand Up @@ -247,6 +250,26 @@ public void afterPropertiesSet() throws Exception {
partyMembersNotReady.bind(playersInGame.emptyProperty().map(empty -> !empty));
}

public ObservableList<MatchmakerQueueInfo> 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) {
// 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());
}
Expand Down Expand Up @@ -398,7 +421,7 @@ public CompletableFuture<Boolean> 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);
}
Expand All @@ -423,7 +446,7 @@ public CompletableFuture<Boolean> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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;
import com.faforever.client.fx.SimpleChangeListener;
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;
Expand All @@ -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;
Expand All @@ -27,6 +30,7 @@
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
Expand All @@ -39,6 +43,7 @@ public class StatusBarController extends NodeController<Node> {
private final I18n i18n;
private final ChatService chatService;
private final TaskService taskService;
private final TeamMatchmakingService teamMatchmakingService;
private final FxApplicationThreadExecutor fxApplicationThreadExecutor;

public Label chatConnectionStatusIcon;
Expand All @@ -50,6 +55,11 @@ public class StatusBarController extends NodeController<Node> {
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() {
Expand Down Expand Up @@ -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<MatchmakerQueueInfo> queues = teamMatchmakingService.getQueuesWithPotentialMatches();
if (queues.isEmpty()) {
queueToJoin = null;
} else {
queueToJoin = queues.getFirst();
}
showJoinQueueButton();
});
}

@Override
Expand Down Expand Up @@ -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();
}
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 @@ -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\:
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/theme/statusbar/status_bar.fxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuButton?>
<?import javafx.scene.control.MenuItem?>
Expand Down Expand Up @@ -28,6 +29,10 @@
<ProgressBar fx:id="taskProgressBar" minWidth="80.0" prefWidth="160.0"/>
</children>
</HBox>
<HBox fx:id="messagePane" alignment="CENTER_LEFT" spacing="20.0">
<Label fx:id="messageText" />
<Button fx:id="joinButton" styleClass="tmm, invite-button" text="%game.join" onAction="#onJoinQueueClicked"/>
</HBox>
<Separator orientation="VERTICAL" />
<MenuButton fx:id="fafConnectionButton" focusTraversable="false" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" popupSide="TOP" styleClass="status-bar-menu-button" text="%statusBar.fafConnected">
<items>
Expand Down
Loading