Remove unused code

This commit is contained in:
yushijinhun 2019-02-23 23:48:23 +08:00
parent e5587418c7
commit 84fbca7905
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
24 changed files with 145 additions and 564 deletions

View File

@ -20,9 +20,6 @@ package org.jackhuang.hmcl.game;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import org.jackhuang.hmcl.event.EventBus;
import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
import org.jackhuang.hmcl.event.RefreshingVersionsEvent;
import org.jackhuang.hmcl.setting.EnumGameDirectory; import org.jackhuang.hmcl.setting.EnumGameDirectory;
import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.VersionSetting; import org.jackhuang.hmcl.setting.VersionSetting;

View File

@ -38,7 +38,7 @@ import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.DialogController; import org.jackhuang.hmcl.ui.DialogController;
import org.jackhuang.hmcl.ui.LogWindow; import org.jackhuang.hmcl.ui.LogWindow;
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent; import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane; import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane;
import org.jackhuang.hmcl.util.Log4jLevel; import org.jackhuang.hmcl.util.Log4jLevel;
import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.Logging;
@ -236,7 +236,7 @@ public final class LauncherHelper {
} }
Controllers.dialog(message, Controllers.dialog(message,
scriptFile == null ? i18n("launch.failed") : i18n("version.launch_script.failed"), scriptFile == null ? i18n("launch.failed") : i18n("version.launch_script.failed"),
MessageBox.ERROR_MESSAGE); MessageType.ERROR);
} }
} }
}); });
@ -263,7 +263,7 @@ public final class LauncherHelper {
VersionNumber gameVersion = VersionNumber.asVersion(GameVersion.minecraftVersion(profile.getRepository().getVersionJar(version)).orElse("Unknown")); VersionNumber gameVersion = VersionNumber.asVersion(GameVersion.minecraftVersion(profile.getRepository().getVersionJar(version)).orElse("Unknown"));
JavaVersion java = setting.getJavaVersion(); JavaVersion java = setting.getJavaVersion();
if (java == null) { if (java == null) {
Controllers.dialog(i18n("launch.wrong_javadir"), i18n("message.warning"), MessageBox.WARNING_MESSAGE, onAccept); Controllers.dialog(i18n("launch.wrong_javadir"), i18n("message.warning"), MessageType.WARNING, onAccept);
setting.setJava(null); setting.setJava(null);
setting.setDefaultJavaPath(null); setting.setDefaultJavaPath(null);
java = JavaVersion.fromCurrentEnvironment(); java = JavaVersion.fromCurrentEnvironment();
@ -282,10 +282,10 @@ public final class LauncherHelper {
if (gameVersion.compareTo(VersionNumber.asVersion("1.13")) >= 0) { if (gameVersion.compareTo(VersionNumber.asVersion("1.13")) >= 0) {
// Minecraft 1.13 and later versions only support Java 8 or later. // Minecraft 1.13 and later versions only support Java 8 or later.
// Terminate launching operation. // Terminate launching operation.
Controllers.dialog(i18n("launch.advice.java8_1_13"), i18n("message.error"), MessageBox.ERROR_MESSAGE, null); Controllers.dialog(i18n("launch.advice.java8_1_13"), i18n("message.error"), MessageType.ERROR, null);
} else { } else {
// Most mods require Java 8 or later version. // Most mods require Java 8 or later version.
Controllers.dialog(i18n("launch.advice.newer_java"), i18n("message.warning"), MessageBox.WARNING_MESSAGE, onAccept); Controllers.dialog(i18n("launch.advice.newer_java"), i18n("message.warning"), MessageType.WARNING, onAccept);
} }
flag = true; flag = true;
} }
@ -301,10 +301,10 @@ public final class LauncherHelper {
if (java8.isPresent()) { if (java8.isPresent()) {
java8required = true; java8required = true;
setting.setJavaVersion(java8.get()); setting.setJavaVersion(java8.get());
Controllers.dialog(i18n("launch.advice.java9") + "\n" + i18n("launch.advice.corrected"), i18n("message.info"), MessageBox.INFORMATION_MESSAGE, onAccept); Controllers.dialog(i18n("launch.advice.java9") + "\n" + i18n("launch.advice.corrected"), i18n("message.info"), MessageType.INFORMATION, onAccept);
flag = true; flag = true;
} else { } else {
Controllers.dialog(i18n("launch.advice.java9") + "\n" + i18n("launch.advice.uncorrected"), i18n("message.error"), MessageBox.ERROR_MESSAGE, null); Controllers.dialog(i18n("launch.advice.java9") + "\n" + i18n("launch.advice.uncorrected"), i18n("message.error"), MessageType.ERROR, null);
flag = true; flag = true;
} }
} }
@ -319,7 +319,7 @@ public final class LauncherHelper {
newJavaRequired = true; newJavaRequired = true;
setting.setJavaVersion(java8.get()); setting.setJavaVersion(java8.get());
} else { } else {
Controllers.dialog(i18n("launch.advice.java8_51_1_13"), i18n("message.warning"), MessageBox.WARNING_MESSAGE, onAccept); Controllers.dialog(i18n("launch.advice.java8_51_1_13"), i18n("message.warning"), MessageType.WARNING, onAccept);
flag = true; flag = true;
} }
} }
@ -351,7 +351,7 @@ public final class LauncherHelper {
if (java64.isPresent()) { if (java64.isPresent()) {
setting.setJavaVersion(java64.get()); setting.setJavaVersion(java64.get());
} else { } else {
Controllers.dialog(i18n("launch.advice.different_platform"), i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); Controllers.dialog(i18n("launch.advice.different_platform"), i18n("message.error"), MessageType.ERROR, onAccept);
flag = true; flag = true;
} }
} }
@ -361,13 +361,13 @@ public final class LauncherHelper {
setting.getMaxMemory() > 1.5 * 1024) { setting.getMaxMemory() > 1.5 * 1024) {
// 1.5 * 1024 is an inaccurate number. // 1.5 * 1024 is an inaccurate number.
// Actual memory limit depends on operating system and memory. // Actual memory limit depends on operating system and memory.
Controllers.dialog(i18n("launch.advice.too_large_memory_for_32bit"), i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); Controllers.dialog(i18n("launch.advice.too_large_memory_for_32bit"), i18n("message.error"), MessageType.ERROR, onAccept);
flag = true; flag = true;
} }
// Cannot allocate too much memory exceeding free space. // Cannot allocate too much memory exceeding free space.
if (!flag && OperatingSystem.TOTAL_MEMORY > 0 && OperatingSystem.TOTAL_MEMORY < setting.getMaxMemory()) { if (!flag && OperatingSystem.TOTAL_MEMORY > 0 && OperatingSystem.TOTAL_MEMORY < setting.getMaxMemory()) {
Controllers.dialog(i18n("launch.advice.not_enough_space", OperatingSystem.TOTAL_MEMORY), i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); Controllers.dialog(i18n("launch.advice.not_enough_space", OperatingSystem.TOTAL_MEMORY), i18n("message.error"), MessageType.ERROR, onAccept);
flag = true; flag = true;
} }
@ -379,7 +379,7 @@ public final class LauncherHelper {
VersionNumber.VERSION_COMPARATOR.compare(it.getVersion(), "1.12.2-14.23.5.2773") < 0); VersionNumber.VERSION_COMPARATOR.compare(it.getVersion(), "1.12.2-14.23.5.2773") < 0);
boolean hasLiteLoader = version.getLibraries().stream().anyMatch(it -> it.is("com.mumfrey", "liteloader")); boolean hasLiteLoader = version.getLibraries().stream().anyMatch(it -> it.is("com.mumfrey", "liteloader"));
if (hasForge2760 && hasLiteLoader && gameVersion.compareTo(VersionNumber.asVersion("1.12.2")) == 0) { if (hasForge2760 && hasLiteLoader && gameVersion.compareTo(VersionNumber.asVersion("1.12.2")) == 0) {
Controllers.dialog(i18n("launch.advice.forge2760_liteloader"), i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); Controllers.dialog(i18n("launch.advice.forge2760_liteloader"), i18n("message.error"), MessageType.ERROR, onAccept);
flag = true; flag = true;
} }
} }

