object indicators: add support for multiple colors
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TileObject> objects = new ArrayList<>();
|
||||
private final List<ColorTileObject> objects = new ArrayList<>();
|
||||
private final Map<Integer, Set<ObjectPoint>> 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<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:
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
private Color color;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user