Merge pull request #4429 from deathbeam/add-movable-widgets
Add support for movable RS widgets
This commit is contained in:
@@ -513,7 +513,7 @@ public class WidgetID
|
|||||||
|
|
||||||
static class ExperienceTracker
|
static class ExperienceTracker
|
||||||
{
|
{
|
||||||
static final int WIDGET = 1;
|
static final int WIDGET = 2;
|
||||||
static final int BOTTOM_BAR = 14;
|
static final int BOTTOM_BAR = 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -343,7 +343,8 @@ public enum WidgetInfo
|
|||||||
|
|
||||||
PYRAMID_PLUNDER_DATA(WidgetID.PYRAMID_PLUNDER_GROUP_ID, 0),
|
PYRAMID_PLUNDER_DATA(WidgetID.PYRAMID_PLUNDER_GROUP_ID, 0),
|
||||||
|
|
||||||
EXPERIENCE_TRACKER(WidgetID.EXPERIENCE_TRACKER_GROUP_ID, WidgetID.ExperienceTracker.WIDGET),
|
EXPERIENCE_TRACKER(WidgetID.EXPERIENCE_TRACKER_GROUP_ID, 0),
|
||||||
|
EXPERIENCE_TRACKER_WIDGET(WidgetID.EXPERIENCE_TRACKER_GROUP_ID, WidgetID.ExperienceTracker.WIDGET),
|
||||||
EXPERIENCE_TRACKER_BOTTOM_BAR(WidgetID.EXPERIENCE_TRACKER_GROUP_ID, WidgetID.ExperienceTracker.BOTTOM_BAR),
|
EXPERIENCE_TRACKER_BOTTOM_BAR(WidgetID.EXPERIENCE_TRACKER_GROUP_ID, WidgetID.ExperienceTracker.BOTTOM_BAR),
|
||||||
|
|
||||||
TITHE_FARM(WidgetID.TITHE_FARM_GROUP_ID, 1),
|
TITHE_FARM(WidgetID.TITHE_FARM_GROUP_ID, 1),
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import net.runelite.client.ui.ClientUI;
|
|||||||
import net.runelite.client.ui.DrawManager;
|
import net.runelite.client.ui.DrawManager;
|
||||||
import net.runelite.client.ui.overlay.OverlayManager;
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
import net.runelite.client.ui.overlay.OverlayRenderer;
|
import net.runelite.client.ui.overlay.OverlayRenderer;
|
||||||
|
import net.runelite.client.ui.overlay.WidgetOverlay;
|
||||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||||
import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay;
|
import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay;
|
||||||
import net.runelite.client.ui.overlay.tooltip.TooltipOverlay;
|
import net.runelite.client.ui.overlay.tooltip.TooltipOverlay;
|
||||||
@@ -260,6 +261,7 @@ public class RuneLite
|
|||||||
if (!isOutdated)
|
if (!isOutdated)
|
||||||
{
|
{
|
||||||
eventBus.register(itemManager.get());
|
eventBus.register(itemManager.get());
|
||||||
|
WidgetOverlay.createOverlays(client).forEach(overlayManager::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add core overlays after configuration has been loaded so their properties will be
|
// Add core overlays after configuration has been loaded so their properties will be
|
||||||
|
|||||||
@@ -205,9 +205,9 @@ public class OverlayRenderer extends MouseListener implements KeyListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
safeRender(client, overlay, layer, graphics, location);
|
safeRender(client, overlay, layer, graphics, location);
|
||||||
dimension.setSize(overlay.getBounds().getSize());
|
final Rectangle bounds = overlay.getBounds();
|
||||||
|
|
||||||
if (dimension.width == 0 && dimension.height == 0)
|
if (bounds.isEmpty())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ public class OverlayRenderer extends MouseListener implements KeyListener
|
|||||||
{
|
{
|
||||||
final Color previous = graphics.getColor();
|
final Color previous = graphics.getColor();
|
||||||
graphics.setColor(movedOverlay == overlay ? MOVING_OVERLAY_ACTIVE_COLOR : MOVING_OVERLAY_COLOR);
|
graphics.setColor(movedOverlay == overlay ? MOVING_OVERLAY_ACTIVE_COLOR : MOVING_OVERLAY_COLOR);
|
||||||
graphics.drawRect(location.x, location.y, dimension.width - 1, dimension.height - 1);
|
graphics.draw(bounds);
|
||||||
graphics.setColor(previous);
|
graphics.setColor(previous);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,11 +242,7 @@ public class OverlayRenderer extends MouseListener implements KeyListener
|
|||||||
{
|
{
|
||||||
if (SwingUtilities.isRightMouseButton(mouseEvent))
|
if (SwingUtilities.isRightMouseButton(mouseEvent))
|
||||||
{
|
{
|
||||||
// detached overlays have no place to reset back to
|
overlayManager.resetOverlay(overlay);
|
||||||
if (overlay.getPosition() != OverlayPosition.DETACHED)
|
|
||||||
{
|
|
||||||
overlayManager.resetOverlay(overlay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -395,7 +391,6 @@ public class OverlayRenderer extends MouseListener implements KeyListener
|
|||||||
subGraphics.setFont(FontManager.getRunescapeFont());
|
subGraphics.setFont(FontManager.getRunescapeFont());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
subGraphics.translate(point.x, point.y);
|
subGraphics.translate(point.x, point.y);
|
||||||
final Dimension dimension = MoreObjects.firstNonNull(overlay.render(subGraphics), new Dimension());
|
final Dimension dimension = MoreObjects.firstNonNull(overlay.render(subGraphics), new Dimension());
|
||||||
subGraphics.dispose();
|
subGraphics.dispose();
|
||||||
|
|||||||
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.widgets.Widget;
|
||||||
|
import net.runelite.api.widgets.WidgetInfo;
|
||||||
|
|
||||||
|
public class WidgetOverlay extends Overlay
|
||||||
|
{
|
||||||
|
private static final Set<WidgetInfo> WIDGETS = ImmutableSet.of(
|
||||||
|
WidgetInfo.RESIZABLE_MINIMAP_WIDGET,
|
||||||
|
WidgetInfo.RESIZABLE_MINIMAP_STONES_WIDGET,
|
||||||
|
WidgetInfo.EXPERIENCE_TRACKER_WIDGET
|
||||||
|
);
|
||||||
|
|
||||||
|
public static Set<WidgetOverlay> createOverlays(final Client client)
|
||||||
|
{
|
||||||
|
return WIDGETS.stream().map(w -> new WidgetOverlay(client, w)).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Client client;
|
||||||
|
private final WidgetInfo widgetInfo;
|
||||||
|
private Integer toRestoreX;
|
||||||
|
private Integer toRestoreY;
|
||||||
|
|
||||||
|
private WidgetOverlay(final Client client, final WidgetInfo widgetInfo)
|
||||||
|
{
|
||||||
|
this.client = client;
|
||||||
|
this.widgetInfo = widgetInfo;
|
||||||
|
setLayer(OverlayLayer.UNDER_WIDGETS);
|
||||||
|
setPosition(OverlayPosition.DETACHED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return Objects.toString(widgetInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rectangle getBounds()
|
||||||
|
{
|
||||||
|
final Widget widget = client.getWidget(widgetInfo);
|
||||||
|
|
||||||
|
if (widget != null && !widget.isHidden())
|
||||||
|
{
|
||||||
|
return new Rectangle(
|
||||||
|
widget.getOriginalX() + widget.getRelativeX(),
|
||||||
|
widget.getOriginalY() + widget.getRelativeY(),
|
||||||
|
widget.getWidth(), widget.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Rectangle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension render(Graphics2D graphics)
|
||||||
|
{
|
||||||
|
final Widget widget = client.getWidget(widgetInfo);
|
||||||
|
|
||||||
|
if (widget == null || widget.isHidden())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getPreferredLocation() == null)
|
||||||
|
{
|
||||||
|
if (toRestoreX != null)
|
||||||
|
{
|
||||||
|
widget.setRelativeX(toRestoreX);
|
||||||
|
toRestoreX = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toRestoreY != null)
|
||||||
|
{
|
||||||
|
widget.setRelativeY(toRestoreY);
|
||||||
|
toRestoreY = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Rectangle bounds = getBounds();
|
||||||
|
int x = getPreferredLocation().x - widget.getOriginalX();
|
||||||
|
int y = getPreferredLocation().y - widget.getOriginalY();
|
||||||
|
x = Math.max(0, x);
|
||||||
|
y = Math.max(0, y);
|
||||||
|
|
||||||
|
final Widget parent = widget.getParent();
|
||||||
|
final Dimension dimensions = parent == null ? client.getRealDimensions() : new Dimension(parent.getWidth(), parent.getHeight());
|
||||||
|
x = Math.min(dimensions.width - bounds.width, x);
|
||||||
|
y = Math.min(dimensions.height - bounds.height, y);
|
||||||
|
|
||||||
|
if (toRestoreX == null)
|
||||||
|
{
|
||||||
|
toRestoreX = widget.getRelativeX();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toRestoreY == null)
|
||||||
|
{
|
||||||
|
toRestoreY = widget.getRelativeY();
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.setRelativeX(x);
|
||||||
|
widget.setRelativeY(y);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user