From 78f16f28f0e4befc52da19c3f2338bee90388d72 Mon Sep 17 00:00:00 2001 From: Koekkruimels Date: Wed, 20 Feb 2019 13:26:51 +0100 Subject: [PATCH] kourend library plugin: add config option to hide duplicate books --- .../kourendlibrary/KourendLibraryConfig.java | 10 +++++ .../kourendlibrary/KourendLibraryOverlay.java | 19 +++++++-- .../kourendlibrary/KourendLibraryPlugin.java | 42 +++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java index b61a24c139..6ec40a00fd 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java @@ -42,4 +42,14 @@ public interface KourendLibraryConfig extends Config { return true; } + + @ConfigItem( + keyName = "hideDuplicateBook", + name = "Hide duplicate book", + description = "Don't show the duplicate book locations in the library" + ) + default boolean hideDuplicateBook() + { + return true; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java index b581b10bd8..f1f0162d59 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import javax.annotation.Nullable; import lombok.AccessLevel; import lombok.Setter; import net.runelite.api.Client; @@ -57,15 +58,19 @@ class KourendLibraryOverlay extends Overlay private final static int MAXIMUM_DISTANCE = 24; private final Library library; private final Client client; + private final KourendLibraryConfig config; + private final KourendLibraryPlugin plugin; @Setter(AccessLevel.PACKAGE) private boolean hidden; @Inject - private KourendLibraryOverlay(Library library, Client client) + private KourendLibraryOverlay(Library library, Client client, KourendLibraryConfig config, KourendLibraryPlugin plugin) { this.library = library; this.client = client; + this.config = config; + this.plugin = plugin; setPosition(OverlayPosition.DYNAMIC); setLayer(OverlayLayer.ABOVE_SCENE); @@ -136,7 +141,7 @@ class KourendLibraryOverlay extends Overlay Color color = bookIsKnown ? Color.ORANGE : Color.WHITE; // Render the poly on the floor - if (!(bookIsKnown && book == null) && (library.getState() == SolvedState.NO_DATA || book != null || !possible.isEmpty())) + if (!(bookIsKnown && book == null) && (library.getState() == SolvedState.NO_DATA || book != null || !possible.isEmpty()) && !shouldHideOverlayIfDuplicateBook(book)) { Polygon poly = getCanvasTilePoly(client, localBookcase); if (poly != null) @@ -149,7 +154,7 @@ class KourendLibraryOverlay extends Overlay // If the book is singled out, render the text and the book's icon if (bookIsKnown) { - if (book != null) + if (book != null && !shouldHideOverlayIfDuplicateBook(book)) { FontMetrics fm = g.getFontMetrics(); Rectangle2D bounds = fm.getStringBounds(book.getShortName(), g); @@ -236,4 +241,12 @@ class KourendLibraryOverlay extends Overlay return null; } + + private boolean shouldHideOverlayIfDuplicateBook(@Nullable Book book) + { + return config.hideDuplicateBook() + && book != null + && !book.isDarkManuscript() + && plugin.doesPlayerContainBook(book); + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java index 73602299f4..649189fc47 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java @@ -26,6 +26,7 @@ package net.runelite.client.plugins.kourendlibrary; import com.google.inject.Provides; import java.awt.image.BufferedImage; +import java.util.EnumSet; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.inject.Inject; @@ -34,6 +35,9 @@ import lombok.extern.slf4j.Slf4j; import net.runelite.api.AnimationID; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; +import net.runelite.api.InventoryID; +import net.runelite.api.Item; +import net.runelite.api.ItemContainer; import net.runelite.api.MenuAction; import net.runelite.api.Player; import net.runelite.api.coords.WorldPoint; @@ -41,6 +45,7 @@ import net.runelite.api.events.AnimationChanged; import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.GameTick; +import net.runelite.api.events.ItemContainerChanged; import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; @@ -94,6 +99,7 @@ public class KourendLibraryPlugin extends Plugin private boolean buttonAttached = false; private WorldPoint lastBookcaseClick = null; private WorldPoint lastBookcaseAnimatedOn = null; + private EnumSet playerBooks = null; @Provides KourendLibraryConfig provideConfig(ConfigManager configManager) @@ -120,6 +126,8 @@ public class KourendLibraryPlugin extends Plugin overlayManager.add(overlay); + updatePlayerBooks(); + if (!config.hideButton()) { clientToolbar.addNavigation(navButton); @@ -135,6 +143,7 @@ public class KourendLibraryPlugin extends Plugin buttonAttached = false; lastBookcaseClick = null; lastBookcaseAnimatedOn = null; + playerBooks = null; } @Subscribe @@ -271,4 +280,37 @@ public class KourendLibraryPlugin extends Plugin } } } + + @Subscribe + public void onItemContainerChanged(ItemContainerChanged itemContainerChangedEvent) + { + updatePlayerBooks(); + } + + boolean doesPlayerContainBook(Book book) + { + return playerBooks.contains(book); + } + + private void updatePlayerBooks() + { + ItemContainer itemContainer = client.getItemContainer(InventoryID.INVENTORY); + + if (itemContainer != null) + { + EnumSet books = EnumSet.noneOf(Book.class); + + for (Item item : itemContainer.getItems()) + { + Book book = Book.byId(item.getId()); + + if (book != null) + { + books.add(book); + } + } + + playerBooks = books; + } + } } \ No newline at end of file