Skip to content

Commit 7b63796

Browse files
authored
在已有账户的情况下移除联机和主页的玩家名称tooltip (#6123)
1 parent 55f4b0d commit 7b63796

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package org.jackhuang.hmcl.ui.account;
1919

20-
import javafx.beans.binding.Bindings;
2120
import javafx.beans.property.ObjectProperty;
2221
import javafx.beans.property.SimpleObjectProperty;
2322
import javafx.beans.value.ObservableValue;
@@ -27,7 +26,6 @@
2726
import org.jackhuang.hmcl.auth.Account;
2827
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
2928
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
30-
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
3129
import org.jackhuang.hmcl.game.TexturesLoader;
3230
import org.jackhuang.hmcl.setting.Accounts;
3331
import org.jackhuang.hmcl.ui.FXUtils;
@@ -42,6 +40,7 @@
4240
public class AccountAdvancedListItem extends AdvancedListItem {
4341
private final Tooltip tooltip;
4442
private final Canvas canvas;
43+
private boolean tooltipInstalled;
4544

4645
private final ObjectProperty<Account> account = new SimpleObjectProperty<Account>() {
4746

@@ -51,18 +50,18 @@ protected void invalidated() {
5150
if (account == null) {
5251
titleProperty().unbind();
5352
subtitleProperty().unbind();
54-
tooltip.textProperty().unbind();
5553
setTitle(i18n("account.missing"));
5654
setSubtitle(i18n("account.missing.add"));
5755
tooltip.setText(i18n("account.create"));
56+
installTooltip();
5857

5958
TexturesLoader.unbindAvatar(canvas);
6059
TexturesLoader.drawAvatar(canvas, TexturesLoader.getDefaultSkinImage());
6160

6261
} else {
6362
titleProperty().bind(BindingMapping.of(account, Account::getCharacter));
6463
subtitleProperty().bind(accountSubtitle(account));
65-
tooltip.textProperty().bind(accountTooltip(account));
64+
uninstallTooltip();
6665
TexturesLoader.bindAvatar(canvas, account);
6766
}
6867
}
@@ -74,7 +73,6 @@ public AccountAdvancedListItem() {
7473

7574
public AccountAdvancedListItem(Account account) {
7675
tooltip = new Tooltip();
77-
FXUtils.installFastTooltip(this, tooltip);
7876

7977
canvas = new Canvas(32, 32);
8078
canvas.setMouseTransparent(true);
@@ -103,19 +101,17 @@ private static ObservableValue<String> accountSubtitle(Account account) {
103101
}
104102
}
105103

106-
private static ObservableValue<String> accountTooltip(Account account) {
107-
if (account instanceof AuthlibInjectorAccount) {
108-
AuthlibInjectorServer server = ((AuthlibInjectorAccount) account).getServer();
109-
return Bindings.format("%s (%s) (%s)",
110-
BindingMapping.of(account, Account::getCharacter),
111-
account.getUsername(),
112-
BindingMapping.of(server, AuthlibInjectorServer::getName));
113-
} else if (account instanceof YggdrasilAccount) {
114-
return Bindings.format("%s (%s)",
115-
BindingMapping.of(account, Account::getCharacter),
116-
account.getUsername());
117-
} else {
118-
return BindingMapping.of(account, Account::getCharacter);
104+
private void installTooltip() {
105+
if (!tooltipInstalled) {
106+
FXUtils.installFastTooltip(this, tooltip);
107+
tooltipInstalled = true;
108+
}
109+
}
110+
111+
private void uninstallTooltip() {
112+
if (tooltipInstalled) {
113+
Tooltip.uninstall(this, tooltip);
114+
tooltipInstalled = false;
119115
}
120116
}
121117

0 commit comments

Comments
 (0)