Search in sources :

Example 31 with Widget

use of net.runelite.api.widgets.Widget in project runelite by runelite.

the class TitheFarmPlantOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    Widget viewport = client.getViewportWidget();
    for (TitheFarmPlant plant : plugin.getPlants()) {
        LocalPoint localLocation = LocalPoint.fromWorld(client, plant.getWorldLocation());
        net.runelite.api.Point canvasLocation = Perspective.worldToCanvas(client, localLocation.getX(), localLocation.getY(), client.getPlane());
        if (viewport != null && localLocation != null) {
            switch(plant.getState()) {
                case UNWATERED:
                    drawTimerOnPlant(graphics, plant, canvasLocation, config.getColorUnwatered());
                    break;
                case WATERED:
                    drawTimerOnPlant(graphics, plant, canvasLocation, config.getColorWatered());
                    break;
                case GROWN:
                    drawTimerOnPlant(graphics, plant, canvasLocation, config.getColorGrown());
                    break;
            }
        }
    }
    return null;
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) Widget(net.runelite.api.widgets.Widget)

Example 32 with Widget

use of net.runelite.api.widgets.Widget in project runelite by runelite.

the class PestControlOverlay method renderPortalWidgets.

private void renderPortalWidgets(Graphics2D graphics) {
    PortalContext purple = game.getPurple();
    PortalContext blue = game.getBlue();
    PortalContext yellow = game.getYellow();
    PortalContext red = game.getRed();
    Widget purpleShield = client.getWidget(PURPLE.getShield());
    Widget blueShield = client.getWidget(BLUE.getShield());
    Widget yellowShield = client.getWidget(YELLOW.getShield());
    Widget redShield = client.getWidget(RED.getShield());
    Widget purpleHealth = client.getWidget(PURPLE.getHitpoints());
    Widget blueHealth = client.getWidget(BLUE.getHitpoints());
    Widget yellowHealth = client.getWidget(YELLOW.getHitpoints());
    Widget redHealth = client.getWidget(RED.getHitpoints());
    assert purpleShield != null;
    assert blueShield != null;
    assert yellowShield != null;
    assert redShield != null;
    // Check for fallen portals
    if (purpleShield.isHidden()) {
        game.fall(purple);
    }
    if (blueShield.isHidden()) {
        game.fall(blue);
    }
    if (yellowShield.isHidden()) {
        game.fall(yellow);
    }
    if (redShield.isHidden()) {
        game.fall(red);
    }
    // Check for dead portals
    if (isZero(purpleHealth)) {
        game.die(purple);
    }
    if (isZero(blueHealth)) {
        game.die(blue);
    }
    if (isZero(yellowHealth)) {
        game.die(yellow);
    }
    if (isZero(redHealth)) {
        game.die(red);
    }
    // display "ATK" overlay on recorded portals without shields
    renderAttack(graphics, purple);
    renderAttack(graphics, blue);
    renderAttack(graphics, yellow);
    renderAttack(graphics, red);
    // display "NEXT" overlay on predicted portals
    for (Portal portal : game.getNextPortals()) {
        renderWidgetOverlay(graphics, portal, "NEXT", Color.ORANGE);
    }
    renderProgressWidget(graphics);
}
Also used : Widget(net.runelite.api.widgets.Widget)

Example 33 with Widget

use of net.runelite.api.widgets.Widget in project runelite by runelite.

the class PestControlOverlay method renderProgressWidget.

private void renderProgressWidget(Graphics2D graphics) {
    Widget bar = client.getWidget(WidgetInfo.PESTCONTROL_ACTIVITY_BAR).getChild(0);
    Rectangle2D bounds = bar.getBounds().getBounds2D();
    Widget prgs = client.getWidget(WidgetInfo.PESTCONTROL_ACTIVITY_PROGRESS).getChild(0);
    int perc = (int) ((prgs.getBounds().getWidth() / bounds.getWidth()) * 100);
    Color color = Color.GREEN;
    if (perc < 25) {
        color = Color.RED;
    }
    String text = String.valueOf(perc) + "%";
    FontMetrics fm = graphics.getFontMetrics();
    Rectangle2D textBounds = fm.getStringBounds(text, graphics);
    int x = (int) (bounds.getX() - textBounds.getWidth());
    int y = (int) (bounds.getY() + fm.getHeight() - 2);
    graphics.setColor(Color.BLACK);
    graphics.drawString(text, x + 1, y + 1);
    graphics.setColor(color);
    graphics.drawString(text, x, y);
}
Also used : FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Widget(net.runelite.api.widgets.Widget) Rectangle2D(java.awt.geom.Rectangle2D)

