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:
@@ -1,63 +1,84 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Jos <Malevolentdev@gmail.com>
|
* Copyright (c) 2018, Jos <Malevolentdev@gmail.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
* list of conditions and the following disclaimer.
|
* list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.statusbars;
|
package net.runelite.client.plugins.statusbars;
|
||||||
|
|
||||||
import net.runelite.client.config.Config;
|
import net.runelite.client.config.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
@ConfigGroup("statusbars")
|
@ConfigGroup("statusbars")
|
||||||
public interface StatusBarsConfig extends Config
|
public interface StatusBarsConfig extends Config
|
||||||
{
|
{
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
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"
|
||||||
)
|
)
|
||||||
default boolean enableCounter()
|
default boolean enableCounter()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
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."
|
||||||
)
|
)
|
||||||
default boolean enableSkillIcon()
|
default boolean enableSkillIcon()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
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."
|
||||||
)
|
)
|
||||||
default boolean enableRestorationBars()
|
default boolean enableRestorationBars()
|
||||||
{
|
{
|
||||||
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