Skip to content

Commit

Permalink
feat: Added shortest path config option (#1784)
Browse files Browse the repository at this point in the history
* feat: Added shortest path config option

* fix: Have shortest path appear/dissapear with config change
  • Loading branch information
Zoinkwiz authored Oct 2, 2024
1 parent cbeff5e commit e41fe52
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/questhelper/QuestHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/questhelper/QuestHelperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/questhelper/managers/QuestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 38 additions & 5 deletions src/main/java/com/questhelper/steps/DetailedQuestStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -85,6 +83,9 @@ public class DetailedQuestStep extends QuestStep
@Inject
WorldMapPointManager worldMapPointManager;

@Inject
EventBus eventBus;

@Inject
private QuestBank questBank;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<String, Object> 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"));
}
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/questhelper/steps/QuestStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,12 @@ protected void renderHoveredItemTooltip(String tooltipText)
protected void renderHoveredMenuEntryPanel(PanelComponent panelComponent, String tooltipText)
{
}

public void setShortestPath()
{
}

public void disableShortestPath()
{
}
}

0 comments on commit e41fe52

Please sign in to comment.