Search in sources :

Example 36 with Widget

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

the class OverlayRenderer method shouldInvalidateBounds.

private boolean shouldInvalidateBounds() {
    final Client client = clientProvider.get();
    final Widget chatbox = client.getWidget(WidgetInfo.CHATBOX_MESSAGES);
    final boolean resizeableChanged = isResizeable != client.isResized();
    boolean changed = false;
    if (resizeableChanged) {
        isResizeable = client.isResized();
        changed = true;
    }
    final boolean chatboxBoundsChanged = chatbox == null || !chatbox.getBounds().equals(chatboxBounds);
    if (chatboxBoundsChanged) {
        chatboxBounds = chatbox != null ? chatbox.getBounds() : new Rectangle();
        changed = true;
    }
    final boolean chatboxHiddenChanged = chatboxHidden != (chatbox == null || chatbox.isHidden());
    if (chatboxHiddenChanged) {
        chatboxHidden = chatbox == null || chatbox.isHidden();
        changed = true;
    }
    final boolean viewportChanged = !client.getViewportWidget().getBounds().equals(viewportBounds);
    if (viewportChanged) {
        viewportBounds = client.getViewportWidget().getBounds();
        changed = true;
    }
    return changed;
}
Also used : Widget(net.runelite.api.widgets.Widget) Rectangle(java.awt.Rectangle) Client(net.runelite.api.Client)

Example 37 with Widget

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

the class XpGlobesOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    // if this is null there is no reason to draw e.g. switching between resizable and fixed
    Widget viewportWidget = client.getViewportWidget();
    if (viewportWidget == null) {
        return null;
    }
    // check the width of the client if we can draw properly
    int clientWidth;
    switch(config.centerOrbs()) {
        case MIDDLE_CANVAS:
            clientWidth = client.getViewportWidth();
            break;
        case MIDDLE_VIEWPORT:
            clientWidth = viewportWidget.getWidth();
            break;
        case DYNAMIC:
            clientWidth = (viewportWidget.getWidth() + client.getViewportWidth()) / 2;
            break;
        default:
            clientWidth = client.getViewportWidth();
            break;
    }
    if (clientWidth <= 0) {
        return null;
    }
    int queueSize = plugin.getXpGlobesSize();
    if (queueSize > 0) {
        List<XpGlobe> xpChangedQueue = plugin.getXpGlobes();
        int markersLength = (queueSize * (config.xpOrbSize())) + ((MINIMUM_STEP) * (queueSize - 1));
        int startDrawX = (clientWidth - markersLength) / 2;
        for (XpGlobe xpGlobe : xpChangedQueue) {
            renderProgressCircle(graphics, xpGlobe, startDrawX, DEFAULT_START_Y);
            startDrawX += MINIMUM_STEP + config.xpOrbSize();
        }
    }
    return null;
}
Also used : Widget(net.runelite.api.widgets.Widget) Point(net.runelite.api.Point)

Example 38 with Widget

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

the class RSWidgetMixin method getDynamicChildren.

@Inject
@Override
public Widget[] getDynamicChildren() {
    RSWidget[] children = getChildren();
    if (children == null) {
        return new Widget[0];
    }
    List<Widget> widgets = new ArrayList<Widget>();
    for (Widget widget : children) {
        if (widget != null && widget.getParentId() == getId()) {
            widgets.add(widget);
        }
    }
    return widgets.toArray(new Widget[widgets.size()]);
}
Also used : RSWidget(net.runelite.rs.api.RSWidget) Widget(net.runelite.api.widgets.Widget) RSWidget(net.runelite.rs.api.RSWidget) ArrayList(java.util.ArrayList) Inject(net.runelite.api.mixins.Inject)

Example 39 with Widget

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

the class AttackIndicatorPluginTest method testHiddenWidget.

/*
	 * Verify that attack style widgets are hidden when filtered with the AttackIndicatorPlugin.
	 */
