From 2a0e6bc14b519b9aebbd6ee9ebcef86b3caf7971 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 15 Sep 2022 21:49:10 +0200 Subject: [PATCH] Update trait dex icon to look more like a lightbulb and change the icon when there are unread entries --- .../magic/spell/trait/TraitDiscovery.java | 4 ++++ .../gui/spellbook/SpellbookChapterList.java | 8 ++++++-- .../client/gui/spellbook/SpellbookScreen.java | 2 +- .../client/gui/spellbook/SpellbookTabBar.java | 9 +++++++-- .../spellbook/SpellbookTraitDexPageContent.java | 13 +++++++++++++ .../textures/gui/container/pages/traits.png | Bin 777 -> 777 bytes .../gui/container/pages/traits_unread.png | Bin 0 -> 794 bytes 7 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/assets/unicopia/textures/gui/container/pages/traits_unread.png diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/TraitDiscovery.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/TraitDiscovery.java index edf637f6..6c7ab527 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/TraitDiscovery.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/TraitDiscovery.java @@ -90,6 +90,10 @@ public class TraitDiscovery implements NbtSerialisable { .flatMap(entry -> Registry.ITEM.getOrEmpty(entry.getKey()).stream()); } + public boolean isUnread() { + return !unreadTraits.isEmpty(); + } + public boolean isUnread(Trait trait) { return unreadTraits.contains(trait); } diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookChapterList.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookChapterList.java index 3066a2c9..b319d108 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookChapterList.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookChapterList.java @@ -58,8 +58,8 @@ public class SpellbookChapterList { int color, Optional content) { - public Identifier icon() { - return new Identifier(id().getNamespace(), "textures/gui/container/pages/" + id().getPath() + ".png"); + public static Identifier createIcon(Identifier id, String suffex) { + return new Identifier(id.getNamespace(), "textures/gui/container/pages/" + id.getPath() + suffex + ".png"); } } @@ -77,6 +77,10 @@ public class SpellbookChapterList { return false; } + default Identifier getIcon(Chapter chapter, Identifier icon) { + return icon; + } + static Optional of(BiConsumer init, Drawable obj) { return Optional.of(new Content() { @Override diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookScreen.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookScreen.java index 16fe432d..222bb210 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookScreen.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookScreen.java @@ -162,7 +162,7 @@ public class SpellbookScreen extends HandledScreen imple drawTexture(matrices, bounds.left, bounds.top, isRight ? 510 - bounds.width : 402, v, bounds.width, bounds.height, 512, 256); RenderSystem.setShaderColor(1, 1, 1, 1); - RenderSystem.setShaderTexture(0, tab.icon()); + RenderSystem.setShaderTexture(0, tab.icon().get()); drawTexture(matrices, isRight ? bounds.left + bounds.width - 16 - 10 : bounds.left + 10, bounds.top + (bounds.height - 16) / 2, 0, 0, 16, 16, 16, 16); RenderSystem.setShaderTexture(0, TEXTURE); }); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookTabBar.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookTabBar.java index cd98517d..313a9fd6 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookTabBar.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookTabBar.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.client.gui.spellbook; import java.util.*; +import java.util.function.Supplier; import java.util.stream.Stream; import com.minelittlepony.common.client.gui.dimension.Bounds; @@ -61,11 +62,15 @@ public class SpellbookTabBar { } int xPosition = side == TabSide.LEFT ? left - width + tabInset : left + backgroundWidth - tabInset; - tabs.add(new Tab(leftTabs.get(i), new Bounds(top + tabY, xPosition, width, tabHeight), leftTabs.get(i).icon())); + Chapter chapter = leftTabs.get(i); + Identifier icon = Chapter.createIcon(chapter.id(), ""); + tabs.add(new Tab(leftTabs.get(i), new Bounds(top + tabY, xPosition, width, tabHeight), () -> { + return chapter.content().map(content -> content.getIcon(chapter, icon)).orElse(icon); + })); } return tabs; } - record Tab (Chapter chapter, Bounds bounds, Identifier icon) {} + record Tab (Chapter chapter, Bounds bounds, Supplier icon) {} } diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookTraitDexPageContent.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookTraitDexPageContent.java index 1e8d7e9d..304cc471 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookTraitDexPageContent.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookTraitDexPageContent.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.client.gui.spellbook; import java.util.Comparator; import java.util.List; +import java.util.function.Function; import com.minelittlepony.common.client.gui.IViewRoot; import com.minelittlepony.common.client.gui.ScrollContainer; @@ -9,6 +10,7 @@ import com.minelittlepony.common.client.gui.element.Button; import com.minelittlepony.common.client.gui.element.Label; import com.minelittlepony.common.client.gui.sprite.TextureSprite; import com.minelittlepony.unicopia.ability.magic.spell.trait.*; +import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.Chapter; import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookScreen.ImageButton; import com.minelittlepony.unicopia.container.SpellbookState; import com.minelittlepony.unicopia.entity.player.Pony; @@ -20,6 +22,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.*; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.Util; import net.minecraft.util.collection.DefaultedList; public class SpellbookTraitDexPageContent extends DrawableHelper implements SpellbookChapterList.Content, SpellbookScreen.RecipesChangedListener { @@ -32,6 +35,8 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel private final SpellbookScreen screen; + private final Function unreadIcon = Util.memoize(id -> Chapter.createIcon(id, "_unread")); + public SpellbookTraitDexPageContent(SpellbookScreen screen) { this.screen = screen; } @@ -41,6 +46,14 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel } + @Override + public Identifier getIcon(Chapter chapter, Identifier icon) { + if (Pony.of(MinecraftClient.getInstance().player).getDiscoveries().isUnread()) { + return unreadIcon.apply(chapter.id()); + } + return icon; + } + @Override public void init(SpellbookScreen screen, Identifier pageId) { state = screen.getState().getState(pageId); diff --git a/src/main/resources/assets/unicopia/textures/gui/container/pages/traits.png b/src/main/resources/assets/unicopia/textures/gui/container/pages/traits.png index 76db65bb65e6294f8799b320ff915d4a928c135b..2d62b4d57560f74a9bab57b4d1f155b1ffb8d86a 100644 GIT binary patch delta 52 zcmeBV>tx$-mq~{?pW$jU<9w%I?2qbIqW|+}==@opna9H5*2m8(=s7Kx0SG)@{an^L HB{Ts5@Hi2U delta 52 zcmeBV>tx$-mr2L@G=tl$9Sx649DKZ7`kan2avu3_a<-RYsTU8=OId+g3_#%N>gTe~ HDWM4f8e zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=KFjvOHjhTl0wj(|68jzh6Xxj~MfpX#ojtraQD zOQbHV2IMinjXx;Or1|6fO5gC1S59gkrIwQMXw}LMlgMw+ypJ{KwdabL?ml`%QTp(U zYeukVe#R&m<>q|klPx6g7L>%A{HTS_y!A}iDUf&&BAFmYSaDjqCVy*Bh1Tl3 zMTFg7y+U2g8w2ew%KnKc0HJlABRd;>+2;pfA)<)dZ4PX(<>MxC7`>e>NhfGQpkdV8 zVjp(_v$xnko&fR831#*T5NSCZ=Xq%q^^1D^j#rDaFgai_OK=&5OH-S8pMqVNt>(qDD)V ztKhC$E!At(T3bWX2IYp;EgBpLA9CnnM>+h6qaLl}_;l^oOZOhV_Lc?@89Ho~;Uh*J zZPLV1nmTQk=`&`XZQ-abS-NbMVcF1002%&L_t(I%f(Vb4geqs694~ax;CfFsFp{E zAfnl&qB?`nz=9A7c554|R#;)Y=@%8bpI-kf0b55>|ApNoTvSL?i3*&0?8JyyDbQZl Y06Tpe`<{^&?*IS*07*qoM6N<$f}Fi~Q2+n{ literal 0 HcmV?d00001