ground markers: add tile labels
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
package net.runelite.client.plugins.groundmarkers;
|
package net.runelite.client.plugins.groundmarkers;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
import net.runelite.api.coords.WorldPoint;
|
import net.runelite.api.coords.WorldPoint;
|
||||||
|
|
||||||
@@ -36,5 +37,8 @@ import net.runelite.api.coords.WorldPoint;
|
|||||||
class ColorTileMarker
|
class ColorTileMarker
|
||||||
{
|
{
|
||||||
private WorldPoint worldPoint;
|
private WorldPoint worldPoint;
|
||||||
|
@Nullable
|
||||||
private Color color;
|
private Color color;
|
||||||
|
@Nullable
|
||||||
|
private String label;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,14 +25,17 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.groundmarkers;
|
package net.runelite.client.plugins.groundmarkers;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.coords.LocalPoint;
|
import net.runelite.api.coords.LocalPoint;
|
||||||
import net.runelite.api.coords.WorldPoint;
|
import net.runelite.api.coords.WorldPoint;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
@@ -79,13 +82,13 @@ public class GroundMarkerOverlay extends Overlay
|
|||||||
tileColor = config.markerColor();
|
tileColor = config.markerColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
drawTile(graphics, worldPoint, tileColor);
|
drawTile(graphics, worldPoint, tileColor, point.getLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawTile(Graphics2D graphics, WorldPoint point, Color color)
|
private void drawTile(Graphics2D graphics, WorldPoint point, Color color, @Nullable String label)
|
||||||
{
|
{
|
||||||
WorldPoint playerLocation = client.getLocalPlayer().getWorldLocation();
|
WorldPoint playerLocation = client.getLocalPlayer().getWorldLocation();
|
||||||
|
|
||||||
@@ -101,11 +104,18 @@ public class GroundMarkerOverlay extends Overlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
Polygon poly = Perspective.getCanvasTilePoly(client, lp);
|
Polygon poly = Perspective.getCanvasTilePoly(client, lp);
|
||||||
if (poly == null)
|
if (poly != null)
|
||||||
{
|
{
|
||||||
return;
|
OverlayUtil.renderPolygon(graphics, poly, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
OverlayUtil.renderPolygon(graphics, poly, color);
|
if (!Strings.isNullOrEmpty(label))
|
||||||
|
{
|
||||||
|
Point canvasTextLocation = Perspective.getCanvasTextLocation(client, graphics, lp, label, 0);
|
||||||
|
if (canvasTextLocation != null)
|
||||||
|
{
|
||||||
|
OverlayUtil.renderTextLocation(graphics, canvasTextLocation, label, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import net.runelite.api.events.MenuEntryAdded;
|
|||||||
import net.runelite.api.events.MenuOptionClicked;
|
import net.runelite.api.events.MenuOptionClicked;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
|
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
@@ -68,6 +69,7 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
private static final String CONFIG_GROUP = "groundMarker";
|
private static final String CONFIG_GROUP = "groundMarker";
|
||||||
private static final String MARK = "Mark tile";
|
private static final String MARK = "Mark tile";
|
||||||
private static final String UNMARK = "Unmark tile";
|
private static final String UNMARK = "Unmark tile";
|
||||||
|
private static final String LABEL = "Label tile";
|
||||||
private static final String WALK_HERE = "Walk here";
|
private static final String WALK_HERE = "Walk here";
|
||||||
private static final String REGION_PREFIX = "region_";
|
private static final String REGION_PREFIX = "region_";
|
||||||
|
|
||||||
@@ -97,6 +99,9 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private KeyManager keyManager;
|
private KeyManager keyManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ChatboxPanelManager chatboxPanelManager;
|
||||||
|
|
||||||
private void savePoints(int regionId, Collection<GroundMarkerPoint> points)
|
private void savePoints(int regionId, Collection<GroundMarkerPoint> points)
|
||||||
{
|
{
|
||||||
if (points == null || points.isEmpty())
|
if (points == null || points.isEmpty())
|
||||||
@@ -166,15 +171,31 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
return points.stream()
|
return points.stream()
|
||||||
.map(point -> new ColorTileMarker(
|
.map(point -> new ColorTileMarker(
|
||||||
WorldPoint.fromRegion(point.getRegionId(), point.getRegionX(), point.getRegionY(), point.getZ()),
|
WorldPoint.fromRegion(point.getRegionId(), point.getRegionX(), point.getRegionY(), point.getZ()),
|
||||||
point.getColor()))
|
point.getColor(), point.getLabel()))
|
||||||
.flatMap(colorTile ->
|
.flatMap(colorTile ->
|
||||||
{
|
{
|
||||||
final Collection<WorldPoint> localWorldPoints = WorldPoint.toLocalInstance(client, colorTile.getWorldPoint());
|
final Collection<WorldPoint> localWorldPoints = WorldPoint.toLocalInstance(client, colorTile.getWorldPoint());
|
||||||
return localWorldPoints.stream().map(wp -> new ColorTileMarker(wp, colorTile.getColor()));
|
return localWorldPoints.stream().map(wp -> new ColorTileMarker(wp, colorTile.getColor(), colorTile.getLabel()));
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startUp()
|
||||||
|
{
|
||||||
|
overlayManager.add(overlay);
|
||||||
|
overlayManager.add(minimapOverlay);
|
||||||
|
loadPoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutDown()
|
||||||
|
{
|
||||||
|
overlayManager.remove(overlay);
|
||||||
|
overlayManager.remove(minimapOverlay);
|
||||||
|
points.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||||
{
|
{
|
||||||
@@ -200,17 +221,26 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
|
||||||
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1);
|
|
||||||
MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry();
|
|
||||||
|
|
||||||
final WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, selectedSceneTile.getLocalLocation());
|
final WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, selectedSceneTile.getLocalLocation());
|
||||||
final int regionId = worldPoint.getRegionID();
|
final int regionId = worldPoint.getRegionID();
|
||||||
final GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane(), config.markerColor());
|
final GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane(), null, null);
|
||||||
|
final boolean exists = getPoints(regionId).contains(point);
|
||||||
|
|
||||||
menuEntry.setOption(getPoints(regionId).contains(point) ? UNMARK : MARK);
|
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||||
menuEntry.setTarget(event.getTarget());
|
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + (exists ? 2 : 1));
|
||||||
menuEntry.setType(MenuAction.RUNELITE.getId());
|
|
||||||
|
MenuEntry mark = menuEntries[menuEntries.length - 1] = new MenuEntry();
|
||||||
|
mark.setOption(exists ? UNMARK : MARK);
|
||||||
|
mark.setTarget(event.getTarget());
|
||||||
|
mark.setType(MenuAction.RUNELITE.getId());
|
||||||
|
|
||||||
|
if (exists)
|
||||||
|
{
|
||||||
|
MenuEntry label = menuEntries[menuEntries.length - 2] = new MenuEntry();
|
||||||
|
label.setOption(LABEL);
|
||||||
|
label.setTarget(event.getTarget());
|
||||||
|
label.setType(MenuAction.RUNELITE.getId());
|
||||||
|
}
|
||||||
|
|
||||||
client.setMenuEntries(menuEntries);
|
client.setMenuEntries(menuEntries);
|
||||||
}
|
}
|
||||||
@@ -219,8 +249,7 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onMenuOptionClicked(MenuOptionClicked event)
|
public void onMenuOptionClicked(MenuOptionClicked event)
|
||||||
{
|
{
|
||||||
if (event.getMenuAction().getId() != MenuAction.RUNELITE.getId() ||
|
if (event.getMenuAction().getId() != MenuAction.RUNELITE.getId())
|
||||||
!(event.getMenuOption().equals(MARK) || event.getMenuOption().equals(UNMARK)))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -230,23 +259,16 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
markTile(target.getLocalLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
final String option = event.getMenuOption();
|
||||||
protected void startUp()
|
if (option.equals(MARK) || option.equals(UNMARK))
|
||||||
{
|
{
|
||||||
overlayManager.add(overlay);
|
markTile(target.getLocalLocation());
|
||||||
overlayManager.add(minimapOverlay);
|
}
|
||||||
loadPoints();
|
else if (option.equals(LABEL))
|
||||||
}
|
{
|
||||||
|
labelTile(target);
|
||||||
@Override
|
}
|
||||||
protected void shutDown()
|
|
||||||
{
|
|
||||||
overlayManager.remove(overlay);
|
|
||||||
overlayManager.remove(minimapOverlay);
|
|
||||||
points.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markTile(LocalPoint localPoint)
|
private void markTile(LocalPoint localPoint)
|
||||||
@@ -259,7 +281,7 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, localPoint);
|
WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, localPoint);
|
||||||
|
|
||||||
int regionId = worldPoint.getRegionID();
|
int regionId = worldPoint.getRegionID();
|
||||||
GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane(), config.markerColor());
|
GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane(), config.markerColor(), null);
|
||||||
log.debug("Updating point: {} - {}", point, worldPoint);
|
log.debug("Updating point: {} - {}", point, worldPoint);
|
||||||
|
|
||||||
List<GroundMarkerPoint> groundMarkerPoints = new ArrayList<>(getPoints(regionId));
|
List<GroundMarkerPoint> groundMarkerPoints = new ArrayList<>(getPoints(regionId));
|
||||||
@@ -276,4 +298,35 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
|
|
||||||
loadPoints();
|
loadPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void labelTile(Tile tile)
|
||||||
|
{
|
||||||
|
LocalPoint localPoint = tile.getLocalLocation();
|
||||||
|
WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, localPoint);
|
||||||
|
final int regionId = worldPoint.getRegionID();
|
||||||
|
|
||||||
|
chatboxPanelManager.openTextInput("Tile label")
|
||||||
|
.onDone((input) ->
|
||||||
|
{
|
||||||
|
input = Strings.emptyToNull(input);
|
||||||
|
|
||||||
|
GroundMarkerPoint searchPoint = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane(), null, null);
|
||||||
|
Collection<GroundMarkerPoint> points = getPoints(regionId);
|
||||||
|
GroundMarkerPoint existing = points.stream()
|
||||||
|
.filter(p -> p.equals(searchPoint))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
if (existing == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GroundMarkerPoint newPoint = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane(), existing.getColor(), input);
|
||||||
|
points.remove(searchPoint);
|
||||||
|
points.add(newPoint);
|
||||||
|
savePoints(regionId, points);
|
||||||
|
|
||||||
|
loadPoints();
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
package net.runelite.client.plugins.groundmarkers;
|
package net.runelite.client.plugins.groundmarkers;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
|
||||||
@@ -33,12 +34,15 @@ import lombok.Value;
|
|||||||
* Used for serialization of ground marker points.
|
* Used for serialization of ground marker points.
|
||||||
*/
|
*/
|
||||||
@Value
|
@Value
|
||||||
@EqualsAndHashCode(exclude = { "color" })
|
@EqualsAndHashCode(exclude = { "color", "label" })
|
||||||
class GroundMarkerPoint
|
class GroundMarkerPoint
|
||||||
{
|
{
|
||||||
private int regionId;
|
private int regionId;
|
||||||
private int regionX;
|
private int regionX;
|
||||||
private int regionY;
|
private int regionY;
|
||||||
private int z;
|
private int z;
|
||||||
|
@Nullable
|
||||||
private Color color;
|
private Color color;
|
||||||
|
@Nullable
|
||||||
|
private String label;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user