Search in sources :

Example 1 with AvatarBean

use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.

the class FafServiceImplTest method selectAvatar.

@Test
public void selectAvatar() throws Exception {
    URL url = new URL("http://example.com");
    instance.selectAvatar(new AvatarBean(url, "Description"));
    ArgumentCaptor<AvatarChangedEvent> eventCaptor = ArgumentCaptor.forClass(AvatarChangedEvent.class);
    verify(eventBus).post(eventCaptor.capture());
    AvatarBean avatar = eventCaptor.getValue().getAvatar();
    assertThat(avatar, not(nullValue()));
    assertThat(avatar.getUrl(), is(url));
    assertThat(avatar.getDescription(), is("Description"));
    verify(fafServerAccessor).selectAvatar(url);
}
Also used : AvatarBean(com.faforever.client.chat.avatar.AvatarBean) AvatarChangedEvent(com.faforever.client.chat.avatar.event.AvatarChangedEvent) URL(java.net.URL) Test(org.junit.Test)

Example 2 with AvatarBean

use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.

the class ChatUserContextMenuControllerTest method onSelectAvatar.

@Test
public void onSelectAvatar() throws Exception {
    instance.avatarComboBox.show();
    WaitForAsyncUtils.waitForAsyncFx(100000, () -> instance.avatarComboBox.getSelectionModel().select(2));
    ArgumentCaptor<AvatarBean> captor = ArgumentCaptor.forClass(AvatarBean.class);
    verify(avatarService).changeAvatar(captor.capture());
    AvatarBean avatarBean = captor.getValue();
    assertThat(avatarBean.getUrl(), equalTo(new URL("http://www.example.com/avatar2.png")));
    assertThat(avatarBean.getDescription(), is("Avatar Number #2"));
}
Also used : AvatarBean(com.faforever.client.chat.avatar.AvatarBean) URL(java.net.URL) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 3 with AvatarBean

use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.

the class PlayerServiceImpl method onAvatarChanged.

@Subscribe
public void onAvatarChanged(AvatarChangedEvent event) {
    Player player = getCurrentPlayer().orElseThrow(() -> new IllegalStateException("Player has not been set"));
    AvatarBean avatar = event.getAvatar();
    if (avatar == null) {
        player.setAvatarTooltip(null);
        player.setAvatarUrl(null);
    } else {
        player.setAvatarTooltip(avatar.getDescription());
        player.setAvatarUrl(Objects.toString(avatar.getUrl(), null));
    }
}
Also used : AvatarBean(com.faforever.client.chat.avatar.AvatarBean) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with AvatarBean

use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.

the class ChatUserContextMenuControllerTest method setUp.

@Before
public void setUp() throws Exception {
    instance = new ChatUserContextMenuController(userService, chatService, preferencesService, playerService, gameService, replayService, notificationService, i18n, eventBus, joinGameHelper, avatarService, uiService);
    Preferences preferences = mock(Preferences.class);
    ChatPrefs chatPrefs = mock(ChatPrefs.class);
    ObjectProperty<ChatColorMode> chatColorModeObjectProperty = new SimpleObjectProperty<>();
    when(preferencesService.getPreferences()).thenReturn(preferences);
    when(preferences.getChat()).thenReturn(chatPrefs);
    when(chatPrefs.getUserToColor()).thenReturn(mock(ObservableMap.class));
    when(chatPrefs.chatColorModeProperty()).thenReturn(chatColorModeObjectProperty);
    when(avatarService.getAvailableAvatars()).thenReturn(CompletableFuture.completedFuture(Arrays.asList(new AvatarBean(new URL("http://www.example.com/avatar1.png"), "Avatar Number #1"), new AvatarBean(new URL("http://www.example.com/avatar2.png"), "Avatar Number #2"), new AvatarBean(new URL("http://www.example.com/avatar3.png"), "Avatar Number #3"))));
    loadFxml("theme/chat/chat_user_context_menu.fxml", clazz -> instance);
    player = PlayerBuilder.create(TEST_USER_NAME).socialStatus(SELF).avatar(null).game(new Game()).get();
    instance.setPlayer(player);
}
Also used : SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Game(com.faforever.client.game.Game) ChatPrefs(com.faforever.client.preferences.ChatPrefs) AvatarBean(com.faforever.client.chat.avatar.AvatarBean) ObservableMap(javafx.collections.ObservableMap) Preferences(com.faforever.client.preferences.Preferences) URL(java.net.URL) Before(org.junit.Before)

Example 5 with AvatarBean

use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.

the class ChatUserContextMenuController method loadAvailableAvatars.

