Merge pull request #13124 from Cyborger1/ground-markers-import-export-toggle
This commit is contained in:
@@ -31,9 +31,13 @@ import net.runelite.client.config.Config;
|
|||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
@ConfigGroup("groundMarker")
|
@ConfigGroup(GroundMarkerConfig.GROUND_MARKER_CONFIG_GROUP)
|
||||||
public interface GroundMarkerConfig extends Config
|
public interface GroundMarkerConfig extends Config
|
||||||
{
|
{
|
||||||
|
String GROUND_MARKER_CONFIG_GROUP = "groundMarker";
|
||||||
|
String SHOW_IMPORT_EXPORT_KEY_NAME = "showImportExport";
|
||||||
|
String SHOW_CLEAR_KEY_NAME = "showClear";
|
||||||
|
|
||||||
@Alpha
|
@Alpha
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "markerColor",
|
keyName = "markerColor",
|
||||||
@@ -64,4 +68,24 @@ public interface GroundMarkerConfig extends Config
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = SHOW_IMPORT_EXPORT_KEY_NAME,
|
||||||
|
name = "Show Import/Export options",
|
||||||
|
description = "Show the Import/Export options on the minimap right-click menu"
|
||||||
|
)
|
||||||
|
default boolean showImportExport()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = SHOW_CLEAR_KEY_NAME,
|
||||||
|
name = "Show Clear option",
|
||||||
|
description = "Show the Clear option on the minimap right-click menu, which deletes all currently loaded markers"
|
||||||
|
)
|
||||||
|
default boolean showClear()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import net.runelite.api.events.MenuOptionClicked;
|
|||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.EventBus;
|
import net.runelite.client.eventbus.EventBus;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
|
import net.runelite.client.events.ConfigChanged;
|
||||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
@@ -190,7 +191,14 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
overlayManager.add(minimapOverlay);
|
overlayManager.add(minimapOverlay);
|
||||||
sharingManager.addMenuOptions();
|
if (config.showImportExport())
|
||||||
|
{
|
||||||
|
sharingManager.addImportExportMenuOptions();
|
||||||
|
}
|
||||||
|
if (config.showClear())
|
||||||
|
{
|
||||||
|
sharingManager.addClearMenuOption();
|
||||||
|
}
|
||||||
loadPoints();
|
loadPoints();
|
||||||
eventBus.register(sharingManager);
|
eventBus.register(sharingManager);
|
||||||
}
|
}
|
||||||
@@ -280,6 +288,27 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onConfigChanged(ConfigChanged event)
|
||||||
|
{
|
||||||
|
if (event.getGroup().equals(GroundMarkerConfig.GROUND_MARKER_CONFIG_GROUP)
|
||||||
|
&& (event.getKey().equals(GroundMarkerConfig.SHOW_IMPORT_EXPORT_KEY_NAME)
|
||||||
|
|| event.getKey().equals(GroundMarkerConfig.SHOW_CLEAR_KEY_NAME)))
|
||||||
|
{
|
||||||
|
// Maintain consistent menu option order by removing everything then adding according to config
|
||||||
|
sharingManager.removeMenuOptions();
|
||||||
|
|
||||||
|
if (config.showImportExport())
|
||||||
|
{
|
||||||
|
sharingManager.addImportExportMenuOptions();
|
||||||
|
}
|
||||||
|
if (config.showClear())
|
||||||
|
{
|
||||||
|
sharingManager.addClearMenuOption();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void markTile(LocalPoint localPoint)
|
private void markTile(LocalPoint localPoint)
|
||||||
{
|
{
|
||||||
if (localPoint == null)
|
if (localPoint == null)
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class GroundMarkerSharingManager
|
|||||||
{
|
{
|
||||||
private static final WidgetMenuOption EXPORT_MARKERS_OPTION = new WidgetMenuOption("Export", "Ground Markers", WORLD_MAP_OPTION);
|
private static final WidgetMenuOption EXPORT_MARKERS_OPTION = new WidgetMenuOption("Export", "Ground Markers", WORLD_MAP_OPTION);
|
||||||
private static final WidgetMenuOption IMPORT_MARKERS_OPTION = new WidgetMenuOption("Import", "Ground Markers", WORLD_MAP_OPTION);
|
private static final WidgetMenuOption IMPORT_MARKERS_OPTION = new WidgetMenuOption("Import", "Ground Markers", WORLD_MAP_OPTION);
|
||||||
|
private static final WidgetMenuOption CLEAR_MARKERS_OPTION = new WidgetMenuOption("Clear", "Ground Markers", WORLD_MAP_OPTION);
|
||||||
|
|
||||||
private final GroundMarkerPlugin plugin;
|
private final GroundMarkerPlugin plugin;
|
||||||
private final Client client;
|
private final Client client;
|
||||||
@@ -79,16 +80,22 @@ class GroundMarkerSharingManager
|
|||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addMenuOptions()
|
void addImportExportMenuOptions()
|
||||||
{
|
{
|
||||||
menuManager.addManagedCustomMenu(EXPORT_MARKERS_OPTION);
|
menuManager.addManagedCustomMenu(EXPORT_MARKERS_OPTION);
|
||||||
menuManager.addManagedCustomMenu(IMPORT_MARKERS_OPTION);
|
menuManager.addManagedCustomMenu(IMPORT_MARKERS_OPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addClearMenuOption()
|
||||||
|
{
|
||||||
|
menuManager.addManagedCustomMenu(CLEAR_MARKERS_OPTION);
|
||||||
|
}
|
||||||
|
|
||||||
void removeMenuOptions()
|
void removeMenuOptions()
|
||||||
{
|
{
|
||||||
menuManager.removeManagedCustomMenu(EXPORT_MARKERS_OPTION);
|
menuManager.removeManagedCustomMenu(EXPORT_MARKERS_OPTION);
|
||||||
menuManager.removeManagedCustomMenu(IMPORT_MARKERS_OPTION);
|
menuManager.removeManagedCustomMenu(IMPORT_MARKERS_OPTION);
|
||||||
|
menuManager.removeManagedCustomMenu(CLEAR_MARKERS_OPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean widgetMenuClickedEquals(final WidgetMenuOptionClicked event, final WidgetMenuOption target)
|
private boolean widgetMenuClickedEquals(final WidgetMenuOptionClicked event, final WidgetMenuOption target)
|
||||||
@@ -114,6 +121,10 @@ class GroundMarkerSharingManager
|
|||||||
{
|
{
|
||||||
promptForImport();
|
promptForImport();
|
||||||
}
|
}
|
||||||
|
else if (widgetMenuClickedEquals(event, CLEAR_MARKERS_OPTION))
|
||||||
|
{
|
||||||
|
promptForClear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportGroundMarkers()
|
private void exportGroundMarkers()
|
||||||
@@ -233,6 +244,41 @@ class GroundMarkerSharingManager
|
|||||||
sendChatMessage(importPoints.size() + " ground markers were imported from the clipboard.");
|
sendChatMessage(importPoints.size() + " ground markers were imported from the clipboard.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void promptForClear()
|
||||||
|
{
|
||||||
|
int[] regions = client.getMapRegions();
|
||||||
|
if (regions == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long numActivePoints = Arrays.stream(regions)
|
||||||
|
.mapToLong(regionId -> plugin.getPoints(regionId).size())
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
if (numActivePoints == 0)
|
||||||
|
{
|
||||||
|
sendChatMessage("You have no ground markers to clear.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chatboxPanelManager.openTextMenuInput("Are you sure you want to clear the<br>" + numActivePoints + " currently loaded ground markers?")
|
||||||
|
.option("Yes", () ->
|
||||||
|
{
|
||||||
|
for (int regionId : regions)
|
||||||
|
{
|
||||||
|
plugin.savePoints(regionId, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.loadPoints();
|
||||||
|
sendChatMessage(numActivePoints + " ground marker"
|
||||||
|
+ (numActivePoints == 1 ? " was cleared." : "s were cleared."));
|
||||||
|
|
||||||
|
})
|
||||||
|
.option("No", Runnables::doNothing)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
private void sendChatMessage(final String message)
|
private void sendChatMessage(final String message)
|
||||||
{
|
{
|
||||||
chatMessageManager.queue(QueuedMessage.builder()
|
chatMessageManager.queue(QueuedMessage.builder()
|
||||||
|
|||||||
Reference in New Issue
Block a user