Configurable Overlay

IntermediateDisplay

An overlay plugin with user-configurable settings. Demonstrates how to create config interfaces, add settings, and use them in your plugin.

20 min read

What It Does

An overlay plugin with user-configurable settings. Demonstrates how to create config interfaces, add settings, and use them in your plugin.

Source Code

java
1package com.example;
2
3import net.runelite.api.Client;
4import net.runelite.client.config.Config;
5import net.runelite.client.config.ConfigGroup;
6import net.runelite.client.config.ConfigItem;
7import net.runelite.client.plugins.Plugin;
8import net.runelite.client.plugins.PluginDescriptor;
9import net.runelite.client.ui.overlay.Overlay;
10import net.runelite.client.ui.overlay.OverlayManager;
11import javax.inject.Inject;
12import java.awt.*;
13
14@PluginDescriptor(
15    name = "Configurable Overlay",
16    description = "Overlay with configurable settings"
17)
18public class ConfigurableOverlayPlugin extends Plugin {
19    @Inject
20    private Client client;
21
22    @Inject
23    private OverlayManager overlayManager;
24
25    @Inject
26    private ConfigurableOverlayConfig config;
27
28    private final Overlay overlay = new Overlay() {
29        @Override
30        public Dimension render(Graphics2D graphics) {
31            if (!config.enabled()) {
32                return null; // Don't render if disabled
33            }
34
35            graphics.setColor(config.textColor());
36            graphics.setFont(new Font("Arial", Font.BOLD, config.fontSize()));
37            graphics.drawString(config.message(), 10, 20);
38            
39            return new Dimension(200, 30);
40        }
41    };
42
43    @Override
44    protected void startUp() {
45        overlayManager.add(overlay);
46    }
47
48    @Override
49    protected void shutDown() {
50        overlayManager.remove(overlay);
51    }
52}
53
54@ConfigGroup("configurableoverlay")
55public interface ConfigurableOverlayConfig extends Config {
56    @ConfigItem(
57        keyName = "enabled",
58        name = "Enable Overlay",
59        description = "Turn the overlay on or off"
60    )
61    default boolean enabled() {
62        return true;
63    }
64
65    @ConfigItem(
66        keyName = "message",
67        name = "Display Message",
68        description = "The message to display on the overlay"
69    )
70    default String message() {
71        return "Hello from Config!";
72    }
73
74    @ConfigItem(
75        keyName = "textColor",
76        name = "Text Color",
77        description = "Color of the overlay text"
78    )
79    default Color textColor() {
80        return Color.WHITE;
81    }
82
83    @ConfigItem(
84        keyName = "fontSize",
85        name = "Font Size",
86        description = "Size of the font"
87    )
88    default int fontSize() {
89        return 14;
90    }
91}

Code Annotations

Line 30

@ConfigGroup groups all config items together

Line 33

@ConfigItem defines a single configuration setting

Line 45

default methods provide default values for settings

Line 25

Use config values in your plugin code

Variations

With Sections

Organize config items into sections

java
1@ConfigGroup("myplugin")
2public interface MyConfig extends Config {
3    @ConfigSection(
4        name = "Display Settings",
5        description = "Settings for display options",
6        position = 1
7    )
8    String displaySection = "display";
9
10    @ConfigItem(
11        keyName = "showText",
12        name = "Show Text",
13        description = "Display text overlay",
14        section = displaySection
15    )
16    default boolean showText() {
17        return true;
18    }
19}

API Classes Used

Key Concepts

  • @ConfigGroup groups all config items together
  • @ConfigItem defines a single configuration setting
  • default methods provide default values for settings
  • Use config values in your plugin code

Next Steps

  • Learn about ConfigGroup and ConfigSection
  • Explore different config types (boolean, int, String, Color)
  • Add config validation