Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2022-05-18 17:08:07 +02:00
14 changed files with 229 additions and 208 deletions

View File

@@ -197,7 +197,7 @@ public interface ChatCommandsConfig extends Config
) )
default Keybind clearSingleWord() default Keybind clearSingleWord()
{ {
return new Keybind(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK); return new Keybind(KeyEvent.VK_BACK_SPACE, InputEvent.CTRL_DOWN_MASK);
} }
@ConfigItem( @ConfigItem(
@@ -208,6 +208,6 @@ public interface ChatCommandsConfig extends Config
) )
default Keybind clearChatBox() default Keybind clearChatBox()
{ {
return new Keybind(KeyEvent.VK_BACK_SPACE, InputEvent.CTRL_DOWN_MASK); return Keybind.NOT_SET;
} }
} }

View File

@@ -48,6 +48,7 @@ import net.runelite.api.VarbitComposition;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.CommandExecuted; import net.runelite.api.events.CommandExecuted;
import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.events.StatChanged; import net.runelite.api.events.StatChanged;
import net.runelite.api.events.VarbitChanged; import net.runelite.api.events.VarbitChanged;
import net.runelite.api.kit.KitType; import net.runelite.api.kit.KitType;
@@ -492,4 +493,13 @@ public class DevToolsPlugin extends Plugin
entry.setTarget(entry.getTarget() + " " + ColorUtil.prependColorTag("(" + info + ")", JagexColors.MENU_TARGET)); entry.setTarget(entry.getTarget() + " " + ColorUtil.prependColorTag("(" + info + ")", JagexColors.MENU_TARGET));
} }
} }
@Subscribe
public void onScriptCallbackEvent(ScriptCallbackEvent ev)
{
if ("devtoolsEnabled".equals(ev.getEventName()))
{
client.getIntStack()[client.getIntStackSize() - 1] = 1;
}
}
} }

View File

@@ -308,6 +308,11 @@ enum ItemWithCharge
ROW3(TELEPORT, RING_OF_WEALTH_3, 3), ROW3(TELEPORT, RING_OF_WEALTH_3, 3),
ROW4(TELEPORT, RING_OF_WEALTH_4, 4), ROW4(TELEPORT, RING_OF_WEALTH_4, 4),
ROW5(TELEPORT, RING_OF_WEALTH_5, 5), ROW5(TELEPORT, RING_OF_WEALTH_5, 5),
ROWI1(TELEPORT, RING_OF_WEALTH_I1, 1),
ROWI2(TELEPORT, RING_OF_WEALTH_I2, 2),
ROWI3(TELEPORT, RING_OF_WEALTH_I3, 3),
ROWI4(TELEPORT, RING_OF_WEALTH_I4, 4),
ROWI5(TELEPORT, RING_OF_WEALTH_I5, 5),
SACK_CABBAGES1(SACK, CABBAGES1, 1), SACK_CABBAGES1(SACK, CABBAGES1, 1),
SACK_CABBAGES2(SACK, CABBAGES2, 2), SACK_CABBAGES2(SACK, CABBAGES2, 2),
SACK_CABBAGES3(SACK, CABBAGES3, 3), SACK_CABBAGES3(SACK, CABBAGES3, 3),

View File

@@ -42,9 +42,10 @@ class ScreenMarkerCreationOverlay extends Overlay
private ScreenMarkerCreationOverlay(final ScreenMarkerPlugin plugin) private ScreenMarkerCreationOverlay(final ScreenMarkerPlugin plugin)
{ {
this.plugin = plugin; this.plugin = plugin;
setPosition(OverlayPosition.DETACHED); setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS); setLayer(OverlayLayer.ABOVE_WIDGETS);
setPriority(OverlayPriority.HIGH); setPriority(OverlayPriority.HIGH);
setMovable(true);
} }
@Override @Override

View File

@@ -45,9 +45,10 @@ public class ScreenMarkerOverlay extends Overlay
{ {
this.marker = marker; this.marker = marker;
this.screenMarkerRenderable = new ScreenMarkerRenderable(); this.screenMarkerRenderable = new ScreenMarkerRenderable();
setPosition(OverlayPosition.DETACHED); setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ALWAYS_ON_TOP); setLayer(OverlayLayer.ALWAYS_ON_TOP);
setPriority(OverlayPriority.HIGH); setPriority(OverlayPriority.HIGH);
setMovable(true);
setResizable(true); setResizable(true);
setMinimumSize(16); setMinimumSize(16);
setResettable(false); setResettable(false);

View File

@@ -51,9 +51,10 @@ class ScreenMarkerWidgetHighlightOverlay extends Overlay
{ {
this.plugin = plugin; this.plugin = plugin;
this.client = client; this.client = client;
setPosition(OverlayPosition.DETACHED); setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS); setLayer(OverlayLayer.ABOVE_WIDGETS);
setPriority(OverlayPriority.HIGH); setPriority(OverlayPriority.HIGH);
setMovable(true);
} }
@Override @Override

