Add a Toggle to the Status Bars w/ a Delay only in Combat
- This is to only show the Status Bars when in Combat, and hides it based on the delay set. Closes #7346 Toggle Demo: https://gyazo.com/ee277e5f0d4bfad598a7a1049d972a67 Delay Demo: https://gyazo.com/421e2a4a725725f1b7b5e62f96a6a8a3
This commit is contained in:
@@ -60,4 +60,25 @@ public interface StatusBarsConfig extends Config
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "hideStatusBarDelay",
|
||||||
|
name = "Delay (seconds)",
|
||||||
|
description = "Number of seconds after combat to hide the status bars."
|
||||||
|
)
|
||||||
|
default int hideStatusBarDelay()
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "toggleRestorationBars",
|
||||||
|
name = "Toggle to Hide when not in Combat",
|
||||||
|
description = "Visually hides the Status Bars when player is out of combat."
|
||||||
|
)
|
||||||
|
default boolean toggleRestorationBars()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,21 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.statusbars;
|
package net.runelite.client.plugins.statusbars;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.api.NPCComposition;
|
||||||
|
import net.runelite.api.events.GameTick;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDependency;
|
import net.runelite.client.plugins.PluginDependency;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
@@ -47,10 +59,56 @@ public class StatusBarsPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private StatusBarsConfig config;
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private Instant lastCombatAction;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
overlayManager.add(overlay);
|
}
|
||||||
|
|
||||||
|
void updateLastCombatAction()
|
||||||
|
{
|
||||||
|
this.lastCombatAction = Instant.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onGameTick(GameTick gameTick)
|
||||||
|
{
|
||||||
|
final Actor interacting = client.getLocalPlayer().getInteracting();
|
||||||
|
final boolean isNpc = interacting instanceof NPC;
|
||||||
|
final int COMBAT_TIMEOUT = config.hideStatusBarDelay();
|
||||||
|
|
||||||
|
if (!config.toggleRestorationBars())
|
||||||
|
{
|
||||||
|
overlayManager.add(overlay);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNpc)
|
||||||
|
{
|
||||||
|
final NPC npc = (NPC) interacting;
|
||||||
|
final NPCComposition npcComposition = npc.getComposition();
|
||||||
|
final List<String> npcMenuActions = Arrays.asList(npcComposition.getActions());
|
||||||
|
if (npcMenuActions.contains("Attack"))
|
||||||
|
{
|
||||||
|
updateLastCombatAction();
|
||||||
|
overlayManager.add(overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lastCombatAction != null)
|
||||||
|
{
|
||||||
|
if (Duration.between(getLastCombatAction(), Instant.now()).getSeconds() > COMBAT_TIMEOUT)
|
||||||
|
{
|
||||||
|
overlayManager.remove(overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user