mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-10 20:37:30 -04:00
Show alex or steve portrait for offline account
This commit is contained in:
parent
6823291eb0
commit
f6c95e3095
@ -84,9 +84,11 @@ public final class AccountHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Image getSkin(YggdrasilAccount account, double scaleRatio) {
|
public static Image getSkin(YggdrasilAccount account, double scaleRatio) {
|
||||||
if (account.getSelectedProfile() == null) return FXUtils.DEFAULT_ICON;
|
if (account.getSelectedProfile() == null)
|
||||||
|
return getDefaultSkin(account, scaleRatio);
|
||||||
String name = account.getSelectedProfile().getName();
|
String name = account.getSelectedProfile().getName();
|
||||||
if (name == null) return FXUtils.DEFAULT_ICON;
|
if (name == null)
|
||||||
|
return getDefaultSkin(account, scaleRatio);
|
||||||
File file = getSkinFile(name);
|
File file = getSkinFile(name);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
Image original = new Image("file:" + file.getAbsolutePath());
|
Image original = new Image("file:" + file.getAbsolutePath());
|
||||||
@ -95,7 +97,7 @@ public final class AccountHelper {
|
|||||||
original.getHeight() * scaleRatio,
|
original.getHeight() * scaleRatio,
|
||||||
false, false);
|
false, false);
|
||||||
}
|
}
|
||||||
return FXUtils.DEFAULT_ICON;
|
return getDefaultSkin(account, scaleRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Image getSkinImmediately(YggdrasilAccount account, GameProfile profile, double scaleRatio, Proxy proxy) throws Exception {
|
public static Image getSkinImmediately(YggdrasilAccount account, GameProfile profile, double scaleRatio, Proxy proxy) throws Exception {
|
||||||
@ -103,13 +105,10 @@ public final class AccountHelper {
|
|||||||
File file = getSkinFile(name);
|
File file = getSkinFile(name);
|
||||||
downloadSkin(account, profile, true, proxy);
|
downloadSkin(account, profile, true, proxy);
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
return FXUtils.DEFAULT_ICON;
|
return getDefaultSkin(account, scaleRatio);
|
||||||
|
|
||||||
Image original = new Image("file:" + file.getAbsolutePath());
|
String url = "file:" + file.getAbsolutePath();
|
||||||
return new Image("file:" + file.getAbsolutePath(),
|
return scale(url, scaleRatio);
|
||||||
original.getWidth() * scaleRatio,
|
|
||||||
original.getHeight() * scaleRatio,
|
|
||||||
false, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Rectangle2D getViewport(double scaleRatio) {
|
public static Rectangle2D getViewport(double scaleRatio) {
|
||||||
@ -164,4 +163,31 @@ public final class AccountHelper {
|
|||||||
return;
|
return;
|
||||||
new FileDownloadTask(NetworkUtils.toURL(url), file, proxy).run();
|
new FileDownloadTask(NetworkUtils.toURL(url), file, proxy).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Image scale(String url, double scaleRatio) {
|
||||||
|
Image origin = new Image(url);
|
||||||
|
return new Image(url,
|
||||||
|
origin.getWidth() * scaleRatio,
|
||||||
|
origin.getHeight() * scaleRatio,
|
||||||
|
false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image getSteveSkin(double scaleRatio) {
|
||||||
|
return scale("/assets/img/steve.png", 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image getAlexSkin(double scaleRatio) {
|
||||||
|
return scale("/assets/img/alex.png", 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image getDefaultSkin(Account account, double scaleRatio) {
|
||||||
|
if (account == null)
|
||||||
|
return getSteveSkin(scaleRatio);
|
||||||
|
|
||||||
|
int type = account.getUUID().hashCode() & 1;
|
||||||
|
if (type == 1)
|
||||||
|
return getAlexSkin(scaleRatio);
|
||||||
|
else
|
||||||
|
return getSteveSkin(scaleRatio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public final class Locales {
|
|||||||
*/
|
*/
|
||||||
public static final SupportedLocale RU = new SupportedLocale(new Locale("ru"));
|
public static final SupportedLocale RU = new SupportedLocale(new Locale("ru"));
|
||||||
|
|
||||||
public static final List<SupportedLocale> LOCALES = Arrays.asList(DEFAULT, EN, ZH, ZH_CN, VI, RU);
|
public static final List<SupportedLocale> LOCALES = Arrays.asList(DEFAULT, ZH_CN);
|
||||||
|
|
||||||
public static SupportedLocale getLocale(int index) {
|
public static SupportedLocale getLocale(int index) {
|
||||||
return Lang.get(LOCALES, index).orElse(DEFAULT);
|
return Lang.get(LOCALES, index).orElse(DEFAULT);
|
||||||
|
@ -96,7 +96,8 @@ public final class AccountItem extends StackPane {
|
|||||||
});
|
});
|
||||||
AccountHelper.loadSkinAsync((YggdrasilAccount) account)
|
AccountHelper.loadSkinAsync((YggdrasilAccount) account)
|
||||||
.subscribe(Schedulers.javafx(), this::loadSkin);
|
.subscribe(Schedulers.javafx(), this::loadSkin);
|
||||||
}
|
} else
|
||||||
|
loadSkin();
|
||||||
|
|
||||||
if (account instanceof OfflineAccount) { // Offline Account cannot be refreshed,
|
if (account instanceof OfflineAccount) { // Offline Account cannot be refreshed,
|
||||||
buttonPane.getChildren().remove(btnRefresh);
|
buttonPane.getChildren().remove(btnRefresh);
|
||||||
@ -104,12 +105,12 @@ public final class AccountItem extends StackPane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadSkin() {
|
private void loadSkin() {
|
||||||
if (!(account instanceof YggdrasilAccount))
|
|
||||||
return;
|
|
||||||
|
|
||||||
pgsSkin.setVisible(false);
|
pgsSkin.setVisible(false);
|
||||||
portraitView.setViewport(AccountHelper.getViewport(4));
|
portraitView.setViewport(AccountHelper.getViewport(4));
|
||||||
portraitView.setImage(AccountHelper.getSkin((YggdrasilAccount) account, 4));
|
if (account instanceof YggdrasilAccount)
|
||||||
|
portraitView.setImage(AccountHelper.getSkin((YggdrasilAccount) account, 4));
|
||||||
|
else
|
||||||
|
portraitView.setImage(AccountHelper.getDefaultSkin(account, 4));
|
||||||
FXUtils.limitSize(portraitView, 32, 32);
|
FXUtils.limitSize(portraitView, 32, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,10 @@ public final class Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void navigate(Node node) {
|
public static void navigate(Node node) {
|
||||||
decorator.showPage(node);
|
if (decorator.getNowPage() == node)
|
||||||
|
decorator.showPage(null);
|
||||||
|
else
|
||||||
|
decorator.showPage(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showUpdate() {
|
public static void showUpdate() {
|
||||||
|
@ -418,6 +418,10 @@ public final class Decorator extends StackPane implements TaskExecutorDialogWiza
|
|||||||
private String category;
|
private String category;
|
||||||
private Node nowPage;
|
private Node nowPage;
|
||||||
|
|
||||||
|
public Node getNowPage() {
|
||||||
|
return nowPage;
|
||||||
|
}
|
||||||
|
|
||||||
public void showPage(Node content) {
|
public void showPage(Node content) {
|
||||||
contentPlaceHolder.getStyleClass().removeAll("gray-background", "white-background");
|
contentPlaceHolder.getStyleClass().removeAll("gray-background", "white-background");
|
||||||
if (content != null)
|
if (content != null)
|
||||||
|
@ -68,7 +68,7 @@ public final class LeftPaneController {
|
|||||||
iconedItem.prefWidthProperty().bind(leftPane.widthProperty());
|
iconedItem.prefWidthProperty().bind(leftPane.widthProperty());
|
||||||
iconedItem.setOnMouseClicked(e -> Controllers.navigate(Controllers.getSettingsPage()));
|
iconedItem.setOnMouseClicked(e -> Controllers.navigate(Controllers.getSettingsPage()));
|
||||||
}))
|
}))
|
||||||
.startCategory(Main.i18n("profile").toUpperCase())
|
.startCategory(Main.i18n("profile.title").toUpperCase())
|
||||||
.add(profilePane);
|
.add(profilePane);
|
||||||
|
|
||||||
EventBus.EVENT_BUS.channel(ProfileLoadingEvent.class).register(this::onProfilesLoading);
|
EventBus.EVENT_BUS.channel(ProfileLoadingEvent.class).register(this::onProfilesLoading);
|
||||||
@ -90,23 +90,22 @@ public final class LeftPaneController {
|
|||||||
|
|
||||||
if (it instanceof YggdrasilAccount) {
|
if (it instanceof YggdrasilAccount) {
|
||||||
Image image = AccountHelper.getSkin((YggdrasilAccount) it, 4);
|
Image image = AccountHelper.getSkin((YggdrasilAccount) it, 4);
|
||||||
if (image == FXUtils.DEFAULT_ICON)
|
accountItem.setImage(image, AccountHelper.getViewport(4));
|
||||||
accountItem.setImage(FXUtils.DEFAULT_ICON, null);
|
|
||||||
else
|
|
||||||
accountItem.setImage(image, AccountHelper.getViewport(4));
|
|
||||||
} else
|
} else
|
||||||
accountItem.setImage(FXUtils.DEFAULT_ICON, null);
|
accountItem.setImage(AccountHelper.getDefaultSkin(it, 4), AccountHelper.getViewport(4));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onProfileChanged(ProfileChangedEvent event) {
|
private void onProfileChanged(ProfileChangedEvent event) {
|
||||||
Profile profile = event.getProfile();
|
Profile profile = event.getProfile();
|
||||||
|
|
||||||
for (Node node : profilePane.getChildren()) {
|
Platform.runLater(() -> {
|
||||||
if (node instanceof RipplerContainer && node.getProperties().get("profile") instanceof Pair<?, ?>) {
|
for (Node node : profilePane.getChildren()) {
|
||||||
((RipplerContainer) node).setSelected(Objects.equals(((Pair) node.getProperties().get("profile")).getKey(), profile.getName()));
|
if (node instanceof RipplerContainer && node.getProperties().get("profile") instanceof Pair<?, ?>) {
|
||||||
|
((RipplerContainer) node).setSelected(Objects.equals(((Pair) node.getProperties().get("profile")).getKey(), profile.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onProfilesLoading() {
|
private void onProfilesLoading() {
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
<StackPane.margin>
|
<StackPane.margin>
|
||||||
<Insets right="12" />
|
<Insets right="12" />
|
||||||
</StackPane.margin>
|
</StackPane.margin>
|
||||||
<Image url="/assets/img/icon.png" />
|
|
||||||
</ImageView>
|
</ImageView>
|
||||||
</StackPane>
|
</StackPane>
|
||||||
</fx:root>
|
</fx:root>
|
||||||
|
@ -285,6 +285,7 @@ profile.instance_directory=Game Directory
|
|||||||
profile.new=New Config
|
profile.new=New Config
|
||||||
profile.new_name=New Profile Name:
|
profile.new_name=New Profile Name:
|
||||||
profile.remove=Sure to remove profile %s?
|
profile.remove=Sure to remove profile %s?
|
||||||
|
profile.title=Game Directories
|
||||||
|
|
||||||
selector.choose=Choose
|
selector.choose=Choose
|
||||||
selector.choose_file=Select a file
|
selector.choose_file=Select a file
|
||||||
|
@ -161,7 +161,7 @@ launch.unsupported_launcher_version=对不起,本启动器现在可能不能
|
|||||||
launch.wrong_javadir=错误的Java路径,将自动重置为默认Java路径。
|
launch.wrong_javadir=错误的Java路径,将自动重置为默认Java路径。
|
||||||
|
|
||||||
launcher=启动器
|
launcher=启动器
|
||||||
launcher.about=默认背景图感谢gamerteam提供。\n关于作者:\n百度ID:huanghongxun20\nmcbbs:huanghongxun\nMinecraft Forum ID: klkl6523\n欢迎提交Bug哦\nCopyright (c) 2013-2017 huangyuhui.\n免责声明:Minecraft软件版权归Mojang AB所有,\n使用本软件产生的版权问题本软件制作方概不负责。\n本启动器在GPLv3协议下开源:https://github.com/huanghongxun/HMCL/ ,\n感谢issues和pull requests贡献者\n本软件使用了基于Apache License 2.0的Gson项目,感谢贡献者。
|
launcher.about=默认背景图感谢gamerteam提供。\n关于作者:\n百度ID:huanghongxun20; mcbbs:huanghongxun; Minecraft Forum ID: klkl6523\nCopyright (c) 2018 huangyuhui.\n免责声明:Minecraft软件版权归Mojang AB所有,\n使用本软件产生的版权问题本软件制作方概不负责。\n本启动器在GPLv3协议下开源:https://github.com/huanghongxun/HMCL/ ,\n感谢issues和pull requests贡献者\n本软件使用了基于Apache License 2.0的Gson项目,感谢贡献者。
|
||||||
launcher.background_location=背景地址
|
launcher.background_location=背景地址
|
||||||
launcher.background_tooltip=启动器默认使用自带的背景\n如果当前目录有background.png,则会使用该文件作为背景\n如果当前目录有bg子目录,则会随机使用里面的一张图作为背景\n如果该背景地址被修改,则会使用背景地址里的一张图作为背景\n背景地址允许有多个地址,使用半角分号";"(不包含双引号)分隔
|
launcher.background_tooltip=启动器默认使用自带的背景\n如果当前目录有background.png,则会使用该文件作为背景\n如果当前目录有bg子目录,则会随机使用里面的一张图作为背景\n如果该背景地址被修改,则会使用背景地址里的一张图作为背景\n背景地址允许有多个地址,使用半角分号";"(不包含双引号)分隔
|
||||||
launcher.choose_bgpath=选择背景路径
|
launcher.choose_bgpath=选择背景路径
|
||||||
@ -285,6 +285,7 @@ profile.instance_directory=游戏路径
|
|||||||
profile.new=新建配置
|
profile.new=新建配置
|
||||||
profile.new_name=新配置名:
|
profile.new_name=新配置名:
|
||||||
profile.remove=真的要删除配置%s吗?
|
profile.remove=真的要删除配置%s吗?
|
||||||
|
profile.title=游戏目录
|
||||||
|
|
||||||
selector.choose=选择
|
selector.choose=选择
|
||||||
selector.choose_file=选择文件
|
selector.choose_file=选择文件
|
||||||
|
@ -20,6 +20,7 @@ package org.jackhuang.hmcl.auth;
|
|||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -32,6 +33,11 @@ public abstract class Account {
|
|||||||
*/
|
*/
|
||||||
public abstract String getUsername();
|
public abstract String getUsername();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the UUID
|
||||||
|
*/
|
||||||
|
public abstract UUID getUUID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* log in.
|
* log in.
|
||||||
* @param selector selects a character
|
* @param selector selects a character
|
||||||
|
@ -20,10 +20,12 @@ package org.jackhuang.hmcl.auth;
|
|||||||
import org.jackhuang.hmcl.util.Lang;
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
import org.jackhuang.hmcl.util.Pair;
|
import org.jackhuang.hmcl.util.Pair;
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
|
import org.jackhuang.hmcl.util.UUIDTypeAdapter;
|
||||||
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -45,8 +47,8 @@ public class OfflineAccount extends Account {
|
|||||||
throw new IllegalArgumentException("Username cannot be blank");
|
throw new IllegalArgumentException("Username cannot be blank");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUuid() {
|
public UUID getUUID() {
|
||||||
return uuid;
|
return UUIDTypeAdapter.fromString(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -244,6 +244,13 @@ public final class YggdrasilAccount extends Account {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getUUID() {
|
||||||
|
if (getSelectedProfile() == null)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return getSelectedProfile().getId();
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<ProfileTexture> getSkin(GameProfile profile) throws IOException, JsonParseException {
|
public Optional<ProfileTexture> getSkin(GameProfile profile) throws IOException, JsonParseException {
|
||||||
if (StringUtils.isBlank(userId))
|
if (StringUtils.isBlank(userId))
|
||||||
throw new IllegalStateException("Not logged in");
|
throw new IllegalStateException("Not logged in");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user