Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#1400-information-on-games
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanPavilionG7 committed Nov 7, 2020
2 parents 09529a6 + cfd1707 commit 38e2184
Show file tree
Hide file tree
Showing 34 changed files with 519 additions and 104 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 @@ -39,6 +39,7 @@ public class ChatChannelUser {
private final ObjectProperty<Image> statusImage;
private final StringProperty statusTooltipText;
private final BooleanProperty displayed;
private final BooleanProperty populated;

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

public Optional<Player> getPlayer() {
Expand Down Expand Up @@ -243,6 +245,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
28 changes: 16 additions & 12 deletions src/main/java/com/faforever/client/chat/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
import com.faforever.client.main.event.JoinChannelEvent;
import com.faforever.client.main.event.NavigateEvent;
import com.faforever.client.net.ConnectionState;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.theme.UiService;
import com.faforever.client.user.UserService;
import com.faforever.client.user.event.LoggedOutEvent;
import com.faforever.client.util.ProgrammingError;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.collections.ListChangeListener;
import javafx.scene.Node;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand All @@ -29,6 +30,7 @@
import java.util.Map;
import java.util.Optional;

@Slf4j
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ChatController extends AbstractViewController<Node> {
Expand All @@ -37,17 +39,19 @@ public class ChatController extends AbstractViewController<Node> {
private final ChatService chatService;
private final UiService uiService;
private final UserService userService;
private final NotificationService notificationService;
private final EventBus eventBus;
public Node chatRoot;
public TabPane tabPane;
public Pane connectingProgressPane;
public VBox noOpenTabsContainer;
public TextField channelNameTextField;

public ChatController(ChatService chatService, UiService uiService, UserService userService, EventBus eventBus) {
public ChatController(ChatService chatService, UiService uiService, UserService userService, NotificationService notificationService, EventBus eventBus) {
this.chatService = chatService;
this.uiService = uiService;
this.userService = userService;
this.notificationService = notificationService;
this.eventBus = eventBus;

nameToChatTabController = new HashMap<>();
Expand All @@ -73,23 +77,20 @@ private void onDisconnected() {
Platform.runLater(() -> {
connectingProgressPane.setVisible(true);
tabPane.setVisible(false);
noOpenTabsContainer.setVisible(false);
});
}

private void onConnected() {
Platform.runLater(() -> {
connectingProgressPane.setVisible(false);
tabPane.setVisible(true);
noOpenTabsContainer.setVisible(false);
});
}

private void onConnecting() {
Platform.runLater(() -> {
connectingProgressPane.setVisible(true);
tabPane.setVisible(false);
noOpenTabsContainer.setVisible(false);
});
}

Expand Down Expand Up @@ -121,20 +122,18 @@ private void addTab(String playerOrChannelName, AbstractChatTabController tabCon

if (chatService.isDefaultChannel(playerOrChannelName)) {
tabPane.getTabs().add(0, tab);
tabPane.getSelectionModel().select(tab);
nameToChatTabController.get(tab.getId()).onDisplay();
} else {
tabPane.getTabs().add(tab);
tabPane.getTabs().add(tabPane.getTabs().size() - 1, tab);
}
tabPane.getSelectionModel().select(tab);
nameToChatTabController.get(tab.getId()).onDisplay();
}

@Override
public void initialize() {
super.initialize();
eventBus.register(this);

tabPane.getTabs().addListener((InvalidationListener) observable -> noOpenTabsContainer.setVisible(tabPane.getTabs().isEmpty()));

chatService.addChannelsListener(change -> {
if (change.wasRemoved()) {
onChannelLeft(change.getValueRemoved());
Expand Down Expand Up @@ -165,7 +164,7 @@ private void onConnectionStateChange(ConnectionState newValue) {
onDisconnected();
break;
case CONNECTED:
// onConnected();
onConnected();
break;
case CONNECTING:
onConnecting();
Expand Down Expand Up @@ -220,6 +219,11 @@ private void openPrivateMessageTabForUser(String username) {
public void onJoinChannelButtonClicked() {
String channelName = channelNameTextField.getText();
channelNameTextField.clear();
if (!channelName.startsWith("#")) {
log.info("Channel name {} does not start with #", channelName);
notificationService.addImmediateErrorNotification(new IllegalArgumentException(), "chat.error.noHashTag", channelName);
return;
}

joinChannel(channelName);
}
Expand Down Expand Up @@ -263,7 +267,7 @@ protected void onDisplay(NavigateEvent navigateEvent) {
}
if (!tabPane.getTabs().isEmpty()) {
Tab tab = tabPane.getSelectionModel().getSelectedItem();
nameToChatTabController.get(tab.getId()).onDisplay();
Optional.ofNullable(nameToChatTabController.get(tab.getId())).ifPresent(AbstractChatTabController::onDisplay);
}
}

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 @@ -321,8 +320,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 @@ -106,16 +114,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
Loading

0 comments on commit 38e2184

Please sign in to comment.