use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.
the class BankCalculation method isBankDifferent.
private boolean isBankDifferent(WidgetItem[] widgetItems) {
Map<Integer, Integer> mapCheck = new HashMap<>();
for (WidgetItem widgetItem : widgetItems) {
mapCheck.put(widgetItem.getId(), widgetItem.getQuantity());
}
int curHash = mapCheck.hashCode();
if (curHash != itemsHash) {
itemsHash = curHash;
return true;
}
return false;
}
use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.
the class BankCalculation method calculate.
/**
* Calculate the bank based on the cache, price can be 0 if bank not active, or cache not set
*/
void calculate() {
Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
// Don't update on a search because rs seems to constantly update the title
if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden() || widgetBankTitleBar.getText().contains("Showing")) {
return;
}
WidgetItem[] widgetItems = new BankItemQuery().result(client);
if (widgetItems.length == 0 || !isBankDifferent(widgetItems)) {
return;
}
log.debug("Calculating new bank value...");
gePrice = haPrice = 0;
finished = false;
List<ItemComposition> itemCompositions = new ArrayList<>();
Map<Integer, WidgetItem> itemMap = new HashMap<>();
List<Integer> itemIds = new ArrayList<>();
// Generate our lists (and do some quick price additions)
for (WidgetItem widgetItem : widgetItems) {
if (widgetItem.getId() <= 0 || widgetItem.getQuantity() == 0) {
continue;
}
if (widgetItem.getId() == COINS_995) {
gePrice += widgetItem.getQuantity();
haPrice += widgetItem.getQuantity();
continue;
}
if (widgetItem.getId() == PLATINUM_TOKEN) {
gePrice += widgetItem.getQuantity() * 1000;
haPrice += widgetItem.getQuantity() * 1000;
continue;
}
ItemComposition itemComposition = itemManager.getItemComposition(widgetItem.getId());
itemCompositions.add(itemComposition);
itemMap.put(widgetItem.getId(), widgetItem);
if (config.showGE()) {
itemIds.add(widgetItem.getId());
}
}
// Now do the calculations
if (config.showGE() && !itemIds.isEmpty()) {
CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(itemIds);
future.whenComplete((ItemPrice[] itemPrices, Throwable ex) -> {
if (ex != null) {
log.debug("Error looking up item prices", ex);
return;
}
if (itemPrices == null) {
log.debug("Error looking up item prices");
return;
}
log.debug("Price lookup is complete. {} prices.", itemPrices.length);
try {
for (ItemPrice itemPrice : itemPrices) {
if (itemPrice.getItem() == null) {
// cached no price
continue;
}
gePrice += itemPrice.getPrice() * itemMap.get(itemPrice.getItem().getId()).getQuantity();
}
} catch (Exception ex2) {
log.warn("error calculating price", ex2);
} finally {
finished = true;
}
});
} else {
finished = true;
}
if (config.showHA()) {
for (ItemComposition itemComposition : itemCompositions) {
int price = itemComposition.getPrice();
if (price > 0) {
haPrice += Math.round(price * HIGH_ALCHEMY_CONSTANT) * itemMap.get(itemComposition.getId()).getQuantity();
}
}
}
}
use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.
the class DevToolsOverlay method renderWidgets.
public void renderWidgets(Graphics2D graphics) {
Widget widget = plugin.currentWidget;
int itemIndex = plugin.itemIndex;
if (widget == null || widget.isHidden()) {
return;
}
Rectangle childBounds = widget.getBounds();
graphics.setColor(CYAN);
graphics.draw(childBounds);
if (itemIndex == -1) {
return;
}
if (widget.getItemId() != ITEM_EMPTY && widget.getItemId() != ITEM_FILLED) {
Rectangle componentBounds = widget.getBounds();
graphics.setColor(ORANGE);
graphics.draw(componentBounds);
renderWidgetText(graphics, componentBounds, widget.getItemId(), YELLOW);
}
WidgetItem widgetItem = widget.getWidgetItem(itemIndex);
if (widgetItem == null || widgetItem.getId() == ITEM_EMPTY || widgetItem.getId() == ITEM_FILLED) {
return;
}
Rectangle itemBounds = widgetItem.getCanvasBounds();
graphics.setColor(ORANGE);
graphics.draw(itemBounds);
renderWidgetText(graphics, itemBounds, widgetItem.getId(), YELLOW);
}
use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.
the class WidgetInspector method addWidget.
private DefaultMutableTreeNode addWidget(String type, Widget widget) {
if (widget == null || widget.isHidden()) {
return null;
}
DefaultMutableTreeNode node = new WidgetTreeNode(type, widget);
Widget[] childComponents = widget.getDynamicChildren();
if (childComponents != null) {
for (Widget component : childComponents) {
DefaultMutableTreeNode childNode = addWidget("D", component);
if (childNode != null) {
node.add(childNode);
}
}
}
childComponents = widget.getStaticChildren();
if (childComponents != null) {
for (Widget component : childComponents) {
DefaultMutableTreeNode childNode = addWidget("S", component);
if (childNode != null) {
node.add(childNode);
}
}
}
childComponents = widget.getNestedChildren();
if (childComponents != null) {
for (Widget component : childComponents) {
DefaultMutableTreeNode childNode = addWidget("N", component);
if (childNode != null) {
node.add(childNode);
}
}
}
Collection<WidgetItem> items = widget.getWidgetItems();
if (items != null) {
for (WidgetItem item : items) {
if (item == null) {
continue;
}
node.add(new WidgetItemNode(item));
}
}
return node;
}
use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.
the class SlayerOverlay method getSlayerWidgetItems.
private Collection<WidgetItem> getSlayerWidgetItems() {
Query inventoryQuery = new InventoryWidgetItemQuery();
WidgetItem[] inventoryWidgetItems = queryRunner.runQuery(inventoryQuery);
Query equipmentQuery = new EquipmentItemQuery().slotEquals(WidgetInfo.EQUIPMENT_HELMET, WidgetInfo.EQUIPMENT_RING);
WidgetItem[] equipmentWidgetItems = queryRunner.runQuery(equipmentQuery);
WidgetItem[] items = concat(inventoryWidgetItems, equipmentWidgetItems, WidgetItem.class);
return ImmutableList.copyOf(items);
}
Aggregations