From 36114c4fd6e3e8ce79dfff6d7b1d42c19c1745d3 Mon Sep 17 00:00:00 2001 From: Morgan Lewis Date: Thu, 3 May 2018 20:54:45 -0400 Subject: [PATCH] runelite-client: add world map overlay renderer --- .../net/runelite/api/widgets/WidgetID.java | 4 +- .../net/runelite/api/widgets/WidgetInfo.java | 2 + .../net/runelite/client/callback/Hooks.java | 10 +- .../client/ui/overlay/OverlayRenderer.java | 6 +- .../ui/overlay/worldmap/WorldMapOverlay.java | 244 ++++++++++++++++++ .../WorldMapOverlayMouseListener.java | 156 +++++++++++ .../ui/overlay/worldmap/WorldMapPoint.java | 80 ++++++ .../worldmap/WorldMapPointManager.java | 48 ++++ 8 files changed, 543 insertions(+), 7 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlayMouseListener.java create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPoint.java create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPointManager.java diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java index cfb57017a0..0739c27c55 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java @@ -77,7 +77,7 @@ public class WidgetID public static final int PUZZLE_BOX_GROUP_ID = 306; public static final int NIGHTMARE_ZONE_GROUP_ID = 202; public static final int BLAST_FURNACE_GROUP_ID = 474; - public static final int WORLD_MAP = 595; + public static final int WORLD_MAP_GROUP_ID = 595; public static final int PYRAMID_PLUNDER_GROUP_ID = 428; public static final int RAIDS_REWARD_GROUP_ID = 539; public static final int EXPERIENCE_TRACKER_GROUP_ID = 122; @@ -88,6 +88,8 @@ public class WidgetID static class WorldMap { static final int OPTION = 36; + static final int TOOLTIP = 35; + static final int MAPVIEW = 3; } static class SlayerRewards diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java index 778830d10d..12708926a1 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java @@ -45,6 +45,8 @@ public enum WidgetInfo RAIDING_PARTY(WidgetID.RAIDING_PARTY_GROUP_ID, 0), WORLD_MAP(WidgetID.WORLD_MAP_MENU_GROUP_ID, WidgetID.WorldMap.OPTION), + WORLD_MAP_TOOLTIP(WidgetID.WORLD_MAP_GROUP_ID, WidgetID.WorldMap.TOOLTIP), + WORLD_MAP_VIEW(WidgetID.WORLD_MAP_GROUP_ID, WidgetID.WorldMap.MAPVIEW), CLUE_SCROLL_TEXT(WidgetID.CLUE_SCROLL_GROUP_ID, WidgetID.Cluescroll.CLUE_TEXT), diff --git a/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java index 18952cde20..cef91c0cd6 100644 --- a/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java +++ b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java @@ -28,14 +28,14 @@ import com.google.common.eventbus.EventBus; import com.google.inject.Injector; import java.awt.Color; import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.image.BufferedImage; -import java.awt.RenderingHints; import net.runelite.api.Actor; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; @@ -63,7 +63,7 @@ import net.runelite.api.events.PostItemComposition; import net.runelite.api.events.ProjectileMoved; import net.runelite.api.events.SetMessage; import net.runelite.api.widgets.Widget; -import static net.runelite.api.widgets.WidgetID.WORLD_MAP; +import static net.runelite.api.widgets.WidgetInfo.WORLD_MAP; import net.runelite.client.Notifier; import net.runelite.client.RuneLite; import net.runelite.client.chat.ChatMessageManager; @@ -158,7 +158,7 @@ public class Hooks */ private static void checkWorldMap() { - Widget widget = client.getWidget(WORLD_MAP, 0); + Widget widget = client.getWidget(WORLD_MAP); if (widget != null) { return; diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java index e976b2c7c9..c9ece17ff5 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java @@ -64,6 +64,7 @@ import net.runelite.client.plugins.PluginManager; import net.runelite.client.ui.FontManager; import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay; import net.runelite.client.ui.overlay.tooltip.TooltipOverlay; +import net.runelite.client.ui.overlay.worldmap.WorldMapOverlay; @Singleton @Slf4j @@ -91,6 +92,7 @@ public class OverlayRenderer extends MouseListener implements KeyListener private final ConfigManager configManager; private final RuneLiteConfig runeLiteConfig; private final TooltipOverlay tooltipOverlay; + private final WorldMapOverlay worldMapOverlay; private final List allOverlays = new CopyOnWriteArrayList<>(); private final String runeliteGroupName = RuneLiteConfig.class.getAnnotation(ConfigGroup.class).keyName(); @@ -117,6 +119,7 @@ public class OverlayRenderer extends MouseListener implements KeyListener final KeyManager keyManager, final TooltipOverlay tooltipOverlay, final InfoBoxOverlay infoBoxOverlay, + final WorldMapOverlay worldMapOverlay, final ConfigManager configManager, final RuneLiteConfig runeLiteConfig) { @@ -124,6 +127,7 @@ public class OverlayRenderer extends MouseListener implements KeyListener this.pluginManager = pluginManager; this.tooltipOverlay = tooltipOverlay; this.infoBoxOverlay = infoBoxOverlay; + this.worldMapOverlay = worldMapOverlay; this.configManager = configManager; this.runeLiteConfig = runeLiteConfig; keyManager.registerKeyListener(this); @@ -169,7 +173,7 @@ public class OverlayRenderer extends MouseListener implements KeyListener .stream() .filter(pluginManager::isPluginEnabled) .flatMap(plugin -> plugin.getOverlays().stream()), - Stream.of(infoBoxOverlay, tooltipOverlay)) + Stream.of(infoBoxOverlay, tooltipOverlay, worldMapOverlay)) .filter(Objects::nonNull) .collect(Collectors.toList()); diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlay.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlay.java new file mode 100644 index 0000000000..fb6b120143 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlay.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2018, Morgan Lewis + * 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.ui.overlay.worldmap; + +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.util.List; +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.Client; +import net.runelite.api.Point; +import net.runelite.api.RenderOverview; +import net.runelite.api.coords.WorldPoint; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; +import net.runelite.client.input.MouseManager; +import net.runelite.client.ui.FontManager; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayLayer; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.OverlayPriority; + +@Singleton +@Slf4j +public class WorldMapOverlay extends Overlay +{ + private static final Color TOOLTIP_BACKGROUND = new Color(255, 255, 160); + private static final int TOOLTIP_OFFSET_HEIGHT = 25; + private static final int TOOLTIP_OFFSET_WIDTH = 5; + private static final int TOOLTIP_PADDING_HEIGHT = 1; + private static final int TOOLTIP_PADDING_WIDTH = 2; + + private final WorldMapPointManager worldMapPointManager; + private final Provider clientProvider; + + @Inject + private WorldMapOverlay(Provider clientProvider, WorldMapPointManager worldMapPointManager, + MouseManager mouseManager, WorldMapOverlayMouseListener worldMapOverlayMouseListener) + { + this.clientProvider = clientProvider; + this.worldMapPointManager = worldMapPointManager; + setPosition(OverlayPosition.DYNAMIC); + setPriority(OverlayPriority.HIGH); + setLayer(OverlayLayer.ALWAYS_ON_TOP); + mouseManager.registerMouseListener(worldMapOverlayMouseListener); + } + + @Override + public Dimension render(Graphics2D graphics) + { + final List points = worldMapPointManager.getWorldMapPoints(); + + if (points.isEmpty()) + { + return null; + } + + final Client client = clientProvider.get(); + + Widget widget = client.getWidget(WidgetInfo.WORLD_MAP_VIEW); + if (widget == null) + { + return null; + } + + final Rectangle worldMapRectangle = widget.getBounds(); + WorldMapPoint tooltipPoint = null; + + for (WorldMapPoint worldPoint : points) + { + BufferedImage image = worldPoint.getImage(); + WorldPoint point = worldPoint.getWorldPoint(); + + if (image != null && point != null) + { + Point drawPoint = mapWorldPointToGraphicsPoint(point); + + if (worldPoint.isSnapToEdge()) + { + Canvas canvas = client.getCanvas(); + graphics.setClip(0, 0, canvas.getWidth(), canvas.getHeight()); + + if (worldMapRectangle.contains(drawPoint.getX(), drawPoint.getY())) + { + if (worldPoint.isCurrentlyEdgeSnapped()) + { + worldPoint.setCurrentlyEdgeSnapped(false); + worldPoint.onEdgeUnsnap(); + } + } + else + { + drawPoint = clipToRectangle(drawPoint, worldMapRectangle); + if (!worldPoint.isCurrentlyEdgeSnapped()) + { + worldPoint.setCurrentlyEdgeSnapped(true); + worldPoint.onEdgeSnap(); + } + } + } + else + { + graphics.setClip(worldMapRectangle); + } + + int drawX = drawPoint.getX(); + int drawY = drawPoint.getY(); + + if (worldPoint.getImagePoint() == null) + { + drawX -= image.getWidth() / 2; + drawY -= image.getHeight() / 2; + } + else + { + drawX -= worldPoint.getImagePoint().getX(); + drawY -= worldPoint.getImagePoint().getY(); + } + + graphics.drawImage(image, drawX, drawY, null); + Rectangle clickbox = new Rectangle(drawX, drawY, image.getWidth(), image.getHeight()); + worldPoint.setClickbox(clickbox); + + if (worldPoint.isTooltipVisible()) + { + tooltipPoint = worldPoint; + } + } + } + + if (tooltipPoint != null) + { + drawTooltip(graphics, tooltipPoint); + } + + return null; + } + + private Point mapWorldPointToGraphicsPoint(WorldPoint worldPoint) + { + RenderOverview ro = clientProvider.get().getRenderOverview(); + Float pixelsPerTile = ro.getWorldMapZoom(); + + Point worldMapPosition = ro.getWorldMapPosition(); + int xWorldDiff = worldPoint.getX() - worldMapPosition.getX(); + int yWorldDiff = worldPoint.getY() - worldMapPosition.getY(); + yWorldDiff = -yWorldDiff; + + Widget map = clientProvider.get().getWidget(WidgetInfo.WORLD_MAP_VIEW); + if (map != null) + { + Rectangle worldMapRect = map.getBounds(); + int xGraphDiff = (int) (xWorldDiff * pixelsPerTile + worldMapRect.getWidth() / 2 + worldMapRect.getX()); + int yGraphDiff = (int) (yWorldDiff * pixelsPerTile + worldMapRect.getHeight() / 2 + worldMapRect.getY()); + + return new Point(xGraphDiff, yGraphDiff); + } + return new Point(0, 0); + } + + private void drawTooltip(Graphics2D graphics, WorldMapPoint worldPoint) + { + String tooltip = worldPoint.getTooltip(); + if (tooltip == null || tooltip.length() <= 0) + { + return; + } + + Point drawPoint = mapWorldPointToGraphicsPoint(worldPoint.getWorldPoint()); + drawPoint = new Point(drawPoint.getX() + TOOLTIP_OFFSET_WIDTH, drawPoint.getY() + TOOLTIP_OFFSET_HEIGHT); + + graphics.setClip(0, 0, clientProvider.get().getCanvas().getWidth(), clientProvider.get().getCanvas().getHeight()); + graphics.setColor(TOOLTIP_BACKGROUND); + graphics.setFont(FontManager.getRunescapeFont()); + FontMetrics fm = graphics.getFontMetrics(); + int width = fm.stringWidth(tooltip); + int height = fm.getHeight(); + + Rectangle tooltipRect = new Rectangle(drawPoint.getX() - TOOLTIP_PADDING_WIDTH, drawPoint.getY() - TOOLTIP_PADDING_HEIGHT, width + TOOLTIP_PADDING_WIDTH * 2, height + TOOLTIP_PADDING_HEIGHT * 2); + graphics.fillRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight()); + + graphics.setColor(Color.black); + graphics.drawRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight()); + graphics.drawString(tooltip, drawPoint.getX(), drawPoint.getY() + height); + } + + private Point clipToRectangle(Point drawPoint, Rectangle mapDisplayRectangle) + { + int clippedX = drawPoint.getX(); + + if (drawPoint.getX() < mapDisplayRectangle.getX()) + { + clippedX = (int) mapDisplayRectangle.getX(); + } + + if (drawPoint.getX() > mapDisplayRectangle.getX() + mapDisplayRectangle.getWidth()) + { + clippedX = (int) (mapDisplayRectangle.getX() + mapDisplayRectangle.getWidth()); + } + + int clippedY = drawPoint.getY(); + + if (drawPoint.getY() < mapDisplayRectangle.getY()) + { + clippedY = (int) mapDisplayRectangle.getY(); + } + + if (drawPoint.getY() > mapDisplayRectangle.getY() + mapDisplayRectangle.getHeight()) + { + clippedY = (int) (mapDisplayRectangle.getY() + mapDisplayRectangle.getHeight()); + } + + return new Point(clippedX, clippedY); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlayMouseListener.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlayMouseListener.java new file mode 100644 index 0000000000..b86fb7e455 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlayMouseListener.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2018, Morgan Lewis + * 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.ui.overlay.worldmap; + +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.util.List; +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.swing.SwingUtilities; +import net.runelite.api.Client; +import net.runelite.api.Point; +import net.runelite.api.RenderOverview; +import net.runelite.api.coords.WorldPoint; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; +import net.runelite.client.input.MouseListener; + +@Singleton +public class WorldMapOverlayMouseListener extends MouseListener +{ + private final Provider clientProvider; + private final WorldMapPointManager worldMapPointManager; + private WorldMapPoint tooltipPoint = null; + + @Inject + private WorldMapOverlayMouseListener(Provider clientProvider, WorldMapPointManager worldMapPointManager) + { + this.clientProvider = clientProvider; + this.worldMapPointManager = worldMapPointManager; + } + + @Override + public MouseEvent mousePressed(MouseEvent e) + { + List worldMapPoints = worldMapPointManager.getWorldMapPoints(); + if (SwingUtilities.isLeftMouseButton(e) && !worldMapPoints.isEmpty()) + { + Point mousePos = clientProvider.get().getMouseCanvasPosition(); + + for (WorldMapPoint worldMapPoint : worldMapPoints) + { + Rectangle clickbox = worldMapPoint.getClickbox(); + if (clickbox != null && clickbox.contains(mousePos.getX(), mousePos.getY())) + { + if (worldMapPoint.isJumpOnClick()) + { + // jump map to position of point + WorldPoint target = worldMapPoint.getWorldPoint(); + Client client = clientProvider.get(); + RenderOverview renderOverview = client.getRenderOverview(); + renderOverview.setWorldMapPositionTarget(target); + } + return worldMapPoint.onClick(e); + } + } + } + return e; + } + + @Override + public MouseEvent mouseMoved(MouseEvent mouseEvent) + { + List worldMapPoints = worldMapPointManager.getWorldMapPoints(); + if (worldMapPoints.isEmpty()) + { + return mouseEvent; + } + + final Client client = clientProvider.get(); + final Point mousePos = client.getMouseCanvasPosition(); + final Widget view = client.getWidget(WidgetInfo.WORLD_MAP_VIEW); + + if (view == null) + { + return mouseEvent; + } + + final Rectangle worldMapDisplay = view.getBounds(); + + if (worldMapDisplay == null || !worldMapDisplay.contains(mousePos.getX(), mousePos.getY())) + { + if (tooltipPoint != null) + { + tooltipPoint.setTooltipVisible(false); + tooltipPoint = null; + final Widget rsTooltip = client.getWidget(WidgetInfo.WORLD_MAP_TOOLTIP); + if (rsTooltip != null) + { + rsTooltip.setHidden(false); + } + } + return mouseEvent; + } + + if (tooltipPoint != null) + { + if (tooltipPoint.getClickbox() != null + && tooltipPoint.getClickbox().contains(mousePos.getX(), mousePos.getY())) + { + return mouseEvent; + } + else + { + tooltipPoint.setTooltipVisible(false); + tooltipPoint = null; + final Widget rsTooltip = client.getWidget(WidgetInfo.WORLD_MAP_TOOLTIP); + if (rsTooltip != null) + { + rsTooltip.setHidden(false); + } + } + } + + for (WorldMapPoint worldMapPoint : worldMapPointManager.getWorldMapPoints()) + { + if (worldMapPoint.getClickbox() != null + && worldMapPoint.getClickbox().contains(mousePos.getX(), mousePos.getY()) + && worldMapPoint.getTooltip() != null) + { + worldMapPoint.setTooltipVisible(true); + tooltipPoint = worldMapPoint; + final Widget rsTooltip = client.getWidget(WidgetInfo.WORLD_MAP_TOOLTIP); + if (rsTooltip != null) + { + rsTooltip.setHidden(true); + } + return mouseEvent; + } + } + return mouseEvent; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPoint.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPoint.java new file mode 100644 index 0000000000..c9e7345e31 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPoint.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2018, Morgan Lewis + * 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.ui.overlay.worldmap; + +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import lombok.Data; +import net.runelite.api.Point; +import net.runelite.api.coords.WorldPoint; + +@Data +public class WorldMapPoint +{ + private BufferedImage image; + + private WorldPoint worldPoint; + + /** + * The point on the image that will be drawn at WorldPoint + * WorldMapPointManager will center the image if imagePoint is null + */ + private Point imagePoint; + + private Rectangle clickbox; + + private boolean snapToEdge; + + private boolean currentlyEdgeSnapped; + + /** + * Whether or not the map jumps to worldPoint when the overlay is clicked + */ + private boolean jumpOnClick; + + private boolean tooltipVisible; + + private String tooltip; + + public WorldMapPoint(WorldPoint worldPoint, BufferedImage image) + { + this.worldPoint = worldPoint; + this.image = image; + } + + public MouseEvent onClick(MouseEvent e) + { + return e; + } + + public void onEdgeSnap() + { + } + + public void onEdgeUnsnap() + { + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPointManager.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPointManager.java new file mode 100644 index 0000000000..ae836478b9 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPointManager.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Morgan Lewis + * 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.ui.overlay.worldmap; + +import java.util.ArrayList; +import java.util.List; +import javax.inject.Singleton; +import lombok.AccessLevel; +import lombok.Getter; + +@Singleton +public class WorldMapPointManager +{ + @Getter(AccessLevel.PACKAGE) + private final List worldMapPoints = new ArrayList<>(); + + public void add(WorldMapPoint worldMapPoint) + { + worldMapPoints.add(worldMapPoint); + } + + public void remove(WorldMapPoint worldMapPoint) + { + worldMapPoints.remove(worldMapPoint); + } +}