Search in sources :

Example 1 with ImmediateNotification

use of com.faforever.client.notification.ImmediateNotification in project downlords-faf-client by FAForever.

the class ServerAccessorImplTest method testOnNotice.

@Test
public void testOnNotice() throws Exception {
    connectAndLogIn();
    NoticeMessage noticeMessage = new NoticeMessage();
    noticeMessage.setText("foo bar");
    noticeMessage.setStyle("warning");
    when(i18n.get("messageFromServer")).thenReturn("Message from Server");
    sendFromServer(noticeMessage);
    ArgumentCaptor<ImmediateNotification> captor = ArgumentCaptor.forClass(ImmediateNotification.class);
    verify(notificationService, timeout(1000)).addNotification(captor.capture());
    ImmediateNotification notification = captor.getValue();
    assertThat(notification.getSeverity(), is(Severity.WARN));
    assertThat(notification.getText(), is("foo bar"));
    assertThat(notification.getTitle(), is("Message from Server"));
    verify(i18n).get("messageFromServer");
}
Also used : ImmediateNotification(com.faforever.client.notification.ImmediateNotification) NoticeMessage(com.faforever.client.remote.domain.NoticeMessage) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 2 with ImmediateNotification

use of com.faforever.client.notification.ImmediateNotification in project downlords-faf-client by FAForever.

the class GameServiceImpl method startGame.

/**
 * Actually starts the game, including relay and replay server. Call this method when everything else is prepared
 * (mod/map download, connectivity check etc.)
 */
private void startGame(GameLaunchMessage gameLaunchMessage, Faction faction, RatingMode ratingMode) {
    if (isRunning()) {
        logger.warn("Forged Alliance is already running, not starting game");
        return;
    }
    stopSearchLadder1v1();
    replayService.startReplayServer(gameLaunchMessage.getUid()).thenCompose(aVoid -> iceAdapter.start()).thenAccept(adapterPort -> {
        List<String> args = fixMalformedArgs(gameLaunchMessage.getArgs());
        process = noCatch(() -> forgedAllianceService.startGame(gameLaunchMessage.getUid(), faction, args, ratingMode, adapterPort, clientProperties.getReplay().getLocalServerPort(), rehostRequested, getCurrentPlayer()));
        setGameRunning(true);
        this.ratingMode = ratingMode;
        spawnTerminationListener(process);
    }).exceptionally(throwable -> {
        logger.warn("Game could not be started", throwable);
        notificationService.addNotification(new ImmediateNotification(i18n.get("errorTitle"), i18n.get("game.start.couldNotStart"), ERROR, throwable, Arrays.asList(new ReportAction(i18n, reportingService, throwable), new DismissAction(i18n))));
        setGameRunning(false);
        return null;
    });
}
Also used : Arrays(java.util.Arrays) RehostRequestEvent(com.faforever.client.fa.relay.event.RehostRequestEvent) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) LoggerFactory(org.slf4j.LoggerFactory) ReadOnlyBooleanProperty(javafx.beans.property.ReadOnlyBooleanProperty) ReportingService(com.faforever.client.reporting.ReportingService) ConnectionState(com.faforever.client.net.ConnectionState) GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) Collections.singletonList(java.util.Collections.singletonList) ListChangeListener(javafx.collections.ListChangeListener) Map(java.util.Map) GameStatus(com.faforever.client.remote.domain.GameStatus) URI(java.net.URI) PlayerService(com.faforever.client.player.PlayerService) Path(java.nio.file.Path) ClientProperties(com.faforever.client.config.ClientProperties) CancellationException(java.util.concurrent.CancellationException) MethodHandles(java.lang.invoke.MethodHandles) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ObservableMap(javafx.collections.ObservableMap) Observable(javafx.beans.Observable) DismissAction(com.faforever.client.notification.DismissAction) FeaturedMod(com.faforever.client.mod.FeaturedMod) Platform(javafx.application.Platform) Player(com.faforever.client.player.Player) Nullable(org.jetbrains.annotations.Nullable) RatingMode(com.faforever.client.fa.RatingMode) BooleanProperty(javafx.beans.property.BooleanProperty) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ForgedAllianceService(com.faforever.client.fa.ForgedAllianceService) PostConstruct(javax.annotation.PostConstruct) ModService(com.faforever.client.mod.ModService) Lazy(org.springframework.context.annotation.Lazy) ObservableList(javafx.collections.ObservableList) NotNull(org.jetbrains.annotations.NotNull) PreferencesService(com.faforever.client.preferences.PreferencesService) WeakChangeListener(javafx.beans.value.WeakChangeListener) GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage) LoginMessage(com.faforever.client.remote.domain.LoginMessage) FXCollections(javafx.collections.FXCollections) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) IceAdapter(com.faforever.client.fa.relay.ice.IceAdapter) PlatformService(com.faforever.client.fx.PlatformService) GameUpdater(com.faforever.client.patch.GameUpdater) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) HashSet(java.util.HashSet) NotificationService(com.faforever.client.notification.NotificationService) Service(org.springframework.stereotype.Service) ERROR(com.faforever.client.notification.Severity.ERROR) Subscribe(com.google.common.eventbus.Subscribe) ReportAction(com.faforever.client.notification.ReportAction) Collections.emptyMap(java.util.Collections.emptyMap) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Executor(java.util.concurrent.Executor) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Action(com.faforever.client.notification.Action) ReplayService(com.faforever.client.replay.ReplayService) IOException(java.io.IOException) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) PersistentNotification(com.faforever.client.notification.PersistentNotification) FafService(com.faforever.client.remote.FafService) Consumer(java.util.function.Consumer) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Severity(com.faforever.client.notification.Severity) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LADDER_1V1(com.faforever.client.game.KnownFeaturedMod.LADDER_1V1) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) NONE(com.faforever.client.fa.RatingMode.NONE) ExternalReplayInfoGenerator(com.faforever.client.replay.ExternalReplayInfoGenerator) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) Collections(java.util.Collections) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) DismissAction(com.faforever.client.notification.DismissAction) ReportAction(com.faforever.client.notification.ReportAction) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList)

