Merge pull request #2943 from open-osrs/config-ugh
This commit is contained in:
@@ -65,6 +65,14 @@ public @interface ConfigItem
|
|||||||
|
|
||||||
String hideValue() default "";
|
String hideValue() default "";
|
||||||
|
|
||||||
|
String enabledBy() default "";
|
||||||
|
|
||||||
|
String enabledByValue() default "";
|
||||||
|
|
||||||
|
String disabledBy() default "";
|
||||||
|
|
||||||
|
String disabledByValue() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this to indicate the enum class that is going to be used in the multiple select config.
|
* Use this to indicate the enum class that is going to be used in the multiple select config.
|
||||||
* This implementation made debugging problems with multiple selects a lot easier
|
* This implementation made debugging problems with multiple selects a lot easier
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ import java.util.concurrent.Future;
|
|||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -97,6 +98,7 @@ import net.runelite.client.events.ClientShutdown;
|
|||||||
import net.runelite.client.events.ConfigChanged;
|
import net.runelite.client.events.ConfigChanged;
|
||||||
import net.runelite.client.events.RuneScapeProfileChanged;
|
import net.runelite.client.events.RuneScapeProfileChanged;
|
||||||
import net.runelite.client.plugins.OPRSExternalPluginManager;
|
import net.runelite.client.plugins.OPRSExternalPluginManager;
|
||||||
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.util.ColorUtil;
|
import net.runelite.client.util.ColorUtil;
|
||||||
import net.runelite.http.api.config.ConfigClient;
|
import net.runelite.http.api.config.ConfigClient;
|
||||||
import net.runelite.http.api.config.ConfigEntry;
|
import net.runelite.http.api.config.ConfigEntry;
|
||||||
@@ -133,6 +135,7 @@ public class ConfigManager
|
|||||||
|
|
||||||
private final ConfigInvocationHandler handler = new ConfigInvocationHandler(this);
|
private final ConfigInvocationHandler handler = new ConfigInvocationHandler(this);
|
||||||
private final Map<String, String> pendingChanges = new HashMap<>();
|
private final Map<String, String> pendingChanges = new HashMap<>();
|
||||||
|
private final Map<String, Consumer<? super Plugin>> consumers = new HashMap<>();
|
||||||
|
|
||||||
private Properties properties = new Properties();
|
private Properties properties = new Properties();
|
||||||
|
|
||||||
@@ -304,6 +307,8 @@ public class ConfigManager
|
|||||||
|
|
||||||
private synchronized void loadFromFile()
|
private synchronized void loadFromFile()
|
||||||
{
|
{
|
||||||
|
consumers.clear();
|
||||||
|
|
||||||
Properties newProperties = new Properties();
|
Properties newProperties = new Properties();
|
||||||
try (FileInputStream in = new FileInputStream(propertiesFile))
|
try (FileInputStream in = new FileInputStream(propertiesFile))
|
||||||
{
|
{
|
||||||
@@ -484,6 +489,12 @@ public class ConfigManager
|
|||||||
|
|
||||||
public void setConfiguration(String groupName, String key, Object value)
|
public void setConfiguration(String groupName, String key, Object value)
|
||||||
{
|
{
|
||||||
|
// do not save consumers for buttons, they cannot be changed anyway
|
||||||
|
if (value instanceof Consumer)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setConfiguration(groupName, null, key, value);
|
setConfiguration(groupName, null, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,6 +682,24 @@ public class ConfigManager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (method.getReturnType().isAssignableFrom(Consumer.class))
|
||||||
|
{
|
||||||
|
Object defaultValue;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
defaultValue = ConfigInvocationHandler.callDefaultMethod(proxy, method, null);
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
log.warn(null, ex);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("Registered consumer: {}.{}", group.value(), item.keyName());
|
||||||
|
consumers.put(group.value() + "." + item.keyName(), (Consumer) defaultValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (!method.isDefault())
|
if (!method.isDefault())
|
||||||
{
|
{
|
||||||
if (override)
|
if (override)
|
||||||
@@ -722,6 +751,7 @@ public class ConfigManager
|
|||||||
setConfiguration(group.value(), item.keyName(), valueString);
|
setConfiguration(group.value(), item.keyName(), valueString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Object stringToObject(String str, Class<?> type)
|
static Object stringToObject(String str, Class<?> type)
|
||||||
{
|
{
|
||||||
@@ -1286,4 +1316,12 @@ public class ConfigManager
|
|||||||
}
|
}
|
||||||
setConfiguration("runelite", migrationKey, 1);
|
setConfiguration("runelite", migrationKey, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a consumer from config group and key name
|
||||||
|
*/
|
||||||
|
public Consumer<? super Plugin> getConsumer(final String configGroup, final String keyName)
|
||||||
|
{
|
||||||
|
return consumers.getOrDefault(configGroup + "." + keyName, (p) -> log.error("Failed to retrieve consumer with name {}.{}", configGroup, keyName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
@@ -442,6 +443,11 @@ class ConfigPanel extends PluginPanel
|
|||||||
|
|
||||||
for (ConfigItemDescriptor cid : cd.getItems())
|
for (ConfigItemDescriptor cid : cd.getItems())
|
||||||
{
|
{
|
||||||
|
if (!hideUnhide(cid))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
JPanel item = new JPanel();
|
JPanel item = new JPanel();
|
||||||
item.setLayout(new BorderLayout());
|
item.setLayout(new BorderLayout());
|
||||||
item.setMinimumSize(new Dimension(PANEL_WIDTH, 0));
|
item.setMinimumSize(new Dimension(PANEL_WIDTH, 0));
|
||||||
@@ -485,6 +491,20 @@ class ConfigPanel extends PluginPanel
|
|||||||
item.add(checkbox, BorderLayout.EAST);
|
item.add(checkbox, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cid.getType().isAssignableFrom(Consumer.class))
|
||||||
|
{
|
||||||
|
item.remove(configEntryName);
|
||||||
|
|
||||||
|
JButton button = new JButton(cid.getItem().name());
|
||||||
|
button.addActionListener((e) ->
|
||||||
|
{
|
||||||
|
log.debug("Running consumer: {}.{}", cd.getGroup().value(), cid.getItem().keyName());
|
||||||
|
configManager.getConsumer(cd.getGroup().value(), cid.getItem().keyName()).accept(pluginConfig.getPlugin());
|
||||||
|
});
|
||||||
|
|
||||||
|
item.add(button, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
if (cid.getType() == int.class)
|
if (cid.getType() == int.class)
|
||||||
{
|
{
|
||||||
int value = Integer.parseInt(configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName()));
|
int value = Integer.parseInt(configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName()));
|
||||||
@@ -780,7 +800,7 @@ class ConfigPanel extends PluginPanel
|
|||||||
backButton.addActionListener(e -> pluginList.getMuxer().popState());
|
backButton.addActionListener(e -> pluginList.getMuxer().popState());
|
||||||
mainPanel.add(backButton);
|
mainPanel.add(backButton);
|
||||||
|
|
||||||
hideUnhide();
|
revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean parse(ConfigItem item, String value)
|
private Boolean parse(ConfigItem item, String value)
|
||||||
@@ -845,7 +865,7 @@ class ConfigPanel extends PluginPanel
|
|||||||
|
|
||||||
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), finalEnumSet);
|
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), finalEnumSet);
|
||||||
|
|
||||||
hideUnhide();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeConfiguration(Component component, ConfigDescriptor cd, ConfigItemDescriptor cid)
|
private void changeConfiguration(Component component, ConfigDescriptor cd, ConfigItemDescriptor cid)
|
||||||
@@ -896,7 +916,8 @@ class ConfigPanel extends PluginPanel
|
|||||||
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), hotkeyButton.getValue());
|
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), hotkeyButton.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
hideUnhide();
|
enableDisable(component, cid);
|
||||||
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -946,12 +967,10 @@ class ConfigPanel extends PluginPanel
|
|||||||
return menuItem;
|
return menuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideUnhide()
|
private boolean hideUnhide(ConfigItemDescriptor cid)
|
||||||
{
|
{
|
||||||
ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
|
ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
|
||||||
|
|
||||||
for (ConfigItemDescriptor cid : cd.getItems())
|
|
||||||
{
|
|
||||||
boolean unhide = cid.getItem().hidden();
|
boolean unhide = cid.getItem().hidden();
|
||||||
boolean hide = !cid.getItem().hide().isEmpty();
|
boolean hide = !cid.getItem().hide().isEmpty();
|
||||||
|
|
||||||
@@ -1007,17 +1026,53 @@ class ConfigPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component comp = findComponentByName(mainPanel, cid.getItem().keyName());
|
return (!unhide || show) && (!hide || !show);
|
||||||
|
}
|
||||||
|
|
||||||
if (comp != null)
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableDisable(Component component, ConfigItemDescriptor cid)
|
||||||
{
|
{
|
||||||
comp.setVisible((!unhide || show) && (!hide || !show));
|
ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
revalidate();
|
if (component instanceof JCheckBox)
|
||||||
repaint();
|
{
|
||||||
|
JCheckBox checkbox = (JCheckBox) component;
|
||||||
|
|
||||||
|
for (ConfigItemDescriptor cid2 : cd.getItems())
|
||||||
|
{
|
||||||
|
if (checkbox.isSelected())
|
||||||
|
{
|
||||||
|
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
|
||||||
|
}
|
||||||
|
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (component instanceof JComboBox)
|
||||||
|
{
|
||||||
|
JComboBox jComboBox = (JComboBox) component;
|
||||||
|
|
||||||
|
for (ConfigItemDescriptor cid2 : cd.getItems())
|
||||||
|
{
|
||||||
|
String changedVal = ((Enum) jComboBox.getSelectedItem()).name();
|
||||||
|
|
||||||
|
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()) && cid2.getItem().enabledByValue().equals(changedVal))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
|
||||||
|
}
|
||||||
|
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()) && cid2.getItem().disabledByValue().equals(changedVal))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String htmlLabel(String key, String value)
|
private static String htmlLabel(String key, String value)
|
||||||
|
|||||||
@@ -137,18 +137,13 @@ public class DynamicGridLayout extends GridLayout
|
|||||||
{
|
{
|
||||||
int i = r * ncols + c;
|
int i = r * ncols + c;
|
||||||
|
|
||||||
Component component = parent.getComponent(i);
|
|
||||||
|
|
||||||
if (component.isVisible())
|
|
||||||
{
|
|
||||||
if (i < ncomponents)
|
if (i < ncomponents)
|
||||||
{
|
{
|
||||||
component.setBounds(x, y, w[c], h[r]);
|
parent.getComponent(i).setBounds(x, y, w[c], h[r]);
|
||||||
}
|
}
|
||||||
|
|
||||||
y += h[r] + vgap;
|
y += h[r] + vgap;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
x += w[c] + hgap;
|
x += w[c] + hgap;
|
||||||
}
|
}
|
||||||
@@ -163,7 +158,7 @@ public class DynamicGridLayout extends GridLayout
|
|||||||
*/
|
*/
|
||||||
private Dimension calculateSize(final Container parent, final Function<Component, Dimension> sizer)
|
private Dimension calculateSize(final Container parent, final Function<Component, Dimension> sizer)
|
||||||
{
|
{
|
||||||
final int ncomponents = getVisibleComponents(parent);;
|
final int ncomponents = parent.getComponentCount();
|
||||||
int nrows = getRows();
|
int nrows = getRows();
|
||||||
int ncols = getColumns();
|
int ncols = getColumns();
|
||||||
|
|
||||||
@@ -220,19 +215,4 @@ public class DynamicGridLayout extends GridLayout
|
|||||||
insets.left + insets.right + nw + (ncols - 1) * getHgap(),
|
insets.left + insets.right + nw + (ncols - 1) * getHgap(),
|
||||||
insets.top + insets.bottom + nh + (nrows - 1) * getVgap());
|
insets.top + insets.bottom + nh + (nrows - 1) * getVgap());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getVisibleComponents(Container parent)
|
|
||||||
{
|
|
||||||
int visible = 0;
|
|
||||||
|
|
||||||
for (Component c : parent.getComponents())
|
|
||||||
{
|
|
||||||
if (c.isVisible())
|
|
||||||
{
|
|
||||||
visible++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return visible;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user