bank plugin: show bank value during searches
This also shows the value of tag tabs, since they internally are just bank searches. Co-authored-by: JZomerlei <jzomerlei@gmail.com>
This commit is contained in:
@@ -28,12 +28,9 @@ package net.runelite.client.plugins.bank;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.inject.Provides;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -48,7 +45,6 @@ import net.runelite.api.ItemID;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.ScriptID;
|
||||
import net.runelite.api.VarClientStr;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.MenuShouldLeftClick;
|
||||
@@ -78,18 +74,6 @@ import net.runelite.client.util.QuantityFormatter;
|
||||
@Slf4j
|
||||
public class BankPlugin extends Plugin
|
||||
{
|
||||
private static final List<Varbits> TAB_VARBITS = ImmutableList.of(
|
||||
Varbits.BANK_TAB_ONE_COUNT,
|
||||
Varbits.BANK_TAB_TWO_COUNT,
|
||||
Varbits.BANK_TAB_THREE_COUNT,
|
||||
Varbits.BANK_TAB_FOUR_COUNT,
|
||||
Varbits.BANK_TAB_FIVE_COUNT,
|
||||
Varbits.BANK_TAB_SIX_COUNT,
|
||||
Varbits.BANK_TAB_SEVEN_COUNT,
|
||||
Varbits.BANK_TAB_EIGHT_COUNT,
|
||||
Varbits.BANK_TAB_NINE_COUNT
|
||||
);
|
||||
|
||||
private static final String DEPOSIT_WORN = "Deposit worn items";
|
||||
private static final String DEPOSIT_INVENTORY = "Deposit inventory";
|
||||
private static final String DEPOSIT_LOOT = "Deposit loot";
|
||||
@@ -177,17 +161,6 @@ public class BankPlugin extends Plugin
|
||||
|
||||
switch (event.getEventName())
|
||||
{
|
||||
case "setBankTitle":
|
||||
final ContainerPrices prices = calculate(getBankTabItems());
|
||||
if (prices == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final String strCurrentTab = createValueText(prices);
|
||||
|
||||
stringStack[stringStackSize - 1] += strCurrentTab;
|
||||
break;
|
||||
case "bankSearchFilter":
|
||||
int itemId = intStack[intStackSize - 1];
|
||||
String search = stringStack[stringStackSize - 1];
|
||||
@@ -251,18 +224,42 @@ public class BankPlugin extends Plugin
|
||||
@Subscribe
|
||||
public void onScriptPostFired(ScriptPostFired event)
|
||||
{
|
||||
if (event.getScriptId() != ScriptID.BANKMAIN_SEARCH_REFRESH)
|
||||
if (event.getScriptId() == ScriptID.BANKMAIN_BUILD)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Compute bank prices using only the shown items so that we can show bank value during searches
|
||||
final Widget bankItemContainer = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
|
||||
final ItemContainer bankContainer = client.getItemContainer(InventoryID.BANK);
|
||||
final Widget[] children = bankItemContainer.getChildren();
|
||||
long geTotal = 0, haTotal = 0;
|
||||
|
||||
// vanilla only lays out the bank every 40 client ticks, so if the search input has changed,
|
||||
// and the bank wasn't laid out this tick, lay it out early
|
||||
final String inputText = client.getVar(VarClientStr.INPUT_TEXT);
|
||||
if (searchString != inputText && client.getGameCycle() % 40 != 0)
|
||||
log.debug("Computing bank price of {} items", bankContainer.size());
|
||||
|
||||
// The first components are the bank items, followed by tabs etc. There are always 816 components regardless
|
||||
// of bank size, but we only need to check up to the bank size.
|
||||
for (int i = 0; i < bankContainer.size(); ++i)
|
||||
{
|
||||
Widget child = children[i];
|
||||
if (child != null && !child.isSelfHidden() && child.getItemId() > -1)
|
||||
{
|
||||
final int alchPrice = getHaPrice(child.getItemId());
|
||||
geTotal += (long) itemManager.getItemPrice(child.getItemId()) * child.getItemQuantity();
|
||||
haTotal += (long) alchPrice * child.getItemQuantity();
|
||||
}
|
||||
}
|
||||
|
||||
Widget bankTitle = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
|
||||
bankTitle.setText(bankTitle.getText() + createValueText(geTotal, haTotal));
|
||||
}
|
||||
else if (event.getScriptId() == ScriptID.BANKMAIN_SEARCH_REFRESH)
|
||||
{
|
||||
clientThread.invokeLater(bankSearch::layoutBank);
|
||||
searchString = inputText;
|
||||
// vanilla only lays out the bank every 40 client ticks, so if the search input has changed,
|
||||
// and the bank wasn't laid out this tick, lay it out early
|
||||
final String inputText = client.getVar(VarClientStr.INPUT_TEXT);
|
||||
if (searchString != inputText && client.getGameCycle() % 40 != 0)
|
||||
{
|
||||
clientThread.invokeLater(bankSearch::layoutBank);
|
||||
searchString = inputText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,78 +278,50 @@ public class BankPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
private String createValueText(final ContainerPrices prices)
|
||||
private String createValueText(long gePrice, long haPrice)
|
||||
{
|
||||
final long gePrice = prices.getGePrice();
|
||||
final long haPrice = prices.getHighAlchPrice();
|
||||
|
||||
String strCurrentTab = "";
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (config.showGE() && gePrice != 0)
|
||||
{
|
||||
strCurrentTab += " (";
|
||||
stringBuilder.append(" (");
|
||||
|
||||
if (config.showHA())
|
||||
{
|
||||
strCurrentTab += "GE: ";
|
||||
stringBuilder.append("GE: ");
|
||||
}
|
||||
|
||||
if (config.showExact())
|
||||
{
|
||||
strCurrentTab += QuantityFormatter.formatNumber(gePrice) + ")";
|
||||
stringBuilder.append(QuantityFormatter.formatNumber(gePrice));
|
||||
}
|
||||
else
|
||||
{
|
||||
strCurrentTab += QuantityFormatter.quantityToStackSize(gePrice) + ")";
|
||||
stringBuilder.append(QuantityFormatter.quantityToStackSize(gePrice));
|
||||
}
|
||||
stringBuilder.append(')');
|
||||
}
|
||||
|
||||
if (config.showHA() && haPrice != 0)
|
||||
{
|
||||
strCurrentTab += " (";
|
||||
stringBuilder.append(" (");
|
||||
|
||||
if (config.showGE())
|
||||
{
|
||||
strCurrentTab += "HA: ";
|
||||
stringBuilder.append("HA: ");
|
||||
}
|
||||
|
||||
if (config.showExact())
|
||||
{
|
||||
strCurrentTab += QuantityFormatter.formatNumber(haPrice) + ")";
|
||||
stringBuilder.append(QuantityFormatter.formatNumber(haPrice));
|
||||
}
|
||||
else
|
||||
{
|
||||
strCurrentTab += QuantityFormatter.quantityToStackSize(haPrice) + ")";
|
||||
stringBuilder.append(QuantityFormatter.quantityToStackSize(haPrice));
|
||||
}
|
||||
stringBuilder.append(')');
|
||||
}
|
||||
|
||||
return strCurrentTab;
|
||||
}
|
||||
|
||||
private Item[] getBankTabItems()
|
||||
{
|
||||
final ItemContainer container = client.getItemContainer(InventoryID.BANK);
|
||||
if (container == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final Item[] items = container.getItems();
|
||||
int currentTab = client.getVar(Varbits.CURRENT_BANK_TAB);
|
||||
|
||||
if (currentTab > 0)
|
||||
{
|
||||
int startIndex = 0;
|
||||
|
||||
for (int i = currentTab - 1; i > 0; i--)
|
||||
{
|
||||
startIndex += client.getVar(TAB_VARBITS.get(i - 1));
|
||||
}
|
||||
|
||||
int itemCount = client.getVar(TAB_VARBITS.get(currentTab - 1));
|
||||
return Arrays.copyOfRange(items, startIndex, startIndex + itemCount);
|
||||
}
|
||||
|
||||
return items;
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private void updateSeedVaultTotal()
|
||||
@@ -375,8 +344,7 @@ public class BankPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
final String titleText = createValueText(prices);
|
||||
|
||||
final String titleText = createValueText(prices.getGePrice(), prices.getHighAlchPrice());
|
||||
title.setText(SEED_VAULT_TITLE + titleText);
|
||||
}
|
||||
|
||||
@@ -509,24 +477,23 @@ public class BankPlugin extends Plugin
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case ItemID.COINS_995:
|
||||
ge += qty;
|
||||
alch += qty;
|
||||
break;
|
||||
case ItemID.PLATINUM_TOKEN:
|
||||
ge += qty * 1000L;
|
||||
alch += qty * 1000L;
|
||||
break;
|
||||
default:
|
||||
final int alchPrice = itemManager.getItemComposition(id).getHaPrice();
|
||||
alch += (long) alchPrice * qty;
|
||||
ge += (long) itemManager.getItemPrice(id) * qty;
|
||||
break;
|
||||
}
|
||||
alch += (long) getHaPrice(id) * qty;
|
||||
ge += (long) itemManager.getItemPrice(id) * qty;
|
||||
}
|
||||
|
||||
return new ContainerPrices(ge, alch);
|
||||
}
|
||||
|
||||
private int getHaPrice(int itemId)
|
||||
{
|
||||
switch (itemId)
|
||||
{
|
||||
case ItemID.COINS_995:
|
||||
return 1;
|
||||
case ItemID.PLATINUM_TOKEN:
|
||||
return 1000;
|
||||
default:
|
||||
return itemManager.getItemComposition(itemId).getHaPrice();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -823,8 +823,6 @@ LABEL725:
|
||||
jump LABEL729
|
||||
LABEL726:
|
||||
sconst "The Bank of Gielinor"
|
||||
sconst "setBankTitle" ;
|
||||
runelite_callback ;
|
||||
iload 5
|
||||
if_settext
|
||||
LABEL729:
|
||||
@@ -987,8 +985,6 @@ LABEL857:
|
||||
get_varbit 4150
|
||||
enum
|
||||
join_string 2
|
||||
sconst "setBankTitle" ;
|
||||
runelite_callback ;
|
||||
iload 5
|
||||
if_settext
|
||||
jump LABEL873
|
||||
@@ -997,8 +993,6 @@ LABEL867:
|
||||
get_varbit 4150
|
||||
tostring
|
||||
join_string 2
|
||||
sconst "setBankTitle" ;
|
||||
runelite_callback ;
|
||||
iload 5
|
||||
if_settext
|
||||
FinishBuilding:
|
||||
|
||||
Reference in New Issue
Block a user