Search in sources :

Example 46 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class MapDetailController method setMap.

public void setMap(MapBean map) {
    this.map = map;
    if (map.getLargeThumbnailUrl() != null) {
        thumbnailImageView.setImage(mapService.loadPreview(map, PreviewSize.LARGE));
    } else {
        thumbnailImageView.setImage(IdenticonUtil.createIdenticon(map.getId()));
    }
    nameLabel.setText(map.getDisplayName());
    authorLabel.setText(Optional.ofNullable(map.getAuthor()).orElse(i18n.get("map.unknownAuthor")));
    maxPlayersLabel.setText(i18n.number(map.getPlayers()));
    MapSize mapSize = map.getSize();
    dimensionsLabel.setText(i18n.get("mapPreview.size", mapSize.getWidthInKm(), mapSize.getHeightInKm()));
    LocalDateTime createTime = map.getCreateTime();
    dateLabel.setText(timeService.asDate(createTime));
    boolean mapInstalled = mapService.isInstalled(map.getFolderName());
    installButton.setVisible(!mapInstalled);
    Player player = playerService.getCurrentPlayer().orElseThrow(() -> new IllegalStateException("No user is logged in"));
    reviewsController.setCanWriteReview(false);
    mapService.hasPlayedMap(player.getId(), map.getId()).thenAccept(hasPlayed -> reviewsController.setCanWriteReview(hasPlayed));
    reviewsController.setOnSendReviewListener(this::onSendReview);
    reviewsController.setOnDeleteReviewListener(this::onDeleteReview);
    reviewsController.setReviews(map.getReviews());
    reviewsController.setOwnReview(map.getReviews().stream().filter(review -> review.getPlayer().getId() == player.getId()).findFirst());
    mapService.getFileSize(map.getDownloadUrl()).thenAccept(mapFileSize -> Platform.runLater(() -> {
        if (mapFileSize > -1) {
            installButton.setText(i18n.get("mapVault.installButtonFormat", Bytes.formatSize(mapFileSize, i18n.getUserSpecificLocale())));
            installButton.setDisable(false);
        } else {
            installButton.setText(i18n.get("notAvailable"));
            installButton.setDisable(true);
        }
    }));
    uninstallButton.setVisible(mapInstalled);
    mapDescriptionLabel.textProperty().bind(Bindings.createStringBinding(() -> Optional.ofNullable(map.getDescription()).map(Strings::emptyToNull).map(FaStrings::removeLocalizationTag).orElseGet(() -> i18n.get("map.noDescriptionAvailable")), map.descriptionProperty()));
    ObservableList<MapBean> installedMaps = mapService.getInstalledMaps();
    synchronized (installedMaps) {
        installedMaps.addListener(new WeakListChangeListener<>(installStatusChangeListener));
    }
    setInstalled(mapService.isInstalled(map.getFolderName()));
}
Also used : LocalDateTime(java.time.LocalDateTime) Player(com.faforever.client.player.Player) Strings(com.google.common.base.Strings) FaStrings(com.faforever.client.fa.FaStrings)

Example 47 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class ChannelTabController method onUserJoinedChannel.

