inventsetups: upstream merge (#2277)

inventsetups: upstream merge (#2277)
This commit is contained in:
Kyle
2020-01-26 16:52:59 +00:00
committed by GitHub
parent 014d1f095c
commit c4ecf95a3d
8 changed files with 155 additions and 29 deletions

View File

@@ -29,6 +29,7 @@ import net.runelite.client.config.Alpha;
import net.runelite.client.config.Config; import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Keybind;
@ConfigGroup(InventorySetupPlugin.CONFIG_GROUP) @ConfigGroup(InventorySetupPlugin.CONFIG_GROUP)
public interface InventorySetupConfig extends Config public interface InventorySetupConfig extends Config
@@ -99,4 +100,26 @@ public interface InventorySetupConfig extends Config
{ {
return Color.RED; return Color.RED;
} }
@ConfigItem(
keyName = "returnToSetupsHotkey",
name = "Return To Setups Hotkey",
description = "Configures the hotkey for returning to setups",
position = 6
)
default Keybind returnToSetupsHotkey()
{
return Keybind.NOT_SET;
}
@ConfigItem(
keyName = "filterBankHotkey",
name = "Filter Bank Hotkey",
description = "Configures the hotkey for filtering the bank",
position = 7
)
default Keybind filterBankHotkey()
{
return Keybind.NOT_SET;
}
} }

View File

@@ -46,13 +46,13 @@ import net.runelite.api.Varbits;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.ItemContainerChanged; import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.ScriptCallbackEvent; import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.events.WidgetLoaded; import net.runelite.api.events.VarClientIntChanged;
import net.runelite.api.vars.InputType; import net.runelite.api.vars.InputType;
import net.runelite.api.widgets.WidgetID;
import net.runelite.client.account.AccountSession; import net.runelite.client.account.AccountSession;
import net.runelite.client.account.SessionManager; import net.runelite.client.account.SessionManager;
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.config.Keybind;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.SessionClose; import net.runelite.client.events.SessionClose;
import net.runelite.client.events.SessionOpen; import net.runelite.client.events.SessionOpen;
@@ -61,6 +61,7 @@ import net.runelite.client.game.ItemVariationMapping;
import net.runelite.client.game.chatbox.ChatboxItemSearch; import net.runelite.client.game.chatbox.ChatboxItemSearch;
import net.runelite.client.game.chatbox.ChatboxPanelManager; import net.runelite.client.game.chatbox.ChatboxPanelManager;
import net.runelite.client.game.chatbox.ChatboxTextInput; import net.runelite.client.game.chatbox.ChatboxTextInput;
import net.runelite.client.input.KeyManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
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.BankSearch;
@@ -68,6 +69,7 @@ import net.runelite.client.plugins.runepouch.Runes;
import net.runelite.client.ui.ClientToolbar; import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton; import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.components.colorpicker.ColorPickerManager; import net.runelite.client.ui.components.colorpicker.ColorPickerManager;
import net.runelite.client.util.HotkeyListener;
import net.runelite.client.util.ImageUtil; import net.runelite.client.util.ImageUtil;
import javax.inject.Inject; import javax.inject.Inject;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@@ -79,6 +81,7 @@ import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@PluginDescriptor( @PluginDescriptor(
@@ -130,6 +133,8 @@ public class InventorySetupPlugin extends Plugin
@Inject @Inject
private BankSearch bankSearch; private BankSearch bankSearch;
@Inject @Inject
private KeyManager keyManager;
@Inject
private ChatboxItemSearch itemSearch; private ChatboxItemSearch itemSearch;
@Inject @Inject
private ChatboxPanelManager chatboxPanelManager; private ChatboxPanelManager chatboxPanelManager;
@@ -141,6 +146,41 @@ public class InventorySetupPlugin extends Plugin
private boolean highlightUnorderedDifference; private boolean highlightUnorderedDifference;
private boolean highlightDifference; private boolean highlightDifference;
private Color highlightColor; private Color highlightColor;
private Keybind returnToSetupsHotkey;
private Keybind filterBankHotkey;
private final HotkeyListener returnToSetupsHotkeyListener = new HotkeyListener(() -> this.returnToSetupsHotkey)
{
@Override
public void hotkeyPressed()
{
panel.returnToOverviewPanel();
}
};
private final HotkeyListener filterBankHotkeyListener = new HotkeyListener(() -> this.filterBankHotkey)
{
@Override
public void hotkeyPressed()
{
// you must wait at least one game tick otherwise
// the bank filter will work but then go back to the previous tab.
// For some reason this can still happen but it is very rare,
// and only when the user clicks a tab and the hot key extremely shortly after.
int gameTick = client.getTickCount();
clientThread.invokeLater(() ->
{
int gameTick2 = client.getTickCount();
if (gameTick2 <= gameTick)
{
return false;
}
doBankSearch();
return true;
});
}
};
@Provides @Provides
InventorySetupConfig getConfig(ConfigManager configManager) InventorySetupConfig getConfig(ConfigManager configManager)
@@ -164,6 +204,8 @@ public class InventorySetupPlugin extends Plugin
.build(); .build();
clientToolbar.addNavigation(navButton); clientToolbar.addNavigation(navButton);
keyManager.registerKeyListener(returnToSetupsHotkeyListener);
keyManager.registerKeyListener(filterBankHotkeyListener);
// load all the inventory setups from the config file // load all the inventory setups from the config file
clientThread.invokeLater(() -> clientThread.invokeLater(() ->
@@ -237,15 +279,12 @@ public class InventorySetupPlugin extends Plugin
updateConfig(); updateConfig();
} }
@Subscribe public List<InventorySetup> filterSetups(String textToFilter)
public void onWidgetLoaded(WidgetLoaded event)
{ {
if (event.getGroupId() != WidgetID.BANK_GROUP_ID) final String textToFilterLower = textToFilter.toLowerCase();
{ return inventorySetups.stream()
return; .filter(i -> i.getName().toLowerCase().contains(textToFilterLower))
} .collect(Collectors.toList());
doBankSearch();
} }
public void doBankSearch() public void doBankSearch()
@@ -259,6 +298,26 @@ public class InventorySetupPlugin extends Plugin
} }
} }
@Subscribe
public void onVarClientIntChanged(VarClientIntChanged event)
{
if (event.getIndex() != 386)
{
return;
}
// must be invoked later otherwise causes freezing.
clientThread.invokeLater(() ->
{
// checks to see if the hide worn items button was clicked or bank was opened
int value = client.getVarcIntValue(386);
if (value == 0)
{
doBankSearch();
}
});
}
public void resetBankSearch() public void resetBankSearch()
{ {
bankSearch.reset(true); bankSearch.reset(true);
@@ -877,6 +936,8 @@ public class InventorySetupPlugin extends Plugin
this.highlightUnorderedDifference = config.highlightUnorderedDifference(); this.highlightUnorderedDifference = config.highlightUnorderedDifference();
this.highlightDifference = config.highlightDifference(); this.highlightDifference = config.highlightDifference();
this.highlightColor = config.highlightColor(); this.highlightColor = config.highlightColor();
this.returnToSetupsHotkey = config.returnToSetupsHotkey();
this.filterBankHotkey = config.filterBankHotkey();
} }
} }