View File

@ -33,8 +33,6 @@ import org.jackhuang.hmcl.game.HMCLGameRepository;
import org.jackhuang.hmcl.game.Version; import org.jackhuang.hmcl.game.Version;
import org.jackhuang.hmcl.ui.WeakListenerHolder; import org.jackhuang.hmcl.ui.WeakListenerHolder;
import org.jackhuang.hmcl.util.*; import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.javafx.ImmediateObjectProperty;
import org.jackhuang.hmcl.util.javafx.ImmediateStringProperty;
import org.jackhuang.hmcl.util.javafx.ObservableHelper; import org.jackhuang.hmcl.util.javafx.ObservableHelper;
import java.io.File; import java.io.File;
@ -90,9 +88,9 @@ public final class Profile implements Observable {
return global.get(); return global.get();
} }
private final ImmediateStringProperty name; private final SimpleStringProperty name;
public ImmediateStringProperty nameProperty() { public StringProperty nameProperty() {
return name; return name;
} }
@ -131,8 +129,8 @@ public final class Profile implements Observable {
} }
public Profile(String name, File initialGameDir, VersionSetting global, String selectedVersion, boolean useRelativePath) { public Profile(String name, File initialGameDir, VersionSetting global, String selectedVersion, boolean useRelativePath) {
this.name = new ImmediateStringProperty(this, "name", name); this.name = new SimpleStringProperty(this, "name", name);
gameDir = new ImmediateObjectProperty<>(this, "gameDir", initialGameDir); gameDir = new SimpleObjectProperty<>(this, "gameDir", initialGameDir);
repository = new HMCLGameRepository(this, initialGameDir); repository = new HMCLGameRepository(this, initialGameDir);
this.global.set(global == null ? new VersionSetting() : global); this.global.set(global == null ? new VersionSetting() : global);
this.selectedVersion.set(selectedVersion); this.selectedVersion.set(selectedVersion);

View File

@ -21,13 +21,18 @@ import com.google.gson.*;
import com.google.gson.annotations.JsonAdapter; import com.google.gson.annotations.JsonAdapter;
import javafx.beans.InvalidationListener; import javafx.beans.InvalidationListener;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.game.LaunchOptions; import org.jackhuang.hmcl.game.LaunchOptions;
import org.jackhuang.hmcl.util.*; import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.javafx.ImmediateBooleanProperty;
import org.jackhuang.hmcl.util.javafx.ImmediateIntegerProperty;
import org.jackhuang.hmcl.util.javafx.ImmediateObjectProperty;
import org.jackhuang.hmcl.util.javafx.ImmediateStringProperty;
import org.jackhuang.hmcl.util.platform.JavaVersion; import org.jackhuang.hmcl.util.platform.JavaVersion;
import org.jackhuang.hmcl.util.platform.OperatingSystem; import org.jackhuang.hmcl.util.platform.OperatingSystem;
@ -60,9 +65,9 @@ public final class VersionSetting {
this.global = global; this.global = global;
} }
private final ImmediateBooleanProperty usesGlobalProperty = new ImmediateBooleanProperty(this, "usesGlobal", false); private final BooleanProperty usesGlobalProperty = new SimpleBooleanProperty(this, "usesGlobal", false);
public ImmediateBooleanProperty usesGlobalProperty() { public BooleanProperty usesGlobalProperty() {
return usesGlobalProperty; return usesGlobalProperty;
} }
@ -84,9 +89,9 @@ public final class VersionSetting {
// java // java
private final ImmediateStringProperty javaProperty = new ImmediateStringProperty(this, "java", ""); private final StringProperty javaProperty = new SimpleStringProperty(this, "java", "");
public ImmediateStringProperty javaProperty() { public StringProperty javaProperty() {
return javaProperty; return javaProperty;
} }
@ -110,7 +115,7 @@ public final class VersionSetting {
setDefaultJavaPath(null); setDefaultJavaPath(null);
} }
private final ImmediateStringProperty defaultJavaPathProperty = new ImmediateStringProperty(this, "defaultJavaPath", ""); private final StringProperty defaultJavaPathProperty = new SimpleStringProperty(this, "defaultJavaPath", "");
/** /**
* Path to Java executable, or null if user customizes java directory. * Path to Java executable, or null if user customizes java directory.
@ -124,9 +129,9 @@ public final class VersionSetting {
defaultJavaPathProperty.set(defaultJavaPath); defaultJavaPathProperty.set(defaultJavaPath);
} }
private final ImmediateStringProperty javaDirProperty = new ImmediateStringProperty(this, "javaDir", ""); private final StringProperty javaDirProperty = new SimpleStringProperty(this, "javaDir", "");
public ImmediateStringProperty javaDirProperty() { public StringProperty javaDirProperty() {
return javaDirProperty; return javaDirProperty;
} }
@ -141,9 +146,9 @@ public final class VersionSetting {
javaDirProperty.set(javaDir); javaDirProperty.set(javaDir);
} }
private final ImmediateStringProperty wrapperProperty = new ImmediateStringProperty(this, "wrapper", ""); private final StringProperty wrapperProperty = new SimpleStringProperty(this, "wrapper", "");
public ImmediateStringProperty wrapperProperty() { public StringProperty wrapperProperty() {
return wrapperProperty; return wrapperProperty;
} }
@ -158,9 +163,9 @@ public final class VersionSetting {
wrapperProperty.set(wrapper); wrapperProperty.set(wrapper);
} }
private final ImmediateStringProperty permSizeProperty = new ImmediateStringProperty(this, "permSize", ""); private final StringProperty permSizeProperty = new SimpleStringProperty(this, "permSize", "");
public ImmediateStringProperty permSizeProperty() { public StringProperty permSizeProperty() {
return permSizeProperty; return permSizeProperty;
} }
@ -175,9 +180,9 @@ public final class VersionSetting {
permSizeProperty.set(permSize); permSizeProperty.set(permSize);
} }
private final ImmediateIntegerProperty maxMemoryProperty = new ImmediateIntegerProperty(this, "maxMemory", OperatingSystem.SUGGESTED_MEMORY); private final IntegerProperty maxMemoryProperty = new SimpleIntegerProperty(this, "maxMemory", OperatingSystem.SUGGESTED_MEMORY);
public ImmediateIntegerProperty maxMemoryProperty() { public IntegerProperty maxMemoryProperty() {
return maxMemoryProperty; return maxMemoryProperty;
} }
@ -195,9 +200,9 @@ public final class VersionSetting {
/** /**
* The minimum memory that JVM can allocate for heap. * The minimum memory that JVM can allocate for heap.
*/ */
private final ImmediateObjectProperty<Integer> minMemoryProperty = new ImmediateObjectProperty<>(this, "minMemory", null); private final ObjectProperty<Integer> minMemoryProperty = new SimpleObjectProperty<>(this, "minMemory", null);
public ImmediateObjectProperty<Integer> minMemoryProperty() { public ObjectProperty<Integer> minMemoryProperty() {
return minMemoryProperty; return minMemoryProperty;
} }
@ -209,9 +214,9 @@ public final class VersionSetting {
minMemoryProperty.set(minMemory); minMemoryProperty.set(minMemory);
} }
private final ImmediateStringProperty preLaunchCommandProperty = new ImmediateStringProperty(this, "precalledCommand", ""); private final StringProperty preLaunchCommandProperty = new SimpleStringProperty(this, "precalledCommand", "");
public ImmediateStringProperty preLaunchCommandProperty() { public StringProperty preLaunchCommandProperty() {
return preLaunchCommandProperty; return preLaunchCommandProperty;
} }
@ -229,9 +234,9 @@ public final class VersionSetting {
// options // options
private final ImmediateStringProperty javaArgsProperty = new ImmediateStringProperty(this, "javaArgs", ""); private final StringProperty javaArgsProperty = new SimpleStringProperty(this, "javaArgs", "");
public ImmediateStringProperty javaArgsProperty() { public StringProperty javaArgsProperty() {
return javaArgsProperty; return javaArgsProperty;
} }
@ -246,9 +251,9 @@ public final class VersionSetting {
javaArgsProperty.set(javaArgs); javaArgsProperty.set(javaArgs);
} }
private final ImmediateStringProperty minecraftArgsProperty = new ImmediateStringProperty(this, "minecraftArgs", ""); private final StringProperty minecraftArgsProperty = new SimpleStringProperty(this, "minecraftArgs", "");
public ImmediateStringProperty minecraftArgsProperty() { public StringProperty minecraftArgsProperty() {
return minecraftArgsProperty; return minecraftArgsProperty;
} }
@ -263,9 +268,9 @@ public final class VersionSetting {
minecraftArgsProperty.set(minecraftArgs); minecraftArgsProperty.set(minecraftArgs);
} }
private final ImmediateBooleanProperty noJVMArgsProperty = new ImmediateBooleanProperty(this, "noJVMArgs", false); private final BooleanProperty noJVMArgsProperty = new SimpleBooleanProperty(this, "noJVMArgs", false);
public ImmediateBooleanProperty noJVMArgsProperty() { public BooleanProperty noJVMArgsProperty() {
return noJVMArgsProperty; return noJVMArgsProperty;
} }
@ -280,9 +285,9 @@ public final class VersionSetting {
noJVMArgsProperty.set(noJVMArgs); noJVMArgsProperty.set(noJVMArgs);
} }
private final ImmediateBooleanProperty notCheckJVMProperty = new ImmediateBooleanProperty(this, "notCheckJVM", false); private final BooleanProperty notCheckJVMProperty = new SimpleBooleanProperty(this, "notCheckJVM", false);
public ImmediateBooleanProperty notCheckJVMProperty() { public BooleanProperty notCheckJVMProperty() {
return notCheckJVMProperty; return notCheckJVMProperty;
} }
@ -297,9 +302,9 @@ public final class VersionSetting {
notCheckJVMProperty.set(notCheckJVM); notCheckJVMProperty.set(notCheckJVM);
} }
private final ImmediateBooleanProperty notCheckGameProperty = new ImmediateBooleanProperty(this, "notCheckGame", false); private final BooleanProperty notCheckGameProperty = new SimpleBooleanProperty(this, "notCheckGame", false);
public ImmediateBooleanProperty notCheckGameProperty() { public BooleanProperty notCheckGameProperty() {
return notCheckGameProperty; return notCheckGameProperty;
} }
@ -314,9 +319,9 @@ public final class VersionSetting {
notCheckGameProperty.set(notCheckGame); notCheckGameProperty.set(notCheckGame);
} }
private final ImmediateBooleanProperty showLogsProperty = new ImmediateBooleanProperty(this, "showLogs", false); private final BooleanProperty showLogsProperty = new SimpleBooleanProperty(this, "showLogs", false);
public ImmediateBooleanProperty showLogsProperty() { public BooleanProperty showLogsProperty() {
return showLogsProperty; return showLogsProperty;
} }
@ -333,14 +338,14 @@ public final class VersionSetting {
// Minecraft settings. // Minecraft settings.
private final ImmediateStringProperty serverIpProperty = new ImmediateStringProperty(this, "serverIp", ""); private final StringProperty serverIpProperty = new SimpleStringProperty(this, "serverIp", "");
public ImmediateStringProperty serverIpProperty() { public StringProperty serverIpProperty() {
return serverIpProperty; return serverIpProperty;
} }
/** /**
* The server ip that will be entered after Minecraft successfully loaded immediately. * The server ip that will be entered after Minecraft successfully loaded ly.
* *
* Format: ip:port or without port. * Format: ip:port or without port.
*/ */
@ -353,9 +358,9 @@ public final class VersionSetting {
} }
private final ImmediateBooleanProperty fullscreenProperty = new ImmediateBooleanProperty(this, "fullscreen", false); private final BooleanProperty fullscreenProperty = new SimpleBooleanProperty(this, "fullscreen", false);
public ImmediateBooleanProperty fullscreenProperty() { public BooleanProperty fullscreenProperty() {
return fullscreenProperty; return fullscreenProperty;
} }
@ -370,9 +375,9 @@ public final class VersionSetting {
fullscreenProperty.set(fullscreen); fullscreenProperty.set(fullscreen);
} }
private final ImmediateIntegerProperty widthProperty = new ImmediateIntegerProperty(this, "width", 854); private final IntegerProperty widthProperty = new SimpleIntegerProperty(this, "width", 854);
public ImmediateIntegerProperty widthProperty() { public IntegerProperty widthProperty() {
return widthProperty; return widthProperty;
} }
@ -392,9 +397,9 @@ public final class VersionSetting {
} }
private final ImmediateIntegerProperty heightProperty = new ImmediateIntegerProperty(this, "height", 480); private final IntegerProperty heightProperty = new SimpleIntegerProperty(this, "height", 480);
public ImmediateIntegerProperty heightProperty() { public IntegerProperty heightProperty() {
return heightProperty; return heightProperty;
} }
@ -417,9 +422,9 @@ public final class VersionSetting {
* 0 - .minecraft<br/> * 0 - .minecraft<br/>
* 1 - .minecraft/versions/&lt;version&gt;/<br/> * 1 - .minecraft/versions/&lt;version&gt;/<br/>
*/ */
private final ImmediateObjectProperty<EnumGameDirectory> gameDirTypeProperty = new ImmediateObjectProperty<>(this, "gameDirType", EnumGameDirectory.ROOT_FOLDER); private final ObjectProperty<EnumGameDirectory> gameDirTypeProperty = new SimpleObjectProperty<>(this, "gameDirType", EnumGameDirectory.ROOT_FOLDER);
public ImmediateObjectProperty<EnumGameDirectory> gameDirTypeProperty() { public ObjectProperty<EnumGameDirectory> gameDirTypeProperty() {
return gameDirTypeProperty; return gameDirTypeProperty;
} }
@ -434,9 +439,9 @@ public final class VersionSetting {
/** /**
* Your custom gameDir * Your custom gameDir
*/ */
private final ImmediateStringProperty gameDirProperty = new ImmediateStringProperty(this, "gameDir", ""); private final StringProperty gameDirProperty = new SimpleStringProperty(this, "gameDir", "");
public ImmediateStringProperty gameDirProperty() { public StringProperty gameDirProperty() {
return gameDirProperty; return gameDirProperty;
} }
@ -455,9 +460,9 @@ public final class VersionSetting {
* 1 - Hide the launcher when the game starts.<br/> * 1 - Hide the launcher when the game starts.<br/>
* 2 - Keep the launcher open.<br/> * 2 - Keep the launcher open.<br/>
*/ */
private final ImmediateObjectProperty<LauncherVisibility> launcherVisibilityProperty = new ImmediateObjectProperty<>(this, "launcherVisibility", LauncherVisibility.HIDE); private final ObjectProperty<LauncherVisibility> launcherVisibilityProperty = new SimpleObjectProperty<>(this, "launcherVisibility", LauncherVisibility.HIDE);
public ImmediateObjectProperty<LauncherVisibility> launcherVisibilityProperty() { public ObjectProperty<LauncherVisibility> launcherVisibilityProperty() {
return launcherVisibilityProperty; return launcherVisibilityProperty;
} }

View File

@ -35,6 +35,7 @@ import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.ui.account.AccountList; import org.jackhuang.hmcl.ui.account.AccountList;
import org.jackhuang.hmcl.ui.account.AuthlibInjectorServersPage; import org.jackhuang.hmcl.ui.account.AuthlibInjectorServersPage;
import org.jackhuang.hmcl.ui.construct.*; import org.jackhuang.hmcl.ui.construct.*;
import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.ui.decorator.DecoratorController; import org.jackhuang.hmcl.ui.decorator.DecoratorController;
import org.jackhuang.hmcl.ui.download.ModpackInstallWizardProvider; import org.jackhuang.hmcl.ui.download.ModpackInstallWizardProvider;
import org.jackhuang.hmcl.ui.profile.ProfileList; import org.jackhuang.hmcl.ui.profile.ProfileList;
@ -223,14 +224,14 @@ public final class Controllers {
} }
public static void dialog(String text, String title) { public static void dialog(String text, String title) {
dialog(text, title, MessageBox.INFORMATION_MESSAGE); dialog(text, title, MessageType.INFORMATION);
} }
public static void dialog(String text, String title, int type) { public static void dialog(String text, String title, MessageType type) {
dialog(text, title, type, null); dialog(text, title, type, null);
} }
public static void dialog(String text, String title, int type, Runnable onAccept) { public static void dialog(String text, String title, MessageType type, Runnable onAccept) {
dialog(new MessageDialogPane(text, title, type, onAccept)); dialog(new MessageDialogPane(text, title, type, onAccept));
} }

View File

@ -201,11 +201,11 @@ public final class LogWindow extends Stage {
if (!flag) if (!flag)
cboLines.getSelectionModel().select(0); cboLines.getSelectionModel().select(0);
btnFatals.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(fatal.get()) + " fatals", fatal)); btnFatals.textProperty().bind(Bindings.concat(fatal, " fatals"));
btnErrors.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(error.get()) + " errors", error)); btnErrors.textProperty().bind(Bindings.concat(error, " errors"));
btnWarns.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(warn.get()) + " warns", warn)); btnWarns.textProperty().bind(Bindings.concat(warn, " warns"));
btnInfos.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(info.get()) + " infos", info)); btnInfos.textProperty().bind(Bindings.concat(info, " infos"));
btnDebugs.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(debug.get()) + " debugs", debug)); btnDebugs.textProperty().bind(Bindings.concat(debug, " debugs"));
btnFatals.selectedProperty().addListener(o -> specificChanged()); btnFatals.selectedProperty().addListener(o -> specificChanged());
btnErrors.selectedProperty().addListener(o -> specificChanged()); btnErrors.selectedProperty().addListener(o -> specificChanged());

