Skip to content

Commit ac45f8d

Browse files
authored
Feature/#2319 veto system: simple maplist popup (#3151)
1 parent e1ed832 commit ac45f8d

File tree

18 files changed

+502
-111
lines changed

18 files changed

+502
-111
lines changed

src/main/java/com/faforever/client/api/FafApiAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class FafApiAccessor implements InitializingBean {
103103
java.util.Map.entry(MapVersion.class, List.of("map", "map.reviewsSummary", "map.author")),
104104
java.util.Map.entry(MapReviewsSummary.class, List.of("map.latestVersion", "map.author", "map.reviewsSummary")),
105105
java.util.Map.entry(Map.class, List.of("latestVersion", "author", "reviewsSummary")),
106-
java.util.Map.entry(MapPoolAssignment.class, List.of("mapVersion", "mapVersion.map", "mapVersion.map.author", "mapVersion.map.reviewsSummary")),
106+
java.util.Map.entry(MapPoolAssignment.class, List.of("mapVersion", "mapVersion.map", "mapVersion.map.author", "mapVersion.map.reviewsSummary", "mapPool", "mapPool.matchmakerQueueMapPool")),
107107
java.util.Map.entry(ModVersion.class, List.of("mod", "mod.latestVersion", "mod.reviewsSummary", "mod.uploader")),
108108
java.util.Map.entry(ModReviewsSummary.class, List.of("mod.latestVersion", "mod.reviewsSummary", "mod.uploader")),
109109
java.util.Map.entry(Mod.class, List.of("latestVersion", "reviewsSummary", "uploader")),

src/main/java/com/faforever/client/domain/api/MatchmakerQueueMapPool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
public record MatchmakerQueueMapPool(
66
Integer id,
7-
double minRating,
8-
double maxRating, MatchmakerQueueInfo matchmakerQueue, MapPool mapPool
7+
Double minRating,
8+
Double maxRating, MatchmakerQueueInfo matchmakerQueue
99
) {}

src/main/java/com/faforever/client/map/MapService.java

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.faforever.client.domain.api.Map;
88
import com.faforever.client.domain.api.MapType;
99
import com.faforever.client.domain.api.MapVersion;
10+
import com.faforever.client.domain.api.MatchmakerQueueMapPool;
1011
import com.faforever.client.domain.server.MatchmakerQueueInfo;
1112
import com.faforever.client.domain.server.PlayerInfo;
1213
import com.faforever.client.exception.AssetLoadException;
@@ -16,6 +17,7 @@
1617
import com.faforever.client.i18n.I18n;
1718
import com.faforever.client.map.generator.MapGeneratorService;
1819
import com.faforever.client.mapstruct.MapMapper;
20+
import com.faforever.client.mapstruct.MatchmakerMapper;
1921
import com.faforever.client.notification.NotificationService;
2022
import com.faforever.client.player.PlayerService;
2123
import com.faforever.client.preferences.ForgedAlliancePrefs;
@@ -34,9 +36,6 @@
3436
import com.faforever.commons.api.elide.ElideNavigator;
3537
import com.faforever.commons.api.elide.ElideNavigatorOnCollection;
3638
import com.faforever.commons.api.elide.ElideNavigatorOnId;
37-
import com.github.rutledgepaulv.qbuilders.builders.QBuilder;
38-
import com.github.rutledgepaulv.qbuilders.conditions.Condition;
39-
import com.github.rutledgepaulv.qbuilders.visitors.RSQLVisitor;
4039
import com.google.common.annotations.VisibleForTesting;
4140
import javafx.beans.InvalidationListener;
4241
import javafx.beans.WeakInvalidationListener;
@@ -64,7 +63,6 @@
6463
import org.springframework.cache.annotation.Cacheable;
6564
import org.springframework.context.annotation.Lazy;
6665
import org.springframework.stereotype.Service;
67-
import reactor.core.publisher.Flux;
6866
import reactor.core.publisher.Mono;
6967
import reactor.util.function.Tuple2;
7068
import reactor.util.retry.Retry;
@@ -80,13 +78,13 @@
8078
import java.nio.file.WatchService;
8179
import java.time.Duration;
8280
import java.util.ArrayList;
83-
import java.util.Comparator;
8481
import java.util.List;
8582
import java.util.Locale;
8683
import java.util.Optional;
8784
import java.util.Set;
8885
import java.util.concurrent.CompletableFuture;
8986
import java.util.regex.Pattern;
87+
import java.util.stream.Collectors;
9088
import java.util.stream.Stream;
9189

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

628627
@Cacheable(value = CacheNames.MATCHMAKER_POOLS, sync = true)
629-
@SuppressWarnings({"rawtypes", "unchecked"})
630-
public Mono<Tuple2<List<MapVersion>, Integer>> getMatchmakerMapsWithPageCount(MatchmakerQueueInfo matchmakerQueue,
631-
int count, int page) {
632-
PlayerInfo player = playerService.getCurrentPlayer();
633-
double rating = Optional.ofNullable(player.getLeaderboardRatings())
634-
.map(ratings -> ratings.get(matchmakerQueue.getLeaderboard().technicalName()))
635-
.map(ratingBean -> ratingBean.mean() - 3 * ratingBean.deviation())
636-
.orElse(0d);
637-
ElideNavigatorOnCollection<MapPoolAssignment> navigator = ElideNavigator.of(MapPoolAssignment.class).collection();
638-
List<Condition<?>> conditions = new ArrayList<>();
639-
conditions.add(qBuilder().intNum("mapPool.matchmakerQueueMapPool.matchmakerQueue.id").eq(matchmakerQueue.getId()));
640-
conditions.add(qBuilder().doubleNum("mapPool.matchmakerQueueMapPool.minRating")
641-
.lte(rating)
642-
.or()
643-
.floatNum("mapPool.matchmakerQueueMapPool.minRating")
644-
.ne(null));
645-
// The api doesn't support the ne operation so we manually replace it with isnull which rsql does not support
646-
String customFilter = ((String) new QBuilder().and(conditions).query(new RSQLVisitor())).replace("ex", "isnull");
647-
Flux<MapVersion> matchmakerMapsFlux = fafApiAccessor.getMany(navigator, customFilter)
648-
.map(mapMapper::mapFromPoolAssignment)
649-
.distinct()
650-
.sort(
651-
Comparator.nullsLast(Comparator.comparing(MapVersion::size))
652-
.thenComparing(Comparator.nullsLast(
653-
Comparator.comparing(MapVersion::map,
654-
Comparator.nullsLast(
655-
Comparator.comparing(
656-
Map::displayName,
657-
Comparator.nullsLast(
658-
String.CASE_INSENSITIVE_ORDER)))))));
659-
return Mono.zip(matchmakerMapsFlux.skip((long) (page - 1) * count).take(count).collectList(),
660-
matchmakerMapsFlux.count().map(size -> (int) (size - 1) / count + 1));
628+
public Mono <java.util.Map<MatchmakerQueueMapPool, List<MapVersion>>> getMatchmakerBrackets(MatchmakerQueueInfo matchmakerQueue) {
629+
ElideNavigatorOnCollection<MapPoolAssignment> navigator = ElideNavigator
630+
.of(MapPoolAssignment.class).collection()
631+
.setFilter(qBuilder().intNum("mapPool.matchmakerQueueMapPool.matchmakerQueue.id").eq(matchmakerQueue.getId()));
632+
633+
return fafApiAccessor.getMany(navigator)
634+
.map(matchmakerMapper::map)
635+
.collect(Collectors.groupingBy(assignment -> assignment.mapPool().mapPool(),
636+
Collectors.mapping(
637+
com.faforever.client.domain.api.MapPoolAssignment::mapVersion,
638+
Collectors.toList())));
639+
661640
}
662641

663642
public Mono<Boolean> hasPlayedMap(PlayerInfo player, MapVersion mapVersion) {

src/main/java/com/faforever/client/map/MapVaultController.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ protected void setSupplier(SearchConfig searchConfig) {
112112
case NEWEST -> mapService.getNewestMapsWithPageCount(pageSize, pagination.getCurrentPageIndex() + 1);
113113
case HIGHEST_RATED -> mapService.getHighestRatedMapsWithPageCount(pageSize, pagination.getCurrentPageIndex() + 1);
114114
case PLAYED -> mapService.getMostPlayedMapsWithPageCount(pageSize, pagination.getCurrentPageIndex() + 1);
115-
case MAP_POOL ->
116-
mapService.getMatchmakerMapsWithPageCount(matchmakerQueue, pageSize, pagination.getCurrentPageIndex() + 1);
117115
case OWN -> mapService.getOwnedMapsWithPageCount(pageSize, pagination.getCurrentPageIndex() + 1);
118116
case PLAYER, HIGHEST_RATED_UI -> throw new UnsupportedOperationException();
119117
};
@@ -174,13 +172,7 @@ protected Class<? extends NavigateEvent> getDefaultNavigateEvent() {
174172

175173
@Override
176174
protected void handleSpecialNavigateEvent(NavigateEvent navigateEvent) {
177-
if (navigateEvent instanceof ShowMapPoolEvent showMapPoolEvent) {
178-
matchmakerQueue = showMapPoolEvent.getQueue();
179-
searchType = SearchType.MAP_POOL;
180-
onPageChange(null, true);
181-
} else {
182-
log.warn("No such NavigateEvent for this Controller: {}", navigateEvent.getClass());
183-
}
175+
log.warn("No such NavigateEvent for this Controller: {}", navigateEvent.getClass());
184176
}
185177

186178
private void openUploadWindow(Path path) {

src/main/java/com/faforever/client/mapstruct/MatchmakerMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface MatchmakerMapper {
2424
@Mapping(target = "queuePopTime", source = "popTime")
2525
@Mapping(target = "technicalName", source = "name")
2626
MatchmakerQueueInfo update(MatchmakerInfo.MatchmakerQueue dto, @MappingTarget MatchmakerQueueInfo bean);
27-
27+
@Mapping(target = "mapVersion", source = "dto")
2828
MapPoolAssignment map(com.faforever.commons.api.dto.MapPoolAssignment dto);
2929

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

3535
List<com.faforever.commons.api.dto.MapPoolAssignment> mapAssignmentBeans(List<MapPoolAssignment> bean);
36-
36+
@Mapping(target = "mapPool", source = "matchmakerQueueMapPool")
3737
MapPool map(com.faforever.commons.api.dto.MapPool dto);
3838

3939
@InheritInverseConfiguration

src/main/java/com/faforever/client/teammatchmaking/MatchmakingQueueItemController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import java.time.Duration;
3333
import java.time.OffsetDateTime;
34+
import java.util.function.Consumer;
3435

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

6466
@Override
6567
protected void onInitialize() {
@@ -170,8 +172,11 @@ private void setQueuePopTimeUpdater() {
170172
queuePopTimeUpdater.play();
171173
}
172174

175+
public void setOnMapPoolClickedListener(Consumer<MatchmakerQueueInfo> onMapPoolClickedListener) {
176+
this.onMapPoolClickedListener = onMapPoolClickedListener;
177+
}
173178
public void showMapPool() {
174-
navigationHandler.navigateTo(new ShowMapPoolEvent(getQueue()));
179+
onMapPoolClickedListener.accept(this.queue.get());
175180
}
176181

177182
public MatchmakerQueueInfo getQueue() {

src/main/java/com/faforever/client/teammatchmaking/TeamMatchmakingController.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import com.faforever.client.player.PlayerService;
1616
import com.faforever.client.preferences.MatchmakerPrefs;
1717
import com.faforever.client.theme.UiService;
18+
import com.faforever.client.ui.dialog.Dialog;
19+
import com.faforever.client.ui.dialog.Dialog.DialogTransition;
20+
import com.faforever.client.ui.dialog.DialogLayout;
1821
import com.faforever.commons.lobby.Faction;
1922
import javafx.beans.InvalidationListener;
2023
import javafx.beans.binding.Bindings;
@@ -31,6 +34,7 @@
3134
import javafx.scene.control.TabPane;
3235
import javafx.scene.control.ToggleButton;
3336
import javafx.scene.image.ImageView;
37+
import javafx.scene.input.KeyCode;
3438
import javafx.scene.layout.ColumnConstraints;
3539
import javafx.scene.layout.FlowPane;
3640
import javafx.scene.layout.GridPane;
@@ -331,6 +335,15 @@ private void selectFactions(List<Faction> factions) {
331335
factionsToButtons.forEach((faction, toggleButton) -> toggleButton.setSelected(factions.contains(faction)));
332336
}
333337

338+
protected void onMapPoolClickedListener(MatchmakerQueueInfo queue) {
339+
TeamMatchmakingMapListController controller = uiService.loadFxml("theme/play/teammatchmaking/matchmaking_maplist_popup.fxml");
340+
controller.maxWidthProperty().bind(teamMatchmakingRoot.widthProperty());
341+
controller.maxHeightProperty().bind(teamMatchmakingRoot.heightProperty());
342+
controller.setQueue(queue);
343+
Pane root = controller.getRoot();
344+
uiService.showInDialog(teamMatchmakingRoot, root, null, true, DialogTransition.CENTER);
345+
}
346+
334347
private void renderQueues() {
335348
List<MatchmakerQueueInfo> queues = new ArrayList<>(teamMatchmakingService.getQueues());
336349
queues.sort(Comparator.comparing(MatchmakerQueueInfo::getTeamSize).thenComparing(MatchmakerQueueInfo::getId));
@@ -343,6 +356,7 @@ private void renderQueues() {
343356
MatchmakingQueueItemController controller = uiService.loadFxml(
344357
"theme/play/teammatchmaking/matchmaking_queue_card.fxml");
345358
controller.setQueue(queue);
359+
controller.setOnMapPoolClickedListener(this::onMapPoolClickedListener);
346360
controller.getRoot().prefWidthProperty().bind(prefWidth);
347361
return controller.getRoot();
348362
}).collect(Collectors.toList());

0 commit comments

Comments
 (0)