将 InstallerItem.State 迁移至 sealed 接口 (#5209)
This commit is contained in:
@@ -63,7 +63,7 @@ public class InstallerItem extends Control {
|
|||||||
private final ObjectProperty<Runnable> onInstall = new SimpleObjectProperty<>(this, "onInstall");
|
private final ObjectProperty<Runnable> onInstall = new SimpleObjectProperty<>(this, "onInstall");
|
||||||
private final ObjectProperty<Runnable> onRemove = new SimpleObjectProperty<>(this, "onRemove");
|
private final ObjectProperty<Runnable> onRemove = new SimpleObjectProperty<>(this, "onRemove");
|
||||||
|
|
||||||
public interface State {
|
public sealed interface State {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class InstallableState implements State {
|
public static final class InstallableState implements State {
|
||||||
@@ -73,46 +73,10 @@ public class InstallerItem extends Control {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class IncompatibleState implements State {
|
public record IncompatibleState(String incompatibleItemName, String incompatibleItemVersion) implements State {
|
||||||
private final String incompatibleItemName;
|
|
||||||
private final String incompatibleItemVersion;
|
|
||||||
|
|
||||||
public IncompatibleState(String incompatibleItemName, String incompatibleItemVersion) {
|
|
||||||
this.incompatibleItemName = incompatibleItemName;
|
|
||||||
this.incompatibleItemVersion = incompatibleItemVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIncompatibleItemName() {
|
|
||||||
return incompatibleItemName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIncompatibleItemVersion() {
|
|
||||||
return incompatibleItemVersion;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class InstalledState implements State {
|
public record InstalledState(String version, boolean external, boolean incompatibleWithGame) implements State {
|
||||||
private final String version;
|
|
||||||
private final boolean external;
|
|
||||||
private final boolean incompatibleWithGame;
|
|
||||||
|
|
||||||
public InstalledState(String version, boolean external, boolean incompatibleWithGame) {
|
|
||||||
this.version = version;
|
|
||||||
this.external = external;
|
|
||||||
this.incompatibleWithGame = incompatibleWithGame;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExternal() {
|
|
||||||
return external;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIncompatibleWithGame() {
|
|
||||||
return incompatibleWithGame;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Style {
|
public enum Style {
|
||||||
@@ -369,21 +333,20 @@ public class InstallerItem extends Control {
|
|||||||
statusLabel.textProperty().bind(Bindings.createStringBinding(() -> {
|
statusLabel.textProperty().bind(Bindings.createStringBinding(() -> {
|
||||||
State state = control.resolvedStateProperty.get();
|
State state = control.resolvedStateProperty.get();
|
||||||
|
|
||||||
if (state instanceof InstalledState) {
|
if (state instanceof InstalledState installedState) {
|
||||||
InstalledState s = (InstalledState) state;
|
if (installedState.incompatibleWithGame) {
|
||||||
if (s.incompatibleWithGame) {
|
return i18n("install.installer.change_version", installedState.version);
|
||||||
return i18n("install.installer.change_version", s.version);
|
|
||||||
}
|
}
|
||||||
if (s.external) {
|
if (installedState.external) {
|
||||||
return i18n("install.installer.external_version", s.version);
|
return i18n("install.installer.external_version", installedState.version);
|
||||||
}
|
}
|
||||||
return i18n("install.installer.version", s.version);
|
return i18n("install.installer.version", installedState.version);
|
||||||
} else if (state instanceof InstallableState) {
|
} else if (state instanceof InstallableState) {
|
||||||
return control.style == Style.CARD
|
return control.style == Style.CARD
|
||||||
? i18n("install.installer.do_not_install")
|
? i18n("install.installer.do_not_install")
|
||||||
: i18n("install.installer.not_installed");
|
: i18n("install.installer.not_installed");
|
||||||
} else if (state instanceof IncompatibleState) {
|
} else if (state instanceof IncompatibleState incompatibleState) {
|
||||||
return i18n("install.installer.incompatible", i18n("install.installer." + ((IncompatibleState) state).incompatibleItemName));
|
return i18n("install.installer.incompatible", i18n("install.installer." + incompatibleState.incompatibleItemName));
|
||||||
} else {
|
} else {
|
||||||
throw new AssertionError("Unknown state type: " + state.getClass());
|
throw new AssertionError("Unknown state type: " + state.getClass());
|
||||||
}
|
}
|
||||||
@@ -404,7 +367,7 @@ public class InstallerItem extends Control {
|
|||||||
} else {
|
} else {
|
||||||
removeButton.visibleProperty().bind(Bindings.createBooleanBinding(() -> {
|
removeButton.visibleProperty().bind(Bindings.createBooleanBinding(() -> {
|
||||||
State state = control.resolvedStateProperty.get();
|
State state = control.resolvedStateProperty.get();
|
||||||
return state instanceof InstalledState && !((InstalledState) state).external;
|
return state instanceof InstalledState installedState && !installedState.external;
|
||||||
}, control.resolvedStateProperty));
|
}, control.resolvedStateProperty));
|
||||||
}
|
}
|
||||||
removeButton.managedProperty().bind(removeButton.visibleProperty());
|
removeButton.managedProperty().bind(removeButton.visibleProperty());
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class InstallersPage extends AbstractInstallersPage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return group.getGame().versionProperty().get().getVersion();
|
return group.getGame().versionProperty().get().version();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getVersion(String id) {
|
private String getVersion(String id) {
|
||||||
@@ -111,7 +111,7 @@ public class InstallersPage extends AbstractInstallersPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setTxtNameWithLoaders() {
|
private void setTxtNameWithLoaders() {
|
||||||
StringBuilder nameBuilder = new StringBuilder(group.getGame().versionProperty().get().getVersion());
|
StringBuilder nameBuilder = new StringBuilder(group.getGame().versionProperty().get().version());
|
||||||
|
|
||||||
for (InstallerItem library : group.getLibraries()) {
|
for (InstallerItem library : group.getLibraries()) {
|
||||||
String libraryId = library.getLibraryId().replace(LibraryAnalyzer.LibraryType.MINECRAFT.getPatchId(), "");
|
String libraryId = library.getLibraryId().replace(LibraryAnalyzer.LibraryType.MINECRAFT.getPatchId(), "");
|
||||||
|
|||||||
Reference in New Issue
Block a user