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

Add support for filtering by quest experience rewards (skill filtering) #1283

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
86 changes: 86 additions & 0 deletions src/main/java/com/questhelper/QuestHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -206,6 +208,78 @@ public static QuestFilter[] displayFilters()
}
}

enum SkillFilter implements Predicate<QuestHelper>
{
ANY(true),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename so its display name is "Show All", this way it's consistent with the base quest filter

ATTACK,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit of a random suggestion, but you could use a constructor that takes a RuneLite Skill that you get the display name from, which also means you don't need to call Skill.valueOf since you already have the underlying skill
.
It would mean this line would look something like this (probably doesn't compile:

		ATTACK(Skill.ATTACK),

and the SkillFilter constructor looking something like this:

// Constructor for meta filters
SkillFilter(String displayName)
{
    this.skill = null;
    this.displayName = displayName;
    this.predicate = q -> true;
}

// Constructor for skills
SkillFilter(Skill skill)
{
    this.skill = skill;
    this.displayName = skill.getName();
	this.predicate = q -> {
		List<ExperienceReward> experienceRewards = q.getQuest().getQuestHelper().getExperienceRewards();
		if (experienceRewards != null)
		{
			return experienceRewards.stream().anyMatch(reward -> reward.getSkill() == this.skill);
		}
		else
		{
			return false;
		}
	};
}

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<QuestHelper> predicate;

@Getter
private final String displayName;

SkillFilter()
{
this(false);
}

SkillFilter(boolean noPredicate)
{
if (!noPredicate)
{
this.predicate = q -> {
List<ExperienceReward> 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consistent with this. prefix

Suggested change
return predicate.test(quest);
return this.predicate.test(quest);

}

public List<QuestHelper> test(Collection<QuestHelper> helpers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this function looks unused

{
return helpers.stream().filter(this).collect(Collectors.toList());
}
}

enum NpcHighlightStyle
{
NONE,
Expand Down Expand Up @@ -616,4 +690,16 @@ default boolean showCompletedQuests()
{
return false;
}

@ConfigItem(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: Should this filter stick around after a restart?

If it does, the name (& key name) should be changed to match its name in the main panel

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;
}
}
10 changes: 8 additions & 2 deletions src/main/java/com/questhelper/QuestHelperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -251,6 +252,10 @@ public class QuestHelperPlugin extends Plugin
@Inject
GameStateManager gameStateManager;

@Getter
@Inject
private SkillIconManager skillIconManager;

private QuestHelperPanel panel;

private NavigationButton navButton;
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since skillIconManager is unused atm, it might be best to remove this requirement for now

navButton = NavigationButton.builder()
.tooltip("Quest Helper")
.icon(icon)
Expand Down Expand Up @@ -478,7 +483,7 @@ public void onVarbitChanged(VarbitChanged event)
});
}

private final Collection<String> configEvents = Arrays.asList("orderListBy", "filterListBy", "questDifficulty", "showCompletedQuests", "");
private final Collection<String> configEvents = Arrays.asList("orderListBy", "filterListBy", "questDifficulty", "showCompletedQuests", "skillReward", "");
private final Collection<String> configItemEvents = Arrays.asList("highlightNeededQuestItems", "highlightNeededMiniquestItems", "highlightNeededAchievementDiaryItems");

@Subscribe
Expand Down Expand Up @@ -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());
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/com/questhelper/panel/QuestHelperPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -78,6 +81,7 @@ public class QuestHelperPanel extends PluginPanel

private final JPanel allDropdownSections = new JPanel();
private final JComboBox<Enum> filterDropdown, difficultyDropdown, orderDropdown;
private final JComboBox<Enum> skillSelectionPanel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Rename to be consistent with the other dropdowns

Suggested change
private final JComboBox<Enum> skillSelectionPanel;
private final JComboBox<Enum> skillFilterDropdown;


private final IconTextField searchBar = new IconTextField();
private final FixedWidthPanel questListPanel = new FixedWidthPanel();
Expand All @@ -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);

Expand Down Expand Up @@ -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 Filtering");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally prefer if this was labeled Skill Filters (consistent with main Filters), or Skill Filter

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);

Expand All @@ -325,6 +334,7 @@ public void changedUpdate(DocumentEvent e)

questOverviewWrapper.setLayout(new BorderLayout());
questOverviewWrapper.add(questOverviewPanel, BorderLayout.NORTH);

}

private void onSearchBarChanged()
Expand Down Expand Up @@ -398,7 +408,8 @@ private void showMatchingQuests(String text)
}

public void refresh(List<QuestHelper> questHelpers, boolean loggedOut,
Map<QuestHelperQuest, QuestState> completedQuests, QuestHelperConfig.QuestFilter... questFilters)
Map<QuestHelperQuest, QuestState> completedQuests,
QuestHelperConfig.QuestFilter... questFilters)
{
questSelectPanels.forEach(questListPanel::remove);
questSelectPanels.clear();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/questhelper/rewards/ExperienceReward.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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";
}
}
}