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