From 794fba7176b316ea138a88759b8b88f80bd23c28 Mon Sep 17 00:00:00 2001 From: TheStonedTurtle <29030969+TheStonedTurtle@users.noreply.github.com> Date: Wed, 20 May 2020 08:54:31 -0700 Subject: [PATCH] Make background color of panel components configurable (#11619) --- .../client/config/RuneLiteConfig.java | 20 +++++++++++-- .../client/ui/overlay/OverlayManager.java | 28 ++++++++++++++++++- .../client/ui/overlay/OverlayPanel.java | 14 ++++++++++ .../ui/overlay/components/PanelComponent.java | 3 +- .../ui/overlay/infobox/InfoBoxOverlay.java | 1 + 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java b/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java index b29a46a5df..b511a5e407 100644 --- a/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java @@ -24,12 +24,14 @@ */ package net.runelite.client.config; +import java.awt.Color; import java.awt.Dimension; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import net.runelite.api.Constants; import net.runelite.client.Notifier; import net.runelite.client.ui.ContainableFrame; +import net.runelite.client.ui.overlay.components.ComponentConstants; @ConfigGroup(RuneLiteConfig.GROUP_NAME) public interface RuneLiteConfig extends Config @@ -280,11 +282,23 @@ public interface RuneLiteConfig extends Config return 35; } + @ConfigItem( + keyName = "overlayBackgroundColor", + name = "Overlay Color", + description = "Configures the background color of infoboxes and overlays", + position = 43 + ) + @Alpha + default Color overlayBackgroundColor() + { + return ComponentConstants.STANDARD_BACKGROUND_COLOR; + } + @ConfigItem( keyName = "blockExtraMouseButtons", name = "Block Extra Mouse Buttons", description = "Blocks extra mouse buttons (4 and above)", - position = 43 + position = 44 ) default boolean blockExtraMouseButtons() { @@ -295,7 +309,7 @@ public interface RuneLiteConfig extends Config keyName = "sidebarToggleKey", name = "Sidebar Toggle Key", description = "The key that will toggle the sidebar (accepts modifiers)", - position = 44 + position = 45 ) default Keybind sidebarToggleKey() { @@ -306,7 +320,7 @@ public interface RuneLiteConfig extends Config keyName = "panelToggleKey", name = "Plugin Panel Toggle Key", description = "The key that will toggle the current or last opened plugin panel (accepts modifiers)", - position = 45 + position = 46 ) default Keybind panelToggleKey() { diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java index 39e08b3964..e5f52668e0 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java @@ -47,6 +47,7 @@ import net.runelite.client.config.ConfigManager; import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.OverlayMenuClicked; import net.runelite.client.events.PluginChanged; @@ -104,12 +105,25 @@ public class OverlayManager private final ConfigManager configManager; private final EventBus eventBus; + private final RuneLiteConfig runeLiteConfig; @Inject - private OverlayManager(final ConfigManager configManager, final EventBus eventBus) + private OverlayManager(final ConfigManager configManager, final EventBus eventBus, final RuneLiteConfig runeLiteConfig) { this.configManager = configManager; this.eventBus = eventBus; + this.runeLiteConfig = runeLiteConfig; + } + + @Subscribe + public void onConfigChanged(final ConfigChanged event) + { + if (!RuneLiteConfig.GROUP_NAME.equals(event.getGroup()) || !"overlayBackgroundColor".equals(event.getKey())) + { + return; + } + + overlays.forEach(this::updateOverlayConfig); } @Subscribe @@ -171,12 +185,15 @@ public class OverlayManager // Add is always true overlays.add(overlay); loadOverlay(overlay); + updateOverlayConfig(overlay); + // WidgetItemOverlays have a reference to the overlay manager in order to get the WidgetItems // for each frame. if (overlay instanceof WidgetItemOverlay) { ((WidgetItemOverlay) overlay).setOverlayManager(this); } + rebuildOverlayLayers(); return true; } @@ -304,6 +321,15 @@ public class OverlayManager overlay.setPreferredPosition(position); } + private void updateOverlayConfig(final Overlay overlay) + { + if (overlay instanceof OverlayPanel) + { + // Update preferred color for overlay panels based on configuration + ((OverlayPanel) overlay).setPreferredColor(runeLiteConfig.overlayBackgroundColor()); + } + } + private void saveOverlayLocation(final Overlay overlay) { final String key = overlay.getName() + OVERLAY_CONFIG_PREFERRED_LOCATION; diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayPanel.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayPanel.java index 4ccbdebc70..6d749b765f 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayPanel.java @@ -24,6 +24,7 @@ */ package net.runelite.client.ui.overlay; +import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import lombok.Getter; @@ -49,6 +50,11 @@ public abstract class OverlayPanel extends Overlay */ private boolean dynamicFont = false; + /** + * Preferred color used for panel component background + */ + private Color preferredColor = null; + protected OverlayPanel() { super(); @@ -83,6 +89,13 @@ public abstract class OverlayPanel extends Overlay } } + final Color oldBackgroundColor = panelComponent.getBackgroundColor(); + + if (getPreferredColor() != null && ComponentConstants.STANDARD_BACKGROUND_COLOR.equals(oldBackgroundColor)) + { + panelComponent.setBackgroundColor(getPreferredColor()); + } + final Dimension dimension = panelComponent.render(graphics); if (clearChildren) @@ -91,6 +104,7 @@ public abstract class OverlayPanel extends Overlay } panelComponent.setPreferredSize(oldSize); + panelComponent.setBackgroundColor(oldBackgroundColor); return dimension; } } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/PanelComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/PanelComponent.java index fbdccdaa54..41829f6dc1 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/PanelComponent.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/PanelComponent.java @@ -31,7 +31,6 @@ import java.awt.Point; import java.awt.Rectangle; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; import lombok.Getter; import lombok.Setter; @@ -48,7 +47,7 @@ public class PanelComponent implements LayoutableRenderableEntity private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0); @Setter - @Nullable + @Getter private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR; @Getter diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java index b917a38e6b..c04da4b6ee 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java @@ -111,6 +111,7 @@ public class InfoBoxOverlay extends OverlayPanel infoBoxComponent.setImage(box.getScaledImage()); infoBoxComponent.setTooltip(box.getTooltip()); infoBoxComponent.setPreferredSize(new Dimension(config.infoBoxSize(), config.infoBoxSize())); + infoBoxComponent.setBackgroundColor(config.overlayBackgroundColor()); panelComponent.getChildren().add(infoBoxComponent); }