@Test
public void testHiddenWidget() {
    ConfigChanged warnForAttackEvent = new ConfigChanged();
    warnForAttackEvent.setGroup("attackIndicator");
    warnForAttackEvent.setKey("warnForAttack");
    warnForAttackEvent.setNewValue("true");
    attackPlugin.onConfigChanged(warnForAttackEvent);
    // Set up mock widgets for atk and str attack styles
    Widget atkWidget = mock(Widget.class);
    Widget strWidget = mock(Widget.class);
    when(client.getWidget(WidgetInfo.COMBAT_STYLE_ONE)).thenReturn(atkWidget);
    when(client.getWidget(WidgetInfo.COMBAT_STYLE_TWO)).thenReturn(strWidget);
    // Set widgets to return their hidden value in widgetsToHide when isHidden() is called
    when(atkWidget.isHidden()).thenAnswer(x -> isAtkHidden());
    when(strWidget.isHidden()).thenAnswer(x -> isStrHidden());
    // equip type_4 weapon type on player
    when(client.getSetting(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(WeaponType.TYPE_4.ordinal());
    attackPlugin.onEquippedWeaponTypeChange(new VarbitChanged());
    // Verify there is a warned skill
    Set<Skill> warnedSkills = attackPlugin.getWarnedSkills();
    assertTrue(warnedSkills.contains(Skill.ATTACK));
    // Enable hiding widgets
    ConfigChanged hideWidgetEvent = new ConfigChanged();
    hideWidgetEvent.setGroup("attackIndicator");
    hideWidgetEvent.setKey("removeWarnedStyles");
    hideWidgetEvent.setNewValue("true");
    attackPlugin.onConfigChanged(hideWidgetEvent);
    when(attackConfig.removeWarnedStyles()).thenReturn(true);
    // verify that the accurate attack style widget is hidden
    assertTrue(atkWidget.isHidden());
    // add another warned skill
    ConfigChanged warnForStrengthEvent = new ConfigChanged();
    warnForStrengthEvent.setGroup("attackIndicator");
    warnForStrengthEvent.setKey("warnForStrength");
    warnForStrengthEvent.setNewValue("true");
    attackPlugin.onConfigChanged(warnForStrengthEvent);
    // verify that the aggressive attack style widget is now hidden
    assertTrue(strWidget.isHidden());
    // disable hiding attack style widgets
    hideWidgetEvent.setGroup("attackIndicator");
    hideWidgetEvent.setKey("removeWarnedStyles");
    hideWidgetEvent.setNewValue("false");
    attackPlugin.onConfigChanged(hideWidgetEvent);
    when(attackConfig.removeWarnedStyles()).thenReturn(false);
    // verify that the aggressive and accurate attack style widgets are no longer hidden
    assertFalse(attackPlugin.getHiddenWidgets().get(WeaponType.TYPE_4, WidgetInfo.COMBAT_STYLE_ONE));
    assertFalse(attackPlugin.getHiddenWidgets().get(WeaponType.TYPE_4, WidgetInfo.COMBAT_STYLE_THREE));
}
Also used : Skill(net.runelite.api.Skill) ConfigChanged(net.runelite.api.events.ConfigChanged) Widget(net.runelite.api.widgets.Widget) VarbitChanged(net.runelite.api.events.VarbitChanged) Test(org.junit.Test)

Example 40 with Widget

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

the class ScreenshotPluginTest method testHitpoints.

@Test
public void testHitpoints() {
    Widget widget = mock(Widget.class);
    when(widget.getId()).thenReturn(PACK(LEVEL_UP_GROUP_ID, 0));
    Widget skillChild = mock(Widget.class);
    when(client.getWidget(Matchers.eq(LEVEL_UP_SKILL))).thenReturn(skillChild);
    Widget levelChild = mock(Widget.class);
    when(client.getWidget(Matchers.eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
    when(skillChild.getText()).thenReturn("Congratulations, you just advanced a Hitpoints level.");
    when(levelChild.getText()).thenReturn("Your Hitpoints are now 99.");
    assertEquals("Hitpoints(99)", screenshotPlugin.parseLevelUpWidget(LEVEL_UP_SKILL, LEVEL_UP_LEVEL));
    WidgetHiddenChanged event = new WidgetHiddenChanged();
    event.setWidget(widget);
    screenshotPlugin.hideWidgets(event);
    verify(overlayRenderer).requestScreenshot(Matchers.any(Consumer.class));
}
Also used : Consumer(java.util.function.Consumer) Widget(net.runelite.api.widgets.Widget) WidgetHiddenChanged(net.runelite.api.events.WidgetHiddenChanged) Test(org.junit.Test)

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