allow characterName/authserverName to be changed at runtime
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.ui.account;
|
package org.jackhuang.hmcl.ui.account;
|
||||||
|
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
@@ -37,12 +38,13 @@ public class AccountAdvancedListItem extends AdvancedListItem {
|
|||||||
protected void invalidated() {
|
protected void invalidated() {
|
||||||
Account account = get();
|
Account account = get();
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
|
titleProperty().unbind();
|
||||||
setTitle(i18n("account.missing"));
|
setTitle(i18n("account.missing"));
|
||||||
setSubtitle(i18n("account.missing.add"));
|
setSubtitle(i18n("account.missing.add"));
|
||||||
imageProperty().unbind();
|
imageProperty().unbind();
|
||||||
setImage(new Image("/assets/img/craft_table.png"));
|
setImage(new Image("/assets/img/craft_table.png"));
|
||||||
} else {
|
} else {
|
||||||
setTitle(account.getCharacter());
|
titleProperty().bind(Bindings.createStringBinding(account::getCharacter, account));
|
||||||
setSubtitle(accountSubtitle(account));
|
setSubtitle(accountSubtitle(account));
|
||||||
imageProperty().bind(TexturesLoader.fxAvatarBinding(account, 32));
|
imageProperty().bind(TexturesLoader.fxAvatarBinding(account, 32));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,19 +17,28 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.ui.account;
|
package org.jackhuang.hmcl.ui.account;
|
||||||
|
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.binding.StringBinding;
|
||||||
import javafx.beans.property.*;
|
import javafx.beans.property.*;
|
||||||
import javafx.scene.control.RadioButton;
|
import javafx.scene.control.RadioButton;
|
||||||
import javafx.scene.control.Skin;
|
import javafx.scene.control.Skin;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import org.jackhuang.hmcl.auth.Account;
|
import org.jackhuang.hmcl.auth.Account;
|
||||||
|
import org.jackhuang.hmcl.auth.AuthenticationException;
|
||||||
|
import org.jackhuang.hmcl.auth.CredentialExpiredException;
|
||||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
|
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
|
||||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
|
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
|
||||||
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
||||||
import org.jackhuang.hmcl.game.TexturesLoader;
|
import org.jackhuang.hmcl.game.TexturesLoader;
|
||||||
import org.jackhuang.hmcl.setting.Accounts;
|
import org.jackhuang.hmcl.setting.Accounts;
|
||||||
|
import org.jackhuang.hmcl.ui.DialogController;
|
||||||
|
|
||||||
|
import static org.jackhuang.hmcl.util.Lang.thread;
|
||||||
|
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class AccountListItem extends RadioButton {
|
public class AccountListItem extends RadioButton {
|
||||||
|
|
||||||
private final Account account;
|
private final Account account;
|
||||||
@@ -42,17 +51,22 @@ public class AccountListItem extends RadioButton {
|
|||||||
getStyleClass().clear();
|
getStyleClass().clear();
|
||||||
setUserData(account);
|
setUserData(account);
|
||||||
|
|
||||||
StringBuilder subtitleString = new StringBuilder(Accounts.getLocalizedLoginTypeName(Accounts.getAccountFactory(account)));
|
String loginTypeName = Accounts.getLocalizedLoginTypeName(Accounts.getAccountFactory(account));
|
||||||
if (account instanceof AuthlibInjectorAccount) {
|
if (account instanceof AuthlibInjectorAccount) {
|
||||||
AuthlibInjectorServer server = ((AuthlibInjectorAccount) account).getServer();
|
AuthlibInjectorServer server = ((AuthlibInjectorAccount) account).getServer();
|
||||||
subtitleString.append(", ").append(i18n("account.injector.server")).append(": ").append(server.getName());
|
subtitle.bind(Bindings.concat(
|
||||||
|
loginTypeName, ", ", i18n("account.injector.server"), ": ",
|
||||||
|
Bindings.createStringBinding(server::getName, server)));
|
||||||
|
} else {
|
||||||
|
subtitle.set(loginTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account instanceof OfflineAccount)
|
StringBinding characterName = Bindings.createStringBinding(account::getCharacter, account);
|
||||||
title.set(account.getCharacter());
|
if (account instanceof OfflineAccount) {
|
||||||
else
|
title.bind(characterName);
|
||||||
title.set(account.getUsername() + " - " + account.getCharacter());
|
} else {
|
||||||
subtitle.set(subtitleString.toString());
|
title.bind(Bindings.concat(account.getUsername(), " - ", characterName));
|
||||||
|
}
|
||||||
|
|
||||||
image.bind(TexturesLoader.fxAvatarBinding(account, 32));
|
image.bind(TexturesLoader.fxAvatarBinding(account, 32));
|
||||||
}
|
}
|
||||||
@@ -64,6 +78,19 @@ public class AccountListItem extends RadioButton {
|
|||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
account.clearCache();
|
account.clearCache();
|
||||||
|
thread(() -> {
|
||||||
|
try {
|
||||||
|
account.logIn();
|
||||||
|
} catch (CredentialExpiredException e) {
|
||||||
|
try {
|
||||||
|
DialogController.logIn(account);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
LOG.log(Level.WARNING, "Failed to refresh " + account + " with password", e1);
|
||||||
|
}
|
||||||
|
} catch (AuthenticationException e) {
|
||||||
|
LOG.log(Level.WARNING, "Failed to refresh " + account + " with token", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package org.jackhuang.hmcl.ui.account;
|
|||||||
|
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
import com.jfoenix.effects.JFXDepthManager;
|
import com.jfoenix.effects.JFXDepthManager;
|
||||||
|
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
@@ -33,17 +35,17 @@ public final class AuthlibInjectorServerItem extends BorderPane {
|
|||||||
private final AuthlibInjectorServer server;
|
private final AuthlibInjectorServer server;
|
||||||
|
|
||||||
private final Label lblServerName = new Label();
|
private final Label lblServerName = new Label();
|
||||||
private final Label lblServerIp = new Label();
|
private final Label lblServerUrl = new Label();
|
||||||
|
|
||||||
public AuthlibInjectorServerItem(AuthlibInjectorServer server, Consumer<AuthlibInjectorServerItem> deleteCallback) {
|
public AuthlibInjectorServerItem(AuthlibInjectorServer server, Consumer<AuthlibInjectorServerItem> deleteCallback) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
lblServerName.setStyle("-fx-font-size: 15;");
|
lblServerName.setStyle("-fx-font-size: 15;");
|
||||||
lblServerIp.setStyle("-fx-font-size: 10;");
|
lblServerUrl.setStyle("-fx-font-size: 10;");
|
||||||
|
|
||||||
VBox center = new VBox();
|
VBox center = new VBox();
|
||||||
BorderPane.setAlignment(center, Pos.CENTER);
|
BorderPane.setAlignment(center, Pos.CENTER);
|
||||||
center.getChildren().addAll(lblServerName, lblServerIp);
|
center.getChildren().addAll(lblServerName, lblServerUrl);
|
||||||
setCenter(center);
|
setCenter(center);
|
||||||
|
|
||||||
JFXButton right = new JFXButton();
|
JFXButton right = new JFXButton();
|
||||||
@@ -55,8 +57,8 @@ public final class AuthlibInjectorServerItem extends BorderPane {
|
|||||||
|
|
||||||
setStyle("-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;");
|
setStyle("-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;");
|
||||||
JFXDepthManager.setDepth(this, 1);
|
JFXDepthManager.setDepth(this, 1);
|
||||||
lblServerName.setText(server.getName());
|
lblServerName.textProperty().bind(Bindings.createStringBinding(server::getName, server));
|
||||||
lblServerIp.setText(server.getUrl());
|
lblServerUrl.setText(server.getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthlibInjectorServer getServer() {
|
public AuthlibInjectorServer getServer() {
|
||||||
|
|||||||
Reference in New Issue
Block a user