View File

@ -31,7 +31,7 @@ import javafx.scene.paint.Color;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.setting.*; import org.jackhuang.hmcl.setting.*;
import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.ui.construct.Validator; import org.jackhuang.hmcl.ui.construct.Validator;
import org.jackhuang.hmcl.ui.decorator.DecoratorPage; import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
import org.jackhuang.hmcl.upgrade.RemoteVersion; import org.jackhuang.hmcl.upgrade.RemoteVersion;
@ -228,7 +228,7 @@ public final class SettingsPage extends SettingsView implements DecoratorPage {
try { try {
Files.write(logFile, Logging.getRawLogs()); Files.write(logFile, Logging.getRawLogs());
} catch (IOException e) { } catch (IOException e) {
Platform.runLater(() -> Controllers.dialog(i18n("settings.launcher.launcher_log.export.failed") + "\n" + e, null, MessageBox.ERROR_MESSAGE)); Platform.runLater(() -> Controllers.dialog(i18n("settings.launcher.launcher_log.export.failed") + "\n" + e, null, MessageType.ERROR));
LOG.log(Level.WARNING, "Failed to export logs", e); LOG.log(Level.WARNING, "Failed to export logs", e);
return; return;
} }

View File

@ -1,172 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.ui.construct;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TextInputDialog;
import org.jackhuang.hmcl.ui.FXUtils;
import javax.swing.*;
import java.util.Optional;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public final class MessageBox {
private MessageBox() {
}
private static final String TITLE = i18n("message.info");
/**
* User Operation: Yes
*/
public static final int YES_OPTION = 0;
/**
* User Operation: No
*/
public static final int NO_OPTION = 1;
/**
* User Operation: Cancel
*/
public static final int CANCEL_OPTION = 2;
/**
* User Operation: OK
*/
public static final int OK_OPTION = 0;
/**
* User Operation: Closed Message Box
*/
public static final int CLOSED_OPTION = -1;
/**
* Buttons: Yes No
*/
public static final int YES_NO_OPTION = 10;
/**
* Buttons: Yes No Cancel
*/
public static final int YES_NO_CANCEL_OPTION = 11;
/**
* Buttons: OK Cancel
*/
public static final int OK_CANCEL_OPTION = 12;
/**
* Message Box Type: Error
*/
public static final int ERROR_MESSAGE = 0;
/**
* Message Box Type: Info
*/
public static final int INFORMATION_MESSAGE = 1;
/**
* Message Box Type: Warning
*/
public static final int WARNING_MESSAGE = 2;
/**
* Message Box Type: Question
*/
public static final int QUESTION_MESSAGE = 3;
/**
* Message Box Type: Fine
*/
public static final int FINE_MESSAGE = 4;
/**
* Message Box Type: Plain
*/
public static final int PLAIN_MESSAGE = -1;
public static void show(String message) {
show(message, TITLE);
}
/**
* Show MsgBox with title and options
*
* @param message The Message
* @param title The title of MsgBox.
* @return user operation.
*/
public static Optional<ButtonType> show(String message, String title) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle(title);
alert.setHeaderText(title);
alert.setContentText(message);
return alert.showAndWait();
}
public static int confirm(String message, String title) {
return confirm(message, title, -1);
}
public static int confirm(String message, int option) {
return confirm(message, TITLE, option);
}
public static int confirm(String message, String title, int option) {
return FXUtils.runInUIThread(() -> {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(title);
alert.setHeaderText(title);
alert.setContentText(message);
switch (option) {
case YES_NO_OPTION:
alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO);
break;
case YES_NO_CANCEL_OPTION:
alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);
break;
case OK_CANCEL_OPTION:
alert.getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL);
break;
default:
throw new IllegalArgumentException("Unrecognized message box option " + option);
}
Optional<ButtonType> buttonType = alert.showAndWait();
if (!buttonType.isPresent()) return CLOSED_OPTION;
else if (buttonType.get() == ButtonType.OK) return OK_OPTION;
else if (buttonType.get() == ButtonType.YES) return YES_OPTION;
else if (buttonType.get() == ButtonType.NO) return NO_OPTION;
else if (buttonType.get() == ButtonType.CANCEL) return CANCEL_OPTION;
else throw new IllegalStateException("Unexpected button type:" + buttonType.get());
});
}
public static Optional<String> input(String message) {
return input(message, UIManager.getString("OptionPane.inputDialogTitle"));
}
public static Optional<String> input(String message, String title) {
return input(message, title, "");
}
public static Optional<String> input(String message, String title, String initialValue) {
TextInputDialog dialog = new TextInputDialog(initialValue);
dialog.setTitle(title);
dialog.setHeaderText(message);
dialog.setContentText(message);
return dialog.showAndWait();
}
}

