diff --git a/src/main/java/net/modfest/scatteredshards/api/shard/Shard.java b/src/main/java/net/modfest/scatteredshards/api/shard/Shard.java index 5f6b21b..abb2ccf 100644 --- a/src/main/java/net/modfest/scatteredshards/api/shard/Shard.java +++ b/src/main/java/net/modfest/scatteredshards/api/shard/Shard.java @@ -20,6 +20,7 @@ import java.util.Objects; import java.util.Optional; +import java.util.OptionalInt; import java.util.stream.Stream; public class Shard { @@ -31,7 +32,8 @@ public class Shard { TextCodecs.CODEC.fieldOf("lore").forGetter(Shard::lore), TextCodecs.CODEC.fieldOf("hint").forGetter(Shard::hint), Identifier.CODEC.fieldOf("source_id").forGetter(Shard::sourceId), - ICON_CODEC.fieldOf("icon").forGetter(Shard::icon) + ICON_CODEC.fieldOf("icon").forGetter(Shard::icon), + Codec.intRange(0, Integer.MAX_VALUE).optionalFieldOf("list_order").forGetter(Shard::listOrder) ).apply(instance, Shard::new)); public static final PacketCodec PACKET_CODEC = PacketCodecs.codec(CODEC).cast(); @@ -39,16 +41,17 @@ public class Shard { public static final Identifier MISSING_ICON_ID = ScatteredShards.id("textures/gui/shards/missing_icon.png"); public static final Either MISSING_ICON = Either.right(MISSING_ICON_ID); public static final Identifier MISSING_SHARD_SOURCE = ScatteredShards.id("missing"); - public static final Shard MISSING_SHARD = new Shard(ShardType.MISSING_ID, Text.of("Missing"), Text.of(""), Text.of(""), MISSING_SHARD_SOURCE, MISSING_ICON); + public static final Shard MISSING_SHARD = new Shard(ShardType.MISSING_ID, Text.of("Missing"), Text.of(""), Text.of(""), MISSING_SHARD_SOURCE, MISSING_ICON, Optional.empty()); protected Identifier shardTypeId; protected Text name; protected Text lore; protected Text hint; + protected Integer listOrder; protected Identifier sourceId; protected Either icon; - public Shard(Identifier shardTypeId, Text name, Text lore, Text hint, Identifier sourceId, Either icon) { + public Shard(Identifier shardTypeId, Text name, Text lore, Text hint, Identifier sourceId, Either icon, Optional listOrder) { Stream.of(name, lore, hint, icon).forEach(Objects::requireNonNull); this.shardTypeId = shardTypeId; this.name = name; @@ -56,6 +59,7 @@ public Shard(Identifier shardTypeId, Text name, Text lore, Text hint, Identifier this.hint = hint; this.sourceId = sourceId; this.icon = icon; + this.listOrder = listOrder.orElse(null); } public Identifier shardTypeId() { @@ -74,6 +78,10 @@ public Text hint() { return hint; } + public Optional listOrder() { + return listOrder == null ? Optional.empty() : Optional.of(listOrder); + } + public Identifier sourceId() { return sourceId; } @@ -102,6 +110,11 @@ public Shard setHint(Text value) { return this; } + public Shard setListOrder(Integer value) { + this.listOrder = value; + return this; + } + public Shard setIcon(Either icon) { this.icon = icon; return this; @@ -136,7 +149,7 @@ public JsonObject toJson() { public Shard copy() { Either icon = icon().mapBoth(stack -> stack, id -> id); - return new Shard(shardTypeId, name.copy(), lore.copy(), hint.copy(), sourceId, icon); + return new Shard(shardTypeId, name.copy(), lore.copy(), hint.copy(), sourceId, icon, listOrder()); } @Override diff --git a/src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java b/src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java index ed13055..b080e25 100644 --- a/src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java +++ b/src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java @@ -52,6 +52,7 @@ public class ShardCreatorGuiDescription extends LightweightGuiDescription { public static final Text NAME_TEXT = Text.translatable("gui.scattered_shards.creator.field.name"); public static final Text LORE_TEXT = Text.translatable("gui.scattered_shards.creator.field.lore"); public static final Text HINT_TEXT = Text.translatable("gui.scattered_shards.creator.field.hint"); + public static final Text ORDER_TEXT = Text.translatable("gui.scattered_shards.creator.field.order"); public static final Text TEXTURE_TEXT = Text.translatable("gui.scattered_shards.creator.field.texture"); public static final Text ICON_TEXTURE_TEXT = Text.translatable("gui.scattered_shards.creator.icon.texture"); public static final Text ICON_ITEM_TEXT = Text.translatable("gui.scattered_shards.creator.icon.item"); @@ -84,6 +85,19 @@ public class ShardCreatorGuiDescription extends LightweightGuiDescription { .setTextChangedListener(it -> shard.setHint(it)) .setMaxLength(70); + public WProtectableField listOrderField = new WProtectableField(ORDER_TEXT) + .setTextChangedListener(it -> { + if (it.getString().isEmpty()) { + shard.setListOrder(null); + } else { + try { + shard.setListOrder(Integer.parseInt(it.getString())); + } catch (NumberFormatException ignored) { + shard.setListOrder(null); + } + } + }).setMaxLength(8); + public WAlternativeToggle iconToggle = new WAlternativeToggle(ICON_TEXTURE_TEXT, ICON_ITEM_TEXT); public WCardPanel cardPanel = new WCardPanel(); public WLayoutBox textureIconPanel = new WLayoutBox(Axis.VERTICAL); @@ -244,6 +258,7 @@ public ShardCreatorGuiDescription(Identifier shardId, Shard shard, String modId) this.nameField.setText(shard.name().getLiteralString()); this.loreField.setText(shard.lore().getLiteralString()); this.hintField.setText(shard.hint().getLiteralString()); + this.listOrderField.setText(shard.listOrder().map(i -> Integer.toString(i)).orElse("")); shard.icon().ifRight(a -> { this.iconToggle.setLeft(); if (Objects.equals(a, modIcon)) { @@ -279,7 +294,7 @@ public ShardCreatorGuiDescription(Identifier shardId) { editorPanel.setSpacing(3); editorPanel.setHorizontalAlignment(HorizontalAlignment.LEFT); - editorPanel.add(titleLabel); + // editorPanel.add(titleLabel); editorPanel.add(nameField); editorPanel.add(loreField); editorPanel.add(hintField); @@ -300,6 +315,8 @@ public ShardCreatorGuiDescription(Identifier shardId) { itemIconPanel.add(itemField); itemIconPanel.add(componentField); + editorPanel.add(listOrderField); + editorPanel.add(saveButton); iconToggle.onLeft(() -> { diff --git a/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardSetPanel.java b/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardSetPanel.java index 86e2a49..5dac530 100644 --- a/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardSetPanel.java +++ b/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardSetPanel.java @@ -56,15 +56,19 @@ public void setShardSet(Identifier setId, ShardLibrary library, ShardCollection List shardSet = new ArrayList<>(library.shardSets().get(setId)); shardSet.sort((a, b) -> { int aPriority = library.shards().get(a) - .map(Shard::shardTypeId) - .flatMap(library.shardTypes()::get) - .map(ShardType::listOrder) + .map(Shard::listOrder) + .orElseGet(() -> library.shards().get(a) + .map(Shard::shardTypeId) + .flatMap(library.shardTypes()::get) + .map(ShardType::listOrder)) .orElse(Integer.MAX_VALUE); int bPriority = library.shards().get(b) - .map(Shard::shardTypeId) - .flatMap(library.shardTypes()::get) - .map(ShardType::listOrder) + .map(Shard::listOrder) + .orElseGet(() -> library.shards().get(b) + .map(Shard::shardTypeId) + .flatMap(library.shardTypes()::get) + .map(ShardType::listOrder)) .orElse(Integer.MAX_VALUE); return Integer.compare(aPriority, bPriority); diff --git a/src/main/resources/assets/scattered_shards/lang/en_us.json b/src/main/resources/assets/scattered_shards/lang/en_us.json index ad6bf1b..2528cd4 100644 --- a/src/main/resources/assets/scattered_shards/lang/en_us.json +++ b/src/main/resources/assets/scattered_shards/lang/en_us.json @@ -38,6 +38,7 @@ "gui.scattered_shards.creator.field.name": "Name...", "gui.scattered_shards.creator.field.lore": "Lore...", "gui.scattered_shards.creator.field.hint": "Hint...", + "gui.scattered_shards.creator.field.order": "Order (Ascending, Empty for Default)", "gui.scattered_shards.creator.icon.texture": "Texture Icon", "gui.scattered_shards.creator.icon.item": "Item Icon", "gui.scattered_shards.creator.field.item.id": "Item ID...", diff --git a/src/main/resources/assets/scattered_shards/lang/zh_cn.json b/src/main/resources/assets/scattered_shards/lang/zh_cn.json index c19615b..90b7fb2 100644 --- a/src/main/resources/assets/scattered_shards/lang/zh_cn.json +++ b/src/main/resources/assets/scattered_shards/lang/zh_cn.json @@ -39,5 +39,6 @@ "gui.scattered_shards.creator.field.item.component": "物品组件...", "gui.scattered_shards.tablet.tooltip.global_collection": "%s 的人有这张卡", "gui.scattered_shards.tablet.label.progress.sets": "已参观 %d/%d 个模组", - "gui.scattered_shards.tablet.label.progress.cards": "%d/%d 张卡片" + "gui.scattered_shards.tablet.label.progress.cards": "%d/%d 张卡片", + "gui.scattered_shards.creator.field.order": "序号 (递增排序, 留空取卡面默认)" } diff --git a/src/main/resources/assets/scattered_shards/lang/zh_tw.json b/src/main/resources/assets/scattered_shards/lang/zh_tw.json index 2c556a6..c5fbb51 100644 --- a/src/main/resources/assets/scattered_shards/lang/zh_tw.json +++ b/src/main/resources/assets/scattered_shards/lang/zh_tw.json @@ -39,5 +39,6 @@ "gui.scattered_shards.creator.field.item.component": "物品組件...", "gui.scattered_shards.tablet.tooltip.global_collection": "%s 的人有這張卡", "gui.scattered_shards.tablet.label.progress.sets": "已參觀 %d/%d 個模組", - "gui.scattered_shards.tablet.label.progress.cards": "%d/%d 張卡片" + "gui.scattered_shards.tablet.label.progress.cards": "%d/%d 張卡片", + "gui.scattered_shards.creator.field.order": "序號 (遞增排序, 留空取卡面缺省)" }