pluginsorter: Merge into OpenOSRS config and pull methods to th… (#1820)

pluginsorter: Merge into OpenOSRS config and pull methods to the client
This commit is contained in:
ST0NEWALL
2019-10-22 17:25:50 -04:00
committed by GitHub
7 changed files with 416 additions and 451 deletions

View File

@@ -26,9 +26,30 @@
*/ */
package net.runelite.client.config; package net.runelite.client.config;
import java.awt.Color;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
@ConfigGroup("openosrs") @ConfigGroup("openosrs")
public interface OpenOSRSConfig extends Config public interface OpenOSRSConfig extends Config
{ {
@Getter(AccessLevel.PUBLIC)
@AllArgsConstructor
enum SortStyle
{
CATEGORY("Category"),
ALPHABETICALLY("Alphabetically");
private String name;
@Override
public String toString()
{
return getName();
}
}
@ConfigTitleSection( @ConfigTitleSection(
keyName = "pluginsTitle", keyName = "pluginsTitle",
name = "Plugins", name = "Plugins",
@@ -40,12 +61,215 @@ public interface OpenOSRSConfig extends Config
return new Title(); return new Title();
} }
@ConfigTitleSection(
keyName = "pluginSortingTitle",
name = "Sorting",
description = "",
position = 2,
titleSection = "pluginsTitle"
)
default Title pluginSortingTitle()
{
return new Title();
}
@ConfigItem(
position = 3,
keyName = "pluginSortMode",
name = "Sorting mode",
description = "Sorts plugins ",
titleSection = "pluginSortingTitle"
)
default SortStyle pluginSortMode()
{
return SortStyle.CATEGORY;
}
@ConfigTitleSection(
keyName = "hidePluginsTitle",
name = "Hide By Type",
description = "",
position = 4,
titleSection = "pluginsTitle"
)
default Title hidePluginsTitle()
{
return new Title();
}
@ConfigItem(
position = 5,
keyName = "hidePlugins",
name = "Hide All Plugins",
description = "Hides all OpenOSRS plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePvmPlugins || hidePvpPlugins || hideSkillingPlugins || hideUtilityPlugins || hideExternalPlugins"
)
default boolean hidePlugins()
{
return false;
}
@ConfigItem(
position = 6,
keyName = "hideExternalPlugins",
name = "Hide External Plugins",
description = "Hides all OpenOSRS external plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hideExternalPlugins()
{
return false;
}
@ConfigItem(
position = 7,
keyName = "hidePvmPlugins",
name = "Hide PvM Plugins",
description = "Hides all OpenOSRS PvM plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hidePvmPlugins()
{
return false;
}
@ConfigItem(
position = 8,
keyName = "hideSkillingPlugins",
name = "Hide Skilling Plugins",
description = "Hides all OpenOSRS skilling plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hideSkillingPlugins()
{
return false;
}
@ConfigItem(
position = 9,
keyName = "hidePvpPlugins",
name = "Hide PvP Plugins",
description = "Hides all OpenOSRS Pvp plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hidePvpPlugins()
{
return false;
}
@ConfigItem(
position = 10,
keyName = "hideUtilityPlugins",
name = "Hide Utility Plugins",
description = "Hides all OpenOSRS utility plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hideUtilityPlugins()
{
return false;
}
@ConfigTitleSection(
keyName = "pluginsColorTitle",
name = "Colors",
description = "",
position = 11,
titleSection = "pluginsTitle"
)
default Title pluginsColorTitle()
{
return new Title();
}
@Alpha
@ConfigItem(
position = 12,
keyName = "externalColor",
name = "External color",
description = "Configure the color of external plugins",
titleSection = "pluginsColorTitle"
)
default Color externalColor()
{
return new Color(177, 156, 217, 255);
}
@Alpha
@ConfigItem(
position = 13,
keyName = "pvmColor",
name = "PVM color",
description = "Configure the color of PVM related plugins",
titleSection = "pluginsColorTitle"
)
default Color pvmColor()
{
return new Color(119, 221, 119, 255);
}
@Alpha
@ConfigItem(
position = 14,
keyName = "pvpColor",
name = "PVP color",
description = "Configure the color of PVP related plugins",
titleSection = "pluginsColorTitle"
)
default Color pvpColor()
{
return new Color(255, 105, 97, 255);
}
@Alpha
@ConfigItem(
position = 15,
keyName = "skillingColor",
name = "Skilling color",
description = "Configure the color of Skilling related plugins",
titleSection = "pluginsColorTitle"
)
default Color skillingColor()
{
return new Color(252, 252, 100, 255);
}
@Alpha
@ConfigItem(
position = 16,
keyName = "utilityColor",
name = "Utility color",
description = "Configure the color of Utility related plugins",
titleSection = "pluginsColorTitle"
)
default Color utilityColor()
{
return new Color(144, 212, 237, 255);
}
@ConfigTitleSection(
keyName = "externalPluginsTitle",
name = "External",
description = "",
position = 17,
titleSection = "pluginsTitle"
)
default Title externalPluginsTitle()
{
return new Title();
}
@ConfigItem( @ConfigItem(
keyName = "enablePlugins", keyName = "enablePlugins",
name = "Enable loading of external plugins", name = "Enable loading of external plugins",
description = "Enable loading of external plugins", description = "Enable loading of external plugins",
position = 2, position = 18,
titleSection = "pluginsTitle" titleSection = "externalPluginsTitle"
) )
default boolean enablePlugins() default boolean enablePlugins()
{ {
@@ -56,7 +280,7 @@ public interface OpenOSRSConfig extends Config
keyName = "opacityTitle", keyName = "opacityTitle",
name = "Opacity", name = "Opacity",
description = "", description = "",
position = 3 position = 19
) )
default Title opacityTitle() default Title opacityTitle()
{ {
@@ -67,7 +291,7 @@ public interface OpenOSRSConfig extends Config
keyName = "enableOpacity", keyName = "enableOpacity",
name = "Enable opacity", name = "Enable opacity",
description = "Enables opacity for the whole window.<br>NOTE: This only stays enabled if your pc supports this!", description = "Enables opacity for the whole window.<br>NOTE: This only stays enabled if your pc supports this!",
position = 4, position = 20,
titleSection = "opacityTitle" titleSection = "opacityTitle"
) )
default boolean enableOpacity() default boolean enableOpacity()
@@ -83,7 +307,7 @@ public interface OpenOSRSConfig extends Config
keyName = "opacityPercentage", keyName = "opacityPercentage",
name = "Opacity percentage", name = "Opacity percentage",
description = "Changes the opacity of the window if opacity is enabled", description = "Changes the opacity of the window if opacity is enabled",
position = 5, position = 21,
titleSection = "opacityTitle" titleSection = "opacityTitle"
) )
default int opacityPercentage() default int opacityPercentage()
@@ -95,7 +319,7 @@ public interface OpenOSRSConfig extends Config
keyName = "miscTitle", keyName = "miscTitle",
name = "Miscellaneous", name = "Miscellaneous",
description = "", description = "",
position = 6 position = 22
) )
default Title miscTitle() default Title miscTitle()
{ {
@@ -106,7 +330,7 @@ public interface OpenOSRSConfig extends Config
keyName = "keyboardPin", keyName = "keyboardPin",
name = "Keyboard bank pin", name = "Keyboard bank pin",
description = "Enables you to type your bank pin", description = "Enables you to type your bank pin",
position = 7, position = 23,
titleSection = "miscTitle" titleSection = "miscTitle"
) )
default boolean keyboardPin() default boolean keyboardPin()
@@ -118,7 +342,7 @@ public interface OpenOSRSConfig extends Config
keyName = "detachHotkey", keyName = "detachHotkey",
name = "Detach Cam", name = "Detach Cam",
description = "Detach Camera hotkey, press this and it will activate detatched camera.", description = "Detach Camera hotkey, press this and it will activate detatched camera.",
position = 8, position = 24,
titleSection = "miscTitle" titleSection = "miscTitle"
) )
default Keybind detachHotkey() default Keybind detachHotkey()

View File

@@ -8,6 +8,5 @@ public enum PluginType
UTILITY, UTILITY,
GENERAL_USE, GENERAL_USE,
EXTERNAL, EXTERNAL,
PLUGIN_ORGANIZER,
IMPORTANT IMPORTANT
} }

