Revert "Merge pull request #5890 from Nightfirecat/colored-ground-markers"

This reverts commit 72b3e4560d, reversing
changes made to 5a5de3d33f.
This commit is contained in:
Adam
2019-03-06 14:53:59 -05:00
parent 66bce610db
commit 33988a72e1
7 changed files with 56 additions and 208 deletions

View File

@@ -326,36 +326,4 @@ public class WorldPoint
{ {
return ((x >> 6) << 8) | (y >> 6); return ((x >> 6) << 8) | (y >> 6);
} }
/**
* Converts the passed region ID and coordinates to a world coordinate
*/
public static WorldPoint fromRegion(int regionId, int regionX, int regionY, int plane)
{
return new WorldPoint(
((regionId >>> 8) << 6) + regionX,
((regionId & 0xff) << 6) + regionY,
plane);
}
/**
* Gets the X-axis coordinate of the region coordinate
*/
public int getRegionX()
{
return getRegionOffset(x);
}
/**
* Gets the Y-axis coordinate of the region coordinate
*/
public int getRegionY()
{
return getRegionOffset(y);
}
private static int getRegionOffset(final int position)
{
return position & 0x3f;
}
} }

View File

@@ -1,45 +0,0 @@
/*
* 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;
boolean sameTile(final ColorTileMarker other)
{
return worldPoint.equals(other.getWorldPoint());
}
}

View File

@@ -23,6 +23,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.client.plugins.groundmarkers; package net.runelite.client.plugins.groundmarkers;
import java.awt.Color; import java.awt.Color;
@@ -44,14 +45,4 @@ public interface GroundMarkerConfig extends Config
{ {
return Color.YELLOW; 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;
}
} }

View File

@@ -25,11 +25,10 @@
*/ */
package net.runelite.client.plugins.groundmarkers; package net.runelite.client.plugins.groundmarkers;
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.List;
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;
@@ -43,8 +42,6 @@ import net.runelite.client.ui.overlay.OverlayUtil;
public class GroundMarkerOverlay extends Overlay public class GroundMarkerOverlay extends Overlay
{ {
private static final int MAX_DRAW_DISTANCE = 32;
private final Client client; private final Client client;
private final GroundMarkerConfig config; private final GroundMarkerConfig config;
private final GroundMarkerPlugin plugin; private final GroundMarkerPlugin plugin;
@@ -63,26 +60,25 @@ public class GroundMarkerOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
final Collection<ColorTileMarker> points = plugin.getPoints(); List<WorldPoint> points = plugin.getPoints();
for (final ColorTileMarker point : points) for (WorldPoint point : points)
{ {
if (point.getWorldPoint().getPlane() != client.getPlane()) if (point.getPlane() != client.getPlane())
{ {
continue; continue;
} }
final Color tileColor = config.rememberTileColors() ? point.getColor() : config.markerColor(); drawTile(graphics, point);
drawTile(graphics, point.getWorldPoint(), tileColor);
} }
return null; return null;
} }
private void drawTile(Graphics2D graphics, WorldPoint point, Color color) private void drawTile(Graphics2D graphics, WorldPoint point)
{ {
WorldPoint playerLocation = client.getLocalPlayer().getWorldLocation(); WorldPoint playerLocation = client.getLocalPlayer().getWorldLocation();
if (point.distanceTo(playerLocation) >= MAX_DRAW_DISTANCE) if (point.distanceTo(playerLocation) >= 32)
{ {
return; return;
} }
@@ -99,6 +95,6 @@ public class GroundMarkerOverlay extends Overlay
return; return;
} }
OverlayUtil.renderPolygon(graphics, poly, color); OverlayUtil.renderPolygon(graphics, poly, config.markerColor());
} }
} }

View File

