Show indeterminate progress bar when loading versions in MainPage
This commit is contained in:
@@ -55,30 +55,27 @@ public final class LauncherHelper {
|
|||||||
public static final Queue<ManagedProcess> PROCESSES = new ConcurrentLinkedQueue<>();
|
public static final Queue<ManagedProcess> PROCESSES = new ConcurrentLinkedQueue<>();
|
||||||
private final TaskExecutorDialogPane launchingStepsPane = new TaskExecutorDialogPane(() -> {});
|
private final TaskExecutorDialogPane launchingStepsPane = new TaskExecutorDialogPane(() -> {});
|
||||||
|
|
||||||
public void launch(String selectedVersion, File scriptFile) {
|
public void launch(Profile profile, Account account, String selectedVersion, File scriptFile) {
|
||||||
Profile profile = Settings.INSTANCE.getSelectedProfile();
|
|
||||||
GameRepository repository = profile.getRepository();
|
|
||||||
Account account = Settings.INSTANCE.getSelectedAccount();
|
|
||||||
if (account == null)
|
if (account == null)
|
||||||
throw new IllegalStateException("No account");
|
throw new IllegalArgumentException("No account");
|
||||||
|
|
||||||
|
GameRepository repository = profile.getRepository();
|
||||||
|
|
||||||
Version version = repository.getResolvedVersion(selectedVersion);
|
Version version = repository.getResolvedVersion(selectedVersion);
|
||||||
VersionSetting setting = profile.getVersionSetting(selectedVersion);
|
VersionSetting setting = profile.getVersionSetting(selectedVersion);
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
try {
|
try {
|
||||||
checkGameState(profile, setting, version, () -> Schedulers.newThread().schedule(() -> launch0(selectedVersion, scriptFile)));
|
checkGameState(profile, setting, version, () -> Schedulers.newThread().schedule(() -> launch0(profile, account, selectedVersion, scriptFile)));
|
||||||
} catch (InterruptedException ignore) {
|
} catch (InterruptedException ignore) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launch0(String selectedVersion, File scriptFile) {
|
private void launch0(Profile profile, Account account, String selectedVersion, File scriptFile) {
|
||||||
Profile profile = Settings.INSTANCE.getSelectedProfile();
|
|
||||||
GameRepository repository = profile.getRepository();
|
GameRepository repository = profile.getRepository();
|
||||||
DefaultDependencyManager dependencyManager = profile.getDependency();
|
DefaultDependencyManager dependencyManager = profile.getDependency();
|
||||||
Version version = repository.getResolvedVersion(selectedVersion);
|
Version version = repository.getResolvedVersion(selectedVersion);
|
||||||
Account account = Settings.INSTANCE.getSelectedAccount();
|
|
||||||
VersionSetting setting = profile.getVersionSetting(selectedVersion);
|
VersionSetting setting = profile.getVersionSetting(selectedVersion);
|
||||||
Optional<String> gameVersion = GameVersion.minecraftVersion(repository.getVersionJar(version));
|
Optional<String> gameVersion = GameVersion.minecraftVersion(repository.getVersionJar(version));
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,7 @@
|
|||||||
package org.jackhuang.hmcl.ui;
|
package org.jackhuang.hmcl.ui;
|
||||||
|
|
||||||
import com.jfoenix.concurrency.JFXUtilities;
|
import com.jfoenix.concurrency.JFXUtilities;
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.*;
|
||||||
import com.jfoenix.controls.JFXListView;
|
|
||||||
import com.jfoenix.controls.JFXMasonryPane;
|
|
||||||
import com.jfoenix.controls.JFXPopup;
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
@@ -51,6 +48,7 @@ import org.jackhuang.hmcl.util.StringUtils;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -60,16 +58,18 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
|
|
||||||
private Profile profile;
|
private Profile profile;
|
||||||
private String rightClickedVersion;
|
private String rightClickedVersion;
|
||||||
|
private HMCLGameRepository rightClickedRepository;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private JFXButton btnRefresh;
|
private JFXButton btnRefresh;
|
||||||
|
@FXML
|
||||||
|
private StackPane contentPane;
|
||||||
@FXML
|
@FXML
|
||||||
private JFXButton btnAdd;
|
private JFXButton btnAdd;
|
||||||
|
@FXML
|
||||||
|
private JFXSpinner spinner;
|
||||||
@FXML
|
@FXML
|
||||||
private JFXMasonryPane masonryPane;
|
private JFXMasonryPane masonryPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private JFXListView versionList;
|
private JFXListView versionList;
|
||||||
|
|
||||||
@@ -78,11 +78,16 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
{
|
{
|
||||||
FXUtils.loadFXML(this, "/assets/fxml/main.fxml");
|
FXUtils.loadFXML(this, "/assets/fxml/main.fxml");
|
||||||
|
|
||||||
|
loadingVersions();
|
||||||
|
|
||||||
EventBus.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(event -> {
|
EventBus.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(event -> {
|
||||||
if (event.getSource() == profile.getRepository())
|
if (event.getSource() == profile.getRepository())
|
||||||
loadVersions((HMCLGameRepository) event.getSource());
|
loadVersions((HMCLGameRepository) event.getSource());
|
||||||
});
|
});
|
||||||
EventBus.EVENT_BUS.channel(ProfileChangedEvent.class).register(event -> this.profile = event.getProfile());
|
EventBus.EVENT_BUS.channel(ProfileChangedEvent.class).register(event -> {
|
||||||
|
JFXUtilities.runInFXAndWait(this::loadingVersions);
|
||||||
|
this.profile = event.getProfile();
|
||||||
|
});
|
||||||
|
|
||||||
versionPopup = new JFXPopup(versionList);
|
versionPopup = new JFXPopup(versionList);
|
||||||
getChildren().remove(versionList);
|
getChildren().remove(versionList);
|
||||||
@@ -94,6 +99,7 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Node buildNode(HMCLGameRepository repository, Version version, String game) {
|
private Node buildNode(HMCLGameRepository repository, Version version, String game) {
|
||||||
|
Profile profile = repository.getProfile();
|
||||||
String id = version.getId();
|
String id = version.getId();
|
||||||
VersionItem item = new VersionItem();
|
VersionItem item = new VersionItem();
|
||||||
item.setUpdate(repository.isModpack(id));
|
item.setUpdate(repository.isModpack(id));
|
||||||
@@ -118,7 +124,7 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
if (Settings.INSTANCE.getSelectedAccount() == null)
|
if (Settings.INSTANCE.getSelectedAccount() == null)
|
||||||
Controllers.dialog(Main.i18n("login.empty_username"));
|
Controllers.dialog(Main.i18n("login.empty_username"));
|
||||||
else
|
else
|
||||||
LauncherHelper.INSTANCE.launch(id, null);
|
LauncherHelper.INSTANCE.launch(profile, Settings.INSTANCE.getSelectedAccount(), id, null);
|
||||||
});
|
});
|
||||||
item.setOnScriptButtonClicked(e -> {
|
item.setOnScriptButtonClicked(e -> {
|
||||||
if (Settings.INSTANCE.getSelectedAccount() == null)
|
if (Settings.INSTANCE.getSelectedAccount() == null)
|
||||||
@@ -132,7 +138,7 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
: new FileChooser.ExtensionFilter(Main.i18n("extension.sh"), "*.sh"));
|
: new FileChooser.ExtensionFilter(Main.i18n("extension.sh"), "*.sh"));
|
||||||
File file = chooser.showSaveDialog(Controllers.getStage());
|
File file = chooser.showSaveDialog(Controllers.getStage());
|
||||||
if (file != null)
|
if (file != null)
|
||||||
LauncherHelper.INSTANCE.launch(id, file);
|
LauncherHelper.INSTANCE.launch(profile, Settings.INSTANCE.getSelectedAccount(), id, file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
item.setOnSettingsButtonClicked(e -> {
|
item.setOnSettingsButtonClicked(e -> {
|
||||||
@@ -165,13 +171,14 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
item.setOnMouseClicked(event -> {
|
item.setOnMouseClicked(event -> {
|
||||||
if (event.getButton() == MouseButton.SECONDARY) {
|
if (event.getButton() == MouseButton.SECONDARY) {
|
||||||
rightClickedVersion = id;
|
rightClickedVersion = id;
|
||||||
|
rightClickedRepository = repository;
|
||||||
versionList.getSelectionModel().select(-1);
|
versionList.getSelectionModel().select(-1);
|
||||||
versionPopup.show(item, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY());
|
versionPopup.show(item, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY());
|
||||||
} else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
|
} else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
|
||||||
if (Settings.INSTANCE.getSelectedAccount() == null)
|
if (Settings.INSTANCE.getSelectedAccount() == null)
|
||||||
Controllers.dialog(Main.i18n("login.empty_username"));
|
Controllers.dialog(Main.i18n("login.empty_username"));
|
||||||
else
|
else
|
||||||
LauncherHelper.INSTANCE.launch(id, null);
|
LauncherHelper.INSTANCE.launch(profile, Settings.INSTANCE.getSelectedAccount(), id, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
File iconFile = repository.getVersionIcon(id);
|
File iconFile = repository.getVersionIcon(id);
|
||||||
@@ -180,12 +187,20 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadingVersions() {
|
||||||
|
contentPane.getChildren().setAll(spinner);
|
||||||
|
FXUtils.resetChildren(masonryPane, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
private void loadVersions(HMCLGameRepository repository) {
|
private void loadVersions(HMCLGameRepository repository) {
|
||||||
List<Node> children = new LinkedList<>();
|
List<Node> children = new LinkedList<>();
|
||||||
for (Version version : repository.getVersions()) {
|
for (Version version : repository.getVersions()) {
|
||||||
children.add(buildNode(repository, version, GameVersion.minecraftVersion(repository.getVersionJar(version.getId())).orElse("Unknown")));
|
children.add(buildNode(repository, version, GameVersion.minecraftVersion(repository.getVersionJar(version.getId())).orElse("Unknown")));
|
||||||
}
|
}
|
||||||
JFXUtilities.runInFX(() -> FXUtils.resetChildren(masonryPane, children));
|
JFXUtilities.runInFX(() -> {
|
||||||
|
contentPane.getChildren().setAll(masonryPane);
|
||||||
|
FXUtils.resetChildren(masonryPane, children);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -193,16 +208,16 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
versionPopup.hide();
|
versionPopup.hide();
|
||||||
switch (versionList.getSelectionModel().getSelectedIndex()) {
|
switch (versionList.getSelectionModel().getSelectedIndex()) {
|
||||||
case 0:
|
case 0:
|
||||||
VersionPage.renameVersion(profile, rightClickedVersion);
|
VersionPage.renameVersion(rightClickedRepository.getProfile(), rightClickedVersion);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
VersionPage.deleteVersion(profile, rightClickedVersion);
|
VersionPage.deleteVersion(rightClickedRepository.getProfile(), rightClickedVersion);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
VersionPage.exportVersion(profile, rightClickedVersion);
|
VersionPage.exportVersion(rightClickedRepository.getProfile(), rightClickedVersion);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
FXUtils.openFolder(profile.getRepository().getRunDirectory(rightClickedVersion));
|
FXUtils.openFolder(rightClickedRepository.getRunDirectory(rightClickedVersion));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error();
|
throw new Error();
|
||||||
|
|||||||
@@ -6,14 +6,18 @@
|
|||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.StackPane?>
|
<?import javafx.scene.layout.StackPane?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
<?import com.jfoenix.controls.JFXSpinner?>
|
||||||
<fx:root
|
<fx:root
|
||||||
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
|
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
|
||||||
type="StackPane" pickOnBounds="false"
|
type="StackPane" pickOnBounds="false"
|
||||||
xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">
|
xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<ScrollPane fitToHeight="true" fitToWidth="true" fx:id="scrollPane" hbarPolicy="NEVER">
|
<StackPane fx:id="contentPane">
|
||||||
<JFXMasonryPane fx:id="masonryPane" HSpacing="3" VSpacing="3" cellWidth="182" cellHeight="160">
|
<JFXSpinner fx:id="spinner" styleClass="first-spinner" />
|
||||||
</JFXMasonryPane>
|
<ScrollPane fitToHeight="true" fitToWidth="true" fx:id="scrollPane" hbarPolicy="NEVER">
|
||||||
</ScrollPane>
|
<JFXMasonryPane fx:id="masonryPane" HSpacing="3" VSpacing="3" cellWidth="182" cellHeight="160">
|
||||||
|
</JFXMasonryPane>
|
||||||
|
</ScrollPane>
|
||||||
|
</StackPane>
|
||||||
<VBox style="-fx-padding: 15;" spacing="15" pickOnBounds="false" alignment="BOTTOM_RIGHT">
|
<VBox style="-fx-padding: 15;" spacing="15" pickOnBounds="false" alignment="BOTTOM_RIGHT">
|
||||||
<JFXButton prefWidth="40" prefHeight="40" buttonType="RAISED" fx:id="btnRefresh" styleClass="jfx-button-raised-round">
|
<JFXButton prefWidth="40" prefHeight="40" buttonType="RAISED" fx:id="btnRefresh" styleClass="jfx-button-raised-round">
|
||||||
<graphic>
|
<graphic>
|
||||||
|
|||||||
Reference in New Issue
Block a user