View File

@@ -26,6 +26,7 @@ package net.runelite.client.plugins.config;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
@@ -45,6 +46,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -105,6 +107,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginInstantiationException; import net.runelite.client.plugins.PluginInstantiationException;
import net.runelite.client.plugins.PluginManager; import net.runelite.client.plugins.PluginManager;
import net.runelite.client.plugins.PluginType;
import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.DynamicGridLayout; import net.runelite.client.ui.DynamicGridLayout;
import net.runelite.client.ui.FontManager; import net.runelite.client.ui.FontManager;
@@ -137,7 +140,7 @@ public class ConfigPanel extends PluginPanel
private static final String RUNELITE_GROUP_NAME = RuneLiteConfig.class.getAnnotation(ConfigGroup.class).value(); private static final String RUNELITE_GROUP_NAME = RuneLiteConfig.class.getAnnotation(ConfigGroup.class).value();
private static final String PINNED_PLUGINS_CONFIG_KEY = "pinnedPlugins"; private static final String PINNED_PLUGINS_CONFIG_KEY = "pinnedPlugins";
private static final String RUNELITE_PLUGIN = "RuneLite"; private static final String RUNELITE_PLUGIN = "RuneLite";
private static final String openosrs_PLUGIN = "OpenOSRS"; private static final String OPENOSRS_PLUGIN = "OpenOSRS";
private static final String CHAT_COLOR_PLUGIN = "Chat Color"; private static final String CHAT_COLOR_PLUGIN = "Chat Color";
private final PluginManager pluginManager; private final PluginManager pluginManager;
private final ConfigManager configManager; private final ConfigManager configManager;
@@ -156,6 +159,9 @@ public class ConfigPanel extends PluginPanel
private boolean showingPluginList = true; private boolean showingPluginList = true;
private int scrollBarPosition = 0; private int scrollBarPosition = 0;
private static final ImmutableList<PluginType> definedOrder = ImmutableList.of(PluginType.IMPORTANT, PluginType.EXTERNAL, PluginType.PVM, PluginType.SKILLING, PluginType.PVP, PluginType.UTILITY, PluginType.GENERAL_USE);
private static final Comparator<PluginListItem> categoryComparator = Comparator.comparing(plugin -> definedOrder.indexOf(plugin.getPluginType()));
static static
{ {
final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_back_icon.png"); final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_back_icon.png");
@@ -282,15 +288,15 @@ public class ConfigPanel extends PluginPanel
// set OpenOSRS config on top, as it should always have been // set OpenOSRS config on top, as it should always have been
final PluginListItem openosrs = new PluginListItem(this, configManager, OpenOSRSConfig, final PluginListItem openosrs = new PluginListItem(this, configManager, OpenOSRSConfig,
configManager.getConfigDescriptor(OpenOSRSConfig), configManager.getConfigDescriptor(OpenOSRSConfig),
openosrs_PLUGIN, "OpenOSRS client settings", "client"); OPENOSRS_PLUGIN, "OpenOSRS client settings", PluginType.IMPORTANT, "client");
openosrs.setPinned(pinnedPlugins.contains(openosrs_PLUGIN)); openosrs.setPinned(pinnedPlugins.contains(OPENOSRS_PLUGIN));
openosrs.nameLabel.setForeground(Color.WHITE); openosrs.nameLabel.setForeground(Color.WHITE);
pluginList.add(openosrs); pluginList.add(openosrs);
// set RuneLite config on top, as it should always have been // set RuneLite config on top, as it should always have been
final PluginListItem runeLite = new PluginListItem(this, configManager, runeLiteConfig, final PluginListItem runeLite = new PluginListItem(this, configManager, runeLiteConfig,
configManager.getConfigDescriptor(runeLiteConfig), configManager.getConfigDescriptor(runeLiteConfig),
RUNELITE_PLUGIN, "RuneLite client settings", "client"); RUNELITE_PLUGIN, "RuneLite client settings", PluginType.IMPORTANT, "client");
runeLite.setPinned(pinnedPlugins.contains(RUNELITE_PLUGIN)); runeLite.setPinned(pinnedPlugins.contains(RUNELITE_PLUGIN));
runeLite.nameLabel.setForeground(Color.WHITE); runeLite.nameLabel.setForeground(Color.WHITE);
pluginList.add(runeLite); pluginList.add(runeLite);
@@ -307,18 +313,21 @@ public class ConfigPanel extends PluginPanel
final PluginListItem listItem = new PluginListItem(this, configManager, plugin, descriptor, config, configDescriptor); final PluginListItem listItem = new PluginListItem(this, configManager, plugin, descriptor, config, configDescriptor);
listItem.setPinned(pinnedPlugins.contains(listItem.getName())); listItem.setPinned(pinnedPlugins.contains(listItem.getName()));
listItem.setColor(getColorByCategory(OpenOSRSConfig, listItem.getPluginType()));
listItem.setHidden(getHiddenByCategory(OpenOSRSConfig, listItem.getPluginType()));
plugins.add(listItem); plugins.add(listItem);
} }
); );
final PluginListItem chatColor = new PluginListItem(this, configManager, chatColorConfig, final PluginListItem chatColor = new PluginListItem(this, configManager, chatColorConfig,
configManager.getConfigDescriptor(chatColorConfig), configManager.getConfigDescriptor(chatColorConfig),
CHAT_COLOR_PLUGIN, "Recolor chat text", "colour", "messages"); CHAT_COLOR_PLUGIN, "Recolor chat text", PluginType.GENERAL_USE, "colour", "messages");
chatColor.setPinned(pinnedPlugins.contains(CHAT_COLOR_PLUGIN)); chatColor.setPinned(pinnedPlugins.contains(CHAT_COLOR_PLUGIN));
chatColor.nameLabel.setForeground(Color.WHITE);
plugins.add(chatColor); plugins.add(chatColor);
pluginList.addAll(plugins); pluginList.addAll(plugins);
ConfigPanel.sortPluginList(OpenOSRSConfig, null);
} }
void refreshPluginList() void refreshPluginList()
@@ -466,10 +475,17 @@ public class ConfigPanel extends PluginPanel
String name = listItem.getName(); String name = listItem.getName();
JLabel title = new JLabel(name); JLabel title = new JLabel(name);
title.setForeground(Color.WHITE); title.setForeground(listItem.getColor());
title.setToolTipText("<html>" + name + ":<br>" + listItem.getDescription() + "</html>"); title.setToolTipText("<html>" + name + ":<br>" + listItem.getDescription() + "</html>");
topPanel.add(title); topPanel.add(title);
IconButton toggleButton = new IconButton(PluginListItem.OFF_SWITCHER);
toggleButton.setPreferredSize(new Dimension(25, 0));
listItem.updateToggleButton(toggleButton);
listItem.attachToggleButtonListener(toggleButton);
topPanel.add(toggleButton, BorderLayout.EAST);
final Map<String, JPanel> sectionWidgets = new HashMap<>(); final Map<String, JPanel> sectionWidgets = new HashMap<>();
final Map<String, JPanel> titleSectionWidgets = new HashMap<>(); final Map<String, JPanel> titleSectionWidgets = new HashMap<>();
@@ -1379,4 +1395,70 @@ public class ConfigPanel extends PluginPanel
{ {
openGroupConfigPanel(listItem, config, cd, true); openGroupConfigPanel(listItem, config, cd, true);
} }
public static Color getColorByCategory(OpenOSRSConfig openOSRSConfig, PluginType pluginType)
{
switch (pluginType)
{
case EXTERNAL:
return openOSRSConfig.externalColor();
case PVM:
return openOSRSConfig.pvmColor();
case PVP:
return openOSRSConfig.pvpColor();
case SKILLING:
return openOSRSConfig.skillingColor();
case UTILITY:
return openOSRSConfig.utilityColor();
}
return null;
}
public static boolean getHiddenByCategory(OpenOSRSConfig openOSRSConfig, PluginType pluginType)
{
if (pluginType == PluginType.IMPORTANT || pluginType == PluginType.GENERAL_USE)
{
return false;
}
if (openOSRSConfig.hidePlugins())
{
return true;
}
switch (pluginType)
{
case EXTERNAL:
return openOSRSConfig.hideExternalPlugins();
case PVM:
return openOSRSConfig.hidePvmPlugins();
case PVP:
return openOSRSConfig.hidePvpPlugins();
case SKILLING:
return openOSRSConfig.hideSkillingPlugins();
case UTILITY:
return openOSRSConfig.hideUtilityPlugins();
}
return false;
}
public static void sortPluginList(OpenOSRSConfig openOSRSConfig, Comparator<PluginListItem> comparator)
{
if (comparator != null)
{
ConfigPanel.pluginList.sort(comparator.thenComparing(PluginListItem::getName));
return;
}
if (openOSRSConfig.pluginSortMode() == net.runelite.client.config.OpenOSRSConfig.SortStyle.CATEGORY)
{
ConfigPanel.pluginList.sort(categoryComparator.thenComparing(PluginListItem::getName));
}
else
{
ConfigPanel.pluginList.sort(Comparator.comparing(PluginListItem::getName));
}
}
} }