View File

@ -32,6 +32,15 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public final class MessageDialogPane extends StackPane { public final class MessageDialogPane extends StackPane {
public static enum MessageType {
ERROR,
INFORMATION,
WARNING,
QUESTION,
FINE,
PLAIN,
}
@FXML @FXML
private JFXButton acceptButton; private JFXButton acceptButton;
@FXML @FXML
@ -45,7 +54,7 @@ public final class MessageDialogPane extends StackPane {
@FXML @FXML
private HBox actions; private HBox actions;
public MessageDialogPane(String text, String title, int type, Runnable onAccept) { public MessageDialogPane(String text, String title, MessageType type, Runnable onAccept) {
FXUtils.loadFXML(this, "/assets/fxml/message-dialog.fxml"); FXUtils.loadFXML(this, "/assets/fxml/message-dialog.fxml");
if (title != null) if (title != null)
@ -60,19 +69,19 @@ public final class MessageDialogPane extends StackPane {
actions.getChildren().remove(cancelButton); actions.getChildren().remove(cancelButton);
switch (type) { switch (type) {
case MessageBox.INFORMATION_MESSAGE: case INFORMATION:
graphic.setGraphic(SVG.infoCircle(Theme.blackFillBinding(), 40, 40)); graphic.setGraphic(SVG.infoCircle(Theme.blackFillBinding(), 40, 40));
break; break;
case MessageBox.ERROR_MESSAGE: case ERROR:
graphic.setGraphic(SVG.closeCircle(Theme.blackFillBinding(), 40, 40)); graphic.setGraphic(SVG.closeCircle(Theme.blackFillBinding(), 40, 40));
break; break;
case MessageBox.FINE_MESSAGE: case FINE:
graphic.setGraphic(SVG.checkCircle(Theme.blackFillBinding(), 40, 40)); graphic.setGraphic(SVG.checkCircle(Theme.blackFillBinding(), 40, 40));
break; break;
case MessageBox.WARNING_MESSAGE: case WARNING:
graphic.setGraphic(SVG.alert(Theme.blackFillBinding(), 40, 40)); graphic.setGraphic(SVG.alert(Theme.blackFillBinding(), 40, 40));
break; break;
case MessageBox.QUESTION_MESSAGE: case QUESTION:
graphic.setGraphic(SVG.helpCircle(Theme.blackFillBinding(), 40, 40)); graphic.setGraphic(SVG.helpCircle(Theme.blackFillBinding(), 40, 40));
break; break;
default: default:
@ -81,7 +90,7 @@ public final class MessageDialogPane extends StackPane {
} }
public MessageDialogPane(String text, String title, Runnable onAccept, Runnable onCancel) { public MessageDialogPane(String text, String title, Runnable onAccept, Runnable onCancel) {
this(text, title, MessageBox.QUESTION_MESSAGE, onAccept); this(text, title, MessageType.QUESTION, onAccept);
cancelButton.setVisible(true); cancelButton.setVisible(true);
cancelButton.setOnMouseClicked(e -> { cancelButton.setOnMouseClicked(e -> {

View File

@ -28,7 +28,7 @@ import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.task.DownloadException; import org.jackhuang.hmcl.task.DownloadException;
import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardController;
import org.jackhuang.hmcl.ui.wizard.WizardProvider; import org.jackhuang.hmcl.ui.wizard.WizardProvider;
import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.StringUtils;
@ -121,11 +121,11 @@ public final class InstallerWizardProvider implements WizardProvider {
public static void alertFailureMessage(Exception exception, Runnable next) { public static void alertFailureMessage(Exception exception, Runnable next) {
if (exception instanceof LibraryDownloadException) { if (exception instanceof LibraryDownloadException) {
Controllers.dialog(i18n("launch.failed.download_library", ((LibraryDownloadException) exception).getLibrary().getName()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageBox.ERROR_MESSAGE, next); Controllers.dialog(i18n("launch.failed.download_library", ((LibraryDownloadException) exception).getLibrary().getName()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next);
} else if (exception instanceof DownloadException) { } else if (exception instanceof DownloadException) {
Controllers.dialog(i18n("install.failed.downloading.detail", ((DownloadException) exception).getUrl()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageBox.ERROR_MESSAGE, next); Controllers.dialog(i18n("install.failed.downloading.detail", ((DownloadException) exception).getUrl()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next);
} else { } else {
Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed"), MessageBox.ERROR_MESSAGE, next); Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed"), MessageType.ERROR, next);
} }
} }
} }

View File

@ -27,7 +27,7 @@ import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardController;
import org.jackhuang.hmcl.ui.wizard.WizardProvider; import org.jackhuang.hmcl.ui.wizard.WizardProvider;
@ -84,11 +84,11 @@ public class ModpackInstallWizardProvider implements WizardProvider {
try { try {
return ModpackHelper.getUpdateTask(profile, selected, modpack.getEncoding(), name, ModpackHelper.readModpackConfiguration(profile.getRepository().getModpackConfiguration(name))); return ModpackHelper.getUpdateTask(profile, selected, modpack.getEncoding(), name, ModpackHelper.readModpackConfiguration(profile.getRepository().getModpackConfiguration(name)));
} catch (UnsupportedModpackException e) { } catch (UnsupportedModpackException e) {
Controllers.dialog(i18n("modpack.unsupported"), i18n("message.error"), MessageBox.ERROR_MESSAGE); Controllers.dialog(i18n("modpack.unsupported"), i18n("message.error"), MessageType.ERROR);
} catch (MismatchedModpackTypeException e) { } catch (MismatchedModpackTypeException e) {
Controllers.dialog(i18n("modpack.mismatched_type"), i18n("message.error"), MessageBox.ERROR_MESSAGE); Controllers.dialog(i18n("modpack.mismatched_type"), i18n("message.error"), MessageType.ERROR);
} catch (IOException e) { } catch (IOException e) {
Controllers.dialog(i18n("modpack.invalid"), i18n("message.error"), MessageBox.ERROR_MESSAGE); Controllers.dialog(i18n("modpack.invalid"), i18n("message.error"), MessageType.ERROR);
} }
return null; return null;
} else { } else {
@ -105,9 +105,9 @@ public class ModpackInstallWizardProvider implements WizardProvider {
public void onFail(Map<String, Object> settings, Exception exception, Runnable next) { public void onFail(Map<String, Object> settings, Exception exception, Runnable next) {
if (exception instanceof CurseCompletionException) { if (exception instanceof CurseCompletionException) {
if (exception.getCause() instanceof FileNotFoundException) { if (exception.getCause() instanceof FileNotFoundException) {
Controllers.dialog(i18n("modpack.type.curse.not_found"), i18n("install.failed"), MessageBox.ERROR_MESSAGE, next); Controllers.dialog(i18n("modpack.type.curse.not_found"), i18n("install.failed"), MessageType.ERROR, next);
} else { } else {
Controllers.dialog(i18n("modpack.type.curse.tolerable_error"), i18n("install.success"), MessageBox.INFORMATION_MESSAGE, next); Controllers.dialog(i18n("modpack.type.curse.tolerable_error"), i18n("install.success"), MessageType.INFORMATION, next);
} }
} else { } else {
InstallerWizardProvider.alertFailureMessage(exception, next); InstallerWizardProvider.alertFailureMessage(exception, next);

View File

@ -33,7 +33,7 @@ import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.WebStage; import org.jackhuang.hmcl.ui.WebStage;
import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.ui.construct.SpinnerPane; import org.jackhuang.hmcl.ui.construct.SpinnerPane;
import org.jackhuang.hmcl.ui.construct.Validator; import org.jackhuang.hmcl.ui.construct.Validator;
import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardController;
@ -129,7 +129,7 @@ public final class ModpackPage extends StackPane implements WizardPage {
txtModpackName.textProperty().addListener(e -> btnInstall.setDisable(!txtModpackName.validate())); txtModpackName.textProperty().addListener(e -> btnInstall.setDisable(!txtModpackName.validate()));
} }
}, e -> { }, e -> {
Controllers.dialog(i18n("modpack.task.install.error"), i18n("message.error"), MessageBox.ERROR_MESSAGE); Controllers.dialog(i18n("modpack.task.install.error"), i18n("message.error"), MessageType.ERROR);
Platform.runLater(controller::onEnd); Platform.runLater(controller::onEnd);
}).start(); }).start();
} }

View File

@ -57,7 +57,6 @@ import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -71,7 +70,6 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
private Profile profile; private Profile profile;
private String versionId; private String versionId;
private boolean javaItemsLoaded; private boolean javaItemsLoaded;
private InvalidationListener specificSettingsListener;
@FXML private VBox rootPane; @FXML private VBox rootPane;
@FXML private ScrollPane scroll; @FXML private ScrollPane scroll;
@ -100,6 +98,12 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
@FXML private JFXCheckBox chkEnableSpecificSettings; @FXML private JFXCheckBox chkEnableSpecificSettings;
@FXML private BorderPane settingsTypePane; @FXML private BorderPane settingsTypePane;
private InvalidationListener specificSettingsListener = any -> {
chkEnableSpecificSettings.setSelected(!lastVersionSetting.isUsesGlobal());
};
private InvalidationListener javaListener = any -> initJavaSubtitle();
public VersionSettingsPage() { public VersionSettingsPage() {
FXUtils.loadFXML(this, "/assets/fxml/version/version-settings.fxml"); FXUtils.loadFXML(this, "/assets/fxml/version/version-settings.fxml");
@ -148,10 +152,6 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
Platform.runLater(() -> loadVersion(profile, versionId)); Platform.runLater(() -> loadVersion(profile, versionId));
}); });
specificSettingsListener = o -> {
chkEnableSpecificSettings.setSelected(!lastVersionSetting.isUsesGlobal());
};
componentList.disableProperty().bind(chkEnableSpecificSettings.selectedProperty().not()); componentList.disableProperty().bind(chkEnableSpecificSettings.selectedProperty().not());
advancedSettingsPane.disableProperty().bind(chkEnableSpecificSettings.selectedProperty().not()); advancedSettingsPane.disableProperty().bind(chkEnableSpecificSettings.selectedProperty().not());
} }
@ -193,6 +193,8 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
FXUtils.unbindEnum(cboLauncherVisibility); FXUtils.unbindEnum(cboLauncherVisibility);
lastVersionSetting.usesGlobalProperty().removeListener(specificSettingsListener); lastVersionSetting.usesGlobalProperty().removeListener(specificSettingsListener);
lastVersionSetting.javaDirProperty().removeListener(javaListener);
lastVersionSetting.javaProperty().removeListener(javaListener);
gameDirItem.selectedDataProperty().unbindBidirectional(lastVersionSetting.gameDirTypeProperty()); gameDirItem.selectedDataProperty().unbindBidirectional(lastVersionSetting.gameDirTypeProperty());
gameDirItem.subtitleProperty().unbind(); gameDirItem.subtitleProperty().unbind();
@ -232,9 +234,8 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
} }
}); });
versionSetting.javaDirProperty().setChangedListener(it -> initJavaSubtitle(versionSetting)); versionSetting.javaDirProperty().addListener(javaListener);
versionSetting.javaProperty().setChangedListener(it -> initJavaSubtitle(versionSetting)); versionSetting.javaProperty().addListener(javaListener);
initJavaSubtitle(versionSetting);
gameDirItem.selectedDataProperty().bindBidirectional(versionSetting.gameDirTypeProperty()); gameDirItem.selectedDataProperty().bindBidirectional(versionSetting.gameDirTypeProperty());
gameDirItem.subtitleProperty().bind(Bindings.createStringBinding(() -> Paths.get(profile.getRepository().getRunDirectory(versionId).getAbsolutePath()).normalize().toString(), gameDirItem.subtitleProperty().bind(Bindings.createStringBinding(() -> Paths.get(profile.getRepository().getRunDirectory(versionId).getAbsolutePath()).normalize().toString(),
@ -243,6 +244,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
lastVersionSetting = versionSetting; lastVersionSetting = versionSetting;
initializeSelectedJava(); initializeSelectedJava();
initJavaSubtitle();
loadIcon(); loadIcon();
} }
@ -267,11 +269,14 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
} }
} }
private void initJavaSubtitle(VersionSetting versionSetting) { private void initJavaSubtitle() {
VersionSetting versionSetting = lastVersionSetting;
if (versionSetting == null)
return;
Task.of(variables -> variables.set("java", versionSetting.getJavaVersion())) Task.of(variables -> variables.set("java", versionSetting.getJavaVersion()))
.subscribe(Task.of(Schedulers.javafx(), .subscribe(Task.of(Schedulers.javafx(),
variables -> javaItem.setSubtitle(variables.<JavaVersion>getOptional("java") variables -> javaItem.setSubtitle(variables.<JavaVersion>getOptional("java")
.map(JavaVersion::getBinary).map(Path::toString).orElse("Invalid Java Directory")))); .map(JavaVersion::getBinary).map(Path::toString).orElse("Invalid Java Path"))));
} }
@FXML @FXML

View File

@ -24,7 +24,7 @@ import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.task.TaskListener; import org.jackhuang.hmcl.task.TaskListener;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent; import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane; import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane;
import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.StringUtils;
@ -67,9 +67,9 @@ public interface TaskExecutorDialogWizardDisplayer extends AbstractWizardDisplay
pane.fireEvent(new DialogCloseEvent()); pane.fireEvent(new DialogCloseEvent());
if (success) { if (success) {
if (settings.containsKey("success_message") && settings.get("success_message") instanceof String) if (settings.containsKey("success_message") && settings.get("success_message") instanceof String)
Controllers.dialog((String) settings.get("success_message"), null, MessageBox.FINE_MESSAGE, () -> onEnd()); Controllers.dialog((String) settings.get("success_message"), null, MessageType.FINE, () -> onEnd());
else if (!settings.containsKey("forbid_success_message")) else if (!settings.containsKey("forbid_success_message"))
Controllers.dialog(i18n("message.success"), null, MessageBox.FINE_MESSAGE, () -> onEnd()); Controllers.dialog(i18n("message.success"), null, MessageType.FINE, () -> onEnd());
} else { } else {
if (executor.getLastException() == null) if (executor.getLastException() == null)
return; return;
@ -77,9 +77,9 @@ public interface TaskExecutorDialogWizardDisplayer extends AbstractWizardDisplay
if (settings.get("failure_callback") instanceof WizardProvider.FailureCallback) if (settings.get("failure_callback") instanceof WizardProvider.FailureCallback)
((WizardProvider.FailureCallback)settings.get("failure_callback")).onFail(settings, executor.getLastException(), () -> onEnd()); ((WizardProvider.FailureCallback)settings.get("failure_callback")).onFail(settings, executor.getLastException(), () -> onEnd());
else if (settings.get("failure_message") instanceof String) else if (settings.get("failure_message") instanceof String)
Controllers.dialog(appendix, (String) settings.get("failure_message"), MessageBox.ERROR_MESSAGE, () -> onEnd()); Controllers.dialog(appendix, (String) settings.get("failure_message"), MessageType.ERROR, () -> onEnd());
else if (!settings.containsKey("forbid_failure_message")) else if (!settings.containsKey("forbid_failure_message"))
Controllers.dialog(appendix, i18n("wizard.failed"), MessageBox.ERROR_MESSAGE, () -> onEnd()); Controllers.dialog(appendix, i18n("wizard.failed"), MessageType.ERROR, () -> onEnd());
} }
}); });

