Make background color of panel components configurable (#11619)
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user