From 5f5123a9c3258adeb7bdfb146ddaef4c2114a28a Mon Sep 17 00:00:00 2001 From: dekvall Date: Mon, 2 Mar 2020 20:25:23 +0100 Subject: [PATCH] object indicators: add support for multiple colors --- .../objectindicators/ColorTileObject.java | 42 ++++++++++++++++ .../ObjectIndicatorsConfig.java | 10 ++++ .../ObjectIndicatorsOverlay.java | 16 +++++-- .../ObjectIndicatorsPlugin.java | 48 +++++++++++-------- .../plugins/objectindicators/ObjectPoint.java | 4 +- 5 files changed, 96 insertions(+), 24 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ColorTileObject.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ColorTileObject.java b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ColorTileObject.java new file mode 100644 index 0000000000..1af342cd20 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ColorTileObject.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020, dekvall + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.objectindicators; + +import java.awt.Color; +import lombok.RequiredArgsConstructor; +import lombok.Value; +import net.runelite.api.TileObject; + +/** + * Used to denote marked objects and their colors. + * Note: This is not used for serialization of object indicators; see {@link ObjectPoint} + */ +@Value +@RequiredArgsConstructor +class ColorTileObject +{ + private final TileObject tileObject; + private final Color color; +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsConfig.java index e7bd35eb58..049269756b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsConfig.java @@ -44,4 +44,14 @@ public interface ObjectIndicatorsConfig extends Config { return Color.YELLOW; } + + @ConfigItem( + keyName = "rememberObjectColors", + name = "Remember color per object", + description = "Color objects using the color from time of marking" + ) + default boolean rememberObjectColors() + { + return false; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsOverlay.java index 21d0a4692d..0e52edf0a4 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsOverlay.java @@ -24,6 +24,7 @@ */ package net.runelite.client.plugins.objectindicators; +import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Shape; @@ -60,13 +61,22 @@ class ObjectIndicatorsOverlay extends Overlay @Override public Dimension render(Graphics2D graphics) { - for (TileObject object : plugin.getObjects()) + for (ColorTileObject colorTileObject : plugin.getObjects()) { + TileObject object = colorTileObject.getTileObject(); + Color color = colorTileObject.getColor(); + if (object.getPlane() != client.getPlane()) { continue; } + if (color == null || !config.rememberObjectColors()) + { + // Fallback to the current config if the object is marked before the addition of multiple colors + color = config.markerColor(); + } + final Shape polygon; Shape polygon2 = null; @@ -95,12 +105,12 @@ class ObjectIndicatorsOverlay extends Overlay if (polygon != null) { - OverlayUtil.renderPolygon(graphics, polygon, config.markerColor()); + OverlayUtil.renderPolygon(graphics, polygon, color); } if (polygon2 != null) { - OverlayUtil.renderPolygon(graphics, polygon2, config.markerColor()); + OverlayUtil.renderPolygon(graphics, polygon2, color); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java index 397b24b29c..1d826d7641 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java @@ -29,6 +29,7 @@ import com.google.common.base.Strings; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.google.inject.Provides; +import java.awt.Color; import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Arrays; @@ -91,7 +92,7 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener private final Gson GSON = new Gson(); @Getter(AccessLevel.PACKAGE) - private final List objects = new ArrayList<>(); + private final List objects = new ArrayList<>(); private final Map> points = new HashMap<>(); private boolean hotKeyPressed; @@ -110,6 +111,9 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener @Inject private KeyManager keyManager; + @Inject + private ObjectIndicatorsConfig config; + @Provides ObjectIndicatorsConfig provideConfig(ConfigManager configManager) { @@ -178,54 +182,50 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener WallObject previous = event.getPrevious(); WallObject wallObject = event.getWallObject(); - objects.remove(previous); + objects.removeIf(o -> o.getTileObject() == previous); checkObjectPoints(wallObject); } @Subscribe public void onWallObjectDespawned(WallObjectDespawned event) { - objects.remove(event.getWallObject()); + objects.removeIf(o -> o.getTileObject() == event.getWallObject()); } @Subscribe public void onGameObjectSpawned(GameObjectSpawned event) { - final GameObject eventObject = event.getGameObject(); - checkObjectPoints(eventObject); + checkObjectPoints(event.getGameObject()); } @Subscribe public void onDecorativeObjectSpawned(DecorativeObjectSpawned event) { - final DecorativeObject eventObject = event.getDecorativeObject(); - checkObjectPoints(eventObject); + checkObjectPoints(event.getDecorativeObject()); } @Subscribe public void onGameObjectDespawned(GameObjectDespawned event) { - objects.remove(event.getGameObject()); + objects.removeIf(o -> o.getTileObject() == event.getGameObject()); } @Subscribe public void onDecorativeObjectDespawned(DecorativeObjectDespawned event) { - objects.remove(event.getDecorativeObject()); + objects.removeIf(o -> o.getTileObject() == event.getDecorativeObject()); } @Subscribe - public void onGroundObjectSpawned(GroundObjectSpawned groundObjectSpawned) + public void onGroundObjectSpawned(GroundObjectSpawned event) { - final GroundObject groundObject = groundObjectSpawned.getGroundObject(); - checkObjectPoints(groundObject); + checkObjectPoints(event.getGroundObject()); } @Subscribe - public void onGroundObjectDespawned(GroundObjectDespawned groundObjectDespawned) + public void onGroundObjectDespawned(GroundObjectDespawned event) { - GroundObject groundObject = groundObjectDespawned.getGroundObject(); - objects.remove(groundObject); + objects.removeIf(o -> o.getTileObject() == event.getGroundObject()); } @Subscribe @@ -263,11 +263,17 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener } final Tile tile = client.getScene().getTiles()[client.getPlane()][event.getActionParam0()][event.getActionParam1()]; + final TileObject tileObject = findTileObject(tile, event.getIdentifier()); + + if (tileObject == null) + { + return; + } MenuEntry[] menuEntries = client.getMenuEntries(); menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1); MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry(); - menuEntry.setOption(objects.contains(findTileObject(tile, event.getIdentifier())) ? UNMARK : MARK); + menuEntry.setOption(objects.stream().anyMatch(o -> o.getTileObject() == tileObject) ? UNMARK : MARK); menuEntry.setTarget(event.getTarget()); menuEntry.setParam0(event.getActionParam0()); menuEntry.setParam1(event.getActionParam1()); @@ -332,7 +338,7 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener if (objectPoint.getName().equals(getObjectComposition(object.getId()).getName())) { log.debug("Marking object {} due to matching {}", object, objectPoint); - objects.add(object); + objects.add(new ColorTileObject(object, objectPoint.getColor())); break; } } @@ -417,17 +423,19 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener { final WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, object.getLocalLocation()); final int regionId = worldPoint.getRegionID(); + final Color color = config.markerColor(); final ObjectPoint point = new ObjectPoint( object.getId(), name, regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), - worldPoint.getPlane()); + worldPoint.getPlane(), + color); Set objectPoints = points.computeIfAbsent(regionId, k -> new HashSet<>()); - if (objects.remove(object)) + if (objects.removeIf(o -> o.getTileObject() == object)) { // Find the object point that caused this object to be marked, there are two cases: // 1) object is a multiloc, the name may have changed since marking - match from base id @@ -446,7 +454,7 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener else { objectPoints.add(point); - objects.add(object); + objects.add(new ColorTileObject(object, color)); log.debug("Marking object: {}", point); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectPoint.java b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectPoint.java index ca8786faa3..6064eb2118 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectPoint.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectPoint.java @@ -25,6 +25,7 @@ package net.runelite.client.plugins.objectindicators; +import java.awt.Color; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -40,4 +41,5 @@ class ObjectPoint private int regionX; private int regionY; private int z; -} \ No newline at end of file + private Color color; +}