View File

@@ -64,12 +64,25 @@ public abstract class Overlay implements LayoutableRenderableEntity
@Setter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED)
private boolean dragTargetable; private boolean dragTargetable;
/**
* Whether this overlay can be moved with alt
*/
@Setter(AccessLevel.PROTECTED)
private boolean movable = true;
/**
* Whether this overlay can be moved to a snap corner
* and have its preferredPosition changed
*/
@Setter(AccessLevel.PROTECTED)
private boolean snappable = true;
protected Overlay() protected Overlay()
{ {
plugin = null; plugin = null;
} }
protected Overlay(Plugin plugin) protected Overlay(@Nullable Plugin plugin)
{ {
this.plugin = plugin; this.plugin = plugin;
} }
@@ -169,4 +182,25 @@ public abstract class Overlay implements LayoutableRenderableEntity
public void revalidate() public void revalidate()
{ {
} }
public void setPosition(OverlayPosition position)
{
this.position = position;
switch (position)
{
case TOOLTIP:
case DYNAMIC:
movable = false;
snappable = false;
break;
case DETACHED:
movable = true;
snappable = false;
break;
default:
movable = true;
snappable = true;
}
}
} }

View File

@@ -313,21 +313,29 @@ public class OverlayManager
private void loadOverlay(final Overlay overlay) private void loadOverlay(final Overlay overlay)
{ {
final Point location = loadOverlayLocation(overlay); final Point location = loadOverlayLocation(overlay);
overlay.setPreferredLocation(location);
final Dimension size = loadOverlaySize(overlay); final Dimension size = loadOverlaySize(overlay);
overlay.setPreferredSize(size);
final OverlayPosition position = loadOverlayPosition(overlay); final OverlayPosition position = loadOverlayPosition(overlay);
if (position != null)
if (overlay.isMovable())
{ {
if (overlay.getPosition() != OverlayPosition.DYNAMIC && overlay.getPosition() != OverlayPosition.TOOLTIP) overlay.setPreferredLocation(location);
{ }
overlay.setPreferredPosition(position); else
} {
else log.info("Resetting preferred location of non-movable overlay {} (class {})", overlay.getName(), overlay.getClass().getName());
{ saveOverlayLocation(overlay);
log.info("Resetting preferred position of dynamic overlay {}", overlay.getClass().getSimpleName()); }
saveOverlayPosition(overlay);
} overlay.setPreferredSize(size);
if (overlay.isSnappable())
{
overlay.setPreferredPosition(position);
}
else
{
log.info("Resetting preferred position of non-snappable overlay {} (class {})", overlay.getName(), overlay.getClass().getName());
saveOverlayPosition(overlay);
} }
} }

View File

