Search in sources :

Example 1 with TimeService

use of com.faforever.client.util.TimeService 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)

Aggregations

CoopResult (com.faforever.client.api.dto.CoopResult)1 AbstractViewController (com.faforever.client.fx.AbstractViewController)1 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)1 NodeTableCell (com.faforever.client.fx.NodeTableCell)1 StringCell (com.faforever.client.fx.StringCell)1 StringListCell (com.faforever.client.fx.StringListCell)1 WebViewConfigurer (com.faforever.client.fx.WebViewConfigurer)1 Game (com.faforever.client.game.Game)1 GameService (com.faforever.client.game.GameService)1 GamesTableController (com.faforever.client.game.GamesTableController)1 COOP (com.faforever.client.game.KnownFeaturedMod.COOP)1 NewGameInfo (com.faforever.client.game.NewGameInfo)1 I18n (com.faforever.client.i18n.I18n)1 MapService (com.faforever.client.map.MapService)1 PreviewSize (com.faforever.client.map.MapServiceImpl.PreviewSize)1 ModService (com.faforever.client.mod.ModService)1 DismissAction (com.faforever.client.notification.DismissAction)1 ImmediateNotification (com.faforever.client.notification.ImmediateNotification)1 NotificationService (com.faforever.client.notification.NotificationService)1 ReportAction (com.faforever.client.notification.ReportAction)1