From 69b7edee6000ce9a2b76a15ec97619423ab5baa1 Mon Sep 17 00:00:00 2001 From: 0xTempest Date: Thu, 21 Sep 2023 15:05:14 -0500 Subject: [PATCH 1/3] Add skill reward filtering to quest list --- .../com/questhelper/QuestHelperConfig.java | 80 +++++++++++++++++++ .../com/questhelper/QuestHelperPlugin.java | 10 ++- .../questhelper/panel/QuestHelperPanel.java | 23 ++++-- .../questhelper/rewards/ExperienceReward.java | 6 +- 4 files changed, 109 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/questhelper/QuestHelperConfig.java b/src/main/java/com/questhelper/QuestHelperConfig.java index cfa864117c..1abb2a0fe6 100644 --- a/src/main/java/com/questhelper/QuestHelperConfig.java +++ b/src/main/java/com/questhelper/QuestHelperConfig.java @@ -27,6 +27,7 @@ import com.questhelper.panel.questorders.QuestOrders; import com.questhelper.questhelpers.QuestDetails; import com.questhelper.questhelpers.QuestHelper; +import com.questhelper.rewards.ExperienceReward; import java.awt.Color; import java.util.Arrays; import java.util.Collection; @@ -35,6 +36,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import lombok.Getter; +import net.runelite.api.Skill; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; @@ -206,6 +208,72 @@ public static QuestFilter[] displayFilters() } } + enum SkillFilter implements Predicate + { + ANY(true), + ATTACK, + DEFENCE, + STRENGTH, + HITPOINTS, + RANGED, + PRAYER, + MAGIC, + COOKING, + WOODCUTTING, + FLETCHING, + FISHING, + FIREMAKING, + CRAFTING, + SMITHING, + MINING, + HERBLORE, + AGILITY, + THIEVING, + SLAYER, + FARMING, + RUNECRAFT, + HUNTER, + CONSTRUCTION + + ; + + private final Predicate predicate; + + @Getter + private final String displayName; + + SkillFilter() + { + this(false); + } + + SkillFilter(boolean noPredicate) { + if(!noPredicate) + { + this.predicate = q -> { + List experienceRewards = q.getQuest().getQuestHelper().getExperienceRewards(); + if(experienceRewards != null) { + return experienceRewards.stream().anyMatch(reward -> reward.getSkill() == Skill.valueOf(this.toString())); + } else return false; + }; + } else { + this.predicate = q -> true; + } + this.displayName = Text.titleCase(this); + } + + @Override + public boolean test(QuestHelper quest) + { + return predicate.test(quest); + } + + public List test(Collection helpers) + { + return helpers.stream().filter(this).collect(Collectors.toList()); + } + } + enum NpcHighlightStyle { NONE, @@ -616,4 +684,16 @@ default boolean showCompletedQuests() { return false; } + + @ConfigItem( + keyName = "skillReward", + name = "Skill Reward", + description = "Configures what quests to show based on the experience reward selected", + position = 5, + section = filterSection + ) + default SkillFilter filterBySkillReward() + { + return SkillFilter.ANY; + } } diff --git a/src/main/java/com/questhelper/QuestHelperPlugin.java b/src/main/java/com/questhelper/QuestHelperPlugin.java index c33d3149ed..690bbace8f 100644 --- a/src/main/java/com/questhelper/QuestHelperPlugin.java +++ b/src/main/java/com/questhelper/QuestHelperPlugin.java @@ -101,6 +101,7 @@ import net.runelite.client.events.ClientShutdown; import net.runelite.client.events.ConfigChanged; import net.runelite.client.game.ItemManager; +import net.runelite.client.game.SkillIconManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.bank.BankSearch; @@ -251,6 +252,10 @@ public class QuestHelperPlugin extends Plugin @Inject GameStateManager gameStateManager; + @Getter + @Inject + private SkillIconManager skillIconManager; + private QuestHelperPanel panel; private NavigationButton navButton; @@ -307,7 +312,7 @@ protected void startUp() throws IOException final BufferedImage icon = Icon.QUEST_ICON.getImage(); - panel = new QuestHelperPanel(this); + panel = new QuestHelperPanel(this, skillIconManager); navButton = NavigationButton.builder() .tooltip("Quest Helper") .icon(icon) @@ -478,7 +483,7 @@ public void onVarbitChanged(VarbitChanged event) }); } - private final Collection configEvents = Arrays.asList("orderListBy", "filterListBy", "questDifficulty", "showCompletedQuests", ""); + private final Collection configEvents = Arrays.asList("orderListBy", "filterListBy", "questDifficulty", "showCompletedQuests", "skillReward", ""); private final Collection configItemEvents = Arrays.asList("highlightNeededQuestItems", "highlightNeededMiniquestItems", "highlightNeededAchievementDiaryItems"); @Subscribe @@ -596,6 +601,7 @@ public void updateQuestList() .stream() .filter(config.filterListBy()) .filter(config.difficulty()) + .filter(config.filterBySkillReward()) .filter(QuestDetails::showCompletedQuests) .sorted(config.orderListBy()) .collect(Collectors.toList()); diff --git a/src/main/java/com/questhelper/panel/QuestHelperPanel.java b/src/main/java/com/questhelper/panel/QuestHelperPanel.java index 49206e5e83..4aae1a5103 100644 --- a/src/main/java/com/questhelper/panel/QuestHelperPanel.java +++ b/src/main/java/com/questhelper/panel/QuestHelperPanel.java @@ -32,6 +32,7 @@ import com.questhelper.questhelpers.QuestHelper; import com.questhelper.steps.QuestStep; import java.awt.BorderLayout; +import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -58,6 +59,8 @@ import net.runelite.api.Client; import net.runelite.api.Item; import net.runelite.api.QuestState; +import net.runelite.api.Skill; +import net.runelite.client.game.SkillIconManager; import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.DynamicGridLayout; import net.runelite.client.ui.PluginPanel; @@ -78,6 +81,7 @@ public class QuestHelperPanel extends PluginPanel private final JPanel allDropdownSections = new JPanel(); private final JComboBox filterDropdown, difficultyDropdown, orderDropdown; + private final JComboBox skillSelectionPanel; private final IconTextField searchBar = new IconTextField(); private final FixedWidthPanel questListPanel = new FixedWidthPanel(); @@ -104,7 +108,7 @@ public class QuestHelperPanel extends PluginPanel SETTINGS_ICON = Icon.SETTINGS.getIcon(img -> ImageUtil.resizeImage(img, 16, 16)); } - public QuestHelperPanel(QuestHelperPlugin questHelperPlugin) + public QuestHelperPanel(QuestHelperPlugin questHelperPlugin, SkillIconManager skillIconManager) { super(false); @@ -297,11 +301,16 @@ public void changedUpdate(DocumentEvent e) JPanel orderPanel = makeDropdownPanel(orderDropdown, "Ordering"); orderPanel.setPreferredSize(new Dimension(PANEL_WIDTH, DROPDOWN_HEIGHT)); + skillSelectionPanel = makeNewDropdown(QuestHelperConfig.SkillFilter.values(), "skillReward"); + JPanel skillSortPanel = makeDropdownPanel(skillSelectionPanel, "Skill Sorting"); + skillSortPanel.setPreferredSize(new Dimension(PANEL_WIDTH, DROPDOWN_HEIGHT)); + allDropdownSections.setBorder(new EmptyBorder(0, 0, 10, 0)); - allDropdownSections.setLayout(new BorderLayout(0, BORDER_OFFSET)); - allDropdownSections.add(filtersPanel, BorderLayout.NORTH); - allDropdownSections.add(difficultyPanel, BorderLayout.CENTER); - allDropdownSections.add(orderPanel, BorderLayout.SOUTH); + allDropdownSections.setLayout(new GridLayout(4, 1, 0, 5)); + allDropdownSections.add(filtersPanel); + allDropdownSections.add(difficultyPanel); + allDropdownSections.add(orderPanel); + allDropdownSections.add(skillSortPanel); searchQuestsPanel.add(allDropdownSections, BorderLayout.NORTH); @@ -325,6 +334,7 @@ public void changedUpdate(DocumentEvent e) questOverviewWrapper.setLayout(new BorderLayout()); questOverviewWrapper.add(questOverviewPanel, BorderLayout.NORTH); + } private void onSearchBarChanged() @@ -398,7 +408,8 @@ private void showMatchingQuests(String text) } public void refresh(List questHelpers, boolean loggedOut, - Map completedQuests, QuestHelperConfig.QuestFilter... questFilters) + Map completedQuests, + QuestHelperConfig.QuestFilter... questFilters) { questSelectPanels.forEach(questListPanel::remove); questSelectPanels.clear(); diff --git a/src/main/java/com/questhelper/rewards/ExperienceReward.java b/src/main/java/com/questhelper/rewards/ExperienceReward.java index 25e8476516..ab6915cf61 100644 --- a/src/main/java/com/questhelper/rewards/ExperienceReward.java +++ b/src/main/java/com/questhelper/rewards/ExperienceReward.java @@ -26,12 +26,14 @@ import java.util.Locale; import javax.annotation.Nonnull; +import lombok.Getter; import net.runelite.api.Skill; import net.runelite.client.util.QuantityFormatter; public class ExperienceReward implements Reward { - private final Skill skill; + @Getter + private final Skill skill; private final int experience; public ExperienceReward(Skill skill, int experience) @@ -53,4 +55,4 @@ public String getDisplayText() { return QuantityFormatter.formatNumber(experience) + " " + Character.toUpperCase(skill.name().charAt(0)) + skill.name().toLowerCase(Locale.ROOT).substring(1) + " Experience"; } -} \ No newline at end of file +} From fa8dd9cab27aa98c9fbd8c4f1ad4528eff9134fb Mon Sep 17 00:00:00 2001 From: 0xTempest Date: Thu, 21 Sep 2023 15:06:44 -0500 Subject: [PATCH 2/3] code style formatting --- .../com/questhelper/QuestHelperConfig.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/questhelper/QuestHelperConfig.java b/src/main/java/com/questhelper/QuestHelperConfig.java index 1abb2a0fe6..1665284ad2 100644 --- a/src/main/java/com/questhelper/QuestHelperConfig.java +++ b/src/main/java/com/questhelper/QuestHelperConfig.java @@ -233,9 +233,7 @@ enum SkillFilter implements Predicate FARMING, RUNECRAFT, HUNTER, - CONSTRUCTION - - ; + CONSTRUCTION; private final Predicate predicate; @@ -247,16 +245,24 @@ enum SkillFilter implements Predicate this(false); } - SkillFilter(boolean noPredicate) { - if(!noPredicate) + SkillFilter(boolean noPredicate) + { + if (!noPredicate) { this.predicate = q -> { List experienceRewards = q.getQuest().getQuestHelper().getExperienceRewards(); - if(experienceRewards != null) { + if (experienceRewards != null) + { return experienceRewards.stream().anyMatch(reward -> reward.getSkill() == Skill.valueOf(this.toString())); - } else return false; + } + else + { + return false; + } }; - } else { + } + else + { this.predicate = q -> true; } this.displayName = Text.titleCase(this); From 6daef23e83040a87e8aed6901aa1488fb1edd428 Mon Sep 17 00:00:00 2001 From: 0xTempest Date: Thu, 21 Sep 2023 19:59:21 -0500 Subject: [PATCH 3/3] change to filtering --- src/main/java/com/questhelper/panel/QuestHelperPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/questhelper/panel/QuestHelperPanel.java b/src/main/java/com/questhelper/panel/QuestHelperPanel.java index 4aae1a5103..ce1d3a9dba 100644 --- a/src/main/java/com/questhelper/panel/QuestHelperPanel.java +++ b/src/main/java/com/questhelper/panel/QuestHelperPanel.java @@ -302,7 +302,7 @@ public void changedUpdate(DocumentEvent e) orderPanel.setPreferredSize(new Dimension(PANEL_WIDTH, DROPDOWN_HEIGHT)); skillSelectionPanel = makeNewDropdown(QuestHelperConfig.SkillFilter.values(), "skillReward"); - JPanel skillSortPanel = makeDropdownPanel(skillSelectionPanel, "Skill Sorting"); + JPanel skillSortPanel = makeDropdownPanel(skillSelectionPanel, "Skill Filtering"); skillSortPanel.setPreferredSize(new Dimension(PANEL_WIDTH, DROPDOWN_HEIGHT)); allDropdownSections.setBorder(new EmptyBorder(0, 0, 10, 0));