Example 3 with ImmediateNotification

use of com.faforever.client.notification.ImmediateNotification in project downlords-faf-client by FAForever.

the class CreateGameController method onCreateButtonClicked.

public void onCreateButtonClicked() {
    ObservableList<ModVersion> selectedModVersions = modListView.getSelectionModel().getSelectedItems();
    try {
        modService.overrideActivatedMods(modListView.getSelectionModel().getSelectedItems());
    } catch (IOException e) {
        logger.warn("Activated mods could not be updated", e);
    }
    Set<String> simMods = selectedModVersions.stream().map(ModVersion::getUid).collect(Collectors.toSet());
    NewGameInfo newGameInfo = new NewGameInfo(titleTextField.getText(), Strings.emptyToNull(passwordTextField.getText()), featuredModListView.getSelectionModel().getSelectedItem(), mapListView.getSelectionModel().getSelectedItem().getFolderName(), simMods);
    gameService.hostGame(newGameInfo).exceptionally(throwable -> {
        logger.warn("Game could not be hosted", throwable);
        notificationService.addNotification(new ImmediateNotification(i18n.get("errorTitle"), i18n.get("game.create.failed"), Severity.WARN, throwable, Collections.singletonList(new ReportAction(i18n, reportingService, throwable))));
        return null;
    });
    onCloseButtonClicked();
}
Also used : ModVersion(com.faforever.client.mod.ModVersion) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) ReportAction(com.faforever.client.notification.ReportAction) IOException(java.io.IOException)

Example 4 with ImmediateNotification

use of com.faforever.client.notification.ImmediateNotification 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 5 with ImmediateNotification

use of com.faforever.client.notification.ImmediateNotification in project downlords-faf-client by FAForever.

the class GamePathHandler method onGameDirectoryChosenEvent.

/**
 * Checks whether the chosen game path contains a ForgedAlliance.exe (either directly if the user selected the "bin"
 * directory, or in the "bin" sub folder). If the path is valid, it is stored in the preferences.
 */
@Subscribe
public void onGameDirectoryChosenEvent(GameDirectoryChosenEvent event) {
    Path path = event.getPath();
    if (path == null || !Files.isDirectory(path)) {
        notificationService.addNotification(new ImmediateNotification(i18n.get("gameChosen.invalidPath"), i18n.get("gameChosen.couldNotLocatedGame"), Severity.WARN));
        return;
    }
    if (!Files.isRegularFile(path.resolve(PreferencesService.FORGED_ALLIANCE_EXE)) && !Files.isRegularFile(path.resolve(PreferencesService.SUPREME_COMMANDER_EXE))) {
        onGameDirectoryChosenEvent(new GameDirectoryChosenEvent(path.resolve("bin")));
        return;
    }
    // At this point, path points to the "bin" directory
    Path gamePath = path.getParent();
    logger.info("Found game path at {}", gamePath);
    preferencesService.getPreferences().getForgedAlliance().setPath(gamePath);
    preferencesService.storeInBackground();
}
Also used : Path(java.nio.file.Path) GameDirectoryChosenEvent(com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

ImmediateNotification (com.faforever.client.notification.ImmediateNotification)22 DismissAction (com.faforever.client.notification.DismissAction)12 ReportAction (com.faforever.client.notification.ReportAction)12 I18n (com.faforever.client.i18n.I18n)7 NotificationService (com.faforever.client.notification.NotificationService)7 Severity (com.faforever.client.notification.Severity)7 EventBus (com.google.common.eventbus.EventBus)6 MethodHandles (java.lang.invoke.MethodHandles)6 Path (java.nio.file.Path)6 Inject (javax.inject.Inject)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 PreferencesService (com.faforever.client.preferences.PreferencesService)5 List (java.util.List)5 Component (org.springframework.stereotype.Component)5 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)4 NavigateEvent (com.faforever.client.main.event.NavigateEvent)4 Action (com.faforever.client.notification.Action)4 Subscribe (com.google.common.eventbus.Subscribe)4 IOException (java.io.IOException)4