@@ -28,7 +28,9 @@ public enum OverlayPosition
{ {
/** /**
* Not attached anywhere, but still movable * Not attached anywhere, but still movable
* Deprecated. Use DYNAMIC and setMovable(true)
*/ */
@Deprecated
DETACHED, DETACHED,
/** /**
* Overlay places itself where it wants * Overlay places itself where it wants

View File

@@ -25,7 +25,6 @@
package net.runelite.client.ui.overlay; package net.runelite.client.ui.overlay;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import java.awt.Color; import java.awt.Color;
import java.awt.Composite; import java.awt.Composite;
@@ -41,7 +40,6 @@ import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -107,7 +105,8 @@ public class OverlayRenderer extends MouseAdapter
private boolean inOverlayResizingMode; private boolean inOverlayResizingMode;
private boolean inOverlayDraggingMode; private boolean inOverlayDraggingMode;
private boolean startedMovingOverlay; private boolean startedMovingOverlay;
private Overlay hoveredOverlay; // for building menu entries private Overlay curHoveredOverlay; // for building menu entries
private Overlay lastHoveredOverlay; // for off-thread access
// Overlay state validation // Overlay state validation
private Rectangle viewportBounds; private Rectangle viewportBounds;
@@ -175,14 +174,16 @@ public class OverlayRenderer extends MouseAdapter
resetOverlayManagementMode(); resetOverlayManagementMode();
} }
hoveredOverlay = null; curHoveredOverlay = null;
} }
} }
@Subscribe @Subscribe
protected void onClientTick(ClientTick t) protected void onClientTick(ClientTick t)
{ {
final Overlay overlay = hoveredOverlay; lastHoveredOverlay = curHoveredOverlay;
final Overlay overlay = curHoveredOverlay;
if (overlay == null || client.isMenuOpen()) if (overlay == null || client.isMenuOpen())
{ {
return; return;
@@ -216,7 +217,7 @@ public class OverlayRenderer extends MouseAdapter
@Subscribe @Subscribe
public void onBeforeRender(BeforeRender event) public void onBeforeRender(BeforeRender event)
{ {
hoveredOverlay = null; curHoveredOverlay = null;
if (focusedOverlay == null && prevFocusedOverlay != null) if (focusedOverlay == null && prevFocusedOverlay != null)
{ {
@@ -261,7 +262,7 @@ public class OverlayRenderer extends MouseAdapter
overlayManager.setWidgetItems(Collections.emptyList()); overlayManager.setWidgetItems(Collections.emptyList());
} }
private void renderOverlays(Graphics2D graphics, Collection<Overlay> overlays, OverlayLayer layer) private void renderOverlays(final Graphics2D graphics, Collection<Overlay> overlays, final OverlayLayer layer)
{ {
if (overlays == null if (overlays == null
|| overlays.isEmpty() || overlays.isEmpty()
@@ -273,7 +274,7 @@ public class OverlayRenderer extends MouseAdapter
OverlayUtil.setGraphicProperties(graphics); OverlayUtil.setGraphicProperties(graphics);
// Draw snap corners // Draw snap corners
if (inOverlayDraggingMode && layer == OverlayLayer.UNDER_WIDGETS && currentManagedOverlay != null && currentManagedOverlay.getPosition() != OverlayPosition.DETACHED) if (inOverlayDraggingMode && layer == OverlayLayer.UNDER_WIDGETS && currentManagedOverlay != null && currentManagedOverlay.isSnappable())
{ {
final OverlayBounds translatedSnapCorners = snapCorners.translated( final OverlayBounds translatedSnapCorners = snapCorners.translated(
-SNAP_CORNER_SIZE.width, -SNAP_CORNER_SIZE.width,
@@ -290,10 +291,6 @@ public class OverlayRenderer extends MouseAdapter
graphics.setColor(previous); graphics.setColor(previous);
} }
// Get mouse position
final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
final Point mouse = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY());
// Save graphics2d properties so we can restore them later // Save graphics2d properties so we can restore them later
final AffineTransform transform = graphics.getTransform(); final AffineTransform transform = graphics.getTransform();
final Stroke stroke = graphics.getStroke(); final Stroke stroke = graphics.getStroke();
@@ -302,126 +299,97 @@ public class OverlayRenderer extends MouseAdapter
final RenderingHints renderingHints = graphics.getRenderingHints(); final RenderingHints renderingHints = graphics.getRenderingHints();
final Color background = graphics.getBackground(); final Color background = graphics.getBackground();
final Rectangle clip = clipBounds(layer);
graphics.setClip(clip);
for (Overlay overlay : overlays) for (Overlay overlay : overlays)
{ {
final OverlayPosition overlayPosition = getCorrectedOverlayPosition(overlay); final OverlayPosition overlayPosition = getCorrectedOverlayPosition(overlay);
final Rectangle bounds = overlay.getBounds();
final Dimension dimension = bounds.getSize();
final Point preferredLocation = overlay.getPreferredLocation();
Point location;
Rectangle snapCorner = null;
if (overlayPosition == OverlayPosition.DYNAMIC || overlayPosition == OverlayPosition.TOOLTIP) // If the final position is not modified, layout it
if (overlayPosition != OverlayPosition.DYNAMIC && overlayPosition != OverlayPosition.TOOLTIP
&& overlayPosition != OverlayPosition.DETACHED && preferredLocation == null)
{ {
safeRender(client, overlay, layer, graphics, new Point()); snapCorner = snapCorners.forPosition(overlayPosition);
final Point translation = OverlayUtil.transformPosition(overlayPosition, dimension); // offset from corner
// Restore graphics2d properties // Target x/y to draw the overlay
graphics.setTransform(transform); int destX = snapCorner.x + translation.x;
graphics.setStroke(stroke); int destY = snapCorner.y + translation.y;
graphics.setComposite(composite); // Clamp the target position to ensure it is on screen or within parent bounds
graphics.setPaint(paint); location = clampOverlayLocation(destX, destY, dimension.width, dimension.height, overlay);
graphics.setRenderingHints(renderingHints);
graphics.setBackground(background);
} }
else else
{ {
final Rectangle bounds = overlay.getBounds(); location = preferredLocation != null ? preferredLocation : bounds.getLocation();
final Dimension dimension = bounds.getSize();
final Point preferredLocation = overlay.getPreferredLocation();
Point location;
Rectangle snapCorner = null;
// If the final position is not modified, layout it // Clamp the overlay position to ensure it is on screen or within parent bounds
if (overlayPosition != OverlayPosition.DETACHED && (preferredLocation == null || overlay.getPreferredPosition() != null)) location = clampOverlayLocation(location.x, location.y, dimension.width, dimension.height, overlay);
}
if (overlay.getPreferredSize() != null)
{
bounds.setSize(overlay.getPreferredSize());
}
safeRender(overlay, graphics, location);
// Adjust snap corner based on where the overlay was drawn
if (snapCorner != null && bounds.width + bounds.height > 0)
{
OverlayUtil.shiftSnapCorner(overlayPosition, snapCorner, bounds, PADDING);
}
// Restore graphics2d properties prior to drawing bounds
graphics.setTransform(transform);
graphics.setStroke(stroke);
graphics.setComposite(composite);
graphics.setPaint(paint);
graphics.setRenderingHints(renderingHints);
graphics.setBackground(background);
if (!graphics.getClip().equals(clip))
{
graphics.setClip(clip);
}
if (!bounds.isEmpty())
{
if (inOverlayManagingMode)
{ {
snapCorner = snapCorners.forPosition(overlayPosition); Color boundsColor;
final Point translation = OverlayUtil.transformPosition(overlayPosition, dimension); // offset from corner if (inOverlayResizingMode && currentManagedOverlay == overlay)
// Target x/y to draw the overlay
int destX = snapCorner.x + translation.x;
int destY = snapCorner.y + translation.y;
// Clamp the target position to ensure it is on screen or within parent bounds
location = clampOverlayLocation(destX, destY, dimension.width, dimension.height, overlay);
}
else
{
location = preferredLocation != null ? preferredLocation : bounds.getLocation();
// Clamp the overlay position to ensure it is on screen or within parent bounds
location = clampOverlayLocation(location.x, location.y, dimension.width, dimension.height, overlay);
}
if (overlay.getPreferredSize() != null)
{
bounds.setSize(overlay.getPreferredSize());
}
safeRender(client, overlay, layer, graphics, location);
// Adjust snap corner based on where the overlay was drawn
if (snapCorner != null && bounds.width + bounds.height > 0)
{
OverlayUtil.shiftSnapCorner(overlayPosition, snapCorner, bounds, PADDING);
}
// Restore graphics2d properties prior to drawing bounds
graphics.setTransform(transform);
graphics.setStroke(stroke);
graphics.setComposite(composite);
graphics.setPaint(paint);
graphics.setRenderingHints(renderingHints);
graphics.setBackground(background);
if (!bounds.isEmpty())
{
if (inOverlayManagingMode)
{ {
Color boundsColor; boundsColor = MOVING_OVERLAY_RESIZING_COLOR;
if (inOverlayResizingMode && currentManagedOverlay == overlay) }
{ else if (inOverlayDraggingMode && currentManagedOverlay == overlay)
boundsColor = MOVING_OVERLAY_RESIZING_COLOR; {
} boundsColor = MOVING_OVERLAY_ACTIVE_COLOR;
else if (inOverlayDraggingMode && currentManagedOverlay == overlay) }
{ else if (inOverlayDraggingMode && overlay.isDragTargetable() && currentManagedOverlay.isDragTargetable()
boundsColor = MOVING_OVERLAY_ACTIVE_COLOR; && currentManagedOverlay.getBounds().intersects(bounds))
} {
else if (inOverlayDraggingMode && overlay.isDragTargetable() && currentManagedOverlay.isDragTargetable() boundsColor = MOVING_OVERLAY_TARGET_COLOR;
&& currentManagedOverlay.getBounds().intersects(bounds)) assert currentManagedOverlay != overlay;
{ dragTargetOverlay = overlay;
boundsColor = MOVING_OVERLAY_TARGET_COLOR; }
assert currentManagedOverlay != overlay; else
dragTargetOverlay = overlay; {
} boundsColor = MOVING_OVERLAY_COLOR;
else
{
boundsColor = MOVING_OVERLAY_COLOR;
}
graphics.setColor(boundsColor);
graphics.draw(bounds);
graphics.setPaint(paint);
} }
if (!client.isMenuOpen() && !client.getSpellSelected() && bounds.contains(mouse)) graphics.setColor(boundsColor);
{ graphics.draw(bounds);
hoveredOverlay = overlay; graphics.setPaint(paint);
}
if (inOverlayManagingMode) if (!client.isMenuOpen() && !client.getSpellSelected() && bounds.contains(mousePosition))
{ {
String tooltipText = overlay.getPlugin() == null ? overlay.getName() : overlay.getPlugin().getName(); curHoveredOverlay = overlay;
tooltipManager.add(new Tooltip(tooltipText)); overlay.onMouseOver();
}
if (focusedOverlay == null)
{
focusedOverlay = overlay;
if (focusedOverlay != prevFocusedOverlay)
{
if (prevFocusedOverlay != null)
{
prevFocusedOverlay.onMouseExit();
}
overlay.onMouseEnter();
}
}
overlay.onMouseOver();
}
} }
} }
} }
@@ -430,17 +398,16 @@ public class OverlayRenderer extends MouseAdapter
@Override @Override
public MouseEvent mousePressed(MouseEvent mouseEvent) public MouseEvent mousePressed(MouseEvent mouseEvent)
{ {
final Point mousePoint = mouseEvent.getPoint();
mousePosition.setLocation(mousePoint);
if (!inOverlayManagingMode) if (!inOverlayManagingMode)
{ {
return mouseEvent; return mouseEvent;
} }
final Point mousePoint = mouseEvent.getPoint();
mousePosition.setLocation(mousePoint);
// See if we've clicked on an overlay // See if we've clicked on an overlay
currentManagedOverlay = findMangedOverlay(mousePoint); currentManagedOverlay = lastHoveredOverlay;
if (currentManagedOverlay == null) if (currentManagedOverlay == null)
{ {
return mouseEvent; return mouseEvent;
@@ -476,17 +443,17 @@ public class OverlayRenderer extends MouseAdapter
@Override @Override
public MouseEvent mouseMoved(MouseEvent mouseEvent) public MouseEvent mouseMoved(MouseEvent mouseEvent)
{ {
final Point mousePoint = mouseEvent.getPoint();
mousePosition.setLocation(mousePoint);
if (!inOverlayManagingMode) if (!inOverlayManagingMode)
{ {
return mouseEvent; return mouseEvent;
} }
final Point mousePoint = mouseEvent.getPoint();
mousePosition.setLocation(mousePoint);
if (!inOverlayResizingMode && !inOverlayDraggingMode) if (!inOverlayResizingMode && !inOverlayDraggingMode)
{ {
currentManagedOverlay = findMangedOverlay(mousePoint); currentManagedOverlay = lastHoveredOverlay;
} }
if (currentManagedOverlay == null || !currentManagedOverlay.isResizable()) if (currentManagedOverlay == null || !currentManagedOverlay.isResizable())
@@ -533,47 +500,17 @@ public class OverlayRenderer extends MouseAdapter
return mouseEvent; return mouseEvent;
} }
/**
* Find an overlay to manage which is under the given mouse point
*
* @param mousePoint
* @return
*/
private Overlay findMangedOverlay(Point mousePoint)
{
synchronized (overlayManager)
{
// render order is roughly: under -> manual -> above -> always on top
final List<OverlayLayer> layerOrder = ImmutableList.of(OverlayLayer.UNDER_WIDGETS, OverlayLayer.MANUAL, OverlayLayer.ABOVE_WIDGETS, OverlayLayer.ALWAYS_ON_TOP);
return overlayManager.getOverlays()
.stream()
// ABOVE_SCENE overlays aren't managed
.filter(c -> layerOrder.contains(c.getLayer()))
// never allow moving dynamic or tooltip overlays
.filter(c -> c.getPosition() != OverlayPosition.DYNAMIC && c.getPosition() != OverlayPosition.TOOLTIP)
.sorted(
Comparator.<Overlay>comparingInt(c -> layerOrder.indexOf(c.getLayer()))
.thenComparing(OverlayManager.OVERLAY_COMPARATOR)
// pick order is reversed from render order
.reversed()
)
.filter(o -> o.getBounds().contains(mousePoint))
.findFirst()
.orElse(null);
}
}
@Override @Override
public MouseEvent mouseDragged(MouseEvent mouseEvent) public MouseEvent mouseDragged(MouseEvent mouseEvent)
{ {
final Point p = mouseEvent.getPoint();
mousePosition.setLocation(p);
if (!inOverlayManagingMode) if (!inOverlayManagingMode)
{ {
return mouseEvent; return mouseEvent;
} }
final Point p = mouseEvent.getPoint();
mousePosition.setLocation(p);
if (currentManagedOverlay == null) if (currentManagedOverlay == null)
{ {
return mouseEvent; return mouseEvent;
@@ -708,13 +645,14 @@ public class OverlayRenderer extends MouseAdapter
@Override @Override
public MouseEvent mouseReleased(MouseEvent mouseEvent) public MouseEvent mouseReleased(MouseEvent mouseEvent)
{ {
final Point mousePoint = mouseEvent.getPoint();
mousePosition.setLocation(mousePoint);
if (!inOverlayManagingMode || currentManagedOverlay == null || (!inOverlayDraggingMode && !inOverlayResizingMode)) if (!inOverlayManagingMode || currentManagedOverlay == null || (!inOverlayDraggingMode && !inOverlayResizingMode))
{ {
return mouseEvent; return mouseEvent;
} }
mousePosition.setLocation(-1, -1);
if (dragTargetOverlay != null) if (dragTargetOverlay != null)
{ {
if (dragTargetOverlay.onDrag(currentManagedOverlay)) if (dragTargetOverlay.onDrag(currentManagedOverlay))
@@ -725,14 +663,14 @@ public class OverlayRenderer extends MouseAdapter
} }
} }
// Check if the overlay is over a snapcorner and move it if so, unless it is a detached overlay // Check if the overlay is over a snapcorner and snap it if so
if (currentManagedOverlay.getPosition() != OverlayPosition.DETACHED && inOverlayDraggingMode) if (currentManagedOverlay.isSnappable() && inOverlayDraggingMode)
{ {
final OverlayBounds snapCorners = this.emptySnapCorners.translated(-SNAP_CORNER_SIZE.width, -SNAP_CORNER_SIZE.height); final OverlayBounds snapCorners = this.emptySnapCorners.translated(-SNAP_CORNER_SIZE.width, -SNAP_CORNER_SIZE.height);
for (Rectangle snapCorner : snapCorners.getBounds()) for (Rectangle snapCorner : snapCorners.getBounds())
{ {
if (snapCorner.contains(mouseEvent.getPoint())) if (snapCorner.contains(mousePoint))
{ {
OverlayPosition position = snapCorners.fromBounds(snapCorner); OverlayPosition position = snapCorners.fromBounds(snapCorner);
@@ -756,20 +694,23 @@ public class OverlayRenderer extends MouseAdapter
return mouseEvent; return mouseEvent;
} }
private void safeRender(Client client, Overlay overlay, OverlayLayer layer, Graphics2D graphics, Point point) private Rectangle clipBounds(OverlayLayer layer)
{ {
if (!isResizeable && (layer == OverlayLayer.ABOVE_SCENE || layer == OverlayLayer.UNDER_WIDGETS)) if (!isResizeable && (layer == OverlayLayer.ABOVE_SCENE || layer == OverlayLayer.UNDER_WIDGETS))
{ {
graphics.setClip(client.getViewportXOffset(), return new Rectangle(client.getViewportXOffset(),
client.getViewportYOffset(), client.getViewportYOffset(),
client.getViewportWidth(), client.getViewportWidth(),
client.getViewportHeight()); client.getViewportHeight());
} }
else else
{ {
graphics.setClip(0, 0, client.getCanvasWidth(), client.getCanvasHeight()); return new Rectangle(0, 0, client.getCanvasWidth(), client.getCanvasHeight());
} }
}
private void safeRender(Overlay overlay, Graphics2D graphics, Point point)
{
final OverlayPosition position = overlay.getPosition(); final OverlayPosition position = overlay.getPosition();
// Set font based on configuration // Set font based on configuration

View File

@@ -213,19 +213,19 @@ public class OverlayUtil
switch (overlayPosition) switch (overlayPosition)
{ {
case BOTTOM_LEFT: case BOTTOM_LEFT:
sX = bounds.x + bounds.width + padding; sX = Math.max(sX, bounds.x + bounds.width + padding);
break; break;
case BOTTOM_RIGHT: case BOTTOM_RIGHT:
sX = bounds.x - padding; sX = Math.min(sX, bounds.x - padding);
break; break;
case TOP_LEFT: case TOP_LEFT:
case TOP_CENTER: case TOP_CENTER:
case CANVAS_TOP_RIGHT: case CANVAS_TOP_RIGHT:
case TOP_RIGHT: case TOP_RIGHT:
sY = bounds.y + bounds.height + padding; sY = Math.max(sY, bounds.y + bounds.height + padding);
break; break;
case ABOVE_CHATBOX_RIGHT: case ABOVE_CHATBOX_RIGHT:
sY = bounds.y - padding; sY = Math.min(sY, bounds.y - padding);
break; break;
default: default:
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@@ -240,8 +240,6 @@ public class OverlayUtil
switch (position) switch (position)
{ {
case DYNAMIC:
case TOOLTIP:
case TOP_LEFT: case TOP_LEFT:
break; break;
case TOP_CENTER: case TOP_CENTER:
@@ -258,6 +256,8 @@ public class OverlayUtil
case TOP_RIGHT: case TOP_RIGHT:
result.x = -dimension.width; result.x = -dimension.width;
break; break;
default:
throw new IllegalArgumentException();
} }
return result; return result;

View File

@@ -42,16 +42,16 @@ public class WidgetOverlay extends Overlay
public static Collection<WidgetOverlay> createOverlays(final OverlayManager overlayManager, final Client client) public static Collection<WidgetOverlay> createOverlays(final OverlayManager overlayManager, final Client client)
{ {
return Arrays.asList( return Arrays.asList(
// classic resizable // classic resizable - these are in render order for managed overlay picking
new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_CHATBOX_PARENT, OverlayPosition.DETACHED, OverlayPriority.HIGH), new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_CHATBOX_PARENT, OverlayPosition.DYNAMIC),
new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_CHATBOX_PARENT, OverlayPosition.DETACHED, OverlayPriority.HIGH), new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_PARENT, OverlayPosition.DYNAMIC),
new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_PARENT, OverlayPosition.DETACHED), new WidgetOverlay(client, WidgetInfo.RESIZABLE_MINIMAP_STONES_WIDGET, OverlayPosition.CANVAS_TOP_RIGHT),
new WidgetOverlay(client, WidgetInfo.RESIZABLE_MINIMAP_WIDGET, OverlayPosition.DETACHED, OverlayPriority.MED),
// modern resizable // modern resizable
new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_TABS1, OverlayPosition.DETACHED), new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_CHATBOX_PARENT, OverlayPosition.DYNAMIC),
new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_TABS2, OverlayPosition.DETACHED), new WidgetOverlay(client, WidgetInfo.RESIZABLE_MINIMAP_WIDGET, OverlayPosition.CANVAS_TOP_RIGHT),
new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_PARENT, OverlayPosition.DETACHED), new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_TABS1, OverlayPosition.DYNAMIC),
new WidgetOverlay(client, WidgetInfo.RESIZABLE_MINIMAP_STONES_WIDGET, OverlayPosition.DETACHED, OverlayPriority.MED), new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_TABS2, OverlayPosition.DYNAMIC),
new WidgetOverlay(client, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_PARENT, OverlayPosition.DYNAMIC),
// The client forces the oxygen bar below the xp tracker, so set its priority lower // The client forces the oxygen bar below the xp tracker, so set its priority lower
new WidgetOverlay(client, WidgetInfo.FOSSIL_ISLAND_OXYGENBAR, OverlayPosition.TOP_CENTER, OverlayPriority.HIGH), new WidgetOverlay(client, WidgetInfo.FOSSIL_ISLAND_OXYGENBAR, OverlayPosition.TOP_CENTER, OverlayPriority.HIGH),
new XpTrackerWidgetOverlay(overlayManager, client, WidgetInfo.EXPERIENCE_TRACKER_WIDGET, OverlayPosition.TOP_RIGHT), new XpTrackerWidgetOverlay(overlayManager, client, WidgetInfo.EXPERIENCE_TRACKER_WIDGET, OverlayPosition.TOP_RIGHT),
@@ -84,7 +84,7 @@ public class WidgetOverlay extends Overlay
new WidgetOverlay(client, WidgetInfo.TEMPOROSS_STATUS_INDICATOR, OverlayPosition.TOP_LEFT), new WidgetOverlay(client, WidgetInfo.TEMPOROSS_STATUS_INDICATOR, OverlayPosition.TOP_LEFT),
new WidgetOverlay(client, WidgetInfo.BA_HEAL_TEAMMATES, OverlayPosition.BOTTOM_LEFT), new WidgetOverlay(client, WidgetInfo.BA_HEAL_TEAMMATES, OverlayPosition.BOTTOM_LEFT),
new WidgetOverlay(client, WidgetInfo.BA_TEAM, OverlayPosition.TOP_RIGHT), new WidgetOverlay(client, WidgetInfo.BA_TEAM, OverlayPosition.TOP_RIGHT),
new WidgetOverlay(client, WidgetInfo.PVP_WILDERNESS_SKULL_CONTAINER, OverlayPosition.DETACHED) new WidgetOverlay(client, WidgetInfo.PVP_WILDERNESS_SKULL_CONTAINER, OverlayPosition.DYNAMIC)
); );
} }
@@ -105,6 +105,8 @@ public class WidgetOverlay extends Overlay
setPriority(overlayPriority); setPriority(overlayPriority);
setLayer(OverlayLayer.UNDER_WIDGETS); setLayer(OverlayLayer.UNDER_WIDGETS);
setPosition(overlayPosition); setPosition(overlayPosition);
setMovable(true);
setSnappable(true);
// It's almost possible to drawAfterInterface(widgetInfo.getGroupId()) here, but that fires // It's almost possible to drawAfterInterface(widgetInfo.getGroupId()) here, but that fires
// *after* the native components are drawn, which is too late. // *after* the native components are drawn, which is too late.
} }

View File

@@ -31,6 +31,7 @@ import java.awt.Dimension;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.List; import java.util.List;
@@ -119,10 +120,10 @@ public class WorldMapOverlay extends Overlay
bottomBar.setHasListener(true); bottomBar.setHasListener(true);
final Rectangle worldMapRectangle = widget.getBounds(); final Rectangle worldMapRectangle = widget.getBounds();
final Area mapViewArea = getWorldMapClipArea(worldMapRectangle); final Shape mapViewArea = getWorldMapClipArea(worldMapRectangle);
final Rectangle canvasBounds = new Rectangle(0, 0, client.getCanvasWidth(), client.getCanvasHeight()); final Rectangle canvasBounds = new Rectangle(0, 0, client.getCanvasWidth(), client.getCanvasHeight());
final Area canvasViewArea = getWorldMapClipArea(canvasBounds); final Shape canvasViewArea = getWorldMapClipArea(canvasBounds);
Area currentClip = null; Shape currentClip = null;
Point mousePos = client.getMouseCanvasPosition(); Point mousePos = client.getMouseCanvasPosition();
if (!mapViewArea.contains(mousePos.getX(), mousePos.getY())) if (!mapViewArea.contains(mousePos.getX(), mousePos.getY()))
@@ -297,24 +298,29 @@ public class WorldMapOverlay extends Overlay
* @return An {@link Area} representing <code>baseRectangle</code>, with the area * @return An {@link Area} representing <code>baseRectangle</code>, with the area
* of visible widgets overlaying the world map clipped from it. * of visible widgets overlaying the world map clipped from it.
*/ */
private Area getWorldMapClipArea(Rectangle baseRectangle) private Shape getWorldMapClipArea(Rectangle baseRectangle)
{ {
final Widget overview = client.getWidget(WidgetInfo.WORLD_MAP_OVERVIEW_MAP); final Widget overview = client.getWidget(WidgetInfo.WORLD_MAP_OVERVIEW_MAP);
final Widget surfaceSelector = client.getWidget(WidgetInfo.WORLD_MAP_SURFACE_SELECTOR); final Widget surfaceSelector = client.getWidget(WidgetInfo.WORLD_MAP_SURFACE_SELECTOR);
Area clipArea = new Area(baseRectangle); Area clipArea = new Area(baseRectangle);
boolean subtracted = false;
if (overview != null && !overview.isHidden()) if (overview != null && !overview.isHidden())
{ {
clipArea.subtract(new Area(overview.getBounds())); clipArea.subtract(new Area(overview.getBounds()));
subtracted = true;
} }
if (surfaceSelector != null && !surfaceSelector.isHidden()) if (surfaceSelector != null && !surfaceSelector.isHidden())
{ {
clipArea.subtract(new Area(surfaceSelector.getBounds())); clipArea.subtract(new Area(surfaceSelector.getBounds()));
subtracted = true;
} }
return clipArea; // The sun g2d implementation is much more efficient at applying clips which are subclasses of rectangle2d,
// so use that as the clip shape if possible
return subtracted ? clipArea : baseRectangle;
} }
private void drawTooltip(Graphics2D graphics, WorldMapPoint worldPoint) private void drawTooltip(Graphics2D graphics, WorldMapPoint worldPoint)
@@ -336,7 +342,7 @@ public class WorldMapOverlay extends Overlay
drawPoint = new Point(drawPoint.getX() + TOOLTIP_OFFSET_WIDTH, drawPoint.getY() + TOOLTIP_OFFSET_HEIGHT); drawPoint = new Point(drawPoint.getX() + TOOLTIP_OFFSET_WIDTH, drawPoint.getY() + TOOLTIP_OFFSET_HEIGHT);
final Rectangle bounds = new Rectangle(0, 0, client.getCanvasWidth(), client.getCanvasHeight()); final Rectangle bounds = new Rectangle(0, 0, client.getCanvasWidth(), client.getCanvasHeight());
final Area mapArea = getWorldMapClipArea(bounds); final Shape mapArea = getWorldMapClipArea(bounds);
graphics.setClip(mapArea); graphics.setClip(mapArea);
graphics.setColor(JagexColors.TOOLTIP_BACKGROUND); graphics.setColor(JagexColors.TOOLTIP_BACKGROUND);
graphics.setFont(FontManager.getRunescapeFont()); graphics.setFont(FontManager.getRunescapeFont());

View File

@@ -870,6 +870,9 @@ LABEL724:
if_icmpgt LABEL728 if_icmpgt LABEL728
jump LABEL791 jump LABEL791
LABEL728: LABEL728:
; move chatout_add under if ($length2 > 2) to only add for :: commands
get_varc_string 335
invoke 77 ; chatout_add
get_varc_string 335 get_varc_string 335
sconst "::toggleroof" sconst "::toggleroof"
iconst 0 iconst 0
@@ -962,8 +965,11 @@ LABEL798:
iload 9 iload 9
invoke 5517 invoke 5517
LABEL804: LABEL804:
; see comment above
jump AFTER_CHATOUT_ADD
get_varc_string 335 get_varc_string 335
invoke 77 invoke 77
AFTER_CHATOUT_ADD:
sconst "" sconst ""
set_varc_string 335 set_varc_string 335
LABEL808: LABEL808:
@@ -975,6 +981,8 @@ LABEL809:
jump LABEL819 jump LABEL819
LABEL813: LABEL813:
iload 3 iload 3
sconst "devtoolsEnabled"
runelite_callback
iconst 1 iconst 1
if_icmpeq LABEL817 if_icmpeq LABEL817
jump LABEL818 jump LABEL818
@@ -989,6 +997,8 @@ LABEL819:
jump LABEL829 jump LABEL829
LABEL823: LABEL823:
iload 3 iload 3
sconst "devtoolsEnabled"
runelite_callback
iconst 1 iconst 1
if_icmpeq LABEL827 if_icmpeq LABEL827
jump LABEL828 jump LABEL828