Skip to content

Commit

Permalink
#1645-add-faction-icon-replay-detail
Browse files Browse the repository at this point in the history
fixes #1645
-added coloured icons next to the name in the replay detail overview
-also fixed long names getting cut off and not being able to see the rating
-also fixed rating change being shown as "..." when there were long names
  • Loading branch information
FemtoZetta committed Mar 29, 2020
1 parent 44c7059 commit ee8c7e0
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.faforever.client.i18n.I18n;
import com.faforever.client.player.Player;
import com.faforever.client.player.SocialStatus;
import com.google.common.annotations.VisibleForTesting;
import javafx.beans.binding.Bindings;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,21 +24,30 @@
@RequiredArgsConstructor
public class PlayerCardTooltipController implements Controller<Node> {

@VisibleForTesting
static final Image RANDOM_IMAGE = new Image("/images/factions/random.png");
private static final String AEON = "aeon";
private static final String CYBRAN = "cybran";
private static final String SERAPHIM = "seraphim";
private final CountryFlagService countryFlagService;
private final I18n i18n;
private static final String UEF = "uef";
public Label playerInfo;
public ImageView countryImageView;
public Label foeIconText;
public HBox root;
public Label friendIconText;
public Label factionIcon;
public ImageView factionImage;

public void setPlayer(Player player, int rating) {
public void setPlayer(Player player, int rating, Faction faction) {
if (player == null) {
return;
}
countryFlagService.loadCountryFlag(player.getCountry()).ifPresent(image -> countryImageView.setImage(image));

String playerInfoLocalized = i18n.get("userInfo.tooltipFormat", player.getUsername(), rating);
setFactionIcon(faction);
playerInfo.setText(playerInfoLocalized);
foeIconText.visibleProperty().bind(Bindings.createBooleanBinding(() -> player.getSocialStatus() == SocialStatus.FOE, player.socialStatusProperty()));
friendIconText.visibleProperty().bind(Bindings.createBooleanBinding(() -> player.getSocialStatus() == SocialStatus.FRIEND, player.socialStatusProperty()));
Expand All @@ -48,9 +59,40 @@ public Node getRoot() {

@Override
public void initialize() {
factionImage.managedProperty().bind(factionImage.visibleProperty());
factionIcon.managedProperty().bind(factionIcon.visibleProperty());
foeIconText.managedProperty().bind(foeIconText.visibleProperty());
foeIconText.setTooltip(new Tooltip(i18n.get("userInfo.foe")));
friendIconText.managedProperty().bind(friendIconText.visibleProperty());
friendIconText.setTooltip(new Tooltip(i18n.get("userInfo.friend")));
}

private void setFactionIcon(Faction faction) {
if (faction == null) {
return;
}

switch (faction) {
case AEON:
factionIcon.setText("\uE900");
factionIcon.getStyleClass().add(AEON);
break;
case CYBRAN:
factionIcon.setText("\uE902");
factionIcon.getStyleClass().add(CYBRAN);
break;
case SERAPHIM:
factionIcon.setText("\uE903");
factionIcon.getStyleClass().add(SERAPHIM);
break;
case UEF:
factionIcon.setText("\uE904");
factionIcon.getStyleClass().add(UEF);
break;
default:
factionImage.setImage(RANDOM_IMAGE);
break;
}
factionIcon.setVisible(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
public class RatingChangeLabelController implements Controller<Node> {
private static final PseudoClass POSITIVE = PseudoClass.getPseudoClass("positive");
private static final PseudoClass NEGATIVE = PseudoClass.getPseudoClass("negative");
public Label ratingChangLabelRoot;
public Label ratingChangeLabelRoot;
private final I18n i18n;

@Override
public Node getRoot() {
return ratingChangLabelRoot;
return ratingChangeLabelRoot;
}

@Override
public void initialize() {
ratingChangLabelRoot.setVisible(false);
ratingChangeLabelRoot.setVisible(false);
}

public void setRatingChange(PlayerStats playerStats) {
Expand All @@ -39,9 +39,9 @@ public void setRatingChange(PlayerStats playerStats) {
int oldRating = RatingUtil.getRating(playerStats.getBeforeMean(), playerStats.getBeforeDeviation());

int ratingChange = newRating - oldRating;
ratingChangLabelRoot.setText(i18n.numberWithSign(ratingChange));
ratingChangLabelRoot.pseudoClassStateChanged(ratingChange < 0 ? NEGATIVE : POSITIVE, true);
ratingChangeLabelRoot.setText(i18n.numberWithSign(ratingChange));
ratingChangeLabelRoot.pseudoClassStateChanged(ratingChange < 0 ? NEGATIVE : POSITIVE, true);

ratingChangLabelRoot.setVisible(true);
ratingChangeLabelRoot.setVisible(true);
}
}
10 changes: 7 additions & 3 deletions src/main/java/com/faforever/client/game/TeamCardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ static void createAndAdd(ObservableMap<? extends String, ? extends List<String>>

TeamCardController teamCardController = uiService.loadFxml("theme/team_card.fxml");
teamCardController.setPlayersInTeam(entry.getKey(), players,
player -> new Rating(player.getGlobalRatingMean(), player.getGlobalRatingDeviation()), RatingType.ROUNDED);
player -> new Rating(player.getGlobalRatingMean(), player.getGlobalRatingDeviation()), null, RatingType.ROUNDED);
teamsPane.getChildren().add(teamCardController.getRoot());
}
}

public void setPlayersInTeam(String team, List<Player> playerList, Function<Player, Rating> ratingProvider, RatingType ratingType) {
public void setPlayersInTeam(String team, List<Player> playerList, Function<Player, Rating> ratingProvider, Function<Player, Faction> playerFactionProvider, RatingType ratingType) {
int totalRating = 0;
for (Player player : playerList) {
// If the server wasn't bugged, this would never be the case.
Expand All @@ -77,7 +77,11 @@ public void setPlayersInTeam(String team, List<Player> playerList, Function<Play
if (ratingType == RatingType.ROUNDED) {
playerRating = RatingUtil.getRoundedGlobalRating(player);
}
playerCardTooltipController.setPlayer(player, playerRating);
Faction faction = null;
if(playerFactionProvider != null) {
faction = playerFactionProvider.apply(player);
}
playerCardTooltipController.setPlayer(player, playerRating, faction);

RatingChangeLabelController ratingChangeLabelController = uiService.loadFxml("theme/rating_change_label.fxml");
ratingChangeControllersByPlayerId.put(player.getId(), ratingChangeLabelController);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/faforever/client/replay/Replay.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.faforever.client.api.dto.Game;
import com.faforever.client.api.dto.GamePlayerStats;
import com.faforever.client.api.dto.Validity;
import com.faforever.client.game.Faction;
import com.faforever.client.map.MapBean;
import com.faforever.client.mod.FeaturedMod;
import com.faforever.client.vault.review.Review;
Expand Down Expand Up @@ -402,6 +403,7 @@ public static class PlayerStats {
private final Double afterMean;
private final Double afterDeviation;
private final int score;
private final Faction faction;

public static PlayerStats fromDto(GamePlayerStats gamePlayerStats) {
return new PlayerStats(
Expand All @@ -410,7 +412,8 @@ public static PlayerStats fromDto(GamePlayerStats gamePlayerStats) {
gamePlayerStats.getBeforeDeviation(),
gamePlayerStats.getAfterMean() == null ? null : Double.valueOf(gamePlayerStats.getAfterMean()),
gamePlayerStats.getAfterDeviation() == null ? null : Double.valueOf(gamePlayerStats.getAfterDeviation()),
gamePlayerStats.getScore()
gamePlayerStats.getScore(),
gamePlayerStats.getFaction()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.faforever.client.fx.Controller;
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.fx.StringCell;
import com.faforever.client.game.Faction;
import com.faforever.client.game.RatingType;
import com.faforever.client.game.TeamCardController;
import com.faforever.client.i18n.I18n;
Expand Down Expand Up @@ -310,11 +311,18 @@ private void populateTeamsContainer() {

TeamCardController controller = uiService.loadFxml("theme/team_card.fxml");
teamCardControllers.add(controller);

Function<Player, Rating> playerRatingFunction = player -> {
PlayerStats playerStats = statsByPlayerId.get(player.getId());
return new Rating(playerStats.getBeforeMean(), playerStats.getBeforeDeviation());
};

Function<Player, Faction> playerFactionFunction = player -> statsByPlayerId.get(player.getId()).getFaction();

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));
.thenAccept(players ->
controller.setPlayersInTeam(team, players, playerRatingFunction, playerFactionFunction, RatingType.EXACT)
);

teamsContainer.getChildren().add(controller.getRoot());
}));
Expand Down
Binary file added src/main/resources/images/factions/random.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 28 additions & 23 deletions src/main/resources/theme/player_card_tooltip.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<HBox xmlns:fx="http://javafx.com/fxml/1" fx:id="root" xmlns="http://javafx.com/javafx/8.0.141"
fx:controller="com.faforever.client.game.PlayerCardTooltipController">
<Label fx:id="playerInfo" styleClass="player-card-tooltip" text="&lt;PlayerInfo&gt;">
<graphic>
<ImageView fx:id="countryImageView" pickOnBounds="true" preserveRatio="true"/>
</graphic>
</Label>
<Label fx:id="foeIconText" minWidth="-Infinity">
<graphic>
<Label text="" styleClass="icon"/>
</graphic>
<HBox.margin>
<Insets left="5.0"/>
</HBox.margin>
</Label>
<Label fx:id="friendIconText" minWidth="-Infinity">
<graphic>
<Label text="" styleClass="icon"/>
</graphic>
<HBox.margin>
<Insets left="5.0"/>
</HBox.margin>
</Label>
<HBox fx:id="root" alignment="CENTER_LEFT" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.faforever.client.game.PlayerCardTooltipController">
<ImageView fx:id="factionImage" fitHeight="22.0" fitWidth="22.0" pickOnBounds="true" preserveRatio="true" visible="false">
<HBox.margin>
<Insets right="4.0" />
</HBox.margin>
</ImageView>
<Label fx:id="factionIcon" styleClass="faction-label, icon" visible="false"/>
<Label fx:id="playerInfo" styleClass="player-card-tooltip" text="&lt;PlayerInfo&gt;" wrapText="true">
<graphic>
<ImageView fx:id="countryImageView" pickOnBounds="true" preserveRatio="true" />
</graphic>
</Label>
<Label fx:id="foeIconText" minWidth="-Infinity">
<graphic>
<Label styleClass="icon" text="" />
</graphic>
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</Label>
<Label fx:id="friendIconText" minWidth="-Infinity">
<graphic>
<Label styleClass="icon" text="" />
</graphic>
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</Label>
</HBox>
13 changes: 7 additions & 6 deletions src/main/resources/theme/rating_change_label.fxml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<Label xmlns:fx="http://javafx.com/fxml"
xmlns="http://javafx.com/javafx"
fx:controller="com.faforever.client.game.RatingChangeLabelController"
fx:id="ratingChangLabelRoot"
styleClass="rating-change-label">
</Label>
<Label fx:id="ratingChangeLabelRoot"
minWidth="-Infinity"
styleClass="rating-change-label"
xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.faforever.client.game.RatingChangeLabelController">
</Label>
32 changes: 27 additions & 5 deletions src/main/resources/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@

/***************** Icon *****************/

.icon {
.icon, .icon .text {
-fx-font-family: 'dfc-icons';
-fx-font-size: 20;
-fx-fill: -fx-light-text-color;
Expand Down Expand Up @@ -979,19 +979,19 @@
-fx-border-color: -divider-color;
}

.toggle-button.aeon .text {
.aeon .text {
-fx-fill: -green-500;
}

.toggle-button.cybran .text {
.cybran .text {
-fx-fill: -red-500;
}

.toggle-button.uef .text {
.uef .text {
-fx-fill: -blue-500;
}

.toggle-button.seraphim .text {
.seraphim .text {
-fx-fill: -amber-500;
}

Expand All @@ -1002,6 +1002,28 @@
-fx-opacity: 1;
}

/***************** Faction label *****************/

.icon.faction-label .text, .icon.faction-label {
-fx-font-size: 2em;
}

.faction-label.aeon .text {
-fx-fill: -green-500;
}

.faction-label.cybran .text {
-fx-fill: -red-500;
}

.faction-label.uef .text {
-fx-fill: -blue-500;
}

.faction-label.seraphim .text {
-fx-fill: -amber-500;
}

/***************** Map preview *****************/

.map-preview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public void testSetFoe() {
.defaultValues()
.socialStatus(SocialStatus.FOE);
Player player = playerBuilder.get();
instance.setPlayer(player, 1000);
instance.setPlayer(player, 1000, Faction.CYBRAN);

assertThat(instance.factionIcon.getText(), is("\uE902"));
assertThat(instance.factionIcon.isVisible(), is(true));
assertThat(instance.factionImage.isVisible(), is(false));
assertThat(instance.foeIconText.isVisible(), is(true));
assertThat(instance.friendIconText.isVisible(), is(false));
assertThat(instance.playerInfo.getText(), is("foe(1000)"));
Expand All @@ -51,8 +54,11 @@ public void testSetFriend() {
.defaultValues()
.socialStatus(SocialStatus.FRIEND);
Player player = playerBuilder.get();
instance.setPlayer(player, 1000);
instance.setPlayer(player, 1000, Faction.SERAPHIM);

assertThat(instance.factionIcon.getText(), is("\uE903"));
assertThat(instance.factionIcon.isVisible(), is(true));
assertThat(instance.factionImage.isVisible(), is(false));
assertThat(instance.foeIconText.isVisible(), is(false));
assertThat(instance.friendIconText.isVisible(), is(true));
assertThat(instance.playerInfo.getText(), is("user(1000)"));
Expand All @@ -66,8 +72,11 @@ public void testSetOther() {
.defaultValues()
.socialStatus(SocialStatus.OTHER);
Player player = playerBuilder.get();
instance.setPlayer(player, 1000);
instance.setPlayer(player, 1000, Faction.NOMAD);

assertThat(instance.factionIcon.isVisible(), is(false));
assertThat(instance.factionImage.getImage().getUrl(), is(PlayerCardTooltipController.RANDOM_IMAGE.getUrl()));
assertThat(instance.factionImage.isVisible(), is(true));
assertThat(instance.foeIconText.isVisible(), is(false));
assertThat(instance.friendIconText.isVisible(), is(false));
assertThat(instance.playerInfo.getText(), is("user(1000)"));
Expand Down

0 comments on commit ee8c7e0

Please sign in to comment.