Reposition instance map correctly in resizeable
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -29,10 +29,10 @@ import java.awt.event.KeyEvent;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import net.runelite.api.Point;
|
||||||
import net.runelite.client.input.KeyListener;
|
import net.runelite.client.input.KeyListener;
|
||||||
import net.runelite.client.input.MouseListener;
|
import net.runelite.client.input.MouseListener;
|
||||||
import net.runelite.client.input.MouseWheelListener;
|
import net.runelite.client.input.MouseWheelListener;
|
||||||
import static net.runelite.client.plugins.instancemap.InstanceMapOverlay.OVERLAY_POSITION;
|
|
||||||
|
|
||||||
public class InstanceMapInputListener extends MouseListener implements KeyListener, MouseWheelListener
|
public class InstanceMapInputListener extends MouseListener implements KeyListener, MouseWheelListener
|
||||||
{
|
{
|
||||||
@@ -116,11 +116,14 @@ public class InstanceMapInputListener extends MouseListener implements KeyListen
|
|||||||
private boolean isWithinOverlay(int x, int y)
|
private boolean isWithinOverlay(int x, int y)
|
||||||
{
|
{
|
||||||
Dimension dimm = plugin.getOverlaySize();
|
Dimension dimm = plugin.getOverlaySize();
|
||||||
|
|
||||||
if (dimm == null)
|
if (dimm == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (x >= OVERLAY_POSITION.getX() && x <= OVERLAY_POSITION.getX() + dimm.width &&
|
|
||||||
y >= OVERLAY_POSITION.getY() && y <= OVERLAY_POSITION.getY() + dimm.height);
|
final Point offset = plugin.getMapOffset();
|
||||||
|
return (x >= offset.getX() && x <= offset.getX() + dimm.width &&
|
||||||
|
y >= offset.getY() && y <= offset.getY() + dimm.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ import net.runelite.client.ui.overlay.OverlayPosition;
|
|||||||
|
|
||||||
class InstanceMapOverlay extends Overlay
|
class InstanceMapOverlay extends Overlay
|
||||||
{
|
{
|
||||||
public static final Point OVERLAY_POSITION = new Point(10, 25);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The size of tiles on the map. The way the client renders requires
|
* The size of tiles on the map. The way the client renders requires
|
||||||
* this value to be 4. Changing this will break the method for rendering
|
* this value to be 4. Changing this will break the method for rendering
|
||||||
@@ -93,6 +91,7 @@ class InstanceMapOverlay extends Overlay
|
|||||||
|
|
||||||
private static final int MAX_PLANE = 3;
|
private static final int MAX_PLANE = 3;
|
||||||
private static final int MIN_PLANE = 0;
|
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
|
* The plane to render on the instance map. When the map is opened this
|
||||||
@@ -112,11 +111,12 @@ class InstanceMapOverlay extends Overlay
|
|||||||
private volatile boolean showMap = false;
|
private volatile boolean showMap = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
InstanceMapOverlay(Client client)
|
InstanceMapOverlay(Client client, InstanceMapPlugin plugin)
|
||||||
{
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.client = client;
|
||||||
setPosition(OverlayPosition.DYNAMIC);
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
setLayer(OverlayLayer.ALWAYS_ON_TOP);
|
setLayer(OverlayLayer.ALWAYS_ON_TOP);
|
||||||
this.client = client;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dimension getInstanceMapDimension()
|
public Dimension getInstanceMapDimension()
|
||||||
@@ -204,11 +204,13 @@ class InstanceMapOverlay extends Overlay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
graphics.drawImage(image, OVERLAY_POSITION.getX(), OVERLAY_POSITION.getY(), null);
|
final Point offset = plugin.getMapOffset();
|
||||||
|
|
||||||
|
graphics.drawImage(image, offset.getX(), offset.getY(), null);
|
||||||
|
|
||||||
if (client.getPlane() == viewedPlane)//If we are not viewing the plane we are on, don't show player's position
|
if (client.getPlane() == viewedPlane)//If we are not viewing the plane we are on, don't show player's position
|
||||||
{
|
{
|
||||||
drawPlayerDot(graphics, client.getLocalPlayer(), Color.white, Color.black);
|
drawPlayerDot(graphics, offset.getX(), offset.getY(), client.getLocalPlayer(), Color.white, Color.black);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getInstanceMapDimension();
|
return getInstanceMapDimension();
|
||||||
@@ -219,7 +221,8 @@ class InstanceMapOverlay extends Overlay
|
|||||||
*
|
*
|
||||||
* @param graphics graphics to be drawn to
|
* @param graphics graphics to be drawn to
|
||||||
*/
|
*/
|
||||||
private void drawPlayerDot(Graphics2D graphics, Player player, Color dotColor, Color outlineColor)
|
private void drawPlayerDot(Graphics2D graphics, int baseX, int baseY, Player player,
|
||||||
|
Color dotColor, Color outlineColor)
|
||||||
{
|
{
|
||||||
LocalPoint playerLoc = player.getLocalLocation();
|
LocalPoint playerLoc = player.getLocalLocation();
|
||||||
|
|
||||||
@@ -227,8 +230,8 @@ class InstanceMapOverlay extends Overlay
|
|||||||
int tileX = playerLoc.getRegionX();
|
int tileX = playerLoc.getRegionX();
|
||||||
int tileY = (tiles[0].length - 1) - playerLoc.getRegionY(); // flip the y value
|
int tileY = (tiles[0].length - 1) - playerLoc.getRegionY(); // flip the y value
|
||||||
|
|
||||||
int x = OVERLAY_POSITION.getX() + (int) (tileX * TILE_SIZE * MAP_SCALING);
|
int x = baseX + (int) (tileX * TILE_SIZE * MAP_SCALING);
|
||||||
int y = OVERLAY_POSITION.getY() + (int) (tileY * TILE_SIZE * MAP_SCALING);
|
int y = baseY + (int) (tileY * TILE_SIZE * MAP_SCALING);
|
||||||
graphics.setColor(dotColor);
|
graphics.setColor(dotColor);
|
||||||
graphics.fillRect(x, y, PLAYER_MARKER_SIZE, PLAYER_MARKER_SIZE);//draw the players point on the map
|
graphics.fillRect(x, y, PLAYER_MARKER_SIZE, PLAYER_MARKER_SIZE);//draw the players point on the map
|
||||||
graphics.setColor(outlineColor);
|
graphics.setColor(outlineColor);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.google.inject.Binder;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.MapRegionChanged;
|
import net.runelite.api.events.MapRegionChanged;
|
||||||
import net.runelite.api.events.WidgetMenuOptionClicked;
|
import net.runelite.api.events.WidgetMenuOptionClicked;
|
||||||
@@ -47,6 +48,10 @@ import net.runelite.client.ui.overlay.Overlay;
|
|||||||
)
|
)
|
||||||
public class InstanceMapPlugin extends Plugin
|
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);
|
private final WidgetMenuOption openMapOption = new WidgetMenuOption("Show", "Instance Map", WidgetInfo.WORLD_MAP);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -150,6 +155,13 @@ public class InstanceMapPlugin extends Plugin
|
|||||||
return overlay.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()
|
public void showMap()
|
||||||
{
|
{
|
||||||
overlay.setShowMap(true);
|
overlay.setShowMap(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user