Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/games-controller-leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 authored Apr 23, 2023
2 parents 9f61a5b + 8a72c8f commit bf59420
Show file tree
Hide file tree
Showing 15 changed files with 635 additions and 368 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/faforever/client/domain/MatchingStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.faforever.client.domain;

public enum MatchingStatus {
MATCH_FOUND, GAME_LAUNCHING, MATCH_CANCELLED, SEARCHING
}
30 changes: 7 additions & 23 deletions src/main/java/com/faforever/client/domain/MatchmakerQueueBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.Value;
import org.springframework.scheduling.TaskScheduler;

import java.time.Duration;
import java.time.Instant;
import java.time.OffsetDateTime;

@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
Expand All @@ -27,24 +24,11 @@ public class MatchmakerQueueBean extends AbstractEntityBean<MatchmakerQueueBean>
IntegerProperty teamSize = new SimpleIntegerProperty(0);
IntegerProperty playersInQueue = new SimpleIntegerProperty(0);
IntegerProperty activeGames = new SimpleIntegerProperty(0);
BooleanProperty joined = new SimpleBooleanProperty(false);
BooleanProperty selected = new SimpleBooleanProperty(true);
ObjectProperty<MatchingStatus> matchingStatus = new SimpleObjectProperty<>();
ObjectProperty<LeaderboardBean> leaderboard = new SimpleObjectProperty<>();
ObjectProperty<FeaturedModBean> featuredMod = new SimpleObjectProperty<>();

public void setTimedOutMatchingStatus(MatchingStatus status, Duration timeout, TaskScheduler taskScheduler) {
setMatchingStatus(status);
taskScheduler.schedule(() -> {
if (getMatchingStatus() == status) {
setMatchingStatus(null);
}
}, Instant.now().plus(timeout));
}

public enum MatchingStatus {
MATCH_FOUND, GAME_LAUNCHING, MATCH_CANCELLED
}

public MatchingStatus getMatchingStatus() {
return matchingStatus.get();
}
Expand Down Expand Up @@ -141,15 +125,15 @@ public void setActiveGames(int activeGames) {
this.activeGames.set(activeGames);
}

