Merge pull request #7944 from Koekkruimels/feature/kourend-library-hide-duplicate-book
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,16 +31,14 @@ import java.awt.FontMetrics;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.InventoryID;
|
|
||||||
import net.runelite.api.ItemContainer;
|
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import static net.runelite.api.Perspective.getCanvasTilePoly;
|
import static net.runelite.api.Perspective.getCanvasTilePoly;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
@@ -57,15 +55,19 @@ class KourendLibraryOverlay extends Overlay
|
|||||||
private final static int MAXIMUM_DISTANCE = 24;
|
private final static int MAXIMUM_DISTANCE = 24;
|
||||||
private final Library library;
|
private final Library library;
|
||||||
private final Client client;
|
private final Client client;
|
||||||
|
private final KourendLibraryConfig config;
|
||||||
|
private final KourendLibraryPlugin plugin;
|
||||||
|
|
||||||
@Setter(AccessLevel.PACKAGE)
|
@Setter(AccessLevel.PACKAGE)
|
||||||
private boolean hidden;
|
private boolean hidden;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private KourendLibraryOverlay(Library library, Client client)
|
private KourendLibraryOverlay(Library library, Client client, KourendLibraryConfig config, KourendLibraryPlugin plugin)
|
||||||
{
|
{
|
||||||
this.library = library;
|
this.library = library;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.config = config;
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
setPosition(OverlayPosition.DYNAMIC);
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
setLayer(OverlayLayer.ABOVE_SCENE);
|
setLayer(OverlayLayer.ABOVE_SCENE);
|
||||||
@@ -136,7 +138,7 @@ class KourendLibraryOverlay extends Overlay
|
|||||||
Color color = bookIsKnown ? Color.ORANGE : Color.WHITE;
|
Color color = bookIsKnown ? Color.ORANGE : Color.WHITE;
|
||||||
|
|
||||||
// Render the poly on the floor
|
// 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);
|
Polygon poly = getCanvasTilePoly(client, localBookcase);
|
||||||
if (poly != null)
|
if (poly != null)
|
||||||
@@ -149,7 +151,7 @@ class KourendLibraryOverlay extends Overlay
|
|||||||
// If the book is singled out, render the text and the book's icon
|
// If the book is singled out, render the text and the book's icon
|
||||||
if (bookIsKnown)
|
if (bookIsKnown)
|
||||||
{
|
{
|
||||||
if (book != null)
|
if (book != null && !shouldHideOverlayIfDuplicateBook(book))
|
||||||
{
|
{
|
||||||
FontMetrics fm = g.getFontMetrics();
|
FontMetrics fm = g.getFontMetrics();
|
||||||
Rectangle2D bounds = fm.getStringBounds(book.getShortName(), g);
|
Rectangle2D bounds = fm.getStringBounds(book.getShortName(), g);
|
||||||
@@ -219,13 +221,10 @@ class KourendLibraryOverlay extends Overlay
|
|||||||
.forEach(n ->
|
.forEach(n ->
|
||||||
{
|
{
|
||||||
Book b = library.getCustomerBook();
|
Book b = library.getCustomerBook();
|
||||||
ItemContainer itemContainer = client.getItemContainer(InventoryID.INVENTORY);
|
boolean doesPlayerContainBook = b != null && plugin.doesPlayerContainBook(b);
|
||||||
boolean hasBookInInventory = itemContainer != null
|
|
||||||
&& b != null
|
|
||||||
&& Arrays.stream(itemContainer.getItems()).anyMatch(item -> item.getId() == b.getItem());
|
|
||||||
LocalPoint local = n.getLocalLocation();
|
LocalPoint local = n.getLocalLocation();
|
||||||
Polygon poly = getCanvasTilePoly(client, local);
|
Polygon poly = getCanvasTilePoly(client, local);
|
||||||
OverlayUtil.renderPolygon(g, poly, hasBookInInventory ? Color.GREEN : Color.WHITE);
|
OverlayUtil.renderPolygon(g, poly, doesPlayerContainBook ? Color.GREEN : Color.WHITE);
|
||||||
Point screen = Perspective.localToCanvas(client, local, client.getPlane(), n.getLogicalHeight());
|
Point screen = Perspective.localToCanvas(client, local, client.getPlane(), n.getLogicalHeight());
|
||||||
if (screen != null)
|
if (screen != null)
|
||||||
{
|
{
|
||||||
@@ -236,4 +235,12 @@ class KourendLibraryOverlay extends Overlay
|
|||||||
|
|
||||||
return null;
|
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 com.google.inject.Provides;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -34,6 +35,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import net.runelite.api.AnimationID;
|
import net.runelite.api.AnimationID;
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
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.MenuAction;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.api.coords.WorldPoint;
|
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.ChatMessage;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.api.events.ItemContainerChanged;
|
||||||
import net.runelite.api.events.MenuOptionClicked;
|
import net.runelite.api.events.MenuOptionClicked;
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
import net.runelite.api.widgets.WidgetInfo;
|
import net.runelite.api.widgets.WidgetInfo;
|
||||||
@@ -94,6 +99,7 @@ public class KourendLibraryPlugin extends Plugin
|
|||||||
private boolean buttonAttached = false;
|
private boolean buttonAttached = false;
|
||||||
private WorldPoint lastBookcaseClick = null;
|
private WorldPoint lastBookcaseClick = null;
|
||||||
private WorldPoint lastBookcaseAnimatedOn = null;
|
private WorldPoint lastBookcaseAnimatedOn = null;
|
||||||
|
private EnumSet<Book> playerBooks = null;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
KourendLibraryConfig provideConfig(ConfigManager configManager)
|
KourendLibraryConfig provideConfig(ConfigManager configManager)
|
||||||
@@ -120,6 +126,8 @@ public class KourendLibraryPlugin extends Plugin
|
|||||||
|
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
|
|
||||||
|
updatePlayerBooks();
|
||||||
|
|
||||||
if (!config.hideButton())
|
if (!config.hideButton())
|
||||||
{
|
{
|
||||||
clientToolbar.addNavigation(navButton);
|
clientToolbar.addNavigation(navButton);
|
||||||
@@ -135,6 +143,7 @@ public class KourendLibraryPlugin extends Plugin
|
|||||||
buttonAttached = false;
|
buttonAttached = false;
|
||||||
lastBookcaseClick = null;
|
lastBookcaseClick = null;
|
||||||
lastBookcaseAnimatedOn = null;
|
lastBookcaseAnimatedOn = null;
|
||||||
|
playerBooks = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@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