Search in sources :

Example 6 with Game

use of com.faforever.client.game.Game in project downlords-faf-client by FAForever.

the class CoopController method initialize.

public void initialize() {
    missionComboBox.setCellFactory(param -> missionListCell());
    missionComboBox.setButtonCell(missionListCell());
    missionComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> setSelectedMission(newValue));
    playButton.disableProperty().bind(titleTextField.textProperty().isEmpty());
    numberOfPlayersComboBox.setButtonCell(numberOfPlayersCell());
    numberOfPlayersComboBox.setCellFactory(param -> numberOfPlayersCell());
    numberOfPlayersComboBox.getSelectionModel().select(2);
    numberOfPlayersComboBox.getSelectionModel().selectedItemProperty().addListener(observable -> loadLeaderboard());
    // TODO don't use API object but bean instead
    rankColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getRanking()));
    rankColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    playerCountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getPlayerCount()));
    playerCountColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    playerNamesColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPlayerNames()));
    playerNamesColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    secondaryObjectivesColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue().isSecondaryObjectives()));
    secondaryObjectivesColumn.setCellFactory(param -> new StringCell<>(aBoolean -> aBoolean ? i18n.get("yes") : i18n.get("no")));
    timeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDuration()));
    timeColumn.setCellFactory(param -> new StringCell<>(timeService::shortDuration));
    replayColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getId()));
    replayColumn.setCellFactory(param -> new NodeTableCell<>((replayId) -> {
        ReplayButtonController button = uiService.loadFxml("theme/play/coop/replay_button.fxml");
        button.setReplayId(replayId);
        button.setOnClickedAction(this::onReplayButtonClicked);
        return button.getRoot();
    }));
    webViewConfigurer.configureWebView(descriptionWebView);
    ObservableList<Game> games = gameService.getGames();
    FilteredList<Game> filteredItems = new FilteredList<>(games);
    filteredItems.setPredicate(OPEN_COOP_GAMES_PREDICATE);
    GamesTableController gamesTableController = uiService.loadFxml("theme/play/games_table.fxml");
    gamesTableController.initializeGameTable(filteredItems);
    Node root = gamesTableController.getRoot();
    populateContainer(root);
    coopService.getMissions().thenAccept(coopMaps -> {
        Platform.runLater(() -> missionComboBox.setItems(observableList(coopMaps)));
        SingleSelectionModel<CoopMission> selectionModel = missionComboBox.getSelectionModel();
        if (selectionModel.isEmpty()) {
            Platform.runLater(selectionModel::selectFirst);
        }
    }).exceptionally(throwable -> {
        notificationService.addPersistentErrorNotification(throwable, "coop.couldNotLoad", throwable.getLocalizedMessage());
        return null;
    });
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) NewGameInfo(com.faforever.client.game.NewGameInfo) Arrays(java.util.Arrays) GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) COOP(com.faforever.client.game.KnownFeaturedMod.COOP) ListCell(javafx.scene.control.ListCell) ReportingService(com.faforever.client.reporting.ReportingService) FXCollections.observableList(javafx.collections.FXCollections.observableList) TimeService(com.faforever.client.util.TimeService) ComboBox(javafx.scene.control.ComboBox) Duration(java.time.Duration) GameStatus(com.faforever.client.remote.domain.GameStatus) TableView(javafx.scene.control.TableView) Pane(javafx.scene.layout.Pane) TextField(javafx.scene.control.TextField) Predicate(java.util.function.Predicate) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) FilteredList(javafx.collections.transformation.FilteredList) AbstractViewController(com.faforever.client.fx.AbstractViewController) CoopResult(com.faforever.client.api.dto.CoopResult) DismissAction(com.faforever.client.notification.DismissAction) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) ModService(com.faforever.client.mod.ModService) ObservableList(javafx.collections.ObservableList) NodeTableCell(com.faforever.client.fx.NodeTableCell) PreferencesService(com.faforever.client.preferences.PreferencesService) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) Strings(com.google.common.base.Strings) StringListCell(com.faforever.client.fx.StringListCell) PasswordField(javafx.scene.control.PasswordField) ReportAction(com.faforever.client.notification.ReportAction) WebView(javafx.scene.web.WebView) StringCell(com.faforever.client.fx.StringCell) Collections.emptySet(java.util.Collections.emptySet) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) ReplayService(com.faforever.client.replay.ReplayService) WebViewConfigurer(com.faforever.client.fx.WebViewConfigurer) GamesTableController(com.faforever.client.game.GamesTableController) Component(org.springframework.stereotype.Component) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Severity(com.faforever.client.notification.Severity) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ImageView(javafx.scene.image.ImageView) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Game(com.faforever.client.game.Game) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) Node(javafx.scene.Node) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) GamesTableController(com.faforever.client.game.GamesTableController) FilteredList(javafx.collections.transformation.FilteredList) Game(com.faforever.client.game.Game)

Example 7 with Game

use of com.faforever.client.game.Game 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)

Example 8 with Game

use of com.faforever.client.game.Game in project downlords-faf-client by FAForever.

the class ReplayServerImpl method finishReplayInfo.

private void finishReplayInfo() {
    Game game = gameService.getByUid(replayInfo.getUid());
    replayInfo.updateFromGameInfoBean(game);
    replayInfo.setGameEnd(pythonTime());
    replayInfo.setRecorder(userService.getUsername());
    replayInfo.setState(GameStatus.CLOSED);
    replayInfo.setComplete(true);
}
Also used : Game(com.faforever.client.game.Game)

