Bank tags: Move search functions to a separate class
This commit is contained in:
@@ -35,10 +35,8 @@ import java.awt.event.MouseWheelEvent;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.List;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.InventoryID;
|
import net.runelite.api.InventoryID;
|
||||||
@@ -64,14 +62,15 @@ import net.runelite.api.widgets.WidgetInfo;
|
|||||||
import net.runelite.client.callback.ClientThread;
|
import net.runelite.client.callback.ClientThread;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
|
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||||
import net.runelite.client.input.KeyListener;
|
import net.runelite.client.input.KeyListener;
|
||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
|
||||||
import net.runelite.client.input.MouseManager;
|
import net.runelite.client.input.MouseManager;
|
||||||
import net.runelite.client.input.MouseWheelListener;
|
import net.runelite.client.input.MouseWheelListener;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDependency;
|
import net.runelite.client.plugins.PluginDependency;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
import net.runelite.client.plugins.banktags.tabs.BankSearch;
|
||||||
import net.runelite.client.plugins.banktags.tabs.TabInterface;
|
import net.runelite.client.plugins.banktags.tabs.TabInterface;
|
||||||
import net.runelite.client.plugins.banktags.tabs.TabSprites;
|
import net.runelite.client.plugins.banktags.tabs.TabSprites;
|
||||||
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
|
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
|
||||||
@@ -123,6 +122,9 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis
|
|||||||
@Inject
|
@Inject
|
||||||
private TabInterface tabInterface;
|
private TabInterface tabInterface;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private BankSearch bankSearch;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private KeyManager keyManager;
|
private KeyManager keyManager;
|
||||||
|
|
||||||
@@ -285,7 +287,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis
|
|||||||
|
|
||||||
chatboxPanelManager.openTextInput(name + " tags:<br>(append " + VAR_TAG_SUFFIX + " for variation tag)")
|
chatboxPanelManager.openTextInput(name + " tags:<br>(append " + VAR_TAG_SUFFIX + " for variation tag)")
|
||||||
.value(initialValue)
|
.value(initialValue)
|
||||||
.onDone((newTags) ->
|
.onDone((newValue) ->
|
||||||
clientThread.invoke(() ->
|
clientThread.invoke(() ->
|
||||||
{
|
{
|
||||||
// Split inputted tags to vartags (ending with *) and regular tags
|
// Split inputted tags to vartags (ending with *) and regular tags
|
||||||
@@ -309,8 +311,8 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis
|
|||||||
|
|
||||||
if (isSearchOpen)
|
if (isSearchOpen)
|
||||||
{
|
{
|
||||||
tabInterface.doSearch(InputType.NONE, "", false);
|
bankSearch.reset(false);
|
||||||
tabInterface.doSearch(InputType.SEARCH, searchText, false);
|
bankSearch.search(InputType.SEARCH, searchText, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Ron Young <https://github.com/raiyni>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.runelite.client.plugins.banktags.tabs;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.ScriptID;
|
||||||
|
import net.runelite.api.VarClientInt;
|
||||||
|
import net.runelite.api.VarClientStr;
|
||||||
|
import net.runelite.api.vars.InputType;
|
||||||
|
import net.runelite.api.widgets.Widget;
|
||||||
|
import net.runelite.api.widgets.WidgetInfo;
|
||||||
|
import net.runelite.client.callback.ClientThread;
|
||||||
|
|
||||||
|
public class BankSearch
|
||||||
|
{
|
||||||
|
// Widget indexes for searching
|
||||||
|
private static final int INNER_CONTAINER_IDX = 2;
|
||||||
|
private static final int SETTINGS_IDX = 4;
|
||||||
|
private static final int ITEM_CONTAINER_IDX = 7;
|
||||||
|
private static final int SCROLLBAR_IDX = 8;
|
||||||
|
private static final int BOTTOM_BAR_IDX = 9;
|
||||||
|
private static final int SEARCH_BUTTON_BACKGROUND_IDX = 15;
|
||||||
|
private static final int TITLE_BAR_IDX = 16;
|
||||||
|
private static final int ITEM_COUNT_IDX = 17;
|
||||||
|
private static final int TAB_BAR_IDX = 18;
|
||||||
|
private static final int INCINERATOR_IDX = 19;
|
||||||
|
private static final int INCINERATOR_CONFIRM_IDX = 20;
|
||||||
|
private static final int HIDDEN_WIDGET_IDX = 21;
|
||||||
|
|
||||||
|
private final Client client;
|
||||||
|
private final ClientThread clientThread;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private BankSearch(
|
||||||
|
final Client client,
|
||||||
|
final ClientThread clientThread
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.client = client;
|
||||||
|
this.clientThread = clientThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void search(InputType inputType, String search, Boolean closeInput)
|
||||||
|
{
|
||||||
|
clientThread.invoke(() ->
|
||||||
|
{
|
||||||
|
Widget bankContainer = client.getWidget(WidgetInfo.BANK_CONTAINER);
|
||||||
|
if (bankContainer == null || bankContainer.isHidden())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] widgetIds = bankContainer.getOnLoadListener();
|
||||||
|
|
||||||
|
// In case the widget ids array is incorrect, do not proceed
|
||||||
|
if (widgetIds == null || widgetIds.length < 21)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// This ensures that any chatbox input (e.g from search) will not remain visible when
|
||||||
|
// selecting/changing tab
|
||||||
|
if (closeInput)
|
||||||
|
{
|
||||||
|
client.runScript(ScriptID.RESET_CHATBOX_INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.setVar(VarClientInt.INPUT_TYPE, inputType.getType());
|
||||||
|
client.setVar(VarClientStr.INPUT_TEXT, search);
|
||||||
|
|
||||||
|
client.runScript(ScriptID.BANK_LAYOUT,
|
||||||
|
WidgetInfo.BANK_CONTAINER.getId(),
|
||||||
|
widgetIds[INNER_CONTAINER_IDX],
|
||||||
|
widgetIds[SETTINGS_IDX],
|
||||||
|
widgetIds[ITEM_CONTAINER_IDX],
|
||||||
|
widgetIds[SCROLLBAR_IDX],
|
||||||
|
widgetIds[BOTTOM_BAR_IDX],
|
||||||
|
widgetIds[TITLE_BAR_IDX],
|
||||||
|
widgetIds[ITEM_COUNT_IDX],
|
||||||
|
widgetIds[SEARCH_BUTTON_BACKGROUND_IDX],
|
||||||
|
widgetIds[TAB_BAR_IDX],
|
||||||
|
widgetIds[INCINERATOR_IDX],
|
||||||
|
widgetIds[INCINERATOR_CONFIRM_IDX],
|
||||||
|
widgetIds[HIDDEN_WIDGET_IDX]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset(Boolean closeChat)
|
||||||
|
{
|
||||||
|
search(InputType.NONE, "", closeChat);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,20 +113,6 @@ public class TabInterface
|
|||||||
private static final int MARGIN = 1;
|
private static final int MARGIN = 1;
|
||||||
private static final int SCROLL_TICK = 500;
|
private static final int SCROLL_TICK = 500;
|
||||||
|
|
||||||
// Widget indexes for searching
|
|
||||||
private static final int INNER_CONTAINER_IDX = 2;
|
|
||||||
private static final int SETTINGS_IDX = 4;
|
|
||||||
private static final int ITEM_CONTAINER_IDX = 7;
|
|
||||||
private static final int SCROLLBAR_IDX = 8;
|
|
||||||
private static final int BOTTOM_BAR_IDX = 9;
|
|
||||||
private static final int SEARCH_BUTTON_BACKGROUND_IDX = 15;
|
|
||||||
private static final int TITLE_BAR_IDX = 16;
|
|
||||||
private static final int ITEM_COUNT_IDX = 17;
|
|
||||||
private static final int TAB_BAR_IDX = 18;
|
|
||||||
private static final int INCINERATOR_IDX = 19;
|
|
||||||
private static final int INCINERATOR_CONFIRM_IDX = 20;
|
|
||||||
private static final int HIDDEN_WIDGET_IDX = 21;
|
|
||||||
|
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final ClientThread clientThread;
|
private final ClientThread clientThread;
|
||||||
private final ItemManager itemManager;
|
private final ItemManager itemManager;
|
||||||
@@ -136,6 +122,7 @@ public class TabInterface
|
|||||||
private final ChatboxPanelManager chatboxPanelManager;
|
private final ChatboxPanelManager chatboxPanelManager;
|
||||||
private final BankTagsConfig config;
|
private final BankTagsConfig config;
|
||||||
private final Notifier notifier;
|
private final Notifier notifier;
|
||||||
|
private final BankSearch bankSearch;
|
||||||
private final Rectangle bounds = new Rectangle();
|
private final Rectangle bounds = new Rectangle();
|
||||||
private final Rectangle canvasBounds = new Rectangle();
|
private final Rectangle canvasBounds = new Rectangle();
|
||||||
|
|
||||||
@@ -144,7 +131,6 @@ public class TabInterface
|
|||||||
private int currentTabIndex;
|
private int currentTabIndex;
|
||||||
private TagTab iconToSet = null;
|
private TagTab iconToSet = null;
|
||||||
private Instant startScroll = Instant.now();
|
private Instant startScroll = Instant.now();
|
||||||
private Object[] widgetIds;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Widget upButton;
|
private Widget upButton;
|
||||||
@@ -168,7 +154,8 @@ public class TabInterface
|
|||||||
final TabManager tabManager,
|
final TabManager tabManager,
|
||||||
final ChatboxPanelManager chatboxPanelManager,
|
final ChatboxPanelManager chatboxPanelManager,
|
||||||
final BankTagsConfig config,
|
final BankTagsConfig config,
|
||||||
final Notifier notifier)
|
final Notifier notifier,
|
||||||
|
final BankSearch bankSearch)
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.clientThread = clientThread;
|
this.clientThread = clientThread;
|
||||||
@@ -179,6 +166,7 @@ public class TabInterface
|
|||||||
this.chatboxPanelManager = chatboxPanelManager;
|
this.chatboxPanelManager = chatboxPanelManager;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.notifier = notifier;
|
this.notifier = notifier;
|
||||||
|
this.bankSearch = bankSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive()
|
public boolean isActive()
|
||||||
@@ -193,9 +181,6 @@ public class TabInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget bankContainer = client.getWidget(WidgetInfo.BANK_CONTAINER);
|
|
||||||
widgetIds = bankContainer.getOnLoadListener();
|
|
||||||
|
|
||||||
currentTabIndex = config.position();
|
currentTabIndex = config.position();
|
||||||
parent = client.getWidget(WidgetInfo.BANK_CONTENT_CONTAINER);
|
parent = client.getWidget(WidgetInfo.BANK_CONTENT_CONTAINER);
|
||||||
|
|
||||||
@@ -346,7 +331,7 @@ public class TabInterface
|
|||||||
|
|
||||||
if (tab.equals(activeTab))
|
if (tab.equals(activeTab))
|
||||||
{
|
{
|
||||||
resetSearch();
|
bankSearch.reset(true);
|
||||||
|
|
||||||
clientThread.invokeLater(() -> client.runScript(ScriptID.RESET_CHATBOX_INPUT));
|
clientThread.invokeLater(() -> client.runScript(ScriptID.RESET_CHATBOX_INPUT));
|
||||||
}
|
}
|
||||||
@@ -599,7 +584,7 @@ public class TabInterface
|
|||||||
final ItemComposition item = getItem(event.getActionParam());
|
final ItemComposition item = getItem(event.getActionParam());
|
||||||
final int itemId = item.getId();
|
final int itemId = item.getId();
|
||||||
tagManager.removeTag(itemId, activeTab.getTag());
|
tagManager.removeTag(itemId, activeTab.getTag());
|
||||||
doSearch(InputType.SEARCH, TAG_SEARCH + activeTab.getTag());
|
bankSearch.search(InputType.SEARCH, TAG_SEARCH + activeTab.getTag(), true);
|
||||||
}
|
}
|
||||||
else if (event.getMenuAction() == MenuAction.RUNELITE
|
else if (event.getMenuAction() == MenuAction.RUNELITE
|
||||||
&& ((event.getWidgetId() == WidgetInfo.BANK_DEPOSIT_INVENTORY.getId() && event.getMenuOption().equals(TAG_INVENTORY))
|
&& ((event.getWidgetId() == WidgetInfo.BANK_DEPOSIT_INVENTORY.getId() && event.getMenuOption().equals(TAG_INVENTORY))
|
||||||
@@ -682,11 +667,6 @@ public class TabInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetSearch()
|
|
||||||
{
|
|
||||||
doSearch(InputType.NONE, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isHidden()
|
private boolean isHidden()
|
||||||
{
|
{
|
||||||
Widget widget = client.getWidget(WidgetInfo.BANK_CONTAINER);
|
Widget widget = client.getWidget(WidgetInfo.BANK_CONTAINER);
|
||||||
@@ -729,7 +709,7 @@ public class TabInterface
|
|||||||
{
|
{
|
||||||
if (activeTab != null && activeTab.getTag().equals(tag))
|
if (activeTab != null && activeTab.getTag().equals(tag))
|
||||||
{
|
{
|
||||||
resetSearch();
|
bankSearch.reset(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
tabManager.remove(tag);
|
tabManager.remove(tag);
|
||||||
@@ -926,48 +906,6 @@ public class TabInterface
|
|||||||
t.revalidate();
|
t.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doSearch(InputType inputType, String search, Boolean closeInput)
|
|
||||||
{
|
|
||||||
// In case the widget ids array is incorrect, do not proceed
|
|
||||||
if (widgetIds == null || widgetIds.length < 21)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clientThread.invoke(() ->
|
|
||||||
{
|
|
||||||
// This ensures that any chatbox input (e.g from search) will not remain visible when
|
|
||||||
// selecting/changing tab
|
|
||||||
if (closeInput)
|
|
||||||
{
|
|
||||||
client.runScript(ScriptID.RESET_CHATBOX_INPUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
client.setVar(VarClientInt.INPUT_TYPE, inputType.getType());
|
|
||||||
client.setVar(VarClientStr.INPUT_TEXT, search);
|
|
||||||
|
|
||||||
client.runScript(ScriptID.BANK_LAYOUT,
|
|
||||||
WidgetInfo.BANK_CONTAINER.getId(),
|
|
||||||
widgetIds[INNER_CONTAINER_IDX],
|
|
||||||
widgetIds[SETTINGS_IDX],
|
|
||||||
widgetIds[ITEM_CONTAINER_IDX],
|
|
||||||
widgetIds[SCROLLBAR_IDX],
|
|
||||||
widgetIds[BOTTOM_BAR_IDX],
|
|
||||||
widgetIds[TITLE_BAR_IDX],
|
|
||||||
widgetIds[ITEM_COUNT_IDX],
|
|
||||||
widgetIds[SEARCH_BUTTON_BACKGROUND_IDX],
|
|
||||||
widgetIds[TAB_BAR_IDX],
|
|
||||||
widgetIds[INCINERATOR_IDX],
|
|
||||||
widgetIds[INCINERATOR_CONFIRM_IDX],
|
|
||||||
widgetIds[HIDDEN_WIDGET_IDX]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void doSearch(InputType inputType, String search)
|
|
||||||
{
|
|
||||||
doSearch(inputType, search, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemComposition getItem(int idx)
|
private ItemComposition getItem(int idx)
|
||||||
{
|
{
|
||||||
@@ -978,7 +916,7 @@ public class TabInterface
|
|||||||
|
|
||||||
private void openTag(String tag)
|
private void openTag(String tag)
|
||||||
{
|
{
|
||||||
doSearch(InputType.SEARCH, tag);
|
bankSearch.search(InputType.SEARCH, tag, true);
|
||||||
activateTab(tabManager.find(tag.substring(TAG_SEARCH.length())));
|
activateTab(tabManager.find(tag.substring(TAG_SEARCH.length())));
|
||||||
|
|
||||||
// When tab is selected with search window open, the search window closes but the search button
|
// When tab is selected with search window open, the search window closes but the search button
|
||||||
|
|||||||
Reference in New Issue
Block a user