From e8925e3e726511d2753d7c8673825870bbce13a7 Mon Sep 17 00:00:00 2001 From: Ermal Date: Sat, 19 Jan 2019 12:46:52 -0500 Subject: [PATCH 1/5] 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 --- .../plugins/statusbars/StatusBarsConfig.java | 147 ++++++++++-------- .../plugins/statusbars/StatusBarsPlugin.java | 60 ++++++- 2 files changed, 143 insertions(+), 64 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java index c3a05b05db..e869f0e010 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java @@ -1,63 +1,84 @@ -/* - * Copyright (c) 2018, Jos - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 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 - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * 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 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.client.plugins.statusbars; - -import net.runelite.client.config.Config; -import net.runelite.client.config.ConfigGroup; -import net.runelite.client.config.ConfigItem; - -@ConfigGroup("statusbars") -public interface StatusBarsConfig extends Config -{ - @ConfigItem( - keyName = "enableCounter", - name = "Show hitpoints & prayer counter", - description = "Shows current amount of hitpoints & prayer on the status bars" - ) - default boolean enableCounter() - { - return false; - } - - @ConfigItem( - keyName = "enableSkillIcon", - name = "Show hitpoints & prayer icons", - description = "Adds skill icons at the top of the bars." - ) - default boolean enableSkillIcon() - { - return true; - } - - @ConfigItem( - keyName = "enableRestorationBars", - name = "Show amount of hitpoints and prayer restored", - description = "Visually shows how much a food or prayer will heal/restore you on the bars." - ) - default boolean enableRestorationBars() - { - return true; - } -} +/* + * Copyright (c) 2018, Jos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 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 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * 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 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.statusbars; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup("statusbars") +public interface StatusBarsConfig extends Config +{ + @ConfigItem( + keyName = "enableCounter", + name = "Show hitpoints & prayer counter", + description = "Shows current amount of hitpoints & prayer on the status bars" + ) + default boolean enableCounter() + { + return false; + } + + @ConfigItem( + keyName = "enableSkillIcon", + name = "Show hitpoints & prayer icons", + description = "Adds skill icons at the top of the bars." + ) + default boolean enableSkillIcon() + { + return true; + } + + @ConfigItem( + keyName = "enableRestorationBars", + name = "Show amount of hitpoints and prayer restored", + description = "Visually shows how much a food or prayer will heal/restore you on the bars." + ) + default boolean enableRestorationBars() + { + 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; + } + +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java index cb36b42d0d..3c163a5b18 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java @@ -24,9 +24,21 @@ */ 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 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.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDependency; import net.runelite.client.plugins.PluginDescriptor; @@ -47,10 +59,56 @@ public class StatusBarsPlugin extends Plugin @Inject private OverlayManager overlayManager; + @Inject + private Client client; + + @Inject + private StatusBarsConfig config; + + @Getter(AccessLevel.PACKAGE) + private Instant lastCombatAction; + @Override 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 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 From e1dbff24aadae6e1482046162800f2f9fa867c98 Mon Sep 17 00:00:00 2001 From: Ermal Date: Sat, 19 Jan 2019 12:53:51 -0500 Subject: [PATCH 2/5] Removed a line break in StatusBarConfig Fixed my .gitconfig file for line endings issue --- .../net/runelite/client/plugins/statusbars/StatusBarsConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java index e869f0e010..9f0f11309e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java @@ -80,5 +80,4 @@ public interface StatusBarsConfig extends Config { return true; } - } From fd202035b51bcca6de42bcd1d5d997fe87f77f9c Mon Sep 17 00:00:00 2001 From: Ermal Shkullaku Date: Sat, 19 Jan 2019 13:05:17 -0500 Subject: [PATCH 3/5] Updated Position of Config Options -Added position to each of the options -Placed the delay at the bottom --- .../plugins/statusbars/StatusBarsConfig.java | 171 +++++++++--------- 1 file changed, 88 insertions(+), 83 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java index 9f0f11309e..8772dcdb12 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java @@ -1,83 +1,88 @@ -/* - * Copyright (c) 2018, Jos - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 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 - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * 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 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.client.plugins.statusbars; - -import net.runelite.client.config.Config; -import net.runelite.client.config.ConfigGroup; -import net.runelite.client.config.ConfigItem; - -@ConfigGroup("statusbars") -public interface StatusBarsConfig extends Config -{ - @ConfigItem( - keyName = "enableCounter", - name = "Show hitpoints & prayer counter", - description = "Shows current amount of hitpoints & prayer on the status bars" - ) - default boolean enableCounter() - { - return false; - } - - @ConfigItem( - keyName = "enableSkillIcon", - name = "Show hitpoints & prayer icons", - description = "Adds skill icons at the top of the bars." - ) - default boolean enableSkillIcon() - { - return true; - } - - @ConfigItem( - keyName = "enableRestorationBars", - name = "Show amount of hitpoints and prayer restored", - description = "Visually shows how much a food or prayer will heal/restore you on the bars." - ) - default boolean enableRestorationBars() - { - 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; - } -} +/* + * Copyright (c) 2018, Jos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 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 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * 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 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.statusbars; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup("statusbars") +public interface StatusBarsConfig extends Config +{ + @ConfigItem( + position = 1, + keyName = "enableCounter", + name = "Show hitpoints & prayer counter", + description = "Shows current amount of hitpoints & prayer on the status bars" + ) + default boolean enableCounter() + { + return false; + } + + @ConfigItem( + position = 2, + keyName = "enableSkillIcon", + name = "Show hitpoints & prayer icons", + description = "Adds skill icons at the top of the bars." + ) + default boolean enableSkillIcon() + { + return true; + } + + @ConfigItem( + position = 3, + keyName = "enableRestorationBars", + name = "Show amount of hitpoints and prayer restored", + description = "Visually shows how much a food or prayer will heal/restore you on the bars." + ) + default boolean enableRestorationBars() + { + 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; + } +} From 2d394a24a39d15e68413564297f7b1fe41717b6f Mon Sep 17 00:00:00 2001 From: Ermal Shkullaku Date: Sat, 19 Jan 2019 13:23:52 -0500 Subject: [PATCH 4/5] Fixed when Toggle Option is off on Login - This caused an issue where the delay would be ignored after setting it on after login --- .../plugins/statusbars/StatusBarsPlugin.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java index 3c163a5b18..33914f4633 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java @@ -81,32 +81,34 @@ public class StatusBarsPlugin extends Plugin @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) + else { - final NPC npc = (NPC) interacting; - final NPCComposition npcComposition = npc.getComposition(); - final List npcMenuActions = Arrays.asList(npcComposition.getActions()); - if (npcMenuActions.contains("Attack")) + final Actor interacting = client.getLocalPlayer().getInteracting(); + final boolean isNpc = interacting instanceof NPC; + final int COMBAT_TIMEOUT = config.hideStatusBarDelay(); + + if (isNpc) + { + final NPC npc = (NPC) interacting; + final NPCComposition npcComposition = npc.getComposition(); + final List 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() > COMBAT_TIMEOUT) + } + else if (lastCombatAction != null) { - overlayManager.remove(overlay); + if (Duration.between(getLastCombatAction(), Instant.now()).getSeconds() > COMBAT_TIMEOUT) + { + overlayManager.remove(overlay); + } } } } From bca45c5d4cf396474d4f57cc57dc29cbef259af5 Mon Sep 17 00:00:00 2001 From: ErmalSh Date: Sat, 19 Jan 2019 14:53:25 -0500 Subject: [PATCH 5/5] Updates based on Reviewer Suggestions - COMBAT_TIMEOUT renamed to combatTimeout since it's not a constant - Created hideStatusBar() method for code cleanliness - Renamed Config option to remove capitalization on some words --- .../plugins/statusbars/StatusBarsConfig.java | 2 +- .../plugins/statusbars/StatusBarsPlugin.java | 39 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java index 8772dcdb12..58842332e2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java @@ -67,7 +67,7 @@ public interface StatusBarsConfig extends Config @ConfigItem( position = 4, keyName = "toggleRestorationBars", - name = "Toggle to Hide when not in Combat", + name = "Toggle to hide when not in combat", description = "Visually hides the Status Bars when player is out of combat." ) default boolean toggleRestorationBars() diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java index 33914f4633..e32895d910 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java @@ -88,27 +88,32 @@ public class StatusBarsPlugin extends Plugin } else { - final Actor interacting = client.getLocalPlayer().getInteracting(); - final boolean isNpc = interacting instanceof NPC; - final int COMBAT_TIMEOUT = config.hideStatusBarDelay(); + hideStatusBar(); + } + } - if (isNpc) + 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 npcMenuActions = Arrays.asList(npcComposition.getActions()); + if (npcMenuActions.contains("Attack") && config.toggleRestorationBars()) { - final NPC npc = (NPC) interacting; - final NPCComposition npcComposition = npc.getComposition(); - final List npcMenuActions = Arrays.asList(npcComposition.getActions()); - if (npcMenuActions.contains("Attack") && config.toggleRestorationBars()) - { - updateLastCombatAction(); - overlayManager.add(overlay); - } + updateLastCombatAction(); + overlayManager.add(overlay); } - else if (lastCombatAction != null) + } + else if (lastCombatAction != null) + { + if (Duration.between(getLastCombatAction(), Instant.now()).getSeconds() > combatTimeout) { - if (Duration.between(getLastCombatAction(), Instant.now()).getSeconds() > COMBAT_TIMEOUT) - { - overlayManager.remove(overlay); - } + overlayManager.remove(overlay); } } }