Search in sources :

Example 1 with GameFullEvent

use of com.faforever.client.fa.relay.event.GameFullEvent in project downlords-faf-client by FAForever.

the class OnGameFullNotifierTest method testAlreadyFocusedDoesntTriggerNotification.

@Test
public void testAlreadyFocusedDoesntTriggerNotification() throws Exception {
    Game game = GameBuilder.create().defaultValues().get();
    when(gameService.getCurrentGame()).thenReturn(game);
    when(platformService.isWindowFocused("Forged Alliance")).thenReturn(true);
    instance.onGameFull(new GameFullEvent());
    verifyZeroInteractions(notificationService);
}
Also used : Game(com.faforever.client.game.Game) GameFullEvent(com.faforever.client.fa.relay.event.GameFullEvent) Test(org.junit.Test)

Example 2 with GameFullEvent

use of com.faforever.client.fa.relay.event.GameFullEvent in project downlords-faf-client by FAForever.

the class OnGameFullNotifierTest method testOnGameFull.

@Test
public void testOnGameFull() throws Exception {
    Game game = GameBuilder.create().defaultValues().get();
    when(gameService.getCurrentGame()).thenReturn(game);
    when(platformService.isWindowFocused("Forged Alliance")).thenReturn(false);
    CountDownLatch countDownLatch = new CountDownLatch(1);
    doAnswer(invocation -> {
        countDownLatch.countDown();
        return null;
    }).when(platformService).stopFlashingWindow("Forged Alliance");
    instance.onGameFull(new GameFullEvent());
    verify(notificationService).addNotification(any(TransientNotification.class));
    verify(executor).execute(any(Runnable.class));
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) Game(com.faforever.client.game.Game) GameFullEvent(com.faforever.client.fa.relay.event.GameFullEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with GameFullEvent

use of com.faforever.client.fa.relay.event.GameFullEvent in project downlords-faf-client by FAForever.

the class IceAdapterImpl method onGpgGameMessage.

@Subscribe
public void onGpgGameMessage(GpgGameMessageEvent event) {
    GpgGameMessage gpgGameMessage = event.getGpgGameMessage();
    GpgClientCommand command = gpgGameMessage.getCommand();
    if (command == GpgClientCommand.REHOST) {
        eventBus.post(new RehostRequestEvent());
        return;
    }
    if (command == GpgClientCommand.GAME_FULL) {
        eventBus.post(new GameFullEvent());
        return;
    }
    fafService.sendGpgGameMessage(gpgGameMessage);
}
Also used : GpgClientCommand(com.faforever.client.fa.relay.GpgClientCommand) RehostRequestEvent(com.faforever.client.fa.relay.event.RehostRequestEvent) GameFullEvent(com.faforever.client.fa.relay.event.GameFullEvent) GpgGameMessage(com.faforever.client.fa.relay.GpgGameMessage) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with GameFullEvent

use of com.faforever.client.fa.relay.event.GameFullEvent in project downlords-faf-client by FAForever.

the class OnGameFullNotifier method onGameFull.

@Subscribe
public void onGameFull(GameFullEvent event) {
    executor.execute(() -> {
        platformService.startFlashingWindow(faWindowTitle);
        while (gameService.isGameRunning() && !platformService.isWindowFocused(faWindowTitle)) {
            noCatch(() -> sleep(500));
        }
        platformService.stopFlashingWindow(faWindowTitle);
    });
    Game currentGame = gameService.getCurrentGame();
    if (currentGame == null) {
        throw new ProgrammingError("Got a GameFull notification but player is not in a game");
    }
    if (platformService.isWindowFocused(faWindowTitle)) {
        return;
    }
    notificationService.addNotification(new TransientNotification(i18n.get("game.full"), i18n.get("game.full.action"), mapService.loadPreview(currentGame.getMapFolderName(), PreviewSize.SMALL), v -> platformService.focusWindow(faWindowTitle)));
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) ClientProperties(com.faforever.client.config.ClientProperties) GameService(com.faforever.client.game.GameService) GameFullEvent(com.faforever.client.fa.relay.event.GameFullEvent) ProgrammingError(com.faforever.client.util.ProgrammingError) Executor(java.util.concurrent.Executor) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) PlatformService(com.faforever.client.fx.PlatformService) TransientNotification(com.faforever.client.notification.TransientNotification) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) Component(org.springframework.stereotype.Component) PostConstruct(javax.annotation.PostConstruct) Thread.sleep(java.lang.Thread.sleep) Subscribe(com.google.common.eventbus.Subscribe) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) Game(com.faforever.client.game.Game) Game(com.faforever.client.game.Game) ProgrammingError(com.faforever.client.util.ProgrammingError) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

GameFullEvent (com.faforever.client.fa.relay.event.GameFullEvent)4 Game (com.faforever.client.game.Game)3 TransientNotification (com.faforever.client.notification.TransientNotification)2 Subscribe (com.google.common.eventbus.Subscribe)2 Test (org.junit.Test)2 ClientProperties (com.faforever.client.config.ClientProperties)1 GpgClientCommand (com.faforever.client.fa.relay.GpgClientCommand)1 GpgGameMessage (com.faforever.client.fa.relay.GpgGameMessage)1 RehostRequestEvent (com.faforever.client.fa.relay.event.RehostRequestEvent)1 PlatformService (com.faforever.client.fx.PlatformService)1 GameService (com.faforever.client.game.GameService)1 I18n (com.faforever.client.i18n.I18n)1 MapService (com.faforever.client.map.MapService)1 PreviewSize (com.faforever.client.map.MapServiceImpl.PreviewSize)1 NotificationService (com.faforever.client.notification.NotificationService)1 ProgrammingError (com.faforever.client.util.ProgrammingError)1 NoCatch.noCatch (com.github.nocatch.NoCatch.noCatch)1 EventBus (com.google.common.eventbus.EventBus)1 Thread.sleep (java.lang.Thread.sleep)1 CountDownLatch (java.util.concurrent.CountDownLatch)1