ground markers: Add clear markers menu option

This commit is contained in:
Cyborger1
2021-02-28 16:47:51 -08:00
committed by Jordan Atwood
parent c1b2017bb1
commit 4c048716d4
3 changed files with 68 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ public interface GroundMarkerConfig extends Config
{ {
String GROUND_MARKER_CONFIG_GROUP = "groundMarker"; String GROUND_MARKER_CONFIG_GROUP = "groundMarker";
String SHOW_IMPORT_EXPORT_KEY_NAME = "showImportExport"; String SHOW_IMPORT_EXPORT_KEY_NAME = "showImportExport";
String SHOW_CLEAR_KEY_NAME = "showClear";
@Alpha @Alpha
@ConfigItem( @ConfigItem(
@@ -77,4 +78,14 @@ public interface GroundMarkerConfig extends Config
{ {
return true; 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;
}
} }

View File

@@ -195,6 +195,10 @@ public class GroundMarkerPlugin extends Plugin
{ {
sharingManager.addImportExportMenuOptions(); sharingManager.addImportExportMenuOptions();
} }
if (config.showClear())
{
sharingManager.addClearMenuOption();
}
loadPoints(); loadPoints();
eventBus.register(sharingManager); eventBus.register(sharingManager);
} }
@@ -288,14 +292,20 @@ public class GroundMarkerPlugin extends Plugin
public void onConfigChanged(ConfigChanged event) public void onConfigChanged(ConfigChanged event)
{ {
if (event.getGroup().equals(GroundMarkerConfig.GROUND_MARKER_CONFIG_GROUP) if (event.getGroup().equals(GroundMarkerConfig.GROUND_MARKER_CONFIG_GROUP)
&& event.getKey().equals(GroundMarkerConfig.SHOW_IMPORT_EXPORT_KEY_NAME)) && (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(); sharingManager.removeMenuOptions();
if (config.showImportExport()) if (config.showImportExport())
{ {
sharingManager.addImportExportMenuOptions(); sharingManager.addImportExportMenuOptions();
} }
if (config.showClear())
{
sharingManager.addClearMenuOption();
}
} }
} }

View File

@@ -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;
@@ -85,10 +86,16 @@ class GroundMarkerSharingManager
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()