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()));
}
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);
}
}
}
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);
}
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);
}
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());
}));
}
Aggregations