pluginsorter: Add ability to hide per category

This commit is contained in:
Owain van Brakel
2019-10-11 06:10:10 +02:00
parent 1f5911b48c
commit 82ced11a61
4 changed files with 134 additions and 81 deletions

View File

@@ -491,14 +491,14 @@ public class ConfigPanel extends PluginPanel
{
if (text.isEmpty())
{
pluginList.stream().filter(item -> pinned == item.isPinned()).forEach(mainPanel::add);
pluginList.stream().filter(item -> pinned == item.isPinned() && !item.isHidden()).forEach(mainPanel::add);
return;
}
final String[] searchTerms = text.toLowerCase().split(" ");
pluginList.forEach(listItem ->
{
if (pinned == listItem.isPinned() && listItem.matchesSearchTerms(searchTerms))
if (pinned == listItem.isPinned() && listItem.matchesSearchTerms(searchTerms) && !listItem.isHidden())
{
mainPanel.add(listItem);
}

View File

@@ -93,6 +93,9 @@ public class PluginListItem extends JPanel
@Getter
private boolean isPinned = false;
@Getter
private boolean isHidden = false;
static
{
BufferedImage configIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_edit_icon.png");
@@ -255,6 +258,11 @@ public class PluginListItem extends JPanel
pinButton.setToolTipText(pinned ? "Unpin plugin" : "Pin plugin");
}
public void setHidden(boolean hidden)
{
isHidden = hidden;
}
private void updateToggleButton(IconButton button)
{
button.setIcon(isPluginEnabled ? ON_SWITCHER : OFF_SWITCHER);

View File

@@ -29,29 +29,119 @@ 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
{
boolean pluginsHidden = false;
@ConfigTitleSection(
keyName = "hidePluginsTitle",
name = "Hiding",
description = "",
position = 0
)
default Title hidePluginsTitle()
{
return new Title();
}
@ConfigItem(
position = 0,
position = 1,
keyName = "hidePlugins",
name = "Hide Plugins",
description = "Hides all 3rd party plugins if checked"
description = "Hides all OpenOSRS plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePvmPlugins || hidePvpPlugins || hideSkillingPlugins || hideUtilityPlugins || hideExternalPlugins"
)
default boolean hidePlugins()
{
return pluginsHidden;
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 = 2,
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 = 4,
keyName = "hideSkillingPlugins",
name = "Hide Skillinh Plugins",
description = "Hides all OpenOSRS skilling plugins if checked",
titleSection = "hidePluginsTitle",
hide = "hidePlugins"
)
default boolean hideSkillingPlugins()
{
return false;
}
@ConfigItem(
position = 3,
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 = 5,
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 = 7
)
default Title pluginsColorTitle()
{
return new Title();
}
@Alpha
@ConfigItem(
position = 1,
position = 8,
keyName = "externalColor",
name = "External color",
description = "Configure the color of external plugins"
description = "Configure the color of external plugins",
titleSection = "pluginsColorTitle"
)
default Color externalColor()
{
@@ -60,10 +150,11 @@ public interface PluginSorterConfig extends Config
@Alpha
@ConfigItem(
position = 2,
position = 9,
keyName = "pvmColor",
name = "PVM color",
description = "Configure the color of PVM related plugins"
description = "Configure the color of PVM related plugins",
titleSection = "pluginsColorTitle"
)
default Color pvmColor()
{
@@ -72,10 +163,11 @@ public interface PluginSorterConfig extends Config
@Alpha
@ConfigItem(
position = 3,
position = 10,
keyName = "pvpColor",
name = "PVP color",
description = "Configure the color of PVP related plugins"
description = "Configure the color of PVP related plugins",
titleSection = "pluginsColorTitle"
)
default Color pvpColor()
{
@@ -84,10 +176,11 @@ public interface PluginSorterConfig extends Config
@Alpha
@ConfigItem(
position = 4,
position = 11,
keyName = "skillingColor",
name = "Skilling color",
description = "Configure the color of Skilling related plugins"
description = "Configure the color of Skilling related plugins",
titleSection = "pluginsColorTitle"
)
default Color skillingColor()
{
@@ -96,10 +189,11 @@ public interface PluginSorterConfig extends Config
@Alpha
@ConfigItem(
position = 5,
position = 12,
keyName = "utilityColor",
name = "Utility color",
description = "Configure the color of Utility related plugins"
description = "Configure the color of Utility related plugins",
titleSection = "pluginsColorTitle"
)
default Color utilityColor()
{

View File

@@ -26,9 +26,6 @@ package net.runelite.client.plugins.pluginsorter;
import com.google.inject.Provides;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import net.runelite.api.events.ConfigChanged;
@@ -50,16 +47,12 @@ import net.runelite.client.plugins.config.PluginListItem;
@Singleton
public class PluginSorterPlugin extends Plugin
{
//Cache the hidden plugins
private static final List<PluginListItem> removedPlugins = new ArrayList<>();
@Inject
private PluginSorterConfig config;
@Inject
private EventBus eventBus;
private boolean hidePlugins;
private Color externalColor;
private Color pvmColor;
private Color pvpColor;
@@ -78,7 +71,7 @@ public class PluginSorterPlugin extends Plugin
updateConfig();
addSubscriptions();
updateColors();
updatePlugins();
}
@Override
@@ -100,16 +93,7 @@ public class PluginSorterPlugin extends Plugin
private void validatePlugins()
{
if (this.hidePlugins)
{
hidePlugins();
}
else
{
showPlugins();
}
updateColors();
updatePlugins();
}
private void onConfigChanged(ConfigChanged configChanged)
@@ -120,15 +104,18 @@ public class PluginSorterPlugin extends Plugin
}
updateConfig();
if (configChanged.getKey().equals("hidePlugins"))
{
validatePlugins();
}
updatePlugins();
}
private void updateColors()
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)
@@ -137,18 +124,23 @@ public class PluginSorterPlugin extends Plugin
{
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);
@@ -158,49 +150,8 @@ public class PluginSorterPlugin extends Plugin
}
}
private void hidePlugins()
{
Iterator<PluginListItem> iter = ConfigPanel.pluginList.iterator();
while (iter.hasNext())
{
PluginListItem pli = iter.next();
if (pli.getPlugin() != null)
{
switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type())
{
case PVM:
case PVP:
case SKILLING:
case UTILITY:
case EXTERNAL:
iter.remove();
removedPlugins.add(pli);
break;
case GENERAL_USE:
default:
break;
}
}
}
}
private void showPlugins()
{
List<PluginListItem> tempList = new ArrayList<>(ConfigPanel.pluginList);
if (tempList.size() > 0)
{
tempList.addAll(2, removedPlugins);
}
else
{
tempList.addAll(removedPlugins);
}
ConfigPanel.pluginList = tempList;
}
private void updateConfig()
{
this.hidePlugins = config.hidePlugins();
this.externalColor = config.externalColor();
this.pvmColor = config.pvmColor();
this.pvpColor = config.pvpColor();