Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create SpellRequirement for easier spell manipulation. #187

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8b703dc
Initial commit.
Senmori Feb 5, 2021
86df78e
Initial work on adding spell requirements.
Senmori Feb 5, 2021
da7dc18
Fix Mud Rune having wrong staves.
Senmori Feb 5, 2021
89d0ca2
Add Kodai Wand to water staffs since it acts like a source of unlimit…
Senmori Feb 5, 2021
d685e69
Add MagicSpell interface and implement it in Spell.
Senmori Feb 5, 2021
b789a80
Added javadocs.
Senmori Feb 6, 2021
e469f98
Renamed Spell to StandardSpell in order to prepare for future Ancient…
Senmori Feb 6, 2021
68d9f3b
First pass at SpellRequirement.
Senmori Feb 6, 2021
93e77e6
Add support for teleportation tablets.
Senmori Feb 6, 2021
72f1678
Reorganize StandardSpell fields so they match their implementation.
Senmori Feb 6, 2021
e9cabb3
Make ItemRequirement name non-final so we can change them if there is…
Senmori Feb 6, 2021
fba4acd
Merge branch 'master' of github.com:Senmori/quest-helper into spell-req
Senmori Feb 6, 2021
3377004
Renamed enchants to match their in-game names.
Senmori Feb 6, 2021
a2d7efb
Fix some merge issues.
Senmori Feb 6, 2021
42500ff
Fix some merge issues.
Senmori Feb 6, 2021
6de6e0a
Bank icons are present, just not in the correct order.
Senmori Feb 7, 2021
708d65d
Merge branch 'master' of github.com:Senmori/quest-helper into spell-req
Senmori Feb 7, 2021
9600cc2
SpellRequirement now shows the proper items in banks as well as the c…
Senmori Feb 7, 2021
37ff4d8
Let QuestBankTab use config text highlight color to color items.
Senmori Feb 7, 2021
5415e63
Don't let unnecessary objects stick around in QuestBankTab.
Senmori Feb 7, 2021
e1bf72d
Add `requireRunes` method to indicate that the SpellRequirement shoul…
Senmori Feb 7, 2021
26bd0c5
Add requirements of spells to the requirement's tooltip.
Senmori Feb 7, 2021
a4dea03
Spell icons now have a helpful border drawn around them to indicate w…
Senmori Feb 7, 2021
aa264f8
Undo changes to MakingHistory.
Senmori Feb 7, 2021
1fd6438
Remove unused imports.
Senmori Feb 7, 2021
85b3114
Add javadocs to all new methods and classes.
Senmori Feb 7, 2021
cb59de8
Fix NPE in QuestStep.
Senmori Feb 7, 2021
de6b129
Fix potential bug in DigStep where if the player's inventory was full…
Senmori Feb 7, 2021
f83ad76
Merge branch 'master' of github.com:Senmori/quest-helper into spell-req
Senmori Feb 8, 2021
d2d275a
Fix copyright
Senmori Feb 8, 2021
6be927b
Remove TODO for kourend castle teleport because we have the varbit fo…
Senmori Feb 8, 2021
aa22467
Use apache convenience methods for checking if tablet requirement nee…
Senmori Feb 8, 2021
bd719af
Merge branch 'master' of github.com:Senmori/quest-helper into spell-req
Senmori Feb 8, 2021
8d70f3e
Fix merge conflicts.
Senmori Feb 8, 2021
11a5297
Merge branch 'master' of github.com:Zoinkwiz/quest-helper into spell-req
Senmori Feb 8, 2021
8246cc4
Fix merge conflicts.
Senmori Feb 8, 2021
813fb54
Get staffs to work with combo runes and not add duplicate runes if th…
Senmori Feb 10, 2021
885f3ac
Remove StaffItemRequirement.
Senmori Feb 10, 2021
1f2b00b
Merge branch 'master' of github.com:Zoinkwiz/quest-helper into spell-req
Senmori Feb 10, 2021
a2d4087
Fix merge conflicts and add TriFunction for our search preferences enum.
Senmori Feb 10, 2021
a854208
Finalize getting staves to work with combinations of runes as best as…
Senmori Feb 10, 2021
68d0ffc
Update item requirements to match the number of casts.
Senmori Feb 10, 2021
4fd7299
Change keyName of the config option so it better represents what it d…
Senmori Feb 10, 2021
36be39d
Finalize SpellRequirement PR.
Senmori Feb 10, 2021
7e4b8b0
Revert all changes to quest.
Senmori Feb 10, 2021
6ee14a0
getUpdatedTooltip should not use BankItems because we now use ItemSea…
Senmori Feb 10, 2021
d949aa9
Merge branch 'master' of github.com:Zoinkwiz/quest-helper into spell-req
Senmori Feb 10, 2021
a2c3f6a
Merge branch 'master' of github.com:Senmori/quest-helper into spell-req
Senmori Feb 11, 2021
973cf8b
Remove imports from DarknessOfHallowvale.
Senmori Feb 11, 2021
98d000f
Remove forwarding call in NpcStep.
Senmori Feb 11, 2021
f7feadd
Add null check for configs so we don't pass null configs into BankIte…
Senmori Feb 11, 2021
61e98aa
Add missing requirements for some spells.
Senmori Feb 11, 2021
63c1289
Add method to set the staff with an item requirement instead of just …
Senmori Feb 11, 2021
900c505
Merge branch 'master' of github.com:Senmori/quest-helper into spell-req
Senmori Feb 19, 2021
2fcf99a
ItemSearch now supports cached bank items.
Senmori Feb 19, 2021
eee1a3b
Overlays no longer check player banks for item checks.
Senmori Feb 19, 2021
f5e0aad
Add 'In Bank' line to overlays to indicate what white text means.
Senmori Feb 19, 2021
4720765
Fix SpellRequirement bug where it would show an empty staff slot as e…
Senmori Feb 20, 2021
3aef487
Use ternary operator instead of if-else for less of a diff.
Senmori Feb 20, 2021
18ac1c1
Fixed loading issue with Rune and Staff enums.
Senmori Feb 20, 2021
b1814d8
Split up getPanelColor into two methods for easier maintenance.
Senmori Feb 20, 2021
b140f71
Fix ItemRequirement not displaying tooltips.
Senmori Feb 21, 2021
25c7831
Remove in bank line on overlays.
Senmori Feb 21, 2021
aefe15c
BankItemHolder now uses QuestHelperPlugin for the most flexibility.
Senmori Feb 21, 2021
566c982
Merge branch 'master' of github.com:Zoinkwiz/quest-helper into spell-req
Senmori Feb 21, 2021
0bf57a8
Merge branch 'master' of github.com:Senmori/quest-helper into spell-req
Senmori Feb 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions src/main/java/com/questhelper/ItemCollections.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ public class ItemCollections

