From 906e8ad5096cd65937d4596ccd1d3ef086ac69b0 Mon Sep 17 00:00:00 2001 From: Twiglet1022 <29353990+Twiglet1022@users.noreply.github.com> Date: Sun, 9 Jun 2019 21:06:56 +0100 Subject: [PATCH] notifier: add customisation to flash notification --- .../java/net/runelite/client/Notifier.java | 47 +++++++++++++++---- .../client/config/FlashNotification.java | 47 +++++++++++++++++++ .../client/config/RuneLiteConfig.java | 8 ++-- 3 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/config/FlashNotification.java diff --git a/runelite-client/src/main/java/net/runelite/client/Notifier.java b/runelite-client/src/main/java/net/runelite/client/Notifier.java index d1423f168e..b8f0b6f592 100644 --- a/runelite-client/src/main/java/net/runelite/client/Notifier.java +++ b/runelite-client/src/main/java/net/runelite/client/Notifier.java @@ -46,11 +46,13 @@ import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; +import net.runelite.api.Constants; import net.runelite.api.GameState; import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatMessageBuilder; import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.QueuedMessage; +import net.runelite.client.config.FlashNotification; import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.ui.ClientUI; import net.runelite.client.util.OSType; @@ -68,7 +70,8 @@ public class Notifier // Notifier properties private static final Color FLASH_COLOR = new Color(255, 0, 0, 70); - private static final int FLASH_DURATION = 2000; + private static final int MINIMUM_FLASH_DURATION_MILLIS = 2000; + private static final int MINIMUM_FLASH_DURATION_TICKS = MINIMUM_FLASH_DURATION_MILLIS / Constants.CLIENT_TICK_LENGTH; private final Client client; private final String appName; @@ -79,6 +82,7 @@ public class Notifier private final Path notifyIconPath; private final boolean terminalNotifierAvailable; private Instant flashStart; + private long mouseLastPressedMillis; @Inject private Notifier( @@ -146,9 +150,10 @@ public class Notifier .build()); } - if (runeLiteConfig.enableFlashNotification()) + if (runeLiteConfig.flashNotification() != FlashNotification.DISABLED) { flashStart = Instant.now(); + mouseLastPressedMillis = client.getMouseLastPressedMillis(); } log.debug(message); @@ -156,24 +161,48 @@ public class Notifier public void processFlash(final Graphics2D graphics) { - if (flashStart == null || client.getGameCycle() % 40 >= 20) - { - return; - } - else if (client.getGameState() != GameState.LOGGED_IN) + if (flashStart == null || client.getGameState() != GameState.LOGGED_IN) { flashStart = null; return; } + FlashNotification flashNotification = runeLiteConfig.flashNotification(); + + if (client.getGameCycle() % 40 >= 20 + // For solid colour, fall through every time. + && (flashNotification == FlashNotification.FLASH_TWO_SECONDS + || flashNotification == FlashNotification.FLASH_UNTIL_CANCELLED)) + { + return; + } + final Color color = graphics.getColor(); graphics.setColor(FLASH_COLOR); graphics.fill(new Rectangle(client.getCanvas().getSize())); graphics.setColor(color); - if (Instant.now().minusMillis(FLASH_DURATION).isAfter(flashStart)) + if (!Instant.now().minusMillis(MINIMUM_FLASH_DURATION_MILLIS).isAfter(flashStart)) { - flashStart = null; + return; + } + + switch (flashNotification) + { + case FLASH_TWO_SECONDS: + case SOLID_TWO_SECONDS: + flashStart = null; + break; + case SOLID_UNTIL_CANCELLED: + case FLASH_UNTIL_CANCELLED: + // Any interaction with the client since the notification started will cancel it after the minimum duration + if (client.getMouseIdleTicks() < MINIMUM_FLASH_DURATION_TICKS + || client.getKeyboardIdleTicks() < MINIMUM_FLASH_DURATION_TICKS + || client.getMouseLastPressedMillis() > mouseLastPressedMillis) + { + flashStart = null; + } + break; } } diff --git a/runelite-client/src/main/java/net/runelite/client/config/FlashNotification.java b/runelite-client/src/main/java/net/runelite/client/config/FlashNotification.java new file mode 100644 index 0000000000..f90ce26ad2 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/config/FlashNotification.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019, Twiglet1022 + * 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.config; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum FlashNotification +{ + DISABLED("Off"), + FLASH_TWO_SECONDS("Flash for 2 seconds"), + SOLID_TWO_SECONDS("Solid for 2 seconds"), + FLASH_UNTIL_CANCELLED("Flash until cancelled"), + SOLID_UNTIL_CANCELLED("Solid until cancelled"); + + private final String type; + + @Override + public String toString() + { + return type; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java b/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java index 546f7e77bc..13b1f5dee6 100644 --- a/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java @@ -175,14 +175,14 @@ public interface RuneLiteConfig extends Config } @ConfigItem( - keyName = "notificationFlash", - name = "Enable flash notification", + keyName = "flashNotification", + name = "Flash notification", description = "Flashes the game frame as a notification", position = 24 ) - default boolean enableFlashNotification() + default FlashNotification flashNotification() { - return false; + return FlashNotification.DISABLED; } @ConfigItem(