From 7a740fa91f030a23a16ea92bbc047c7c54dcf8d3 Mon Sep 17 00:00:00 2001 From: Enza-Denino <49626207+Enza-Denino@users.noreply.github.com> Date: Tue, 25 Jun 2019 00:35:29 -0500 Subject: [PATCH] add wilderness level lines to multiindicators plugin (also remove collision filter toggle) (#739) * testing * add wilderness level lines to multiindicators plugin * remove test file * fix checkstyle violation --- .../plugins/multiindicators/MapLocations.java | 86 +++++++++++++------ .../MultiIndicatorsConfig.java | 23 +++-- .../MultiIndicatorsMinimapOverlay.java | 6 ++ .../MultiIndicatorsOverlay.java | 6 ++ .../MultiIndicatorsPlugin.java | 76 ++++++++++++++-- .../multiindicators/ZoneVisibility.java | 2 +- 6 files changed, 161 insertions(+), 38 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MapLocations.java b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MapLocations.java index de1525e6d8..044e9bdb36 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MapLocations.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MapLocations.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Woox + * Copyright (c) 2019, Enza-Denino * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,11 +35,12 @@ import net.runelite.api.Constants; public class MapLocations { - private static final List[] MULTICOMBAT = new List[Constants.MAX_Z]; - private static final List[] NOT_MULTICOMBAT = new List[Constants.MAX_Z]; - private static final List[] ROUGH_WILDERNESS = new List[Constants.MAX_Z]; - private static final List[] DEADMAN_SAFE_ZONES = new List[Constants.MAX_Z]; - private static final List[] PVP_WORLD_SAFE_ZONES = new List[Constants.MAX_Z]; + private static final List[] MULTICOMBAT = new List[Constants.MAX_Z]; + private static final List[] NOT_MULTICOMBAT = new List[Constants.MAX_Z]; + private static final List[] ROUGH_WILDERNESS = new List[Constants.MAX_Z]; + private static final List[] WILDERNESS_LEVEL_LINES = new List[Constants.MAX_Z]; + private static final List[] DEADMAN_SAFE_ZONES = new List[Constants.MAX_Z]; + private static final List[] PVP_WORLD_SAFE_ZONES = new List[Constants.MAX_Z]; private static Area getArea(List shapes) { @@ -87,6 +89,16 @@ public class MapLocations return getArea(ROUGH_WILDERNESS[plane], view); } + public static Area getWildernessLevelLines(int plane) + { + return getArea(WILDERNESS_LEVEL_LINES[plane]); + } + + public static Area getWildernessLevelLines(Rectangle view, int plane) + { + return getArea(WILDERNESS_LEVEL_LINES[plane], view); + } + public static Area getDeadmanSafeZones(int plane) { return getArea(DEADMAN_SAFE_ZONES[plane]); @@ -107,33 +119,28 @@ public class MapLocations return getArea(PVP_WORLD_SAFE_ZONES[plane], view); } + private static void initializeWithEmptyLists(List[] array) + { + for (int i = 0; i < array.length; i++) + { + array[i] = new ArrayList<>(); + } + } + static { - for (int i = 0; i < MULTICOMBAT.length; i++) - { - MULTICOMBAT[i] = new ArrayList<>(); - } - for (int i = 0; i < NOT_MULTICOMBAT.length; i++) - { - NOT_MULTICOMBAT[i] = new ArrayList<>(); - } - for (int i = 0; i < ROUGH_WILDERNESS.length; i++) - { - ROUGH_WILDERNESS[i] = new ArrayList<>(); - } - for (int i = 0; i < DEADMAN_SAFE_ZONES.length; i++) - { - DEADMAN_SAFE_ZONES[i] = new ArrayList<>(); - } - for (int i = 0; i < PVP_WORLD_SAFE_ZONES.length; i++) - { - PVP_WORLD_SAFE_ZONES[i] = new ArrayList<>(); - } + initializeWithEmptyLists(MULTICOMBAT); + initializeWithEmptyLists(NOT_MULTICOMBAT); + initializeWithEmptyLists(ROUGH_WILDERNESS); + initializeWithEmptyLists(WILDERNESS_LEVEL_LINES); + initializeWithEmptyLists(DEADMAN_SAFE_ZONES); + initializeWithEmptyLists(PVP_WORLD_SAFE_ZONES); defineMulticombatAreas(); defineDeadmanSafeZones(); definePvpSafeZones(); defineWilderness(); + defineWildernessLevelLines(); } private static void defineMulticombatAreas() @@ -3441,6 +3448,33 @@ public class MapLocations 3264, 9918); } + private static void defineWildernessLevelLines() + { + int wildyLeftX = 2944; + int wildyRightX = 3392; + int wildyBottomY = 3525; + int wildyTopY = 3971; + + // define wilderness level lines at ground level + int accumulatedY = 0; + for (int level = 1; level <= 56; level++) + { + int levelTiles = level == 1 ? 3 : 8; + // only draw every 2 levels, otherwise lines on two adjacent levels will collide + // and it will not show up + if (level % 2 != 0) + { + addPolygonTo(WILDERNESS_LEVEL_LINES, + wildyLeftX, wildyBottomY + accumulatedY, + wildyRightX, wildyBottomY + accumulatedY, + wildyRightX, wildyBottomY + accumulatedY + levelTiles, + wildyLeftX, wildyBottomY + accumulatedY + levelTiles); + } + accumulatedY += levelTiles; + } + } + + private static void addPolygonTo(List[] shapes, int... coords) { Polygon poly = new Polygon(); @@ -3476,4 +3510,4 @@ public class MapLocations shapes[i].add(poly); } } -} \ No newline at end of file +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsConfig.java index 27aed88be3..da14992e01 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsConfig.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Woox + * Copyright (c) 2019, Enza-Denino * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -66,14 +67,14 @@ public interface MultiIndicatorsConfig extends Config } @ConfigItem( - keyName = "collisionDetection", - name = "Collision detection", - description = "Only show lines where they can be walked through", + keyName = "wildernessLevelLines", + name = "Wilderness level lines", + description = "Show wilderness level lines", position = 4 ) - default boolean collisionDetection() + default boolean showWildernessLevelLines() { - return false; + return true; } @ConfigItem( @@ -108,4 +109,16 @@ public interface MultiIndicatorsConfig extends Config { return Color.GREEN; } + + @ConfigItem( + keyName = "wildernessLevelLinesColor", + name = "Wilderness level lines color", + description = "Choose color to use for marking wilderness level lines", + position = 8 + ) + default Color wildernessLevelLinesColor() + { + return Color.WHITE; + } + } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsMinimapOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsMinimapOverlay.java index 8fd85bd934..b0c1187745 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsMinimapOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsMinimapOverlay.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Woox + * Copyright (c) 2019, Enza-Denino * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -102,6 +103,7 @@ public class MultiIndicatorsMinimapOverlay extends Overlay GeneralPath multicombatPath = plugin.getMulticombatPathToDisplay()[client.getPlane()]; GeneralPath pvpPath = plugin.getPvpPathToDisplay()[client.getPlane()]; + GeneralPath wildernessLevelLinesPath = plugin.getWildernessLevelLinesPathToDisplay()[client.getPlane()]; if (config.multicombatZoneVisibility() != ZoneVisibility.HIDE && multicombatPath != null) { @@ -111,6 +113,10 @@ public class MultiIndicatorsMinimapOverlay extends Overlay { renderPath(graphics, pvpPath, getTransparentColorVersion(config.safeZoneColor())); } + if (config.showWildernessLevelLines() && wildernessLevelLinesPath != null) + { + renderPath(graphics, wildernessLevelLinesPath, getTransparentColorVersion(config.wildernessLevelLinesColor())); + } return null; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsOverlay.java index 73985fd08e..d9268121f0 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsOverlay.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Woox + * Copyright (c) 2019, Enza-Denino * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -98,6 +99,7 @@ public class MultiIndicatorsOverlay extends Overlay { GeneralPath multicombatPath = plugin.getMulticombatPathToDisplay()[client.getPlane()]; GeneralPath pvpPath = plugin.getPvpPathToDisplay()[client.getPlane()]; + GeneralPath wildernessLevelLinesPath = plugin.getWildernessLevelLinesPathToDisplay()[client.getPlane()]; if (config.multicombatZoneVisibility() != ZoneVisibility.HIDE && multicombatPath != null) { @@ -107,6 +109,10 @@ public class MultiIndicatorsOverlay extends Overlay { renderPath(graphics, pvpPath, getTransparentColorVersion(config.safeZoneColor())); } + if (config.showWildernessLevelLines() && wildernessLevelLinesPath != null) + { + renderPath(graphics, wildernessLevelLinesPath, getTransparentColorVersion(config.wildernessLevelLinesColor())); + } return null; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsPlugin.java index 8568d26fb1..c20fa25810 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/MultiIndicatorsPlugin.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Woox + * Copyright (c) 2019, Enza-Denino * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,6 +28,7 @@ package net.runelite.client.plugins.multiindicators; import com.google.inject.Provides; import java.awt.Rectangle; import java.awt.geom.GeneralPath; +import java.time.temporal.ChronoUnit; import java.util.Arrays; import javax.inject.Inject; import lombok.Getter; @@ -50,6 +52,7 @@ import net.runelite.client.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginType; +import net.runelite.client.task.Schedule; import net.runelite.client.ui.overlay.OverlayManager; @PluginDescriptor( @@ -86,6 +89,9 @@ public class MultiIndicatorsPlugin extends Plugin @Getter private GeneralPath[] pvpPathToDisplay; + @Getter + private GeneralPath[] wildernessLevelLinesPathToDisplay; + @Getter private boolean inPvp; @@ -106,8 +112,7 @@ public class MultiIndicatorsPlugin extends Plugin overlayManager.add(overlay); overlayManager.add(minimapOverlay); - multicombatPathToDisplay = new GeneralPath[Constants.MAX_Z]; - pvpPathToDisplay = new GeneralPath[Constants.MAX_Z]; + initializePaths(); clientThread.invokeLater(() -> { @@ -124,8 +129,37 @@ public class MultiIndicatorsPlugin extends Plugin overlayManager.remove(overlay); overlayManager.remove(minimapOverlay); + uninitializePaths(); + } + + private void initializePaths() + { + multicombatPathToDisplay = new GeneralPath[Constants.MAX_Z]; + pvpPathToDisplay = new GeneralPath[Constants.MAX_Z]; + wildernessLevelLinesPathToDisplay = new GeneralPath[Constants.MAX_Z]; + } + + private void uninitializePaths() + { multicombatPathToDisplay = null; pvpPathToDisplay = null; + wildernessLevelLinesPathToDisplay = null; + } + + // sometimes the lines get offset (seems to happen when there is a delay + // due to map reloading when walking/running "Loading - please wait") + // resetting the lines generation logic fixes this + @Schedule( + period = 1800, + unit = ChronoUnit.MILLIS + ) + public void update() + { + if (client.getGameState() == GameState.LOGGED_IN) + { + findLinesInScene(); + } + } private void transformWorldToLocal(float[] coords) @@ -134,7 +168,6 @@ public class MultiIndicatorsPlugin extends Plugin coords[0] = lp.getX() - Perspective.LOCAL_TILE_SIZE / 2; coords[1] = lp.getY() - Perspective.LOCAL_TILE_SIZE / 2; } - private boolean isOpenableAt(WorldPoint wp) { int sceneX = wp.getX() - client.getBaseX(); @@ -153,6 +186,7 @@ public class MultiIndicatorsPlugin extends Plugin } ObjectDefinition objectComposition = client.getObjectDefinition(wallObject.getId()); + if (objectComposition == null) { return false; @@ -240,7 +274,7 @@ public class MultiIndicatorsPlugin extends Plugin lines = Geometry.clipPath(lines, MapLocations.getRoughWilderness(i)); } lines = Geometry.splitIntoSegments(lines, 1); - if (config.collisionDetection()) + if (useCollisionLogic()) { lines = Geometry.filterPath(lines, this::collisionFilter); } @@ -267,7 +301,7 @@ public class MultiIndicatorsPlugin extends Plugin { safeZonePath = Geometry.clipPath(safeZonePath, sceneRect); safeZonePath = Geometry.splitIntoSegments(safeZonePath, 1); - if (config.collisionDetection()) + if (useCollisionLogic()) { safeZonePath = Geometry.filterPath(safeZonePath, this::collisionFilter); } @@ -275,6 +309,35 @@ public class MultiIndicatorsPlugin extends Plugin } pvpPathToDisplay[i] = safeZonePath; } + + // Generate wilderness level lines + for (int i = 0; i < wildernessLevelLinesPathToDisplay.length; i++) + { + currentPlane = i; + + GeneralPath wildernessLevelLinesPath = null; + if (config.showWildernessLevelLines()) + { + wildernessLevelLinesPath = new GeneralPath(MapLocations.getWildernessLevelLines(sceneRect, i)); + } + if (wildernessLevelLinesPath != null) + { + wildernessLevelLinesPath = Geometry.clipPath(wildernessLevelLinesPath, sceneRect); + wildernessLevelLinesPath = Geometry.splitIntoSegments(wildernessLevelLinesPath, 1); + if (useCollisionLogic()) + { + wildernessLevelLinesPath = Geometry.filterPath(wildernessLevelLinesPath, this::collisionFilter); + } + wildernessLevelLinesPath = Geometry.transformPath(wildernessLevelLinesPath, this::transformWorldToLocal); + } + wildernessLevelLinesPathToDisplay[i] = wildernessLevelLinesPath; + } + } + + private boolean useCollisionLogic() + { + // currently prevents overlay lines from showing up if this is ever enabled right now + return false; } @Subscribe @@ -283,7 +346,8 @@ public class MultiIndicatorsPlugin extends Plugin if (event.getKey().equals("collisionDetection") || event.getKey().equals("multicombatZoneVisibility") || event.getKey().equals("deadmanSafeZones") || - event.getKey().equals("pvpSafeZones")) + event.getKey().equals("pvpSafeZones") || + event.getKey().equals("wildernessLevelLines")) { findLinesInScene(); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/ZoneVisibility.java b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/ZoneVisibility.java index b024a93846..c3e9a8fcf4 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/ZoneVisibility.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/multiindicators/ZoneVisibility.java @@ -40,4 +40,4 @@ public enum ZoneVisibility { return visibility; } -} \ No newline at end of file +}