object indicators: add support for multiple colors

This commit is contained in:
dekvall
2020-03-02 20:25:23 +01:00
committed by Adam
parent c1d5e3ae16
commit 5f5123a9c3
5 changed files with 96 additions and 24 deletions

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2020, dekvall <https://github.com/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;
}

View File

@@ -44,4 +44,14 @@ public interface ObjectIndicatorsConfig extends Config
{ {
return Color.YELLOW; 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;
}
} }

View File

@@ -24,6 +24,7 @@
*/ */
package net.runelite.client.plugins.objectindicators; package net.runelite.client.plugins.objectindicators;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Shape; import java.awt.Shape;
@@ -60,13 +61,22 @@ class ObjectIndicatorsOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) 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()) if (object.getPlane() != client.getPlane())
{ {
continue; 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; final Shape polygon;
Shape polygon2 = null; Shape polygon2 = null;
@@ -95,12 +105,12 @@ class ObjectIndicatorsOverlay extends Overlay
if (polygon != null) if (polygon != null)
{ {
OverlayUtil.renderPolygon(graphics, polygon, config.markerColor()); OverlayUtil.renderPolygon(graphics, polygon, color);
} }
if (polygon2 != null) if (polygon2 != null)
{ {
OverlayUtil.renderPolygon(graphics, polygon2, config.markerColor()); OverlayUtil.renderPolygon(graphics, polygon2, color);
} }
} }

View File

@@ -29,6 +29,7 @@ import com.google.common.base.Strings;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -91,7 +92,7 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
private final Gson GSON = new Gson(); private final Gson GSON = new Gson();
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private final List<TileObject> objects = new ArrayList<>(); private final List<ColorTileObject> objects = new ArrayList<>();
private final Map<Integer, Set<ObjectPoint>> points = new HashMap<>(); private final Map<Integer, Set<ObjectPoint>> points = new HashMap<>();
private boolean hotKeyPressed; private boolean hotKeyPressed;
@@ -110,6 +111,9 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
@Inject @Inject
private KeyManager keyManager; private KeyManager keyManager;
@Inject
private ObjectIndicatorsConfig config;
@Provides @Provides
ObjectIndicatorsConfig provideConfig(ConfigManager configManager) ObjectIndicatorsConfig provideConfig(ConfigManager configManager)
{ {
@@ -178,54 +182,50 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
WallObject previous = event.getPrevious(); WallObject previous = event.getPrevious();
WallObject wallObject = event.getWallObject(); WallObject wallObject = event.getWallObject();
objects.remove(previous); objects.removeIf(o -> o.getTileObject() == previous);
checkObjectPoints(wallObject); checkObjectPoints(wallObject);
} }
@Subscribe @Subscribe
public void onWallObjectDespawned(WallObjectDespawned event) public void onWallObjectDespawned(WallObjectDespawned event)
{ {
objects.remove(event.getWallObject()); objects.removeIf(o -> o.getTileObject() == event.getWallObject());
} }
@Subscribe @Subscribe
public void onGameObjectSpawned(GameObjectSpawned event) public void onGameObjectSpawned(GameObjectSpawned event)
{ {
final GameObject eventObject = event.getGameObject(); checkObjectPoints(event.getGameObject());
checkObjectPoints(eventObject);
} }
@Subscribe @Subscribe
public void onDecorativeObjectSpawned(DecorativeObjectSpawned event) public void onDecorativeObjectSpawned(DecorativeObjectSpawned event)
{ {
final DecorativeObject eventObject = event.getDecorativeObject(); checkObjectPoints(event.getDecorativeObject());
checkObjectPoints(eventObject);
} }
@Subscribe @Subscribe
public void onGameObjectDespawned(GameObjectDespawned event) public void onGameObjectDespawned(GameObjectDespawned event)
{ {
objects.remove(event.getGameObject()); objects.removeIf(o -> o.getTileObject() == event.getGameObject());
} }
@Subscribe @Subscribe
public void onDecorativeObjectDespawned(DecorativeObjectDespawned event) public void onDecorativeObjectDespawned(DecorativeObjectDespawned event)
{ {
objects.remove(event.getDecorativeObject()); objects.removeIf(o -> o.getTileObject() == event.getDecorativeObject());
} }
@Subscribe @Subscribe
public void onGroundObjectSpawned(GroundObjectSpawned groundObjectSpawned) public void onGroundObjectSpawned(GroundObjectSpawned event)
{ {
final GroundObject groundObject = groundObjectSpawned.getGroundObject(); checkObjectPoints(event.getGroundObject());
checkObjectPoints(groundObject);
} }
@Subscribe @Subscribe
public void onGroundObjectDespawned(GroundObjectDespawned groundObjectDespawned) public void onGroundObjectDespawned(GroundObjectDespawned event)
{ {
GroundObject groundObject = groundObjectDespawned.getGroundObject(); objects.removeIf(o -> o.getTileObject() == event.getGroundObject());
objects.remove(groundObject);
} }
@Subscribe @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 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(); MenuEntry[] menuEntries = client.getMenuEntries();
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1); menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1);
MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry(); 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.setTarget(event.getTarget());
menuEntry.setParam0(event.getActionParam0()); menuEntry.setParam0(event.getActionParam0());
menuEntry.setParam1(event.getActionParam1()); menuEntry.setParam1(event.getActionParam1());
@@ -332,7 +338,7 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
if (objectPoint.getName().equals(getObjectComposition(object.getId()).getName())) if (objectPoint.getName().equals(getObjectComposition(object.getId()).getName()))
{ {
log.debug("Marking object {} due to matching {}", object, objectPoint); log.debug("Marking object {} due to matching {}", object, objectPoint);
objects.add(object); objects.add(new ColorTileObject(object, objectPoint.getColor()));
break; break;
} }
} }
@@ -417,17 +423,19 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
{ {
final WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, object.getLocalLocation()); final WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, object.getLocalLocation());
final int regionId = worldPoint.getRegionID(); final int regionId = worldPoint.getRegionID();
final Color color = config.markerColor();
final ObjectPoint point = new ObjectPoint( final ObjectPoint point = new ObjectPoint(
object.getId(), object.getId(),
name, name,
regionId, regionId,
worldPoint.getRegionX(), worldPoint.getRegionX(),
worldPoint.getRegionY(), worldPoint.getRegionY(),
worldPoint.getPlane()); worldPoint.getPlane(),
color);
Set<ObjectPoint> objectPoints = points.computeIfAbsent(regionId, k -> new HashSet<>()); Set<ObjectPoint> 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: // 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 // 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 else
{ {
objectPoints.add(point); objectPoints.add(point);
objects.add(object); objects.add(new ColorTileObject(object, color));
log.debug("Marking object: {}", point); log.debug("Marking object: {}", point);
} }

View File

@@ -25,6 +25,7 @@
package net.runelite.client.plugins.objectindicators; package net.runelite.client.plugins.objectindicators;
import java.awt.Color;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -40,4 +41,5 @@ class ObjectPoint
private int regionX; private int regionX;
private int regionY; private int regionY;
private int z; private int z;
} private Color color;
}