Load skin when added new account
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2018 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* 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.event;
|
||||||
|
|
||||||
|
import org.jackhuang.hmcl.auth.Account;
|
||||||
|
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event gets fired when added accounts.
|
||||||
|
* <br>
|
||||||
|
* This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS}
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public class AccountAddedEvent extends Event {
|
||||||
|
|
||||||
|
private final Account account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param source {@link org.jackhuang.hmcl.setting.Settings}
|
||||||
|
*/
|
||||||
|
public AccountAddedEvent(Object source, Account account) {
|
||||||
|
super(source);
|
||||||
|
this.account = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Account getAccount() {
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this)
|
||||||
|
.append("source", source)
|
||||||
|
.append("account", account)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -28,10 +28,7 @@ import org.jackhuang.hmcl.auth.Account;
|
|||||||
import org.jackhuang.hmcl.auth.AccountFactory;
|
import org.jackhuang.hmcl.auth.AccountFactory;
|
||||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
|
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
|
||||||
import org.jackhuang.hmcl.download.DownloadProvider;
|
import org.jackhuang.hmcl.download.DownloadProvider;
|
||||||
import org.jackhuang.hmcl.event.AccountLoadingEvent;
|
import org.jackhuang.hmcl.event.*;
|
||||||
import org.jackhuang.hmcl.event.EventBus;
|
|
||||||
import org.jackhuang.hmcl.event.ProfileChangedEvent;
|
|
||||||
import org.jackhuang.hmcl.event.ProfileLoadingEvent;
|
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
import org.jackhuang.hmcl.util.*;
|
import org.jackhuang.hmcl.util.*;
|
||||||
|
|
||||||
@@ -391,6 +388,8 @@ public class Settings {
|
|||||||
public void addAccount(Account account) {
|
public void addAccount(Account account) {
|
||||||
accounts.put(Accounts.getAccountId(account), account);
|
accounts.put(Accounts.getAccountId(account), account);
|
||||||
onAccountLoading();
|
onAccountLoading();
|
||||||
|
|
||||||
|
EventBus.EVENT_BUS.fireEvent(new AccountAddedEvent(this, account));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Account getAccount(String name, String character) {
|
public Account getAccount(String name, String character) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import org.jackhuang.hmcl.auth.Account;
|
|||||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
|
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
|
||||||
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
||||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
||||||
|
import org.jackhuang.hmcl.download.VersionList;
|
||||||
import org.jackhuang.hmcl.event.*;
|
import org.jackhuang.hmcl.event.*;
|
||||||
import org.jackhuang.hmcl.game.AccountHelper;
|
import org.jackhuang.hmcl.game.AccountHelper;
|
||||||
import org.jackhuang.hmcl.game.HMCLGameRepository;
|
import org.jackhuang.hmcl.game.HMCLGameRepository;
|
||||||
@@ -50,6 +51,7 @@ import org.jackhuang.hmcl.ui.construct.RipplerContainer;
|
|||||||
import org.jackhuang.hmcl.util.Lang;
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@@ -60,6 +62,7 @@ public final class LeftPaneController {
|
|||||||
private final VBox accountPane = new VBox();
|
private final VBox accountPane = new VBox();
|
||||||
private final IconedItem launcherSettingsItem;
|
private final IconedItem launcherSettingsItem;
|
||||||
private final VersionListItem missingAccountItem = new VersionListItem(Launcher.i18n("account.missing"), Launcher.i18n("message.unknown"));
|
private final VersionListItem missingAccountItem = new VersionListItem(Launcher.i18n("account.missing"), Launcher.i18n("message.unknown"));
|
||||||
|
private final HashMap<Account, VersionListItem> items = new HashMap<>();
|
||||||
|
|
||||||
public LeftPaneController(AdvancedListBox leftPane) {
|
public LeftPaneController(AdvancedListBox leftPane) {
|
||||||
this.leftPane = leftPane;
|
this.leftPane = leftPane;
|
||||||
@@ -86,6 +89,7 @@ public final class LeftPaneController {
|
|||||||
})))
|
})))
|
||||||
.add(profilePane);
|
.add(profilePane);
|
||||||
|
|
||||||
|
EventBus.EVENT_BUS.channel(AccountAddedEvent.class).register(this::onAccountAdd);
|
||||||
EventBus.EVENT_BUS.channel(AccountLoadingEvent.class).register(this::onAccountsLoading);
|
EventBus.EVENT_BUS.channel(AccountLoadingEvent.class).register(this::onAccountsLoading);
|
||||||
EventBus.EVENT_BUS.channel(ProfileLoadingEvent.class).register(this::onProfilesLoading);
|
EventBus.EVENT_BUS.channel(ProfileLoadingEvent.class).register(this::onProfilesLoading);
|
||||||
EventBus.EVENT_BUS.channel(ProfileChangedEvent.class).register(this::onProfileChanged);
|
EventBus.EVENT_BUS.channel(ProfileChangedEvent.class).register(this::onProfileChanged);
|
||||||
@@ -144,11 +148,24 @@ public final class LeftPaneController {
|
|||||||
else throw new Error(Launcher.i18n("account.methods.no_method") + ": " + account);
|
else throw new Error(Launcher.i18n("account.methods.no_method") + ": " + account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onAccountAdd(AccountAddedEvent event) {
|
||||||
|
Account account = event.getAccount();
|
||||||
|
VersionListItem item = items.get(account);
|
||||||
|
if (account instanceof YggdrasilAccount)
|
||||||
|
AccountHelper.refreshSkinAsync((YggdrasilAccount) account)
|
||||||
|
.subscribe(Schedulers.javafx(), () -> {
|
||||||
|
Image image = AccountHelper.getSkin((YggdrasilAccount) account, 4);
|
||||||
|
item.setImage(image, AccountHelper.getViewport(4));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void onAccountsLoading() {
|
private void onAccountsLoading() {
|
||||||
LinkedList<RipplerContainer> list = new LinkedList<>();
|
LinkedList<RipplerContainer> list = new LinkedList<>();
|
||||||
|
items.clear();
|
||||||
Account selectedAccount = Settings.INSTANCE.getSelectedAccount();
|
Account selectedAccount = Settings.INSTANCE.getSelectedAccount();
|
||||||
for (Account account : Settings.INSTANCE.getAccounts()) {
|
for (Account account : Settings.INSTANCE.getAccounts()) {
|
||||||
VersionListItem item = new VersionListItem(account.getCharacter(), accountType(account));
|
VersionListItem item = new VersionListItem(account.getCharacter(), accountType(account));
|
||||||
|
items.put(account, item);
|
||||||
RipplerContainer ripplerContainer = new RipplerContainer(item);
|
RipplerContainer ripplerContainer = new RipplerContainer(item);
|
||||||
item.setOnSettingsButtonClicked(e -> {
|
item.setOnSettingsButtonClicked(e -> {
|
||||||
AccountPage accountPage = new AccountPage(account, item);
|
AccountPage accountPage = new AccountPage(account, item);
|
||||||
|
|||||||
Reference in New Issue
Block a user