fix(ui): crash.

This commit is contained in:
huanghongxun 2021-10-06 17:18:21 +08:00
parent 1b8cf6b1e5
commit e4a1fa5bb4
3 changed files with 14 additions and 43 deletions

View File

@ -90,7 +90,7 @@ public final class MainPage extends StackPane implements DecoratorPage {
titleLabel.getStyleClass().add("jfx-decorator-title"); titleLabel.getStyleClass().add("jfx-decorator-title");
titleNode.getChildren().setAll(titleIcon, titleLabel); titleNode.getChildren().setAll(titleIcon, titleLabel);
state.setValue(State.fromTitleNode(titleNode)); state.setValue(new State(null, titleNode, false, false, true));
setPadding(new Insets(20)); setPadding(new Insets(20));

View File

@ -17,9 +17,7 @@
*/ */
package org.jackhuang.hmcl.ui.main; package org.jackhuang.hmcl.ui.main;
import javafx.scene.Node; import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.scene.control.SkinBase;
import javafx.scene.layout.BorderPane;
import org.jackhuang.hmcl.event.EventBus; import org.jackhuang.hmcl.event.EventBus;
import org.jackhuang.hmcl.event.RefreshedVersionsEvent; import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
import org.jackhuang.hmcl.game.HMCLGameRepository; import org.jackhuang.hmcl.game.HMCLGameRepository;
@ -36,8 +34,8 @@ import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.account.AccountAdvancedListItem; import org.jackhuang.hmcl.ui.account.AccountAdvancedListItem;
import org.jackhuang.hmcl.ui.construct.AdvancedListBox; import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
import org.jackhuang.hmcl.ui.construct.AdvancedListItem; import org.jackhuang.hmcl.ui.construct.AdvancedListItem;
import org.jackhuang.hmcl.ui.construct.TabHeader; import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
import org.jackhuang.hmcl.ui.decorator.DecoratorTabPage; import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
import org.jackhuang.hmcl.ui.download.ModpackInstallWizardProvider; import org.jackhuang.hmcl.ui.download.ModpackInstallWizardProvider;
import org.jackhuang.hmcl.ui.versions.GameAdvancedListItem; import org.jackhuang.hmcl.ui.versions.GameAdvancedListItem;
import org.jackhuang.hmcl.ui.versions.Versions; import org.jackhuang.hmcl.ui.versions.Versions;
@ -57,14 +55,10 @@ import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap; import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class RootPage extends DecoratorTabPage { public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
private MainPage mainPage = null; private MainPage mainPage = null;
private final TabHeader.Tab<MainPage> mainTab = new TabHeader.Tab<>("main");
public RootPage() { public RootPage() {
setLeftPaneWidth(200);
EventBus.EVENT_BUS.channel(RefreshedVersionsEvent.class) EventBus.EVENT_BUS.channel(RefreshedVersionsEvent.class)
.register(event -> onRefreshedVersions((HMCLGameRepository) event.getSource())); .register(event -> onRefreshedVersions((HMCLGameRepository) event.getSource()));
@ -72,25 +66,13 @@ public class RootPage extends DecoratorTabPage {
if (profile != null && profile.getRepository().isLoaded()) if (profile != null && profile.getRepository().isLoaded())
onRefreshedVersions(Profiles.selectedProfileProperty().get().getRepository()); onRefreshedVersions(Profiles.selectedProfileProperty().get().getRepository());
mainTab.setNodeSupplier(this::getMainPage); getStyleClass().remove("gray-background");
getTabs().setAll(mainTab); getLeft().getStyleClass().add("gray-background");
} }
@Override @Override
public boolean back() { public ReadOnlyObjectProperty<State> stateProperty() {
if (mainTab.isSelected()) return getMainPage().stateProperty();
return true;
else {
getSelectionModel().select(mainTab);
return false;
}
}
@Override
protected void onNavigated(Node to) {
backableProperty().set(!(to instanceof MainPage));
super.onNavigated(to);
} }
@Override @Override
@ -132,7 +114,7 @@ public class RootPage extends DecoratorTabPage {
return mainPage; return mainPage;
} }
private static class Skin extends SkinBase<RootPage> { private static class Skin extends DecoratorAnimatedPageSkin<RootPage> {
protected Skin(RootPage control) { protected Skin(RootPage control) {
super(control); super(control);
@ -195,18 +177,8 @@ public class RootPage extends DecoratorTabPage {
.add(launcherSettingsItem); .add(launcherSettingsItem);
// the root page, with the sidebar in left, navigator in center. // the root page, with the sidebar in left, navigator in center.
BorderPane root = new BorderPane(); setLeft(sideBar);
sideBar.setPrefWidth(200); setCenter(getSkinnable().getMainPage());
root.setLeft(sideBar);
{
control.transitionPane.getStyleClass().add("jfx-decorator-content-container");
control.transitionPane.getChildren().setAll(getSkinnable().getMainPage());
FXUtils.setOverflowHidden(control.transitionPane, 8);
root.setCenter(control.transitionPane);
}
getChildren().setAll(root);
} }
} }

View File

@ -29,7 +29,6 @@ import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.Profiles;
import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
@ -78,9 +77,9 @@ public class VersionPage extends DecoratorAnimatedPage implements DecoratorPage
private <T extends Node> Supplier<T> loadVersionFor(Supplier<T> nodeSupplier) { private <T extends Node> Supplier<T> loadVersionFor(Supplier<T> nodeSupplier) {
return () -> { return () -> {
T node = nodeSupplier.get(); T node = nodeSupplier.get();
if (this.version.get() != null) { if (version.get() != null) {
if (node instanceof VersionPage.VersionLoadable) { if (node instanceof VersionPage.VersionLoadable) {
((VersionPage.VersionLoadable) node).loadVersion(Profiles.getSelectedProfile(), null); ((VersionLoadable) node).loadVersion(version.get().getProfile(), version.get().getVersion());
} }
} }
return node; return node;