private synchronized void onUserJoinedChannel(ChatUser chatUser) {
    JavaFxUtil.assertBackgroundThread();
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    String username = chatUser.getUsername();
    Player player = playerService.createAndGetPlayerForUsername(username);
    player.moderatorForChannelsProperty().bind(chatUser.moderatorInChannelsProperty());
    player.usernameProperty().addListener((observable, oldValue, newValue) -> {
        Map<Pane, ChatUserItemController> userItemControllers = userToChatUserControls.get(oldValue);
        if (userItemControllers == null) {
            return;
        }
        for (Map.Entry<Pane, ChatUserItemController> entry : userItemControllers.entrySet()) {
            Pane pane = entry.getKey();
            ChatUserItemController chatUserItemController = entry.getValue();
            pane.getChildren().remove(chatUserItemController.getRoot());
            addChatUserItemSorted(pane, chatUserItemController);
        }
    });
    player.usernameProperty().bind(chatUser.usernameProperty());
    player.socialStatusProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue == OTHER && player.isChatOnly()) {
            addToPane(player, chatOnlyPane);
            setUserMessageClass(player, CSS_CLASS_CHAT_ONLY);
        } else {
            addToPane(player, getPaneForSocialStatus(newValue));
            setUserMessageClass(player, newValue.getCssClass());
        }
        if (chatPrefs.getHideFoeMessages() && newValue == FOE) {
            updateUserMessageDisplay(player, "none");
        }
        if (oldValue == OTHER && player.isChatOnly()) {
            removeFromPane(player, chatOnlyPane);
            removeUserMessageClass(player, CSS_CLASS_CHAT_ONLY);
        } else {
            removeFromPane(player, getPaneForSocialStatus(oldValue));
            removeUserMessageClass(player, oldValue.getCssClass());
        }
        if (chatPrefs.getHideFoeMessages() && oldValue == FOE) {
            updateUserMessageDisplay(player, "");
        }
    });
    player.chatOnlyProperty().addListener((observable, oldValue, newValue) -> {
        if (player.getSocialStatus() == OTHER && !chatUser.getModeratorInChannels().contains(username)) {
            if (newValue) {
                removeFromPane(player, othersPane);
                addToPane(player, chatOnlyPane);
                setUserMessageClass(player, CSS_CLASS_CHAT_ONLY);
            } else {
                removeFromPane(player, chatOnlyPane);
                addToPane(player, getPaneForSocialStatus(player.getSocialStatus()));
                removeUserMessageClass(player, CSS_CLASS_CHAT_ONLY);
            }
        }
    });
    player.getModeratorForChannels().addListener((SetChangeListener<String>) change -> {
        if (change.wasAdded()) {
            addToPane(player, moderatorsPane);
            removeFromPane(player, othersPane);
            removeFromPane(player, chatOnlyPane);
            setUserMessageClass(player, CSS_CLASS_MODERATOR);
        } else {
            removeFromPane(player, moderatorsPane);
            SocialStatus socialStatus = player.getSocialStatus();
            if (socialStatus == OTHER || socialStatus == SELF) {
                addToPane(player, othersPane);
            }
            removeUserMessageClass(player, CSS_CLASS_MODERATOR);
        }
    });
    chatPrefs.hideFoeMessagesProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue && player.getSocialStatus() == FOE) {
            updateUserMessageDisplay(player, "none");
        } else {
            updateUserMessageDisplay(player, "");
        }
    });
    chatUser.colorProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> updateUserMessageColor(chatUser)));
    Collection<Pane> targetPanesForUser = getTargetPanesForUser(player);
    for (Pane pane : targetPanesForUser) {
        ChatUserItemController chatUserItemController = createChatUserControlForPlayerIfNecessary(pane, player);
        // Apply filter if exists
        if (!userSearchTextField.textProperty().get().isEmpty()) {
            chatUserItemController.setVisible(isUsernameMatch(chatUserItemController));
        }
        if (filterUserPopup.isShowing()) {
            userFilterController.filterUser(chatUserItemController);
        }
    }
}
Also used : Button(javafx.scene.control.Button) UiService(com.faforever.client.theme.UiService) TextInputControl(javafx.scene.control.TextInputControl) Date(java.util.Date) ImageUploadService(com.faforever.client.uploader.ImageUploadService) ReportingService(com.faforever.client.reporting.ReportingService) VBox(javafx.scene.layout.VBox) AudioService(com.faforever.client.audio.AudioService) TimeService(com.faforever.client.util.TimeService) Gson(com.google.gson.Gson) Duration(java.time.Duration) Map(java.util.Map) OTHER(com.faforever.client.chat.SocialStatus.OTHER) ChatPrefs(com.faforever.client.preferences.ChatPrefs) SELF(com.faforever.client.chat.SocialStatus.SELF) PlayerService(com.faforever.client.player.PlayerService) Pane(javafx.scene.layout.Pane) ClientProperties(com.faforever.client.config.ClientProperties) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) MapChangeListener(javafx.collections.MapChangeListener) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TaskScheduler(org.springframework.scheduling.TaskScheduler) KeyEvent(javafx.scene.input.KeyEvent) Instant(java.time.Instant) Platform(javafx.application.Platform) Player(com.faforever.client.player.Player) ObservableList(javafx.collections.ObservableList) Bounds(javafx.geometry.Bounds) PreferencesService(com.faforever.client.preferences.PreferencesService) WeakChangeListener(javafx.beans.value.WeakChangeListener) DEFAULT(com.faforever.client.chat.ChatColorMode.DEFAULT) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SetChangeListener(javafx.collections.SetChangeListener) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) UserService(com.faforever.client.user.UserService) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) PlatformService(com.faforever.client.fx.PlatformService) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) KeyCode(javafx.scene.input.KeyCode) WebView(javafx.scene.web.WebView) TitledPane(javafx.scene.control.TitledPane) PopupWindow(javafx.stage.PopupWindow) ClanService(com.faforever.client.clan.ClanService) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) ReplayService(com.faforever.client.replay.ReplayService) FOE(com.faforever.client.chat.SocialStatus.FOE) WebViewConfigurer(com.faforever.client.fx.WebViewConfigurer) Popup(javafx.stage.Popup) ActionEvent(javafx.event.ActionEvent) Component(org.springframework.stereotype.Component) Tab(javafx.scene.control.Tab) ExternalReplayInfoGenerator(com.faforever.client.replay.ExternalReplayInfoGenerator) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) ChangeListener(javafx.beans.value.ChangeListener) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Player(com.faforever.client.player.Player) ChatPrefs(com.faforever.client.preferences.ChatPrefs) Pane(javafx.scene.layout.Pane) TitledPane(javafx.scene.control.TitledPane) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 48 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class AbstractChatTabController method getInlineStyle.

