ground markers: Allow different colored markers
This adds a color indicator per marker, saved to config, allowing multiple markers to be different colors. In addition, a configuration option is added to switch between per-tile color display or current configured color display. (that is, new or existing behavior) This change will set a color in config for old markers with null colors when those markers are loaded. Fixes runelite/runelite#3395
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Jordan Atwood <nightfirecat@protonmail.com>
|
||||
* 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.groundmarkers;
|
||||
|
||||
import java.awt.Color;
|
||||
import lombok.Value;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
|
||||
/**
|
||||
* Used to denote marked tiles and their colors.
|
||||
* Note: This is not used for serialization of ground markers; see {@link GroundMarkerPoint}
|
||||
*/
|
||||
@Value
|
||||
class ColorTileMarker
|
||||
{
|
||||
private WorldPoint worldPoint;
|
||||
private Color color;
|
||||
}
|
||||
@@ -44,4 +44,14 @@ public interface GroundMarkerConfig extends Config
|
||||
{
|
||||
return Color.YELLOW;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "rememberTileColors",
|
||||
name = "Remember color per tile",
|
||||
description = "Color tiles using the color from time of placement"
|
||||
)
|
||||
default boolean rememberTileColors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.groundmarkers;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Perspective;
|
||||
@@ -62,21 +63,29 @@ public class GroundMarkerOverlay extends Overlay
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
List<WorldPoint> points = plugin.getPoints();
|
||||
for (WorldPoint point : points)
|
||||
final Collection<ColorTileMarker> points = plugin.getPoints();
|
||||
for (final ColorTileMarker point : points)
|
||||
{
|
||||
if (point.getPlane() != client.getPlane())
|
||||
WorldPoint worldPoint = point.getWorldPoint();
|
||||
if (worldPoint.getPlane() != client.getPlane())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
drawTile(graphics, point);
|
||||
Color tileColor = point.getColor();
|
||||
if (tileColor == null || !config.rememberTileColors())
|
||||
{
|
||||
// If this is an old tile which has no color, or rememberTileColors is off, use marker color
|
||||
tileColor = config.markerColor();
|
||||
}
|
||||
|
||||
drawTile(graphics, worldPoint, tileColor);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void drawTile(Graphics2D graphics, WorldPoint point)
|
||||
private void drawTile(Graphics2D graphics, WorldPoint point, Color color)
|
||||
{
|
||||
WorldPoint playerLocation = client.getLocalPlayer().getWorldLocation();
|
||||
|
||||
@@ -97,6 +106,6 @@ public class GroundMarkerOverlay extends Overlay
|
||||
return;
|
||||
}
|
||||
|
||||
OverlayUtil.renderPolygon(graphics, poly, config.markerColor());
|
||||
OverlayUtil.renderPolygon(graphics, poly, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,11 +78,14 @@ public class GroundMarkerPlugin extends Plugin
|
||||
private boolean hotKeyPressed;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final List<WorldPoint> points = new ArrayList<>();
|
||||
private final List<ColorTileMarker> points = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private GroundMarkerConfig config;
|
||||
|
||||
@Inject
|
||||
private GroundMarkerInputListener inputListener;
|
||||
|
||||
@@ -117,9 +120,10 @@ public class GroundMarkerPlugin extends Plugin
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return GSON.fromJson(json, new TypeToken<List<GroundMarkerPoint>>()
|
||||
{
|
||||
}.getType());
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
return GSON.fromJson(json, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -144,18 +148,19 @@ public class GroundMarkerPlugin extends Plugin
|
||||
// load points for region
|
||||
log.debug("Loading points for region {}", regionId);
|
||||
Collection<GroundMarkerPoint> regionPoints = getPoints(regionId);
|
||||
Collection<WorldPoint> worldPoints = translateToWorld(regionPoints);
|
||||
points.addAll(worldPoints);
|
||||
Collection<ColorTileMarker> colorTileMarkers = translateToColorTileMarker(regionPoints);
|
||||
points.addAll(colorTileMarkers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a collection of ground marker points to world points, accounting for instances
|
||||
* Translate a collection of ground marker points to color tile markers, accounting for instances
|
||||
*
|
||||
* @param points
|
||||
* @return
|
||||
* @param points {@link GroundMarkerPoint}s to be converted to {@link ColorTileMarker}s
|
||||
* @return A collection of color tile markers, converted from the passed ground marker points, accounting for local
|
||||
* instance points. See {@link WorldPoint#toLocalInstance(Client, WorldPoint)}
|
||||
*/
|
||||
private Collection<WorldPoint> translateToWorld(Collection<GroundMarkerPoint> points)
|
||||
private Collection<ColorTileMarker> translateToColorTileMarker(Collection<GroundMarkerPoint> points)
|
||||
{
|
||||
if (points.isEmpty())
|
||||
{
|
||||
@@ -163,16 +168,14 @@ public class GroundMarkerPlugin extends Plugin
|
||||
}
|
||||
|
||||
return points.stream()
|
||||
.map(point ->
|
||||
.map(point -> new ColorTileMarker(
|
||||
WorldPoint.fromRegion(point.getRegionId(), point.getRegionX(), point.getRegionY(), point.getZ()),
|
||||
point.getColor()))
|
||||
.flatMap(colorTile ->
|
||||
{
|
||||
int regionId = point.getRegionId();
|
||||
int regionX = point.getRegionX();
|
||||
int regionY = point.getRegionY();
|
||||
int z = point.getZ();
|
||||
|
||||
return WorldPoint.fromRegion(regionId, regionX, regionY, z);
|
||||
final Collection<WorldPoint> localWorldPoints = WorldPoint.toLocalInstance(client, colorTile.getWorldPoint());
|
||||
return localWorldPoints.stream().map(wp -> new ColorTileMarker(wp, colorTile.getColor()));
|
||||
})
|
||||
.flatMap(wp -> WorldPoint.toLocalInstance(client, wp).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -257,7 +260,7 @@ public class GroundMarkerPlugin extends Plugin
|
||||
WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, localPoint);
|
||||
|
||||
int regionId = worldPoint.getRegionID();
|
||||
GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane());
|
||||
GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane(), config.markerColor());
|
||||
log.debug("Updating point: {} - {}", point, worldPoint);
|
||||
|
||||
List<GroundMarkerPoint> groundMarkerPoints = new ArrayList<>(getPoints(regionId));
|
||||
|
||||
@@ -25,13 +25,20 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.groundmarkers;
|
||||
|
||||
import java.awt.Color;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
||||
/**
|
||||
* Used for serialization of ground marker points.
|
||||
*/
|
||||
@Value
|
||||
@EqualsAndHashCode(exclude = { "color" })
|
||||
class GroundMarkerPoint
|
||||
{
|
||||
private int regionId;
|
||||
private int regionX;
|
||||
private int regionY;
|
||||
private int z;
|
||||
private Color color;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user