Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.runelite.client.config;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
* Simple configuration action button that appears inside plugin configuration panels.
*/
@RequiredArgsConstructor
public class ConfigButton
{
@Getter
private final String label;

private final Runnable onClick;

/**
* Invoke the configured action if one was supplied.
*/
public void press()
{
if (onClick != null)
{
onClick.run();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,11 @@ public <T extends Config> void setDefaultConfiguration(T proxy, boolean override
continue;
}

if (method.getReturnType() == ConfigButton.class)
{
continue;
}

if (!method.isDefault())
{
if (override)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.*;
Expand Down Expand Up @@ -355,6 +356,10 @@ else if (cid.getType() == Notification.class)
{
item.add(createNotification(cd, cid), BorderLayout.EAST);
}
else if (cid.getType() == ConfigButton.class)
{
item.add(createConfigButton(cid), BorderLayout.EAST);
}
else if (cid.getType() instanceof ParameterizedType)
{
ParameterizedType parameterizedType = (ParameterizedType) cid.getType();
Expand Down Expand Up @@ -602,7 +607,7 @@ private JPanel createDimension(ConfigDescriptor cd, ConfigItemDescriptor cid)
return dimensionPanel;
}

private JComboBox<Enum<?>> createComboBox(ConfigDescriptor cd, ConfigItemDescriptor cid)
private JComboBox<Enum<?>> createComboBox(ConfigDescriptor cd, ConfigItemDescriptor cid)
{
Class<? extends Enum> type = (Class<? extends Enum>) cid.getType();

Expand Down Expand Up @@ -692,14 +697,14 @@ private JPanel createNotification(ConfigDescriptor cd, ConfigItemDescriptor cid)
return panel;
}

private JList<Enum<?>> createList(ConfigDescriptor cd, ConfigItemDescriptor cid)
{
ParameterizedType parameterizedType = (ParameterizedType) cid.getType();
Class<? extends Enum> type = (Class<? extends Enum>) parameterizedType.getActualTypeArguments()[0];
Set<? extends Enum> set = configManager.getConfiguration(cd.getGroup().value(), null,
cid.getItem().keyName(), parameterizedType);
private JList<Enum<?>> createList(ConfigDescriptor cd, ConfigItemDescriptor cid)
{
ParameterizedType parameterizedType = (ParameterizedType) cid.getType();
Class<? extends Enum> type = (Class<? extends Enum>) parameterizedType.getActualTypeArguments()[0];
Set<? extends Enum> set = configManager.getConfiguration(cd.getGroup().value(), null,
cid.getItem().keyName(), parameterizedType);

JList<Enum<?>> list = new JList<Enum<?>>(type.getEnumConstants()); // NOPMD: UseDiamondOperator
JList<Enum<?>> list = new JList<Enum<?>>(type.getEnumConstants()); // NOPMD: UseDiamondOperator
list.setCellRenderer(listCellRenderer);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list.setLayoutOrientation(JList.VERTICAL);
Expand All @@ -717,8 +722,73 @@ public void focusLost(FocusEvent e)
}
});

return list;
}
return list;
}

private JButton createConfigButton(ConfigItemDescriptor cid)
{
JButton button = new JButton();
button.setFocusable(false);
button.addActionListener(e ->
{
ConfigButton configButton = getConfigButtonValue(cid);
if (configButton != null)
{
configButton.press();
}
});

ConfigButton configButton = getConfigButtonValue(cid);
if (configButton != null)
{
button.setText(configButton.getLabel());
}
else
{
button.setText("Open");
button.setEnabled(false);
}

return button;
}

private ConfigButton getConfigButtonValue(ConfigItemDescriptor cid)
{
if (pluginConfig == null || pluginConfig.getConfig() == null)
{
return null;
}

Config config = pluginConfig.getConfig();
Class<?> configInterface = config.getClass().getInterfaces()[0];

for (Method method : configInterface.getDeclaredMethods())
{
ConfigItem item = method.getDeclaredAnnotation(ConfigItem.class);
if (item == null || method.getParameterCount() != 0)
{
continue;
}

if (!item.keyName().equals(cid.getItem().keyName()))
{
continue;
}

try
{
Object value = method.invoke(config);
return value instanceof ConfigButton ? (ConfigButton) value : null;
}
catch (ReflectiveOperationException ex)
{
log.warn("Unable to invoke config button {}", method.getName(), ex);
return null;
}
}

return null;
}

private void changeConfiguration(Component component, ConfigDescriptor cd, ConfigItemDescriptor cid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigButton;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.ConfigSection;
import net.runelite.client.plugins.microbot.util.prayer.PrayerHotkeyAssignments;
import net.runelite.client.plugins.microbot.util.prayer.PrayerHotkeyConfigAccess;
import net.runelite.client.plugins.microbot.util.prayer.PrayerHotkeyOption;

@ConfigGroup(MicrobotConfig.configGroup)
public interface MicrobotConfig extends Config
Expand Down Expand Up @@ -46,18 +50,104 @@ default boolean disableWorldSwitcherConfirmation()
return true;
}

@ConfigSection(
name = "Logging",
description = "Game chat logging configuration",
position = 1
)
String loggingSection = "loggingSection";
@ConfigSection(
name = "Caching",
description = "Caching ingame data",
position = 2
)
String cacheSection = "cacheSection";
@ConfigSection(
name = "Logging",
description = "Game chat logging configuration",
position = 1
)
String loggingSection = "loggingSection";
@ConfigSection(
name = "Caching",
description = "Caching ingame data",
position = 2
)
String cacheSection = "cacheSection";
@ConfigSection(
name = "Prayer Hotkeys",
description = "Configure the five Microbot prayer hotkey slots",
position = 3
)
String prayerHotkeysSection = "prayerHotkeysSection";

String keyPrayerHotkeyConfigure = "configurePrayerHotkeys";

@ConfigItem(
keyName = keyPrayerHotkeyConfigure,
name = "Configure hotkeys",
description = "Open the in-game selector to assign prayers to hotkey slots.",
position = 0,
section = prayerHotkeysSection
)
default ConfigButton openPrayerHotkeySelector()
{
return new ConfigButton("Open selector", PrayerHotkeyConfigAccess::openSelector);
}

String keyPrayerHotkeySlot1 = PrayerHotkeyAssignments.SLOT_KEY_PREFIX + "1";
String keyPrayerHotkeySlot2 = PrayerHotkeyAssignments.SLOT_KEY_PREFIX + "2";
String keyPrayerHotkeySlot3 = PrayerHotkeyAssignments.SLOT_KEY_PREFIX + "3";
String keyPrayerHotkeySlot4 = PrayerHotkeyAssignments.SLOT_KEY_PREFIX + "4";
String keyPrayerHotkeySlot5 = PrayerHotkeyAssignments.SLOT_KEY_PREFIX + "5";

@ConfigItem(
keyName = keyPrayerHotkeySlot1,
name = "Hotkey 1",
description = "Prayer triggered when hotkey slot 1 is clicked.",
position = 1,
section = prayerHotkeysSection
)
default PrayerHotkeyOption prayerHotkeySlot1()
{
return PrayerHotkeyOption.NONE;
}

@ConfigItem(
keyName = keyPrayerHotkeySlot2,
name = "Hotkey 2",
description = "Prayer triggered when hotkey slot 2 is clicked.",
position = 2,
section = prayerHotkeysSection
)
default PrayerHotkeyOption prayerHotkeySlot2()
{
return PrayerHotkeyOption.NONE;
}

@ConfigItem(
keyName = keyPrayerHotkeySlot3,
name = "Hotkey 3",
description = "Prayer triggered when hotkey slot 3 is clicked.",
position = 3,
section = prayerHotkeysSection
)
default PrayerHotkeyOption prayerHotkeySlot3()
{
return PrayerHotkeyOption.NONE;
}

@ConfigItem(
keyName = keyPrayerHotkeySlot4,
name = "Hotkey 4",
description = "Prayer triggered when hotkey slot 4 is clicked.",
position = 4,
section = prayerHotkeysSection
)
default PrayerHotkeyOption prayerHotkeySlot4()
{
return PrayerHotkeyOption.NONE;
}

@ConfigItem(
keyName = keyPrayerHotkeySlot5,
name = "Hotkey 5",
description = "Prayer triggered when hotkey slot 5 is clicked.",
position = 5,
section = prayerHotkeysSection
)
default PrayerHotkeyOption prayerHotkeySlot5()
{
return PrayerHotkeyOption.NONE;
}

String keyEnableGameChatLogging = "enableGameChatLogging";
@ConfigItem(
Expand Down Expand Up @@ -111,23 +201,23 @@ default boolean onlyMicrobotLogging() {
return false;
}

String keyEnableMenuEntryLogging = "enableMenuEntryLogging";
String keyEnableMenuEntryLogging = "enableMenuEntryLogging";

@ConfigItem(
keyName = keyEnableMenuEntryLogging,
name = "Enable Menu Entry Logging",
@ConfigItem(
keyName = keyEnableMenuEntryLogging,
name = "Enable Menu Entry Logging",
description = "Enable or disable logging menu entry clicked",
position = 4,
section = loggingSection
)
default boolean enableMenuEntryLogging() {
return false;
}
default boolean enableMenuEntryLogging() {
return false;
}

String keyEnableCache = "enableRs2Cache";
@ConfigItem(
keyName = keyEnableCache,
name = "Enable Microbot Cache",
String keyEnableCache = "enableRs2Cache";
@ConfigItem(
keyName = keyEnableCache,
name = "Enable Microbot Cache",
description = "This will cache ingame entities (npcs, objects,...) to improve performance",
position = 0,
section = cacheSection
Expand Down
Loading
Loading