From bf7df040ba2bc0f20fa6130a7f452d0dbba4c759 Mon Sep 17 00:00:00 2001 From: 1Defence <> Date: Wed, 12 Jun 2024 15:07:33 -0400 Subject: [PATCH] Add config option to remember last active inventory-setup, loads on plugin/client startup. --- .../InventorySetupsConfig.java | 12 ++++++++++++ .../InventorySetupsPlugin.java | 19 ++++++++++++++++++- .../ui/InventorySetupsPluginPanel.java | 3 +++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/inventorysetups/InventorySetupsConfig.java b/src/main/java/inventorysetups/InventorySetupsConfig.java index 78433d8..f9350f0 100644 --- a/src/main/java/inventorysetups/InventorySetupsConfig.java +++ b/src/main/java/inventorysetups/InventorySetupsConfig.java @@ -26,6 +26,7 @@ import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_HIDE_BUTTON; import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_MANUAL_BANK_FILTER; +import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_REMEMBER_LAST_SETUP; import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_PANEL_VIEW; import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_PERSIST_HOTKEYS; import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_SECTION_MODE; @@ -456,6 +457,17 @@ default boolean manualBankFilter() return false; } + @ConfigItem( + keyName = CONFIG_KEY_REMEMBER_LAST_SETUP, + name = "Remember Last Setup", + description = "If a setup was active previously, it will be opened when the client or plugin starts", + position = 28 + ) + default boolean rememberLastSetup() + { + return false; + } + } diff --git a/src/main/java/inventorysetups/InventorySetupsPlugin.java b/src/main/java/inventorysetups/InventorySetupsPlugin.java index 29de583..fb4ab4a 100644 --- a/src/main/java/inventorysetups/InventorySetupsPlugin.java +++ b/src/main/java/inventorysetups/InventorySetupsPlugin.java @@ -136,6 +136,8 @@ public class InventorySetupsPlugin extends Plugin public static final String CONFIG_KEY_VERSION_STR = "version"; public static final String CONFIG_KEY_UNASSIGNED_MAXIMIZED = "unassignedMaximized"; public static final String CONFIG_KEY_MANUAL_BANK_FILTER = "manualBankFilter"; + public static final String CONFIG_KEY_REMEMBER_LAST_SETUP = "rememberLastSetup"; + public static final String CONFIG_KEY_LAST_SETUP_VALUE = "lastSetupValue"; public static final String CONFIG_KEY_PERSIST_HOTKEYS = "persistHotKeysOutsideBank"; public static final String TUTORIAL_LINK = "https://github.com/dillydill123/inventory-setups#inventory-setups"; public static final String SUGGESTION_LINK = "https://github.com/dillydill123/inventory-setups/issues"; @@ -863,7 +865,22 @@ public void startUp() clientThread.invokeLater(() -> { dataManager.loadConfig(); - SwingUtilities.invokeLater(() -> panel.redrawOverviewPanel(true)); + SwingUtilities.invokeLater(() -> + { + panel.redrawOverviewPanel(true); + if (config.rememberLastSetup()) + { + String lastSetupName = configManager.getConfiguration(CONFIG_GROUP, CONFIG_KEY_LAST_SETUP_VALUE); + if (!lastSetupName.isEmpty()) + { + final InventorySetup lastSetup = getCache().getInventorySetupNames().get(lastSetupName); + if (lastSetup != null) + { + panel.setCurrentInventorySetup(lastSetup, true); + } + } + } + }); }); return true; diff --git a/src/main/java/inventorysetups/ui/InventorySetupsPluginPanel.java b/src/main/java/inventorysetups/ui/InventorySetupsPluginPanel.java index f9d4f93..4324553 100644 --- a/src/main/java/inventorysetups/ui/InventorySetupsPluginPanel.java +++ b/src/main/java/inventorysetups/ui/InventorySetupsPluginPanel.java @@ -33,6 +33,7 @@ import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_PANEL_VIEW; import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_SECTION_MODE; import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_UNASSIGNED_MAXIMIZED; +import static inventorysetups.InventorySetupsPlugin.CONFIG_KEY_LAST_SETUP_VALUE; import static inventorysetups.InventorySetupsPlugin.TUTORIAL_LINK; import inventorysetups.InventorySetupsSection; @@ -445,6 +446,7 @@ public void mousePressed(MouseEvent e) if (SwingUtilities.isLeftMouseButton(e)) { redrawOverviewPanel(false); + plugin.setConfigValue(CONFIG_KEY_LAST_SETUP_VALUE, ""); } } @@ -754,6 +756,7 @@ public void setCurrentInventorySetup(final InventorySetup inventorySetup, boolea plugin.setBankFilteringMode(InventorySetupsFilteringModeID.ALL); plugin.doBankSearch(); + plugin.setConfigValue(CONFIG_KEY_LAST_SETUP_VALUE, inventorySetup.getName()); validate(); repaint();