private void loadAvailableAvatars() {
    avatarService.getAvailableAvatars().thenAccept(avatars -> {
        ObservableList<AvatarBean> items = FXCollections.observableArrayList(avatars);
        items.add(0, new AvatarBean(null, i18n.get("chat.userContext.noAvatar")));
        String currentAvatarUrl = player.getAvatarUrl();
        Platform.runLater(() -> {
            avatarComboBox.setItems(items);
            avatarComboBox.getSelectionModel().select(items.stream().filter(avatarBean -> Objects.equals(Objects.toString(avatarBean.getUrl(), null), currentAvatarUrl)).findFirst().orElse(null));
            // Only after the box has been populated and we selected the current value, we add the listener.
            // Otherwise the code above already triggers a changeAvatar()
            avatarComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
                player.setAvatarTooltip(newValue == null ? null : newValue.getDescription());
                player.setAvatarUrl(newValue == null ? null : Objects.toString(newValue.getUrl(), null));
                avatarService.changeAvatar(newValue);
            });
        });
    });
}
Also used : StageStyle(javafx.stage.StageStyle) GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) JoinGameHelper(com.faforever.client.game.JoinGameHelper) PlayerStatus(com.faforever.client.game.PlayerStatus) AvatarBean(com.faforever.client.chat.avatar.AvatarBean) CustomMenuItem(javafx.scene.control.CustomMenuItem) WindowController(com.faforever.client.fx.WindowController) CUSTOM(com.faforever.client.chat.ChatColorMode.CUSTOM) ComboBox(javafx.scene.control.ComboBox) ContextMenu(javafx.scene.control.ContextMenu) ChatPrefs(com.faforever.client.preferences.ChatPrefs) SELF(com.faforever.client.chat.SocialStatus.SELF) PlayerService(com.faforever.client.player.PlayerService) MenuItem(javafx.scene.control.MenuItem) MethodHandles(java.lang.invoke.MethodHandles) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Objects(java.util.Objects) Player(com.faforever.client.player.Player) FRIEND(com.faforever.client.chat.SocialStatus.FRIEND) ObservableList(javafx.collections.ObservableList) NotNull(org.jetbrains.annotations.NotNull) PreferencesService(com.faforever.client.preferences.PreferencesService) FXCollections(javafx.collections.FXCollections) US(java.util.Locale.US) UserService(com.faforever.client.user.UserService) Bindings(javafx.beans.binding.Bindings) Scope(org.springframework.context.annotation.Scope) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) StringListCell(com.faforever.client.fx.StringListCell) ColorPicker(javafx.scene.control.ColorPicker) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Controller(com.faforever.client.fx.Controller) CLOSE(com.faforever.client.fx.WindowController.WindowButtonType.CLOSE) ReplayService(com.faforever.client.replay.ReplayService) FOE(com.faforever.client.chat.SocialStatus.FOE) AvatarService(com.faforever.client.chat.avatar.AvatarService) Component(org.springframework.stereotype.Component) Stage(javafx.stage.Stage) Severity(com.faforever.client.notification.Severity) ImageView(javafx.scene.image.ImageView) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) I18n(com.faforever.client.i18n.I18n) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) AvatarBean(com.faforever.client.chat.avatar.AvatarBean)

Aggregations

AvatarBean (com.faforever.client.chat.avatar.AvatarBean)5 URL (java.net.URL)4 ChatPrefs (com.faforever.client.preferences.ChatPrefs)2 Test (org.junit.Test)2 CUSTOM (com.faforever.client.chat.ChatColorMode.CUSTOM)1 FOE (com.faforever.client.chat.SocialStatus.FOE)1 FRIEND (com.faforever.client.chat.SocialStatus.FRIEND)1 SELF (com.faforever.client.chat.SocialStatus.SELF)1 AvatarService (com.faforever.client.chat.avatar.AvatarService)1 AvatarChangedEvent (com.faforever.client.chat.avatar.event.AvatarChangedEvent)1 Controller (com.faforever.client.fx.Controller)1 StringListCell (com.faforever.client.fx.StringListCell)1 WindowController (com.faforever.client.fx.WindowController)1 CLOSE (com.faforever.client.fx.WindowController.WindowButtonType.CLOSE)1 Game (com.faforever.client.game.Game)1 GameService (com.faforever.client.game.GameService)1 JoinGameHelper (com.faforever.client.game.JoinGameHelper)1 PlayerStatus (com.faforever.client.game.PlayerStatus)1 I18n (com.faforever.client.i18n.I18n)1 ImmediateNotification (com.faforever.client.notification.ImmediateNotification)1