diff --git a/src/main/java/net/tfminecraft/activitytf/config/ActivityConfiguration.java b/src/main/java/net/tfminecraft/activitytf/config/ActivityConfiguration.java index 7f6e8c7..54a069b 100644 --- a/src/main/java/net/tfminecraft/activitytf/config/ActivityConfiguration.java +++ b/src/main/java/net/tfminecraft/activitytf/config/ActivityConfiguration.java @@ -124,6 +124,7 @@ public static String referencedPool(RewardEntry entry) { } private String guiTitle; + private volatile Map poolDisplayNames = Map.of(); private volatile int barMax; private volatile int dailyMax; @@ -193,6 +194,7 @@ public void load() { } guiTitle = config.getString("gui.title", "&8Weekly Activity"); + poolDisplayNames = loadPoolDisplayNames(config); barLength = barLength(config.getInt("bar.length", 40)); @@ -1472,6 +1474,26 @@ public String guiTitle() { return guiTitle; } + /** The short name gui.pool-names gives a reward pool for the weekly icon, or null. */ + public String poolDisplayName(String pool) { + return pool == null ? null : poolDisplayNames.get(poolName(pool)); + } + + private Map loadPoolDisplayNames(ConfigurationSection config) { + ConfigurationSection names = section(config, "gui.pool-names"); + if (names == null) { + return Map.of(); + } + Map loaded = new LinkedHashMap<>(); + for (String key : keys(names)) { + String name = names.isString(key) ? names.getString(key) : null; + if (name != null && !name.isBlank()) { + loaded.put(poolName(key), name); + } + } + return Map.copyOf(loaded); + } + public int barMax() { return barMax; } diff --git a/src/main/java/net/tfminecraft/activitytf/gui/ActivityGui.java b/src/main/java/net/tfminecraft/activitytf/gui/ActivityGui.java index 65fd1a6..034d406 100644 --- a/src/main/java/net/tfminecraft/activitytf/gui/ActivityGui.java +++ b/src/main/java/net/tfminecraft/activitytf/gui/ActivityGui.java @@ -46,6 +46,9 @@ public class ActivityGui implements Listener { private static final int PROGRESS_BAR_LENGTH = 20; + /** Most reward options the weekly icon lists before it sums up the rest. */ + static final int MAX_PREVIEW_LINES = 10; + private final ActivityManager manager; private Consumer referralOpener; @@ -150,7 +153,7 @@ private ItemStack barItem(ActivityConfiguration config, Messages messages, Playe lore.add(Utils.colorize(bar)); lore.add(" "); lore.addAll(weeklyRewardLore(messages, data, milestones, config.milestoneDrops(), - config.rewardMultiplier(), config.multiplierPools(), config::rewardPool)); + config.rewardMultiplier(), config.multiplierPools(), config::rewardPool, config::poolDisplayName)); return item(Material.EXPERIENCE_BOTTLE, messages.get("gui.bar-name", "%points%", data.points(), "%max%", config.barMax()), @@ -159,7 +162,8 @@ private ItemStack barItem(ActivityConfiguration config, Messages messages, Playe static List weeklyRewardLore(Messages messages, PlayerData data, List milestones, Map drops, int multiplier, Set multiplierPools, - Function> pools) { + Function> pools, + Function poolNames) { List lore = new ArrayList<>(); int due = data.claimable(milestones); Integer next = nextMilestone(data, milestones); @@ -168,50 +172,135 @@ static List weeklyRewardLore(Messages messages, PlayerData data, List rewards = nextRewardDisplays(next, drops, multiplier, pools); - if (pool == null && rewards.size() == 1) { + boolean noteShown = false; + String pool = poolOf(drops.get(next)); + if (pool == null) { lore.add(messages.get("gui.bar-lore-reward", "%points%", next, "%reward%", - Utils.colorize(rewards.get(0)))); + Utils.colorize(fixedDisplay(drops.get(next), multiplier)))); } else { lore.add(messages.get("gui.bar-lore-next-options", "%points%", next)); + RewardPreview.Preview preview = RewardPreview.preview(entries(pools, pool)); + List rewards = preview.lines(); if (rewards.isEmpty()) { lore.add(messages.get("gui.reward-preview-unavailable")); } else { - int draws = multiplierPools.contains(pool) ? multiplier : 1; + int draws = draws(pool, multiplier, multiplierPools); lore.add(messages.get(draws == 1 ? "gui.reward-preview-one" : "gui.reward-preview-many", "%count%", draws)); - int shown = Math.min(4, rewards.size()); + int shown = Math.min(MAX_PREVIEW_LINES, rewards.size()); for (String reward : rewards.subList(0, shown)) { lore.add(Utils.colorize(reward)); } if (shown < rewards.size()) { lore.add(messages.get("gui.reward-preview-more", "%count%", rewards.size() - shown)); } + if (preview.ranged(shown)) { + lore.addAll(messages.lines("gui.reward-preview-ranges")); + noteShown = true; + } } } + lore.addAll(laterRewardLore(messages, next, milestones, drops, multiplier, multiplierPools, pools, poolNames, + noteShown)); if (due > 0) { lore.add(messages.get("gui.reward-click", "%count%", due)); } return lore; } - static List nextRewardDisplays(int milestone, Map drops, int multiplier, - Function> pools) { - RewardEntry drop = drops.get(milestone); - String pool = drop == null ? ActivityConfiguration.DEFAULT_POOL - : ActivityConfiguration.referencedPool(drop); + /** + * One line per later milestone this week naming its reward; neighbours with the same reward share a line. + * Adds the range note when a line shows a range and {@code noteShown} says it is not above already. + */ + static List laterRewardLore(Messages messages, int next, List milestones, + Map drops, int multiplier, Set multiplierPools, + Function> pools, + Function poolNames, boolean noteShown) { + List points = new ArrayList<>(); + List names = new ArrayList<>(); + boolean ranged = false; + String lastSource = null; + for (Integer milestone : milestones) { + if (milestone <= next) { + continue; + } + RewardEntry drop = drops.get(milestone); + Later later = laterReward(messages, drop, multiplier, multiplierPools, pools, poolNames); + if (later == null) { + continue; + } + String name = later.name(); + ranged |= later.ranged(); + // Neighbours join only when they pay from the same pool, or the same fixed reward. + String pool = poolOf(drop); + String source = pool != null ? "pool:" + pool : "fixed:" + name; + if (source.equals(lastSource)) { + int last = names.size() - 1; + points.set(last, points.get(last) + "/" + milestone); + } else { + points.add(Integer.toString(milestone)); + names.add(name); + } + lastSource = source; + } + List lore = new ArrayList<>(); + if (names.isEmpty()) { + return lore; + } + lore.add(messages.get("gui.bar-lore-later")); + for (int i = 0; i < names.size(); i++) { + lore.add(messages.get("gui.bar-lore-later-line", "%points%", points.get(i), "%reward%", names.get(i))); + } + if (ranged && !noteShown) { + lore.addAll(messages.lines("gui.reward-preview-ranges")); + } + return lore; + } + + // A later milestone's shown name, and whether that name is a generated range. + private record Later(String name, boolean ranged) { + } + + // What a later milestone pays: a fixed drop, the pool's configured name, the pool's only option, or + // "a random reward". Null when there is nothing to pay (an empty pool). + private static Later laterReward(Messages messages, RewardEntry drop, int multiplier, + Set multiplierPools, Function> pools, + Function poolNames) { + String pool = poolOf(drop); if (pool == null) { - RewardEntry.Item item = drop.items().get(0); - return List.of("#50d990x" + item.amount() * multiplier + " #b8906e" + drop.display()); + return new Later(Utils.colorize(fixedDisplay(drop, multiplier)), false); } - List entries = pools.apply(pool); - if (entries == null || entries.isEmpty()) { - return List.of(); + RewardPreview.Preview preview = RewardPreview.preview(entries(pools, pool)); + List options = preview.lines(); + if (options.isEmpty()) { + return null; } - return RewardPreview.summarize(entries); + String configured = poolNames == null ? null : poolNames.apply(pool); + boolean onlyOption = (configured == null || configured.isBlank()) && options.size() == 1; + String name = configured != null && !configured.isBlank() ? Utils.colorize(configured) + : onlyOption ? Utils.colorize(options.get(0)) + : messages.get("gui.bar-lore-later-random"); + int draws = draws(pool, multiplier, multiplierPools); + return new Later(draws == 1 ? name : messages.get("gui.bar-lore-later-many", "%count%", draws, "%reward%", name), + onlyOption && preview.ranged()); + } + + private static List entries(Function> pools, String pool) { + List entries = pools.apply(pool); + return entries == null ? List.of() : entries; + } + + private static String poolOf(RewardEntry drop) { + return drop == null ? ActivityConfiguration.DEFAULT_POOL : ActivityConfiguration.referencedPool(drop); + } + + private static int draws(String pool, int multiplier, Set multiplierPools) { + return multiplierPools.contains(pool) ? multiplier : 1; + } + + private static String fixedDisplay(RewardEntry drop, int multiplier) { + RewardEntry.Item item = drop.items().get(0); + return "#50d990x" + item.amount() * multiplier + " #b8906e" + drop.display(); } private static Integer nextMilestone(PlayerData data, List milestones) { diff --git a/src/main/java/net/tfminecraft/activitytf/gui/ReferralGui.java b/src/main/java/net/tfminecraft/activitytf/gui/ReferralGui.java index c84cbf1..17bddbb 100644 --- a/src/main/java/net/tfminecraft/activitytf/gui/ReferralGui.java +++ b/src/main/java/net/tfminecraft/activitytf/gui/ReferralGui.java @@ -476,9 +476,13 @@ List rewardLore(Reward reward) { return lore; } lore.add(messages.get("gui.reward-preview-one")); - for (String option : RewardPreview.summarize(pool)) { + RewardPreview.Preview preview = RewardPreview.preview(pool); + for (String option : preview.lines()) { lore.add(Utils.colorize(option)); } + if (preview.ranged()) { + lore.addAll(messages.lines("gui.reward-preview-ranges")); + } return lore; } diff --git a/src/main/java/net/tfminecraft/activitytf/gui/RewardPreview.java b/src/main/java/net/tfminecraft/activitytf/gui/RewardPreview.java index f3b1258..c82bbbe 100644 --- a/src/main/java/net/tfminecraft/activitytf/gui/RewardPreview.java +++ b/src/main/java/net/tfminecraft/activitytf/gui/RewardPreview.java @@ -3,60 +3,150 @@ import net.tfminecraft.activitytf.models.RewardEntry; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; import java.util.regex.Pattern; final class RewardPreview { // Display text supplies the name/colour only. Bounds come from the actual item amounts. private static final String COLOUR = "(?:#[a-fA-F0-9]{6}|[&§][0-9a-fk-orA-FK-OR])"; - private static final Pattern QUANTITY = Pattern.compile("^(?:" + COLOUR + ")*[xX×]\\d+\\s+"); + private static final Pattern QUANTITY = Pattern.compile("^(?:" + COLOUR + ")*[xX×](\\d+)\\s+"); + // The " + " between the parts of a bundle's display, with any colour codes in front of the plus. + private static final Pattern PART_SEPARATOR = Pattern.compile("\\s+(?:" + COLOUR + ")*\\+\\s+"); private RewardPreview() { } - private record Key(String path, String label) { + /** {@code lines} are the options to show; {@code rangedLines} marks each line that joins rewards of different sizes. */ + record Preview(List lines, List rangedLines) { + /** True when any line joins rewards of different sizes. */ + boolean ranged() { + return ranged(lines.size()); + } + + /** True when one of the first {@code shown} lines joins rewards of different sizes. */ + boolean ranged(int shown) { + return rangedLines.subList(0, Math.min(shown, rangedLines.size())).contains(true); + } } - private record Range(String label, int min, int max) { - Range include(int amount) { - return new Range(label, Math.min(min, amount), Math.max(max, amount)); + // The name of each item path; a map, so the same items listed in another order are the same key. + private record Key(Map labels) { + } + + // Shown in the order of the first entry; later entries are matched to it by path. + private record Range(List paths, List labels, int[] min, int[] max) { + Range include(Map totals) { + int[] low = min.clone(); + int[] high = max.clone(); + for (int i = 0; i < paths.size(); i++) { + int amount = totals.get(paths.get(i)); + low[i] = Math.min(low[i], amount); + high[i] = Math.max(high[i], amount); + } + return new Range(paths, labels, low, high); + } + + boolean ranged() { + return !Arrays.equals(min, max); } String display() { - return "#50d990x" + min + (min == max ? "" : "–" + max) + " &r" + label; + List parts = new ArrayList<>(); + for (int i = 0; i < labels.size(); i++) { + parts.add("#50d990x" + min[i] + (min[i] == max[i] ? "" : "–" + max[i]) + " &r" + labels.get(i)); + } + return String.join(" &7+ ", parts); } } static List summarize(List entries) { + return preview(entries).lines(); + } + + /** + * One line per kind of outcome. Entries handing over the same items (stacks of one item added + * together) share a line with a range per item; commands, and bundles whose display cannot be + * matched to their items, stay whole outcomes under their own text. + */ + static Preview preview(List entries) { Map options = new LinkedHashMap<>(); for (RewardEntry entry : entries) { if (entry.weight() <= 0) { continue; } - if (entry.items().size() == 1 && entry.commands().isEmpty()) { - RewardEntry.Item item = entry.items().get(0); - String label = entry.display() == null ? "" : QUANTITY.matcher(entry.display()).replaceFirst("").strip(); - if (label.isBlank()) { - label = "&7" + item.path(); + Map totals = totals(entry); + List labels = totals == null ? null : labels(entry.display(), totals, entry.items().size()); + if (labels != null) { + List paths = List.copyOf(totals.keySet()); + Map named = new LinkedHashMap<>(); + for (int i = 0; i < paths.size(); i++) { + named.put(paths.get(i), labels.get(i)); } - Key key = new Key(item.path(), label); + Key key = new Key(Map.copyOf(named)); + int[] amounts = totals.values().stream().mapToInt(Integer::intValue).toArray(); Range range = options.get(key); - options.put(key, range == null ? new Range(label, item.amount(), item.amount()) - : range.include(item.amount())); + options.put(key, range == null ? new Range(paths, labels, amounts, amounts.clone()) + : range.include(totals)); } else { - // Commands and bundles are whole outcomes; do not invent per-item ranges for them. String label = entry.display(); if (label == null || label.isBlank()) { label = "&7Other reward"; } - options.putIfAbsent(label, new Range(label, 0, 0)); + options.putIfAbsent(label, new Range(List.of(), List.of(label), new int[0], new int[0])); } } List displays = new ArrayList<>(); - options.forEach((key, range) -> displays.add(key instanceof Key ? range.display() : range.label())); - return displays; + List ranged = new ArrayList<>(); + for (Map.Entry option : options.entrySet()) { + Range range = option.getValue(); + displays.add(option.getKey() instanceof Key ? range.display() : range.labels().get(0)); + ranged.add(range.ranged()); + } + return new Preview(List.copyOf(displays), List.copyOf(ranged)); + } + + // Item amounts by path, in first-seen order; null for commands or an entry without items. + private static Map totals(RewardEntry entry) { + if (entry.items().isEmpty() || !entry.commands().isEmpty()) { + return null; + } + Map totals = new LinkedHashMap<>(); + for (RewardEntry.Item item : entry.items()) { + totals.merge(item.path(), item.amount(), (a, b) -> (int) Math.min(Integer.MAX_VALUE, (long) a + b)); + } + return totals; + } + + /** + * The name of each item, in {@code totals} order. A single stack is named by its display without + * the quantity. Otherwise the display must have one "xN name" part per item, in item order, whose N + * matches that item's total (stacks of one item added up); if not, null, and the entry stays a + * whole outcome. + */ + private static List labels(String display, Map totals, int stacks) { + String text = display == null ? "" : display.strip(); + if (stacks == 1) { + String label = QUANTITY.matcher(text).replaceFirst("").strip(); + return List.of(label.isBlank() ? "&7" + totals.keySet().iterator().next() : label); + } + String[] parts = PART_SEPARATOR.split(text); + if (parts.length != totals.size()) { + return null; + } + List labels = new ArrayList<>(); + int index = 0; + for (int amount : totals.values()) { + Matcher quantity = QUANTITY.matcher(parts[index++].strip()); + if (!quantity.find() || !quantity.group(1).equals(Integer.toString(amount))) { + return null; + } + labels.add(quantity.replaceFirst("").strip()); + } + return List.copyOf(labels); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a083ac9..c4f9e63 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -925,6 +925,11 @@ daily-reward: gui: title: "&8Weekly Activity" + # Short names for reward pools in the weekly icon's "Later this week" list, e.g. + # pool_act1: "#7f7d80Act materials" + # pool_skin: "#b8906eItem Skin Scroll" + # A pool with no name shows its only option, or "a random reward" when it has several. + pool-names: {} bar: max: 50 # points to fill the weekly bar diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 5b60a4f..638d8c1 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -22,6 +22,14 @@ gui: reward-preview-many: "&7%count% random rewards, each from:" reward-preview-more: "&7+%count% other possible rewards" reward-preview-unavailable: "&8Reward preview unavailable" + # Shown under a reward list when a line joins the same reward in several sizes ("x20-80"). + reward-preview-ranges: + - "&8&oA range is the same reward in several" + - "&8&osizes - each draw pays one of them." + bar-lore-later: "#d97b66Later this week&e:" + bar-lore-later-line: "&6%points% #b8906epts&8: &f%reward%" + bar-lore-later-many: "&f%count%x %reward%" + bar-lore-later-random: "&7a random reward" reward-click: "#6b9c68[#fafa16Click to claim %count% reward(s)#6b9c68]" activity-lore-progress: "#af97bdProgress&e: %bar%" activity-lore-today: "#d97b66Today&e: &6%today%" diff --git a/src/test/java/net/tfminecraft/activitytf/config/ActivityConfigurationTest.java b/src/test/java/net/tfminecraft/activitytf/config/ActivityConfigurationTest.java index a680cd9..6711320 100644 --- a/src/test/java/net/tfminecraft/activitytf/config/ActivityConfigurationTest.java +++ b/src/test/java/net/tfminecraft/activitytf/config/ActivityConfigurationTest.java @@ -414,6 +414,9 @@ void validFileLoadsPublicSettingsAndMessages() throws Exception { settings.set("reset.day", " wednesday "); settings.set("reset.hour", 17); settings.set("gui.title", "&6Activity board"); + settings.set("gui.pool-names.Pool_Act1", "&7Act materials"); + settings.set("gui.pool-names.pool_blank", " "); + settings.set("gui.pool-names.pool_list", List.of("not", "a name")); settings.set("bar.max", 60); settings.set("bar.daily-max", 12); settings.set("bar.length", 30); @@ -434,6 +437,10 @@ void validFileLoadsPublicSettingsAndMessages() throws Exception { assertEquals(DayOfWeek.WEDNESDAY, config.resetDay()); assertEquals(17, config.resetHour()); assertEquals("&6Activity board", config.guiTitle()); + assertEquals("&7Act materials", config.poolDisplayName("pool_act1")); + assertNull(config.poolDisplayName("pool_blank")); + assertNull(config.poolDisplayName("pool_list")); + assertNull(config.poolDisplayName(null)); assertEquals(60, config.barMax()); assertEquals(12, config.dailyMax()); assertEquals(12, config.nonVoteDailyMax()); diff --git a/src/test/java/net/tfminecraft/activitytf/gui/ActivityGuiTest.java b/src/test/java/net/tfminecraft/activitytf/gui/ActivityGuiTest.java index 6adb7b0..fc01443 100644 --- a/src/test/java/net/tfminecraft/activitytf/gui/ActivityGuiTest.java +++ b/src/test/java/net/tfminecraft/activitytf/gui/ActivityGuiTest.java @@ -333,7 +333,7 @@ void theWeeklyIconNamesTheNextReward() { List.of(new RewardEntry.Item("m.material.steel", 3))); List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10, 20), - Map.of(10, steel), 1, Set.of(), pool -> List.of()); + Map.of(10, steel), 1, Set.of(), pool -> List.of(), unnamed -> null); assertEquals(List.of(messages.get("gui.bar-lore-reward", "%points%", 10, "%reward%", Utils.colorize("#50d990x3 #b8906eSteel"))), lore); @@ -349,12 +349,12 @@ void theWeeklyIconSummarizesTheNextPoolAsOneRandomRange() { material(3, 8, "ignitium", "#7f7d80Ignitium")); List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10, 20), - Map.of(20, ActivityConfiguration.poolRef("pool_prologue")), 1, Set.of(), name -> pool); + Map.of(20, ActivityConfiguration.poolRef("pool_prologue")), 1, Set.of(), name -> pool, unnamed -> null); assertEquals(messages.get("gui.bar-lore-next-options", "%points%", 20), lore.get(0)); assertEquals(messages.get("gui.reward-preview-one"), lore.get(1)); assertEquals(Utils.colorize("#50d990x2–8 &r#7f7d80Ignitium"), lore.get(2)); - assertEquals(3, lore.size()); + assertEquals(messages.lines("gui.reward-preview-ranges"), lore.subList(3, lore.size())); } @Test @@ -363,7 +363,7 @@ void theWeeklyIconSaysThereAreNoMoreRewardsThisWeek() { PlayerData data = new PlayerData(40, 0, "2026-W38", "2026-09-17", 40, java.util.Map.of()); List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10, 20, 40), - Map.of(), 1, Set.of(), pool -> List.of()); + Map.of(), 1, Set.of(), pool -> List.of(), unnamed -> null); assertEquals(List.of(messages.get("gui.bar-lore-none")), lore); assertTrue(lore.get(0).toLowerCase(java.util.Locale.ROOT).contains("no more rewards this week"), @@ -378,7 +378,7 @@ void aReadyRewardStillSaysWhatItIsAndThatItCanBeClaimed() { List.of(new RewardEntry.Item("DIAMOND", 1))); List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10), - Map.of(10, steel), 2, Set.of(), pool -> List.of()); + Map.of(10, steel), 2, Set.of(), pool -> List.of(), unnamed -> null); assertTrue(lore.get(0).contains("x2"), lore.toString()); assertEquals(messages.get("gui.reward-click", "%count%", 1), lore.get(1)); @@ -401,13 +401,14 @@ void actOneShowsThreeMaterialRangesPerIndependentDraw() { } PlayerData data = new PlayerData(10, 0, "2026-W38", "2026-09-17", 0, Map.of()); List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10), - Map.of(10, ActivityConfiguration.poolRef("pool_act1")), 2, Set.of("pool_act1"), name -> pool); + Map.of(10, ActivityConfiguration.poolRef("pool_act1")), 2, Set.of("pool_act1"), name -> pool, unnamed -> null); assertEquals(messages.get("gui.reward-preview-many", "%count%", 2), lore.get(1)); assertEquals(Utils.colorize("#50d990x20–80 &r#7f7d80Ignitium"), lore.get(2)); assertEquals(Utils.colorize("#50d990x2–8 &r#7f7d80Raw Tin"), lore.get(3)); assertEquals(Utils.colorize("#50d990x2–8 &r#3b4e60Abyssalite Fragment"), lore.get(4)); - assertEquals(messages.get("gui.reward-click", "%count%", 1), lore.get(5)); + assertEquals(messages.lines("gui.reward-preview-ranges"), lore.subList(5, 7)); + assertEquals(messages.get("gui.reward-click", "%count%", 1), lore.get(7)); } @Test @@ -417,7 +418,7 @@ void unlistedSkinPoolStillPreviewsOnlyOneDraw() { List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10), Map.of(10, ActivityConfiguration.poolRef("pool_skin")), 2, Set.of("pool_act1"), name -> List.of(material(65, 1, "common_item_skin_scroll", "&7Common Item Skin Scroll"), - material(3, 1, "legendary_item_skin_scroll", "&7Legendary Item Skin Scroll"))); + material(3, 1, "legendary_item_skin_scroll", "&7Legendary Item Skin Scroll")), unnamed -> null); assertEquals(messages.get("gui.reward-preview-one"), lore.get(1)); assertTrue(lore.get(2).contains("x1")); @@ -453,9 +454,146 @@ void largePoolsAreBoundedAndMentionTheRemainingPossibilities() { pool.add(material(1, 1, "item_" + i, "&7Item " + i)); } List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10), Map.of(), - 1, Set.of(), name -> pool); - assertEquals(7, lore.size()); - assertEquals(messages.get("gui.reward-preview-more", "%count%", 8), lore.get(6)); + 1, Set.of(), name -> pool, unnamed -> null); + assertEquals(2 + ActivityGui.MAX_PREVIEW_LINES + 1, lore.size()); + assertEquals(messages.get("gui.reward-preview-more", "%count%", 2), lore.get(lore.size() - 1)); + } + + private static RewardEntry bundle(int weight, String display, Object... pathAmounts) { + List items = new ArrayList<>(); + for (int i = 0; i < pathAmounts.length; i += 2) { + items.add(new RewardEntry.Item((String) pathAmounts[i], (Integer) pathAmounts[i + 1])); + } + return new RewardEntry(weight, display, List.of(), items); + } + + @Test + void bundlesWithTheSameItemsShareOneLineWithARangePerItem() { + String plus = " #7f7d80+ "; + List pool = List.of( + bundle(35, "#50d990x20 #7f7d80Ignitium" + plus + "#50d990x20 #d8d8d8Iron Ingot", + "m.materials.ignitium", 20, "v.iron_ingot", 20), + bundle(15, "#50d990x2 #3b4e60Tin" + plus + "#50d990x10 #d8d8d8Iron Ingot", + "m.materials.raw_tin", 2, "v.iron_ingot", 10), + bundle(13, "#50d990x40 #7f7d80Ignitium" + plus + "#50d990x40 #d8d8d8Iron Ingot", + "m.materials.ignitium", 40, "v.iron_ingot", 40), + bundle(1, "#50d990x80 #7f7d80Ignitium" + plus + "#50d990x80 #d8d8d8Iron Ingot", + "m.materials.ignitium", 64, "m.materials.ignitium", 16, "v.iron_ingot", 64, "v.iron_ingot", 16), + bundle(1, "#50d990x8 #3b4e60Tin" + plus + "#50d990x40 #d8d8d8Iron Ingot", + "m.materials.raw_tin", 8, "v.iron_ingot", 40)); + + RewardPreview.Preview preview = RewardPreview.preview(pool); + + assertEquals(List.of( + "#50d990x20–80 &r#7f7d80Ignitium &7+ #50d990x20–80 &r#d8d8d8Iron Ingot", + "#50d990x2–8 &r#3b4e60Tin &7+ #50d990x10–40 &r#d8d8d8Iron Ingot"), preview.lines()); + assertTrue(preview.ranged()); + } + + @Test + void bundlesWhoseDisplayDoesNotMatchTheirItemsStayWholeOutcomes() { + RewardEntry wrongAmount = bundle(1, "#50d990x5 &7Ignitium + #50d990x20 &7Iron Ingot", + "m.materials.ignitium", 20, "v.iron_ingot", 20); + RewardEntry noQuantity = bundle(1, "&7Steel tools + &7rations", "m.tools.steel_pickaxe", 1, "BREAD", 64); + RewardEntry blankName = bundle(1, "#50d990x1 + #50d990x2 &7Bread", "DIAMOND", 1, "BREAD", 2); + RewardEntry splitStacks = bundle(1, "x64 &7Iron + x16 &7Iron", "IRON_INGOT", 64, "IRON_INGOT", 16); + RewardEntry splitPile = bundle(1, "&7A pile of iron", "IRON_INGOT", 64, "IRON_INGOT", 16); + RewardEntry splitWhole = bundle(1, "x80 &7Iron", "IRON_INGOT", 64, "IRON_INGOT", 16); + + RewardPreview.Preview preview = RewardPreview.preview(List.of(wrongAmount, noQuantity, blankName, + splitStacks, splitPile, splitWhole)); + + assertEquals(List.of(wrongAmount.display(), noQuantity.display(), blankName.display(), + splitStacks.display(), splitPile.display(), "#50d990x80 &r&7Iron"), preview.lines()); + assertFalse(preview.ranged()); + } + + @Test + void bundlesWithTheSameItemsInAnotherOrderShareALine() { + RewardPreview.Preview preview = RewardPreview.preview(List.of( + bundle(1, "x2 &7Diamond + x4 &7Iron", "DIAMOND", 2, "IRON_INGOT", 4), + bundle(1, "x8 &7Iron + x6 &7Diamond", "IRON_INGOT", 8, "DIAMOND", 6))); + + assertEquals(List.of("#50d990x2–6 &r&7Diamond &7+ #50d990x4–8 &r&7Iron"), preview.lines()); + } + + @Test + void aRangedLaterRewardGetsTheRangeNoteOnce() { + Messages messages = shippedMessages(); + PlayerData data = new PlayerData(0, 0, "2026-W38", "2026-09-17", 0, Map.of()); + RewardEntry steel = new RewardEntry(1, "Steel", List.of(), List.of(new RewardEntry.Item("m.material.steel", 3))); + List gems = List.of(material(1, 2, "gem", "&7Gem"), material(1, 8, "gem", "&7Gem")); + Map drops = Map.of(10, steel, 20, ActivityConfiguration.poolRef("pool_gems"), + 30, ActivityConfiguration.poolRef("pool_gems2")); + Map> pools = Map.of("pool_gems", gems, "pool_gems2", gems); + List note = messages.lines("gui.reward-preview-ranges"); + + List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10, 20, 30), drops, 1, Set.of(), + pools::get, null); + + int at = java.util.Collections.indexOfSubList(lore, note); + assertEquals(lore.size() - note.size(), at, "the note follows the later lines, once"); + assertEquals(at, java.util.Collections.lastIndexOfSubList(lore, note)); + assertFalse(ActivityGui.laterRewardLore(messages, 10, List.of(10, 20), drops, 1, Set.of(), pools::get, + null, true).containsAll(note)); + } + + @Test + void theRangeNoteFollowsOnlyTheShownLines() { + Messages messages = shippedMessages(); + PlayerData data = new PlayerData(0, 0, "2026-W38", "2026-09-17", 0, Map.of()); + List pool = new ArrayList<>(); + for (int i = 0; i < ActivityGui.MAX_PREVIEW_LINES; i++) { + pool.add(material(1, 1, "item_" + i, "&7Item " + i)); + } + pool.add(material(1, 1, "hidden", "&7Hidden")); + pool.add(material(1, 5, "hidden", "&7Hidden")); + + List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10), Map.of(), 1, Set.of(), + name -> pool, null); + + assertEquals(messages.get("gui.reward-preview-more", "%count%", 1), lore.get(lore.size() - 1)); + assertTrue(RewardPreview.preview(pool).ranged()); + } + + @Test + void theWeeklyIconListsTheRestOfTheWeeksRewards() { + Messages messages = shippedMessages(); + PlayerData data = new PlayerData(0, 0, "2026-W38", "2026-09-17", 0, Map.of()); + List act = List.of(material(1, 2, "ignitium", "&7Ignitium"), material(1, 2, "raw_tin", "&7Tin")); + List skins = List.of(material(1, 1, "common_scroll", "&7Common"), + material(1, 1, "rare_scroll", "&7Rare")); + List single = List.of(material(1, 3, "gem", "&7Gem")); + Map> pools = Map.of("pool_act1", act, "pool_skin", skins, + "pool_single", single, "pool_unnamed", skins, "pool_other", skins); + RewardEntry steel = new RewardEntry(1, "Steel", List.of(), List.of(new RewardEntry.Item("m.material.steel", 3))); + Map drops = Map.of( + 10, ActivityConfiguration.poolRef("pool_act1"), 20, ActivityConfiguration.poolRef("pool_act1"), + 30, ActivityConfiguration.poolRef("pool_skin"), 40, ActivityConfiguration.poolRef("pool_skin"), + 50, ActivityConfiguration.poolRef("pool_empty"), 60, ActivityConfiguration.poolRef("pool_skin"), + 70, ActivityConfiguration.poolRef("pool_single"), 80, ActivityConfiguration.poolRef("pool_unnamed"), + 90, steel, 85, ActivityConfiguration.poolRef("pool_other")); + + List later = ActivityGui.laterRewardLore(messages, 10, + List.of(10, 20, 30, 40, 50, 60, 70, 80, 85, 90), + drops, 2, Set.of("pool_act1"), pools::get, + pool -> Map.of("pool_act1", "&7Act materials", "pool_skin", "&7Skin Scroll").get(pool), false); + + assertEquals(List.of(messages.get("gui.bar-lore-later"), + messages.get("gui.bar-lore-later-line", "%points%", "20", "%reward%", + messages.get("gui.bar-lore-later-many", "%count%", 2, "%reward%", Utils.colorize("&7Act materials"))), + messages.get("gui.bar-lore-later-line", "%points%", "30/40/60", "%reward%", Utils.colorize("&7Skin Scroll")), + messages.get("gui.bar-lore-later-line", "%points%", "70", "%reward%", Utils.colorize("#50d990x3 &r&7Gem")), + messages.get("gui.bar-lore-later-line", "%points%", "80", "%reward%", messages.get("gui.bar-lore-later-random")), + messages.get("gui.bar-lore-later-line", "%points%", "85", "%reward%", messages.get("gui.bar-lore-later-random")), + messages.get("gui.bar-lore-later-line", "%points%", "90", "%reward%", Utils.colorize("#50d990x6 #b8906eSteel"))), + later); + assertTrue(ActivityGui.laterRewardLore(messages, 90, List.of(10, 90), drops, 1, Set.of(), pools::get, + null, false).isEmpty()); + + List weekly = ActivityGui.weeklyRewardLore(messages, data, List.of(10, 20, 30), drops, 2, + Set.of("pool_act1"), pools::get, null); + assertEquals(messages.get("gui.bar-lore-later"), weekly.get(weekly.size() - 3)); } @Test @@ -463,7 +601,7 @@ void anEmptyPoolReportsAnUnavailablePreview() { Messages messages = shippedMessages(); PlayerData data = new PlayerData(0, 0, "2026-W38", "2026-09-17", 0, Map.of()); List lore = ActivityGui.weeklyRewardLore(messages, data, List.of(10), Map.of(), - 1, Set.of(), name -> List.of()); + 1, Set.of(), name -> List.of(), unnamed -> null); assertEquals(messages.get("gui.reward-preview-unavailable"), lore.get(1)); } diff --git a/src/test/java/net/tfminecraft/activitytf/gui/ReferralGuiTest.java b/src/test/java/net/tfminecraft/activitytf/gui/ReferralGuiTest.java index e6f4d9b..3718b99 100644 --- a/src/test/java/net/tfminecraft/activitytf/gui/ReferralGuiTest.java +++ b/src/test/java/net/tfminecraft/activitytf/gui/ReferralGuiTest.java @@ -547,6 +547,12 @@ void rewardLoreListsItemsCommandsAndPools() { List options = gui.rewardLore(new Reward("Two", null, "pool_two", null)); assertTrue(options.get(0).contains("One random reward"), String.valueOf(options)); assertEquals(3, options.size()); + net.tfminecraft.activitytf.managers.TestManagers.pool(fixture.manager, "pool_sizes", List.of( + new RewardEntry(1, "x1 &aTin", List.of(), List.of(new RewardEntry.Item("DIAMOND", 1))), + new RewardEntry(1, "x4 &aTin", List.of(), List.of(new RewardEntry.Item("DIAMOND", 4))))); + List sizes = gui.rewardLore(new Reward("Sizes", null, "pool_sizes", null)); + assertEquals(fixture.manager.getConfiguration().messages().lines("gui.reward-preview-ranges"), + sizes.subList(2, sizes.size())); Reward empty = new Reward("Pool", null, "pool_nothing", null); assertTrue(gui.rewardLore(empty).get(0).contains("unavailable"));