Merge pull request #10315 from Hydrox6/library-fix

Improve Kourend Library User Experience
This commit is contained in:
Adam
2019-12-05 19:44:35 -05:00
committed by GitHub
7 changed files with 226 additions and 110 deletions

View File

@@ -52,4 +52,24 @@ public interface KourendLibraryConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "hideVarlamoreEnvoy",
name = "Hide Varlamore Envoy",
description = "Whether to hide Varlamore Envoy, as it is only required in the Depths of Despair quest, and is never asked for."
)
default boolean hideVarlamoreEnvoy()
{
return false;
}
@ConfigItem(
keyName = "showTutorialOverlay",
name = "Show tutorial overlay",
description = "Whether to show an overlay to help understand how to use the plugin"
)
default boolean showTutorialOverlay()
{
return true;
}
}

View File

@@ -36,9 +36,8 @@ 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;
import net.runelite.api.NPC;
import net.runelite.api.Perspective;
import static net.runelite.api.Perspective.getCanvasTilePoly;
import net.runelite.api.Player;
@@ -52,15 +51,12 @@ import net.runelite.client.ui.overlay.OverlayUtil;
class KourendLibraryOverlay extends Overlay
{
private final static int MAXIMUM_DISTANCE = 24;
private static final 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, KourendLibraryConfig config, KourendLibraryPlugin plugin)
{
@@ -76,11 +72,6 @@ class KourendLibraryOverlay extends Overlay
@Override
public Dimension render(Graphics2D g)
{
if (hidden)
{
return null;
}
Player player = client.getLocalPlayer();
if (player == null)
{
@@ -135,7 +126,13 @@ class KourendLibraryOverlay extends Overlay
book = possible.iterator().next();
bookIsKnown = true;
}
Color color = bookIsKnown ? Color.ORANGE : Color.WHITE;
if (book == Book.VARLAMORE_ENVOY && config.hideVarlamoreEnvoy())
{
continue;
}
Color color = bookIsKnown ? (book == library.getCustomerBook() ? Color.GREEN : Color.ORANGE) : Color.WHITE;
// Render the poly on the floor
if (!(bookIsKnown && book == null) && (library.getState() == SolvedState.NO_DATA || book != null || !possible.isEmpty()) && !shouldHideOverlayIfDuplicateBook(book))
@@ -213,24 +210,27 @@ class KourendLibraryOverlay extends Overlay
}
// Render the customer's wanted book on their head and a poly under their feet
LibraryCustomer customer = library.getCustomer();
if (customer != null)
int customerId = library.getCustomerId();
if (customerId != -1)
{
client.getNpcs().stream()
.filter(n -> n.getId() == customer.getId())
.forEach(n ->
for (NPC n : plugin.getNpcsToMark())
{
if (n.getId() != customerId)
{
Book b = library.getCustomerBook();
boolean doesPlayerContainBook = b != null && plugin.doesPlayerContainBook(b);
LocalPoint local = n.getLocalLocation();
Polygon poly = getCanvasTilePoly(client, local);
OverlayUtil.renderPolygon(g, poly, doesPlayerContainBook ? Color.GREEN : Color.WHITE);
Point screen = Perspective.localToCanvas(client, local, client.getPlane(), n.getLogicalHeight());
if (screen != null)
{
g.drawImage(b.getIcon(), screen.getX() - (b.getIcon().getWidth() / 2), screen.getY() - b.getIcon().getHeight(), null);
}
});
continue;
}
Book b = library.getCustomerBook();
boolean doesPlayerContainBook = plugin.doesPlayerContainBook(b);
LocalPoint local = n.getLocalLocation();
Polygon poly = getCanvasTilePoly(client, local);
OverlayUtil.renderPolygon(g, poly, doesPlayerContainBook ? Color.GREEN : Color.WHITE);
Point screen = Perspective.localToCanvas(client, local, client.getPlane(), n.getLogicalHeight());
if (screen != null)
{
g.drawImage(b.getIcon(), screen.getX() - (b.getIcon().getWidth() / 2), screen.getY() - b.getIcon().getHeight(), null);
}
}
}
return null;

View File

