Skip to content

Commit

Permalink
Feature/#2319 veto system: simple maplist popup (#3151)
Browse files Browse the repository at this point in the history
  • Loading branch information
K-ETFreeman committed Apr 22, 2024
1 parent e1ed832 commit ac45f8d
Show file tree
Hide file tree
Showing 18 changed files with 502 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/faforever/client/api/FafApiAccessor.java
Expand Up @@ -103,7 +103,7 @@ public class FafApiAccessor implements InitializingBean {
java.util.Map.entry(MapVersion.class, List.of("map", "map.reviewsSummary", "map.author")),
java.util.Map.entry(MapReviewsSummary.class, List.of("map.latestVersion", "map.author", "map.reviewsSummary")),
java.util.Map.entry(Map.class, List.of("latestVersion", "author", "reviewsSummary")),
java.util.Map.entry(MapPoolAssignment.class, List.of("mapVersion", "mapVersion.map", "mapVersion.map.author", "mapVersion.map.reviewsSummary")),
java.util.Map.entry(MapPoolAssignment.class, List.of("mapVersion", "mapVersion.map", "mapVersion.map.author", "mapVersion.map.reviewsSummary", "mapPool", "mapPool.matchmakerQueueMapPool")),
java.util.Map.entry(ModVersion.class, List.of("mod", "mod.latestVersion", "mod.reviewsSummary", "mod.uploader")),
java.util.Map.entry(ModReviewsSummary.class, List.of("mod.latestVersion", "mod.reviewsSummary", "mod.uploader")),
java.util.Map.entry(Mod.class, List.of("latestVersion", "reviewsSummary", "uploader")),
Expand Down
Expand Up @@ -4,6 +4,6 @@

public record MatchmakerQueueMapPool(
Integer id,
double minRating,
double maxRating, MatchmakerQueueInfo matchmakerQueue, MapPool mapPool
Double minRating,
Double maxRating, MatchmakerQueueInfo matchmakerQueue
) {}
53 changes: 16 additions & 37 deletions src/main/java/com/faforever/client/map/MapService.java
Expand Up @@ -7,6 +7,7 @@
import com.faforever.client.domain.api.Map;
import com.faforever.client.domain.api.MapType;
import com.faforever.client.domain.api.MapVersion;
import com.faforever.client.domain.api.MatchmakerQueueMapPool;
import com.faforever.client.domain.server.MatchmakerQueueInfo;
import com.faforever.client.domain.server.PlayerInfo;
import com.faforever.client.exception.AssetLoadException;
Expand All @@ -16,6 +17,7 @@
import com.faforever.client.i18n.I18n;
import com.faforever.client.map.generator.MapGeneratorService;
import com.faforever.client.mapstruct.MapMapper;
import com.faforever.client.mapstruct.MatchmakerMapper;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.ForgedAlliancePrefs;
Expand All @@ -34,9 +36,6 @@
import com.faforever.commons.api.elide.ElideNavigator;
import com.faforever.commons.api.elide.ElideNavigatorOnCollection;
import com.faforever.commons.api.elide.ElideNavigatorOnId;
import com.github.rutledgepaulv.qbuilders.builders.QBuilder;
import com.github.rutledgepaulv.qbuilders.conditions.Condition;
import com.github.rutledgepaulv.qbuilders.visitors.RSQLVisitor;
import com.google.common.annotations.VisibleForTesting;
import javafx.beans.InvalidationListener;
import javafx.beans.WeakInvalidationListener;
Expand Down Expand Up @@ -64,7 +63,6 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;
import reactor.util.retry.Retry;
Expand All @@ -80,13 +78,13 @@
import java.nio.file.WatchService;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.faforever.client.util.LuaUtil.loadFile;
Expand Down Expand Up @@ -117,6 +115,7 @@ public class MapService implements InitializingBean, DisposableBean {
private final MapGeneratorService mapGeneratorService;
private final PlayerService playerService;
private final MapMapper mapMapper;
private final MatchmakerMapper matchmakerMapper;
private final FileSizeReader fileSizeReader;
private final ClientProperties clientProperties;
private final ForgedAlliancePrefs forgedAlliancePrefs;
Expand Down Expand Up @@ -626,38 +625,18 @@ public Mono<Void> downloadAllMatchmakerMaps(MatchmakerQueueInfo matchmakerQueue)
}

@Cacheable(value = CacheNames.MATCHMAKER_POOLS, sync = true)
@SuppressWarnings({"rawtypes", "unchecked"})
public Mono<Tuple2<List<MapVersion>, Integer>> getMatchmakerMapsWithPageCount(MatchmakerQueueInfo matchmakerQueue,
int count, int page) {
PlayerInfo player = playerService.getCurrentPlayer();
double rating = Optional.ofNullable(player.getLeaderboardRatings())
.map(ratings -> ratings.get(matchmakerQueue.getLeaderboard().technicalName()))
.map(ratingBean -> ratingBean.mean() - 3 * ratingBean.deviation())
.orElse(0d);
ElideNavigatorOnCollection<MapPoolAssignment> navigator = ElideNavigator.of(MapPoolAssignment.class).collection();
List<Condition<?>> conditions = new ArrayList<>();
conditions.add(qBuilder().intNum("mapPool.matchmakerQueueMapPool.matchmakerQueue.id").eq(matchmakerQueue.getId()));
conditions.add(qBuilder().doubleNum("mapPool.matchmakerQueueMapPool.minRating")
.lte(rating)
.or()
.floatNum("mapPool.matchmakerQueueMapPool.minRating")
.ne(null));
// The api doesn't support the ne operation so we manually replace it with isnull which rsql does not support
String customFilter = ((String) new QBuilder().and(conditions).query(new RSQLVisitor())).replace("ex", "isnull");
Flux<MapVersion> matchmakerMapsFlux = fafApiAccessor.getMany(navigator, customFilter)
.map(mapMapper::mapFromPoolAssignment)
.distinct()
.sort(
Comparator.nullsLast(Comparator.comparing(MapVersion::size))
.thenComparing(Comparator.nullsLast(
Comparator.comparing(MapVersion::map,
Comparator.nullsLast(
Comparator.comparing(
Map::displayName,
Comparator.nullsLast(
String.CASE_INSENSITIVE_ORDER)))))));
return Mono.zip(matchmakerMapsFlux.skip((long) (page - 1) * count).take(count).collectList(),
matchmakerMapsFlux.count().map(size -> (int) (size - 1) / count + 1));
public Mono <java.util.Map<MatchmakerQueueMapPool, List<MapVersion>>> getMatchmakerBrackets(MatchmakerQueueInfo matchmakerQueue) {
ElideNavigatorOnCollection<MapPoolAssignment> navigator = ElideNavigator
.of(MapPoolAssignment.class).collection()
.setFilter(qBuilder().intNum("mapPool.matchmakerQueueMapPool.matchmakerQueue.id").eq(matchmakerQueue.getId()));

return fafApiAccessor.getMany(navigator)
.map(matchmakerMapper::map)
.collect(Collectors.groupingBy(assignment -> assignment.mapPool().mapPool(),
Collectors.mapping(
com.faforever.client.domain.api.MapPoolAssignment::mapVersion,
Collectors.toList())));

}

public Mono<Boolean> hasPlayedMap(PlayerInfo player, MapVersion mapVersion) {
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/com/faforever/client/map/MapVaultController.java
Expand Up @@ -112,8 +112,6 @@ protected void setSupplier(SearchConfig searchConfig) {
case NEWEST -> mapService.getNewestMapsWithPageCount(pageSize, pagination.getCurrentPageIndex() + 1);
case HIGHEST_RATED -> mapService.getHighestRatedMapsWithPageCount(pageSize, pagination.getCurrentPageIndex() + 1);
case PLAYED -> mapService.getMostPlayedMapsWithPageCount(pageSize, pagination.getCurrentPageIndex() + 1);
case MAP_POOL ->
mapService.getMatchmakerMapsWithPageCount(matchmakerQueue, pageSize, pagination.getCurrentPageIndex() + 1);
case OWN -> mapService.getOwnedMapsWithPageCount(pageSize, pagination.getCurrentPageIndex() + 1);
case PLAYER, HIGHEST_RATED_UI -> throw new UnsupportedOperationException();
};
Expand Down Expand Up @@ -174,13 +172,7 @@ protected Class<? extends NavigateEvent> getDefaultNavigateEvent() {

@Override
protected void handleSpecialNavigateEvent(NavigateEvent navigateEvent) {
if (navigateEvent instanceof ShowMapPoolEvent showMapPoolEvent) {
matchmakerQueue = showMapPoolEvent.getQueue();
searchType = SearchType.MAP_POOL;
onPageChange(null, true);
} else {
log.warn("No such NavigateEvent for this Controller: {}", navigateEvent.getClass());
}
log.warn("No such NavigateEvent for this Controller: {}", navigateEvent.getClass());
}

private void openUploadWindow(Path path) {
Expand Down
Expand Up @@ -24,7 +24,7 @@ public interface MatchmakerMapper {
@Mapping(target = "queuePopTime", source = "popTime")
@Mapping(target = "technicalName", source = "name")
MatchmakerQueueInfo update(MatchmakerInfo.MatchmakerQueue dto, @MappingTarget MatchmakerQueueInfo bean);

@Mapping(target = "mapVersion", source = "dto")
MapPoolAssignment map(com.faforever.commons.api.dto.MapPoolAssignment dto);

@InheritInverseConfiguration
Expand All @@ -33,7 +33,7 @@ public interface MatchmakerMapper {
List<MapPoolAssignment> mapAssignmentDtos(List<com.faforever.commons.api.dto.MapPoolAssignment> dto);

List<com.faforever.commons.api.dto.MapPoolAssignment> mapAssignmentBeans(List<MapPoolAssignment> bean);

@Mapping(target = "mapPool", source = "matchmakerQueueMapPool")
MapPool map(com.faforever.commons.api.dto.MapPool dto);

@InheritInverseConfiguration
Expand Down
Expand Up @@ -31,6 +31,7 @@

import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.function.Consumer;

@Slf4j
@Component
Expand Down Expand Up @@ -60,6 +61,7 @@ public class MatchmakingQueueItemController extends NodeController<VBox> {
private final ObjectProperty<MatchmakerQueueInfo> queue = new SimpleObjectProperty<>();
private final ObservableValue<OffsetDateTime> popTime = queue.flatMap(MatchmakerQueueInfo::queuePopTimeProperty);
private Timeline queuePopTimeUpdater;
private Consumer<MatchmakerQueueInfo> onMapPoolClickedListener;

@Override
protected void onInitialize() {
Expand Down Expand Up @@ -170,8 +172,11 @@ private void setQueuePopTimeUpdater() {
queuePopTimeUpdater.play();
}

public void setOnMapPoolClickedListener(Consumer<MatchmakerQueueInfo> onMapPoolClickedListener) {
this.onMapPoolClickedListener = onMapPoolClickedListener;
}
public void showMapPool() {
navigationHandler.navigateTo(new ShowMapPoolEvent(getQueue()));
onMapPoolClickedListener.accept(this.queue.get());
}

public MatchmakerQueueInfo getQueue() {
Expand Down
Expand Up @@ -15,6 +15,9 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.MatchmakerPrefs;
import com.faforever.client.theme.UiService;
import com.faforever.client.ui.dialog.Dialog;
import com.faforever.client.ui.dialog.Dialog.DialogTransition;
import com.faforever.client.ui.dialog.DialogLayout;
import com.faforever.commons.lobby.Faction;
import javafx.beans.InvalidationListener;
import javafx.beans.binding.Bindings;
Expand All @@ -31,6 +34,7 @@
import javafx.scene.control.TabPane;
import javafx.scene.control.ToggleButton;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
Expand Down Expand Up @@ -331,6 +335,15 @@ private void selectFactions(List<Faction> factions) {
factionsToButtons.forEach((faction, toggleButton) -> toggleButton.setSelected(factions.contains(faction)));
}

protected void onMapPoolClickedListener(MatchmakerQueueInfo queue) {
TeamMatchmakingMapListController controller = uiService.loadFxml("theme/play/teammatchmaking/matchmaking_maplist_popup.fxml");
controller.maxWidthProperty().bind(teamMatchmakingRoot.widthProperty());
controller.maxHeightProperty().bind(teamMatchmakingRoot.heightProperty());
controller.setQueue(queue);
Pane root = controller.getRoot();
uiService.showInDialog(teamMatchmakingRoot, root, null, true, DialogTransition.CENTER);
}

private void renderQueues() {
List<MatchmakerQueueInfo> queues = new ArrayList<>(teamMatchmakingService.getQueues());
queues.sort(Comparator.comparing(MatchmakerQueueInfo::getTeamSize).thenComparing(MatchmakerQueueInfo::getId));
Expand All @@ -343,6 +356,7 @@ private void renderQueues() {
MatchmakingQueueItemController controller = uiService.loadFxml(
"theme/play/teammatchmaking/matchmaking_queue_card.fxml");
controller.setQueue(queue);
controller.setOnMapPoolClickedListener(this::onMapPoolClickedListener);
controller.getRoot().prefWidthProperty().bind(prefWidth);
return controller.getRoot();
}).collect(Collectors.toList());
Expand Down

0 comments on commit ac45f8d

Please sign in to comment.