diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java
index cc8fbb5b6..c620eee7e 100644
--- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java
+++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java
@@ -21,9 +21,9 @@ import com.jfoenix.concurrency.JFXUtilities;
import com.jfoenix.controls.*;
import javafx.beans.binding.Bindings;
+import javafx.beans.property.ReadOnlyIntegerProperty;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
-import javafx.scene.Node;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
@@ -85,22 +85,22 @@ public class AddAccountPane extends StackPane {
selectDefaultServer();
cboType.getItems().setAll(i18n("account.methods.offline"), i18n("account.methods.yggdrasil"), i18n("account.methods.authlib_injector"));
- cboType.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> {
- txtPassword.setVisible(newValue.intValue() != 0);
- lblPassword.setVisible(newValue.intValue() != 0);
- cboServers.setVisible(newValue.intValue() == 2);
- linkManageInjectorServers.setVisible(newValue.intValue() == 2);
- lblInjectorServer.setVisible(newValue.intValue() == 2);
- validateAcceptButton();
- });
cboType.getSelectionModel().select(0);
- txtPassword.setOnAction(e -> onCreationAccept());
- txtUsername.setOnAction(e -> onCreationAccept());
+ ReadOnlyIntegerProperty loginTypeIdProperty = cboType.getSelectionModel().selectedIndexProperty();
+
+ txtPassword.visibleProperty().bind(loginTypeIdProperty.isNotEqualTo(0));
+ lblPassword.visibleProperty().bind(txtPassword.visibleProperty());
+
+ cboServers.visibleProperty().bind(loginTypeIdProperty.isEqualTo(2));
+ lblInjectorServer.visibleProperty().bind(cboServers.visibleProperty());
+ linkManageInjectorServers.visibleProperty().bind(cboServers.visibleProperty());
+
txtUsername.getValidators().add(new Validator(i18n("input.email"), str -> !txtPassword.isVisible() || str.contains("@")));
- txtUsername.textProperty().addListener(it -> validateAcceptButton());
- txtPassword.textProperty().addListener(it -> validateAcceptButton());
+ btnAccept.disableProperty().bind(Bindings.createBooleanBinding(
+ () -> !txtUsername.validate() || (loginTypeIdProperty.get() != 0 && !txtPassword.validate()),
+ txtUsername.textProperty(), txtPassword.textProperty(), loginTypeIdProperty));
}
/**
@@ -112,12 +112,11 @@ public class AddAccountPane extends StackPane {
}
}
- private void validateAcceptButton() {
- btnAccept.setDisable(!txtUsername.validate() || (cboType.getSelectionModel().getSelectedIndex() != 0 && !txtPassword.validate()));
- }
-
@FXML
private void onCreationAccept() {
+ if (btnAccept.isDisabled())
+ return;
+
String username = txtUsername.getText();
String password = txtPassword.getText();
Object addtionalData;
@@ -149,6 +148,7 @@ public class AddAccountPane extends StackPane {
acceptPane.showSpinner();
lblCreationWarning.setText("");
+ setDisable(true);
Task.ofResult("create_account", () -> factory.create(new Selector(), username, password, addtionalData, Settings.INSTANCE.getProxy()))
.finalized(Schedulers.javafx(), variables -> {
@@ -161,6 +161,7 @@ public class AddAccountPane extends StackPane {
} else {
lblCreationWarning.setText(accountException(exception));
}
+ setDisable(false);
acceptPane.hideSpinner();
}).start();
}
@@ -176,14 +177,6 @@ public class AddAccountPane extends StackPane {
Controllers.navigate(Controllers.getServersPage());
}
- private void showSelector(Node node) {
- getChildren().setAll(node);
- }
-
- private void closeSelector() {
- getChildren().setAll(layout);
- }
-
private class Selector extends BorderPane implements CharacterSelector {
private final AdvancedListBox listBox = new AdvancedListBox();
private final JFXButton cancel = new JFXButton();
@@ -240,7 +233,7 @@ public class AddAccountPane extends StackPane {
listBox.add(accountItem);
}
- JFXUtilities.runInFX(() -> showSelector(this));
+ JFXUtilities.runInFX(() -> Controllers.dialog(this));
try {
latch.await();
@@ -248,11 +241,11 @@ public class AddAccountPane extends StackPane {
if (selectedProfile == null)
throw new NoSelectedCharacterException(account);
- JFXUtilities.runInFX(AddAccountPane.this::closeSelector);
-
return selectedProfile;
} catch (InterruptedException ignore) {
throw new NoSelectedCharacterException(account);
+ } finally {
+ JFXUtilities.runInFX(() -> Selector.this.fireEvent(new DialogCloseEvent()));
}
}
}
diff --git a/HMCL/src/main/resources/assets/fxml/account-add.fxml b/HMCL/src/main/resources/assets/fxml/account-add.fxml
index 2567bd210..bf0e6313e 100644
--- a/HMCL/src/main/resources/assets/fxml/account-add.fxml
+++ b/HMCL/src/main/resources/assets/fxml/account-add.fxml
@@ -37,7 +37,7 @@
+ FXUtils.validateWhileTextChanged="true" onAction="#onCreationAccept">
@@ -47,7 +47,7 @@
+ GridPane.columnSpan="2" FXUtils.validateWhileTextChanged="true" onAction="#onCreationAccept">