From c296cfbd57bb153b44ce47b4fa7b6a494c1bd566 Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 24 Nov 2024 21:07:56 +0100 Subject: [PATCH] fix: ensure last step is reset on quest shutdown (#1862) * refactor: Consolidate quest shutdown to a single function * fix: ensure last step is reset when a quest is shut down this ensures `panel.updateHighlight` is always called once when the quest is started --- .../questhelper/managers/QuestManager.java | 42 +++++++------------ .../questhelper/panel/QuestOverviewPanel.java | 3 +- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/questhelper/managers/QuestManager.java b/src/main/java/com/questhelper/managers/QuestManager.java index fe0be56992..b79b7d3b84 100644 --- a/src/main/java/com/questhelper/managers/QuestManager.java +++ b/src/main/java/com/questhelper/managers/QuestManager.java @@ -36,6 +36,7 @@ import com.questhelper.steps.QuestStep; import lombok.Getter; import lombok.Setter; +import lombok.extern.slf4j.Slf4j; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.QuestState; @@ -59,6 +60,7 @@ * Responsible for initializing, updating, and shutting down quests. */ @Singleton +@Slf4j public class QuestManager { @Inject @@ -320,32 +322,6 @@ private void initializeNewQuest(QuestHelper questHelper, boolean shouldOpenSideb } } - /** - * Shuts down the quest from the sidebar. - * Unregisters the quest and removes it from the panel. - */ - public void shutDownQuestFromSidebar() - { - if (selectedQuest != null) - { - selectedQuest.shutDown(); - questBankManager.shutDownQuest(); - SwingUtilities.invokeLater(panel::removeQuest); - unregisterQuestFromEventBus(selectedQuest); - - // If closing the item checking helper and should still check in background, start it back up in background - if (selectedQuest.getQuest() == QuestHelperQuest.CHECK_ITEMS && config.highlightItemsBackground()) - { - selectedQuest = null; - startUpBackgroundQuest(QuestHelperQuest.CHECK_ITEMS.getName()); - } - else - { - selectedQuest = null; - } - } - } - private void shutDownPreviousQuest() { shutDownQuest(true); @@ -370,8 +346,20 @@ public void shutDownQuest(boolean shouldUpdateList) questBankManager.shutDownQuest(); SwingUtilities.invokeLater(panel::removeQuest); unregisterQuestFromEventBus(selectedQuest); - selectedQuest = null; + + // If closing the item checking helper and should still check in background, start it back up in background + if (selectedQuest.getQuest() == QuestHelperQuest.CHECK_ITEMS && config.highlightItemsBackground()) + { + selectedQuest = null; + startUpBackgroundQuest(QuestHelperQuest.CHECK_ITEMS.getName()); + } + else + { + selectedQuest = null; + } } + + this.lastStep = null; } public void activateShortestPath() diff --git a/src/main/java/com/questhelper/panel/QuestOverviewPanel.java b/src/main/java/com/questhelper/panel/QuestOverviewPanel.java index 93b107d1e4..f88ff74000 100644 --- a/src/main/java/com/questhelper/panel/QuestOverviewPanel.java +++ b/src/main/java/com/questhelper/panel/QuestOverviewPanel.java @@ -375,9 +375,10 @@ public void removeQuest() revalidate(); } + /// The quest helper's X is clicked private void closeHelper() { - questManager.shutDownQuestFromSidebar(); + questManager.shutDownQuest(false); } void updateCollapseText()