mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2024-11-21 03:10:58 +08:00
安装新版本的版本名输入框显示已选择加载器名称 (#3234)
* Update InstallersPage.java * 优化代码 * Update InstallersPage.java * Update InstallersPage.java * fix: checkstyle * 给 LibraryAnalyzer.LibraryType.fromPatchId 稍微优化一下,把她里面的实现改为一个预先生成的 map, 相信你知道怎么把这个函数改成一个 lookupMap.get(patchId) 的形式 * Update InstallersPage.java * Update InstallersPage.java * Fix * update --------- Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
parent
00b7085370
commit
dec307b531
@ -52,6 +52,8 @@ public class InstallersPage extends Control implements WizardPage {
|
||||
protected JFXTextField txtName = new JFXTextField();
|
||||
protected BooleanProperty installable = new SimpleBooleanProperty();
|
||||
|
||||
private boolean isNameModifiedByUser = false;
|
||||
|
||||
public InstallersPage(WizardController controller, HMCLGameRepository repository, String gameVersion, DownloadProvider downloadProvider) {
|
||||
this.controller = controller;
|
||||
this.group = new InstallerItem.InstallerItemGroup(gameVersion, getInstallerItemStyle());
|
||||
@ -61,7 +63,8 @@ public class InstallersPage extends Control implements WizardPage {
|
||||
new Validator(i18n("install.new_game.already_exists"), str -> !repository.versionIdConflicts(str)),
|
||||
new Validator(i18n("install.new_game.malformed"), HMCLGameRepository::isValidVersionId));
|
||||
installable.bind(createBooleanBinding(txtName::validate, txtName.textProperty()));
|
||||
txtName.setText(gameVersion);
|
||||
|
||||
txtName.textProperty().addListener((obs, oldText, newText) -> isNameModifiedByUser = true);
|
||||
|
||||
for (InstallerItem library : group.getLibraries()) {
|
||||
String libraryId = library.getLibraryId();
|
||||
@ -103,6 +106,9 @@ public class InstallersPage extends Control implements WizardPage {
|
||||
library.versionProperty().set(null);
|
||||
}
|
||||
}
|
||||
if (!isNameModifiedByUser) {
|
||||
setTxtNameWithLoaders();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -124,6 +130,49 @@ public class InstallersPage extends Control implements WizardPage {
|
||||
return new InstallersPageSkin(this);
|
||||
}
|
||||
|
||||
private void setTxtNameWithLoaders() {
|
||||
StringBuilder nameBuilder = new StringBuilder(group.getGame().versionProperty().get().getVersion());
|
||||
|
||||
for (InstallerItem library : group.getLibraries()) {
|
||||
String libraryId = library.getLibraryId().replace(LibraryAnalyzer.LibraryType.MINECRAFT.getPatchId(), "");
|
||||
if (!controller.getSettings().containsKey(libraryId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LibraryAnalyzer.LibraryType libraryType = LibraryAnalyzer.LibraryType.fromPatchId(libraryId);
|
||||
if (libraryType != null) {
|
||||
String loaderName;
|
||||
switch (libraryType) {
|
||||
case FORGE:
|
||||
loaderName = i18n("install.installer.forge");
|
||||
break;
|
||||
case NEO_FORGE:
|
||||
loaderName = i18n("install.installer.neoforge");
|
||||
break;
|
||||
case FABRIC:
|
||||
loaderName = i18n("install.installer.fabric");
|
||||
break;
|
||||
case LITELOADER:
|
||||
loaderName = i18n("install.installer.liteloader");
|
||||
break;
|
||||
case QUILT:
|
||||
loaderName = i18n("install.installer.quilt");
|
||||
break;
|
||||
case OPTIFINE:
|
||||
loaderName = i18n("install.installer.optifine");
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
nameBuilder.append("-").append(loaderName);
|
||||
}
|
||||
}
|
||||
|
||||
txtName.setText(nameBuilder.toString());
|
||||
isNameModifiedByUser = false;
|
||||
}
|
||||
|
||||
protected static class InstallersPageSkin extends SkinBase<InstallersPage> {
|
||||
|
||||
/**
|
||||
|
@ -270,6 +270,13 @@ public final class LibraryAnalyzer implements Iterable<LibraryAnalyzer.LibraryMa
|
||||
private final Pattern group, artifact;
|
||||
private final ModLoaderType modLoaderType;
|
||||
|
||||
private static final Map<String, LibraryType> PATCH_ID_MAP = new HashMap<>();
|
||||
static {
|
||||
for (LibraryType type : values()) {
|
||||
PATCH_ID_MAP.put(type.getPatchId(), type);
|
||||
}
|
||||
}
|
||||
|
||||
LibraryType(boolean modLoader, String patchId, Pattern group, Pattern artifact, ModLoaderType modLoaderType) {
|
||||
this.modLoader = modLoader;
|
||||
this.patchId = patchId;
|
||||
@ -291,10 +298,7 @@ public final class LibraryAnalyzer implements Iterable<LibraryAnalyzer.LibraryMa
|
||||
}
|
||||
|
||||
public static LibraryType fromPatchId(String patchId) {
|
||||
for (LibraryType type : values())
|
||||
if (type.getPatchId().equals(patchId))
|
||||
return type;
|
||||
return null;
|
||||
return PATCH_ID_MAP.get(patchId);
|
||||
}
|
||||
|
||||
protected boolean matchLibrary(Library library, List<Library> libraries) {
|
||||
|
Loading…
Reference in New Issue
Block a user