Skip to content

Commit

Permalink
add map pack filename to map preview in create-game controller.
Browse files Browse the repository at this point in the history
detect and remove conflicting map packs when installing a new map pack.
use mod display name in UI's instead of technical name.
pre-populate settings/ta with all mods known by ModService.
  • Loading branch information
Axle1975 committed Apr 10, 2021
1 parent e6aa434 commit 277e646
Show file tree
Hide file tree
Showing 29 changed files with 97 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class CreateGameController implements Controller<Pane> {
public VBox mapPreview;
public Pane mapPreviewPane;
public Label versionLabel;
public Label hpiArchiveLabel;
public ComboBox<PreviewType> mapPreviewTypeComboBox;
public ComboBox<Integer> mapPreviewMaxPositionsComboBox;
public CheckBox onlyForFriendsCheckBox;
Expand All @@ -118,6 +119,7 @@ public class CreateGameController implements Controller<Pane> {

public void initialize() {
versionLabel.managedProperty().bind(versionLabel.visibleProperty());
hpiArchiveLabel.managedProperty().bind(hpiArchiveLabel.visibleProperty());

mapPreviewTypeComboBox.getItems().setAll(PreviewType.values());
mapPreviewMaxPositionsComboBox.getItems().setAll(IntStream.rangeClosed(2,10).boxed().collect(Collectors.toList()));
Expand Down Expand Up @@ -342,6 +344,9 @@ protected void setSelectedMap(MapBean newValue, PreviewType previewType, int max
.map(FaStrings::removeLocalizationTag)
.orElseGet(() -> i18n.get("map.noDescriptionAvailable")));

hpiArchiveLabel.setText(newValue.getHpiArchiveName());
hpiArchiveLabel.setVisible(true);

ComparableVersion mapVersion = newValue.getVersion();
if (mapVersion == null) {
versionLabel.setVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.faforever.client.i18n.I18n;
import com.faforever.client.map.MapService;
import com.faforever.client.map.MapService.PreviewType;
import com.faforever.client.mod.ModService;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.remote.domain.GameStatus;
import com.faforever.client.remote.domain.RatingRange;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class GamesTableController implements Controller<Node> {
private final MapService mapService;
private final JoinGameHelper joinGameHelper;
private final GameService gameService;
private final ModService modService;
private final I18n i18n;
private final UiService uiService;
private final PreferencesService preferencesService;
Expand Down Expand Up @@ -113,8 +115,8 @@ public void initializeGameTable(ObservableList<Game> games, Function<String, Str

passwordProtectionColumn.setCellValueFactory(param -> param.getValue().passwordProtectedProperty());
passwordProtectionColumn.setCellFactory(param -> passwordIndicatorColumn());
mapPreviewColumn.setCellFactory(param -> new MapPreviewTableCell(uiService));
passwordProtectionColumn.setVisible(preferencesService.getPreferences().isShowPasswordProtectedGames());
mapPreviewColumn.setCellFactory(param -> new MapPreviewTableCell(uiService));
mapPreviewColumn.setCellValueFactory(param -> Bindings.createObjectBinding(
() -> mapService
.loadPreview(param.getValue().getFeaturedMod(), param.getValue().getMapName(), PreviewType.MINI, 10),
Expand All @@ -135,6 +137,7 @@ public void initializeGameTable(ObservableList<Game> games, Function<String, Str
hostColumn.setCellFactory(param -> new StringCell<>(String::toString));
modsColumn.setCellValueFactory(this::modCell);
modsColumn.setCellFactory(param -> new StringCell<>(String::toString));

coopMissionName.setVisible(coopMissionNameProvider != null);

if (averageRatingColumn != null) {
Expand Down Expand Up @@ -187,7 +190,8 @@ private void onColumnSorted(@NotNull SortEvent<TableView<Game>> event) {
@NotNull
private ObservableValue<String> modCell(CellDataFeatures<Game, String> param) {
String modTechnical = param.getValue().getFeaturedMod();
return new SimpleStringProperty(modTechnical);
String displayName = modService.getFeaturedModDisplayName(modTechnical);
return new SimpleStringProperty(displayName);
}

private void selectFirstGame() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void onInstallButtonClicked() {
}

public void onUninstallButtonClicked() {
mapService.uninstallMap(preferencesService.getPreferences().getLastGamePrefs().getLastGameType(), map)
mapService.uninstallMap(preferencesService.getPreferences().getLastGamePrefs().getLastGameType(), map.getMapName(), map.getCrc())
.thenRun(() -> setInstalled(false))
.exceptionally(throwable -> {
notificationService.addNotification(new ImmediateErrorNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void onUninstallButtonClicked() {
progressBar.progressProperty().unbind();
progressBar.setProgress(-1);

mapService.uninstallMap(preferencesService.getPreferences().getLastGamePrefs().getLastGameType(), map)
mapService.uninstallMap(preferencesService.getPreferences().getLastGamePrefs().getLastGameType(), map.getMapName(), map.getCrc())
.thenRun(() -> setInstalled(false))
.exceptionally(throwable -> {
notificationService.addNotification(new ImmediateErrorNotification(
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/com/faforever/client/map/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,19 +655,25 @@ private Image loadPreview(String modTechnical, String mapName, URL url, PreviewT
return im;
}

public CompletableFuture<Void> uninstallMap(String modTechnicalName, MapBean map) {
if (isOfficialMap(map.getMapName())) {

public CompletableFuture<Void> uninstallMap(String modTechnicalName, String mapName, String mapCrc) {
if (isOfficialMap(mapName)) {
throw new IllegalArgumentException("Attempt to uninstall an official map");
}
UninstallMapTask task = applicationContext.getBean(com.faforever.client.map.UninstallMapTask.class);

Path mapsDirectory = preferencesService.getTotalAnnihilation(modTechnicalName).getInstalledPath();
if (mapsDirectory == null) {
return new CompletableFuture<>();
if (!isInstalled(modTechnicalName, mapName, mapCrc)) {
CompletableFuture<Void> result = new CompletableFuture<>();
result.complete(null);
return result;
}
task.setInstallationPath(mapsDirectory);
task.setHpiArchiveName(map.getHpiArchiveName());

Path mapsDirectory = preferencesService.getTotalAnnihilation(modTechnicalName).getInstalledPath();
Installation installation = installations.get(modTechnicalName);
MapBean installedMap = installation.mapsByName.get(mapName);

UninstallMapTask task = applicationContext.getBean(com.faforever.client.map.UninstallMapTask.class);
task.setInstallationPath(mapsDirectory);
task.setHpiArchiveName(installedMap.getHpiArchiveName());
return taskService.submitTask(task).getFuture();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.faforever.client.main.event.OpenMapVaultEvent;
import com.faforever.client.main.event.ShowLadderMapsEvent;
import com.faforever.client.map.event.MapUploadedEvent;
import com.faforever.client.mod.ModService;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.query.SearchablePropertyMappings;
Expand Down Expand Up @@ -49,8 +50,8 @@ public class MapVaultController extends VaultEntityController<MapBean> {
private MapDetailController mapDetailController;

public MapVaultController(MapService mapService, I18n i18n, EventBus eventBus, PreferencesService preferencesService,
UiService uiService, NotificationService notificationService, ReportingService reportingService) {
super(uiService, notificationService, i18n, preferencesService, reportingService);
UiService uiService, NotificationService notificationService, ReportingService reportingService, ModService modService) {
super(uiService, notificationService, i18n, preferencesService, reportingService, modService);
this.mapService = mapService;
this.eventBus = eventBus;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/faforever/client/mod/ModService.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -291,6 +292,16 @@ public CompletableFuture<FeaturedMod> getFeaturedMod(String featuredMod) {
));
}

public String getFeaturedModDisplayName(String modTechnical) {
String displayName = modTechnical;
try {
displayName = getFeaturedMod(modTechnical).get().getDisplayName();
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
return displayName;
}

public CompletableFuture<Tuple<List<ModVersion>, Integer>> findByQueryWithPageCount(SearchConfig searchConfig, int count, int page) {
return fafService.findModsByQueryWithPageCount(searchConfig, count, page);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ModVaultController extends VaultEntityController<ModVersion> {

public ModVaultController(ModService modService, I18n i18n, EventBus eventBus, PreferencesService preferencesService,
UiService uiService, NotificationService notificationService, ReportingService reportingService) {
super(uiService, notificationService, i18n, preferencesService, reportingService);
super(uiService, notificationService, i18n, preferencesService, reportingService, modService);
this.eventBus = eventBus;
this.modService = modService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ public TotalAnnihilationPrefs getTotalAnnihilation(String modTechnical) {
}

public TotalAnnihilationPrefs setTotalAnnihilation(String modTechnical, Path installedExePath, String commandLineOptions) {
String baseGameName = KnownFeaturedMod.fromString(modTechnical).getBaseGameName();
if (baseGameName == null) {
baseGameName = modTechnical;
String baseGameName = modTechnical;
KnownFeaturedMod kfm = KnownFeaturedMod.fromString(modTechnical);
if (kfm != null) {
baseGameName = kfm.getBaseGameName();
}

for (TotalAnnihilationPrefs pref: totalAnnihilation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
import com.faforever.client.fx.Controller;
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.fx.PlatformService;
import com.faforever.client.fx.StringCell;
import com.faforever.client.fx.StringListCell;
import com.faforever.client.game.KnownFeaturedMod;
import com.faforever.client.i18n.I18n;
import com.faforever.client.main.event.NavigationItem;
import com.faforever.client.mod.ModService;
import com.faforever.client.notification.Action;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.notification.PersistentNotification;
import com.faforever.client.notification.Severity;
import com.faforever.client.notification.TransientNotification;
import com.faforever.client.player.Player;
import com.faforever.client.preferences.LocalizationPrefs;
import com.faforever.client.preferences.NotificationsPrefs;
import com.faforever.client.preferences.Preferences;
import com.faforever.client.preferences.Preferences.UnitDataBaseType;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.preferences.TimeInfo;
import com.faforever.client.preferences.ToastPosition;
Expand All @@ -43,32 +43,23 @@
import javafx.beans.value.WeakChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Cell;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.TableColumn;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Screen;
import javafx.util.StringConverter;
Expand All @@ -79,10 +70,7 @@
import org.springframework.stereotype.Component;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
Expand All @@ -105,6 +93,7 @@ public class SettingsController implements Controller<Node> {
private final PlatformService platformService;
private final ClientProperties clientProperties;
private final ClientUpdateService clientUpdateService;
private final ModService modService;

public TextField executableDecoratorField;
public TextField executionDirectoryField;
Expand Down Expand Up @@ -175,7 +164,8 @@ public class SettingsController implements Controller<Node> {

public SettingsController(UserService userService, PreferencesService preferencesService, UiService uiService,
I18n i18n, EventBus eventBus, NotificationService notificationService,
PlatformService platformService, ClientProperties clientProperties, ClientUpdateService clientUpdateService) {
PlatformService platformService, ClientProperties clientProperties,
ClientUpdateService clientUpdateService, ModService modService) {
this.userService = userService;
this.preferencesService = preferencesService;
this.uiService = uiService;
Expand All @@ -185,6 +175,7 @@ public SettingsController(UserService userService, PreferencesService preference
this.platformService = platformService;
this.clientProperties = clientProperties;
this.clientUpdateService = clientUpdateService;
this.modService = modService;

availableLanguagesListener = observable -> {
LocalizationPrefs localization = preferencesService.getPreferences().getLocalization();
Expand Down Expand Up @@ -317,9 +308,19 @@ public void initialize() {
notifyOnAtMentionOnlyToggle.selectedProperty().bindBidirectional(preferences.getNotification().notifyOnAtMentionOnlyEnabledProperty());
enableSoundsToggle.selectedProperty().bindBidirectional(preferences.getNotification().soundsEnabledProperty());
gameLocationModTableColumn.setCellValueFactory(new PropertyValueFactory<>("getModName"));
gameLocationModTableColumn.setCellFactory(param -> new StringCell<>(technicalName -> modService.getFeaturedModDisplayName(technicalName)));
gameLocationExecutableTableColumn.setCellValueFactory(new PropertyValueFactory<>("getInstalledExePath"));
gameLocationCommandLineOptionsTableColumn.setCellValueFactory(new PropertyValueFactory<>("getCommandLineOptions"));

// ensure SettingsController knows about all the mods that ModService knows about
modService.getFeaturedMods()
.thenApply(modList -> {
modList.stream()
.filter(featuredMod -> featuredMod.isVisible())
.forEach(featuredMod -> preferencesService.getTotalAnnihilation(featuredMod.getTechnicalName()));
return modList;
});

// gameLocationExecutableTableColumn.setCellFactory(TextFieldTableCell.forTableColumn());
// gameLocationExecutableTableColumn.setOnEditCommit(
// t -> t.getTableView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.faforever.client.main.event.OpenOnlineReplayVaultEvent;
import com.faforever.client.main.event.ShowReplayEvent;
import com.faforever.client.main.event.ShowUserReplaysEvent;
import com.faforever.client.mod.ModService;
import com.faforever.client.notification.ImmediateNotification;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.notification.Severity;
Expand Down Expand Up @@ -40,8 +41,8 @@ public class OnlineReplayVaultController extends VaultEntityController<Replay> {
private int playerId;
private ReplayDetailController replayDetailController;

public OnlineReplayVaultController(ReplayService replayService, UiService uiService, NotificationService notificationService, I18n i18n, PreferencesService preferencesService, ReportingService reportingService) {
super(uiService, notificationService, i18n, preferencesService, reportingService);
public OnlineReplayVaultController(ReplayService replayService, UiService uiService, NotificationService notificationService, I18n i18n, PreferencesService preferencesService, ReportingService reportingService, ModService modService) {
super(uiService, notificationService, i18n, preferencesService, reportingService, modService);
this.replayService = replayService;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.client.ui.preferences;

import com.faforever.client.i18n.I18n;
import com.faforever.client.mod.ModService;
import com.faforever.client.ui.StageHolder;
import com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent;
import com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent;
Expand Down Expand Up @@ -30,6 +31,7 @@ public class GameDirectoryRequiredHandler implements InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private final EventBus eventBus;
private final ModService modService;
private final I18n i18n;
private CompletableFuture<Path> future;

Expand All @@ -42,10 +44,11 @@ public void afterPropertiesSet() {
public void onChooseGameDirectory(GameDirectoryChooseEvent event) {
runLater(() -> {
final String baseGameName = event.getBaseGameName();
String displayName = modService.getFeaturedModDisplayName(baseGameName);
Path path;
{
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(i18n.get("missingGamePath.chooserTitle", baseGameName.toUpperCase()));
fileChooser.setTitle(i18n.get("missingGamePath.chooserTitle", displayName));
File result = fileChooser.showOpenDialog(StageHolder.getStage().getScene().getWindow());

logger.info("User selected game path: {}", result);
Expand All @@ -56,9 +59,9 @@ public void onChooseGameDirectory(GameDirectoryChooseEvent event) {
if (path != null)
{
TextInputDialog cmdLineOptionsInputDialog = new TextInputDialog("");
cmdLineOptionsInputDialog.setTitle(String.format("Total Annihilation: %s", baseGameName.toUpperCase()));
cmdLineOptionsInputDialog.setTitle(String.format("Total Annihilation: %s", displayName));
cmdLineOptionsInputDialog.setHeaderText(
String.format("Executable for %s: %s\n\n", baseGameName.toUpperCase(), path.toString()) +
String.format("Executable for %s: %s\n\n", displayName, path.toString()) +
i18n.get("settings.fa.executableDecorator.description"));
cmdLineOptionsInputDialog.setContentText(i18n.get("settings.fa.executableDecorator"));

Expand Down
Loading

0 comments on commit 277e646

Please sign in to comment.