@Getter
private static final List<Integer> waterStaff = QuestUtil.toLinkedList(
ItemID.FIRE_BATTLESTAFF,
ItemID.MYSTIC_FIRE_STAFF,
ItemID.STAFF_OF_FIRE,
ItemID.KODAI_WAND,
ItemID.WATER_BATTLESTAFF,
ItemID.MYSTIC_WATER_STAFF,
ItemID.STAFF_OF_WATER,
ItemID.MUD_BATTLESTAFF,
ItemID.MYSTIC_MUD_STAFF,
ItemID.MIST_BATTLESTAFF,
Expand Down Expand Up @@ -304,6 +305,42 @@ public class ItemCollections
ItemID.MYSTIC_LAVA_STAFF
);

@Getter
private static final List<Integer> lavaStaff = QuestUtil.toLinkedList(
ItemID.LAVA_BATTLESTAFF,
ItemID.MYSTIC_LAVA_STAFF
);

@Getter
private static final List<Integer> mudStaff = QuestUtil.toLinkedList(
ItemID.MUD_BATTLESTAFF,
ItemID.MYSTIC_MUD_STAFF
);

@Getter
private static final List<Integer> steamStaff = QuestUtil.toLinkedList(
ItemID.STEAM_BATTLESTAFF,
ItemID.MYSTIC_STEAM_STAFF
);

@Getter
private static final List<Integer> smokeStaff = QuestUtil.toLinkedList(
ItemID.SMOKE_BATTLESTAFF,
ItemID.MYSTIC_SMOKE_STAFF
);

@Getter
private static final List<Integer> mistStaff = QuestUtil.toLinkedList(
ItemID.MIST_BATTLESTAFF,
ItemID.MYSTIC_MIST_STAFF
);

@Getter
private static final List<Integer> dustStaff = QuestUtil.toLinkedList(
ItemID.DUST_BATTLESTAFF,
ItemID.MYSTIC_DUST_STAFF
);

// Potions

@Getter
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/questhelper/QuestHelperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public class QuestHelperPlugin extends Plugin

private static final Zone PHOENIX_START_ZONE = new Zone(new WorldPoint(3204, 3488, 0), new WorldPoint(3221, 3501, 0));

@Getter
private final BankItems bankItems = new BankItems();

