banktags: use script event for detecting bank search

The bank plugin is being changed to manually initiate bank searches,
by invoking the script, and the bank tabs plugin needs to be able to
detect this search too.
This commit is contained in:
Adam
2020-11-22 11:43:18 -05:00
committed by Adam
parent 6552355fd7
commit 514995d140
2 changed files with 21 additions and 15 deletions

View File

@@ -458,7 +458,8 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
@Subscribe
public void onScriptPreFired(ScriptPreFired event)
{
if (event.getScriptId() == ScriptID.BANKMAIN_FINISHBUILDING)
int scriptId = event.getScriptId();
if (scriptId == ScriptID.BANKMAIN_FINISHBUILDING)
{
// Since we apply tag tab search filters even when the bank is not in search mode,
// bankkmain_build will reset the bank title to "The Bank of Gielinor". So apply our
@@ -476,6 +477,10 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
bankTitle.setText("Tag tab <col=ff0000>" + activeTab.getTag() + "</col>");
}
}
else if (scriptId == ScriptID.BANKMAIN_SEARCH_TOGGLE)
{
tabInterface.handleSearch();
}
}
@Subscribe

View File

@@ -347,7 +347,7 @@ public class TabInterface
final Iterator<String> dataIter = Text.fromCSV(dataString).iterator();
String name = dataIter.next();
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (char c : name.toCharArray())
{
if (FILTERED_CHARS.test(c))
@@ -369,7 +369,7 @@ public class TabInterface
while (dataIter.hasNext())
{
final int itemId = Integer.valueOf(dataIter.next());
final int itemId = Integer.parseInt(dataIter.next());
tagManager.addTag(itemId, name, itemId < 0);
}
@@ -656,16 +656,6 @@ public class TabInterface
}
if (activeTab != null
&& event.getMenuOption().equals("Search")
&& client.getWidget(WidgetInfo.BANK_SEARCH_BUTTON_BACKGROUND).getSpriteId() != SpriteID.EQUIPMENT_SLOT_SELECTED)
{
activateTab(null);
// This ensures that when clicking Search when tab is selected, the search input is opened rather
// than client trying to close it first
client.setVar(VarClientStr.INPUT_TEXT, "");
client.setVar(VarClientInt.INPUT_TYPE, 0);
}
else if (activeTab != null
&& (event.getMenuOption().startsWith("View tab") || event.getMenuOption().equals("View all items")))
{
activateTab(null);
@@ -696,6 +686,18 @@ public class TabInterface
}
}
public void handleSearch()
{
if (activeTab != null)
{
activateTab(null);
// This ensures that when clicking Search when tab is selected, the search input is opened rather
// than client trying to close it first
client.setVar(VarClientStr.INPUT_TEXT, "");
client.setVar(VarClientInt.INPUT_TYPE, 0);
}
}
public void updateTabIfActive(final Collection<String> tags)
{
if (activeTab != null && tags.contains(activeTab.getTag()))
@@ -1158,11 +1160,10 @@ public class TabInterface
t.revalidate();
}
private ItemComposition getItem(int idx)
{
ItemContainer bankContainer = client.getItemContainer(InventoryID.BANK);
Item item = bankContainer.getItems()[idx];
Item item = bankContainer.getItem(idx);
return itemManager.getItemComposition(item.getId());
}