public boolean isJoined() {
return joined.get();
public boolean isSelected() {
return selected.get();
}

public void setJoined(boolean joined) {
this.joined.set(joined);
public void setSelected(boolean selected) {
this.selected.set(selected);
}

public BooleanProperty joinedProperty() {
return joined;
public BooleanProperty selectedProperty() {
return selected;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/faforever/client/player/PlayerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.faforever.commons.lobby.SocialInfo;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue;
import javafx.collections.MapChangeListener;
Expand Down Expand Up @@ -263,6 +264,10 @@ public PlayerBean getCurrentPlayer() {
return currentPlayer.get();
}

public ReadOnlyObjectProperty<PlayerBean> currentPlayerProperty() {
return currentPlayer.getReadOnlyProperty();
}

public Optional<PlayerBean> getPlayerByIdIfOnline(int playerId) {
return Optional.ofNullable(playersById.get(playerId));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.faforever.client.preferences;

import com.faforever.commons.lobby.Faction;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.ObservableList;
import javafx.collections.ObservableSet;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;

import static javafx.collections.FXCollections.observableArrayList;
import static javafx.collections.FXCollections.observableSet;

@FieldDefaults(makeFinal=true, level= AccessLevel.PRIVATE)
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class MatchmakerPrefs {

ListProperty<Faction> factions = new SimpleListProperty<>(observableArrayList(Faction.AEON, Faction.CYBRAN, Faction.UEF, Faction.SERAPHIM));
ObservableList<Faction> factions = observableArrayList(Faction.AEON, Faction.CYBRAN, Faction.UEF, Faction.SERAPHIM);
ObservableSet<Integer> unselectedQueueIds = observableSet();

public ObservableList<Faction> getFactions() {
return factions.get();
}

public ListProperty<Faction> factionsProperty() {
return factions;
}

public ObservableSet<Integer> getUnselectedQueueIds() {
return unselectedQueueIds;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.faforever.client.teammatchmaking;

import com.faforever.client.domain.MatchingStatus;
import com.faforever.client.domain.MatchmakerQueueBean;
import com.faforever.client.domain.MatchmakerQueueBean.MatchingStatus;
import com.faforever.client.fx.Controller;
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.fx.SimpleChangeListener;
import com.faforever.client.i18n.I18n;
import com.faforever.client.main.event.ShowMapPoolEvent;
import com.faforever.client.player.PlayerService;
import com.faforever.client.user.UserService;
import com.google.common.eventbus.EventBus;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
Expand Down Expand Up @@ -43,7 +42,6 @@ public class MatchmakingQueueItemController implements Controller<VBox> {

private final static String QUEUE_I18N_PATTERN = "teammatchmaking.queue.%s";

private final UserService userService;
private final PlayerService playerService;
private final TeamMatchmakingService teamMatchmakingService;
private final I18n i18n;
Expand All @@ -53,38 +51,48 @@ public class MatchmakingQueueItemController implements Controller<VBox> {
public Label playersInQueueLabel;
public Label activeGamesLabel;
public Label queuePopTimeLabel;
public ToggleButton joinLeaveQueueButton;
public Label refreshingLabel;
public ToggleButton selectButton;
public Label searchingLabel;
public Label matchFoundLabel;
public Label matchStartingLabel;
public Label matchCancelledLabel;
public Button mapPoolButton;

@VisibleForTesting
private final ObjectProperty<MatchmakerQueueBean> queue = new SimpleObjectProperty<>();
private final ObservableValue<Boolean> queueJoined = queue.flatMap(MatchmakerQueueBean::joinedProperty).orElse(false);

private final SimpleChangeListener<Boolean> queueStateInvalidationListener = newValue -> JavaFxUtil.runLater(() -> {
refreshingLabel.setVisible(false);
joinLeaveQueueButton.setSelected(newValue);
});

@Override
public void initialize() {
JavaFxUtil.bindManagedToVisible(matchFoundLabel, matchStartingLabel, matchCancelledLabel);

eventBus.register(this);
joinLeaveQueueButton.setTextOverrun(OverrunStyle.WORD_ELLIPSIS);
ObservableValue<Boolean> showing = JavaFxUtil.showingProperty(getRoot());

queue.addListener(((observable, oldValue, newValue) -> {
if (oldValue != null) {
selectButton.selectedProperty().unbindBidirectional(oldValue.selectedProperty());
}

if (newValue != null) {
selectButton.selectedProperty().bindBidirectional(newValue.selectedProperty());
}
}));

selectButton.setTextOverrun(OverrunStyle.WORD_ELLIPSIS);
mapPoolButton.setText(i18n.get("teammatchmaking.mapPool").toUpperCase());

ObservableValue<MatchingStatus> matchingStatus = queue.flatMap(MatchmakerQueueBean::matchingStatusProperty);
matchFoundLabel.visibleProperty().bind(matchingStatus.map(status -> status == MatchingStatus.MATCH_FOUND).orElse(false));
matchStartingLabel.visibleProperty().bind(matchingStatus.map(status -> status == MatchingStatus.GAME_LAUNCHING).orElse(false));
matchCancelledLabel.visibleProperty().bind(matchingStatus.map(status -> status == MatchingStatus.MATCH_CANCELLED).orElse(false));

joinLeaveQueueButton.textProperty()
searchingLabel.visibleProperty()
.bind(matchingStatus.map(status -> status == MatchingStatus.SEARCHING).orElse(false).when(showing));
matchFoundLabel.visibleProperty()
.bind(matchingStatus.map(status -> status == MatchingStatus.MATCH_FOUND).orElse(false).when(showing));
matchStartingLabel.visibleProperty()
.bind(matchingStatus.map(status -> status == MatchingStatus.GAME_LAUNCHING).orElse(false).when(showing));
matchCancelledLabel.visibleProperty()
.bind(matchingStatus.map(status -> status == MatchingStatus.MATCH_CANCELLED).orElse(false).when(showing));

selectButton.textProperty()
.bind(queue.map(MatchmakerQueueBean::getTechnicalName)
.map(technicalName -> i18n.getOrDefault(technicalName, String.format(QUEUE_I18N_PATTERN, technicalName))));
.map(technicalName -> i18n.getOrDefault(technicalName, QUEUE_I18N_PATTERN.formatted(technicalName))));

playersInQueueLabel.textProperty()
.bind(queue.flatMap(MatchmakerQueueBean::playersInQueueProperty)
Expand All @@ -101,16 +109,15 @@ public void initialize() {

BooleanExpression notPartyOwner = BooleanBinding.booleanExpression(teamMatchmakingService.getParty()
.ownerProperty()
.map(owner -> !owner.equals(playerService.getCurrentPlayer())));
.isNotEqualTo(playerService.currentPlayerProperty()));

joinLeaveQueueButton.disableProperty()
.bind(userService.ownPlayerProperty().isNull()
selectButton.disableProperty()
.bind(playerService.currentPlayerProperty().isNull()
.or(queue.isNull())
.or(partyTooBig)
.or(teamMatchmakingService.partyMembersNotReadyProperty())
.or(notPartyOwner));

queueJoined.addListener(queueStateInvalidationListener);
.or(notPartyOwner)
.when(showing));

queue.addListener((SimpleChangeListener<MatchmakerQueueBean>) this::setQueuePopTimeUpdater);
}
Expand Down Expand Up @@ -139,20 +146,6 @@ private void setQueuePopTimeUpdater(MatchmakerQueueBean queue) {
queuePopTimeUpdater.play();
}

public void onJoinLeaveQueueClicked() {
if (queueJoined.getValue()) {
teamMatchmakingService.leaveQueue(getQueue());
} else {
teamMatchmakingService.joinQueue(getQueue()).thenAccept(success -> {
if (!success) {
joinLeaveQueueButton.setSelected(false);
refreshingLabel.setVisible(false);
}
});
}
refreshingLabel.setVisible(true);
}

public void showMapPool() {
eventBus.post(new ShowMapPoolEvent(getQueue()));
}
Expand Down
Loading

0 comments on commit bf59420

Please sign in to comment.