Instance map improvements + moving
- Change instance map to resize on "fixed" layer so it can be layouted - Scroll minimap only when mouse is in the minimap bounds Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -24,12 +24,11 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.instancemap;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.MouseListener;
|
||||
import net.runelite.client.input.MouseWheelListener;
|
||||
@@ -39,6 +38,9 @@ public class InstanceMapInputListener extends MouseListener implements KeyListen
|
||||
@Inject
|
||||
private InstanceMapPlugin plugin;
|
||||
|
||||
@Inject
|
||||
private InstanceMapOverlay overlay;
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent event)
|
||||
{
|
||||
@@ -48,7 +50,7 @@ public class InstanceMapInputListener extends MouseListener implements KeyListen
|
||||
@Override
|
||||
public void keyPressed(KeyEvent event)
|
||||
{
|
||||
if (!plugin.isMapShown())
|
||||
if (!overlay.isMapShown())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -69,7 +71,7 @@ public class InstanceMapInputListener extends MouseListener implements KeyListen
|
||||
@Override
|
||||
public MouseWheelEvent mouseWheelMoved(MouseWheelEvent event)
|
||||
{
|
||||
if (!plugin.isMapShown())
|
||||
if (!overlay.isMapShown() || isNotWithinOverlay(event.getPoint()))
|
||||
{
|
||||
return event;
|
||||
}
|
||||
@@ -92,7 +94,7 @@ public class InstanceMapInputListener extends MouseListener implements KeyListen
|
||||
@Override
|
||||
public MouseEvent mouseClicked(MouseEvent event)
|
||||
{
|
||||
if (!plugin.isMapShown() || !isWithinOverlay(event.getX(), event.getY()))
|
||||
if (!overlay.isMapShown() || isNotWithinOverlay(event.getPoint()))
|
||||
{
|
||||
return event;
|
||||
}
|
||||
@@ -104,7 +106,7 @@ public class InstanceMapInputListener extends MouseListener implements KeyListen
|
||||
@Override
|
||||
public MouseEvent mousePressed(MouseEvent event)
|
||||
{
|
||||
if (!plugin.isMapShown() || !isWithinOverlay(event.getX(), event.getY()))
|
||||
if (!overlay.isMapShown() || isNotWithinOverlay(event.getPoint()))
|
||||
{
|
||||
return event;
|
||||
}
|
||||
@@ -113,17 +115,8 @@ public class InstanceMapInputListener extends MouseListener implements KeyListen
|
||||
return event;
|
||||
}
|
||||
|
||||
private boolean isWithinOverlay(int x, int y)
|
||||
private boolean isNotWithinOverlay(final Point point)
|
||||
{
|
||||
Dimension dimm = plugin.getOverlaySize();
|
||||
|
||||
if (dimm == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Point offset = plugin.getMapOffset();
|
||||
return (x >= offset.getX() && x <= offset.getX() + dimm.width &&
|
||||
y >= offset.getY() && y <= offset.getY() + dimm.height);
|
||||
return !overlay.getBounds().contains(point);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameObject;
|
||||
import net.runelite.api.GroundObject;
|
||||
@@ -67,10 +68,11 @@ import static net.runelite.client.plugins.instancemap.WallOffset.NONE;
|
||||
import static net.runelite.client.plugins.instancemap.WallOffset.TOP_LEFT;
|
||||
import static net.runelite.client.plugins.instancemap.WallOffset.TOP_RIGHT;
|
||||
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;
|
||||
import net.runelite.client.ui.overlay.components.BackgroundComponent;
|
||||
|
||||
@Singleton
|
||||
class InstanceMapOverlay extends Overlay
|
||||
{
|
||||
/**
|
||||
@@ -93,7 +95,6 @@ class InstanceMapOverlay extends Overlay
|
||||
|
||||
private static final int MAX_PLANE = 3;
|
||||
private static final int MIN_PLANE = 0;
|
||||
private final InstanceMapPlugin plugin;
|
||||
|
||||
/**
|
||||
* The plane to render on the instance map. When the map is opened this
|
||||
@@ -114,24 +115,11 @@ class InstanceMapOverlay extends Overlay
|
||||
private final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
||||
|
||||
@Inject
|
||||
InstanceMapOverlay(Client client, InstanceMapPlugin plugin)
|
||||
InstanceMapOverlay(Client client)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.client = client;
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
setLayer(OverlayLayer.ALWAYS_ON_TOP);
|
||||
}
|
||||
|
||||
public Dimension getInstanceMapDimension()
|
||||
{
|
||||
BufferedImage image = mapImage;
|
||||
|
||||
if (image == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Dimension(image.getWidth(), image.getHeight());
|
||||
setPriority(OverlayPriority.HIGH);
|
||||
setPosition(OverlayPosition.TOP_LEFT);
|
||||
}
|
||||
|
||||
public boolean isMapShown()
|
||||
@@ -207,16 +195,19 @@ class InstanceMapOverlay extends Overlay
|
||||
}
|
||||
}
|
||||
|
||||
final Point offset = plugin.getMapOffset();
|
||||
|
||||
graphics.drawImage(image, offset.getX(), offset.getY(), null);
|
||||
graphics.drawImage(image, 0, 0, null);
|
||||
|
||||
if (client.getPlane() == viewedPlane)//If we are not viewing the plane we are on, don't show player's position
|
||||
{
|
||||
drawPlayerDot(graphics, offset.getX(), offset.getY(), client.getLocalPlayer(), Color.white, Color.black);
|
||||
drawPlayerDot(graphics, client.getLocalPlayer(), Color.white, Color.black);
|
||||
}
|
||||
|
||||
return getInstanceMapDimension();
|
||||
if (image == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Dimension(image.getWidth(), image.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +215,7 @@ class InstanceMapOverlay extends Overlay
|
||||
*
|
||||
* @param graphics graphics to be drawn to
|
||||
*/
|
||||
private void drawPlayerDot(Graphics2D graphics, int baseX, int baseY, Player player,
|
||||
private void drawPlayerDot(Graphics2D graphics, Player player,
|
||||
Color dotColor, Color outlineColor)
|
||||
{
|
||||
LocalPoint playerLoc = player.getLocalLocation();
|
||||
@@ -233,8 +224,8 @@ class InstanceMapOverlay extends Overlay
|
||||
int tileX = playerLoc.getRegionX();
|
||||
int tileY = (tiles[0].length - 1) - playerLoc.getRegionY(); // flip the y value
|
||||
|
||||
int x = baseX + (int) (tileX * TILE_SIZE * MAP_SCALING);
|
||||
int y = baseY + (int) (tileY * TILE_SIZE * MAP_SCALING);
|
||||
int x = (int) (tileX * TILE_SIZE * MAP_SCALING);
|
||||
int y = (int) (tileY * TILE_SIZE * MAP_SCALING);
|
||||
graphics.setColor(dotColor);
|
||||
graphics.fillRect(x, y, PLAYER_MARKER_SIZE, PLAYER_MARKER_SIZE);//draw the players point on the map
|
||||
graphics.setColor(outlineColor);
|
||||
|
||||
@@ -26,10 +26,7 @@ package net.runelite.client.plugins.instancemap;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Binder;
|
||||
import java.awt.Dimension;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.MapRegionChanged;
|
||||
import net.runelite.api.events.WidgetMenuOptionClicked;
|
||||
@@ -48,15 +45,8 @@ import net.runelite.client.ui.overlay.Overlay;
|
||||
)
|
||||
public class InstanceMapPlugin extends Plugin
|
||||
{
|
||||
private static final int OVERLAY_POSITION_X = 5;
|
||||
private static final int OVERLAY_POSITION_Y = 20;
|
||||
private static final int FRAME_OFFSET = 4;
|
||||
|
||||
private final WidgetMenuOption openMapOption = new WidgetMenuOption("Show", "Instance Map", WidgetInfo.WORLD_MAP);
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private InstanceMapInputListener inputListener;
|
||||
|
||||
@@ -150,18 +140,6 @@ public class InstanceMapPlugin extends Plugin
|
||||
return overlay;
|
||||
}
|
||||
|
||||
public boolean isMapShown()
|
||||
{
|
||||
return overlay.isMapShown();
|
||||
}
|
||||
|
||||
public Point getMapOffset()
|
||||
{
|
||||
return new Point(
|
||||
OVERLAY_POSITION_X + (client.isResized() ? 0 : FRAME_OFFSET),
|
||||
OVERLAY_POSITION_Y + (client.isResized() ? 0 : FRAME_OFFSET));
|
||||
}
|
||||
|
||||
public void showMap()
|
||||
{
|
||||
overlay.setShowMap(true);
|
||||
@@ -183,9 +161,4 @@ public class InstanceMapPlugin extends Plugin
|
||||
{
|
||||
overlay.onDescend();
|
||||
}
|
||||
|
||||
public Dimension getOverlaySize()
|
||||
{
|
||||
return overlay.getInstanceMapDimension();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user