@VisibleForTesting
String getInlineStyle(String username) {
    ChatUser chatUser = chatService.getOrCreateChatUser(username);
    Player player = playerService.getPlayerForUsername(username);
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    String color = "";
    String display = "";
    if (chatPrefs.getHideFoeMessages() && player != null && player.getSocialStatus() == FOE) {
        display = "display: none;";
    } else if (player != null && (player.getSocialStatus() == SELF || player.getSocialStatus() == FRIEND)) {
        return "";
    } else {
        ChatColorMode chatColorMode = chatPrefs.getChatColorMode();
        if ((chatColorMode == ChatColorMode.CUSTOM || chatColorMode == ChatColorMode.RANDOM) && chatUser.getColor() != null) {
            color = createInlineStyleFromColor(chatUser.getColor());
        }
    }
    return String.format("%s%s", color, display);
}
Also used : Player(com.faforever.client.player.Player) ChatPrefs(com.faforever.client.preferences.ChatPrefs) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 49 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class AbstractChatTabController method playerInfo.

/**
 * Called from JavaScript when user hovers over a user name.
 */
public void playerInfo(String username) {
    Player player = playerService.getPlayerForUsername(username);
    if (player == null || player.isChatOnly()) {
        return;
    }
    playerInfoPopup = new Popup();
    Label label = new Label();
    label.getStyleClass().add("tooltip");
    playerInfoPopup.getContent().setAll(label);
    label.textProperty().bind(Bindings.createStringBinding(() -> i18n.get("userInfo.ratingFormat", getGlobalRating(player), getLeaderboardRating(player)), player.leaderboardRatingMeanProperty(), player.leaderboardRatingDeviationProperty(), player.globalRatingMeanProperty(), player.globalRatingDeviationProperty()));
    playerInfoPopup.setAnchorLocation(PopupWindow.AnchorLocation.CONTENT_BOTTOM_LEFT);
    playerInfoPopup.show(getRoot().getTabPane(), lastMouseX, lastMouseY - 10);
}
Also used : Player(com.faforever.client.player.Player) Popup(javafx.stage.Popup) Label(javafx.scene.control.Label)

Example 50 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class AbstractChatTabController method showNotificationIfNecessary.