View File

@ -26,7 +26,7 @@ import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.io.JarUtils; import org.jackhuang.hmcl.util.io.JarUtils;
@ -116,14 +116,14 @@ public final class UpdateHandler {
System.exit(0); System.exit(0);
} catch (IOException e) { } catch (IOException e) {
LOG.log(Level.WARNING, "Failed to update to " + version, e); LOG.log(Level.WARNING, "Failed to update to " + version, e);
Platform.runLater(() -> Controllers.dialog(StringUtils.getStackTrace(e), i18n("update.failed"), MessageBox.ERROR_MESSAGE)); Platform.runLater(() -> Controllers.dialog(StringUtils.getStackTrace(e), i18n("update.failed"), MessageType.ERROR));
return; return;
} }
} else { } else {
Throwable e = executor.getLastException(); Throwable e = executor.getLastException();
LOG.log(Level.WARNING, "Failed to update to " + version, e); LOG.log(Level.WARNING, "Failed to update to " + version, e);
Platform.runLater(() -> Controllers.dialog(e.toString(), i18n("update.failed"), MessageBox.ERROR_MESSAGE)); Platform.runLater(() -> Controllers.dialog(e.toString(), i18n("update.failed"), MessageType.ERROR));
} }
}); });
} }

View File

@ -18,9 +18,11 @@
package org.jackhuang.hmcl.util; package org.jackhuang.hmcl.util;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.ui.CrashWindow; import org.jackhuang.hmcl.ui.CrashWindow;
import org.jackhuang.hmcl.ui.construct.MessageBox;
import org.jackhuang.hmcl.upgrade.IntegrityChecker; import org.jackhuang.hmcl.upgrade.IntegrityChecker;
import org.jackhuang.hmcl.upgrade.UpdateChecker; import org.jackhuang.hmcl.upgrade.UpdateChecker;
import org.jackhuang.hmcl.util.io.NetworkUtils; import org.jackhuang.hmcl.util.io.NetworkUtils;
@ -69,7 +71,10 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
String info = entry.getValue(); String info = entry.getValue();
LOG.severe(info); LOG.severe(info);
try { try {
MessageBox.show(info); Alert alert = new Alert(AlertType.INFORMATION, info);
alert.setTitle(i18n("message.info"));
alert.setHeaderText(i18n("message.info"));
alert.showAndWait();
} catch (Throwable t) { } catch (Throwable t) {
LOG.log(Level.SEVERE, "Unable to show message", t); LOG.log(Level.SEVERE, "Unable to show message", t);
} }

