-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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,78 @@ public static QuestFilter[] displayFilters() | |||||
} | ||||||
} | ||||||
|
||||||
enum SkillFilter implements Predicate<QuestHelper> | ||||||
{ | ||||||
ANY(true), | ||||||
ATTACK, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: consistent with
Suggested change
|
||||||
} | ||||||
|
||||||
public List<QuestHelper> test(Collection<QuestHelper> helpers) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||||||
|
@@ -616,4 +690,16 @@ default boolean showCompletedQuests() | |||||
{ | ||||||
return false; | ||||||
} | ||||||
|
||||||
@ConfigItem( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Since |
||
navButton = NavigationButton.builder() | ||
.tooltip("Quest Helper") | ||
.icon(icon) | ||
|
@@ -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 | ||
|
@@ -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()); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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<Enum> filterDropdown, difficultyDropdown, orderDropdown; | ||||||
private final JComboBox<Enum> skillSelectionPanel; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 Filtering"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd personally prefer if this was labeled |
||||||
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<QuestHelper> questHelpers, boolean loggedOut, | ||||||
Map<QuestHelperQuest, QuestState> completedQuests, QuestHelperConfig.QuestFilter... questFilters) | ||||||
Map<QuestHelperQuest, QuestState> completedQuests, | ||||||
QuestHelperConfig.QuestFilter... questFilters) | ||||||
{ | ||||||
questSelectPanels.forEach(questListPanel::remove); | ||||||
questSelectPanels.clear(); | ||||||
|
There was a problem hiding this comment.
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