@Getter
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/questhelper/banktab/BankItemHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
*
* * Copyright (c) 2021, Senmori
* * 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 com.questhelper.banktab;

import com.questhelper.requirements.item.ItemRequirement;
import java.util.List;
import javax.annotation.Nullable;
import net.runelite.api.Client;
import net.runelite.api.Item;

/**
* Represents anything that holds {@link ItemRequirement}s that are to be used
* for displaying via the {@link QuestBankTab}.
* <br>
* Most requirements will not need this interface, however this interface does allow
* that requirement to specify which {@link ItemRequirement} should be displayed
* via the quest bank tab.
*/
public interface BankItemHolder
{
/**
* Get a list of {@link ItemRequirement} to be displayed.
*
* @param client the {@link Client}
* @param checkConsideringSlotRestrictions if the client item container checks should respect slot restrictions
* @param bankItems the player's {@link com.questhelper.BankItems}, this can be null
* @return a list of {@link ItemRequirement} that should be displayed, or an empty list if none are found
*/
List<ItemRequirement> getRequirements(Client client, boolean checkConsideringSlotRestrictions, @Nullable Item[] bankItems);
}
38 changes: 26 additions & 12 deletions src/main/java/com/questhelper/banktab/QuestBankTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
import com.google.common.primitives.Shorts;
import com.questhelper.QuestHelperPlugin;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -43,6 +47,7 @@
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.FontID;
import net.runelite.api.FontTypeFace;
import net.runelite.api.ItemID;
import net.runelite.api.ScriptEvent;
import net.runelite.api.ScriptID;
Expand All @@ -64,6 +69,7 @@
import net.runelite.client.chat.ChatMessageBuilder;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.config.FontType;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.ItemVariationMapping;
Expand Down Expand Up @@ -333,6 +339,12 @@ private int addPluginTabSection(Widget itemContainer, List<BankTabItem> items, L
return 0;
}

