From c4ecf95a3d89aab4bbcac2541de9c77e5f44c657 Mon Sep 17 00:00:00 2001 From: Kyle <48519776+xKylee@users.noreply.github.com> Date: Sun, 26 Jan 2020 16:52:59 +0000 Subject: [PATCH] inventsetups: upstream merge (#2277) inventsetups: upstream merge (#2277) --- .../inventorysetups/InventorySetupConfig.java | 23 +++++ .../inventorysetups/InventorySetupPlugin.java | 81 +++++++++++++++--- .../ui/InventorySetupContainerPanel.java | 2 +- .../ui/InventorySetupPanel.java | 1 + .../ui/InventorySetupPluginPanel.java | 77 +++++++++++++---- .../plugins/inventorysetups/add_icon.png | Bin 121 -> 114 bytes .../inventorysetups/back_arrow_icon.png | Bin 146 -> 145 bytes .../plugins/inventorysetups/import_icon.png | Bin 181 -> 188 bytes 8 files changed, 155 insertions(+), 29 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/InventorySetupConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/InventorySetupConfig.java index 4e64a10019..6c14ff0c4e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/InventorySetupConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/InventorySetupConfig.java @@ -29,6 +29,7 @@ import net.runelite.client.config.Alpha; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; +import net.runelite.client.config.Keybind; @ConfigGroup(InventorySetupPlugin.CONFIG_GROUP) public interface InventorySetupConfig extends Config @@ -99,4 +100,26 @@ public interface InventorySetupConfig extends Config { 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; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/InventorySetupPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/InventorySetupPlugin.java index 5302b0703a..35a27d439f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/InventorySetupPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/InventorySetupPlugin.java @@ -46,13 +46,13 @@ import net.runelite.api.Varbits; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.ItemContainerChanged; 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.widgets.WidgetID; import net.runelite.client.account.AccountSession; import net.runelite.client.account.SessionManager; import net.runelite.client.callback.ClientThread; import net.runelite.client.config.ConfigManager; +import net.runelite.client.config.Keybind; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.events.SessionClose; 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.ChatboxPanelManager; import net.runelite.client.game.chatbox.ChatboxTextInput; +import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; 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.NavigationButton; import net.runelite.client.ui.components.colorpicker.ColorPickerManager; +import net.runelite.client.util.HotkeyListener; import net.runelite.client.util.ImageUtil; import javax.inject.Inject; import javax.swing.JOptionPane; @@ -79,6 +81,7 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; +import java.util.List; import java.util.stream.Collectors; @PluginDescriptor( @@ -130,6 +133,8 @@ public class InventorySetupPlugin extends Plugin @Inject private BankSearch bankSearch; @Inject + private KeyManager keyManager; + @Inject private ChatboxItemSearch itemSearch; @Inject private ChatboxPanelManager chatboxPanelManager; @@ -141,6 +146,41 @@ public class InventorySetupPlugin extends Plugin private boolean highlightUnorderedDifference; private boolean highlightDifference; 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 InventorySetupConfig getConfig(ConfigManager configManager) @@ -164,6 +204,8 @@ public class InventorySetupPlugin extends Plugin .build(); clientToolbar.addNavigation(navButton); + keyManager.registerKeyListener(returnToSetupsHotkeyListener); + keyManager.registerKeyListener(filterBankHotkeyListener); // load all the inventory setups from the config file clientThread.invokeLater(() -> @@ -237,15 +279,12 @@ public class InventorySetupPlugin extends Plugin updateConfig(); } - @Subscribe - public void onWidgetLoaded(WidgetLoaded event) + public List filterSetups(String textToFilter) { - if (event.getGroupId() != WidgetID.BANK_GROUP_ID) - { - return; - } - - doBankSearch(); + final String textToFilterLower = textToFilter.toLowerCase(); + return inventorySetups.stream() + .filter(i -> i.getName().toLowerCase().contains(textToFilterLower)) + .collect(Collectors.toList()); } public void doBankSearch() @@ -258,6 +297,26 @@ public class InventorySetupPlugin extends Plugin bankSearch.search(InputType.SEARCH, INV_SEARCH + currentSelectedSetup.getName(), true); } } + + @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() { @@ -877,6 +936,8 @@ public class InventorySetupPlugin extends Plugin this.highlightUnorderedDifference = config.highlightUnorderedDifference(); this.highlightDifference = config.highlightDifference(); this.highlightColor = config.highlightColor(); + this.returnToSetupsHotkey = config.returnToSetupsHotkey(); + this.filterBankHotkey = config.filterBankHotkey(); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupContainerPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupContainerPanel.java index 7e378a3c9d..2c1d842ecc 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupContainerPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupContainerPanel.java @@ -138,7 +138,7 @@ public abstract class InventorySetupContainerPanel extends JPanel break; } - assert index < items.size() && index > 0 : "Index Off Array"; + assert index < items.size() && index >= 0 : "Index Off Array"; containerSlot.setParentSetup(setup); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupPanel.java index f629404154..6cb5404872 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupPanel.java @@ -212,6 +212,7 @@ public class InventorySetupPanel extends JPanel nameInput.setEditable(false); updateNameActions(false); requestFocusInWindow(); + panel.rebuild(); } @Override diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupPluginPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupPluginPanel.java index 1b89546e86..54575f8fd8 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupPluginPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorysetups/ui/InventorySetupPluginPanel.java @@ -32,6 +32,7 @@ import net.runelite.api.InventoryID; import net.runelite.client.game.ItemManager; import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.PluginPanel; +import net.runelite.client.ui.components.IconTextField; import net.runelite.client.ui.components.PluginErrorPanel; import net.runelite.client.util.ImageUtil; import javax.swing.Box; @@ -47,10 +48,13 @@ import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.util.ArrayList; +import java.util.List; public class InventorySetupPluginPanel extends PluginPanel { @@ -81,8 +85,8 @@ public class InventorySetupPluginPanel extends PluginPanel UPDATE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(updateIcon, 0.53f)); final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(InventorySetupPlugin.class, "back_arrow_icon.png"); - BACK_ICON = new ImageIcon(ImageUtil.flipImage(backIcon, true, false)); - BACK_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(ImageUtil.flipImage(backIcon, true, false), 0.53f)); + BACK_ICON = new ImageIcon(backIcon); + BACK_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(backIcon, 0.53f)); MAIN_TITLE = "Inventory Setups"; } @@ -98,6 +102,7 @@ public class InventorySetupPluginPanel extends PluginPanel private final JLabel addImportMarker; private final JLabel updateMarker; private final JLabel backMarker; + private final IconTextField searchBar; private final InventorySetupInventoryPanel invPanel; private final InventorySetupEquipmentPanel eqpPanel; private final InventorySetupRunePouchPanel rpPanel; @@ -199,14 +204,7 @@ public class InventorySetupPluginPanel extends PluginPanel @Override public void mousePressed(MouseEvent e) { - noSetupsPanel.setVisible(false); - invEqPanel.setVisible(false); - overviewPanel.setVisible(true); - overviewTopRightButtonsPanel.setVisible(true); - setupTopRightButtonsPanel.setVisible(false); - title.setText(MAIN_TITLE); - currentSelectedSetup = null; - plugin.resetBankSearch(); + returnToOverviewPanel(); } @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(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(backMarker); + backMarker.setBorder(new EmptyBorder(0, 8, 0, 0)); // the panel on the top right that holds the buttons final JPanel markersPanel = new JPanel(); @@ -238,11 +238,36 @@ public class InventorySetupPluginPanel extends PluginPanel overviewTopRightButtonsPanel.setVisible(true); 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(); titleAndMarkersPanel.setLayout(new BorderLayout()); titleAndMarkersPanel.add(title, BorderLayout.WEST); 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 // contains the title and buttons @@ -250,7 +275,8 @@ public class InventorySetupPluginPanel extends PluginPanel northAnchoredPanel.setLayout(new BoxLayout(northAnchoredPanel, BoxLayout.Y_AXIS)); northAnchoredPanel.setBorder(new EmptyBorder(0, 0, 10, 0)); 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 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 setups) { overviewPanel.setLayout(new GridBagLayout()); overviewPanel.setBackground(ColorScheme.DARK_GRAY_COLOR); @@ -303,7 +329,7 @@ public class InventorySetupPluginPanel extends PluginPanel constraints.gridx = 0; constraints.gridy = 0; - for (final InventorySetup setup : plugin.getInventorySetups()) + for (final InventorySetup setup : setups) { InventorySetupPanel newPanel = new InventorySetupPanel(plugin, this, setup); overviewPanel.add(newPanel, constraints); @@ -323,7 +349,9 @@ public class InventorySetupPluginPanel extends PluginPanel public void rebuild() { overviewPanel.removeAll(); - init(); + final String text = searchBar.getText(); + List setupsToAdd = searchBar.getText().isEmpty() ? plugin.getInventorySetups() : plugin.filterSetups(searchBar.getText()); + init(setupsToAdd); revalidate(); repaint(); } @@ -351,6 +379,7 @@ public class InventorySetupPluginPanel extends PluginPanel overviewPanel.setVisible(false); title.setText(inventorySetup.getName()); + searchBar.setVisible(false); // only show the rune pouch if the setup has a rune pouch rpPanel.setVisible(currentSelectedSetup.getRune_pouch() != null); @@ -410,5 +439,17 @@ public class InventorySetupPluginPanel extends PluginPanel final ArrayList eqp = plugin.getNormalizedContainer(InventoryID.EQUIPMENT); 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(); + } } diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/inventorysetups/add_icon.png b/runelite-client/src/main/resources/net/runelite/client/plugins/inventorysetups/add_icon.png index 343c3dce0cd5c460af2627b8a4acb39f68cc86fe..c16a645f379431c4a21255bd7f5d66ada24bc741 100644 GIT binary patch delta 96 zcmb;{njju6#KFeEz>ppD-VjJxdb&7gTe~DWM4f0g52y delta 103 zcmXS_oFJaW$HB(Hz##9Tdl5)+7I;J!Gca%qgD@k*tT_@uL2XYL#}JK)$q5G-W6~`C zmd||nMSi-CupXyVf=Wip5%D6Eje_bDz3yBlObmxxxmK=OkTeCTjlt8^&t;ucLK6TX C{Tzn? diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/inventorysetups/back_arrow_icon.png b/runelite-client/src/main/resources/net/runelite/client/plugins/inventorysetups/back_arrow_icon.png index 1318a567bfb91869692b4b77999dd50eff4db8bd..ee2d07534762d3632c05df533f5e262b76cb6dcc 100644 GIT binary patch delta 129 zcmV-{0Dk|H0g(Za7kUy11^@s6ThRUx00013Nkle-A8bM_00000NkvXXu0mjfwN)}i delta 130 zcmV-|0Db?F0g?fb7kdr}1^@s6FT_0X00014NklmB+zMj>nbPY9h0`*WZ2cOK4&j0`b07*qoM6N<$g3HY{9smFU diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/inventorysetups/import_icon.png b/runelite-client/src/main/resources/net/runelite/client/plugins/inventorysetups/import_icon.png index 18235072ad27e99a0f764fea408b14e78c80af53..20e531ecd4384cbdb306bab15676bdf7b95b36c8 100644 GIT binary patch delta 173 zcmV;e08;<80lWc_7k?561^@s6R?d!B0001kNkl)u?PX9sP z-;=Qquj|2*FvZB>1=EOb5H7Wh*d&l$K#V~k^>Bl5Ih~N#VDhvz2xJSsFhX`cUKb&I z2NxR_F+>@JE7cS2B3wxVTY4fYu+ftSwwNW#AY_*jN*)BGpC(Z0fZ-xS8VJeb%xi=+ bqUTEhf76Fjy_!KW00000NkvXXu0mjfg|9;d delta 166 zcmV;X09pUM0kr{;7k>^21^@s6BHB#10001dNkl