kourend library plugin: add config option to hide duplicate books
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Book> 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<Book> books = EnumSet.noneOf(Book.class);
|
||||
|
||||
for (Item item : itemContainer.getItems())
|
||||
{
|
||||
Book book = Book.byId(item.getId());
|
||||
|
||||
if (book != null)
|
||||
{
|
||||
books.add(book);
|
||||
}
|
||||
}
|
||||
|
||||
playerBooks = books;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user