View File

@ -58,10 +58,6 @@ public final class Locales {
public static final List<SupportedLocale> LOCALES = Lang.immutableListOf(DEFAULT, EN, ZH_CN, ZH); public static final List<SupportedLocale> LOCALES = Lang.immutableListOf(DEFAULT, EN, ZH_CN, ZH);
public static SupportedLocale getLocale(int index) {
return Lang.get(LOCALES, index).orElse(DEFAULT);
}
public static SupportedLocale getLocaleByName(String name) { public static SupportedLocale getLocaleByName(String name) {
if (name == null) return DEFAULT; if (name == null) return DEFAULT;
switch (name.toLowerCase()) { switch (name.toLowerCase()) {

View File

@ -24,7 +24,6 @@ import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.io.FileUtils;
import java.io.File; import java.io.File;
import java.io.IOException;
/** /**
* This task is to save the version json. * This task is to save the version json.
@ -52,8 +51,6 @@ public final class VersionJsonSaveTask extends Task {
@Override @Override
public void execute() throws Exception { public void execute() throws Exception {
File json = repository.getVersionJson(version.getId()).getAbsoluteFile(); File json = repository.getVersionJson(version.getId()).getAbsoluteFile();
if (!FileUtils.makeFile(json))
throw new IOException("Cannot create file " + json);
FileUtils.writeText(json, JsonUtils.GSON.toJson(version)); FileUtils.writeText(json, JsonUtils.GSON.toJson(version));
} }
} }

View File

@ -20,7 +20,9 @@ package org.jackhuang.hmcl.mod;
import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.Logging;
import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.javafx.ImmediateBooleanProperty;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -42,7 +44,7 @@ public final class ModInfo implements Comparable<ModInfo> {
private final String gameVersion; private final String gameVersion;
private final String url; private final String url;
private final String fileName; private final String fileName;
private final ImmediateBooleanProperty activeProperty; private final BooleanProperty activeProperty;
public ModInfo(ModManager modManager, File file, String name, String description) { public ModInfo(ModManager modManager, File file, String name, String description) {
this(modManager, file, name, description, "", "", "", ""); this(modManager, file, name, description, "", "", "", "");
@ -57,7 +59,7 @@ public final class ModInfo implements Comparable<ModInfo> {
this.gameVersion = gameVersion; this.gameVersion = gameVersion;
this.url = url; this.url = url;
activeProperty = new ImmediateBooleanProperty(this, "active", !modManager.isDisabled(file)) { activeProperty = new SimpleBooleanProperty(this, "active", !modManager.isDisabled(file)) {
@Override @Override
protected void invalidated() { protected void invalidated() {
Path path = ModInfo.this.file.toAbsolutePath(); Path path = ModInfo.this.file.toAbsolutePath();
@ -104,7 +106,7 @@ public final class ModInfo implements Comparable<ModInfo> {
return url; return url;
} }
public ImmediateBooleanProperty activeProperty() { public BooleanProperty activeProperty() {
return activeProperty; return activeProperty;
} }

View File

@ -17,7 +17,6 @@
*/ */
package org.jackhuang.hmcl.util; package org.jackhuang.hmcl.util;
import org.jackhuang.hmcl.util.function.ExceptionalRunnable;
import org.jackhuang.hmcl.util.function.ExceptionalSupplier; import org.jackhuang.hmcl.util.function.ExceptionalSupplier;
import java.util.*; import java.util.*;
@ -76,13 +75,6 @@ public final class Lang {
} }
} }
public static void ignoringException(ExceptionalRunnable<?> runnable) {
try {
runnable.run();
} catch (Exception ignore) {
}
}
/** /**
* Cast {@code obj} to V dynamically. * Cast {@code obj} to V dynamically.
* @param obj the object reference to be cast. * @param obj the object reference to be cast.
@ -98,20 +90,6 @@ public final class Lang {
} }
} }
/**
* Get the element at the specific position {@code index} in {@code list}.
*
* @param index the index of element to be return
* @param <V> the type of elements in {@code list}
* @return the element at the specific position, null if index is out of bound.
*/
public static <V> Optional<V> get(List<V> list, int index) {
if (index < 0 || index >= list.size())
return Optional.empty();
else
return Optional.ofNullable(list.get(index));
}
/** /**
* Join two collections into one list. * Join two collections into one list.
* *

View File

@ -1,55 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util.javafx;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
/**
* @author huangyuhui
* @deprecated Use SimpleBooleanProperty instead
*/
@Deprecated
public class ImmediateBooleanProperty extends SimpleBooleanProperty {
@Override
public void set(boolean newValue) {
super.get();
super.set(newValue);
}
@Override
public void bind(ObservableValue<? extends Boolean> newObservable) {
super.get();
super.bind(newObservable);
}
@Override
public void unbind() {
super.get();
super.unbind();
}
public ImmediateBooleanProperty(Object bean, String name, boolean initialValue) {
super(bean, name, initialValue);
ChangeListener<Boolean> changeListener = (a, b, newValue) -> {
};
addListener(changeListener);
}
}

View File

@ -1,55 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util.javafx;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
/**
* @author huangyuhui
* @deprecated Use SimpleIntegerProperty instead
*/
@Deprecated
public class ImmediateIntegerProperty extends SimpleIntegerProperty {
@Override
public void set(int newValue) {
super.get();
super.set(newValue);
}
@Override
public void bind(ObservableValue<? extends Number> newObservable) {
super.get();
super.bind(newObservable);
}
@Override
public void unbind() {
super.get();
super.unbind();
}
public ImmediateIntegerProperty(Object bean, String name, int initialValue) {
super(bean, name, initialValue);
ChangeListener<Number> changeListener = (a, b, newValue) -> {
};
addListener(changeListener);
}
}

View File

@ -1,55 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util.javafx;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
/**
* @author huangyuhui
* @deprecated Use SimpleObjectProperty instead
*/
@Deprecated
public class ImmediateObjectProperty<T> extends SimpleObjectProperty<T> {
@Override
public void set(T newValue) {
super.get();
super.set(newValue);
}
@Override
public void bind(ObservableValue<? extends T> newObservable) {
super.get();
super.bind(newObservable);
}
@Override
public void unbind() {
super.get();
super.unbind();
}
public ImmediateObjectProperty(Object bean, String name, T initialValue) {
super(bean, name, initialValue);
ChangeListener<T> changeListener = (a, b, newValue) -> {
};
addListener(changeListener);
}
}

View File

@ -1,75 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util.javafx;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import java.util.Objects;
import java.util.function.Consumer;
/**
* @author huangyuhui
* @deprecated Use SimpleStringProperty instead
*/
@Deprecated
public class ImmediateStringProperty extends SimpleStringProperty {
@Override
public void set(String newValue) {
super.get();
super.set(newValue);
}
@Override
public void bind(ObservableValue<? extends String> newObservable) {
super.get();
super.bind(newObservable);
}
@Override
public void unbind() {
super.get();
super.unbind();
}
private Consumer<String> consumer = null;
private ChangeListener<String> listener = null;
public void setChangedListener(Consumer<String> consumer) {
this.consumer = Objects.requireNonNull(consumer);
this.listener = null;
}
public void setChangedListener(ChangeListener<String> listener) {
this.consumer = null;
this.listener = Objects.requireNonNull(listener);
}
public ImmediateStringProperty(Object bean, String name, String initialValue) {
super(bean, name, initialValue);
ChangeListener<String> changeListener = (a, b, newValue) -> {
if (consumer != null)
consumer.accept(newValue);
if (listener != null)
listener.changed(a, b, newValue);
};
addListener(changeListener);
}
}