@@ -54,8 +54,8 @@ class KourendLibraryPanel extends PluginPanel
private static final ImageIcon RESET_ICON;
private static final ImageIcon RESET_CLICK_ICON;
@Inject
private Library library;
private final KourendLibraryConfig config;
private final Library library;
private final HashMap<Book, BookPanel> bookPanels = new HashMap<>();
@@ -66,6 +66,15 @@ class KourendLibraryPanel extends PluginPanel
RESET_CLICK_ICON = new ImageIcon(ImageUtil.alphaOffset(resetIcon, -100));
}
@Inject
KourendLibraryPanel(KourendLibraryConfig config, Library library)
{
super();
this.config = config;
this.library = library;
}
void init()
{
setLayout(new BorderLayout(0, 5));
@@ -80,6 +89,7 @@ class KourendLibraryPanel extends PluginPanel
c.gridy = 0;
Stream.of(Book.values())
.filter(b -> !b.isDarkManuscript())
.filter(b -> !config.hideVarlamoreEnvoy() || b != Book.VARLAMORE_ENVOY)
.sorted(Comparator.comparing(Book::getShortName))
.forEach(b ->
{
@@ -156,4 +166,11 @@ class KourendLibraryPanel extends PluginPanel
}
});
}
void reload()
{
bookPanels.clear();
removeAll();
init();
}
}

View File

@@ -27,10 +27,14 @@ package net.runelite.client.plugins.kourendlibrary;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.AnimationID;
import net.runelite.api.ChatMessageType;
@@ -39,10 +43,14 @@ import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.MenuAction;
import net.runelite.api.NPC;
import net.runelite.api.NpcID;
import net.runelite.api.Player;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.client.events.ConfigChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.ItemContainerChanged;
@@ -69,9 +77,9 @@ public class KourendLibraryPlugin extends Plugin
{
private static final Pattern BOOK_EXTRACTOR = Pattern.compile("'<col=0000ff>(.*)</col>'");
private static final Pattern TAG_MATCHER = Pattern.compile("(<[^>]*>)");
final static int REGION = 6459;
static final int REGION = 6459;
final static boolean debug = false;
static final boolean debug = false;
@Inject
private ClientToolbar clientToolbar;
@@ -88,6 +96,9 @@ public class KourendLibraryPlugin extends Plugin
@Inject
private KourendLibraryOverlay overlay;
@Inject
private KourendLibraryTutorialOverlay tutorialOverlay;
@Inject
private KourendLibraryConfig config;
@@ -101,6 +112,9 @@ public class KourendLibraryPlugin extends Plugin
private WorldPoint lastBookcaseAnimatedOn = null;
private EnumSet<Book> playerBooks = null;
@Getter(AccessLevel.PACKAGE)
private final Set<NPC> npcsToMark = new HashSet<>();
@Provides
KourendLibraryConfig provideConfig(ConfigManager configManager)
{
@@ -125,6 +139,7 @@ public class KourendLibraryPlugin extends Plugin
.build();
overlayManager.add(overlay);
overlayManager.add(tutorialOverlay);
updatePlayerBooks();
@@ -137,8 +152,8 @@ public class KourendLibraryPlugin extends Plugin
@Override
protected void shutDown()
{
overlay.setHidden(true);
overlayManager.remove(overlay);
overlayManager.remove(tutorialOverlay);
clientToolbar.removeNavigation(navButton);
buttonAttached = false;
lastBookcaseClick = null;
@@ -154,6 +169,11 @@ public class KourendLibraryPlugin extends Plugin
return;
}
if (ev.getKey().equals("hideVarlamoreEnvoy"))
{
panel.reload();
}
SwingUtilities.invokeLater(() ->
{
if (!config.hideButton())
@@ -182,7 +202,6 @@ public class KourendLibraryPlugin extends Plugin
if (MenuAction.GAME_OBJECT_FIRST_OPTION == menuOpt.getMenuAction() && menuOpt.getMenuTarget().contains("Bookshelf"))
{
lastBookcaseClick = WorldPoint.fromScene(client, menuOpt.getActionParam(), menuOpt.getWidgetId(), client.getPlane());
overlay.setHidden(false);
}
}
@@ -252,8 +271,7 @@ public class KourendLibraryPlugin extends Plugin
Widget npcHead = client.getWidget(WidgetInfo.DIALOG_NPC_HEAD_MODEL);
if (npcHead != null)
{
LibraryCustomer cust = LibraryCustomer.getById(npcHead.getModelId());
if (cust != null)
if (isLibraryCustomer(npcHead.getModelId()))
{
Widget textw = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
String text = textw.getText();
@@ -268,13 +286,12 @@ public class KourendLibraryPlugin extends Plugin
return;
}
overlay.setHidden(false);
library.setCustomer(cust, book);
library.setCustomer(npcHead.getModelId(), book);
panel.update();
}
else if (text.contains("You can have this other book") || text.contains("please accept a token of my thanks.") || text.contains("Thanks, I'll get on with reading it."))
{
library.setCustomer(null, null);
library.setCustomer(-1, null);
panel.update();
}
}
@@ -287,6 +304,21 @@ public class KourendLibraryPlugin extends Plugin
updatePlayerBooks();
}
@Subscribe
public void onNpcSpawned(NpcSpawned event)
{
if (isLibraryCustomer(event.getNpc().getId()))
{
npcsToMark.add(event.getNpc());
}
}
@Subscribe
public void onNpcDespawned(NpcDespawned event)
{
npcsToMark.remove(event.getNpc());
}
boolean doesPlayerContainBook(Book book)
{
return playerBooks.contains(book);
@@ -313,4 +345,9 @@ public class KourendLibraryPlugin extends Plugin
playerBooks = books;
}
}
static boolean isLibraryCustomer(int npcId)
{
return npcId == NpcID.VILLIA || npcId == NpcID.PROFESSOR_GRACKLEBONE || npcId == NpcID.SAM_7049;
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2019 Hydrox6 <ikada@protonmail.ch>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.kourendlibrary;
import net.runelite.api.Client;
import net.runelite.api.Player;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import javax.inject.Inject;
import java.awt.Dimension;
import java.awt.Graphics2D;
class KourendLibraryTutorialOverlay extends Overlay
{
private final Client client;
private final KourendLibraryConfig config;
private final Library library;
private final PanelComponent panelComponent;
private final LineComponent noDataMessageComponent;
private final LineComponent incompleteMessageComponent;
private final LineComponent completeMessageComponent;
private final LineComponent sidebarMessageComponent;
@Inject
private KourendLibraryTutorialOverlay(Client client, KourendLibraryConfig config, Library library)
{
this.client = client;
this.config = config;
this.library = library;
panelComponent = new PanelComponent();
panelComponent.setPreferredSize(new Dimension(177, 0));
noDataMessageComponent = LineComponent.builder().left("Click on the white squares to start finding books.").build();
incompleteMessageComponent = LineComponent.builder().left("Some books have been found. Keep checking marked bookcases to find more.").build();
completeMessageComponent = LineComponent.builder().left("All books found.").build();
sidebarMessageComponent = LineComponent.builder().left("Locations are in the sidebar.").build();
setPriority(OverlayPriority.LOW);
setPosition(OverlayPosition.TOP_LEFT);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.showTutorialOverlay())
{
return null;
}
Player player = client.getLocalPlayer();
if (player == null)
{
return null;
}
WorldPoint playerLoc = player.getWorldLocation();
if (playerLoc.getRegionID() != KourendLibraryPlugin.REGION)
{
return null;
}
panelComponent.getChildren().clear();
switch (library.getState())
{
case NO_DATA:
panelComponent.getChildren().add(noDataMessageComponent);
break;
case INCOMPLETE:
panelComponent.getChildren().add(incompleteMessageComponent);
panelComponent.getChildren().add(sidebarMessageComponent);
break;
case COMPLETE:
panelComponent.getChildren().add(completeMessageComponent);
panelComponent.getChildren().add(sidebarMessageComponent);
break;
}
return panelComponent.render(graphics);
}
}

