Merge remote-tracking branch 'origin/master'

This commit is contained in:
Owain van Brakel
2022-01-20 00:33:57 +01:00
3 changed files with 193 additions and 41 deletions

View File

@@ -183,6 +183,18 @@ public interface Client extends GameEngine
*/ */
void stopNow(); void stopNow();
/**
* Gets the login screen world select state.
*
* @return the world select state
*/
boolean isWorldSelectOpen();
/**
* Sets the login screen world select state.
*/
void setWorldSelectOpen(boolean open);
/** /**
* Gets the current logged in username. * Gets the current logged in username.
* *

View File

@@ -33,7 +33,6 @@ import java.awt.BasicStroke;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
@@ -112,6 +111,7 @@ import net.runelite.client.config.Range;
import net.runelite.client.config.Units; import net.runelite.client.config.Units;
import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.events.ExternalPluginsChanged; import net.runelite.client.events.ExternalPluginsChanged;
import net.runelite.client.events.PluginChanged; import net.runelite.client.events.PluginChanged;
import net.runelite.client.externalplugins.ExternalPluginManager; import net.runelite.client.externalplugins.ExternalPluginManager;
@@ -173,11 +173,13 @@ class ConfigPanel extends PluginPanel
private final ListCellRenderer<Enum<?>> listCellRenderer = new ComboBoxListRenderer<>(); private final ListCellRenderer<Enum<?>> listCellRenderer = new ComboBoxListRenderer<>();
private final JScrollPane scrollPane;
private final FixedWidthPanel mainPanel; private final FixedWidthPanel mainPanel;
private final JLabel title; private final JLabel title;
private final PluginToggleButton pluginToggle; private final PluginToggleButton pluginToggle;
private PluginConfigurationDescriptor pluginConfig = null; private PluginConfigurationDescriptor pluginConfig = null;
private boolean skipRebuild;
@Inject @Inject
@@ -212,7 +214,7 @@ class ConfigPanel extends PluginPanel
northPanel.setLayout(new BorderLayout()); northPanel.setLayout(new BorderLayout());
northPanel.add(mainPanel, BorderLayout.NORTH); northPanel.add(mainPanel, BorderLayout.NORTH);
JScrollPane scrollPane = new JScrollPane(northPanel); scrollPane = new JScrollPane(northPanel);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(scrollPane, BorderLayout.CENTER); add(scrollPane, BorderLayout.CENTER);
@@ -274,7 +276,7 @@ class ConfigPanel extends PluginPanel
pluginToggle.setVisible(false); pluginToggle.setVisible(false);
} }
rebuild(); rebuild(false);
} }
private void toggleSection(ConfigSectionDescriptor csd, JButton button, JPanel contents) private void toggleSection(ConfigSectionDescriptor csd, JButton button, JPanel contents)
@@ -288,8 +290,10 @@ class ConfigPanel extends PluginPanel
SwingUtilities.invokeLater(contents::revalidate); SwingUtilities.invokeLater(contents::revalidate);
} }
private void rebuild() private void rebuild(boolean refresh)
{ {
int scrollBarPosition = scrollPane.getVerticalScrollBar().getValue();
mainPanel.removeAll(); mainPanel.removeAll();
ConfigDescriptor cd = pluginConfig.getConfigDescriptor(); ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
@@ -459,7 +463,7 @@ class ConfigPanel extends PluginPanel
for (ConfigItemDescriptor cid : cd.getItems()) for (ConfigItemDescriptor cid : cd.getItems())
{ {
if (!hideUnhide(cid)) if (!shouldBeHidden(cid))
{ {
continue; continue;
} }
@@ -581,7 +585,7 @@ class ConfigPanel extends PluginPanel
plugin.resetConfiguration(); plugin.resetConfiguration();
} }
rebuild(); rebuild(false);
} }
}); });
mainPanel.add(resetButton); mainPanel.add(resetButton);
@@ -590,6 +594,15 @@ class ConfigPanel extends PluginPanel
backButton.addActionListener(e -> pluginList.getMuxer().popState()); backButton.addActionListener(e -> pluginList.getMuxer().popState());
mainPanel.add(backButton); mainPanel.add(backButton);
if (refresh)
{
scrollPane.getVerticalScrollBar().setValue(scrollBarPosition);
}
else
{
scrollPane.getVerticalScrollBar().setValue(0);
}
revalidate(); revalidate();
} }
@@ -1094,11 +1107,13 @@ class ConfigPanel extends PluginPanel
if (result != JOptionPane.YES_OPTION) if (result != JOptionPane.YES_OPTION)
{ {
rebuild(); rebuild(false);
return; return;
} }
} }
skipRebuild = true;
if (component instanceof JCheckBox) if (component instanceof JCheckBox)
{ {
JCheckBox checkbox = (JCheckBox) component; JCheckBox checkbox = (JCheckBox) component;
@@ -1142,8 +1157,10 @@ class ConfigPanel extends PluginPanel
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), Sets.newHashSet(selectedValues)); configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), Sets.newHashSet(selectedValues));
} }
enableDisable(component, cid); if (enableDisable(component, cid) || hideUnhide(component, cd, cid))
rebuild(); {
rebuild(true);
}
} }
@Override @Override
@@ -1172,7 +1189,23 @@ class ConfigPanel extends PluginPanel
{ {
pluginList.getMuxer().popState(); pluginList.getMuxer().popState();
} }
SwingUtilities.invokeLater(this::rebuild); SwingUtilities.invokeLater(() -> rebuild(false));
}
@Subscribe
private void onConfigChanged(ConfigChanged event)
{
if (pluginConfig.getConfigDescriptor() == null)
{
return;
}
if (!skipRebuild && pluginConfig.getConfigDescriptor().getGroup().value().equals(event.getGroup()))
{
SwingUtilities.invokeLater(() -> rebuild(true));
}
skipRebuild = false;
} }
private JMenuItem createResetMenuItem(PluginConfigurationDescriptor pluginConfig, ConfigItemDescriptor configItemDescriptor) private JMenuItem createResetMenuItem(PluginConfigurationDescriptor pluginConfig, ConfigItemDescriptor configItemDescriptor)
@@ -1188,12 +1221,127 @@ class ConfigPanel extends PluginPanel
configManager.unsetConfiguration(configGroup.value(), configItem.keyName()); configManager.unsetConfiguration(configGroup.value(), configItem.keyName());
configManager.setDefaultConfiguration(pluginConfig.getConfig(), false); configManager.setDefaultConfiguration(pluginConfig.getConfig(), false);
rebuild(); rebuild(false);
}); });
return menuItem; return menuItem;
} }
private boolean hideUnhide(ConfigItemDescriptor cid) private boolean hideUnhide(Component component, ConfigDescriptor cd, ConfigItemDescriptor cid)
{
boolean rebuild = false;
if (component instanceof JCheckBox)
{
JCheckBox checkbox = (JCheckBox) component;
for (ConfigItemDescriptor cid2 : cd.getItems())
{
if (cid2.getItem().hidden() || !cid2.getItem().hide().isEmpty())
{
List<String> itemHide = Splitter
.onPattern("\\|\\|")
.trimResults()
.omitEmptyStrings()
.splitToList(String.format("%s || %s", cid2.getItem().unhide(), cid2.getItem().hide()));
if (itemHide.contains(cid.getItem().keyName()))
{
rebuild = true;
}
}
if (checkbox.isSelected())
{
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()))
{
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
rebuild = true;
}
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()))
{
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
rebuild = true;
}
}
}
}
else if (component instanceof JComboBox)
{
JComboBox jComboBox = (JComboBox) component;
for (ConfigItemDescriptor cid2 : cd.getItems())
{
if (cid2.getItem().hidden() || !cid2.getItem().hide().isEmpty())
{
List<String> itemHide = Splitter
.onPattern("\\|\\|")
.trimResults()
.omitEmptyStrings()
.splitToList(String.format("%s || %s", cid2.getItem().unhide(), cid2.getItem().hide()));
String changedVal = ((Enum) jComboBox.getSelectedItem()).name();
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()) && cid2.getItem().enabledByValue().equals(changedVal))
{
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
rebuild = true;
}
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()) && cid2.getItem().disabledByValue().equals(changedVal))
{
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
rebuild = true;
}
else if (itemHide.contains(cid.getItem().keyName()))
{
rebuild = true;
}
}
}
}
else if (component instanceof JList)
{
JList jList = (JList) component;
for (ConfigItemDescriptor cid2 : cd.getItems())
{
if (cid2.getItem().hidden() || !cid2.getItem().hide().isEmpty())
{
List<String> itemHide = Splitter
.onPattern("\\|\\|")
.trimResults()
.omitEmptyStrings()
.splitToList(String.format("%s || %s", cid2.getItem().unhide(), cid2.getItem().hide()));
String changedVal = String.valueOf((jList.getSelectedValues()));
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()) && cid2.getItem().enabledByValue().equals(changedVal))
{
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
rebuild = true;
}
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()) && cid2.getItem().disabledByValue().equals(changedVal))
{
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
rebuild = true;
}
else if (itemHide.contains(cid.getItem().keyName()))
{
rebuild = true;
}
}
}
}
return rebuild;
}
private boolean shouldBeHidden(ConfigItemDescriptor cid)
{ {
ConfigDescriptor cd = pluginConfig.getConfigDescriptor(); ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
@@ -1258,8 +1406,10 @@ class ConfigPanel extends PluginPanel
return true; return true;
} }
private void enableDisable(Component component, ConfigItemDescriptor cid) private boolean enableDisable(Component component, ConfigItemDescriptor cid)
{ {
boolean rebuild = false;
ConfigDescriptor cd = pluginConfig.getConfigDescriptor(); ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
if (component instanceof JCheckBox) if (component instanceof JCheckBox)
@@ -1272,11 +1422,15 @@ class ConfigPanel extends PluginPanel
{ {
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName())) if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()))
{ {
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true"); configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
rebuild = true;
} }
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName())) else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()))
{ {
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false"); configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
rebuild = true;
} }
} }
} }
@@ -1291,46 +1445,24 @@ class ConfigPanel extends PluginPanel
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()) && cid2.getItem().enabledByValue().equals(changedVal)) if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()) && cid2.getItem().enabledByValue().equals(changedVal))
{ {
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true"); configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
rebuild = true;
} }
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()) && cid2.getItem().disabledByValue().equals(changedVal)) else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()) && cid2.getItem().disabledByValue().equals(changedVal))
{ {
skipRebuild = true;
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false"); configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
rebuild = true;
} }
} }
} }
return rebuild;
} }
private static String htmlLabel(String key, String value) private static String htmlLabel(String key, String value)
{ {
return "<html><body style = 'color:#a5a5a5'>" + key + ": <span style = 'color:white'>" + value + "</span></body></html>"; return "<html><body style = 'color:#a5a5a5'>" + key + ": <span style = 'color:white'>" + value + "</span></body></html>";
} }
public static Component findComponentByName(Component component, String componentName)
{
if (component == null)
{
return null;
}
if (component.getName() != null && component.getName().equalsIgnoreCase(componentName))
{
return component;
}
if (component instanceof Container)
{
Component[] children = ((Container) component).getComponents();
for (Component child : children)
{
Component found = findComponentByName(child, componentName);
if (found != null)
{
return found;
}
}
}
return null;
}
} }

View File

@@ -259,6 +259,14 @@ public interface RSClient extends RSGameEngine, Client
@Import("graphicsObjects") @Import("graphicsObjects")
RSNodeDeque getGraphicsObjectDeque(); RSNodeDeque getGraphicsObjectDeque();
@Import("worldSelectOpen")
@Override
boolean isWorldSelectOpen();
@Import("worldSelectOpen")
@Override
void setWorldSelectOpen(boolean open);
@Import("Login_username") @Import("Login_username")
@Override @Override
String getUsername(); String getUsername();