diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/Trait.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/Trait.java index cb8e3944..a1f3189b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/Trait.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/Trait.java @@ -8,7 +8,6 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; -import com.minelittlepony.common.client.gui.Tooltip; import com.minelittlepony.unicopia.Unicopia; import net.minecraft.item.ItemStack; @@ -65,10 +64,31 @@ public enum Trait { private final Identifier sprite; private final TraitGroup group; + private final Text tooltip; + private final Text obfuscatedTooltip; + Trait(TraitGroup group) { this.id = Unicopia.id(name().toLowerCase()); this.sprite = Unicopia.id("textures/gui/trait/" + name().toLowerCase() + ".png"); this.group = group; + + Formatting corruptionColor = getGroup().getCorruption() < -0.01F + ? Formatting.GREEN + : getGroup().getCorruption() > 0.25F + ? Formatting.RED + : Formatting.WHITE; + + MutableText tooltipText = Text.translatable("gui.unicopia.trait.label", + Text.translatable("trait." + getId().getNamespace() + "." + getId().getPath() + ".name") + ).formatted(Formatting.YELLOW) + .append(Text.translatable("gui.unicopia.trait.group", getGroup().name().toLowerCase()).formatted(Formatting.ITALIC, Formatting.GRAY)) + .append(Text.literal("\n\n").formatted(Formatting.WHITE) + .append(Text.translatable("trait." + getId().getNamespace() + "." + getId().getPath() + ".description").formatted(Formatting.GRAY)) + .append("\n") + .append(Text.translatable("gui.unicopia.trait.corruption", ItemStack.MODIFIER_FORMAT.format(getGroup().getCorruption())).formatted(Formatting.ITALIC, corruptionColor))); + this.tooltip = tooltipText; + this.obfuscatedTooltip = tooltipText.copy().formatted(Formatting.OBFUSCATED); + } public Identifier getId() { @@ -83,22 +103,12 @@ public enum Trait { return sprite; } - public Tooltip getTooltip() { - Formatting corruptionColor = getGroup().getCorruption() < -0.01F - ? Formatting.GREEN - : getGroup().getCorruption() > 0.25F - ? Formatting.RED - : Formatting.WHITE; + public Text getTooltip() { + return tooltip; + } - return Tooltip.of( - Text.translatable("gui.unicopia.trait.label", - Text.translatable("trait." + getId().getNamespace() + "." + getId().getPath() + ".name") - ).formatted(Formatting.YELLOW) - .append(Text.translatable("gui.unicopia.trait.group", getGroup().name().toLowerCase()).formatted(Formatting.ITALIC, Formatting.GRAY)) - .append(Text.literal("\n\n").formatted(Formatting.WHITE) - .append(Text.translatable("trait." + getId().getNamespace() + "." + getId().getPath() + ".description").formatted(Formatting.GRAY)) - .append("\n") - .append(Text.translatable("gui.unicopia.trait.corruption", ItemStack.MODIFIER_FORMAT.format(getGroup().getCorruption())).formatted(Formatting.ITALIC, corruptionColor))), 200); + public Text getObfuscatedTooltip() { + return obfuscatedTooltip; } public static Collection<Trait> all() { diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/ItemTraitsTooltipRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/gui/ItemTraitsTooltipRenderer.java index 953549de..faab1666 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/ItemTraitsTooltipRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/ItemTraitsTooltipRenderer.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.client.gui; import java.util.ArrayList; import java.util.List; +import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.magic.spell.trait.*; import com.minelittlepony.unicopia.entity.player.Pony; import com.mojang.blaze3d.systems.RenderSystem; @@ -17,9 +18,11 @@ import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; import net.minecraft.text.*; +import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; public class ItemTraitsTooltipRenderer implements Text, OrderedText, TooltipComponent { + private static final Identifier UNKNOWN = Unicopia.id("textures/gui/trait/unknown.png"); private final SpellTraits traits; @@ -100,7 +103,7 @@ public class ItemTraitsTooltipRenderer implements Text, OrderedText, TooltipComp } } - private static boolean isKnown(Trait trait) { + public static boolean isKnown(Trait trait) { return MinecraftClient.getInstance().player == null || Pony.of(MinecraftClient.getInstance().player).getDiscoveries().isKnown(trait); } @@ -111,11 +114,7 @@ public class ItemTraitsTooltipRenderer implements Text, OrderedText, TooltipComp int size = 12; - if (!isKnown(trait)) { - trait = Trait.values()[MinecraftClient.getInstance().player.getRandom().nextInt(Trait.all().size())]; - } - - RenderSystem.setShaderTexture(0, trait.getSprite()); + RenderSystem.setShaderTexture(0, isKnown(trait) ? trait.getSprite() : UNKNOWN); matrices.push(); matrices.translate(xx, yy, itemRenderer.zOffset + 300.0F); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/IngredientTree.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/IngredientTree.java index 6af276d5..4ad93049 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/IngredientTree.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/IngredientTree.java @@ -102,7 +102,18 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder { int left = x + column * colWidth + 3 + (addLabels && row > 0 ? colWidth : 0); int top = y + row * rowHeight + 3; - container.addButton(new IngredientButton(left, top, colWidth, rowHeight, entry, !addLabels || ii == 0 ? "" : "+", false)); + var button = container.addButton(new IngredientButton(left, top, colWidth, rowHeight, entry, !addLabels || ii == 0 ? "" : "+", false)); + + if (entry instanceof Traits traits) { + final Trait trait = traits.trait; + button.onClick(sender -> { + if (MinecraftClient.getInstance().currentScreen instanceof SpellbookScreen spellbook) { + spellbook.getState().setCurrentPageId(SpellbookChapterList.TRAIT_DEX_ID); + spellbook.getTraitDex().pageTo(spellbook, trait); + } + }); + } + ii++; } result.ifPresent(result -> { @@ -263,7 +274,7 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder { @Override public Tooltip getTooltip() { - return trait.getTooltip(); + return Tooltip.of(ItemTraitsTooltipRenderer.isKnown(trait) ? trait.getTooltip() : trait.getObfuscatedTooltip(), 200); } } } \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/textures/gui/trait/unknown.png b/src/main/resources/assets/unicopia/textures/gui/trait/unknown.png new file mode 100644 index 00000000..9abf7af0 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/gui/trait/unknown.png differ