pluginsorter: Make plugin sorting configurable (#1766)
This commit is contained in:
@@ -8,5 +8,6 @@ public enum PluginType
|
||||
UTILITY,
|
||||
GENERAL_USE,
|
||||
EXTERNAL,
|
||||
PLUGIN_ORGANIZER
|
||||
PLUGIN_ORGANIZER,
|
||||
IMPORTANT
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ package net.runelite.client.plugins.config;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
@@ -46,7 +45,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -107,7 +105,6 @@ import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.plugins.PluginInstantiationException;
|
||||
import net.runelite.client.plugins.PluginManager;
|
||||
import net.runelite.client.plugins.PluginType;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.DynamicGridLayout;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
@@ -320,20 +317,6 @@ public class ConfigPanel extends PluginPanel
|
||||
chatColor.nameLabel.setForeground(Color.WHITE);
|
||||
plugins.add(chatColor);
|
||||
|
||||
ImmutableList<PluginType> definedOrder = ImmutableList.of(PluginType.EXTERNAL, PluginType.PVM, PluginType.SKILLING, PluginType.PVP, PluginType.UTILITY, PluginType.GENERAL_USE, PluginType.PLUGIN_ORGANIZER);
|
||||
Comparator<PluginListItem> pluginTypeComparator = Comparator.comparing(plugin ->
|
||||
{
|
||||
PluginType type = PluginType.GENERAL_USE;
|
||||
Plugin sortPlugin = plugin.getPlugin();
|
||||
if (sortPlugin != null)
|
||||
{
|
||||
type = sortPlugin.getClass().getAnnotation(PluginDescriptor.class).type();
|
||||
}
|
||||
|
||||
return definedOrder.indexOf(type);
|
||||
});
|
||||
|
||||
plugins.sort(pluginTypeComparator.thenComparing(PluginListItem::getName));
|
||||
pluginList.addAll(plugins);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
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;
|
||||
@@ -35,11 +38,50 @@ 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 = "Hiding",
|
||||
description = "",
|
||||
position = 0
|
||||
position = 2
|
||||
)
|
||||
default Title hidePluginsTitle()
|
||||
{
|
||||
@@ -47,7 +89,7 @@ public interface PluginSorterConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 1,
|
||||
position = 3,
|
||||
keyName = "hidePlugins",
|
||||
name = "Hide Plugins",
|
||||
description = "Hides all OpenOSRS plugins if checked",
|
||||
@@ -60,7 +102,7 @@ public interface PluginSorterConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 6,
|
||||
position = 4,
|
||||
keyName = "hideExternalPlugins",
|
||||
name = "Hide External Plugins",
|
||||
description = "Hides all OpenOSRS external plugins if checked",
|
||||
@@ -73,7 +115,7 @@ public interface PluginSorterConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 2,
|
||||
position = 5,
|
||||
keyName = "hidePvmPlugins",
|
||||
name = "Hide PvM Plugins",
|
||||
description = "Hides all OpenOSRS PvM plugins if checked",
|
||||
@@ -86,7 +128,7 @@ public interface PluginSorterConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 4,
|
||||
position = 6,
|
||||
keyName = "hideSkillingPlugins",
|
||||
name = "Hide Skillinh Plugins",
|
||||
description = "Hides all OpenOSRS skilling plugins if checked",
|
||||
@@ -99,7 +141,7 @@ public interface PluginSorterConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 3,
|
||||
position = 7,
|
||||
keyName = "hidePvpPlugins",
|
||||
name = "Hide PvP Plugins",
|
||||
description = "Hides all OpenOSRS Pvp plugins if checked",
|
||||
@@ -112,7 +154,7 @@ public interface PluginSorterConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 5,
|
||||
position = 8,
|
||||
keyName = "hideUtilityPlugins",
|
||||
name = "Hide Utility Plugins",
|
||||
description = "Hides all OpenOSRS utility plugins if checked",
|
||||
@@ -128,7 +170,7 @@ public interface PluginSorterConfig extends Config
|
||||
keyName = "pluginsColorTitle",
|
||||
name = "Colors",
|
||||
description = "",
|
||||
position = 7
|
||||
position = 9
|
||||
)
|
||||
default Title pluginsColorTitle()
|
||||
{
|
||||
@@ -137,7 +179,7 @@ public interface PluginSorterConfig extends Config
|
||||
|
||||
@Alpha
|
||||
@ConfigItem(
|
||||
position = 8,
|
||||
position = 10,
|
||||
keyName = "externalColor",
|
||||
name = "External color",
|
||||
description = "Configure the color of external plugins",
|
||||
@@ -150,7 +192,7 @@ public interface PluginSorterConfig extends Config
|
||||
|
||||
@Alpha
|
||||
@ConfigItem(
|
||||
position = 9,
|
||||
position = 11,
|
||||
keyName = "pvmColor",
|
||||
name = "PVM color",
|
||||
description = "Configure the color of PVM related plugins",
|
||||
@@ -163,7 +205,7 @@ public interface PluginSorterConfig extends Config
|
||||
|
||||
@Alpha
|
||||
@ConfigItem(
|
||||
position = 10,
|
||||
position = 12,
|
||||
keyName = "pvpColor",
|
||||
name = "PVP color",
|
||||
description = "Configure the color of PVP related plugins",
|
||||
@@ -176,7 +218,7 @@ public interface PluginSorterConfig extends Config
|
||||
|
||||
@Alpha
|
||||
@ConfigItem(
|
||||
position = 11,
|
||||
position = 13,
|
||||
keyName = "skillingColor",
|
||||
name = "Skilling color",
|
||||
description = "Configure the color of Skilling related plugins",
|
||||
@@ -189,7 +231,7 @@ public interface PluginSorterConfig extends Config
|
||||
|
||||
@Alpha
|
||||
@ConfigItem(
|
||||
position = 12,
|
||||
position = 14,
|
||||
keyName = "utilityColor",
|
||||
name = "Utility color",
|
||||
description = "Configure the color of Utility related plugins",
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
*/
|
||||
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.Singleton;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
@@ -53,12 +55,30 @@ public class PluginSorterPlugin extends Plugin
|
||||
@Inject
|
||||
private EventBus eventBus;
|
||||
|
||||
private PluginSorterConfig.SortStyle pluginSortMode;
|
||||
private Color externalColor;
|
||||
private Color pvmColor;
|
||||
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;
|
||||
Plugin sortPlugin = plugin.getPlugin();
|
||||
if (sortPlugin != null)
|
||||
{
|
||||
type = sortPlugin.getClass().getAnnotation(PluginDescriptor.class).type();
|
||||
}
|
||||
else if (plugin.configDescriptor.getGroup().value().equals("openosrs") || plugin.configDescriptor.getGroup().value().equals("runelite"))
|
||||
{
|
||||
type = PluginType.IMPORTANT;
|
||||
}
|
||||
|
||||
return definedOrder.indexOf(type);
|
||||
});
|
||||
|
||||
@Provides
|
||||
PluginSorterConfig provideConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -148,10 +168,20 @@ public class PluginSorterPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user