Search in sources :

Example 1 with GameDirectoryChooseEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent in project downlords-faf-client by FAForever.

the class MissingGamePathNotifier method onMissingGamePathEvent.

@Subscribe
public void onMissingGamePathEvent(MissingGamePathEvent event) {
    List<Action> actions = Collections.singletonList(new Action(i18n.get("missingGamePath.locate"), chooseEvent -> eventBus.post(new GameDirectoryChooseEvent())));
    String notificationText = i18n.get("missingGamePath.notification");
    if (event.isImmediateUserActionRequired()) {
        notificationService.addNotification(new ImmediateNotification(notificationText, notificationText, Severity.WARN, actions));
    } else {
        notificationService.addNotification(new PersistentNotification(notificationText, Severity.WARN, actions));
    }
}
Also used : Action(com.faforever.client.notification.Action) PersistentNotification(com.faforever.client.notification.PersistentNotification) MissingGamePathEvent(com.faforever.client.preferences.event.MissingGamePathEvent) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) Component(org.springframework.stereotype.Component) List(java.util.List) Severity(com.faforever.client.notification.Severity) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) PostConstruct(javax.annotation.PostConstruct) GameDirectoryChooseEvent(com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent) Subscribe(com.google.common.eventbus.Subscribe) I18n(com.faforever.client.i18n.I18n) Collections(java.util.Collections) Action(com.faforever.client.notification.Action) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) GameDirectoryChooseEvent(com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent) PersistentNotification(com.faforever.client.notification.PersistentNotification) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with GameDirectoryChooseEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent in project downlords-faf-client by FAForever.

the class JoinGameHelperTest method testJoinGameMissingGamePathUserSelectsInvalidPath.

/**
 * Ensure that the user is allowed to choose the GameDirectory if no path is provided
 */
@Test
public void testJoinGameMissingGamePathUserSelectsInvalidPath() throws Exception {
    when(preferencesService.isGamePathValid()).thenReturn(false);
    // First, user selects invalid path. Seconds, he aborts so we don't stay in an endless loop
    AtomicInteger invocationCounter = new AtomicInteger();
    doAnswer(invocation -> {
        Optional<CompletableFuture<Path>> optional = ((GameDirectoryChooseEvent) invocation.getArgument(0)).getFuture();
        if (invocationCounter.incrementAndGet() == 1) {
            optional.ifPresent(future -> future.complete(Paths.get("")));
        } else {
            optional.ifPresent(future -> future.complete(null));
        }
        return null;
    }).when(eventBus).post(any(GameDirectoryChooseEvent.class));
    instance.join(game);
    verify(eventBus, times(2)).post(Mockito.any(GameDirectoryChooseEvent.class));
    verify(gameService, never()).joinGame(any(), any());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GameDirectoryChooseEvent(com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 3 with GameDirectoryChooseEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent in project downlords-faf-client by FAForever.

the class CustomGamesController method onCreateGame.

private void onCreateGame(@Nullable String mapFolderName) {
    if (preferencesService.getPreferences().getForgedAlliance().getPath() == null) {
        CompletableFuture<Path> gameDirectoryFuture = new CompletableFuture<>();
        eventBus.post(new GameDirectoryChooseEvent(gameDirectoryFuture));
        gameDirectoryFuture.thenAccept(path -> Optional.ofNullable(path).ifPresent(path1 -> onCreateGame(null)));
        return;
    }
    CreateGameController createGameController = uiService.loadFxml("theme/play/create_game.fxml");
    if (mapFolderName != null && !createGameController.selectMap(mapFolderName)) {
        log.warn("Map with folder name: '{}' could not be found in map list", mapFolderName);
    }
    Pane createGameRoot = createGameController.getRoot();
    gamesRoot.getChildren().add(createGameRoot);
    AnchorPane.setTopAnchor(createGameRoot, 0d);
    AnchorPane.setRightAnchor(createGameRoot, 0d);
    AnchorPane.setBottomAnchor(createGameRoot, 0d);
    AnchorPane.setLeftAnchor(createGameRoot, 0d);
    createGameRoot.requestFocus();
}
Also used : Path(java.nio.file.Path) PreferencesService(com.faforever.client.preferences.PreferencesService) WeakChangeListener(javafx.beans.value.WeakChangeListener) Button(javafx.scene.control.Button) Arrays(java.util.Arrays) UiService(com.faforever.client.theme.UiService) CompletableFuture(java.util.concurrent.CompletableFuture) Scope(org.springframework.context.annotation.Scope) NavigateEvent(com.faforever.client.main.event.NavigateEvent) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) ScrollPane(javafx.scene.control.ScrollPane) TilesSortingOrder(com.faforever.client.game.GamesTilesContainerController.TilesSortingOrder) GameStatus(com.faforever.client.remote.domain.GameStatus) Path(java.nio.file.Path) Pane(javafx.scene.layout.Pane) HostGameEvent(com.faforever.client.main.event.HostGameEvent) Predicate(java.util.function.Predicate) Node(javafx.scene.Node) Collection(java.util.Collection) FilteredList(javafx.collections.transformation.FilteredList) CheckBox(javafx.scene.control.CheckBox) AbstractViewController(com.faforever.client.fx.AbstractViewController) StringConverter(javafx.util.StringConverter) ChoiceBox(javafx.scene.control.ChoiceBox) Platform(javafx.application.Platform) Nullable(org.jetbrains.annotations.Nullable) ToggleGroup(javafx.scene.control.ToggleGroup) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) ToggleButton(javafx.scene.control.ToggleButton) AnchorPane(javafx.scene.layout.AnchorPane) Optional(java.util.Optional) GameDirectoryChooseEvent(com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ObservableList(javafx.collections.ObservableList) I18n(com.faforever.client.i18n.I18n) ChangeListener(javafx.beans.value.ChangeListener) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) CompletableFuture(java.util.concurrent.CompletableFuture) GameDirectoryChooseEvent(com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent) ScrollPane(javafx.scene.control.ScrollPane) Pane(javafx.scene.layout.Pane) AnchorPane(javafx.scene.layout.AnchorPane)

