Search in sources :

Example 1 with PlayerStats

use of com.faforever.client.replay.Replay.PlayerStats in project downlords-faf-client by FAForever.

the class TeamCardControllerTest method setUp.

@Before
public void setUp() throws IOException {
    instance = new TeamCardController(uiService, i18n);
    playerList = new ArrayList<>();
    playerList.add(player);
    teams = FXCollections.observableHashMap();
    when(uiService.loadFxml("theme/player_card_tooltip.fxml")).thenReturn(playerCardTooltipController);
    when(uiService.loadFxml("theme/rating_change_label.fxml")).thenReturn(ratingChangeLabelController);
    when(playerCardTooltipController.getRoot()).thenReturn(new Label());
    when(ratingChangeLabelController.getRoot()).thenReturn(new Label());
    when(player.getId()).thenReturn(1);
    playerStats = new PlayerStats(1, 1000, 0, 1100d, 0d, 0);
    teams.put("2", Collections.singletonList(playerStats));
    loadFxml("theme/team_card.fxml", param -> instance);
}
Also used : Label(javafx.scene.control.Label) PlayerStats(com.faforever.client.replay.Replay.PlayerStats) Before(org.junit.Before)

Example 2 with PlayerStats

use of com.faforever.client.replay.Replay.PlayerStats 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 3 with PlayerStats

use of com.faforever.client.replay.Replay.PlayerStats in project downlords-faf-client by FAForever.

the class ReplayDetailController method populateTeamsContainer.

private void populateTeamsContainer() {
    if (!replay.getValidity().equals(Validity.VALID)) {
        showRatingChangeButton.setDisable(true);
        showRatingChangeButton.setText(i18n.get("game.notValid"));
    } else if (!replayService.replayChangedRating(replay)) {
        showRatingChangeButton.setDisable(true);
        showRatingChangeButton.setText(i18n.get("game.notRatedYet"));
    }
    Map<Integer, PlayerStats> statsByPlayerId = teams.values().stream().flatMap(Collection::stream).collect(Collectors.toMap(PlayerStats::getPlayerId, Function.identity()));
    Platform.runLater(() -> teams.forEach((team, value) -> {
        List<Integer> playerIds = value.stream().map(PlayerStats::getPlayerId).collect(Collectors.toList());
        TeamCardController controller = uiService.loadFxml("theme/team_card.fxml");
        teamCardControllers.add(controller);
        playerService.getPlayersByIds(playerIds).thenAccept(players -> controller.setPlayersInTeam(team, players, player -> {
            PlayerStats playerStats = statsByPlayerId.get(player.getId());
            return new Rating(playerStats.getBeforeMean(), playerStats.getBeforeDeviation());
        }, RatingType.EXACT));
        teamsContainer.getChildren().add(controller.getRoot());
    }));
}
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) Rating(com.faforever.client.util.Rating) List(java.util.List) ArrayList(java.util.ArrayList) PlayerStats(com.faforever.client.replay.Replay.PlayerStats) TeamCardController(com.faforever.client.game.TeamCardController)

Aggregations

PlayerStats (com.faforever.client.replay.Replay.PlayerStats)3 Label (javafx.scene.control.Label)3 Validity (com.faforever.client.api.dto.Validity)2 ClientProperties (com.faforever.client.config.ClientProperties)2 Controller (com.faforever.client.fx.Controller)2 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)2 StringCell (com.faforever.client.fx.StringCell)2 RatingType (com.faforever.client.game.RatingType)2 TeamCardController (com.faforever.client.game.TeamCardController)2 I18n (com.faforever.client.i18n.I18n)2 MapBean (com.faforever.client.map.MapBean)2 MapService (com.faforever.client.map.MapService)2 PreviewSize (com.faforever.client.map.MapServiceImpl.PreviewSize)2 Player (com.faforever.client.player.Player)2 PlayerService (com.faforever.client.player.PlayerService)2 RatingService (com.faforever.client.rating.RatingService)2 ChatMessage (com.faforever.client.replay.Replay.ChatMessage)2 GameOption (com.faforever.client.replay.Replay.GameOption)2 UiService (com.faforever.client.theme.UiService)2 Rating (com.faforever.client.util.Rating)2