View File

@@ -138,7 +138,7 @@ public abstract class InventorySetupContainerPanel extends JPanel
break; break;
} }
assert index < items.size() && index > 0 : "Index Off Array"; assert index < items.size() && index >= 0 : "Index Off Array";
containerSlot.setParentSetup(setup); containerSlot.setParentSetup(setup);

View File

@@ -212,6 +212,7 @@ public class InventorySetupPanel extends JPanel
nameInput.setEditable(false); nameInput.setEditable(false);
updateNameActions(false); updateNameActions(false);
requestFocusInWindow(); requestFocusInWindow();
panel.rebuild();
} }
@Override @Override

View File

@@ -32,6 +32,7 @@ import net.runelite.api.InventoryID;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.PluginPanel; import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.IconTextField;
import net.runelite.client.ui.components.PluginErrorPanel; import net.runelite.client.ui.components.PluginErrorPanel;
import net.runelite.client.util.ImageUtil; import net.runelite.client.util.ImageUtil;
import javax.swing.Box; import javax.swing.Box;
@@ -47,10 +48,13 @@ import java.awt.Dimension;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class InventorySetupPluginPanel extends PluginPanel public class InventorySetupPluginPanel extends PluginPanel
{ {
@@ -81,8 +85,8 @@ public class InventorySetupPluginPanel extends PluginPanel
UPDATE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(updateIcon, 0.53f)); UPDATE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(updateIcon, 0.53f));
final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(InventorySetupPlugin.class, "back_arrow_icon.png"); final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(InventorySetupPlugin.class, "back_arrow_icon.png");
BACK_ICON = new ImageIcon(ImageUtil.flipImage(backIcon, true, false)); BACK_ICON = new ImageIcon(backIcon);
BACK_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(ImageUtil.flipImage(backIcon, true, false), 0.53f)); BACK_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(backIcon, 0.53f));
MAIN_TITLE = "Inventory Setups"; MAIN_TITLE = "Inventory Setups";
} }
@@ -98,6 +102,7 @@ public class InventorySetupPluginPanel extends PluginPanel
private final JLabel addImportMarker; private final JLabel addImportMarker;
private final JLabel updateMarker; private final JLabel updateMarker;
private final JLabel backMarker; private final JLabel backMarker;
private final IconTextField searchBar;
private final InventorySetupInventoryPanel invPanel; private final InventorySetupInventoryPanel invPanel;
private final InventorySetupEquipmentPanel eqpPanel; private final InventorySetupEquipmentPanel eqpPanel;
private final InventorySetupRunePouchPanel rpPanel; private final InventorySetupRunePouchPanel rpPanel;
@@ -199,14 +204,7 @@ public class InventorySetupPluginPanel extends PluginPanel
@Override @Override
public void mousePressed(MouseEvent e) public void mousePressed(MouseEvent e)
{ {
noSetupsPanel.setVisible(false); returnToOverviewPanel();
invEqPanel.setVisible(false);
overviewPanel.setVisible(true);
overviewTopRightButtonsPanel.setVisible(true);
setupTopRightButtonsPanel.setVisible(false);
title.setText(MAIN_TITLE);
currentSelectedSetup = null;
plugin.resetBankSearch();
} }
@Override @Override
@@ -222,13 +220,15 @@ public class InventorySetupPluginPanel extends PluginPanel
} }
}); });
this.overviewTopRightButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 0)); this.overviewTopRightButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
overviewTopRightButtonsPanel.add(addImportMarker); overviewTopRightButtonsPanel.add(addImportMarker);
overviewTopRightButtonsPanel.add(addMarker); overviewTopRightButtonsPanel.add(addMarker);
addMarker.setBorder(new EmptyBorder(0, 8, 0, 0));
this.setupTopRightButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 0)); this.setupTopRightButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
setupTopRightButtonsPanel.add(updateMarker); setupTopRightButtonsPanel.add(updateMarker);
setupTopRightButtonsPanel.add(backMarker); setupTopRightButtonsPanel.add(backMarker);
backMarker.setBorder(new EmptyBorder(0, 8, 0, 0));
// the panel on the top right that holds the buttons // the panel on the top right that holds the buttons
final JPanel markersPanel = new JPanel(); final JPanel markersPanel = new JPanel();
@@ -238,11 +238,36 @@ public class InventorySetupPluginPanel extends PluginPanel
overviewTopRightButtonsPanel.setVisible(true); overviewTopRightButtonsPanel.setVisible(true);
setupTopRightButtonsPanel.setVisible(false); setupTopRightButtonsPanel.setVisible(false);
// the top panel that has the title and the buttons // the top panel that has the title and the buttons, and search bar
final JPanel titleAndMarkersPanel = new JPanel(); final JPanel titleAndMarkersPanel = new JPanel();
titleAndMarkersPanel.setLayout(new BorderLayout()); titleAndMarkersPanel.setLayout(new BorderLayout());
titleAndMarkersPanel.add(title, BorderLayout.WEST); titleAndMarkersPanel.add(title, BorderLayout.WEST);
titleAndMarkersPanel.add(markersPanel, BorderLayout.EAST); titleAndMarkersPanel.add(markersPanel, BorderLayout.EAST);
this.searchBar = new IconTextField();
searchBar.setIcon(IconTextField.Icon.SEARCH);
searchBar.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH - 20, 30));
searchBar.setBackground(ColorScheme.DARKER_GRAY_COLOR);
searchBar.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR);
searchBar.setMinimumSize(new Dimension(0, 30));
searchBar.addKeyListener(new KeyListener()
{
@Override
public void keyTyped(KeyEvent e)
{
}
@Override
public void keyPressed(KeyEvent e)
{
}
@Override
public void keyReleased(KeyEvent e)
{
rebuild();
}
});
searchBar.addClearListener(actionEvent -> rebuild());
// the panel that stays at the top and doesn't scroll // the panel that stays at the top and doesn't scroll
// contains the title and buttons // contains the title and buttons
@@ -250,7 +275,8 @@ public class InventorySetupPluginPanel extends PluginPanel
northAnchoredPanel.setLayout(new BoxLayout(northAnchoredPanel, BoxLayout.Y_AXIS)); northAnchoredPanel.setLayout(new BoxLayout(northAnchoredPanel, BoxLayout.Y_AXIS));
northAnchoredPanel.setBorder(new EmptyBorder(0, 0, 10, 0)); northAnchoredPanel.setBorder(new EmptyBorder(0, 0, 10, 0));
northAnchoredPanel.add(titleAndMarkersPanel); northAnchoredPanel.add(titleAndMarkersPanel);
northAnchoredPanel.add(Box.createRigidArea(new Dimension(0, 10))); northAnchoredPanel.add(Box.createRigidArea(new Dimension(0, 5)));
northAnchoredPanel.add(searchBar);
// the panel that holds the inventory and equipment panels // the panel that holds the inventory and equipment panels
final BoxLayout invEqLayout = new BoxLayout(invEqPanel, BoxLayout.Y_AXIS); final BoxLayout invEqLayout = new BoxLayout(invEqPanel, BoxLayout.Y_AXIS);
@@ -292,7 +318,7 @@ public class InventorySetupPluginPanel extends PluginPanel
} }
public void init() public void init(List<InventorySetup> setups)
{ {
overviewPanel.setLayout(new GridBagLayout()); overviewPanel.setLayout(new GridBagLayout());
overviewPanel.setBackground(ColorScheme.DARK_GRAY_COLOR); overviewPanel.setBackground(ColorScheme.DARK_GRAY_COLOR);
@@ -303,7 +329,7 @@ public class InventorySetupPluginPanel extends PluginPanel
constraints.gridx = 0; constraints.gridx = 0;
constraints.gridy = 0; constraints.gridy = 0;
for (final InventorySetup setup : plugin.getInventorySetups()) for (final InventorySetup setup : setups)
{ {
InventorySetupPanel newPanel = new InventorySetupPanel(plugin, this, setup); InventorySetupPanel newPanel = new InventorySetupPanel(plugin, this, setup);
overviewPanel.add(newPanel, constraints); overviewPanel.add(newPanel, constraints);
@@ -323,7 +349,9 @@ public class InventorySetupPluginPanel extends PluginPanel
public void rebuild() public void rebuild()
{ {
overviewPanel.removeAll(); overviewPanel.removeAll();
init(); final String text = searchBar.getText();
List<InventorySetup> setupsToAdd = searchBar.getText().isEmpty() ? plugin.getInventorySetups() : plugin.filterSetups(searchBar.getText());
init(setupsToAdd);
revalidate(); revalidate();
repaint(); repaint();
} }
@@ -351,6 +379,7 @@ public class InventorySetupPluginPanel extends PluginPanel
overviewPanel.setVisible(false); overviewPanel.setVisible(false);
title.setText(inventorySetup.getName()); title.setText(inventorySetup.getName());
searchBar.setVisible(false);
// only show the rune pouch if the setup has a rune pouch // only show the rune pouch if the setup has a rune pouch
rpPanel.setVisible(currentSelectedSetup.getRune_pouch() != null); rpPanel.setVisible(currentSelectedSetup.getRune_pouch() != null);
@@ -411,4 +440,16 @@ public class InventorySetupPluginPanel extends PluginPanel
eqpPanel.highlightSlotDifferences(eqp, currentSelectedSetup); eqpPanel.highlightSlotDifferences(eqp, currentSelectedSetup);
} }
public void returnToOverviewPanel()
{
noSetupsPanel.setVisible(false);
invEqPanel.setVisible(false);
overviewPanel.setVisible(true);
overviewTopRightButtonsPanel.setVisible(true);
setupTopRightButtonsPanel.setVisible(false);
title.setText(MAIN_TITLE);
currentSelectedSetup = null;
searchBar.setVisible(true);
plugin.resetBankSearch();
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 B

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 B

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 B

After

Width:  |  Height:  |  Size: 188 B