Example 9 with Game

use of com.faforever.client.game.Game in project downlords-faf-client by FAForever.

the class LiveReplayController method initializeGameTable.

private void initializeGameTable(ObservableList<Game> games) {
    SortedList<Game> sortedList = new SortedList<>(games);
    sortedList.comparatorProperty().bind(liveReplayControllerRoot.comparatorProperty());
    mapPreviewColumn.setCellFactory(param -> new MapPreviewTableCell(uiService));
    mapPreviewColumn.setCellValueFactory(param -> Bindings.createObjectBinding(() -> mapService.loadPreview(param.getValue().getMapFolderName(), PreviewSize.SMALL), param.getValue().mapFolderNameProperty()));
    gameTitleColumn.setCellValueFactory(param -> param.getValue().titleProperty());
    gameTitleColumn.setCellFactory(param -> new StringCell<>(title -> title));
    playersColumn.setCellValueFactory(param -> param.getValue().numPlayersProperty());
    playersColumn.setCellFactory(param -> new StringCell<>(number -> i18n.number(number.intValue())));
    hostColumn.setCellValueFactory(param -> param.getValue().hostProperty());
    hostColumn.setCellFactory(param -> new StringCell<>(String::toString));
    modsColumn.setCellValueFactory(this::modCell);
    modsColumn.setCellFactory(param -> new StringCell<>(String::toString));
    watchColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue()));
    watchColumn.setCellFactory(param -> new NodeTableCell<>(this::watchReplayButton));
    liveReplayControllerRoot.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> selectedGame.set(newValue)));
    liveReplayControllerRoot.setItems(games);
}
Also used : GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) MapPreviewTableCell(com.faforever.client.game.MapPreviewTableCell) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Bindings(javafx.beans.binding.Bindings) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) GameStatus(com.faforever.client.remote.domain.GameStatus) TableView(javafx.scene.control.TableView) SortedList(javafx.collections.transformation.SortedList) StringCell(com.faforever.client.fx.StringCell) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) AbstractViewController(com.faforever.client.fx.AbstractViewController) ObservableMap(javafx.collections.ObservableMap) Collectors(java.util.stream.Collectors) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) Platform(javafx.application.Platform) Component(org.springframework.stereotype.Component) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Entry(java.util.Map.Entry) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) NotNull(org.jetbrains.annotations.NotNull) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Image(javafx.scene.image.Image) Game(com.faforever.client.game.Game) NodeTableCell(com.faforever.client.fx.NodeTableCell) Joiner(com.google.common.base.Joiner) MapPreviewTableCell(com.faforever.client.game.MapPreviewTableCell) Game(com.faforever.client.game.Game) SortedList(javafx.collections.transformation.SortedList)

Example 10 with Game

use of com.faforever.client.game.Game in project downlords-faf-client by FAForever.

the class FriendJoinedGameNotifier method onFriendJoinedGame.

@Subscribe
public void onFriendJoinedGame(FriendJoinedGameEvent event) {
    Player player = event.getPlayer();
    Game game = event.getGame();
    audioService.playFriendJoinsGameSound();
    if (preferencesService.getPreferences().getNotification().isFriendJoinsGameToastEnabled()) {
        notificationService.addNotification(new TransientNotification(i18n.get("friend.joinedGameNotification.title", player.getUsername(), game.getTitle()), i18n.get("friend.joinedGameNotification.action"), IdenticonUtil.createIdenticon(player.getId()), event1 -> joinGameHelper.join(player.getGame())));
    }
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) PreferencesService(com.faforever.client.preferences.PreferencesService) IdenticonUtil(com.faforever.client.util.IdenticonUtil) JoinGameHelper(com.faforever.client.game.JoinGameHelper) TransientNotification(com.faforever.client.notification.TransientNotification) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) AudioService(com.faforever.client.audio.AudioService) Component(org.springframework.stereotype.Component) PostConstruct(javax.annotation.PostConstruct) FriendJoinedGameEvent(com.faforever.client.player.event.FriendJoinedGameEvent) Subscribe(com.google.common.eventbus.Subscribe) I18n(com.faforever.client.i18n.I18n) Game(com.faforever.client.game.Game) Game(com.faforever.client.game.Game) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Game (com.faforever.client.game.Game)10 I18n (com.faforever.client.i18n.I18n)4 TransientNotification (com.faforever.client.notification.TransientNotification)4 Inject (javax.inject.Inject)4 Component (org.springframework.stereotype.Component)4 GameFullEvent (com.faforever.client.fa.relay.event.GameFullEvent)3 GameService (com.faforever.client.game.GameService)3 MapService (com.faforever.client.map.MapService)3 PreviewSize (com.faforever.client.map.MapServiceImpl.PreviewSize)3 NotificationService (com.faforever.client.notification.NotificationService)3 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)3 Test (org.junit.Test)3 AbstractViewController (com.faforever.client.fx.AbstractViewController)2 NodeTableCell (com.faforever.client.fx.NodeTableCell)2 StringCell (com.faforever.client.fx.StringCell)2 PreferencesService (com.faforever.client.preferences.PreferencesService)2 GameStatus (com.faforever.client.remote.domain.GameStatus)2 UiService (com.faforever.client.theme.UiService)2 EventBus (com.google.common.eventbus.EventBus)2 Subscribe (com.google.common.eventbus.Subscribe)2