Search in sources :

Example 1 with MapBean

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);
}
Also used : PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) Scope(org.springframework.context.annotation.Scope) InvalidationListener(javafx.beans.InvalidationListener) Inject(javax.inject.Inject) TimeService(com.faforever.client.util.TimeService) Duration(java.time.Duration) StarsController(com.faforever.client.vault.review.StarsController) RatingUtil(com.faforever.client.util.RatingUtil) Label(javafx.scene.control.Label) Controller(com.faforever.client.fx.Controller) Node(javafx.scene.Node) MapBean(com.faforever.client.map.MapBean) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Consumer(java.util.function.Consumer) WeakInvalidationListener(javafx.beans.WeakInvalidationListener) Component(org.springframework.stereotype.Component) List(java.util.List) ImageView(javafx.scene.image.ImageView) RatingService(com.faforever.client.rating.RatingService) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Image(javafx.scene.image.Image) Review(com.faforever.client.vault.review.Review) Joiner(com.google.common.base.Joiner) MapBean(com.faforever.client.map.MapBean) WeakInvalidationListener(javafx.beans.WeakInvalidationListener) Review(com.faforever.client.vault.review.Review) Image(javafx.scene.image.Image)

Example 2 with MapBean

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));
}
Also used : MapBean(com.faforever.client.map.MapBean) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 3 with MapBean

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();
}
Also used : Button(javafx.scene.control.Button) UiService(com.faforever.client.theme.UiService) Rating(com.faforever.client.util.Rating) TimeService(com.faforever.client.util.TimeService) ScrollPane(javafx.scene.control.ScrollPane) Duration(java.time.Duration) Map(java.util.Map) TableView(javafx.scene.control.TableView) PlayerService(com.faforever.client.player.PlayerService) Pane(javafx.scene.layout.Pane) ClientProperties(com.faforever.client.config.ClientProperties) TextField(javafx.scene.control.TextField) Collection(java.util.Collection) ObservableMap(javafx.collections.ObservableMap) MapBean(com.faforever.client.map.MapBean) Collectors(java.util.stream.Collectors) Bytes(com.faforever.commons.io.Bytes) Platform(javafx.application.Platform) Player(com.faforever.client.player.Player) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Clipboard(javafx.scene.input.Clipboard) Optional(java.util.Optional) ClipboardContent(javafx.scene.input.ClipboardContent) Temporal(java.time.temporal.Temporal) Setter(lombok.Setter) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) MouseEvent(javafx.scene.input.MouseEvent) GameOption(com.faforever.client.replay.Replay.GameOption) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) ChatMessage(com.faforever.client.replay.Replay.ChatMessage) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) TeamCardController(com.faforever.client.game.TeamCardController) ReviewsController(com.faforever.client.vault.review.ReviewsController) StringCell(com.faforever.client.fx.StringCell) RatingUtil(com.faforever.client.util.RatingUtil) Label(javafx.scene.control.Label) Controller(com.faforever.client.fx.Controller) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) RatingType(com.faforever.client.game.RatingType) Component(org.springframework.stereotype.Component) PlayerStats(com.faforever.client.replay.Replay.PlayerStats) ImageView(javafx.scene.image.ImageView) ReviewService(com.faforever.client.vault.review.ReviewService) RatingService(com.faforever.client.rating.RatingService) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Validity(com.faforever.client.api.dto.Validity) Image(javafx.scene.image.Image) Review(com.faforever.client.vault.review.Review) Assert(org.springframework.util.Assert) Player(com.faforever.client.player.Player) MapBean(com.faforever.client.map.MapBean) Temporal(java.time.temporal.Temporal) Image(javafx.scene.image.Image)

Example 4 with MapBean

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;
}
Also used : MapPreviewTableCellController(com.faforever.client.vault.map.MapPreviewTableCellController) MapBean(com.faforever.client.map.MapBean) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) TableCell(javafx.scene.control.TableCell) Replay(com.faforever.client.replay.Replay) ImageView(javafx.scene.image.ImageView)

Example 5 with MapBean

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();
    }
}
Also used : MapBean(com.faforever.client.map.MapBean)

Aggregations

MapBean (com.faforever.client.map.MapBean)5 ImageView (javafx.scene.image.ImageView)3 Controller (com.faforever.client.fx.Controller)2 I18n (com.faforever.client.i18n.I18n)2 MapService (com.faforever.client.map.MapService)2 PreviewSize (com.faforever.client.map.MapServiceImpl.PreviewSize)2 RatingService (com.faforever.client.rating.RatingService)2 RatingUtil (com.faforever.client.util.RatingUtil)2 TimeService (com.faforever.client.util.TimeService)2 Review (com.faforever.client.vault.review.Review)2 Duration (java.time.Duration)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Platform (javafx.application.Platform)2 Validity (com.faforever.client.api.dto.Validity)1 ClientProperties (com.faforever.client.config.ClientProperties)1 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)1 StringCell (com.faforever.client.fx.StringCell)1 RatingType (com.faforever.client.game.RatingType)1