Merge pull request #990 from Kamielvf/overlay-progress-pie
Add progress pie overlay component
This commit is contained in:
@@ -24,12 +24,10 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.hunter;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
@@ -40,6 +38,7 @@ import net.runelite.api.coords.WorldPoint;
|
||||
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.components.ProgressPie;
|
||||
|
||||
/**
|
||||
* Represents the overlay that shows timers on traps that are placed by the
|
||||
@@ -47,16 +46,6 @@ import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
*/
|
||||
public class TrapOverlay extends Overlay
|
||||
{
|
||||
/**
|
||||
* Size of the trap timer.
|
||||
*/
|
||||
private static final int TIMER_SIZE = 25;
|
||||
|
||||
/**
|
||||
* Width of the border around the trap timer.
|
||||
*/
|
||||
private static final int TIMER_BORDER_WIDTH = 1;
|
||||
|
||||
/**
|
||||
* The timer is low when only 25% is left.
|
||||
*/
|
||||
@@ -158,21 +147,12 @@ public class TrapOverlay extends Overlay
|
||||
}
|
||||
net.runelite.api.Point loc = Perspective.worldToCanvas(client, localLoc.getX(), localLoc.getY(), trap.getWorldLocation().getPlane());
|
||||
|
||||
//Construct the arc
|
||||
Arc2D.Float arc = new Arc2D.Float(Arc2D.PIE);
|
||||
arc.setAngleStart(90);
|
||||
double timeLeft = 1 - trap.getTrapTimeRelative();
|
||||
arc.setAngleExtent(timeLeft * 360);
|
||||
arc.setFrame(loc.getX() - TIMER_SIZE / 2, loc.getY() - TIMER_SIZE / 2, TIMER_SIZE, TIMER_SIZE);
|
||||
|
||||
//Draw the inside of the arc
|
||||
graphics.setColor(timeLeft > TIMER_LOW ? fill : fillTimeLow);
|
||||
graphics.fill(arc);
|
||||
|
||||
//Draw the outlines of the arc
|
||||
graphics.setStroke(new BasicStroke(TIMER_BORDER_WIDTH));
|
||||
graphics.setColor(timeLeft > TIMER_LOW ? border : borderTimeLow);
|
||||
graphics.drawOval(loc.getX() - TIMER_SIZE / 2, loc.getY() - TIMER_SIZE / 2, TIMER_SIZE, TIMER_SIZE);
|
||||
ProgressPie pie = new ProgressPie();
|
||||
pie.setFill(timeLeft > TIMER_LOW ? fill : fillTimeLow);
|
||||
pie.setBorderColor(timeLeft > TIMER_LOW ? border : borderTimeLow);
|
||||
pie.render(graphics, loc, timeLeft);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,13 +176,9 @@ public class TrapOverlay extends Overlay
|
||||
}
|
||||
net.runelite.api.Point loc = Perspective.worldToCanvas(client, localLoc.getX(), localLoc.getY(), trap.getWorldLocation().getPlane());
|
||||
|
||||
//Draw the inside of the arc
|
||||
graphics.setColor(fill);
|
||||
graphics.fillOval(loc.getX() - TIMER_SIZE / 2, loc.getY() - TIMER_SIZE / 2, TIMER_SIZE, TIMER_SIZE);
|
||||
|
||||
//Draw the border of the cirlce
|
||||
graphics.setColor(border);
|
||||
graphics.setStroke(new BasicStroke(TIMER_BORDER_WIDTH));
|
||||
graphics.drawOval(loc.getX() - TIMER_SIZE / 2, loc.getY() - TIMER_SIZE / 2, TIMER_SIZE, TIMER_SIZE);
|
||||
ProgressPie pie = new ProgressPie();
|
||||
pie.setFill(fill);
|
||||
pie.setBorderColor(border);
|
||||
pie.render(graphics, loc, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Kamiel
|
||||
* 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.components;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Arc2D;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.Point;
|
||||
|
||||
|
||||
public class ProgressPie
|
||||
{
|
||||
@Setter
|
||||
private int diameter = 25;
|
||||
|
||||
@Setter
|
||||
private Color borderColor = Color.WHITE;
|
||||
|
||||
@Setter
|
||||
private Color fill = Color.WHITE;
|
||||
|
||||
@Setter
|
||||
private Stroke stroke = new BasicStroke(1);
|
||||
|
||||
public Dimension render(Graphics2D graphics, Point position, double progress)
|
||||
{
|
||||
//Construct the arc
|
||||
Arc2D.Float arc = new Arc2D.Float(Arc2D.PIE);
|
||||
arc.setAngleStart(90);
|
||||
arc.setAngleExtent(progress * 360);
|
||||
arc.setFrame(position.getX() - diameter / 2, position.getY() - diameter / 2, diameter, diameter);
|
||||
|
||||
//Draw the inside of the arc
|
||||
graphics.setColor(fill);
|
||||
graphics.fill(arc);
|
||||
|
||||
//Draw the outlines of the arc
|
||||
graphics.setStroke(stroke);
|
||||
graphics.setColor(borderColor);
|
||||
graphics.drawOval(position.getX() - diameter / 2, position.getY() - diameter / 2, diameter, diameter);
|
||||
|
||||
return new Dimension(diameter, diameter);
|
||||
}
|
||||
|
||||
public void setBorder(Color border, int size)
|
||||
{
|
||||
this.borderColor = border;
|
||||
stroke = new BasicStroke(size);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user