@@ -29,12 +29,11 @@ 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.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.AccessLevel; import lombok.AccessLevel;
@@ -70,23 +69,19 @@ 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 WALK_HERE = "Walk here"; private static final String WALK_HERE = "Walk here";
private static final String REGION_PREFIX = "region_";
private static final Gson GSON = new Gson(); private static final Gson gson = new Gson();
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
private boolean hotKeyPressed; private boolean hotKeyPressed;
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private final Set<ColorTileMarker> points = new HashSet<>(); private final List<WorldPoint> points = new ArrayList<>();
@Inject @Inject
private Client client; private Client client;
@Inject
private GroundMarkerConfig config;
@Inject @Inject
private GroundMarkerInputListener inputListener; private GroundMarkerInputListener inputListener;
@@ -102,53 +97,28 @@ public class GroundMarkerPlugin extends Plugin
@Inject @Inject
private KeyManager keyManager; private KeyManager keyManager;
private void saveColorTileMarkers(int regionId, Collection<ColorTileMarker> points)
{
savePoints(regionId, translateFromColorTileMarker(points));
}
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())
{ {
configManager.unsetConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId); configManager.unsetConfiguration(CONFIG_GROUP, "region_" + regionId);
return; return;
} }
String json = GSON.toJson(points); String json = gson.toJson(points);
configManager.setConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId, json); configManager.setConfiguration(CONFIG_GROUP, "region_" + regionId, json);
} }
private Collection<GroundMarkerPoint> getPoints(int regionId) private Collection<GroundMarkerPoint> getPoints(int regionId)
{ {
String json = configManager.getConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId); String json = configManager.getConfiguration(CONFIG_GROUP, "region_" + regionId);
if (Strings.isNullOrEmpty(json)) if (Strings.isNullOrEmpty(json))
{ {
return Collections.emptyList(); return Collections.EMPTY_LIST;
} }
return gson.fromJson(json, new TypeToken<List<GroundMarkerPoint>>()
Collection<GroundMarkerPoint> configPoints = GSON.fromJson(json, new GroundMarkerListTypeToken().getType());
if (configPoints.stream().anyMatch(point -> point.getColor() == null))
{ {
log.debug("Adding color to old ground marker(s) of region " + regionId); }.getType());
configPoints = configPoints.stream()
.map(point ->
{
if (point.getColor() != null)
{
return point;
}
return new GroundMarkerPoint(point.getRegionId(), point.getRegionX(), point.getRegionY(), point.getZ(), config.markerColor());
})
.collect(Collectors.toSet());
savePoints(regionId, configPoints);
}
return configPoints;
}
private static class GroundMarkerListTypeToken extends TypeToken<List<GroundMarkerPoint>>
{
} }
@Provides @Provides
@@ -162,68 +132,46 @@ public class GroundMarkerPlugin extends Plugin
points.clear(); points.clear();
int[] regions = client.getMapRegions(); int[] regions = client.getMapRegions();
if (regions == null)
{
return;
}
for (int regionId : regions) for (int regionId : regions)
{ {
// load points for region // load points for region
log.debug("Loading points for region {}", regionId); log.debug("Loading points for region {}", regionId);
final Collection<GroundMarkerPoint> configPoints = getPoints(regionId); Collection<GroundMarkerPoint> regionPoints = getPoints(regionId);
final Collection<ColorTileMarker> colorTileMarkers = translateToColorTileMarker(configPoints); Collection<WorldPoint> worldPoints = translateToWorld(regionPoints);
points.addAll(colorTileMarkers); points.addAll(worldPoints);
} }
} }
/** /**
* Translate a collection of ground marker points to color tile markers, accounting for instances * Translate a collection of ground marker points to world points, accounting for instances
* *
* @param points {@link GroundMarkerPoint}s to be converted to {@link ColorTileMarker}s * @param points
* @return A collection of color tile markers, converted from the passed ground marker points, accounting for local * @return
* instance points. See {@link WorldPoint#toLocalInstance(Client, WorldPoint)}
*/ */
private Collection<ColorTileMarker> translateToColorTileMarker(Collection<GroundMarkerPoint> points) private Collection<WorldPoint> translateToWorld(Collection<GroundMarkerPoint> points)
{ {
if (points == null || points.isEmpty()) if (points.isEmpty())
{ {
return Collections.emptyList(); return Collections.EMPTY_LIST;
}
return points.stream()
.map(point -> new ColorTileMarker(
WorldPoint.fromRegion(point.getRegionId(), point.getRegionX(), point.getRegionY(), point.getZ()),
point.getColor()))
.flatMap(colorTile ->
{
final Collection<WorldPoint> localWorldPoints = WorldPoint.toLocalInstance(client, colorTile.getWorldPoint());
return localWorldPoints.stream().map(wp -> new ColorTileMarker(wp, colorTile.getColor()));
})
.collect(Collectors.toSet());
}
/**
* Translate a collection of color tile markers to a set of ground marker points
*
* @param points {@link ColorTileMarker}s to be converted to {@link GroundMarkerPoint}s
* @return A set of ground marker points, converted from the passed color tile markers
*/
private static Set<GroundMarkerPoint> translateFromColorTileMarker(Collection<ColorTileMarker> points)
{
if (points == null || points.isEmpty())
{
return Collections.emptySet();
} }
return points.stream() return points.stream()
.map(point -> .map(point ->
{ {
final WorldPoint worldPoint = point.getWorldPoint(); int regionId = point.getRegionId();
return new GroundMarkerPoint(worldPoint.getRegionID(), worldPoint.getRegionX(), worldPoint.getRegionY(), worldPoint.getPlane(), point.getColor()); int regionX = point.getRegionX();
int regionY = point.getRegionY();
int z = point.getZ();
// world point of the tile marker
return new WorldPoint(
((regionId >>> 8) << 6) + regionX,
((regionId & 0xff) << 6) + regionY,
z
);
}) })
.collect(Collectors.toSet()); .flatMap(wp -> WorldPoint.toLocalInstance(client, wp).stream())
.collect(Collectors.toList());
} }
@Subscribe @Subscribe
@@ -286,7 +234,6 @@ public class GroundMarkerPlugin extends Plugin
{ {
overlayManager.add(overlay); overlayManager.add(overlay);
keyManager.registerKeyListener(inputListener); keyManager.registerKeyListener(inputListener);
loadPoints();
} }
@Override @Override
@@ -294,38 +241,33 @@ public class GroundMarkerPlugin extends Plugin
{ {
overlayManager.remove(overlay); overlayManager.remove(overlay);
keyManager.unregisterKeyListener(inputListener); keyManager.unregisterKeyListener(inputListener);
points.clear();
} }
private void markTile(LocalPoint localPoint)
protected void markTile(LocalPoint localPoint)
{ {
if (localPoint == null) if (localPoint == null)
{ {
return; return;
} }
final WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, localPoint); WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, localPoint);
final ColorTileMarker point = new ColorTileMarker(worldPoint, config.markerColor());
int regionId = worldPoint.getRegionID();
GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getX() & 0x3f, worldPoint.getY() & 0x3f, client.getPlane());
log.debug("Updating point: {} - {}", point, worldPoint); log.debug("Updating point: {} - {}", point, worldPoint);
List<GroundMarkerPoint> points = new ArrayList<>(getPoints(regionId));
if (points.contains(point)) if (points.contains(point))
{ {
points.remove(point); points.remove(point);
} }
else else
{ {
// Remove any points on the same tile but are of a different color points.add(point);
points.removeIf(p -> p.sameTile(point));
// Add point back only if we are remembering tile colors, otherwise simply remove it
if (config.rememberTileColors())
{
points.add(point);
}
} }
final int regionId = worldPoint.getRegionID(); savePoints(regionId, points);
saveColorTileMarkers(regionId, points);
loadPoints(); loadPoints();
} }

View File

@@ -23,20 +23,16 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.client.plugins.groundmarkers; package net.runelite.client.plugins.groundmarkers;
import java.awt.Color;
import lombok.Value; import lombok.Value;
/**
* Used for serialization of ground marker points.
*/
@Value @Value
class GroundMarkerPoint public 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;
private Color color;
} }