notifier: add customisation to flash notification

This commit is contained in:
Twiglet1022
2019-06-09 21:06:56 +01:00
committed by Adam
parent 0faa0a427b
commit 906e8ad509
3 changed files with 89 additions and 13 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2019, Twiglet1022 <https://github.com/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;
}
}

View File

@@ -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(