diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAuthlibInjectorServerPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAuthlibInjectorServerPane.java index d5a3cdca5..7ad0ce437 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAuthlibInjectorServerPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAuthlibInjectorServerPane.java @@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui.account; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXDialogLayout; import com.jfoenix.controls.JFXTextField; + import javafx.beans.binding.Bindings; import javafx.fxml.FXML; import javafx.scene.control.Label; @@ -29,6 +30,7 @@ import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.animation.ContainerAnimations; import org.jackhuang.hmcl.ui.animation.TransitionHandler; +import org.jackhuang.hmcl.ui.construct.DialogAware; import org.jackhuang.hmcl.ui.construct.DialogCloseEvent; import org.jackhuang.hmcl.ui.construct.SpinnerPane; import org.jackhuang.hmcl.util.io.NetworkUtils; @@ -37,9 +39,10 @@ import java.io.IOException; import static org.jackhuang.hmcl.setting.ConfigHolder.config; import static org.jackhuang.hmcl.ui.FXUtils.loadFXML; +import static org.jackhuang.hmcl.util.Lang.thread; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public class AddAuthlibInjectorServerPane extends StackPane { +public class AddAuthlibInjectorServerPane extends StackPane implements DialogAware { @FXML private StackPane addServerContainer; @FXML private Label lblServerUrl; @@ -70,6 +73,14 @@ public class AddAuthlibInjectorServerPane extends StackPane { btnAddNext.disableProperty().bind( Bindings.createBooleanBinding(txtServerUrl::validate, txtServerUrl.textProperty()).not()); nextPane.hideSpinner(); + + txtServerUrl.setText("https://"); + } + + @Override + public void onDialogShown() { + txtServerUrl.requestFocus(); + txtServerUrl.selectEnd(); } private String fixInputUrl(String url) { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/DialogAware.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/DialogAware.java new file mode 100644 index 000000000..5dbcdc79c --- /dev/null +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/DialogAware.java @@ -0,0 +1,31 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2017 huangyuhui + * + * 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 {http://www.gnu.org/licenses/}. + */ +package org.jackhuang.hmcl.ui.construct; + +import org.jackhuang.hmcl.ui.Controllers; + +/** + * @author yushijinhun + * @see Controllers#dialog(javafx.scene.layout.Region) + */ +public interface DialogAware { + + default void onDialogShown() { + } + +} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java index 8b44072ad..a0a57723a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java @@ -24,6 +24,8 @@ import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Platform; import javafx.beans.binding.Bindings; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Cursor; @@ -303,6 +305,23 @@ public class DecoratorController { EventHandler handler = event -> closeDialog(node); node.getProperties().put(PROPERTY_DIALOG_CLOSE_HANDLER, handler); node.addEventHandler(DialogCloseEvent.CLOSE, handler); + + if (node instanceof DialogAware) { + DialogAware dialogAware = (DialogAware) node; + if (dialog.isVisible()) { + dialogAware.onDialogShown(); + } else { + dialog.visibleProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { + if (newValue) { + dialogAware.onDialogShown(); + observable.removeListener(this); + } + } + }); + } + } } @SuppressWarnings("unchecked") diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 2e2d5e0f1..cabeb15d9 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -40,7 +40,7 @@ account.failed.invalid_credentials=Incorrect password, or you are forbidden to l account.failed.invalid_password=Invalid password account.failed.invalid_token=Please log out and re-input your password to login. account.failed.no_character=No character in this account. -account.failed.server_response_malformed=Invalid server response. Is this a valid authentication server? +account.failed.server_response_malformed=Invalid server response. The authentication server may have a failure. account.injector.add=Add an authentication server account.injector.manage=Manage authentication servers account.injector.manage.title=Authentication servers diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 7591ad524..276da5f6a 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -40,7 +40,7 @@ account.failed.invalid_credentials=您的使用者名稱或密碼錯誤,或者 account.failed.invalid_password=無效的密碼 account.failed.invalid_token=請嘗試登出並重新輸入密碼登入 account.failed.no_character=該帳號沒有角色 -account.failed.server_response_malformed=這個伺服器不是合法的登入驗證伺服器 +account.failed.server_response_malformed=無法解析認證伺服器響應,可能是伺服器故障 account.injector.add=新增認證伺服器 account.injector.manage=管理認證伺服器 account.injector.manage.title=認證伺服器 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 5531252b4..81ad563ac 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -34,13 +34,13 @@ account.character=角色 account.choose=选择一个角色 account.create=新建账户 account.email=邮箱 -account.failed.connect_authentication_server=无法连接认证服务器,可能是网络问题 +account.failed.connect_authentication_server=无法连接认证服务器,可能是网络问题 account.failed.connect_injector_server=无法连接认证服务器,可能是网络故障或 URL 输入错误 account.failed.invalid_credentials=您的用户名或密码错误,或者登录次数过多被暂时禁止登录,请稍后再试 account.failed.invalid_password=无效的密码 account.failed.invalid_token=请尝试登出并重新输入密码登录 account.failed.no_character=该帐号没有角色 -account.failed.server_response_malformed=这个服务器不是合法的登录验证服务器 +account.failed.server_response_malformed=无法解析认证服务器响应,可能是服务器故障 account.injector.add=添加认证服务器 account.injector.manage=管理认证服务器 account.injector.manage.title=认证服务器