From 52f2bd71b035ffb8b111698cd2ca5d93c6bee915 Mon Sep 17 00:00:00 2001 From: SnavvieJD <258896103+SnavvieJD@users.noreply.github.com> Date: Fri, 4 Sep 2026 14:31:37 -0500 Subject: [PATCH] Add option to hide the histogram when the inventory is closed The overlay is typically positioned over the inventory panel. When the inventory is closed the panel disappears but the histogram stays, leaving the tick marks floating over the game world. HistogramOverlay had no access to game state (it was constructed with only the config), so it couldn't tell whether the inventory was open. This passes the plugin's existing injected Client through to the overlay and adds a "Hide When Inventory Closed" toggle to the Panel section, defaulting to off so existing behaviour is unchanged. The event updates now run before the visibility check rather than after the draw, so events are still aged and pruned while the panel is hidden and the frame delta doesn't spike when it reappears. Co-Authored-By: Claude Opus 5 (1M context) --- .../java/com/histogram/HistogramConfig.java | 12 +++++++++ .../java/com/histogram/HistogramOverlay.java | 26 ++++++++++++++++--- .../java/com/histogram/HistogramPlugin.java | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/histogram/HistogramConfig.java b/src/main/java/com/histogram/HistogramConfig.java index b9ad8ca..393ebff 100644 --- a/src/main/java/com/histogram/HistogramConfig.java +++ b/src/main/java/com/histogram/HistogramConfig.java @@ -39,6 +39,18 @@ public interface HistogramConfig extends Config ) String advancedSection = "Advanced"; + @ConfigItem( + keyName = "hidewheninventoryclosed", + name = "Hide When Inventory Closed", + description = "Hide the histogram whenever the inventory panel is hidden, so it comes and goes with the rest of the interface", + section = panelSection, + position = -1 + ) + default boolean hideWhenInventoryClosed() + { + return false; + } + @ConfigItem( keyName = "panelsize", name = "Panel size", diff --git a/src/main/java/com/histogram/HistogramOverlay.java b/src/main/java/com/histogram/HistogramOverlay.java index 47978fa..41d06ab 100644 --- a/src/main/java/com/histogram/HistogramOverlay.java +++ b/src/main/java/com/histogram/HistogramOverlay.java @@ -1,5 +1,8 @@ package com.histogram; +import net.runelite.api.Client; +import net.runelite.api.gameval.InterfaceID; +import net.runelite.api.widgets.Widget; import net.runelite.client.ui.overlay.Overlay; import java.awt.*; import java.util.*; @@ -26,12 +29,15 @@ private class Event private HistogramConfig config; + private Client client; + private long lastnano; private float delta; - HistogramOverlay(HistogramConfig config) + HistogramOverlay(HistogramConfig config, Client client) { this.config = config; + this.client = client; events = new ArrayDeque<>(); lastnano = System.nanoTime(); @@ -61,16 +67,30 @@ public void addEvent(EventType type, float pingdelay, float serverdelay) @Override public Dimension render(Graphics2D graphics) { + // Age and prune events even while hidden, so the deque doesn't grow + // unbounded and `delta` doesn't spike on the frame the panel returns. + updateDelta(); + updateEvents(); + + if (config.hideWhenInventoryClosed() && isInventoryHidden()) + { + return null; + } + graphics.setColor(config.bgColor()); graphics.fillRect(0, 0, config.panelSize().width, config.panelSize().height); - updateDelta(); - updateEvents(); drawEvents(graphics); return config.panelSize(); } + private boolean isInventoryHidden() + { + Widget inventory = client.getWidget(InterfaceID.Inventory.ITEMS); + return inventory == null || inventory.isHidden(); + } + private void drawEvents(Graphics2D graphics) { for (Event event : events) diff --git a/src/main/java/com/histogram/HistogramPlugin.java b/src/main/java/com/histogram/HistogramPlugin.java index dcc2902..6bab9ab 100644 --- a/src/main/java/com/histogram/HistogramPlugin.java +++ b/src/main/java/com/histogram/HistogramPlugin.java @@ -48,7 +48,7 @@ public class HistogramPlugin extends Plugin @Override protected void startUp() throws Exception { - histogramOverlay = new HistogramOverlay(config); + histogramOverlay = new HistogramOverlay(config, client); overlayManager.add(histogramOverlay); pingThreads = Executors.newScheduledThreadPool(20);