Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Oct 7, 2024
1 parent 4c1e607 commit 269f12f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import org.jackhuang.hmcl.ui.FXUtils;
Expand Down Expand Up @@ -234,7 +235,7 @@ protected Node createItem(ToggleGroup group) {
}
}

public static final class FileOption<T> extends Option<T> {
public static class FileOption<T> extends Option<T> {
private final FileSelector selector = new FileSelector();

public FileOption(String title, T data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
import javafx.beans.binding.Bindings;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.collections.ObservableList;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
Expand All @@ -47,6 +50,7 @@
import org.jackhuang.hmcl.util.Pair;
import org.jackhuang.hmcl.util.javafx.BindingMapping;
import org.jackhuang.hmcl.util.javafx.SafeStringConverter;
import org.jackhuang.hmcl.util.logging.Logger;
import org.jackhuang.hmcl.util.platform.Architecture;
import org.jackhuang.hmcl.java.JavaRuntime;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
Expand Down Expand Up @@ -212,13 +216,38 @@ public VersionSettingsPage(boolean globalSetting) {

gameDirItem = new MultiFileItem<>();
gameDirSublist = new ComponentSublist();
{
HintPane gameDirHint = new HintPane(MessageDialogPane.MessageType.INFO);
gameDirHint.setText(i18n("settings.game.working_directory.should_use_game_repo_feature"));
gameDirSublist.getContent().add(gameDirHint);
}
gameDirSublist.getContent().add(gameDirItem);
gameDirSublist.setTitle(i18n("settings.game.working_directory"));
gameDirSublist.setHasSubtitle(versionId != null);
gameDirItem.disableProperty().bind(modpack);
gameDirCustomOption = new MultiFileItem.FileOption<>(i18n("settings.custom"), GameDirectoryType.CUSTOM)
.setChooserTitle(i18n("settings.game.working_directory.choose"))
.setDirectory(true);
gameDirCustomOption = new MultiFileItem.FileOption<GameDirectoryType>(i18n("settings.custom"), GameDirectoryType.CUSTOM) {
private final WeakListenerHolder holder = new WeakListenerHolder();

@Override
protected Node createItem(ToggleGroup group) {
Node node = super.createItem(group);

ObservableList<Node> children = gameDirItem.getChildren();
holder.add(FXUtils.observeWeak(() -> {
boolean exist = children.contains(node);
if (!"".equals(getValue()) || gameDirItem.getSelectedData() == GameDirectoryType.CUSTOM) {
if (!exist) {
children.add(node);
}
} else {
if (exist) {
children.remove(node);
}
}
}, valueProperty(), gameDirItem.selectedDataProperty()));
return node;
}
}.setChooserTitle(i18n("settings.game.working_directory.choose")).setDirectory(true);

gameDirItem.loadChildren(Arrays.asList(
new MultiFileItem.Option<>(i18n("settings.advanced.game_dir.default"), GameDirectoryType.ROOT_FOLDER),
Expand Down Expand Up @@ -482,6 +511,7 @@ public void loadVersion(Profile profile, String versionId) {
this.listenerHolder = new WeakListenerHolder();

if (versionId == null) {
gameDirSublist.setHasSubtitle(false);
enableSpecificSettings.set(true);
state.set(State.fromTitle(Profiles.getProfileDisplayName(profile) + " - " + i18n("settings.type.global.manage")));

Expand All @@ -497,6 +527,7 @@ public void loadVersion(Profile profile, String versionId) {
}
}));
} else {
gameDirSublist.setHasSubtitle(true);
navigateToSpecificSettings.unbind();
navigateToSpecificSettings.set(false);
}
Expand Down
16 changes: 7 additions & 9 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1030,18 +1030,16 @@ world.reveal=Reveal in Explorer
world.show_all=Show All
world.time=EEE, MMM d, yyyy HH\:mm\:ss

profile=Game Directories
profile=Game Repository
profile.already_exists=This name already exists, please use a different name.
profile.default=Current Directory
profile.home=Vanilla Launcher Directory
profile.home=Vanilla Launcher Repository
profile.instance_directory=Instance Directory
profile.instance_directory.choose=Select an instance directory
profile.manage=Instance Directory List
profile.instance_directory.choose=Select an instance Directory
profile.name=Name
profile.new=New Directory
profile.title=Game Directories
profile.selected=Selected
profile.use_relative_path=Use relative path for game path if possible
profile.new=New Repository
profile.title=Game Repositories
profile.use_relative_path=Use relative path for game repository path if possible

repositories.custom=Custom Maven Repository (%s)
repositories.maven_central=Universal (Maven Central)
Expand Down Expand Up @@ -1162,7 +1160,7 @@ settings.game.working_directory.choose=Select working directory
settings.game.working_directory.hint=Turn on the 'Isolated' option under 'Working Directory' to allow the current instance to store its settings, saves, and mods in a separate directory.\n\
\n\
It is recommended to turn this option on to avoid mod conflicts, but you'll need to move your saves manually.
# '
settings.game.working_directory.should_use_game_repo_feature=Willing to change the game storage path? Go to HMCL Homepage - Version List, and click [Add game repository].

settings.icon=Icon

Expand Down
13 changes: 6 additions & 7 deletions HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -898,18 +898,16 @@ world.reveal=開啟資料夾
world.show_all=全部顯示
world.time=yyyy年MM月dd日 HH:mm:ss

profile=遊戲目錄
profile=遊戲倉庫
profile.already_exists=該名稱已存在
profile.default=目前目錄
profile.home=官方啟動器目錄
profile.default=目前目錄倉庫
profile.home=官方啟動器倉庫
profile.instance_directory=遊戲路徑
profile.instance_directory.choose=選擇遊戲路徑
profile.manage=遊戲目錄列表
profile.name=名稱
profile.new=建立設定
profile.title=遊戲目錄
profile.selected=已選取
profile.use_relative_path=如可行,則在遊戲目錄使用相對路徑
profile.title=遊戲倉庫
profile.use_relative_path=如可行,則在遊戲倉庫使用相對路徑

repositories.custom=自定義 Maven 倉庫(%s)
repositories.maven_central=全球(Maven Central)
Expand Down Expand Up @@ -1021,6 +1019,7 @@ settings.game.management=管理
settings.game.working_directory=執行路徑(版本隔離,修改後請自行移動相關遊戲檔案,如存檔模組設定等)
settings.game.working_directory.choose=選擇執行路徑
settings.game.working_directory.hint=在“運行路徑(版本隔離)”選項中開啟“各版本獨立”使當前版本獨立存放設定、存檔、模組等數據,使用模組時建議開啟此選項以避免不同版本模組衝突。修改此選項後請自行移動存檔等檔案。
settings.game.working_directory.should_use_game_repo_feature=想要更改遊戲的儲存路徑?進入 HMCL 首頁 - 版本列表,點選【添加游戏仓库】

settings.icon=遊戲圖示

Expand Down
15 changes: 7 additions & 8 deletions HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -897,18 +897,16 @@ world.reveal=打开文件夹
world.show_all=显示全部
world.time=yyyy 年 MM 月 dd 日 HH:mm:ss

profile=游戏目录
profile=游戏仓库
profile.already_exists=该名称已存在
profile.default=当前目录
profile.home=官方启动器目录
profile.default=当前目录仓库
profile.home=官方启动器目录仓库
profile.instance_directory=游戏路径
profile.instance_directory.choose=选择游戏路径
profile.manage=游戏目录列表
profile.name=名称
profile.new=添加游戏目录
profile.title=游戏目录
profile.selected=已选中
profile.use_relative_path=若可能,游戏目录使用相对路径
profile.new=添加游戏仓库
profile.title=游戏仓库
profile.use_relative_path=若可能,游戏仓库使用相对路径

repositories.custom=自定义 Maven 仓库(%s)
repositories.maven_central=全球(Maven Central)
Expand Down Expand Up @@ -1020,6 +1018,7 @@ settings.game.management=管理
settings.game.working_directory=版本隔离(建议使用模组时开启“各版本隔离”,改后需移动存档模组等相关游戏文件)
settings.game.working_directory.choose=选择运行路径
settings.game.working_directory.hint=在“运行路径(版本隔离)”选项中开启“各版本独立”使当前版本独立存放设置、存档、模组等数据,使用模组时建议开启此选项以避免不同版本模组冲突。修改此选项后请自行移动存档等文件。
settings.game.working_directory.should_use_game_repo_feature=想要更改游戏的存储路径?进入 HMCL 主页 - 版本列表,点击【添加游戏仓库】

settings.icon=游戏图标

Expand Down

0 comments on commit 269f12f

Please sign in to comment.