feat: show no version hint in GameListPage

This commit is contained in:
huanghongxun 2021-09-18 20:10:28 +08:00
parent 223c45130f
commit 27f87c3a25
8 changed files with 68 additions and 7 deletions

View File

@ -20,6 +20,8 @@ package org.jackhuang.hmcl.ui;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Control;
public class ListPageBase<T> extends Control {
@ -62,4 +64,24 @@ public class ListPageBase<T> extends Control {
public void setFailedReason(String failedReason) {
this.failedReason.set(failedReason);
}
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() {
return onAction;
}
public final void setOnAction(EventHandler<ActionEvent> value) {
onActionProperty().set(value);
}
public final EventHandler<ActionEvent> getOnAction() {
return onActionProperty().get();
}
private ObjectProperty<EventHandler<ActionEvent>> onAction = new SimpleObjectProperty<EventHandler<ActionEvent>>(this, "onAction") {
@Override
protected void invalidated() {
setEventHandler(ActionEvent.ACTION, get());
}
};
}

View File

@ -44,6 +44,7 @@ public abstract class ToolbarListPageSkin<T extends ListPageBase<? extends Node>
SpinnerPane spinnerPane = new SpinnerPane();
spinnerPane.loadingProperty().bind(skinnable.loadingProperty());
spinnerPane.failedReasonProperty().bind(skinnable.failedReasonProperty());
spinnerPane.onActionProperty().bind(skinnable.onActionProperty());
spinnerPane.getStyleClass().add("large-spinner-pane");
ComponentList root = new ComponentList();

View File

@ -21,6 +21,8 @@ import com.jfoenix.controls.JFXSpinner;
import javafx.beans.DefaultProperty;
import javafx.beans.InvalidationListener;
import javafx.beans.property.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
@ -29,6 +31,7 @@ import javafx.scene.layout.StackPane;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
import org.jackhuang.hmcl.ui.animation.TransitionPane;
import org.jackhuang.hmcl.util.javafx.BindingMapping;
@DefaultProperty("content")
public class SpinnerPane extends Control {
@ -85,6 +88,25 @@ public class SpinnerPane extends Control {
this.failedReason.set(failedReason);
}
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() {
return onAction;
}
public final void setOnAction(EventHandler<ActionEvent> value) {
onActionProperty().set(value);
}
public final EventHandler<ActionEvent> getOnAction() {
return onActionProperty().get();
}
private ObjectProperty<EventHandler<ActionEvent>> onAction = new SimpleObjectProperty<EventHandler<ActionEvent>>(this, "onAction") {
@Override
protected void invalidated() {
setEventHandler(ActionEvent.ACTION, get());
}
};
@Override
protected Skin createDefaultSkin() {
return new Skin(this);
@ -105,7 +127,11 @@ public class SpinnerPane extends Control {
topPane.getChildren().setAll(spinner);
topPane.getStyleClass().add("notice-pane");
failedPane.getStyleClass().add("notice-pane");
failedPane.getChildren().setAll(failedReasonLabel);
failedPane.onMouseClickedProperty().bind(
BindingMapping.of(control.onAction)
.map(actionHandler -> (e -> actionHandler.handle(new ActionEvent()))));
FXUtils.onChangeAndOperate(getSkinnable().content, newValue -> {
if (newValue == null) {

View File

@ -22,6 +22,7 @@ import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SkinBase;
import javafx.scene.control.ToggleGroup;
@ -179,9 +180,13 @@ public class GameListPage extends ListPageBase<GameListItem> implements Decorato
super();
Profiles.registerVersionsListener(this::loadVersions);
setOnAction(e -> Controllers.navigate(Controllers.getDownloadPage()));
}
private void loadVersions(Profile profile) {
setLoading(true);
setFailedReason(null);
HMCLGameRepository repository = profile.getRepository();
toggleGroup = new ToggleGroup();
WeakListenerHolder listenerHolder = new WeakListenerHolder();
@ -198,6 +203,10 @@ public class GameListPage extends ListPageBase<GameListItem> implements Decorato
itemsProperty().setAll(children);
children.forEach(GameListItem::checkSelection);
if (children.isEmpty()) {
setFailedReason(i18n("version.empty.hint"));
}
profile.selectedVersionProperty().addListener(listenerHolder.weak((a, b, newValue) -> {
FXUtils.checkFxUserThread();
children.forEach(it -> it.selectedProperty().set(false));

View File

@ -228,7 +228,7 @@ public final class Versions {
private static boolean checkVersionForLaunching(Profile profile, String id) {
if (id == null || !profile.getRepository().isLoaded() || !profile.getRepository().hasVersion(id)) {
Controllers.dialog(i18n("version.empty.launch"), i18n("launch.failed"), MessageDialogPane.MessageType.ERROR, () -> {
Controllers.navigate(Controllers.getGameListPage());
Controllers.navigate(Controllers.getDownloadPage());
});
return false;
} else {

View File

@ -755,7 +755,8 @@ version=Games
version.cannot_read=Unable to find the game version. Cannot continue automatic installation.
version.empty=No game
version.empty.add=Install new version
version.empty.launch=No version to launch, please install a version via version list page.
version.empty.launch=No version to launch, please install a version via download page.
version.empty.hint=No installed game version. Click here to download a new game.
version.game.old=Old
version.game.release=Release
version.game.releases=Releases

View File

@ -753,9 +753,10 @@ update.tooltip=更新
version=遊戲
version.cannot_read=讀取遊戲版本失敗,無法進行自動安裝
version.empty=無遊戲版本
version.empty.add=進入遊戲列表安裝
version.empty.launch=沒有可啟動的遊戲,你可以點選左側遊戲欄內的設定按鈕進入遊戲列表安裝遊戲
version.empty=沒有遊戲版本
version.empty.add=進入下載頁安裝遊戲
version.empty.launch=沒有可啟動的遊戲,你可以點擊左側邊欄內的下載按鈕安裝遊戲
version.empty.hint=沒有已安裝的遊戲,你可以切換其他遊戲目錄,或者點擊此處進入遊戲下載頁面
version.game.old=老舊版本
version.game.release=穩定版本
version.game.releases=穩定版本

View File

@ -754,8 +754,9 @@ update.tooltip=更新
version=游戏
version.cannot_read=读取游戏版本失败,无法进行自动安装
version.empty=没有游戏版本
version.empty.add=进入版本列表安装
version.empty.launch=没有可启动的游戏,你可以点击左侧游戏栏内的设置按钮进入版本列表安装游戏
version.empty.add=进入下载页安装游戏
version.empty.launch=没有可启动的游戏,你可以点击左侧边栏内的下载按钮安装游戏
version.empty.hint=没有已安装的游戏,你可以切换其他游戏目录,或者点击此处进入游戏下载页面
version.game.old=远古版
version.game.release=正式版
version.game.releases=正式版