diff --git a/src/main/java/com/questhelper/QuestHelperConfig.java b/src/main/java/com/questhelper/QuestHelperConfig.java index 747f468dcb..de5cb5b811 100644 --- a/src/main/java/com/questhelper/QuestHelperConfig.java +++ b/src/main/java/com/questhelper/QuestHelperConfig.java @@ -528,6 +528,14 @@ default boolean showWidgetHints() ) default boolean solvePuzzles() { return true; } + @ConfigItem( + keyName = "useShortestPath", + name = "Use 'Shortest Path' plugin", + description = "If you have the 'Shortest Path' plugin downloaded, it will be used to show routes to locations", + section = hintsSection + ) + default boolean useShortestPath() { return false; } + @ConfigSection( position = 3, name = "Colours", diff --git a/src/main/java/com/questhelper/QuestHelperPlugin.java b/src/main/java/com/questhelper/QuestHelperPlugin.java index e9c0ba9439..ebb76d6a4a 100644 --- a/src/main/java/com/questhelper/QuestHelperPlugin.java +++ b/src/main/java/com/questhelper/QuestHelperPlugin.java @@ -376,6 +376,18 @@ public void onConfigChanged(ConfigChanged event) { questManager.updateAllItemsBackgroundHelper(event.getNewValue()); } + + if ("useShortestPath".equals(event.getKey())) + { + if ("true".equals(event.getNewValue())) + { + questManager.activateShortestPath(); + } + else + { + questManager.disableShortestPath(); + } + } } @Subscribe diff --git a/src/main/java/com/questhelper/managers/QuestManager.java b/src/main/java/com/questhelper/managers/QuestManager.java index 767c4ffb58..8836943692 100644 --- a/src/main/java/com/questhelper/managers/QuestManager.java +++ b/src/main/java/com/questhelper/managers/QuestManager.java @@ -374,6 +374,17 @@ public void shutDownQuest(boolean shouldUpdateList) } } + public void activateShortestPath() + { + if (selectedQuest == null) return; + selectedQuest.getCurrentStep().setShortestPath(); + } + + public void disableShortestPath() + { + if (selectedQuest == null) return; + selectedQuest.getCurrentStep().disableShortestPath(); + } /** * Starts up a background quest based on the quest name. diff --git a/src/main/java/com/questhelper/steps/DetailedQuestStep.java b/src/main/java/com/questhelper/steps/DetailedQuestStep.java index 60a8cc2eca..b2e5ee36e3 100644 --- a/src/main/java/com/questhelper/steps/DetailedQuestStep.java +++ b/src/main/java/com/questhelper/steps/DetailedQuestStep.java @@ -42,11 +42,8 @@ import com.questhelper.util.worldmap.WorldMapAreaChanged; import java.awt.*; import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; +import java.util.*; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.Getter; @@ -70,9 +67,10 @@ import net.runelite.api.events.ItemSpawned; import net.runelite.api.widgets.ComponentID; import net.runelite.api.widgets.Widget; +import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.events.PluginMessage; import net.runelite.client.ui.overlay.OverlayUtil; -import net.runelite.client.ui.overlay.components.ComponentConstants; import net.runelite.client.ui.overlay.components.LineComponent; import net.runelite.client.ui.overlay.components.PanelComponent; import net.runelite.client.ui.overlay.tooltip.Tooltip; @@ -85,6 +83,9 @@ public class DetailedQuestStep extends QuestStep @Inject WorldMapPointManager worldMapPointManager; + @Inject + EventBus eventBus; + @Inject private QuestBank questBank; @@ -180,16 +181,20 @@ public void startUp() { mapPoint = new QuestHelperWorldMapPoint(worldPoint, getQuestImage()); worldMapPointManager.add(mapPoint); + + setShortestPath(); } addItemTiles(requirements); addItemTiles(recommended); started = true; + } @Override public void shutDown() { worldMapPointManager.removeIf(QuestHelperWorldMapPoint.class::isInstance); + disableShortestPath(); tileHighlights.clear(); started = false; } @@ -891,4 +896,32 @@ protected boolean isActionForRequiredItem(MenuEntry entry) !((ItemRequirement) item).check(client, false, questBank.getBankItems()) && option.equals("Take")); } + + @Override + public void setShortestPath() + { + if (worldPoint != null) + { + WorldPoint playerWp = client.getLocalPlayer().getWorldLocation(); + if (getQuestHelper().getConfig().useShortestPath() && playerWp != null) { + Map data = new HashMap<>(); + data.put("start", playerWp); + data.put("target", worldPoint); + eventBus.post(new PluginMessage("shortestpath", "path", data)); + } + } + } + + @Override + public void disableShortestPath() + { + if (worldPoint != null) + { + WorldPoint playerWp = client.getLocalPlayer().getWorldLocation(); + if (!getQuestHelper().getConfig().useShortestPath() && playerWp != null) + { + eventBus.post(new PluginMessage("shortestpath", "clear")); + } + } + } } diff --git a/src/main/java/com/questhelper/steps/QuestStep.java b/src/main/java/com/questhelper/steps/QuestStep.java index adee85bbc4..3ac89a291d 100644 --- a/src/main/java/com/questhelper/steps/QuestStep.java +++ b/src/main/java/com/questhelper/steps/QuestStep.java @@ -548,4 +548,12 @@ protected void renderHoveredItemTooltip(String tooltipText) protected void renderHoveredMenuEntryPanel(PanelComponent panelComponent, String tooltipText) { } + + public void setShortestPath() + { + } + + public void disableShortestPath() + { + } }