From 353ce8a55e91c42082a9516e1bdfe85fe426300e Mon Sep 17 00:00:00 2001 From: TheStonedTurtle Date: Wed, 13 Mar 2024 02:02:47 -0700 Subject: [PATCH] Add tooltip support to modifiers Closes #140 --- .../data/modifiers/ConsumptionModifier.java | 6 ++++++ .../bankedexperience/data/modifiers/Modifier.java | 14 +++++++++++++- .../bankedexperience/data/modifiers/Modifiers.java | 14 ++++++++------ .../data/modifiers/StaticModifier.java | 6 ++++++ .../data/modifiers/ui/ModifierPanel.java | 5 +++++ 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/thestonedturtle/bankedexperience/data/modifiers/ConsumptionModifier.java b/src/main/java/thestonedturtle/bankedexperience/data/modifiers/ConsumptionModifier.java index 879f123..e780d16 100644 --- a/src/main/java/thestonedturtle/bankedexperience/data/modifiers/ConsumptionModifier.java +++ b/src/main/java/thestonedturtle/bankedexperience/data/modifiers/ConsumptionModifier.java @@ -53,4 +53,10 @@ public class ConsumptionModifier extends Modifier super(skill, name, included, ignored); this.savePercentage = savePercentage; } + + ConsumptionModifier(Skill skill, String name, float savePercentage, Collection included, Collection ignored, String tooltip) + { + super(skill, name, included, ignored, tooltip); + this.savePercentage = savePercentage; + } } diff --git a/src/main/java/thestonedturtle/bankedexperience/data/modifiers/Modifier.java b/src/main/java/thestonedturtle/bankedexperience/data/modifiers/Modifier.java index 3059336..a942d0d 100644 --- a/src/main/java/thestonedturtle/bankedexperience/data/modifiers/Modifier.java +++ b/src/main/java/thestonedturtle/bankedexperience/data/modifiers/Modifier.java @@ -56,17 +56,29 @@ public abstract class Modifier */ private final ImmutableSet ignoredActivities; + private final String tooltip; + Modifier(Skill skill, String name) { - this(skill, name, null, null); + this(skill, name, null, null, null); } + Modifier(Skill skill, String name, String tooltip) + { + this(skill, name, null, null, tooltip); + } Modifier(Skill skill, String name, Collection included, Collection ignored) + { + this(skill, name, included, ignored, null); + } + + Modifier(Skill skill, String name, Collection included, Collection ignored, String tooltip) { this.skill = skill; this.name = name; this.includedActivities = included == null ? ImmutableSet.of() : ImmutableSet.copyOf(included); this.ignoredActivities = ignored == null ? ImmutableSet.of() : ImmutableSet.copyOf(ignored); + this.tooltip = tooltip; } /** diff --git a/src/main/java/thestonedturtle/bankedexperience/data/modifiers/Modifiers.java b/src/main/java/thestonedturtle/bankedexperience/data/modifiers/Modifiers.java index 8999435..0cf18a2 100644 --- a/src/main/java/thestonedturtle/bankedexperience/data/modifiers/Modifiers.java +++ b/src/main/java/thestonedturtle/bankedexperience/data/modifiers/Modifiers.java @@ -43,6 +43,8 @@ */ public final class Modifiers { + private static final String ASHES_TOOLTIP_TEXT = "Only applies to ashes"; + private static final String BONES_TOOLTIP_TEXT = "Only applies to bones"; private static final Multimap modifiers = ArrayListMultimap.create(); static final Set BONES = ImmutableSet.of( @@ -60,7 +62,7 @@ public final class Modifiers public static void prepare(ItemManager manager) { - assert modifiers.size() == 0; + assert modifiers.isEmpty(); final Map compositions = new HashMap<>(); @@ -96,11 +98,11 @@ private static void createModifiers(final ItemManager manager, final Map included, Collection ignored, String tooltip) + { + super(skill, name, included, ignored, tooltip); + this.xpModifier = xpModifier; + } + /** * Applies the {@link #xpModifier} to the default xp rate of the passed activity, if applicable. * @param activity the {@link Activity} to apply this modifier to. diff --git a/src/main/java/thestonedturtle/bankedexperience/data/modifiers/ui/ModifierPanel.java b/src/main/java/thestonedturtle/bankedexperience/data/modifiers/ui/ModifierPanel.java index 3e09b92..49ba1e7 100644 --- a/src/main/java/thestonedturtle/bankedexperience/data/modifiers/ui/ModifierPanel.java +++ b/src/main/java/thestonedturtle/bankedexperience/data/modifiers/ui/ModifierPanel.java @@ -59,6 +59,11 @@ public ModifierPanel(final Modifier modifier) modifierConsumer.accept(modifier, getButton().isSelected()); }); + + if (modifier.getTooltip() != null) + { + this.setToolTipText(modifier.getTooltip()); + } } @Override