Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/zkitefly/version-name' int…
Browse files Browse the repository at this point in the history
…o prs
  • Loading branch information
burningtnt committed Aug 18, 2024
2 parents 092b8ff + fd26bf8 commit 74c51ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -61,7 +63,8 @@ public InstallersPage(WizardController controller, HMCLGameRepository repository
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();
Expand Down Expand Up @@ -103,6 +106,9 @@ protected void reload() {
library.versionProperty().set(null);
}
}
if (!isNameModifiedByUser) {
setTxtNameWithLoaders();
}
}

@Override
Expand All @@ -124,6 +130,24 @@ protected Skin<?> createDefaultSkin() {
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;
}
if (LibraryAnalyzer.LibraryType.fromPatchId(libraryId).getModLoaderType() != null) {
String capitalizedLibraryId = Character.toUpperCase(libraryId.charAt(0)) + libraryId.substring(1);
nameBuilder.append("-").append(capitalizedLibraryId);
}
}

txtName.setText(nameBuilder.toString());
isNameModifiedByUser = false;
}

protected static class InstallersPageSkin extends SkinBase<InstallersPage> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.jackhuang.hmcl.util.Pair.pair;

Expand Down Expand Up @@ -270,6 +271,9 @@ private String scanVersion(Version version) {
private final Pattern group, artifact;
private final ModLoaderType modLoaderType;

private static final Map<String, LibraryType> PATCH_ID_MAP = Stream.of(values())
.collect(Collectors.toMap(LibraryType::getPatchId, type -> type));

LibraryType(boolean modLoader, String patchId, Pattern group, Pattern artifact, ModLoaderType modLoaderType) {
this.modLoader = modLoader;
this.patchId = patchId;
Expand All @@ -291,10 +295,7 @@ public ModLoaderType getModLoaderType() {
}

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) {
Expand Down

0 comments on commit 74c51ef

Please sign in to comment.