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 @@ -17,7 +17,10 @@
*/
package org.jackhuang.hmcl.ui.construct;

import javafx.beans.InvalidationListener;
import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
Expand All @@ -30,22 +33,33 @@
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.util.AggregatedObservableList;

import java.util.stream.Collectors;

import static org.jackhuang.hmcl.util.i18n.I18n.i18n;

public class TwoLineListItem extends VBox {
private static final String DEFAULT_STYLE_CLASS = "two-line-list-item";
private static final int UNLIMITED_TAGS = -1;

private static Label createTagLabel(String tag) {
Label tagLabel = new Label();
tagLabel.setText(tag);
HBox.setMargin(tagLabel, new Insets(0, 8, 0, 0));
private static Label createTagLabel(String tag, String StyleClass) {
Label tagLabel = FXUtils.newSafeTruncatedLabel(tag);
HBox.setMargin(tagLabel, new Insets(0, 6, 0, 0));
tagLabel.getStyleClass().add(StyleClass);
return tagLabel;
}

private final StringProperty title = new SimpleStringProperty(this, "title");
private final ObservableList<Label> tags = FXCollections.observableArrayList();
private final ObservableList<Label> allTags = FXCollections.observableArrayList();
private final ObservableList<Label> shownTags = FXCollections.observableArrayList();
private final StringProperty subtitle = new SimpleStringProperty(this, "subtitle");

private IntegerProperty maxShownTags = new SimpleIntegerProperty(UNLIMITED_TAGS);
private boolean updateScheduled = false;

private final AggregatedObservableList<Node> firstLineChildren;

private final Label overflowLabel = createTagLabel("", "tag-overflow");

public TwoLineListItem(String titleString, String subtitleString) {
this();

Expand All @@ -54,23 +68,27 @@ public TwoLineListItem(String titleString, String subtitleString) {
}

public TwoLineListItem() {
setMouseTransparent(true);

HBox firstLine = new HBox();
firstLine.getStyleClass().add("first-line");

Label lblTitle = new Label();
lblTitle.getStyleClass().add("title");
lblTitle.textProperty().bind(title);
FXUtils.showTooltipWhenTruncated(lblTitle);

firstLineChildren = new AggregatedObservableList<>();
firstLineChildren.appendList(FXCollections.singletonObservableList(lblTitle));
firstLineChildren.appendList(tags);
firstLineChildren.appendList(shownTags);
allTags.addListener((InvalidationListener) observable -> updateShownTags());
maxShownTags.addListener(observable -> updateShownTags());

Bindings.bindContent(firstLine.getChildren(), firstLineChildren.getAggregatedList());

Label lblSubtitle = new Label();
lblSubtitle.getStyleClass().add("subtitle");
lblSubtitle.textProperty().bind(subtitle);
FXUtils.showTooltipWhenTruncated(lblSubtitle);

HBox secondLine = new HBox();
secondLine.getChildren().setAll(lblSubtitle);
Expand All @@ -85,6 +103,19 @@ public TwoLineListItem() {
getStyleClass().add(DEFAULT_STYLE_CLASS);
}

private void updateShownTags() {
shownTags.clear();
if (maxShownTags.get() == UNLIMITED_TAGS || allTags.size() <= maxShownTags.get()) {
shownTags.addAll(allTags);
} else {
shownTags.addAll(allTags.subList(0, maxShownTags.get()));
FXUtils.installFastTooltip(overflowLabel, allTags.stream().skip(maxShownTags.get())
.map(Label::getText).collect(Collectors.joining("\n")));
overflowLabel.setText(i18n("tag.overflow", (allTags.size() - maxShownTags.get())));
shownTags.add(overflowLabel);
}
}

public String getTitle() {
return title.get();
}
Expand All @@ -110,19 +141,29 @@ public void setSubtitle(String subtitle) {
}

public void addTag(String tag) {
Label tagLabel = createTagLabel(tag);
tagLabel.getStyleClass().add("tag");
getTags().add(tagLabel);
getTags().add(createTagLabel(tag, "tag"));
}

public void addTagWarning(String tag) {
Label tagLabel = createTagLabel(tag);
tagLabel.getStyleClass().add("tag-warning");
getTags().add(tagLabel);
getTags().add(createTagLabel(tag, "tag-warning"));
}

public ObservableList<Label> getTags() {
return tags;
return allTags;
}

public void setMaxShownTags(int maxShownTags) {
if (maxShownTags >= 0) {
this.maxShownTags.set(maxShownTags);
}
}

public IntegerProperty getMaxShownTags() {
return maxShownTags;
}

public void clearTags() {
allTags.clear();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void updateItem(RemoteVersion remoteVersion, boolean empty) {
} else {
twoLineListItem.setSubtitle(null);
}
twoLineListItem.getTags().clear();
twoLineListItem.clearTags();

if (remoteVersion instanceof GameRemoteVersion) {
RemoteVersion.Type versionType = remoteVersion.getVersionType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ protected void updateControl(RemoteMod dataItem, boolean empty) {
ModTranslations.Mod mod = ModTranslations.getTranslationsByRepositoryType(getSkinnable().repository.getType()).getModByCurseForgeId(dataItem.getSlug());
content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : dataItem.getTitle());
content.setSubtitle(dataItem.getDescription());
content.getTags().clear();
content.setMaxShownTags(4);
content.clearTags();
dataItem.getCategories().stream()
.map(category -> getSkinnable().getLocalizedCategory(category))
.forEach(content::addTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ protected ModDownloadPageSkin(DownloadPage control) {
ModTranslations.Mod mod = getSkinnable().translations.getModByCurseForgeId(getSkinnable().addon.getSlug());
content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : getSkinnable().addon.getTitle());
content.setSubtitle(getSkinnable().addon.getDescription());
content.setMaxShownTags(4);
getSkinnable().addon.getCategories().stream()
.map(category -> getSkinnable().page.getLocalizedCategory(category))
.forEach(content::addTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public GameItemSkin(GameItem skinnable) {
TwoLineListItem item = new TwoLineListItem();
item.titleProperty().bind(skinnable.titleProperty());
FXUtils.onChangeAndOperate(skinnable.tagProperty(), tag -> {
item.getTags().clear();
item.clearTags();
if (StringUtils.isNotBlank(tag))
item.addTag(tag);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ protected void updateControl(ModInfoObject dataItem, boolean empty) {

List<String> warning = new ArrayList<>();

content.getTags().clear();
content.clearTags();

LocalModFile modInfo = dataItem.getModInfo();
ModTranslations.Mod modTranslations = dataItem.getModTranslations();
Expand Down
10 changes: 9 additions & 1 deletion HMCL/src/main/resources/assets/css/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,21 @@
}

.two-line-list-item > .first-line > .tag-warning {
-fx-text-fill: #d34336;;
-fx-text-fill: #d34336;
-fx-background-color: #f1aeb5;
-fx-padding: 2;
-fx-font-weight: normal;
-fx-font-size: 12px;
}

.two-line-list-item > .first-line > .tag-overflow {
-fx-text-fill: -fx-base-color;
-fx-background-color: rgba(202, 227, 244, 0.3);
-fx-padding: 2;
-fx-font-weight: normal;
-fx-font-size: 12px;
}

.two-line-item-second-large {

}
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 @@ -1109,6 +1109,8 @@ datapack.choose_datapack=Choose datapack to import
datapack.extension=Datapack
datapack.title=World [%s] - Datapacks

tag.overflow=+%d more

web.failed=Failed to load page
web.open_in_browser=Do you want to open this address in a browser:\n%s
web.view_in_browser=View all in browser
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 @@ -906,6 +906,8 @@ datapack.choose_datapack=選取要匯入的資料包壓縮檔
datapack.extension=資料包
datapack.title=世界 [%s] - 資料包

tag.overflow=+%d 更多

web.failed=載入頁面失敗
web.open_in_browser=是否要在瀏覽器中開啟此連結:\n%s
web.view_in_browser=在瀏覽器中查看完整日誌
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 @@ -916,6 +916,8 @@ datapack.choose_datapack=选择要导入的数据包压缩包
datapack.extension=数据包
datapack.title=世界 [%s] - 数据包

tag.overflow=+%d 更多

web.failed=加载页面失败
web.open_in_browser=是否要在浏览器中打开此链接:\n%s
web.view_in_browser=在浏览器中查看完整日志
Expand Down