mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-09 11:55:52 -04: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 JFXTextField txtName = new JFXTextField();
|
||||||
protected BooleanProperty installable = new SimpleBooleanProperty();
|
protected BooleanProperty installable = new SimpleBooleanProperty();
|
||||||
|
|
||||||
|
private boolean isNameModifiedByUser = false;
|
||||||
|
|
||||||
public InstallersPage(WizardController controller, HMCLGameRepository repository, String gameVersion, DownloadProvider downloadProvider) {
|
public InstallersPage(WizardController controller, HMCLGameRepository repository, String gameVersion, DownloadProvider downloadProvider) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
this.group = new InstallerItem.InstallerItemGroup(gameVersion, getInstallerItemStyle());
|
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.already_exists"), str -> !repository.versionIdConflicts(str)),
|
||||||
new Validator(i18n("install.new_game.malformed"), HMCLGameRepository::isValidVersionId));
|
new Validator(i18n("install.new_game.malformed"), HMCLGameRepository::isValidVersionId));
|
||||||
installable.bind(createBooleanBinding(txtName::validate, txtName.textProperty()));
|
installable.bind(createBooleanBinding(txtName::validate, txtName.textProperty()));
|
||||||
txtName.setText(gameVersion);
|
|
||||||
|
txtName.textProperty().addListener((obs, oldText, newText) -> isNameModifiedByUser = true);
|
||||||
|
|
||||||
for (InstallerItem library : group.getLibraries()) {
|
for (InstallerItem library : group.getLibraries()) {
|
||||||
String libraryId = library.getLibraryId();
|
String libraryId = library.getLibraryId();
|
||||||
@ -103,6 +106,9 @@ public class InstallersPage extends Control implements WizardPage {
|
|||||||
library.versionProperty().set(null);
|
library.versionProperty().set(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!isNameModifiedByUser) {
|
||||||
|
setTxtNameWithLoaders();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -124,6 +130,49 @@ public class InstallersPage extends Control implements WizardPage {
|
|||||||
return new InstallersPageSkin(this);
|
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> {
|
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 Pattern group, artifact;
|
||||||
private final ModLoaderType modLoaderType;
|
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) {
|
LibraryType(boolean modLoader, String patchId, Pattern group, Pattern artifact, ModLoaderType modLoaderType) {
|
||||||
this.modLoader = modLoader;
|
this.modLoader = modLoader;
|
||||||
this.patchId = patchId;
|
this.patchId = patchId;
|
||||||
@ -291,10 +298,7 @@ public final class LibraryAnalyzer implements Iterable<LibraryAnalyzer.LibraryMa
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static LibraryType fromPatchId(String patchId) {
|
public static LibraryType fromPatchId(String patchId) {
|
||||||
for (LibraryType type : values())
|
return PATCH_ID_MAP.get(patchId);
|
||||||
if (type.getPatchId().equals(patchId))
|
|
||||||
return type;
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean matchLibrary(Library library, List<Library> libraries) {
|
protected boolean matchLibrary(Library library, List<Library> libraries) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user