// Get FontMetrics so we can accurately get font height/width
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics graphics = img.getGraphics();
FontMetrics fm = graphics.getFontMetrics(FontType.SMALL.getFont());
img = null;
graphics = null;
for (BankTabItem bankTabItem : items)
{
boolean foundItem = false;
Expand All @@ -356,21 +368,22 @@ private int addPluginTabSection(Widget itemContainer, List<BankTabItem> items, L
if (bankTabItem.getQuantity() > 0)
{
String quantityString = QuantityFormatter.quantityToStackSize(bankTabItem.getQuantity());
int extraLength =
QuantityFormatter.quantityToStackSize(widget.getItemQuantity()).length() * 6;
int requirementLength = quantityString.length() * 6;
int itemStackSizeLength = fm.stringWidth(QuantityFormatter.quantityToStackSize(widget.getItemQuantity()));
int requirementLength = fm.stringWidth(quantityString);

int xPos = point.x + 2 + extraLength;
int xPos = point.x + 2 + itemStackSizeLength;
int yPos = point.y - 1;
if (extraLength + requirementLength > 24)
{
if (itemStackSizeLength + requirementLength > 24)
{ // put text on next line
xPos = point.x;
yPos = point.y + 9;
yPos = point.y + fm.getHeight();
}

Color color = questHelper.getConfig().textHighlightColor();

addedWidgets.add(createText(itemContainer,
"/ " + quantityString,
Color.WHITE.getRGB(),
color.getRGB(),
ITEM_HORIZONTAL_SPACING,
TEXT_HEIGHT - 3,
xPos,
Expand Down Expand Up @@ -400,18 +413,19 @@ private int addPluginTabSection(Widget itemContainer, List<BankTabItem> items, L
if (bankTabItem.getQuantity() > 0)
{
String quantityString = QuantityFormatter.quantityToStackSize(bankTabItem.getQuantity());
int requirementLength = quantityString.length() * 5;
int requirementLength = fm.stringWidth(quantityString);
int xPos = adjXOffset + 8;
int yPos = adjYOffset - 1;
if (requirementLength > 20)
{
{ // put text on next line
xPos = adjXOffset;
yPos = adjYOffset + 9;
yPos = adjYOffset + fm.getHeight();
}
Color color = questHelper.getConfig().textHighlightColor();

addedWidgets.add(createText(itemContainer,
"/ " + quantityString,
Color.WHITE.getRGB(),
color.getRGB(),
ITEM_HORIZONTAL_SPACING,
TEXT_HEIGHT - 3,
xPos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
import com.questhelper.requirements.util.LogicType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.inject.Inject;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;

public class QuestHelperBankTagService
Expand Down Expand Up @@ -127,15 +129,34 @@ private void getItemsFromRequirement(BankTabItems pluginItems, ItemRequirement i
getItemsFromRequirement(pluginItems, match);
}
}
else if (itemRequirement instanceof BankItemHolder)
{
BankItemHolder holder = (BankItemHolder) itemRequirement;
final Item[] items = plugin.getBankItems().getItems();
// Force run on client thread even though it's not as responsive as not doing that, however it
// ensures we run on the client thread and never run into threading issues.
plugin.getClientThread().invoke(() -> {
List<ItemRequirement> reqs = holder.getRequirements(plugin.getClient(), false, items);
makeBankHolderItems(reqs, pluginItems); // callback because we can't halt on the client thread
});
}
else
{
if (itemRequirement.getDisplayItemId() != null)
makeBankHolderItems(Collections.singletonList(itemRequirement), pluginItems);
}
}

private void makeBankHolderItems(List<ItemRequirement> requirements, BankTabItems pluginItems)
{
for (ItemRequirement req : requirements)
{
if (req.getDisplayItemId() != null)
{
pluginItems.addItems(new BankTabItem(itemRequirement));
pluginItems.addItems(new BankTabItem(req));
}
else if (!itemRequirement.getDisplayItemIds().contains(-1))
else if (!req.getDisplayItemIds().contains(-1))
{
pluginItems.addItems(makeBankTabItem(itemRequirement));
pluginItems.addItems(makeBankTabItem(req));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/questhelper/panel/QuestOverviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ public void updateRequirementPanels(Client client, List<QuestRequirementPanel> r
{
newColor = itemRequirement.getColorConsideringBank(client, false, bankItems.getItems());
}
String updatedTooltip = itemRequirement.getUpdatedTooltip(client, bankItems);
requirementPanel.setInfoButtonTooltip(updatedTooltip);
}
else
{
Expand Down
46 changes: 34 additions & 12 deletions src/main/java/com/questhelper/panel/QuestRequirementPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import javax.annotation.Nullable;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
Expand All @@ -51,6 +52,10 @@ public class QuestRequirementPanel extends JPanel
@Getter
private final Requirement requirement;

@Nullable
@Getter
private JButton infoButton;

public QuestRequirementPanel(Requirement requirement)
{
this.requirement = requirement;
Expand Down Expand Up @@ -84,20 +89,37 @@ public QuestRequirementPanel(Requirement requirement)
}
}

public void setInfoButtonTooltip(String text)
{
if (infoButton != null)
{
if (text == null || text.isEmpty())
{
infoButton.setToolTipText("");
infoButton.setVisible(false);
}
else
{
String html1 = "<html><body>";
String html2 = "</body></html>";
text = text.replaceAll("\\n", "<br>");
infoButton.setToolTipText(html1 + text + html2);
}
}
}

private void addButtonToPanel(String tooltipText)
{
String html1 = "<html><body>";
String html2 = "</body></html>";
tooltipText = tooltipText.replaceAll("\\n", "<br>");
JButton b = new JButton(INFO_ICON);
b.setPreferredSize(new Dimension(10, 10));
b.setToolTipText(html1 + tooltipText + html2);
b.setBorderPainted(false);
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setContentAreaFilled(false);
b.setMargin(new Insets(0, 0, 0, 0));
add(b);

infoButton = new JButton(INFO_ICON);
infoButton.setPreferredSize(new Dimension(10, 10));
setInfoButtonTooltip(tooltipText);
infoButton.setBorderPainted(false);
infoButton.setFocusPainted(false);
infoButton.setBorderPainted(false);
infoButton.setContentAreaFilled(false);
infoButton.setMargin(new Insets(0, 0, 0, 0));
add(infoButton);
}
}

24 changes: 24 additions & 0 deletions src/main/java/com/questhelper/questhelpers/QuestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;

public class QuestUtil
Expand All @@ -59,4 +60,27 @@ public static <T> List<T> toReversedLinkedList(@Nonnull T... elements)
{
return Collectors.toCollection(ArrayList::new);
}

/**
* Removes all the duplicate elements from a stream and collects them into a
* mutable ArrayList
*
* @param stream stream to remove duplicates from
* @return a mutable list containing all the remaining elements of the stream
*/
public static <T> List<T> collectAndRemoveDuplicates(Stream<T> stream)
{
return stream.distinct().collect(collectToArrayList());
}

/**
* Remove duplicates in the given list.
*
* @param list the list
* @return a mutable list without duplicates.
*/
public static <T> List<T> removeDuplicates(List<T> list)
{
return collectAndRemoveDuplicates(list.stream());
}
}
Loading