protected void showNotificationIfNecessary(ChatMessage chatMessage) {
    Stage stage = StageHolder.getStage();
    if (stage.isFocused() && stage.isShowing()) {
        return;
    }
    Player player = playerService.getPlayerForUsername(chatMessage.getUsername());
    String identiconSource = player != null ? String.valueOf(player.getId()) : chatMessage.getUsername();
    notificationService.addNotification(new TransientNotification(chatMessage.getUsername(), chatMessage.getMessage(), IdenticonUtil.createIdenticon(identiconSource), event -> {
        eventBus.post(new NavigateEvent(NavigationItem.CHAT));
        stage.toFront();
        getRoot().getTabPane().getSelectionModel().select(getRoot());
    }));
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) EventHandler(javafx.event.EventHandler) Arrays(java.util.Arrays) CHAT_TEXT(com.faforever.client.theme.UiService.CHAT_TEXT) UiService(com.faforever.client.theme.UiService) TextInputControl(javafx.scene.control.TextInputControl) PseudoClass(javafx.css.PseudoClass) URL(java.net.URL) ImageUploadService(com.faforever.client.uploader.ImageUploadService) LoggerFactory(org.slf4j.LoggerFactory) ReportingService(com.faforever.client.reporting.ReportingService) StringUtils(org.apache.commons.lang3.StringUtils) CHAT_CONTAINER(com.faforever.client.theme.UiService.CHAT_CONTAINER) CASE_INSENSITIVE(java.util.regex.Pattern.CASE_INSENSITIVE) NavigateEvent(com.faforever.client.main.event.NavigateEvent) AudioService(com.faforever.client.audio.AudioService) TimeService(com.faforever.client.util.TimeService) TabPane(javafx.scene.control.TabPane) Matcher(java.util.regex.Matcher) CharStreams(com.google.common.io.CharStreams) MINUTES(java.time.temporal.ChronoUnit.MINUTES) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) ITEM_AT_INDEX(javafx.scene.AccessibleAttribute.ITEM_AT_INDEX) ChatPrefs(com.faforever.client.preferences.ChatPrefs) SELF(com.faforever.client.chat.SocialStatus.SELF) PlayerService(com.faforever.client.player.PlayerService) HtmlEscapers.htmlEscaper(com.google.common.html.HtmlEscapers.htmlEscaper) ClientProperties(com.faforever.client.config.ClientProperties) JSObject(netscape.javascript.JSObject) RatingUtil.getLeaderboardRating(com.faforever.client.util.RatingUtil.getLeaderboardRating) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) KeyEvent(javafx.scene.input.KeyEvent) Reader(java.io.Reader) NavigationItem(com.faforever.client.main.event.NavigationItem) DismissAction(com.faforever.client.notification.DismissAction) Platform(javafx.application.Platform) Player(com.faforever.client.player.Player) StageHolder(com.faforever.client.ui.StageHolder) List(java.util.List) Clipboard(javafx.scene.input.Clipboard) FRIEND(com.faforever.client.chat.SocialStatus.FRIEND) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) CHAT_ENTRY(com.faforever.client.theme.UiService.CHAT_ENTRY) PreferencesService(com.faforever.client.preferences.PreferencesService) WeakChangeListener(javafx.beans.value.WeakChangeListener) Worker(javafx.concurrent.Worker) RatingUtil.getGlobalRating(com.faforever.client.util.RatingUtil.getGlobalRating) WebEngine(javafx.scene.web.WebEngine) AnchorLocation(javafx.stage.PopupWindow.AnchorLocation) MouseEvent(javafx.scene.input.MouseEvent) ClassPathResource(org.springframework.core.io.ClassPathResource) UserService(com.faforever.client.user.UserService) Bindings(javafx.beans.binding.Bindings) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) PlatformService(com.faforever.client.fx.PlatformService) TransientNotification(com.faforever.client.notification.TransientNotification) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) TabPaneSkin(com.sun.javafx.scene.control.skin.TabPaneSkin) Tooltip(javafx.scene.control.Tooltip) ReportAction(com.faforever.client.notification.ReportAction) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) WebView(javafx.scene.web.WebView) Label(javafx.scene.control.Label) PopupWindow(javafx.stage.PopupWindow) Logger(org.slf4j.Logger) ClanService(com.faforever.client.clan.ClanService) IdenticonUtil(com.faforever.client.util.IdenticonUtil) Controller(com.faforever.client.fx.Controller) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) ReplayService(com.faforever.client.replay.ReplayService) FOE(com.faforever.client.chat.SocialStatus.FOE) IOException(java.io.IOException) WebViewConfigurer(com.faforever.client.fx.WebViewConfigurer) InputStreamReader(java.io.InputStreamReader) Popup(javafx.stage.Popup) ClanTooltipController(com.faforever.client.clan.ClanTooltipController) Preview(com.faforever.client.chat.UrlPreviewResolver.Preview) Stage(javafx.stage.Stage) Severity(com.faforever.client.notification.Severity) Tab(javafx.scene.control.Tab) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) ExternalReplayInfoGenerator(com.faforever.client.replay.ExternalReplayInfoGenerator) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) ChangeListener(javafx.beans.value.ChangeListener) Image(javafx.scene.image.Image) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) ContentDisplay(javafx.scene.control.ContentDisplay) Player(com.faforever.client.player.Player) NavigateEvent(com.faforever.client.main.event.NavigateEvent) Stage(javafx.stage.Stage)

Aggregations

Player (com.faforever.client.player.Player)51 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)17 Test (org.junit.Test)17 Pane (javafx.scene.layout.Pane)8 I18n (com.faforever.client.i18n.I18n)7 PlayerService (com.faforever.client.player.PlayerService)7 UiService (com.faforever.client.theme.UiService)7 ClientProperties (com.faforever.client.config.ClientProperties)6 Controller (com.faforever.client.fx.Controller)6 ArrayList (java.util.ArrayList)6 Platform (javafx.application.Platform)6 Node (javafx.scene.Node)6 Scope (org.springframework.context.annotation.Scope)6 Component (org.springframework.stereotype.Component)6 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)5 NotificationService (com.faforever.client.notification.NotificationService)5 TimeService (com.faforever.client.util.TimeService)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5