Skip to content

Commit

Permalink
feat: hide pre-releases by default (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
skaldarnar authored Aug 29, 2021
1 parent 5d5b0db commit 55ffb4b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyProperty;
import javafx.beans.property.SimpleBooleanProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
Expand Down Expand Up @@ -35,6 +38,7 @@ public final class BaseLauncherSettings extends LauncherSettings {
public static final String PROPERTY_GAME_DIRECTORY = "gameDirectory";
public static final String PROPERTY_GAME_DATA_DIRECTORY = "gameDataDirectory";
public static final String PROPERTY_SAVE_DOWNLOADED_FILES = "saveDownloadedFiles";
public static final String PROPERTY_SHOW_PRE_RELEASES = "showPreReleases";
public static final String PROPERTY_BASE_JAVA_PARAMETERS = "baseJavaParameters";
public static final String PROPERTY_USER_JAVA_PARAMETERS = "userJavaParameters";
public static final String PROPERTY_USER_GAME_PARAMETERS = "userGameParameters";
Expand All @@ -48,19 +52,21 @@ public final class BaseLauncherSettings extends LauncherSettings {
public static final JavaHeapSize INITIAL_HEAP_SIZE_DEFAULT = JavaHeapSize.NOT_USED;
public static final boolean CLOSE_LAUNCHER_AFTER_GAME_START_DEFAULT = true;
public static final boolean SAVE_DOWNLOADED_FILES_DEFAULT = false;
public static final boolean SHOW_PRE_RELEASES_DEFAULT = false;
public static final String LAST_PLAYED_GAME_VERSION_DEFAULT = "";
public static final String LAST_INSTALLED_GAME_VERSION_DEFAULT = "";

public static final String LAUNCHER_SETTINGS_FILE_NAME = "TerasologyLauncherSettings.properties";

private static final Logger logger = LoggerFactory.getLogger(BaseLauncherSettings.class);


private static final String WARN_MSG_INVALID_VALUE = "Invalid value '{}' for the parameter '{}'!";
private static final Level LOG_LEVEL_DEFAULT = Level.INFO;

private final Properties properties;

private final Property<Boolean> showPreReleases = new SimpleBooleanProperty(SHOW_PRE_RELEASES_DEFAULT);

BaseLauncherSettings(Properties properties) {
this.properties = properties;
}
Expand Down Expand Up @@ -160,6 +166,15 @@ protected void initSaveDownloadedFiles() {
properties.setProperty(PROPERTY_SAVE_DOWNLOADED_FILES, Boolean.toString(saveDownloadedFiles));
}

protected void initShowPreReleases() {
final String showPreReleasesStr = properties.getProperty(PROPERTY_SHOW_PRE_RELEASES);
if (showPreReleasesStr != null) {
setShowPreReleases(Boolean.parseBoolean(showPreReleasesStr));
} else {
setShowPreReleases(SHOW_PRE_RELEASES_DEFAULT);
}
}

protected void initGameDirectory() {
final String gameDirectoryStr = properties.getProperty(PROPERTY_GAME_DIRECTORY);
Path gameDirectory = null;
Expand Down Expand Up @@ -208,6 +223,15 @@ protected void initLastInstalledGameVersion() {
}
}

// --------------------------------------------------------------------- //
// PROPERTIES
// --------------------------------------------------------------------- //

@Override
public ReadOnlyProperty<Boolean> showPreReleases() {
return showPreReleases;
}

// --------------------------------------------------------------------- //
// GETTERS
// --------------------------------------------------------------------- //
Expand Down Expand Up @@ -283,6 +307,11 @@ public synchronized boolean isKeepDownloadedFiles() {
return Boolean.valueOf(properties.getProperty(PROPERTY_SAVE_DOWNLOADED_FILES));
}

@Override
public synchronized boolean isShowPreReleases() {
return Boolean.parseBoolean(properties.getProperty(PROPERTY_SHOW_PRE_RELEASES));
}

@Override
public synchronized Optional<GameIdentifier> getLastPlayedGameVersion() {
String property = properties.getProperty(PROPERTY_LAST_PLAYED_GAME_VERSION);
Expand Down Expand Up @@ -348,6 +377,12 @@ public synchronized void setKeepDownloadedFiles(boolean keepDownloadedFiles) {
properties.setProperty(PROPERTY_SAVE_DOWNLOADED_FILES, Boolean.toString(keepDownloadedFiles));
}

@Override
public synchronized void setShowPreReleases(boolean selected) {
showPreReleases.setValue(selected);
properties.setProperty(PROPERTY_SHOW_PRE_RELEASES, Boolean.toString(selected));
}

@Override
public synchronized void setGameDirectory(Path gameDirectory) {
properties.setProperty(PROPERTY_GAME_DIRECTORY, gameDirectory.toUri().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.terasology.launcher.settings;

import com.google.common.collect.Lists;
import javafx.beans.property.ReadOnlyProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
Expand Down Expand Up @@ -33,6 +34,7 @@ public synchronized void init() {
initBaseJavaParameters();
initCloseLauncherAfterGameStart();
initSaveDownloadedFiles();
initShowPreReleases();
initGameDirectory();
initGameDataDirectory();
initUserJavaParameters();
Expand All @@ -52,6 +54,8 @@ public synchronized void init() {

protected abstract void initSaveDownloadedFiles();

protected abstract void initShowPreReleases();

protected abstract void initGameDirectory();

protected abstract void initGameDataDirectory();
Expand All @@ -72,6 +76,12 @@ public synchronized void init() {

protected abstract void initLastInstalledGameVersion();

// --------------------------------------------------------------------- //
// PROPERTIES
// --------------------------------------------------------------------- //

public abstract ReadOnlyProperty<Boolean> showPreReleases();

// --------------------------------------------------------------------- //
// GETTERS
// --------------------------------------------------------------------- //
Expand Down Expand Up @@ -119,6 +129,8 @@ public synchronized List<String> getUserGameParameterList() {

public abstract boolean isKeepDownloadedFiles();

public abstract boolean isShowPreReleases();

public abstract Optional<GameIdentifier> getLastPlayedGameVersion();

public abstract String getLastInstalledGameJob();
Expand All @@ -143,6 +155,8 @@ public synchronized List<String> getUserGameParameterList() {

public abstract void setKeepDownloadedFiles(boolean keepDownloadedFiles);

public abstract void setShowPreReleases(boolean selected);

public abstract void setGameDirectory(Path gameDirectory);

public abstract void setGameDataDirectory(Path gameDataDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.terasology.launcher.game.GameManager;
import org.terasology.launcher.game.GameService;
import org.terasology.launcher.game.Installation;
import org.terasology.launcher.model.Build;
import org.terasology.launcher.model.GameIdentifier;
import org.terasology.launcher.model.GameRelease;
import org.terasology.launcher.model.Profile;
Expand Down Expand Up @@ -83,6 +84,7 @@ public class ApplicationController {
private Property<GameRelease> selectedRelease;
private Property<GameAction> gameAction;
private BooleanProperty downloading;
private BooleanProperty showPreReleases;

private ObservableSet<GameIdentifier> installedGames;

Expand Down Expand Up @@ -124,6 +126,7 @@ public ApplicationController() {
gameService.valueProperty().addListener(this::handleRunStarted);

downloading = new SimpleBooleanProperty(false);
showPreReleases = new SimpleBooleanProperty(false);

selectedRelease = new SimpleObjectProperty<>();

Expand Down Expand Up @@ -200,10 +203,11 @@ private void initComboBoxes() {
List<GameRelease> releasesForProfile =
repositoryManager.getReleases().stream()
.filter(release -> release.getId().getProfile() == selectedProfile.get())
.filter(release -> showPreReleases.getValue() || release.getId().getBuild().equals(Build.STABLE))
.sorted(ApplicationController::compareReleases)
.collect(Collectors.toList());
return FXCollections.observableList(releasesForProfile);
}, selectedProfile);
}, selectedProfile, showPreReleases);

gameReleaseComboBox.itemsProperty().bind(releases);
gameReleaseComboBox.buttonCellProperty().bind(Bindings.createObjectBinding(() -> new GameReleaseCell(installedGames, true), installedGames));
Expand Down Expand Up @@ -252,6 +256,7 @@ public void update(final Path launcherDirectory, final Path downloadDirectory, f
final Stage stage, final HostServices hostServices) {
this.launcherDirectory = launcherDirectory;
this.launcherSettings = launcherSettings;
this.showPreReleases.bind(launcherSettings.showPreReleases());

this.repositoryManager = repositoryManager;
this.gameManager = gameManager;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/terasology/launcher/ui/SettingsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class SettingsController {
@FXML
private CheckBox closeAfterStartBox;
@FXML
private CheckBox showPreReleasesBox;
@FXML
private CheckBox saveDownloadedFilesBox;
@FXML
private Label launcherDirectoryLabel;
Expand Down Expand Up @@ -127,6 +129,9 @@ protected void saveSettingsAction(ActionEvent event) {
// save closeLauncherAfterGameStart
launcherSettings.setCloseLauncherAfterGameStart(closeAfterStartBox.isSelected());

// save showPreReleases
launcherSettings.setShowPreReleases(showPreReleasesBox.isSelected());

// save saveDownloadedFiles
launcherSettings.setKeepDownloadedFiles(saveDownloadedFilesBox.isSelected());

Expand Down Expand Up @@ -202,6 +207,7 @@ void initialize(final Path newLauncherDirectory, final LauncherSettings newLaunc
populateLanguageIcons();
populateCloseLauncherAfterGameStart();
populateSaveDownloadedFiles();
populateShowPreReleases();
populateLogLevel();

gameDirectory = newLauncherSettings.getGameDirectory();
Expand Down Expand Up @@ -242,6 +248,7 @@ private void setLabelStrings() {
chooseLanguageLabel.setText(BundleUtils.getLabel("settings_launcher_chooseLanguage"));
closeAfterStartBox.setText(BundleUtils.getLabel("settings_launcher_closeLauncherAfterGameStart"));
saveDownloadedFilesBox.setText(BundleUtils.getLabel("settings_launcher_saveDownloadedFiles"));
showPreReleasesBox.setText(BundleUtils.getLabel("settings_launcher_showPreReleases"));
launcherDirectoryLabel.setText(BundleUtils.getLabel("settings_launcher_launcherDirectory"));
launcherDirectoryOpenButton.setText(BundleUtils.getLabel("settings_launcher_launcherDirectory_open"));
saveSettingsButton.setText(BundleUtils.getLabel("settings_save"));
Expand Down Expand Up @@ -292,6 +299,10 @@ private void populateCloseLauncherAfterGameStart() {
closeAfterStartBox.setSelected(launcherSettings.isCloseLauncherAfterGameStart());
}

private void populateShowPreReleases() {
showPreReleasesBox.setSelected(launcherSettings.isShowPreReleases());
}

private void populateSaveDownloadedFiles() {
saveDownloadedFilesBox.setSelected(launcherSettings.isKeepDownloadedFiles());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ settings_launcher_closeLauncherAfterGameStart=
settings_launcher_launcherDirectory=
settings_launcher_launcherDirectory_open=
settings_launcher_saveDownloadedFiles=
settings_launcher_showPreReleases=
settings_launcher_searchForLauncherUpdates=
settings_launcher_title=
settings_save=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ settings_launcher_closeLauncherAfterGameStart=Launcher beim Spielstart schlie\u0
settings_launcher_launcherDirectory=Launcher Nutzerdatenverzeichnis
settings_launcher_launcherDirectory_open=\u00D6ffnen
settings_launcher_saveDownloadedFiles=Heruntergeladene Pakete behalten
settings_launcher_showPreReleases=Prereleases (Vorabversionen) und Testversionen anzeigen
settings_launcher_searchForLauncherUpdates=Launcher-Aktualisierungen
settings_launcher_title=Launcher
settings_save=Speichern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ settings_launcher_downloadDirectory_open=Open
settings_launcher_launcherDirectory=Launcher User Data Directory
settings_launcher_launcherDirectory_open=Open
settings_launcher_saveDownloadedFiles=Save downloaded files
settings_launcher_showPreReleases=Show pre-releases and nightly builds
settings_launcher_searchForLauncherUpdates=Search for launcher updates
settings_launcher_title=Launcher
settings_save=Save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<StackPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.terasology.launcher.ui.SettingsController">
<StackPane xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.terasology.launcher.ui.SettingsController">
<children>
<VBox prefHeight="600.0" prefWidth="600.0">
<children>
Expand Down Expand Up @@ -49,6 +49,7 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label fx:id="gameSettingsTitle" text="Game settings">
Expand Down Expand Up @@ -114,8 +115,9 @@
<TextField fx:id="launcherDirectoryPath" editable="false" GridPane.rowIndex="12" />
<Button fx:id="launcherDirectoryOpenButton" mnemonicParsing="false" onAction="#openLauncherDirectoryAction" text="Browse" GridPane.columnIndex="1" GridPane.rowIndex="12" />
<Label text="Other" GridPane.rowIndex="13" />
<CheckBox fx:id="closeAfterStartBox" mnemonicParsing="false" text="Close after game starts" GridPane.rowIndex="14" />
<CheckBox fx:id="saveDownloadedFilesBox" mnemonicParsing="false" text="Save downloaded files" GridPane.rowIndex="15" />
<CheckBox fx:id="showPreReleasesBox" mnemonicParsing="false" text="Show pre-releases and nightly builds" GridPane.rowIndex="14" />
<CheckBox fx:id="closeAfterStartBox" mnemonicParsing="false" text="Close after game starts" GridPane.rowIndex="15" />
<CheckBox fx:id="saveDownloadedFilesBox" mnemonicParsing="false" text="Save downloaded files" GridPane.rowIndex="16" />
</children>
</GridPane>
</content>
Expand Down

0 comments on commit 55ffb4b

Please sign in to comment.