Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#1990-add-channel-button
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Nov 6, 2020
2 parents e49efb0 + 901e37f commit e1eef6c
Show file tree
Hide file tree
Showing 27 changed files with 309 additions and 48 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/faforever/client/chat/ChatChannelUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ChatChannelUser {
private final ObjectProperty<Image> mapImage;
private final ObjectProperty<Image> statusImage;
private final BooleanProperty displayed;
private final BooleanProperty populated;

ChatChannelUser(String username, Color color, boolean moderator) {
this(username, color, moderator, null);
Expand All @@ -58,6 +59,7 @@ public class ChatChannelUser {
this.mapImage = new SimpleObjectProperty<>();
this.statusImage = new SimpleObjectProperty<>();
this.displayed = new SimpleBooleanProperty(false);
this.populated = new SimpleBooleanProperty(false);
}

public Optional<Player> getPlayer() {
Expand Down Expand Up @@ -229,6 +231,18 @@ public BooleanProperty displayedProperty() {
return displayed;
}

public boolean isPopulated() {
return populated.get();
}

public void setPopulated(boolean populated) {
this.populated.set(populated);
}

public BooleanProperty populatedProperty() {
return populated;
}

@Override
public boolean equals(Object obj) {
return obj != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.faforever.client.fx.PlatformService;
import com.faforever.client.fx.StringListCell;
import com.faforever.client.game.JoinGameHelper;
import com.faforever.client.game.KnownFeaturedMod;
import com.faforever.client.game.PlayerStatus;
import com.faforever.client.i18n.I18n;
import com.faforever.client.main.event.ShowUserReplaysEvent;
Expand All @@ -22,6 +21,7 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.remote.domain.GameType;
import com.faforever.client.replay.ReplayService;
import com.faforever.client.theme.UiService;
import com.faforever.client.ui.alert.Alert;
Expand Down Expand Up @@ -201,15 +201,12 @@ public void setChatUser(ChatChannelUser chatUser) {
removeFoeItem.visibleProperty().bind(newValue.socialStatusProperty().isEqualTo(FOE));
reportItem.visibleProperty().bind(newValue.socialStatusProperty().isNotEqualTo(SELF));

// TODO: Make this ignore TMM games too and not just ladder
// https://github.com/FAForever/downlords-faf-client/issues/1770
joinGameItem.visibleProperty().bind(newValue.socialStatusProperty().isNotEqualTo(SELF)
.and(newValue.statusProperty().isEqualTo(PlayerStatus.LOBBYING)
.or(newValue.statusProperty().isEqualTo(PlayerStatus.HOSTING)))
.and(Bindings.createBooleanBinding(() -> {
return newValue.getGame() != null
&& newValue.getGame().getFeaturedMod() != null
&& !newValue.getGame().getFeaturedMod().equals(KnownFeaturedMod.LADDER_1V1.getTechnicalName());
&& newValue.getGame().getGameType() != GameType.MATCHMAKER;
}, newValue.gameProperty())
));
watchGameItem.visibleProperty().bind(newValue.statusProperty().isEqualTo(PlayerStatus.PLAYING));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.faforever.client.chat;

import com.faforever.client.chat.event.ChatUserGameChangeEvent;
import com.faforever.client.chat.event.ChatUserPopulateEvent;
import com.faforever.client.clan.Clan;
import com.faforever.client.fx.Controller;
Expand Down Expand Up @@ -146,7 +145,7 @@ public void initialize() {

JavaFxUtil.bind(avatarImageView.visibleProperty(), Bindings.isNotNull(avatarImageView.imageProperty()));
JavaFxUtil.bind(countryImageView.visibleProperty(), Bindings.isNotNull(countryImageView.imageProperty()));
JavaFxUtil.bind(clanMenu.visibleProperty(), Bindings.isNotNull(clanMenu.textProperty()));
JavaFxUtil.bind(clanMenu.visibleProperty(), Bindings.isNotEmpty(clanMenu.textProperty()));
JavaFxUtil.bind(playerStatusIndicator.visibleProperty(), Bindings.isNotNull(playerStatusIndicator.imageProperty()));
JavaFxUtil.bind(playerMapImage.visibleProperty(), Bindings.isNotNull(playerMapImage.imageProperty()));

Expand Down Expand Up @@ -255,8 +254,9 @@ public void setChatUser(@Nullable ChatChannelUser chatUser) {
if (this.chatUser.getPlayer().isPresent()) {
JavaFxUtil.bind(avatarTooltip.textProperty(), this.chatUser.getPlayer().get().avatarTooltipProperty());
}
eventBus.post(new ChatUserGameChangeEvent(this.chatUser));
eventBus.post(new ChatUserPopulateEvent(this.chatUser));
if (!this.chatUser.isPopulated()) {
eventBus.post(new ChatUserPopulateEvent(this.chatUser));
}
}

updateColor();
Expand Down
36 changes: 25 additions & 11 deletions src/main/java/com/faforever/client/chat/ChatUserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@ public void afterPropertiesSet() {

public void populateClan(ChatChannelUser chatChannelUser) {
if (chatChannelUser.getClan().isEmpty()) {
chatChannelUser.getPlayer().ifPresent(player -> clanService.getClanByTag(player.getClan())
.thenAccept(optionalClan -> Platform.runLater(() -> {
if (optionalClan.isPresent()) {
chatChannelUser.setClan(optionalClan.get());
chatChannelUser.setClanTag(String.format("[%s]", optionalClan.get().getTag()));
} else {
chatChannelUser.setClan(null);
chatChannelUser.setClanTag(null);
}
})));
chatChannelUser.getPlayer().ifPresent(player -> {
if (player.getClan() != null) {
clanService.getClanByTag(player.getClan())
.thenAccept(optionalClan -> Platform.runLater(() -> {
if (optionalClan.isPresent()) {
chatChannelUser.setClan(optionalClan.get());
chatChannelUser.setClanTag(String.format("[%s]", optionalClan.get().getTag()));
} else {
chatChannelUser.setClan(null);
chatChannelUser.setClanTag(null);
}
})
);
} else {
chatChannelUser.setClan(null);
chatChannelUser.setClanTag(null);
}
});
}
}

Expand Down Expand Up @@ -104,16 +112,22 @@ public void populateGameStatus(ChatChannelUser chatChannelUser) {
@Subscribe
public void onChatUserPopulate(ChatUserPopulateEvent event) {
ChatChannelUser chatChannelUser = event.getChatChannelUser();
if (chatChannelUser.isDisplayed()) {
if (chatChannelUser.isDisplayed() && !chatChannelUser.isPopulated()) {
chatChannelUser.setPopulated(true);
populateAvatar(chatChannelUser);
populateClan(chatChannelUser);
populateCountry(chatChannelUser);
populateGameStatus(chatChannelUser);
} else if (!chatChannelUser.isDisplayed()) {
chatChannelUser.setClan(null);
chatChannelUser.setClanTag(null);
chatChannelUser.setAvatar(null);
chatChannelUser.setCountryFlag(null);
chatChannelUser.setCountryName(null);
chatChannelUser.setStatus(null);
chatChannelUser.setMapImage(null);
chatChannelUser.setStatusImage(null);
chatChannelUser.setPopulated(false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/faforever/client/coop/CoopController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.faforever.client.mod.ModService;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.remote.domain.GameStatus;
import com.faforever.client.remote.domain.GameType;
import com.faforever.client.replay.ReplayService;
import com.faforever.client.reporting.ReportingService;
import com.faforever.client.theme.UiService;
Expand Down Expand Up @@ -70,8 +71,7 @@
public class CoopController extends AbstractViewController<Node> {

private static final Predicate<Game> OPEN_COOP_GAMES_PREDICATE = gameInfoBean ->
gameInfoBean.getStatus() == GameStatus.OPEN
&& COOP.getTechnicalName().equals(gameInfoBean.getFeaturedMod());
gameInfoBean.getStatus() == GameStatus.OPEN && gameInfoBean.getGameType() == GameType.COOP;

private final ReplayService replayService;
private final GameService gameService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ private IceAdapterApi newIceAdapterProxy() {
}

private void updateLobbyModeFromGameInfo(GameLaunchMessage gameLaunchMessage) {
// TODO: Replace with game type. Needs https://github.com/FAForever/server/issues/685
if (gameLaunchMessage.getInitMode() != null) {
lobbyInitMode = gameLaunchMessage.getInitMode();
return;
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/com/faforever/client/game/CustomGamesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.remote.domain.GameStatus;
import com.faforever.client.remote.domain.GameType;
import com.faforever.client.theme.UiService;
import com.faforever.client.ui.dialog.Dialog;
import com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent;
Expand Down Expand Up @@ -38,8 +39,6 @@
import org.springframework.stereotype.Component;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
Expand All @@ -49,16 +48,8 @@
@Slf4j
public class CustomGamesController extends AbstractViewController<Node> {

private static final Collection<String> HIDDEN_FEATURED_MODS = Arrays.asList(
KnownFeaturedMod.COOP.getTechnicalName(),
KnownFeaturedMod.LADDER_1V1.getTechnicalName(),
KnownFeaturedMod.GALACTIC_WAR.getTechnicalName(),
KnownFeaturedMod.MATCHMAKER.getTechnicalName()
);

private static final Predicate<Game> OPEN_CUSTOM_GAMES_PREDICATE = gameInfoBean ->
gameInfoBean.getStatus() == GameStatus.OPEN
&& !HIDDEN_FEATURED_MODS.contains(gameInfoBean.getFeaturedMod());
gameInfoBean.getStatus() == GameStatus.OPEN && gameInfoBean.getGameType() == GameType.CUSTOM;

private final UiService uiService;
private final GameService gameService;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/faforever/client/game/Game.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.client.game;

import com.faforever.client.remote.domain.GameStatus;
import com.faforever.client.remote.domain.GameType;
import com.faforever.client.remote.domain.VictoryCondition;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class Game {
private final ObjectProperty<VictoryCondition> victoryCondition;
private final ObjectProperty<Instant> startTime;
private final BooleanProperty enforceRating;
private final ObjectProperty<GameType> gameType;
/**
* Maps a sim mod's UID to its name.
*/
Expand Down Expand Up @@ -69,6 +71,7 @@ public Game() {
status = new SimpleObjectProperty<>();
startTime = new SimpleObjectProperty<>();
enforceRating = new SimpleBooleanProperty(false);
gameType = new SimpleObjectProperty<>();
}

public String getHost() {
Expand Down Expand Up @@ -223,6 +226,18 @@ public ObjectProperty<VictoryCondition> victoryConditionProperty() {
return victoryCondition;
}

public GameType getGameType() {
return gameType.get();
}

public void setGameType(GameType gameType) {
this.gameType.set(gameType);
}

public ObjectProperty<GameType> gameTypeProperty() {
return gameType;
}

/**
* Returns a map of simulation mod UIDs to the mod's name.
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/faforever/client/game/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ private void updateFromGameInfo(GameInfoMessage gameInfoMessage, Game game) {
));
game.setStatus(gameInfoMessage.getState());
game.setPasswordProtected(gameInfoMessage.getPasswordProtected());
game.setGameType(gameInfoMessage.getGameType());

game.setAverageRating(calcAverageRating(gameInfoMessage));

Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/faforever/client/player/PlayerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import com.faforever.client.game.GameAddedEvent;
import com.faforever.client.game.GameRemovedEvent;
import com.faforever.client.game.GameUpdatedEvent;
import com.faforever.client.game.KnownFeaturedMod;
import com.faforever.client.player.event.CurrentPlayerInfo;
import com.faforever.client.player.event.FriendJoinedGameEvent;
import com.faforever.client.remote.FafService;
import com.faforever.client.remote.domain.GameStatus;
import com.faforever.client.remote.domain.GameType;
import com.faforever.client.remote.domain.PlayersMessage;
import com.faforever.client.remote.domain.SocialMessage;
import com.faforever.client.user.UserService;
Expand Down Expand Up @@ -169,7 +169,7 @@ private void updateGamePlayers(List<String> currentPlayers, Game game) {
if (!currentPlayers.contains(player.getUsername())) {
player.setGame(null);
playersThatLeftTheGame.add(player);
player.getChatChannelUsers().forEach(chatChannelUser -> eventBus.post(new ChatUserGameChangeEvent(chatChannelUser)));
updatePlayerChatUsers(player);
}
}
previousPlayersFromGame.removeAll(playersThatLeftTheGame);
Expand All @@ -180,7 +180,7 @@ private void updateGamePlayers(List<String> currentPlayers, Game game) {
List<Player> previousPlayersFromGame = playersByGame.get(game.getId());
for (Player player : previousPlayersFromGame) {
player.setGame(null);
player.getChatChannelUsers().forEach(chatChannelUser -> eventBus.post(new ChatUserGameChangeEvent(chatChannelUser)));
updatePlayerChatUsers(player);
}
previousPlayersFromGame.clear();
}
Expand All @@ -189,14 +189,14 @@ private void updateGamePlayers(List<String> currentPlayers, Game game) {
private void updateGameDataForPlayer(Game game, Player player) {
if (game == null) {
player.setGame(null);
player.getChatChannelUsers().forEach(chatChannelUser -> eventBus.post(new ChatUserGameChangeEvent(chatChannelUser)));
updatePlayerChatUsers(player);
return;
}

if (game.getStatus() == GameStatus.CLOSED) {
playersByGame.remove(game.getId());
player.setGame(null);
player.getChatChannelUsers().forEach(chatChannelUser -> eventBus.post(new ChatUserGameChangeEvent(chatChannelUser)));
updatePlayerChatUsers(player);
return;
}

Expand All @@ -206,11 +206,11 @@ private void updateGameDataForPlayer(Game game, Player player) {

if (!playersByGame.get(game.getId()).contains(player)) {
player.setGame(game);
player.getChatChannelUsers().forEach(chatChannelUser -> eventBus.post(new ChatUserGameChangeEvent(chatChannelUser)));
updatePlayerChatUsers(player);
playersByGame.get(game.getId()).add(player);
if (player.getSocialStatus() == FRIEND
&& game.getStatus() == GameStatus.OPEN
&& !game.getFeaturedMod().equals(KnownFeaturedMod.LADDER_1V1.getTechnicalName())) {
&& game.getGameType() != GameType.MATCHMAKER) {
eventBus.post(new FriendJoinedGameEvent(player, game));
}
}
Expand Down Expand Up @@ -254,6 +254,15 @@ public Set<String> getPlayerNames() {
return new HashSet<>(playersByName.keySet());
}

public void updatePlayerChatUsers(Player player) {
player.getChatChannelUsers().forEach(chatChannelUser -> {
if (chatChannelUser.isDisplayed()
&& chatChannelUser.getStatus().filter(playerStatus -> playerStatus != player.getStatus()).isPresent()) {
eventBus.post(new ChatUserGameChangeEvent(chatChannelUser));
}
});
}

public void addFriend(Player player) {
playersByName.get(player.getUsername()).setSocialStatus(FRIEND);
friendList.add(player.getId());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/faforever/client/preferences/ChatPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ChatPrefs {
private final BooleanProperty hideFoeMessages;
private final BooleanProperty playerListShown;
private final ObjectProperty<TimeInfo> timeFormat;
private final ObjectProperty<DateInfo> dateFormat;
private final ObjectProperty<ChatFormat> chatFormat;
private final ListProperty<String> autoJoinChannels;
/**
Expand All @@ -58,6 +59,7 @@ public class ChatPrefs {

public ChatPrefs() {
timeFormat = new SimpleObjectProperty<>(TimeInfo.AUTO);
dateFormat = new SimpleObjectProperty<>(DateInfo.AUTO);
maxMessages = new SimpleIntegerProperty(500);
zoom = new SimpleDoubleProperty(1);
learnedAutoComplete = new SimpleBooleanProperty(false);
Expand Down Expand Up @@ -92,6 +94,14 @@ public void setTimeFormat(TimeInfo time) {
this.timeFormat.set(time);
}

public DateInfo getDateFormat() {
return dateFormat.get();
}

public void setDateFormat(DateInfo date) {
this.dateFormat.set(date);
}

public ChatFormat getChatFormat() {
return this.chatFormat.get();
}
Expand Down
Loading

0 comments on commit e1eef6c

Please sign in to comment.