Jump to content

Toggling Roofs Hidden


Explv

Recommended Posts

Alternative much simpler snippet provided by @Deceiver

getKeyboard().typeString("::toggleroofs");

 

 

If you still want to use the widget interaction way:

 

This makes use of my CachedWidget class: https://osbot.org/forum/topic/97399-a-better-way-to-handle-widgets-cachedwidget/

And also my WidgetActionFilter class: https://osbot.org/forum/topic/127248-widget-action-filter/

 

import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.event.Event;

public final class ToggleRoofsHiddenEvent extends Event {

    private final CachedWidget advancedOptionsWidget = new CachedWidget("Advanced options");
    private final CachedWidget displaySettingsWidget = new CachedWidget(new WidgetActionFilter("Display"));
    private final CachedWidget toggleRoofHiddenWidget = new CachedWidget(new WidgetActionFilter("Roof-removal"));

    @Override
    public final int execute() throws InterruptedException {
        if (Tab.SETTINGS.isDisabled(getBot())) {
            setFailed();
        } else if (getTabs().getOpen() != Tab.SETTINGS) {
            getTabs().open(Tab.SETTINGS);
        } else if (!advancedOptionsWidget.get(getWidgets()).isPresent()) {
            displaySettingsWidget.get(getWidgets()).ifPresent(widget -> widget.interact());
        } else if (!toggleRoofHiddenWidget.get(getWidgets()).isPresent()) {
            advancedOptionsWidget.get(getWidgets()).get().interact();
        } else if (toggleRoofHiddenWidget.get(getWidgets()).get().interact()) {
            setFinished();
        }
        return 200;
    }
}

 

Usage:

if (!getSettings().areRoofsEnabled()) {
    Event toggleRoofsHiddenEvent = new ToggleRoofsHiddenEvent();
    execute(toggleRoofsHiddenEvent);
}

 

Edited by Explv
  • Like 3
Link to comment
Share on other sites

37 minutes ago, Alek said:

There's already a CachedWidget class that I wrote two years ago though?

There is, I just wanted to write it in my own style, without passing MethodProvider as a constructor argument, with a few extra constructors, and without having to explicitly call cache() before getWidget(). I could have just extended yours, but whatever.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...