Skip to content

Commit 70d4b57

Browse files
committed
WIP
1 parent 629212b commit 70d4b57

File tree

9 files changed

+74
-10
lines changed

9 files changed

+74
-10
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ dependencies {
294294
implementation("io.projectreactor.addons:reactor-extra")
295295
implementation("io.projectreactor:reactor-tools")
296296

297-
def commonsVersion = "c060e973aa54e1fa215df15c1b8bad22806d84aa"
297+
def commonsVersion = "6d00833b277996e851730a2b1a5593852174e701"
298298

299299
implementation("com.github.FAForever.faf-java-commons:faf-commons-data:${commonsVersion}") {
300300
exclude module: 'guava'

src/main/java/com/faforever/client/domain/ReplayBean.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class ReplayBean {
6767
.boxed()
6868
.findFirst()
6969
.orElse(null));
70+
ObjectProperty<List<LeagueScoreJournalBean>> leagueScores = new SimpleObjectProperty<>();
7071

7172
public static String getReplayUrl(int replayId, String baseUrlFormat) {
7273
return String.format(baseUrlFormat, replayId);
@@ -311,6 +312,19 @@ public void setLocal(boolean local) {
311312
this.local.set(local);
312313
}
313314

315+
public List<LeagueScoreJournalBean> getLeagueScores() {
316+
return leagueScores.get();
317+
}
318+
319+
public ObjectProperty<List<LeagueScoreJournalBean>> leagueScoresProperty() {
320+
return leagueScores;
321+
}
322+
323+
public void setLeagueScores(List<LeagueScoreJournalBean> scores) {
324+
leagueScores.set(scores);
325+
System.out.println(scores);
326+
}
327+
314328
@Value
315329
public static class ChatMessage {
316330
ObjectProperty<Duration> time = new SimpleObjectProperty<>();

src/main/java/com/faforever/client/game/PlayerCardController.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.faforever.client.domain.GamePlayerStatsBean;
66
import com.faforever.client.domain.LeaderboardRatingJournalBean;
77
import com.faforever.client.domain.PlayerBean;
8+
import com.faforever.client.domain.SubdivisionBean;
89
import com.faforever.client.fx.Controller;
910
import com.faforever.client.fx.JavaFxUtil;
1011
import com.faforever.client.fx.SimpleChangeListener;
@@ -21,6 +22,7 @@
2122
import com.faforever.client.fx.contextmenu.ShowPlayerInfoMenuItem;
2223
import com.faforever.client.fx.contextmenu.ViewReplaysMenuItem;
2324
import com.faforever.client.i18n.I18n;
25+
import com.faforever.client.leaderboard.LeaderboardService;
2426
import com.faforever.client.player.CountryFlagService;
2527
import com.faforever.client.player.SocialStatus;
2628
import com.faforever.client.theme.UiService;
@@ -59,6 +61,7 @@ public class PlayerCardController implements Controller<Node> {
5961
private final UiService uiService;
6062
private final CountryFlagService countryFlagService;
6163
private final AvatarService avatarService;
64+
private final LeaderboardService leaderboardService;
6265
private final ContextMenuBuilder contextMenuBuilder;
6366
private final I18n i18n;
6467

@@ -70,21 +73,24 @@ public class PlayerCardController implements Controller<Node> {
7073
public Label friendIconText;
7174
public Region factionIcon;
7275
public ImageView factionImage;
76+
public ImageView divisionImageView;
7377
public Label noteIcon;
7478
public Label ratingChange;
7579

7680
private final ObjectProperty<PlayerBean> player = new SimpleObjectProperty<>();
7781
private final ObjectProperty<GamePlayerStatsBean> playerStats = new SimpleObjectProperty<>();
7882
private final ObjectProperty<Integer> rating = new SimpleObjectProperty<>();
83+
private final ObjectProperty<SubdivisionBean> division = new SimpleObjectProperty<>();
7984
private final ObjectProperty<Faction> faction = new SimpleObjectProperty<>();
8085
private final Tooltip noteTooltip = new Tooltip();
8186
private final Tooltip avatarTooltip = new Tooltip();
8287

8388
@Override
8489
public void initialize() {
85-
JavaFxUtil.bindManagedToVisible(factionIcon, foeIconText, factionImage, friendIconText, countryImageView, noteIcon);
90+
JavaFxUtil.bindManagedToVisible(factionIcon, foeIconText, factionImage, friendIconText, countryImageView, divisionImageView, noteIcon);
8691
countryImageView.visibleProperty().bind(countryImageView.imageProperty().isNotNull());
8792
avatarImageView.visibleProperty().bind(avatarImageView.imageProperty().isNotNull());
93+
divisionImageView.visibleProperty().bind(divisionImageView.imageProperty().isNotNull());
8894

8995
ObservableValue<Boolean> showing = uiService.createShowingProperty(getRoot());
9096

@@ -98,10 +104,13 @@ public void initialize() {
98104
.when(showing));
99105
avatarImageView.imageProperty()
100106
.bind(player.flatMap(PlayerBean::avatarProperty).map(avatarService::loadAvatar).when(showing));
107+
divisionImageView.imageProperty()
108+
.bind(division.flatMap(SubdivisionBean::smallImageUrlProperty).map(leaderboardService::loadDivisionImage).when(showing));
101109
playerInfo.textProperty()
102110
.bind(player.flatMap(PlayerBean::usernameProperty)
103-
.flatMap(username -> rating.map(value -> i18n.get("userInfo.tooltipFormat.withRating", username, value))
104-
.orElse(i18n.get("userInfo.tooltipFormat.noRating", username)))
111+
.map(username -> (rating.get() != null && division.get() == null)
112+
? i18n.get("userInfo.tooltipFormat.withRating", username, rating.get())
113+
: i18n.get("userInfo.tooltipFormat.noRating", username))
105114
.when(showing));
106115
foeIconText.visibleProperty()
107116
.bind(player.flatMap(PlayerBean::socialStatusProperty)
@@ -235,6 +244,18 @@ public void setRating(Integer rating) {
235244
this.rating.set(rating);
236245
}
237246

247+
public SubdivisionBean getDivision() {
248+
return division.get();
249+
}
250+
251+
public ObjectProperty<SubdivisionBean> divisionProperty() {
252+
return division;
253+
}
254+
255+
public void setDivision(SubdivisionBean subdivision) {
256+
this.division.set(subdivision);
257+
}
258+
238259
public Faction getFaction() {
239260
return faction.get();
240261
}

src/main/java/com/faforever/client/game/TeamCardController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.faforever.client.domain.GameBean;
55
import com.faforever.client.domain.GamePlayerStatsBean;
66
import com.faforever.client.domain.PlayerBean;
7+
import com.faforever.client.domain.SubdivisionBean;
78
import com.faforever.client.fx.Controller;
89
import com.faforever.client.fx.FxApplicationThreadExecutor;
910
import com.faforever.client.fx.SimpleChangeListener;
@@ -55,6 +56,7 @@ public class TeamCardController implements Controller<Node> {
5556
private final ObjectProperty<List<Integer>> playerIds = new SimpleObjectProperty<>(List.of());
5657
private final ObjectProperty<List<PlayerBean>> players = new SimpleObjectProperty<>(List.of());
5758
private final ObjectProperty<Function<PlayerBean, Integer>> ratingProvider = new SimpleObjectProperty<>();
59+
private final ObjectProperty<Function<PlayerBean, SubdivisionBean>> divisionProvider = new SimpleObjectProperty<>();
5860
private final ObjectProperty<Function<PlayerBean, Faction>> factionProvider = new SimpleObjectProperty<>();
5961
private final ObjectProperty<RatingPrecision> ratingPrecision = new SimpleObjectProperty<>();
6062
private final IntegerProperty teamId = new SimpleIntegerProperty();
@@ -98,6 +100,8 @@ private List<PlayerCardController> createPlayerCardControllers(List<PlayerBean>
98100
controller.ratingProperty()
99101
.bind(ratingProvider.map(ratingFunction -> ratingFunction.apply(player))
100102
.flatMap(rating -> ratingPrecision.map(precision -> precision == RatingPrecision.ROUNDED ? RatingUtil.getRoundedRating(rating) : rating)));
103+
controller.divisionProperty()
104+
.bind(divisionProvider.map(divisionFunction -> divisionFunction.apply(player)));
101105
controller.factionProperty()
102106
.bind(factionProvider.map(factionFunction -> factionFunction.apply(player)));
103107
controller.setPlayer(player);
@@ -119,6 +123,10 @@ public void setRatingProvider(Function<PlayerBean, Integer> ratingProvider) {
119123
this.ratingProvider.set(ratingProvider);
120124
}
121125

126+
public void setDivisionProvider(Function<PlayerBean, SubdivisionBean> divisionProvider) {
127+
this.divisionProvider.set(divisionProvider);
128+
}
129+
122130
public void setFactionProvider(Function<PlayerBean, Faction> factionProvider) {
123131
this.factionProvider.set(factionProvider);
124132
}

src/main/java/com/faforever/client/leaderboard/LeaderboardService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,12 @@ public CompletableFuture<List<LeagueEntryBean>> getEntries(SubdivisionBean subdi
225225
);
226226
}
227227

228-
public CompletableFuture<LeagueScoreJournalBean> getLeagueScoreJournalEntry(PlayerBean player, ReplayBean replay) {
228+
public CompletableFuture<List<LeagueScoreJournalBean>> getLeagueScoreJournalForReplay(ReplayBean replay) {
229229
ElideNavigatorOnCollection<LeagueScoreJournal> navigator = ElideNavigator.of(LeagueScoreJournal.class).collection()
230-
.setFilter(qBuilder().intNum("login.id").eq(player.getId())
231-
.and().intNum("game.id").eq(replay.getId()));
230+
.setFilter(qBuilder().intNum("game.id").eq(replay.getId()));
232231
return fafApiAccessor.getMany(navigator)
233-
.next()
234232
.map(dto -> leaderboardMapper.map(dto, new CycleAvoidingMappingContext()))
233+
.collectList()
235234
.toFuture();
236235
}
237236

src/main/java/com/faforever/client/replay/ReplayDetailController.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import com.faforever.client.config.ClientProperties;
44
import com.faforever.client.domain.FeaturedModBean;
55
import com.faforever.client.domain.GamePlayerStatsBean;
6+
import com.faforever.client.domain.LeagueScoreJournalBean;
67
import com.faforever.client.domain.MapBean;
78
import com.faforever.client.domain.MapVersionBean;
89
import com.faforever.client.domain.PlayerBean;
910
import com.faforever.client.domain.ReplayBean;
1011
import com.faforever.client.domain.ReplayBean.ChatMessage;
1112
import com.faforever.client.domain.ReplayBean.GameOption;
1213
import com.faforever.client.domain.ReplayReviewBean;
14+
import com.faforever.client.domain.SubdivisionBean;
1315
import com.faforever.client.fx.Controller;
1416
import com.faforever.client.fx.FxApplicationThreadExecutor;
1517
import com.faforever.client.fx.ImageViewHelper;
@@ -20,6 +22,7 @@
2022
import com.faforever.client.game.RatingPrecision;
2123
import com.faforever.client.game.TeamCardController;
2224
import com.faforever.client.i18n.I18n;
25+
import com.faforever.client.leaderboard.LeaderboardService;
2326
import com.faforever.client.main.event.DeleteLocalReplayEvent;
2427
import com.faforever.client.map.MapService;
2528
import com.faforever.client.map.MapService.PreviewSize;
@@ -98,6 +101,7 @@ public class ReplayDetailController implements Controller<Node> {
98101
private final UiService uiService;
99102
private final ReplayService replayService;
100103
private final RatingService ratingService;
104+
private final LeaderboardService leaderboardService;
101105
private final MapService mapService;
102106
private final MapGeneratorService mapGeneratorService;
103107
private final PlayerService playerService;
@@ -300,6 +304,8 @@ private void onReplayChanged(ReplayBean newValue) {
300304
if (newValue.getReplayFile() != null) {
301305
enrichReplayLater(newValue.getReplayFile(), newValue);
302306
}
307+
308+
leaderboardService.getLeagueScoreJournalForReplay(newValue).thenAccept(newValue::setLeagueScores);
303309

304310
reviewsController.setCanWriteReview(true);
305311

@@ -441,6 +447,7 @@ private List<TeamCardController> createTeamCardControllers(Map<String, List<Game
441447

442448
controller.setRatingPrecision(RatingPrecision.EXACT);
443449
controller.setRatingProvider(player -> getPlayerRating(player, statsByPlayer));
450+
controller.setDivisionProvider(this::getPlayerDivision);
444451
controller.setFactionProvider(player -> getPlayerFaction(player, statsByPlayer));
445452
controller.setTeamId(Integer.parseInt(team));
446453
controller.setPlayers(statsByPlayer.keySet());
@@ -464,6 +471,16 @@ private Integer getPlayerRating(PlayerBean player, Map<PlayerBean, GamePlayerSta
464471
.map(RatingUtil::getRating)
465472
.orElse(null);
466473
}
474+
475+
private SubdivisionBean getPlayerDivision(PlayerBean player) {
476+
return replay.map(ReplayBean::getLeagueScores).map(leagueScoreJournalBeans -> leagueScoreJournalBeans
477+
.stream()
478+
.filter(leagueScoreJournalBean -> leagueScoreJournalBean.getLoginId() == player.getId())
479+
.findFirst()
480+
.map(LeagueScoreJournalBean::getDivisionAfter)
481+
.orElse(null)
482+
).getValue();
483+
}
467484

468485
public void onReport() {
469486
ReportDialogController reportDialogController = uiService.loadFxml("theme/reporting/report_dialog.fxml");

src/main/resources/theme/player_card.fxml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@
5454
<Label fx:id="ratingChange"
5555
minWidth="-Infinity"
5656
styleClass="rating-change-label"/>
57+
<ImageView fx:id="divisionImageView" fitHeight="20.0" fitWidth="40.0" pickOnBounds="true" preserveRatio="true"
58+
visible="false"/>
5759
</HBox>

src/main/resources/theme/team_card.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<?import javafx.scene.layout.VBox?>
66
<VBox xmlns:fx="http://javafx.com/fxml/1" VBox.vgrow="ALWAYS" fx:id="teamPaneRoot"
77
xmlns="http://javafx.com/javafx/10.0.2" fx:controller="com.faforever.client.game.TeamCardController">
8-
<VBox VBox.vgrow="ALWAYS" prefWidth="215.0" spacing="20.0" styleClass="card">
8+
<VBox VBox.vgrow="ALWAYS" prefWidth="230.0" spacing="20.0" styleClass="card">
99
<children>
1010
<Label fx:id="teamNameLabel" styleClass="h3" text="Label"/>
1111
<VBox fx:id="teamPane"/>

src/test/java/com/faforever/client/game/PlayerCardControllerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.faforever.client.fx.contextmenu.ContextMenuBuilder;
88
import com.faforever.client.helper.TooltipHelper;
99
import com.faforever.client.i18n.I18n;
10+
import com.faforever.client.leaderboard.LeaderboardService;
1011
import com.faforever.client.player.CountryFlagService;
1112
import com.faforever.client.player.SocialStatus;
1213
import com.faforever.client.test.PlatformTest;
@@ -37,6 +38,8 @@ public class PlayerCardControllerTest extends PlatformTest {
3738
@Mock
3839
private CountryFlagService countryFlagService;
3940
@Mock
41+
private LeaderboardService leaderboardService;
42+
@Mock
4043
private AvatarService avatarService;
4144
@Mock
4245
private EventBus eventBus;
@@ -47,7 +50,7 @@ public class PlayerCardControllerTest extends PlatformTest {
4750

4851
@BeforeEach
4952
public void setUp() throws Exception {
50-
instance = new PlayerCardController(uiService, countryFlagService, avatarService, contextMenuBuilder, i18n);
53+
instance = new PlayerCardController(uiService, countryFlagService, avatarService, leaderboardService, contextMenuBuilder, i18n);
5154

5255
when(uiService.getImage(UiService.RANDOM_FACTION_IMAGE)).thenReturn(new Image(UiService.RANDOM_FACTION_IMAGE));
5356
when(uiService.createShowingProperty(any())).thenReturn(new SimpleBooleanProperty(true));

0 commit comments

Comments
 (0)