Skip to content

Commit

Permalink
Swap menu entry swapping to use onClick
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoinkwiz committed Sep 27, 2023
1 parent c782c02 commit c8e5199
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 121 deletions.
91 changes: 20 additions & 71 deletions src/main/java/com/questhelper/QuestHelperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.questhelper.runeliteobjects.Cheerer;
import com.questhelper.runeliteobjects.GlobalFakeObjects;
import com.questhelper.statemanagement.GameStateManager;
import com.questhelper.steps.QuestStep;
import com.questhelper.runeliteobjects.RuneliteConfigSetter;
import com.questhelper.runeliteobjects.extendedruneliteobjects.RuneliteObjectManager;
import com.google.inject.Module;
Expand All @@ -53,39 +52,30 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Named;
import javax.swing.SwingUtilities;
import com.questhelper.tools.Icon;
import com.questhelper.tools.QuestWidgets;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.Player;
import net.runelite.api.QuestState;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.CommandExecuted;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.RuneLite;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.chat.ChatMessageManager;
Expand All @@ -111,12 +101,10 @@
@Slf4j
public class QuestHelperPlugin extends Plugin
{
private static final String MENUOP_STARTHELPER = "Start Quest Helper";
private static final String MENUOP_STOPHELPER = "Stop Quest Helper";
private static final String MENUOP_QUESTHELPER = "Quest Helper";

private static final String MENUOP_STARTGENERICHELPER = "Start Helper";
private static final String MENUOP_STOPGENERICHELPER = "Stop Helper";
@Getter
@Inject
@Named("developerMode")
private boolean developerMode;

@Getter
@Inject
Expand Down Expand Up @@ -148,12 +136,22 @@ public class QuestHelperPlugin extends Plugin
@Inject
private QuestHelperConfig config;

private QuestStep lastStep = null;

@Getter
@Inject
RuneliteObjectManager runeliteObjectManager;

@Inject
private QuestOverlayManager questOverlayManager;

@Inject
private QuestBankManager questBankManager;

@Inject
private QuestManager questManager;

@Inject
private QuestNameToHelper questNameToHelper;

@Getter
@Inject
private ColorPickerManager colorPickerManager;
Expand All @@ -170,8 +168,6 @@ public class QuestHelperPlugin extends Plugin

private NavigationButton navButton;

private boolean loadQuestList;

public Map<String, QuestHelper> backgroundHelpers = new HashMap<>();
public SortedMap<QuestHelperQuest, List<ItemRequirement>> itemRequirements = new TreeMap<>();
public SortedMap<QuestHelperQuest, List<ItemRequirement>> itemRecommended = new TreeMap<>();
Expand All @@ -184,22 +180,8 @@ public class QuestHelperPlugin extends Plugin
@Getter
private int lastTickBankUpdated = -1;

@Getter
@Inject
@Named("developerMode")
private boolean developerMode;

@Inject
private QuestOverlayManager questOverlayManager;

@Inject
private QuestBankManager questBankManager;

@Inject
private QuestManager questManager;

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

@Provides
QuestHelperConfig getConfig(ConfigManager configManager)
Expand Down Expand Up @@ -245,8 +227,6 @@ protected void startUp() throws IOException
if (client.getGameState() == GameState.LOGGED_IN)
{
questManager.setupOnLogin();
// Update with new items
loadQuestList = true;
GlobalFakeObjects.createNpcs(client, runeliteObjectManager, configManager, config);
}
});
Expand Down Expand Up @@ -306,12 +286,8 @@ public void onGameStateChanged(final GameStateChanged event)
if (state == GameState.LOGGED_IN)
{
GlobalFakeObjects.createNpcs(client, runeliteObjectManager, configManager, config);
loadQuestList = true;
questBankManager.setUnknownInitialState();
clientThread.invokeLater(() -> {
// TODO: Need to set up sidebar
questManager.setupOnLogin();
});
clientThread.invokeLater(() -> questManager.setupOnLogin());
}
}

Expand All @@ -326,9 +302,6 @@ public void onVarbitChanged(VarbitChanged event)
questManager.handleVarbitChanged();
}

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

@Subscribe
public void onConfigChanged(ConfigChanged event)
{
Expand Down Expand Up @@ -420,7 +393,7 @@ public void refreshBank()
clientThread.invokeLater(() -> questBankManager.refreshBankTab());
}

public List<BankTabItems> getPluginBankTagItemsForSections(boolean onlyGetMissingItems)
public List<BankTabItems> getPluginBankTagItemsForSections()
{
return questBankManager.getBankTagService().getPluginBankTagItemsForSections(false);
}
Expand Down Expand Up @@ -453,30 +426,6 @@ public List<Integer> itemsToTag()
return questBankManager.getBankTagService().itemsToTag();
}

@Subscribe
private void onMenuOptionClicked(MenuOptionClicked event)
{
if (event.getMenuAction() != MenuAction.RUNELITE)
{
return;
}

switch (event.getMenuOption())
{
case MENUOP_STARTHELPER:
case MENUOP_STARTGENERICHELPER:
event.consume();
String quest = Text.removeTags(event.getMenuTarget());
questManager.startUpQuest(QuestHelperQuest.getByName(quest));
break;
case MENUOP_STOPHELPER:
case MENUOP_STOPGENERICHELPER:
event.consume();
questManager.shutDownQuest(true);
break;
}
}