View File

@@ -25,6 +25,7 @@
package net.runelite.client.plugins.config; package net.runelite.client.plugins.config;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@@ -43,6 +44,7 @@ import net.runelite.client.config.ConfigDescriptor;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
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.PluginType;
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.IconButton; import net.runelite.client.ui.components.IconButton;
@@ -58,7 +60,7 @@ public class PluginListItem extends JPanel
private static final ImageIcon CONFIG_ICON; private static final ImageIcon CONFIG_ICON;
private static final ImageIcon CONFIG_ICON_HOVER; private static final ImageIcon CONFIG_ICON_HOVER;
private static final ImageIcon ON_SWITCHER; private static final ImageIcon ON_SWITCHER;
private static final ImageIcon OFF_SWITCHER; public static final ImageIcon OFF_SWITCHER;
private static final ImageIcon ON_STAR; private static final ImageIcon ON_STAR;
private static final ImageIcon OFF_STAR; private static final ImageIcon OFF_STAR;
@@ -82,12 +84,16 @@ public class PluginListItem extends JPanel
@Getter(AccessLevel.PUBLIC) @Getter(AccessLevel.PUBLIC)
private final String description; private final String description;
@Getter(AccessLevel.PUBLIC)
private final PluginType pluginType;
private final List<String> keywords = new ArrayList<>(); private final List<String> keywords = new ArrayList<>();
private final IconButton pinButton = new IconButton(OFF_STAR); private final IconButton pinButton = new IconButton(OFF_STAR);
private final IconButton configButton = new IconButton(CONFIG_ICON, CONFIG_ICON_HOVER); private final IconButton configButton = new IconButton(CONFIG_ICON, CONFIG_ICON_HOVER);
private final IconButton toggleButton = new IconButton(OFF_SWITCHER); private final IconButton toggleButton = new IconButton(OFF_SWITCHER);
@Getter
private boolean isPluginEnabled = false; private boolean isPluginEnabled = false;
@Getter @Getter
@@ -96,6 +102,8 @@ public class PluginListItem extends JPanel
@Getter @Getter
private boolean isHidden = false; private boolean isHidden = false;
private Color color = null;
static static
{ {
BufferedImage configIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_edit_icon.png"); BufferedImage configIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_edit_icon.png");
@@ -131,20 +139,20 @@ public class PluginListItem extends JPanel
@Nullable Config config, @Nullable ConfigDescriptor configDescriptor) @Nullable Config config, @Nullable ConfigDescriptor configDescriptor)
{ {
this(configPanel, configManager, plugin, config, configDescriptor, this(configPanel, configManager, plugin, config, configDescriptor,
descriptor.name(), descriptor.description(), descriptor.tags()); descriptor.name(), descriptor.description(), descriptor.type(), descriptor.tags());
} }
/** /**
* Creates a new {@code PluginListItem} for a core configuration. * Creates a new {@code PluginListItem} for a core configuration.
*/ */
PluginListItem(ConfigPanel configPanel, ConfigManager configManager, Config config, ConfigDescriptor configDescriptor, PluginListItem(ConfigPanel configPanel, ConfigManager configManager, Config config, ConfigDescriptor configDescriptor,
String name, String description, String... tags) String name, String description, PluginType pluginType, String... tags)
{ {
this(configPanel, configManager, null, config, configDescriptor, name, description, tags); this(configPanel, configManager, null, config, configDescriptor, name, description, pluginType, tags);
} }
private PluginListItem(ConfigPanel configPanel, ConfigManager configManager, @Nullable Plugin plugin, @Nullable Config config, private PluginListItem(ConfigPanel configPanel, ConfigManager configManager, @Nullable Plugin plugin, @Nullable Config config,
@Nullable ConfigDescriptor configDescriptor, String name, String description, String... tags) @Nullable ConfigDescriptor configDescriptor, String name, String description, PluginType pluginType, String... tags)
{ {
this.configPanel = configPanel; this.configPanel = configPanel;
this.plugin = plugin; this.plugin = plugin;
@@ -152,6 +160,7 @@ public class PluginListItem extends JPanel
this.configDescriptor = configDescriptor; this.configDescriptor = configDescriptor;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.pluginType = pluginType;
Collections.addAll(keywords, name.toLowerCase().split(" ")); Collections.addAll(keywords, name.toLowerCase().split(" "));
Collections.addAll(keywords, description.toLowerCase().split(" ")); Collections.addAll(keywords, description.toLowerCase().split(" "));
Collections.addAll(keywords, tags); Collections.addAll(keywords, tags);
@@ -206,7 +215,7 @@ public class PluginListItem extends JPanel
buttonPanel.add(toggleButton); buttonPanel.add(toggleButton);
} }
private void attachToggleButtonListener(IconButton button) void attachToggleButtonListener(IconButton button)
{ {
// no need for a listener if there is no plugin to enable / disable // no need for a listener if there is no plugin to enable / disable
if (plugin == null) if (plugin == null)
@@ -231,15 +240,6 @@ public class PluginListItem extends JPanel
}); });
} }
IconButton createToggleButton()
{
IconButton button = new IconButton(OFF_SWITCHER);
button.setPreferredSize(new Dimension(25, 0));
updateToggleButton(button);
attachToggleButtonListener(button);
return button;
}
void setPluginEnabled(boolean enabled) void setPluginEnabled(boolean enabled)
{ {
isPluginEnabled = enabled; isPluginEnabled = enabled;
@@ -253,12 +253,28 @@ public class PluginListItem extends JPanel
pinButton.setToolTipText(pinned ? "Unpin plugin" : "Pin plugin"); pinButton.setToolTipText(pinned ? "Unpin plugin" : "Pin plugin");
} }
Color getColor()
{
return this.color == null ? Color.WHITE : this.color;
}
public void setColor(Color color)
{
if (color == null)
{
return;
}
this.color = color;
this.nameLabel.setForeground(color);
}
public void setHidden(boolean hidden) public void setHidden(boolean hidden)
{ {
isHidden = hidden; isHidden = hidden;
} }
private void updateToggleButton(IconButton button) void updateToggleButton(IconButton button)
{ {
button.setIcon(isPluginEnabled ? ON_SWITCHER : OFF_SWITCHER); button.setIcon(isPluginEnabled ? ON_SWITCHER : OFF_SWITCHER);
button.setToolTipText(isPluginEnabled ? "Disable plugin" : "Enable plugin"); button.setToolTipText(isPluginEnabled ? "Disable plugin" : "Enable plugin");

View File

@@ -27,6 +27,8 @@
package net.runelite.client.plugins.openosrs; package net.runelite.client.plugins.openosrs;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.Arrays;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -37,7 +39,6 @@ import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.widgets.WidgetID; import net.runelite.api.widgets.WidgetID;
import static net.runelite.api.widgets.WidgetInfo.*; import static 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.Keybind; import net.runelite.client.config.Keybind;
import net.runelite.client.config.OpenOSRSConfig; import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.EventBus;
@@ -45,6 +46,8 @@ import net.runelite.client.input.KeyListener;
import net.runelite.client.input.KeyManager; 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.PluginType;
import net.runelite.client.plugins.config.ConfigPanel;
import net.runelite.client.util.HotkeyListener; import net.runelite.client.util.HotkeyListener;
@PluginDescriptor( @PluginDescriptor(
@@ -57,6 +60,8 @@ import net.runelite.client.util.HotkeyListener;
public class OpenOSRSPlugin extends Plugin public class OpenOSRSPlugin extends Plugin
{ {
private final openosrsKeyListener keyListener = new openosrsKeyListener(); private final openosrsKeyListener keyListener = new openosrsKeyListener();
private final List<String> colorOptions = Arrays.asList("externalColor", "pvmColor", "pvpColor", "skillingColor", "utilityColor");
@Inject @Inject
private OpenOSRSConfig config; private OpenOSRSConfig config;
@@ -72,9 +77,6 @@ public class OpenOSRSPlugin extends Plugin
@Inject @Inject
private EventBus eventbus; private EventBus eventbus;
@Inject
private ConfigManager configManager;
private HotkeyListener hotkeyListener = new HotkeyListener(() -> this.keybind) private HotkeyListener hotkeyListener = new HotkeyListener(() -> this.keybind)
{ {
@Override @Override
@@ -94,7 +96,6 @@ public class OpenOSRSPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
migrateConfigs();
addSubscriptions(); addSubscriptions();
entered = -1; entered = -1;
@@ -123,6 +124,16 @@ public class OpenOSRSPlugin extends Plugin
return; return;
} }
if (colorOptions.stream().anyMatch(option -> option.equals(event.getKey())))
{
updatePlugins();
}
if (event.getKey().equals("pluginSortMode"))
{
ConfigPanel.sortPluginList(config, null);
}
this.keybind = config.detachHotkey(); this.keybind = config.detachHotkey();
if (!config.keyboardPin()) if (!config.keyboardPin())
@@ -254,35 +265,17 @@ public class OpenOSRSPlugin extends Plugin
} }
} }
/** private void updatePlugins()
* Migrates configs from runenergy and regenmeter to this plugin and deletes the old config values.
* This method should be removed after a reasonable amount of time.
*/
@Deprecated
private void migrateConfigs()
{ {
migrateConfig("runeliteplus", "enableOpacity"); ConfigPanel.pluginList.forEach(listItem ->
migrateConfig("runeliteplus", "opacityPercentage");
migrateConfig("runeliteplus", "keyboardPin");
migrateConfig("runeliteplus", "enablePlugins");
migrateConfig("runeliteplus", "detachHotkey");
}
/**
* Wrapper for migrating individual config options
* This method should be removed after a reasonable amount of time.
*
* @param group old group name
* @param key key name to migrate
*/
@Deprecated
private void migrateConfig(String group, String key)
{
String value = configManager.getConfiguration(group, key);
if (value != null)
{ {
configManager.setConfiguration("openosrs", key, value); if (listItem.getPluginType() == PluginType.GENERAL_USE || listItem.getPluginType() == PluginType.IMPORTANT)
configManager.unsetConfiguration(group, key); {
} return;
}
listItem.setColor(ConfigPanel.getColorByCategory(config, listItem.getPluginType()));
listItem.setHidden(ConfigPanel.getHiddenByCategory(config, listItem.getPluginType()));
});
} }
} }

