Search in sources :

Example 1 with Prayer

use of net.runelite.api.Prayer in project runelite by runelite.

the class ReorderPrayersPlugin method onDraggingWidgetChanged.

@Subscribe
public void onDraggingWidgetChanged(DraggingWidgetChanged event) {
    // is dragging widget and mouse button released
    if (event.isDraggingWidget() && client.getMouseCurrentButton() == 0) {
        Widget draggedWidget = client.getDraggedWidget();
        Widget draggedOnWidget = client.getDraggedOnWidget();
        if (draggedWidget != null && draggedOnWidget != null) {
            int draggedGroupId = WidgetInfo.TO_GROUP(draggedWidget.getId());
            int draggedOnGroupId = WidgetInfo.TO_GROUP(draggedOnWidget.getId());
            if (draggedGroupId != WidgetID.PRAYER_GROUP_ID || draggedOnGroupId != WidgetID.PRAYER_GROUP_ID || draggedOnWidget.getWidth() != PRAYER_WIDTH || draggedOnWidget.getHeight() != PRAYER_HEIGHT) {
                return;
            }
            // reset dragged on widget to prevent sending a drag widget packet to the server
            client.setDraggedOnWidget(null);
            int fromPrayerIndex = getPrayerIndex(draggedWidget);
            int toPrayerIndex = getPrayerIndex(draggedOnWidget);
            Prayer tmp = prayerOrder[toPrayerIndex];
            prayerOrder[toPrayerIndex] = prayerOrder[fromPrayerIndex];
            prayerOrder[fromPrayerIndex] = tmp;
            save();
        }
    }
}
Also used : Widget(net.runelite.api.widgets.Widget) Prayer(net.runelite.api.Prayer) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with Prayer

use of net.runelite.api.Prayer in project runelite by runelite.

the class ReorderPrayersPlugin method reorderPrayers.

private void reorderPrayers() {
    if (client.getGameState() != GameState.LOGGED_IN) {
        return;
    }
    PrayerTabState prayerTabState = getPrayerTabState();
    if (prayerTabState == PrayerTabState.PRAYERS) {
        List<Widget> prayerWidgets = PRAYER_WIDGET_INFO_LIST.stream().map(client::getWidget).filter(Objects::nonNull).collect(Collectors.toList());
        if (prayerWidgets.size() != PRAYER_WIDGET_INFO_LIST.size()) {
            return;
        }
        for (int index = 0; index < prayerOrder.length; index++) {
            Prayer prayer = prayerOrder[index];
            Widget prayerWidget = prayerWidgets.get(prayer.ordinal());
            int widgetConfig = prayerWidget.setClickMask();
            if (config.unlockPrayerReordering()) {
                // allow dragging of this widget
                widgetConfig |= DRAG;
                // allow this widget to be dragged on
                widgetConfig |= DRAG_ON;
            } else {
                // remove drag flag
                widgetConfig &= ~DRAG;
                // remove drag on flag
                widgetConfig &= ~DRAG_ON;
            }
            prayerWidget.setClickMask(widgetConfig);
            int x = index % PRAYER_COLUMN_COUNT;
            int y = index / PRAYER_COLUMN_COUNT;
            int widgetX = x * PRAYER_X_OFFSET;
            int widgetY = y * PRAYER_Y_OFFSET;
            setWidgetPosition(prayerWidget, widgetX, widgetY);
        }
    } else if (prayerTabState == PrayerTabState.QUICK_PRAYERS) {
        Widget prayersContainer = client.getWidget(WidgetInfo.QUICK_PRAYER_PRAYERS);
        if (prayersContainer == null) {
            return;
        }
        Widget[] prayerWidgets = prayersContainer.getDynamicChildren();
        if (prayerWidgets == null || prayerWidgets.length != PRAYER_COUNT * 3) {
            return;
        }
        for (int index = 0; index < prayerOrder.length; index++) {
            Prayer prayer = prayerOrder[index];
            int x = index % PRAYER_COLUMN_COUNT;
            int y = index / PRAYER_COLUMN_COUNT;
            Widget prayerWidget = prayerWidgets[QUICK_PRAYER_CHILD_IDS.get(prayer.ordinal())];
            setWidgetPosition(prayerWidget, x * PRAYER_X_OFFSET, y * PRAYER_Y_OFFSET);
            int childId = PRAYER_COUNT + 2 * prayer.ordinal();
            Widget prayerSpriteWidget = prayerWidgets[childId];
            setWidgetPosition(prayerSpriteWidget, QUICK_PRAYER_SPRITE_X_OFFSET + x * PRAYER_X_OFFSET, QUICK_PRAYER_SPRITE_Y_OFFSET + y * PRAYER_Y_OFFSET);
            Widget prayerToggleWidget = prayerWidgets[childId + 1];
            setWidgetPosition(prayerToggleWidget, x * PRAYER_X_OFFSET, y * PRAYER_Y_OFFSET);
        }
    }
}
Also used : Widget(net.runelite.api.widgets.Widget) Prayer(net.runelite.api.Prayer)

Aggregations

Prayer (net.runelite.api.Prayer)2 Widget (net.runelite.api.widgets.Widget)2 Subscribe (com.google.common.eventbus.Subscribe)1