From fce836bf3bbf6d9c40492f38716187cc6c34b449 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 21 Oct 2022 14:56:10 +0200 Subject: [PATCH] Clicking on a trait in a recipe will now take you to that trait in the dex --- .../client/gui/spellbook/SpellbookScreen.java | 12 +++++++++- .../SpellbookTraitDexPageContent.java | 22 +++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) 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 627acc35..c3225d89 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 @@ -47,10 +47,11 @@ public class SpellbookScreen extends HandledScreen imple private final RecipeBookWidget recipeBook = new RecipeBookWidget(); private final Chapter craftingChapter; + private final SpellbookTraitDexPageContent traitDex = new SpellbookTraitDexPageContent(this); private final SpellbookChapterList chapters = new SpellbookChapterList(this, craftingChapter = new Chapter(SpellbookChapterList.CRAFTING_ID, TabSide.LEFT, 0, 0, Optional.of(new SpellbookCraftingPageContent(this))), new Chapter(SpellbookChapterList.PROFILE_ID, TabSide.LEFT, 1, 0, Optional.of(new SpellbookProfilePageContent(this))), - new Chapter(SpellbookChapterList.TRAIT_DEX_ID, TabSide.LEFT, 3, 0, Optional.of(new SpellbookTraitDexPageContent(this))) + new Chapter(SpellbookChapterList.TRAIT_DEX_ID, TabSide.LEFT, 3, 0, Optional.of(traitDex)) ); private final SpellbookTabBar tabs = new SpellbookTabBar(this, chapters); @@ -77,6 +78,10 @@ public class SpellbookScreen extends HandledScreen imple return handler.getSpellbookState(); } + public SpellbookTraitDexPageContent getTraitDex() { + return traitDex; + } + public void addPageButtons(int buttonY, int prevX, int nextX, IntConsumer pageAction) { addDrawableChild(new PageButton(this, x + nextX, y + buttonY, 1, pageAction)); addDrawableChild(new PageButton(this, x + prevX, y + buttonY, -1, pageAction)); @@ -225,6 +230,11 @@ public class SpellbookScreen extends HandledScreen imple }) || super.mouseClicked(mouseX, mouseY, button); } + @Override + protected void clearAndInit() { + super.clearAndInit(); + } + @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { return hoveredElement(mouseX, mouseY).filter((element) -> { 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 304cc471..7144a07a 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 @@ -1,11 +1,9 @@ package com.minelittlepony.unicopia.client.gui.spellbook; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.function.Function; -import com.minelittlepony.common.client.gui.IViewRoot; -import com.minelittlepony.common.client.gui.ScrollContainer; +import com.minelittlepony.common.client.gui.*; import com.minelittlepony.common.client.gui.element.Button; import com.minelittlepony.common.client.gui.element.Label; import com.minelittlepony.common.client.gui.sprite.TextureSprite; @@ -20,6 +18,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.*; +import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.Util; @@ -68,6 +67,21 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel }); } + public void pageTo(SpellbookScreen screen, Trait trait) { + int page = Arrays.binarySearch(traits, trait); + if (page < 0) { + return; + } + page /= 2; + state = screen.getState().getState(SpellbookChapterList.TRAIT_DEX_ID); + state.setOffset(page); + leftPage.scrollbar.scrollBy(leftPage.scrollbar.getVerticalScrollAmount()); + rightPage.scrollbar.scrollBy(rightPage.scrollbar.getVerticalScrollAmount()); + + GameGui.playSound(SoundEvents.ITEM_BOOK_PAGE_TURN); + screen.clearAndInit(); + } + @Override public void onRecipesChanged() { init(screen, SpellbookChapterList.TRAIT_DEX_ID);