View File

@@ -1,245 +0,0 @@
/*
* Copyright (c) 2018, https://openosrs.com
* 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.pluginsorter;
import java.awt.Color;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
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.ConfigTitleSection;
import net.runelite.client.config.Title;
@ConfigGroup("pluginsorter")
public interface PluginSorterConfig extends Config
{
@Getter(AccessLevel.PACKAGE)
@AllArgsConstructor
enum SortStyle
{
CATEGORY("Category"),
ALPHABETICALLY("Alphabetically");
private String name;
@Override
public String toString()
{
return getName();
}
}
@ConfigTitleSection(
keyName = "pluginSortingTitle",
name = "Sorting",
description = "",
position = 0
)
default Title pluginSortingTitle()
{
return new Title();
}
@ConfigItem(
position = 1,
keyName = "pluginSortMode",
name = "Sorting mode",
description = "Sorts plugins ",
titleSection = "pluginSortingTitle"
)
default SortStyle pluginSortMode()
{
return SortStyle.CATEGORY;
}
@ConfigTitleSection(
keyName = "hidePluginsTitle",
name = "Hide By Type",
description = "",
position = 2
)
default Title hidePluginsTitle()
{
return new Title();
}
@ConfigItem(
position = 3,
keyName = "hidePlugins",
name = "Hide All Plugins",
description = "Hides all OpenOSRS plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePvmPlugins || hidePvpPlugins || hideSkillingPlugins || hideUtilityPlugins || hideExternalPlugins"
)
default boolean hidePlugins()
{
return false;
}
@ConfigItem(
position = 4,
keyName = "hideExternalPlugins",
name = "Hide External Plugins",
description = "Hides all OpenOSRS external plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hideExternalPlugins()
{
return false;
}
@ConfigItem(
position = 5,
keyName = "hidePvmPlugins",
name = "Hide PvM Plugins",
description = "Hides all OpenOSRS PvM plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hidePvmPlugins()
{
return false;
}
@ConfigItem(
position = 6,
keyName = "hideSkillingPlugins",
name = "Hide Skilling Plugins",
description = "Hides all OpenOSRS skilling plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hideSkillingPlugins()
{
return false;
}
@ConfigItem(
position = 7,
keyName = "hidePvpPlugins",
name = "Hide PvP Plugins",
description = "Hides all OpenOSRS Pvp plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hidePvpPlugins()
{
return false;
}
@ConfigItem(
position = 8,
keyName = "hideUtilityPlugins",
name = "Hide Utility Plugins",
description = "Hides all OpenOSRS utility plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hideUtilityPlugins()
{
return false;
}
@ConfigTitleSection(
keyName = "pluginsColorTitle",
name = "Colors",
description = "",
position = 9
)
default Title pluginsColorTitle()
{
return new Title();
}
@Alpha
@ConfigItem(
position = 10,
keyName = "externalColor",
name = "External color",
description = "Configure the color of external plugins",
titleSection = "pluginsColorTitle"
)
default Color externalColor()
{
return new Color(177, 156, 217, 255);
}
@Alpha
@ConfigItem(
position = 11,
keyName = "pvmColor",
name = "PVM color",
description = "Configure the color of PVM related plugins",
titleSection = "pluginsColorTitle"
)
default Color pvmColor()
{
return new Color(119, 221, 119, 255);
}
@Alpha
@ConfigItem(
position = 12,
keyName = "pvpColor",
name = "PVP color",
description = "Configure the color of PVP related plugins",
titleSection = "pluginsColorTitle"
)
default Color pvpColor()
{
return new Color(255, 105, 97, 255);
}
@Alpha
@ConfigItem(
position = 13,
keyName = "skillingColor",
name = "Skilling color",
description = "Configure the color of Skilling related plugins",
titleSection = "pluginsColorTitle"
)
default Color skillingColor()
{
return new Color(252, 252, 100, 255);
}
@Alpha
@ConfigItem(
position = 14,
keyName = "utilityColor",
name = "Utility color",
description = "Configure the color of Utility related plugins",
titleSection = "pluginsColorTitle"
)
default Color utilityColor()
{
return new Color(144, 212, 237, 255);
}
}

View File

@@ -24,168 +24,64 @@
*/ */
package net.runelite.client.plugins.pluginsorter; package net.runelite.client.plugins.pluginsorter;
import com.google.common.collect.ImmutableList;
import com.google.inject.Provides;
import java.awt.Color;
import java.util.Comparator;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import net.runelite.api.events.ConfigChanged;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.events.PluginChanged;
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.PluginType;
import net.runelite.client.plugins.config.ConfigPanel;
import net.runelite.client.plugins.config.PluginListItem;
@PluginDescriptor( @PluginDescriptor(
name = "Plugin Organizer", name = "Plugin Organizer",
description = "Hides and colors 3rd party plugins for better control", hidden = true
tags = {"plugins", "organizer"},
type = PluginType.PLUGIN_ORGANIZER
) )
@Singleton @Singleton
public class PluginSorterPlugin extends Plugin public class PluginSorterPlugin extends Plugin
{ {
@Inject @Inject
private PluginSorterConfig config; private ConfigManager configManager;
@Inject /**
private EventBus eventBus; * Migrates configs from plugin organizer to the OpenOSRS global plugin and deletes the old config values.
* This method should be removed after a reasonable amount of time.
private PluginSorterConfig.SortStyle pluginSortMode; */
private Color externalColor; @Deprecated
private Color pvmColor; private void migrateConfigs()
private Color pvpColor;
private Color skillingColor;
private Color utilityColor;
private final ImmutableList<PluginType> definedOrder = ImmutableList.of(PluginType.IMPORTANT, PluginType.EXTERNAL, PluginType.PVM, PluginType.SKILLING, PluginType.PVP, PluginType.UTILITY, PluginType.GENERAL_USE, PluginType.PLUGIN_ORGANIZER);
private final Comparator<PluginListItem> pluginTypeComparator = Comparator.comparing(plugin ->
{ {
PluginType type = PluginType.GENERAL_USE; migrateConfig("pluginsorter", "pluginSortMode");
Plugin sortPlugin = plugin.getPlugin(); migrateConfig("pluginsorter", "hidePlugins");
if (sortPlugin != null) migrateConfig("pluginsorter", "hideExternalPlugins");
{ migrateConfig("pluginsorter", "hidePvmPlugins");
type = sortPlugin.getClass().getAnnotation(PluginDescriptor.class).type(); migrateConfig("pluginsorter", "hideSkillingPlugins");
} migrateConfig("pluginsorter", "hidePvpPlugins");
else if (plugin.configDescriptor.getGroup().value().equals("openosrs") || plugin.configDescriptor.getGroup().value().equals("runelite")) migrateConfig("pluginsorter", "hideUtilityPlugins");
{ migrateConfig("pluginsorter", "externalColor");
type = PluginType.IMPORTANT; migrateConfig("pluginsorter", "pvmColor");
} migrateConfig("pluginsorter", "pvpColor");
migrateConfig("pluginsorter", "skillingColor");
migrateConfig("pluginsorter", "utilityColor");
}
return definedOrder.indexOf(type); /**
}); * Wrapper for migrating individual config options
* This method should be removed after a reasonable amount of time.
@Provides *
PluginSorterConfig provideConfig(ConfigManager configManager) * @param group old group name
* @param key key name to migrate
*/
@Deprecated
private void migrateConfig(String group, String key)
{ {
return configManager.getConfig(PluginSorterConfig.class); String value = configManager.getConfiguration(group, key);
if (value != null)
{
configManager.setConfiguration("openosrs", key, value);
configManager.unsetConfiguration(group, key);
}
} }
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
updateConfig(); migrateConfigs();
addSubscriptions();
updatePlugins();
}
@Override
protected void shutDown() throws Exception
{
eventBus.unregister(this);
}
private void addSubscriptions()
{
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
eventBus.subscribe(PluginChanged.class, this, this::onPluginChanged);
}
private void onPluginChanged(PluginChanged pluginChanged)
{
validatePlugins();
}
private void validatePlugins()
{
updatePlugins();
}
private void onConfigChanged(ConfigChanged configChanged)
{
if (!configChanged.getGroup().equals("pluginsorter"))
{
return;
}
updateConfig();
updatePlugins();
}
private void updatePlugins()
{
boolean hidePlugins = config.hidePlugins();
boolean hidePvmPlugins = config.hidePvmPlugins();
boolean hidePvpPlugins = config.hidePvpPlugins();
boolean hideSkillingPlugins = config.hideSkillingPlugins();
boolean hideUtilityPlugins = config.hideUtilityPlugins();
boolean hideExternalPlugins = config.hideExternalPlugins();
for (PluginListItem pli : ConfigPanel.pluginList)
{
if (pli.getPlugin() != null)
{
switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type())
{
case EXTERNAL:
pli.nameLabel.setForeground(this.externalColor);
pli.setHidden(hidePlugins || hideExternalPlugins);
break;
case PVM:
pli.nameLabel.setForeground(this.pvmColor);
pli.setHidden(hidePlugins || hidePvmPlugins);
break;
case PVP:
pli.nameLabel.setForeground(this.pvpColor);
pli.setHidden(hidePlugins || hidePvpPlugins);
break;
case SKILLING:
pli.nameLabel.setForeground(this.skillingColor);
pli.setHidden(hidePlugins || hideSkillingPlugins);
break;
case UTILITY:
pli.nameLabel.setForeground(this.utilityColor);
pli.setHidden(hidePlugins || hideUtilityPlugins);
break;
default:
pli.nameLabel.setForeground(Color.WHITE);
break;
}
}
}
if (this.pluginSortMode == PluginSorterConfig.SortStyle.CATEGORY)
{
ConfigPanel.pluginList.sort(pluginTypeComparator.thenComparing(PluginListItem::getName));
}
else
{
ConfigPanel.pluginList.sort(Comparator.comparing(PluginListItem::getName));
}
}
private void updateConfig()
{
this.pluginSortMode = config.pluginSortMode();
this.externalColor = config.externalColor();
this.pvmColor = config.pvmColor();
this.pvpColor = config.pvpColor();
this.skillingColor = config.skillingColor();
this.utilityColor = config.utilityColor();
} }
} }