private void addCheerer()
{
Cheerer.activateCheerer(client, chatMessageManager);
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/questhelper/bank/banktab/QuestBankTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ public class QuestBankTab

private final ArrayList<Widget> addedWidgets = new ArrayList<>();

private ArrayList<Integer> priorEvents = new ArrayList<>();

boolean isSwappingDuplicates = false;

@Inject
private ItemManager itemManager;

Expand Down Expand Up @@ -332,7 +328,7 @@ public void onScriptPostFired(ScriptPostFired event)
// Desired extra functionality:
// X - Recommended items also included in section
// X - Expand option to see alternative items for a recommended item
List<BankTabItems> tabLayout = questHelper.getPluginBankTagItemsForSections(false);
List<BankTabItems> tabLayout = questHelper.getPluginBankTagItemsForSections();

if (tabLayout != null)
{
Expand Down Expand Up @@ -400,6 +396,7 @@ else if (!itemWidget.isHidden() &&
totalSectionsHeight = addGeneralSection(itemContainer, itemList, totalSectionsHeight);

final Widget bankItemContainer = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
if (bankItemContainer == null) return;
int itemContainerHeight = bankItemContainer.getHeight();

bankItemContainer.setScrollHeight(Math.max(totalSectionsHeight, itemContainerHeight));
Expand Down

This file was deleted.

33 changes: 22 additions & 11 deletions src/main/java/com/questhelper/managers/QuestNameToHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void setupQuestMenuOptions(MenuEntry[] menuEntries, int widgetIndex, int
for (String achievementTier : achievementTiers)
{
menuEntries = addRightClickMenuOptions(diary + achievementTier + " Diary", MENUOP_GENERICHELPER,
"<col=ff9040>" + diary + achievementTier + " Diary</col>", menuEntries, widgetIndex, widgetID);
diary + achievementTier + " Diary", menuEntries, widgetIndex, widgetID);
}
}

Expand All @@ -145,7 +145,7 @@ public void setupQuestMenuOptions(MenuEntry[] menuEntries, int widgetIndex, int
if (questManager.getSelectedQuest() != null &&
(questManager.getSelectedQuest().getQuest().getId() == QuestHelperQuest.SHIELD_OF_ARRAV_PHOENIX_GANG.getId()))
{
addNewEntry(menuEntries, MENUOP_STOPHELPER, target, widgetIndex, widgetID);
addNewEntry(menuEntries, MENUOP_STOPHELPER, target, widgetIndex, widgetID, false);
}
else
{
Expand All @@ -156,12 +156,12 @@ public void setupQuestMenuOptions(MenuEntry[] menuEntries, int widgetIndex, int
if (questHelperPhoenix != null && !questHelperPhoenix.isCompleted())
{
menuEntries = addRightClickMenuOptions(phoenixName, MENUOP_QUESTHELPER,
"<col=ff9040>" + phoenixName + "</col>", menuEntries, widgetIndex, widgetID);
phoenixName, menuEntries, widgetIndex, widgetID);
}
if (questHelperBlackArm != null && !questHelperBlackArm.isCompleted())
{
addRightClickMenuOptions(blackArmName, MENUOP_QUESTHELPER,
"<col=ff9040>" + blackArmName + "</col>", menuEntries, widgetIndex, widgetID);
blackArmName, menuEntries, widgetIndex, widgetID);
}
}
}
Expand All @@ -178,7 +178,7 @@ else if (target.equals("Recipe for Disaster"))
for (String rfdName : RFD_NAMES)
{
menuEntries = addRightClickMenuOptions(rfdName, MENUOP_QUESTHELPER,
"<col=ff9040>" + rfdName + "</col>", menuEntries, widgetIndex, widgetID);
rfdName, menuEntries, widgetIndex, widgetID);
}
}
}
Expand All @@ -189,11 +189,11 @@ else if (target.equals("Recipe for Disaster"))
{
if (questManager.getSelectedQuest() != null && questManager.getSelectedQuest().getQuest().getName().equals(target))
{
addNewEntry(menuEntries, MENUOP_STOPHELPER, target, widgetIndex, widgetID);
addNewEntry(menuEntries, MENUOP_STOPHELPER, target, widgetIndex, widgetID, false);
}
else
{
addNewEntry(menuEntries, MENUOP_STARTHELPER, target, widgetIndex, widgetID);
addNewEntry(menuEntries, MENUOP_STARTHELPER, target, widgetIndex, widgetID, true);
}
}
}
Expand All @@ -209,24 +209,35 @@ private MenuEntry[] addRightClickMenuOptions(String helperName, String entryName
{
if (questManager.getSelectedQuest() != null && questManager.getSelectedQuest().getQuest().getName().equals(helperName))
{
return addNewEntry(menuEntries, "Stop " + entryName, target, widgetIndex, widgetID);
return addNewEntry(menuEntries, "Stop " + entryName, target, widgetIndex, widgetID, false);
}
else
{
return addNewEntry(menuEntries, "Start " + entryName, target, widgetIndex, widgetID);
return addNewEntry(menuEntries, "Start " + entryName, target, widgetIndex, widgetID, true);
}
}

return menuEntries;
}

private MenuEntry[] addNewEntry(MenuEntry[] menuEntries, String newEntry, String target, int widgetIndex, int widgetID)
private MenuEntry[] addNewEntry(MenuEntry[] menuEntries, String newEntry, String target, int widgetIndex, int widgetID, boolean startUp)
{
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1);

client.createMenuEntry(menuEntries.length - 1)
.setOption(newEntry)
.setTarget(target)
.setTarget("<col=ff9040>" + target + "</col>")
.onClick((menuEntry -> {
if (startUp)
{
String quest = Text.removeTags(target);
questManager.startUpQuest(QuestHelperQuest.getByName(quest));
}
else
{
questManager.shutDownQuest(true);
}
}))
.setType(MenuAction.RUNELITE)
.setParam0(widgetIndex)
.setParam1(widgetID);
Expand Down

0 comments on commit c8e5199

Please sign in to comment.