use of com.faforever.client.preferences.ChatPrefs in project downlords-faf-client by FAForever.
the class PircBotXChatService method postConstruct.
@PostConstruct
void postConstruct() {
eventBus.register(this);
fafService.addOnMessageListener(SocialMessage.class, this::onSocialMessage);
connectionState.addListener((observable, oldValue, newValue) -> {
switch(newValue) {
case DISCONNECTED:
case CONNECTING:
onDisconnected();
break;
}
});
addEventListener(NoticeEvent.class, this::onNotice);
addEventListener(ConnectEvent.class, event -> connectionState.set(ConnectionState.CONNECTED));
addEventListener(DisconnectEvent.class, event -> connectionState.set(ConnectionState.DISCONNECTED));
addEventListener(UserListEvent.class, event -> onChatUserList(event.getChannel().getName(), chatUsers(event.getUsers())));
addEventListener(JoinEvent.class, event -> onUserJoinedChannel(event.getChannel().getName(), getOrCreateChatUser(event.getUser())));
addEventListener(PartEvent.class, event -> onChatUserLeftChannel(event.getChannel().getName(), event.getUser().getNick()));
addEventListener(QuitEvent.class, event -> onChatUserQuit(event.getUser().getNick()));
addEventListener(TopicEvent.class, event -> getOrCreateChannel(event.getChannel().getName()).setTopic(event.getTopic()));
addEventListener(MessageEvent.class, this::onMessage);
addEventListener(ActionEvent.class, this::onAction);
addEventListener(PrivateMessageEvent.class, this::onPrivateMessage);
addEventListener(MotdEvent.class, this::onMotd);
addEventListener(OpEvent.class, event -> {
User recipient = event.getRecipient();
if (recipient != null) {
onModeratorSet(event.getChannel().getName(), recipient.getNick());
}
});
ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
chatPrefs.userToColorProperty().addListener((MapChangeListener<? super String, ? super Color>) change -> preferencesService.store());
chatPrefs.chatColorModeProperty().addListener((observable, oldValue, newValue) -> {
synchronized (chatUsersByName) {
switch(newValue) {
case CUSTOM:
chatUsersByName.values().stream().filter(chatUser -> chatPrefs.getUserToColor().containsKey(chatUser.getUsername().toLowerCase(US))).forEach(chatUser -> chatUser.setColor(chatPrefs.getUserToColor().get(chatUser.getUsername().toLowerCase(US))));
break;
case RANDOM:
for (ChatUser chatUser : chatUsersByName.values()) {
chatUser.setColor(ColorGeneratorUtil.generateRandomColor(chatUser.getUsername().hashCode()));
}
break;
default:
for (ChatUser chatUser : chatUsersByName.values()) {
chatUser.setColor(null);
}
}
}
});
}
use of com.faforever.client.preferences.ChatPrefs in project downlords-faf-client by FAForever.
the class PircBotXChatService method getOrCreateChatUser.
@Override
public ChatUser getOrCreateChatUser(String username) {
synchronized (chatUsersByName) {
String lowerUsername = username.toLowerCase(US);
if (!chatUsersByName.containsKey(lowerUsername)) {
ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
Color color = null;
if (chatPrefs.getChatColorMode() == CUSTOM && chatPrefs.getUserToColor().containsKey(lowerUsername)) {
color = chatPrefs.getUserToColor().get(lowerUsername);
} else if (chatPrefs.getChatColorMode() == RANDOM) {
color = ColorGeneratorUtil.generateRandomColor(lowerUsername.hashCode());
}
chatUsersByName.put(lowerUsername, new ChatUser(username, color));
}
return chatUsersByName.get(lowerUsername);
}
}
use of com.faforever.client.preferences.ChatPrefs 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.preferences.ChatPrefs 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.preferences.ChatPrefs in project downlords-faf-client by FAForever.
the class ChatUserItemController method configureColor.
private void configureColor() {
ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
if (player.getSocialStatus() == SELF) {
usernameLabel.getStyleClass().add(SELF.getCssClass());
clanMenu.getStyleClass().add(SELF.getCssClass());
return;
}
Color color = null;
String lowerUsername = player.getUsername().toLowerCase(US);
ChatUser chatUser = chatService.getOrCreateChatUser(lowerUsername);
if (chatPrefs.getChatColorMode() == CUSTOM) {
synchronized (chatPrefs.getUserToColor()) {
if (chatPrefs.getUserToColor().containsKey(lowerUsername)) {
color = chatPrefs.getUserToColor().get(lowerUsername);
}
chatPrefs.getUserToColor().addListener(new WeakMapChangeListener<>(colorPerUserMapChangeListener));
}
} else if (chatPrefs.getChatColorMode() == ChatColorMode.RANDOM && colorsAllowedInPane) {
color = ColorGeneratorUtil.generateRandomColor(chatUser.getUsername().hashCode());
}
chatUser.setColor(color);
assignColor(color);
}
Aggregations