Example 4 with GameDirectoryChooseEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent in project downlords-faf-client by FAForever.

the class JoinGameHelper method join.

public void join(Game game, String password, boolean ignoreRating) {
    Player currentPlayer = playerService.getCurrentPlayer().orElseThrow(() -> new IllegalStateException("Player has not been set"));
    int playerRating = RatingUtil.getRoundedGlobalRating(currentPlayer);
    if (!preferencesService.isGamePathValid()) {
        CompletableFuture<Path> gameDirectoryFuture = new CompletableFuture<>();
        eventBus.post(new GameDirectoryChooseEvent(gameDirectoryFuture));
        gameDirectoryFuture.thenAccept(path -> Optional.ofNullable(path).ifPresent(path1 -> join(game, password, ignoreRating)));
        return;
    }
    if (!ignoreRating && (playerRating < game.getMinRating() || playerRating > game.getMaxRating())) {
        showRatingOutOfBoundsConfirmation(playerRating, game, password);
        return;
    }
    if (game.getPasswordProtected() && password == null) {
        EnterPasswordController enterPasswordController = uiService.loadFxml("theme/enter_password.fxml");
        enterPasswordController.setOnPasswordEnteredListener(this::join);
        enterPasswordController.setGame(game);
        enterPasswordController.setIgnoreRating(ignoreRating);
        enterPasswordController.showPasswordDialog(StageHolder.getStage());
    } else {
        gameService.joinGame(game, password).exceptionally(throwable -> {
            logger.warn("Game could not be joined", throwable);
            notificationService.addNotification(new ImmediateNotification(i18n.get("errorTitle"), i18n.get("games.couldNotJoin"), ERROR, throwable, asList(new DismissAction(i18n), new ReportAction(i18n, reportingService, throwable))));
            return null;
        });
    }
}
Also used : Path(java.nio.file.Path) PreferencesService(com.faforever.client.preferences.PreferencesService) UiService(com.faforever.client.theme.UiService) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ReportingService(com.faforever.client.reporting.ReportingService) Scope(org.springframework.context.annotation.Scope) EventBus(com.google.common.eventbus.EventBus) NotificationService(com.faforever.client.notification.NotificationService) Arrays.asList(java.util.Arrays.asList) ERROR(com.faforever.client.notification.Severity.ERROR) PlayerService(com.faforever.client.player.PlayerService) Path(java.nio.file.Path) ReportAction(com.faforever.client.notification.ReportAction) RatingUtil(com.faforever.client.util.RatingUtil) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Action(com.faforever.client.notification.Action) DismissAction(com.faforever.client.notification.DismissAction) Player(com.faforever.client.player.Player) StageHolder(com.faforever.client.ui.StageHolder) Component(org.springframework.stereotype.Component) Severity(com.faforever.client.notification.Severity) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) Optional(java.util.Optional) GameDirectoryChooseEvent(com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent) I18n(com.faforever.client.i18n.I18n) Player(com.faforever.client.player.Player) CompletableFuture(java.util.concurrent.CompletableFuture) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) DismissAction(com.faforever.client.notification.DismissAction) ReportAction(com.faforever.client.notification.ReportAction) GameDirectoryChooseEvent(com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent)

Aggregations

GameDirectoryChooseEvent (com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent)4 I18n (com.faforever.client.i18n.I18n)3 EventBus (com.google.common.eventbus.EventBus)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Component (org.springframework.stereotype.Component)3 Action (com.faforever.client.notification.Action)2 ImmediateNotification (com.faforever.client.notification.ImmediateNotification)2 NotificationService (com.faforever.client.notification.NotificationService)2 Severity (com.faforever.client.notification.Severity)2 PreferencesService (com.faforever.client.preferences.PreferencesService)2 UiService (com.faforever.client.theme.UiService)2 Path (java.nio.file.Path)2 Optional (java.util.Optional)2 Scope (org.springframework.context.annotation.Scope)2 AbstractViewController (com.faforever.client.fx.AbstractViewController)1 TilesSortingOrder (com.faforever.client.game.GamesTilesContainerController.TilesSortingOrder)1 HostGameEvent (com.faforever.client.main.event.HostGameEvent)1 NavigateEvent (com.faforever.client.main.event.NavigateEvent)1 DismissAction (com.faforever.client.notification.DismissAction)1 PersistentNotification (com.faforever.client.notification.PersistentNotification)1