Example 34 with Widget

use of net.runelite.api.widgets.Widget in project runelite by runelite.

the class PrayerFlickOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    if (// If there are no prayers active we don't need to be flicking
    !prayersActive) {
        return null;
    }
    Widget xpOrb = client.getWidget(WidgetInfo.QUICK_PRAYER_ORB);
    if (xpOrb == null) {
        return null;
    }
    Rectangle2D bounds = xpOrb.getBounds().getBounds2D();
    if (bounds.getX() <= 0) {
        return null;
    }
    // Purposefully using height twice here as the bounds of the prayer orb includes the number sticking out the side
    int orbInnerHeight = (int) bounds.getHeight();
    int orbInnerWidth = orbInnerHeight;
    // x pos of the inside of the prayer orb
    int orbInnerX = (int) (bounds.getX() + 24);
    // y pos of the inside of the prayer orb
    int orbInnerY = (int) (bounds.getY() - 1);
    long timeSinceLastTick = Duration.between(startOfLastTick, Instant.now()).toMillis();
    float tickProgress = timeSinceLastTick / 600f;
    // Cap to 1, so if a tick continues past the expected 600 we don't move the indicator off the orb
    tickProgress = Math.min(tickProgress, 1);
    // t on interval [0,pi]
    double t = tickProgress * Math.PI;
    int xOffset = (int) (-Math.cos(t) * orbInnerWidth / 2) + orbInnerWidth / 2;
    int indicatorHeight = (int) (Math.sin(t) * orbInnerHeight);
    int yOffset = (orbInnerHeight / 2) - (indicatorHeight / 2);
    graphics.setColor(Color.cyan);
    graphics.fillRect(orbInnerX + xOffset, orbInnerY + yOffset, 1, indicatorHeight);
    return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight());
}
Also used : Widget(net.runelite.api.widgets.Widget) Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension)

Example 35 with Widget

use of net.runelite.api.widgets.Widget in project runelite by runelite.

the class TitheFarmSackOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    Widget sack = client.getWidget(WidgetInfo.TITHE_FARM);
    if (sack == null) {
        return null;
    }
    panelComponent.getLines().clear();
    sack.setHidden(true);
    if (config.showSack()) {
        panelComponent.getLines().add(new PanelComponent.Line("Fruits in sack:", String.valueOf(client.getSetting(Varbits.TITHE_FARM_SACK_AMOUNT))));
        panelComponent.getLines().add(new PanelComponent.Line("Points:", String.valueOf(client.getSetting(Varbits.TITHE_FARM_POINTS))));
    }
    return panelComponent.render(graphics);
}
Also used : Widget(net.runelite.api.widgets.Widget) PanelComponent(net.runelite.client.ui.overlay.components.PanelComponent)

Aggregations

Widget (net.runelite.api.widgets.Widget)56 Rectangle (java.awt.Rectangle)10 WidgetItem (net.runelite.api.widgets.WidgetItem)10 ArrayList (java.util.ArrayList)9 Subscribe (com.google.common.eventbus.Subscribe)7 Inject (net.runelite.api.mixins.Inject)6 RSWidget (net.runelite.rs.api.RSWidget)6 Point (net.runelite.api.Point)5 WidgetHiddenChanged (net.runelite.api.events.WidgetHiddenChanged)5 PanelComponent (net.runelite.client.ui.overlay.components.PanelComponent)5 Test (org.junit.Test)5 FontMetrics (java.awt.FontMetrics)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Consumer (java.util.function.Consumer)4 LocalPoint (net.runelite.api.coords.LocalPoint)4 ItemComposition (net.runelite.api.ItemComposition)3 WidgetInfo (net.runelite.api.widgets.WidgetInfo)3 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 Matcher (java.util.regex.Matcher)2