Plugins can now accept colors (not my code)

This commit is contained in:
Giovanni Ruddy Gazivoda
2019-04-19 03:20:27 -04:00
parent 09d2b056f1
commit 8e094f7386
2 changed files with 44 additions and 41 deletions

View File

@@ -130,7 +130,7 @@ public class ConfigPanel extends PluginPanel
} }
ConfigPanel(PluginManager pluginManager, ConfigManager configManager, ScheduledExecutorService executorService, ConfigPanel(PluginManager pluginManager, ConfigManager configManager, ScheduledExecutorService executorService,
RuneLiteConfig runeLiteConfig, ChatColorConfig chatColorConfig) RuneLiteConfig runeLiteConfig, ChatColorConfig chatColorConfig)
{ {
super(false); super(false);
this.pluginManager = pluginManager; this.pluginManager = pluginManager;
@@ -195,28 +195,28 @@ public class ConfigPanel extends PluginPanel
// populate pluginList with all non-hidden plugins // populate pluginList with all non-hidden plugins
pluginManager.getPlugins().stream() pluginManager.getPlugins().stream()
.filter(plugin -> !plugin.getClass().getAnnotation(PluginDescriptor.class).hidden()) .filter(plugin -> !plugin.getClass().getAnnotation(PluginDescriptor.class).hidden())
.forEach(plugin -> .forEach(plugin ->
{ {
final PluginDescriptor descriptor = plugin.getClass().getAnnotation(PluginDescriptor.class); final PluginDescriptor descriptor = plugin.getClass().getAnnotation(PluginDescriptor.class);
final Config config = pluginManager.getPluginConfigProxy(plugin); final Config config = pluginManager.getPluginConfigProxy(plugin);
final ConfigDescriptor configDescriptor = config == null ? null : configManager.getConfigDescriptor(config); final ConfigDescriptor configDescriptor = config == null ? null : configManager.getConfigDescriptor(config);
final PluginListItem listItem = new PluginListItem(this, plugin, descriptor, config, configDescriptor); final PluginListItem listItem = new PluginListItem(this, plugin, descriptor, config, configDescriptor);
listItem.setPinned(pinnedPlugins.contains(listItem.getName())); listItem.setPinned(pinnedPlugins.contains(listItem.getName()));
pluginList.add(listItem); pluginList.add(listItem);
}); });
// add special entries for core client configurations // add special entries for core client configurations
final PluginListItem runeLite = new PluginListItem(this, runeLiteConfig, final PluginListItem runeLite = new PluginListItem(this, runeLiteConfig,
configManager.getConfigDescriptor(runeLiteConfig), configManager.getConfigDescriptor(runeLiteConfig),
RUNELITE_PLUGIN, "RuneLite client settings", "client"); RUNELITE_PLUGIN, "RuneLite client settings", "client");
runeLite.setPinned(pinnedPlugins.contains(RUNELITE_PLUGIN)); runeLite.setPinned(pinnedPlugins.contains(RUNELITE_PLUGIN));
pluginList.add(runeLite); pluginList.add(runeLite);
final PluginListItem chatColor = new PluginListItem(this, chatColorConfig, final PluginListItem chatColor = new PluginListItem(this, chatColorConfig,
configManager.getConfigDescriptor(chatColorConfig), configManager.getConfigDescriptor(chatColorConfig),
CHAT_COLOR_PLUGIN, "Recolor chat text", "colour", "messages"); CHAT_COLOR_PLUGIN, "Recolor chat text", "colour", "messages");
chatColor.setPinned(pinnedPlugins.contains(CHAT_COLOR_PLUGIN)); chatColor.setPinned(pinnedPlugins.contains(CHAT_COLOR_PLUGIN));
pluginList.add(chatColor); pluginList.add(chatColor);
@@ -310,7 +310,8 @@ 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(Color.WHITE);
title.setToolTipText("<html>" + name + ":<br>" + listItem.getDescription() + "</html>"); title.setText("<html>" + name +"</html>");
title.setToolTipText("<html>" + ":<br>" + listItem.getDescription() + "</html>");
topPanel.add(title); topPanel.add(title);
for (ConfigItemDescriptor cid : cd.getItems()) for (ConfigItemDescriptor cid : cd.getItems())
@@ -421,7 +422,7 @@ public class ConfigPanel extends PluginPanel
public void mouseClicked(MouseEvent e) public void mouseClicked(MouseEvent e)
{ {
RuneliteColorPicker colorPicker = new RuneliteColorPicker(SwingUtilities.windowForComponent(ConfigPanel.this), RuneliteColorPicker colorPicker = new RuneliteColorPicker(SwingUtilities.windowForComponent(ConfigPanel.this),
colorPickerBtn.getBackground(), cid.getItem().name(), cid.getAlpha() == null); colorPickerBtn.getBackground(), cid.getItem().name(), cid.getAlpha() == null);
colorPicker.setLocation(getLocationOnScreen()); colorPicker.setLocation(getLocationOnScreen());
colorPicker.setOnColorChange(c -> colorPicker.setOnColorChange(c ->
{ {
@@ -467,7 +468,7 @@ public class ConfigPanel extends PluginPanel
heightSpinnerTextField.setColumns(4); heightSpinnerTextField.setColumns(4);
ChangeListener listener = e -> ChangeListener listener = e ->
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), widthSpinner.getValue() + "x" + heightSpinner.getValue()); configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), widthSpinner.getValue() + "x" + heightSpinner.getValue());
widthSpinner.addChangeListener(listener); widthSpinner.addChangeListener(listener);
heightSpinner.addChangeListener(listener); heightSpinner.addChangeListener(listener);
@@ -512,8 +513,8 @@ public class ConfigPanel extends PluginPanel
if (cid.getType() == Keybind.class || cid.getType() == ModifierlessKeybind.class) if (cid.getType() == Keybind.class || cid.getType() == ModifierlessKeybind.class)
{ {
Keybind startingValue = configManager.getConfiguration(cd.getGroup().value(), Keybind startingValue = configManager.getConfiguration(cd.getGroup().value(),
cid.getItem().keyName(), cid.getItem().keyName(),
(Class<? extends Keybind>) cid.getType()); (Class<? extends Keybind>) cid.getType());
HotkeyButton button = new HotkeyButton(startingValue, cid.getType() == ModifierlessKeybind.class); HotkeyButton button = new HotkeyButton(startingValue, cid.getType() == ModifierlessKeybind.class);
@@ -536,8 +537,8 @@ public class ConfigPanel extends PluginPanel
resetButton.addActionListener((e) -> resetButton.addActionListener((e) ->
{ {
final int result = JOptionPane.showOptionDialog(resetButton, "Are you sure you want to reset this plugin's configuration?", final int result = JOptionPane.showOptionDialog(resetButton, "Are you sure you want to reset this plugin's configuration?",
"Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, "Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
null, new String[]{"Yes", "No"}, "No"); null, new String[]{"Yes", "No"}, "No");
if (result == JOptionPane.YES_OPTION) if (result == JOptionPane.YES_OPTION)
{ {
@@ -564,8 +565,8 @@ public class ConfigPanel extends PluginPanel
if (!Strings.isNullOrEmpty(configItem.warning())) if (!Strings.isNullOrEmpty(configItem.warning()))
{ {
final int result = JOptionPane.showOptionDialog(component, configItem.warning(), final int result = JOptionPane.showOptionDialog(component, configItem.warning(),
"Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, "Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
null, new String[]{"Yes", "No"}, "No"); null, new String[]{"Yes", "No"}, "No");
if (result != JOptionPane.YES_OPTION) if (result != JOptionPane.YES_OPTION)
{ {
@@ -659,9 +660,9 @@ public class ConfigPanel extends PluginPanel
void savePinnedPlugins() void savePinnedPlugins()
{ {
final String value = pluginList.stream() final String value = pluginList.stream()
.filter(PluginListItem::isPinned) .filter(PluginListItem::isPinned)
.map(PluginListItem::getName) .map(PluginListItem::getName)
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
configManager.setConfiguration(RUNELITE_GROUP_NAME, PINNED_PLUGINS_CONFIG_KEY, value); configManager.setConfiguration(RUNELITE_GROUP_NAME, PINNED_PLUGINS_CONFIG_KEY, value);
} }

View File

@@ -99,17 +99,17 @@ class PluginListItem extends JPanel
ON_STAR = new ImageIcon(onStar); ON_STAR = new ImageIcon(onStar);
CONFIG_ICON_HOVER = new ImageIcon(ImageUtil.grayscaleOffset(configIcon, -100)); CONFIG_ICON_HOVER = new ImageIcon(ImageUtil.grayscaleOffset(configIcon, -100));
BufferedImage offSwitcherImage = ImageUtil.flipImage( BufferedImage offSwitcherImage = ImageUtil.flipImage(
ImageUtil.grayscaleOffset( ImageUtil.grayscaleOffset(
ImageUtil.grayscaleImage(onSwitcher), ImageUtil.grayscaleImage(onSwitcher),
0.61f 0.61f
), ),
true, true,
false false
); );
OFF_SWITCHER = new ImageIcon(offSwitcherImage); OFF_SWITCHER = new ImageIcon(offSwitcherImage);
BufferedImage offStar = ImageUtil.grayscaleOffset( BufferedImage offStar = ImageUtil.grayscaleOffset(
ImageUtil.grayscaleImage(onStar), ImageUtil.grayscaleImage(onStar),
0.77f 0.77f
); );
OFF_STAR = new ImageIcon(offStar); OFF_STAR = new ImageIcon(offStar);
} }
@@ -121,23 +121,23 @@ class PluginListItem extends JPanel
* if there is no configuration associated with the plugin. * if there is no configuration associated with the plugin.
*/ */
PluginListItem(ConfigPanel configPanel, Plugin plugin, PluginDescriptor descriptor, PluginListItem(ConfigPanel configPanel, Plugin plugin, PluginDescriptor descriptor,
@Nullable Config config, @Nullable ConfigDescriptor configDescriptor) @Nullable Config config, @Nullable ConfigDescriptor configDescriptor)
{ {
this(configPanel, plugin, config, configDescriptor, this(configPanel, plugin, config, configDescriptor,
descriptor.name(), descriptor.description(), descriptor.tags()); descriptor.name(), descriptor.description(), descriptor.tags());
} }
/** /**
* Creates a new {@code PluginListItem} for a core configuration. * Creates a new {@code PluginListItem} for a core configuration.
*/ */
PluginListItem(ConfigPanel configPanel, Config config, ConfigDescriptor configDescriptor, PluginListItem(ConfigPanel configPanel, Config config, ConfigDescriptor configDescriptor,
String name, String description, String... tags) String name, String description, String... tags)
{ {
this(configPanel, null, config, configDescriptor, name, description, tags); this(configPanel, null, config, configDescriptor, name, description, tags);
} }
private PluginListItem(ConfigPanel configPanel, @Nullable Plugin plugin, @Nullable Config config, private PluginListItem(ConfigPanel configPanel, @Nullable Plugin plugin, @Nullable Config config,
@Nullable ConfigDescriptor configDescriptor, String name, String description, String... tags) @Nullable ConfigDescriptor configDescriptor, String name, String description, String... tags)
{ {
this.configPanel = configPanel; this.configPanel = configPanel;
this.plugin = plugin; this.plugin = plugin;
@@ -153,8 +153,10 @@ class PluginListItem extends JPanel
setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH, 20)); setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH, 20));
JLabel nameLabel = new JLabel(name); JLabel nameLabel = new JLabel(name);
nameLabel.setText("<html>" + name +"</html>");
nameLabel.setForeground(Color.WHITE); nameLabel.setForeground(Color.WHITE);
if (!description.isEmpty()) if (!description.isEmpty())
{ {
nameLabel.setToolTipText("<html>" + name + ":<br>" + description + "</html>"); nameLabel.setToolTipText("<html>" + name + ":<br>" + description + "</html>");
@@ -260,7 +262,7 @@ class PluginListItem extends JPanel
for (String term : searchTerms) for (String term : searchTerms)
{ {
if (keywords.stream().noneMatch((t) -> t.contains(term) || if (keywords.stream().noneMatch((t) -> t.contains(term) ||
DISTANCE.apply(t, term) > 0.9)) DISTANCE.apply(t, term) > 0.9))
{ {
return false; return false;
} }