Merge pull request #97 from ermalsh/status_Bar_toggle
Status bar toggle when not in combat
This commit is contained in:
@@ -32,6 +32,7 @@ import net.runelite.client.config.ConfigItem;
|
|||||||
public interface StatusBarsConfig extends Config
|
public interface StatusBarsConfig extends Config
|
||||||
{
|
{
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
position = 1,
|
||||||
keyName = "enableCounter",
|
keyName = "enableCounter",
|
||||||
name = "Show hitpoints & prayer counter",
|
name = "Show hitpoints & prayer counter",
|
||||||
description = "Shows current amount of hitpoints & prayer on the status bars"
|
description = "Shows current amount of hitpoints & prayer on the status bars"
|
||||||
@@ -42,6 +43,7 @@ public interface StatusBarsConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
position = 2,
|
||||||
keyName = "enableSkillIcon",
|
keyName = "enableSkillIcon",
|
||||||
name = "Show hitpoints & prayer icons",
|
name = "Show hitpoints & prayer icons",
|
||||||
description = "Adds skill icons at the top of the bars."
|
description = "Adds skill icons at the top of the bars."
|
||||||
@@ -52,6 +54,7 @@ public interface StatusBarsConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
position = 3,
|
||||||
keyName = "enableRestorationBars",
|
keyName = "enableRestorationBars",
|
||||||
name = "Show amount of hitpoints and prayer restored",
|
name = "Show amount of hitpoints and prayer restored",
|
||||||
description = "Visually shows how much a food or prayer will heal/restore you on the bars."
|
description = "Visually shows how much a food or prayer will heal/restore you on the bars."
|
||||||
@@ -60,4 +63,26 @@ public interface StatusBarsConfig extends Config
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
position = 4,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
position = 5,
|
||||||
|
keyName = "hideStatusBarDelay",
|
||||||
|
name = "Delay (seconds)",
|
||||||
|
description = "Number of seconds after combat to hide the status bars."
|
||||||
|
)
|
||||||
|
default int hideStatusBarDelay()
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,63 @@ 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)
|
||||||
|
{
|
||||||
|
if (!config.toggleRestorationBars())
|
||||||
|
{
|
||||||
|
overlayManager.add(overlay);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hideStatusBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideStatusBar()
|
||||||
|
{
|
||||||
|
final Actor interacting = client.getLocalPlayer().getInteracting();
|
||||||
|
final boolean isNpc = interacting instanceof NPC;
|
||||||
|
final int combatTimeout = config.hideStatusBarDelay();
|
||||||
|
|
||||||
|
if (isNpc)
|
||||||
|
{
|
||||||
|
final NPC npc = (NPC) interacting;
|
||||||
|
final NPCComposition npcComposition = npc.getComposition();
|
||||||
|
final List<String> npcMenuActions = Arrays.asList(npcComposition.getActions());
|
||||||
|
if (npcMenuActions.contains("Attack") && config.toggleRestorationBars())
|
||||||
|
{
|
||||||
|
updateLastCombatAction();
|
||||||
|
overlayManager.add(overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lastCombatAction != null)
|
||||||
|
{
|
||||||
|
if (Duration.between(getLastCombatAction(), Instant.now()).getSeconds() > combatTimeout)
|
||||||
|
{
|
||||||
|
overlayManager.remove(overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user