1717 */
1818package org .jackhuang .hmcl .ui .account ;
1919
20- import javafx .beans .binding .Bindings ;
2120import javafx .beans .property .ObjectProperty ;
2221import javafx .beans .property .SimpleObjectProperty ;
2322import javafx .beans .value .ObservableValue ;
2726import org .jackhuang .hmcl .auth .Account ;
2827import org .jackhuang .hmcl .auth .authlibinjector .AuthlibInjectorAccount ;
2928import org .jackhuang .hmcl .auth .authlibinjector .AuthlibInjectorServer ;
30- import org .jackhuang .hmcl .auth .yggdrasil .YggdrasilAccount ;
3129import org .jackhuang .hmcl .game .TexturesLoader ;
3230import org .jackhuang .hmcl .setting .Accounts ;
3331import org .jackhuang .hmcl .ui .FXUtils ;
4240public 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