use of com.faforever.client.map.MapBean in project downlords-faf-client by FAForever.
the class ReplayCardController method setReplay.
public void setReplay(Replay replay) {
this.replay = replay;
Optional<MapBean> optionalMap = Optional.ofNullable(replay.getMap());
if (optionalMap.isPresent()) {
MapBean map = optionalMap.get();
Image image = mapService.loadPreview(map, PreviewSize.SMALL);
mapThumbnailImageView.setImage(image);
onMapLabel.setText(i18n.get("game.onMapFormat", map.getDisplayName()));
} else {
onMapLabel.setText(i18n.get("game.onUnknownMap"));
}
gameTitleLabel.setText(replay.getTitle());
dateLabel.setText(timeService.asDate(replay.getStartTime()));
timeLabel.setText(timeService.asShortTime(replay.getStartTime()));
modLabel.setText(replay.getFeaturedMod().getDisplayName());
playerCountLabel.setText(i18n.number(replay.getTeams().values().stream().mapToInt(List::size).sum()));
qualityLabel.setText(i18n.get("percentage", (int) ratingService.calculateQuality(replay) * 100));
replay.getTeamPlayerStats().values().stream().flatMapToInt(playerStats -> playerStats.stream().mapToInt(stats -> RatingUtil.getRating(stats.getBeforeMean(), stats.getBeforeDeviation()))).average().ifPresent(averageRating -> ratingLabel.setText(i18n.number((int) averageRating)));
durationLabel.setText(Optional.ofNullable(replay.getEndTime()).map(endTime -> timeService.shortDuration(Duration.between(replay.getStartTime(), endTime))).orElse(i18n.get("notAvailable")));
String players = replay.getTeams().values().stream().map(team -> Joiner.on(i18n.get("textSeparator")).join(team)).collect(Collectors.joining(i18n.get("vsSeparator")));
playerListLabel.setText(players);
ObservableList<Review> reviews = replay.getReviews();
reviews.addListener(new WeakInvalidationListener(reviewsChangedListener));
reviewsChangedListener.invalidated(reviews);
}
use of com.faforever.client.map.MapBean in project downlords-faf-client by FAForever.
the class CreateGameControllerTest method testSelectLastMap.
@Test
public void testSelectLastMap() {
MapBean lastMapBean = MapBuilder.create().defaultValues().folderName("foo").get();
preferences.setLastMap("foo");
mapList.add(MapBuilder.create().defaultValues().folderName("Test1").get());
mapList.add(lastMapBean);
WaitForAsyncUtils.asyncFx(() -> instance.initialize());
WaitForAsyncUtils.waitForFxEvents();
assertThat(instance.mapListView.getSelectionModel().getSelectedItem(), is(lastMapBean));
}
use of com.faforever.client.map.MapBean in project downlords-faf-client by FAForever.
the class ReplayDetailController method setReplay.
public void setReplay(Replay replay) {
this.replay = replay;
replayIdField.setText(i18n.get("game.idFormat", replay.getId()));
titleLabel.setText(replay.getTitle());
dateLabel.setText(timeService.asDate(replay.getStartTime()));
timeLabel.setText(timeService.asShortTime(replay.getStartTime()));
Optional<MapBean> optionalMap = Optional.ofNullable(replay.getMap());
if (optionalMap.isPresent()) {
MapBean map = optionalMap.get();
Image image = mapService.loadPreview(map, PreviewSize.LARGE);
mapThumbnailImageView.setImage(image);
onMapLabel.setText(i18n.get("game.onMapFormat", map.getDisplayName()));
} else {
onMapLabel.setText(i18n.get("game.onUnknownMap"));
}
Temporal endTime = replay.getEndTime();
if (endTime != null) {
durationLabel.setText(timeService.shortDuration(Duration.between(replay.getStartTime(), endTime)));
} else {
durationLabel.setVisible(false);
}
modLabel.setText(replay.getFeaturedMod().getDisplayName());
playerCountLabel.setText(i18n.number(replay.getTeams().values().stream().mapToInt(List::size).sum()));
qualityLabel.setText(i18n.get("percentage", (int) ratingService.calculateQuality(replay) * 100));
replay.getTeamPlayerStats().values().stream().flatMapToInt(playerStats -> playerStats.stream().mapToInt(stats -> RatingUtil.getRating(stats.getBeforeMean(), stats.getBeforeDeviation()))).average().ifPresent(averageRating -> ratingLabel.setText(i18n.number((int) averageRating)));
replayService.getSize(replay.getId()).thenAccept(replaySize -> Platform.runLater(() -> {
if (replaySize > -1) {
String humanReadableSize = Bytes.formatSize(replaySize, i18n.getUserSpecificLocale());
downloadMoreInfoButton.setText(i18n.get("game.downloadMoreInfo", humanReadableSize));
watchButton.setText(i18n.get("game.watchButtonFormat", humanReadableSize));
} else {
downloadMoreInfoButton.setText(i18n.get("game.replayFileMissing"));
downloadMoreInfoButton.setDisable(true);
watchButton.setText(i18n.get("game.replayFileMissing"));
watchButton.setDisable(true);
}
}));
Optional<Player> currentPlayer = playerService.getCurrentPlayer();
Assert.state(currentPlayer.isPresent(), "No user is logged in");
reviewsController.setOnSendReviewListener(this::onSendReview);
reviewsController.setOnDeleteReviewListener(this::onDeleteReview);
reviewsController.setReviews(replay.getReviews());
reviewsController.setOwnReview(replay.getReviews().stream().filter(review -> review.getPlayer().equals(currentPlayer.get())).findFirst());
// These items are initially empty but will be populated in #onDownloadMoreInfoClicked()
optionsTable.setItems(replay.getGameOptions());
chatTable.setItems(replay.getChatMessages());
teams = replay.getTeamPlayerStats();
populateTeamsContainer();
}
use of com.faforever.client.map.MapBean in project downlords-faf-client by FAForever.
the class ReplayVaultController method mapCellFactory.
private TableCell<Replay, MapBean> mapCellFactory(TableColumn<Replay, MapBean> column) {
MapPreviewTableCellController controller = uiService.loadFxml("theme/vault/map/map_preview_table_cell.fxml");
final ImageView imageView = controller.getRoot();
TableCell<Replay, MapBean> cell = new TableCell<Replay, MapBean>() {
@Override
protected void updateItem(MapBean map, boolean empty) {
super.updateItem(map, empty);
if (empty || map == null) {
setText(null);
setGraphic(null);
} else {
imageView.setImage(mapService.loadPreview(map.getFolderName(), PreviewSize.SMALL));
setGraphic(imageView);
setText(map.getDisplayName());
}
}
};
cell.setGraphic(imageView);
return cell;
}
use of com.faforever.client.map.MapBean in project downlords-faf-client by FAForever.
the class CreateGameController method selectLastMap.
private void selectLastMap() {
String lastMap = preferencesService.getPreferences().getLastMap();
for (MapBean mapBean : mapListView.getItems()) {
if (mapBean.getFolderName().equalsIgnoreCase(lastMap)) {
mapListView.getSelectionModel().select(mapBean);
mapListView.scrollTo(mapBean);
return;
}
}
if (mapListView.getSelectionModel().isEmpty()) {
mapListView.getSelectionModel().selectFirst();
}
}
Aggregations