Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
import org.jackhuang.hmcl.auth.yggdrasil.CompleteGameProfile;
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
import org.jackhuang.hmcl.auth.yggdrasil.TextureType;
import org.jackhuang.hmcl.setting.Accounts;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.DialogController;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.skin.InvalidSkinException;
Expand All @@ -49,14 +52,16 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;

import static java.util.Collections.emptySet;
import static javafx.beans.binding.Bindings.createBooleanBinding;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

public class AccountListItem extends RadioButton {

Expand All @@ -73,9 +78,7 @@ public AccountListItem(Account account) {
String portableSuffix = account.isPortable() ? ", " + i18n("account.portable") : "";
if (account instanceof AuthlibInjectorAccount) {
AuthlibInjectorServer server = ((AuthlibInjectorAccount) account).getServer();
subtitle.bind(Bindings.concat(
loginTypeName, ", ", i18n("account.injector.server"), ": ",
Bindings.createStringBinding(server::getName, server), portableSuffix));
subtitle.bind(Bindings.concat(loginTypeName, ", ", i18n("account.injector.server"), ": ", Bindings.createStringBinding(server::getName, server), portableSuffix));
} else {
subtitle.set(loginTypeName + portableSuffix);
}
Expand All @@ -84,9 +87,7 @@ public AccountListItem(Account account) {
if (account instanceof OfflineAccount) {
title.bind(characterName);
} else {
title.bind(
account.getUsername().isEmpty() ? characterName :
Bindings.concat(account.getUsername(), " - ", characterName));
title.bind(account.getUsername().isEmpty() ? characterName : Bindings.concat(account.getUsername(), " - ", characterName));
}
}

Expand Down Expand Up @@ -120,9 +121,7 @@ public ObservableBooleanValue canUploadSkin() {
if (account instanceof AuthlibInjectorAccount aiAccount) {
ObjectBinding<Optional<CompleteGameProfile>> profile = aiAccount.getYggdrasilService().getProfileRepository().binding(aiAccount.getUUID());
return createBooleanBinding(() -> {
Set<TextureType> uploadableTextures = profile.get()
.map(AuthlibInjectorAccount::getUploadableTextures)
.orElse(emptySet());
Set<TextureType> uploadableTextures = profile.get().map(AuthlibInjectorAccount::getUploadableTextures).orElse(emptySet());
return uploadableTextures.contains(TextureType.SKIN);
}, profile);
} else if (account instanceof OfflineAccount || account.canUploadSkin()) {
Expand Down Expand Up @@ -153,28 +152,60 @@ public Task<?> uploadSkin() {
return null;
}

return refreshAsync()
.thenRunAsync(() -> {
Image skinImg;
try (var input = Files.newInputStream(selectedFile)) {
skinImg = new Image(input);
} catch (IOException e) {
throw new InvalidSkinException("Failed to read skin image", e);
}
if (skinImg.isError()) {
throw new InvalidSkinException("Failed to read skin image", skinImg.getException());
}
NormalizedSkin skin = new NormalizedSkin(skinImg);
String model = skin.isSlim() ? "slim" : "";
LOG.info("Uploading skin [" + selectedFile + "], model [" + model + "]");
account.uploadSkin(skin.isSlim(), selectedFile);
})
.thenComposeAsync(refreshAsync())
.whenComplete(Schedulers.javafx(), e -> {
if (e != null) {
Controllers.dialog(Accounts.localizeErrorMessage(e), i18n("account.skin.upload.failed"), MessageType.ERROR);
}
});
return refreshAsync().thenSupplyAsync(() -> {
Image skinImg;
try (var input = Files.newInputStream(selectedFile)) {
skinImg = new Image(input);
} catch (IOException e) {
throw new InvalidSkinException("Failed to read skin image", e);
}
if (skinImg.isError()) {
throw new InvalidSkinException("Failed to read skin image", skinImg.getException());
}

return new NormalizedSkin(skinImg);
}).thenApplyAsync(Schedulers.javafx(), (normalizedSkin) -> {
boolean isSlim = normalizedSkin.isSlim();

CompletableFuture<TextureModel> modelFuture = new CompletableFuture<>();

FXUtils.runInFX(() -> {
MessageDialogPane.Builder builder = new MessageDialogPane.Builder(
i18n("account.skin.model.select"),
i18n("account.skin.upload"),
MessageDialogPane.MessageType.QUESTION
);

if (isSlim) {
builder.addAction(i18n("account.skin.model.slim") + " " + i18n("account.skin.model.auto"),
() -> modelFuture.complete(TextureModel.SLIM));
builder.addAction(i18n("account.skin.model.default"),
() -> modelFuture.complete(TextureModel.WIDE));
} else {
builder.addAction(i18n("account.skin.model.default") + " " + i18n("account.skin.model.auto"),
() -> modelFuture.complete(TextureModel.WIDE));
builder.addAction(i18n("account.skin.model.slim"),
() -> modelFuture.complete(TextureModel.SLIM));
}

builder.addCancel(() -> modelFuture.complete(null));
Controllers.dialog(builder.build());
});

return modelFuture;
}).thenApplyAsync((future) -> {
if (future == null) {
return null;
}
TextureModel model = future.get();
LOG.info("Uploading skin [" + selectedFile + "], model [" + model.modelName + "]");
account.uploadSkin(Objects.equals(TextureModel.SLIM, model), selectedFile);
return null;
}).thenComposeAsync(refreshAsync()).whenComplete(Schedulers.javafx(), e -> {
if (e != null) {
Controllers.dialog(Accounts.localizeErrorMessage(e), i18n("account.skin.upload.failed"), MessageType.ERROR);
}
});
}

public void remove() {
Expand Down
2 changes: 2 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ account.skin.file=Skin File
account.skin.model=Model
account.skin.model.default=Classic
account.skin.model.slim=Slim
account.skin.model.auto=(Auto)
account.skin.model.select=The model of the skin you chose is?
account.skin.type.alex=Alex
account.skin.type.csl_api=Blessing Skin
account.skin.type.csl_api.location=Address
Expand Down
2 changes: 2 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ account.skin.file=外觀圖片檔案
account.skin.model=模型
account.skin.model.default=寬型
account.skin.model.slim=纖細
account.skin.model.auto=(自動識別)
account.skin.model.select=你選取的外觀模型是?
account.skin.type.alex=Alex
account.skin.type.csl_api=Blessing Skin 伺服器
account.skin.type.csl_api.location=伺服器位址
Expand Down
2 changes: 2 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ account.skin.file=皮肤图片文件
account.skin.model=模型
account.skin.model.default=宽型
account.skin.model.slim=纤细
account.skin.model.auto=(自动识别)
account.skin.model.select=你选择的皮肤模型是?
account.skin.type.alex=Alex
account.skin.type.csl_api=Blessing Skin 服务器
account.skin.type.csl_api.location=服务器地址
Expand Down