Skip to content

Commit

Permalink
Remove player choice from live replay button
Browse files Browse the repository at this point in the history
Current live replay server merges all incoming streams into one,
therefore there's no need to select a specific player when launching a
live replay. Remove the selection from the UI, but still pick and send
some player's name in case the replay server finds it useful.

Fixes FAForever#1375.

Signed-off-by: Igor Kotrasinski <i.kotrasinsk@gmail.com>
  • Loading branch information
Igor Kotrasinski committed Dec 17, 2019
1 parent b493e1f commit deaba26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
Expand Up @@ -11,20 +11,16 @@
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.Node;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Button;
import javafx.util.Duration;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
Expand All @@ -34,7 +30,7 @@ public class WatchButtonController implements Controller<Node> {
private final ClientProperties clientProperties;
private final TimeService timeService;

public MenuButton watchButton;
public Button watchButton;
private Game game;
private I18n i18n;
private Timeline delayTimeline;
Expand All @@ -55,30 +51,25 @@ public void initialize() {
delayTimeline.setCycleCount(Timeline.INDEFINITE);

watchButton.setDisable(true);
watchButton.setOnAction(event -> {
getAnyPlayer(game)
.ifPresent(player -> replayService.runLiveReplay(game.getId(), player.getId()));
});
}

public void setGame(Game game) {
this.game = game;
Assert.notNull(game.getStartTime(), "The game's start must not be null: " + game);

List<MenuItem> menuItems = game.getTeams().values().stream()
private Optional<Player> getAnyPlayer(Game game) {
return game.getTeams().values().stream()
.flatMap(Collection::stream)
.map(playerService::getPlayerForUsername)
.filter(Optional::isPresent)
.map(Optional::get)
.map(player -> createMenuItem(game, player))
.collect(Collectors.toList());

watchButton.getItems().setAll(menuItems);
delayTimeline.play();
.findFirst();
}

@NotNull
private MenuItem createMenuItem(Game game, Player player) {
MenuItem menuItem = new MenuItem(player.getUsername());
menuItem.setUserData(player.getId());
menuItem.setOnAction(event -> replayService.runLiveReplay(game.getId(), player.getId()));
return menuItem;
public void setGame(Game game) {
this.game = game;
Assert.notNull(game.getStartTime(), "The game's start must not be null: " + game);
delayTimeline.play();
}

private void updateWatchButtonTimer() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/theme/vault/replay/watch_button.fxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>


<?import javafx.scene.control.MenuButton?>
<MenuButton xmlns:fx="http://javafx.com/fxml/1" fx:id="watchButton" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" text="%game.watchButtonFormat" xmlns="http://javafx.com/javafx/8.0.141" fx:controller="com.faforever.client.vault.replay.WatchButtonController" />
<?import javafx.scene.control.Button?>
<Button xmlns:fx="http://javafx.com/fxml/1" fx:id="watchButton" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" text="%game.watchButtonFormat" xmlns="http://javafx.com/javafx/8.0.141" fx:controller="com.faforever.client.vault.replay.WatchButtonController" />

0 comments on commit deaba26

Please sign in to comment.