View File

@@ -74,7 +74,7 @@ class Library
private Book customerBook;
@Getter
private LibraryCustomer customer;
private int customerId;
Library()
{
@@ -93,9 +93,9 @@ class Library
return Collections.unmodifiableList(byIndex);
}
void setCustomer(LibraryCustomer customer, Book book)
void setCustomer(int customerId, Book book)
{
this.customer = customer;
this.customerId = customerId;
this.customerBook = book;
}
@@ -131,7 +131,7 @@ class Library
else if (state != SolvedState.NO_DATA)
{
// We know all of the possible things in this shelf.
if (book != null)
if (book != null || bookcase.getPossibleBooks().stream().noneMatch(Book::isDarkManuscript))
{
// Check to see if our guess is wrong
if (!bookcase.getPossibleBooks().contains(book))

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) 2018 Abex
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.kourendlibrary;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import net.runelite.api.NpcID;
enum LibraryCustomer
{
VILLIA(NpcID.VILLIA, "Villia"),
PROFESSOR_GRACKLEBONE(NpcID.PROFESSOR_GRACKLEBONE, "Prof. Gracklebone"),
SAM(NpcID.SAM_7049, "Sam");
@Getter
private final int id;
@Getter
private final String name;
private static final Map<Integer, LibraryCustomer> byId = buildIdMap();
LibraryCustomer(int id, String name)
{
this.id = id;
this.name = name;
}
static LibraryCustomer getById(int id)
{
return byId.get(id);
}
private static Map<Integer, LibraryCustomer> buildIdMap()
{
Map<Integer, LibraryCustomer> byId = new HashMap<>();
for (LibraryCustomer c : values())
{
byId.put(c.id, c);
}
return byId;
}
}