Slayer overlay use query idEquals, use consts (#4322)
- QueryRunner is now injected in the constructor. - Method checkInventory moved bellow the constructor. - Restructured queries inside checkInventory to utilize idEquals. - Renamed method checkInventory to getSlayerItems to better reflect the new business logic. - Removed the now unnecessary check in the render call. - Changed Set<Integer> of slayer equipment to ImmutableIntArray, and expanded it to include jewelry to prevent the necessity of repeated concat calls when calling idEquals. - Transformed allSlayer items into a static variable ALL_SLAYER_ITEMS - Changed slayerJewelry to static. - Moved static variables to start of class.
This commit is contained in:
@@ -33,6 +33,7 @@ import java.awt.Point;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import com.google.common.primitives.ImmutableIntArray;
|
||||||
import net.runelite.api.ItemID;
|
import net.runelite.api.ItemID;
|
||||||
import net.runelite.api.Query;
|
import net.runelite.api.Query;
|
||||||
import net.runelite.api.queries.EquipmentItemQuery;
|
import net.runelite.api.queries.EquipmentItemQuery;
|
||||||
@@ -48,62 +49,70 @@ import net.runelite.client.util.QueryRunner;
|
|||||||
|
|
||||||
class SlayerOverlay extends Overlay
|
class SlayerOverlay extends Overlay
|
||||||
{
|
{
|
||||||
|
private final static Set<Integer> SLAYER_JEWELRY = ImmutableSet.of(
|
||||||
|
ItemID.SLAYER_RING_1,
|
||||||
|
ItemID.SLAYER_RING_2,
|
||||||
|
ItemID.SLAYER_RING_3,
|
||||||
|
ItemID.SLAYER_RING_4,
|
||||||
|
ItemID.SLAYER_RING_5,
|
||||||
|
ItemID.SLAYER_RING_6,
|
||||||
|
ItemID.SLAYER_RING_7,
|
||||||
|
ItemID.SLAYER_RING_8
|
||||||
|
);
|
||||||
|
|
||||||
|
private final static ImmutableIntArray ALL_SLAYER_ITEMS = ImmutableIntArray.of(
|
||||||
|
ItemID.SLAYER_HELMET,
|
||||||
|
ItemID.SLAYER_HELMET_I,
|
||||||
|
ItemID.BLACK_SLAYER_HELMET,
|
||||||
|
ItemID.BLACK_SLAYER_HELMET_I,
|
||||||
|
ItemID.GREEN_SLAYER_HELMET,
|
||||||
|
ItemID.GREEN_SLAYER_HELMET_I,
|
||||||
|
ItemID.PURPLE_SLAYER_HELMET,
|
||||||
|
ItemID.PURPLE_SLAYER_HELMET_I,
|
||||||
|
ItemID.RED_SLAYER_HELMET,
|
||||||
|
ItemID.RED_SLAYER_HELMET_I,
|
||||||
|
ItemID.TURQUOISE_SLAYER_HELMET,
|
||||||
|
ItemID.TURQUOISE_SLAYER_HELMET_I,
|
||||||
|
ItemID.SLAYER_RING_ETERNAL,
|
||||||
|
ItemID.ENCHANTED_GEM,
|
||||||
|
ItemID.ETERNAL_GEM,
|
||||||
|
ItemID.BRACELET_OF_SLAUGHTER,
|
||||||
|
ItemID.EXPEDITIOUS_BRACELET,
|
||||||
|
ItemID.SLAYER_RING_1,
|
||||||
|
ItemID.SLAYER_RING_2,
|
||||||
|
ItemID.SLAYER_RING_3,
|
||||||
|
ItemID.SLAYER_RING_4,
|
||||||
|
ItemID.SLAYER_RING_5,
|
||||||
|
ItemID.SLAYER_RING_6,
|
||||||
|
ItemID.SLAYER_RING_7,
|
||||||
|
ItemID.SLAYER_RING_8
|
||||||
|
);
|
||||||
|
|
||||||
private final SlayerConfig config;
|
private final SlayerConfig config;
|
||||||
private final SlayerPlugin plugin;
|
private final SlayerPlugin plugin;
|
||||||
|
private final QueryRunner queryRunner;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private QueryRunner queryRunner;
|
private SlayerOverlay(SlayerPlugin plugin, SlayerConfig config, QueryRunner queryRunner)
|
||||||
|
|
||||||
private final Set<Integer> slayerJewelry = ImmutableSet.of(
|
|
||||||
ItemID.SLAYER_RING_1,
|
|
||||||
ItemID.SLAYER_RING_2,
|
|
||||||
ItemID.SLAYER_RING_3,
|
|
||||||
ItemID.SLAYER_RING_4,
|
|
||||||
ItemID.SLAYER_RING_5,
|
|
||||||
ItemID.SLAYER_RING_6,
|
|
||||||
ItemID.SLAYER_RING_7,
|
|
||||||
ItemID.SLAYER_RING_8
|
|
||||||
);
|
|
||||||
|
|
||||||
private final Set<Integer> slayerEquipment = ImmutableSet.of(
|
|
||||||
ItemID.SLAYER_HELMET,
|
|
||||||
ItemID.SLAYER_HELMET_I,
|
|
||||||
ItemID.BLACK_SLAYER_HELMET,
|
|
||||||
ItemID.BLACK_SLAYER_HELMET_I,
|
|
||||||
ItemID.GREEN_SLAYER_HELMET,
|
|
||||||
ItemID.GREEN_SLAYER_HELMET_I,
|
|
||||||
ItemID.PURPLE_SLAYER_HELMET,
|
|
||||||
ItemID.PURPLE_SLAYER_HELMET_I,
|
|
||||||
ItemID.RED_SLAYER_HELMET,
|
|
||||||
ItemID.RED_SLAYER_HELMET_I,
|
|
||||||
ItemID.TURQUOISE_SLAYER_HELMET,
|
|
||||||
ItemID.TURQUOISE_SLAYER_HELMET_I,
|
|
||||||
ItemID.SLAYER_RING_ETERNAL,
|
|
||||||
ItemID.ENCHANTED_GEM,
|
|
||||||
ItemID.ETERNAL_GEM,
|
|
||||||
ItemID.BRACELET_OF_SLAUGHTER,
|
|
||||||
ItemID.EXPEDITIOUS_BRACELET
|
|
||||||
);
|
|
||||||
|
|
||||||
private ImmutableList<WidgetItem> checkInventory()
|
|
||||||
{
|
|
||||||
Query inventoryQuery = new InventoryWidgetItemQuery();
|
|
||||||
WidgetItem[] inventoryWidgetItems = queryRunner.runQuery(inventoryQuery);
|
|
||||||
|
|
||||||
Query equipmentQuery = new EquipmentItemQuery().slotEquals(WidgetInfo.EQUIPMENT_HELMET, WidgetInfo.EQUIPMENT_RING, WidgetInfo.EQUIPMENT_GLOVES);
|
|
||||||
WidgetItem[] equipmentWidgetItems = queryRunner.runQuery(equipmentQuery);
|
|
||||||
|
|
||||||
WidgetItem[] items = concat(inventoryWidgetItems, equipmentWidgetItems, WidgetItem.class);
|
|
||||||
return ImmutableList.copyOf(items);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private SlayerOverlay(SlayerPlugin plugin, SlayerConfig config)
|
|
||||||
{
|
{
|
||||||
setPosition(OverlayPosition.DYNAMIC);
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.queryRunner = queryRunner;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImmutableList<WidgetItem> getSlayerItems()
|
||||||
|
{
|
||||||
|
int[] slayerItems = ALL_SLAYER_ITEMS.toArray();
|
||||||
|
Query inventoryQuery = new InventoryWidgetItemQuery().idEquals(slayerItems);
|
||||||
|
WidgetItem[] inventoryWidgetItems = queryRunner.runQuery(inventoryQuery);
|
||||||
|
|
||||||
|
Query equipmentQuery = new EquipmentItemQuery().slotEquals(WidgetInfo.EQUIPMENT_HELMET, WidgetInfo.EQUIPMENT_RING, WidgetInfo.EQUIPMENT_GLOVES).idEquals(slayerItems);
|
||||||
|
WidgetItem[] equipmentWidgetItems = queryRunner.runQuery(equipmentQuery);
|
||||||
|
|
||||||
|
WidgetItem[] items = concat(inventoryWidgetItems, equipmentWidgetItems, WidgetItem.class);
|
||||||
|
return ImmutableList.copyOf(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -125,15 +134,10 @@ class SlayerOverlay extends Overlay
|
|||||||
|
|
||||||
graphics.setFont(FontManager.getRunescapeSmallFont());
|
graphics.setFont(FontManager.getRunescapeSmallFont());
|
||||||
|
|
||||||
for (WidgetItem item : checkInventory())
|
for (WidgetItem item : getSlayerItems())
|
||||||
{
|
{
|
||||||
int itemId = item.getId();
|
int itemId = item.getId();
|
||||||
|
|
||||||
if (!slayerEquipment.contains(itemId) && !slayerJewelry.contains(itemId))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Rectangle bounds = item.getCanvasBounds();
|
final Rectangle bounds = item.getCanvasBounds();
|
||||||
final TextComponent textComponent = new TextComponent();
|
final TextComponent textComponent = new TextComponent();
|
||||||
|
|
||||||
@@ -151,7 +155,7 @@ class SlayerOverlay extends Overlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw the counter in the bottom left for equipment, and top left for jewelry
|
// Draw the counter in the bottom left for equipment, and top left for jewelry
|
||||||
textComponent.setPosition(new Point(bounds.x, bounds.y + (slayerJewelry.contains(itemId)
|
textComponent.setPosition(new Point(bounds.x, bounds.y + (SLAYER_JEWELRY.contains(itemId)
|
||||||
? bounds.height
|
? bounds.height
|
||||||
: graphics.getFontMetrics().getHeight())));
|
: graphics.getFontMetrics().getHeight())));
|
||||||
textComponent.render(graphics);
|
textComponent.render(graphics);
|
||||||
|
|||||||
Reference in New Issue
Block a user