Skip to content
Closed
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 @@ -20,6 +20,7 @@
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialogLayout;
import com.jfoenix.controls.JFXListView;
import com.jfoenix.controls.JFXTextField;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
Expand Down Expand Up @@ -55,6 +56,7 @@
import java.util.*;
import java.util.stream.Stream;

import static javafx.application.Platform.runLater;
import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
Expand All @@ -65,8 +67,12 @@
public final class SchematicsPage extends ListPageBase<SchematicsPage.Item> implements VersionPage.VersionLoadable {

private static String translateAuthorName(String author) {
if (I18n.isUseChinese() && "hsds".equals(author)) {
return "黑山大叔";
if (I18n.isUseChinese()){
return switch (author) {
case "hsds" -> "黑山大叔";
case "CNJ233" -> "长安街";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议添加太多的特判

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实如此

default -> author;
};
}
return author;
}
Expand Down Expand Up @@ -482,9 +488,30 @@ private void addDetailItem(String key, Object detail) {
details.getContent().add(borderPane);
}

private void addEditableDetailItem(String key, String text, EditHandler h) {
BorderPane borderPane = new BorderPane();
BorderPane labelBorderPane = new BorderPane();

labelBorderPane.setCenter(new Label(key));
borderPane.setLeft(labelBorderPane);

var nameEditField = new JFXTextField();
nameEditField.setText(text);
Validator.addTo(nameEditField).accept(
fileName -> {
if (!Objects.equals(fileName, "")){
h.setValue(nameEditField.getText());
return true;
}else return false;
}
);
borderPane.setRight(nameEditField);
details.getContent().add(borderPane);
}

private void updateContent(LitematicFile file) {
details.getContent().clear();
addDetailItem(i18n("schematics.info.name"), file.getName());
addEditableDetailItem(i18n("schematics.info.name"), file.getName(), file::setName);
if (StringUtils.isNotBlank(file.getAuthor()))
addDetailItem(i18n("schematics.info.schematic_author"), translateAuthorName(file.getAuthor()));
if (file.getTimeCreated() != null)
Expand Down Expand Up @@ -531,14 +558,53 @@ private void updateContent(LitematicFile file) {
JFXButton okButton = new JFXButton();
okButton.getStyleClass().add("dialog-accept");
okButton.setText(i18n("button.ok"));
okButton.setOnAction(e -> fireEvent(new DialogCloseEvent()));
okButton.setOnAction(e -> {
try {
LitematicFile.save(file);
fireEvent(new DialogCloseEvent());
LOG.info("Saved litematic file: " + file.getFile());
} catch (IOException ex) {
LOG.error("Cannot save litematic file", ex);
showErrorDialog(ex);
}
});
getActions().add(okButton);

onEscPressed(this, okButton::fire);
}

updateContent(file);
}

private void showErrorDialog(Exception exception){
LitematicInfoDialog lid = this;
var dialog = new MessageDialogPane.Builder(
i18n("schematics.error.save") + "\n" + StringUtils.getStackTrace(exception),
i18n("message.error"),
MessageDialogPane.MessageType.ERROR
).ok(() -> DialogUtils.close(lid)).build();

Node p = lid.getParent();
while (p != null && !(p instanceof StackPane)) p = p.getParent();
if (p instanceof StackPane container) {
DialogUtils.show(container, dialog);
} else {
runLater(() -> {
Node p2 = lid.getParent();
while (p2 != null && !(p2 instanceof StackPane)) p2 = p2.getParent();
if (p2 instanceof StackPane container2) {
DialogUtils.show(container2, dialog);
} else {
Controllers.dialog(dialog);
}
});
}
}

@FunctionalInterface
private interface EditHandler {
void setValue(String value);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ schematics.info.total_volume=Total Volume
schematics.info.version=Schematic Version
schematics.manage=Schematics
schematics.sub_items=%d sub-item(s)
schematics.error.save=failed to save file

search=Search
search.hint.chinese=Search in English and Chinese
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_ar.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ schematics.info.total_volume=الحجم الإجمالي
schematics.info.version=إصدار المخطط
schematics.manage=المخططات
schematics.sub_items=%d عنصر فرعي
schematics.error.save=فشل في حفظ الملف

search=بحث
search.hint.chinese=البحث بالإنجليزية والصينية
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ schematics.info.total_volume=Volumen total
schematics.info.version=Versión de esquema
schematics.manage=Esquemas
schematics.sub_items=%d elemento(s)
schematics.error.save=No se pudo guardar el archivo

search=Búsqueda
search.hint.chinese=Buscar en inglés y chino
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_lzh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ schematics.info.total_volume=總體積
schematics.info.version=蜃圖之版
schematics.manage=司蜃圖
schematics.sub_items=%d 子项
schematics.error.save=存檔未成

search=尋
search.hint.chinese=以中英文尋
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ schematics.info.total_volume=Общий объём
schematics.info.version=Версия схемы
schematics.manage=Схемы
schematics.sub_items=%d элемент(ов)
schematics.error.save=Не удалось сохранить файл

search=Поиск
search.hint.chinese=Поиск на китайском и английском языках
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_uk.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ schematics.info.total_volume=Загальний об'єм
schematics.info.version=Версія схематики
schematics.manage=Схематики
schematics.sub_items=%d підпунктів
schematics.error.save=Збереження файлу не вдалося

search=Пошук
search.hint.chinese=Пошук англійською та китайською
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ schematics.info.total_volume=總體積
schematics.info.version=原理圖版本
schematics.manage=原理圖管理
schematics.sub_items=%d 個子項
schematics.error.save=保存檔案失敗

search=搜尋
search.hint.chinese=支援中英文搜尋
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ schematics.info.total_volume=总体积
schematics.info.version=原理图版本
schematics.manage=原理图管理
schematics.sub_items=%d 个子项
schematics.error.save=保存文件失败

search=搜索
search.hint.chinese=支持中英文搜索
Expand Down
Loading
Loading