Skip to content

Commit

Permalink
Merge branch 'master' into feat/alert-hub
Browse files Browse the repository at this point in the history
  • Loading branch information
adamk33n3r committed Oct 21, 2023
2 parents 1e2eaf3 + 068ca1d commit dc38379
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 9 deletions.
27 changes: 24 additions & 3 deletions src/main/java/com/adamk33n3r/runelite/watchdog/WatchdogConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public interface WatchdogConfig extends Config {
String DEFAULT_SCREEN_FLASH_MODE = "defaultScreenFlashMode";
String DEFAULT_SCREEN_FLASH_DURATION = "defaultScreenFlashDuration";

// AFK Notification
String DEFAULT_AFK_SECONDS = "defaultAFKSeconds";

// Sound
String PUT_SOUNDS_INTO_QUEUE = "putSoundsIntoQueue";
String DEFAULT_SOUND_VOLUME = "defaultSoundVolume";
Expand Down Expand Up @@ -251,11 +254,29 @@ public interface WatchdogConfig extends Config {
default int defaultScreenFlashDuration() { return 2; }
//endregion

//region AFK Notification
@ConfigSection(
name = "AFK Notification",
description = "The options that control the afk alert filter settings",
position = 3
)
String afkNotificationSection = "afkNotificationSection";

@ConfigItem(
keyName = DEFAULT_AFK_SECONDS,
name = "Default AFK Seconds",
description = "The default AFK seconds value",
section = afkNotificationSection
)
@Units(Units.SECONDS)
default int defaultAFKSeconds() { return 5; }
//endregion

//region Sound
@ConfigSection(
name = "Custom Sound",
description = "The options that control the custom sound notifications",
position = 3
position = 4
)
String soundSection = "soundSection";

Expand All @@ -281,7 +302,7 @@ public interface WatchdogConfig extends Config {
@ConfigSection(
name = "Sound Effect",
description = "The options that control the custom sound notifications",
position = 4
position = 5
)
String soundEffectSection = "soundEffectSection";

Expand All @@ -307,7 +328,7 @@ public interface WatchdogConfig extends Config {
@ConfigSection(
name = "Text to Speech",
description = "The options that control the text to speech notifications",
position = 5
position = 6
)
String ttsSection = "ttsSection";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.adamk33n3r.runelite.watchdog.NotificationType;
import com.adamk33n3r.runelite.watchdog.alerts.Alert;

import net.runelite.api.Client;
import net.runelite.api.Constants;
import net.runelite.client.ui.ClientUI;

import lombok.Getter;
Expand All @@ -15,13 +17,23 @@ public abstract class Notification implements INotification {
@Inject
protected transient ClientUI clientUI;

@Inject
protected transient Client client;

@Getter @Setter
private boolean fireWhenFocused = true;

@Getter @Setter
private int fireWhenAFKForSeconds = 0;

@Getter @Setter
protected transient Alert alert;

protected boolean shouldFire() {
int afkTime = (int)Math.floor(Math.min(client.getKeyboardIdleTicks(), client.getMouseIdleTicks()) * Constants.CLIENT_TICK_LENGTH / 1000f);
if (afkTime < this.fireWhenAFKForSeconds) {
return false;
}
return !this.clientUI.isFocused() || this.fireWhenFocused;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/adamk33n3r/runelite/watchdog/ui/Icons.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public abstract class Icons {
public static final ImageIcon FOREGROUND_HOVER = new ImageIcon(ImageUtil.luminanceOffset(FOREGROUND.getImage(), -80));
public static final ImageIcon BACKGROUND = new ImageIcon(ImageUtil.loadImageResource(Icons.class, "mdi_flip-to-back.png"));
public static final ImageIcon BACKGROUND_HOVER = new ImageIcon(ImageUtil.luminanceOffset(BACKGROUND.getImage(), -80));
public static final ImageIcon AFK = new ImageIcon(ImageUtil.loadImageResource(Icons.class, "afk_icon.png"));
public static final ImageIcon AFK_HOVER = new ImageIcon(ImageUtil.luminanceOffset(AFK.getImage(), -80));
public static final ImageIcon NON_AFK = new ImageIcon(ImageUtil.loadImageResource(Icons.class, "non_afk_icon.png"));
public static final ImageIcon NON_AFK_HOVER = new ImageIcon(ImageUtil.luminanceOffset(NON_AFK.getImage(), -80));
public static final ImageIcon TEST = new ImageIcon(ImageUtil.loadImageResource(Icons.class, "mdi_flask.png"));
public static final ImageIcon TEST_HOVER = new ImageIcon(ImageUtil.luminanceOffset(TEST.getImage(), -80));
public static final ImageIcon VOLUME = new ImageIcon(ImageUtil.luminanceOffset(ImageUtil.loadImageResource(Icons.class, "mdi_volume-high.png"), -80));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.adamk33n3r.runelite.watchdog.ui.notifications.panels;

import com.adamk33n3r.runelite.watchdog.NotificationType;
import com.adamk33n3r.runelite.watchdog.WatchdogConfig;
import com.adamk33n3r.runelite.watchdog.WatchdogPlugin;
import com.adamk33n3r.runelite.watchdog.notifications.Notification;
import com.adamk33n3r.runelite.watchdog.ui.Icons;
import com.adamk33n3r.runelite.watchdog.ui.StretchedStackedLayout;
Expand All @@ -11,16 +13,15 @@
import net.runelite.client.ui.components.MouseDragEventForwarder;

import lombok.Getter;
import net.runelite.client.util.ImageUtil;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.concurrent.atomic.AtomicInteger;

public abstract class NotificationPanel extends JPanel {
// worldhopper - arrow down
Expand Down Expand Up @@ -50,6 +51,8 @@ public NotificationPanel(Notification notification, NotificationsPanel parentPan
this.onChangeListener = onChangeListener;
this.onRemove = onRemove;

WatchdogConfig config = WatchdogPlugin.getInstance().getConfig();

this.setLayout(new BorderLayout());
this.setBorder(new EmptyBorder(3, 0, 0, 0));
JPanel container = new JPanel(new StretchedStackedLayout(3, 3));
Expand Down Expand Up @@ -77,6 +80,50 @@ public NotificationPanel(Notification notification, NotificationsPanel parentPan
rightActions.setBackground(ColorScheme.DARKER_GRAY_COLOR);
nameWrapper.add(rightActions, BorderLayout.EAST);

JPanel afkTimerConfigRow = new JPanel(new GridLayout(1, 2));
afkTimerConfigRow.setBorder(new EmptyBorder(4, 10, 0, 5));
afkTimerConfigRow.setBackground(ColorScheme.DARKER_GRAY_COLOR);
JLabel afkTimerLabel = new JLabel("AFK Seconds:");
afkTimerLabel.setToolTipText("Number of seconds for which the client doesn't get any mouse or keyboard inputs.");
AtomicInteger previousAFKSeconds = new AtomicInteger(notification.getFireWhenAFKForSeconds() > 0 ? notification.getFireWhenAFKForSeconds() : config.defaultAFKSeconds());

JSpinner afkTimerSpinner = PanelUtils.createSpinner(Math.max(notification.getFireWhenAFKForSeconds(), 1),
1,
25 * 60,
1,
(val) -> {
notification.setFireWhenAFKForSeconds(val);
previousAFKSeconds.set(val);
onChangeListener.run();
});
if (notification.getFireWhenAFKForSeconds() != 0) {
afkTimerConfigRow.add(afkTimerLabel);
afkTimerConfigRow.add(afkTimerSpinner);
}

JButton afkButton = PanelUtils.createToggleActionButton(
Icons.AFK,
Icons.AFK_HOVER,
Icons.NON_AFK,
Icons.NON_AFK_HOVER,
"Enable notification even when you are active",
"Switch to only fire notification when you have been AFK for a certain amount of time",
notification.getFireWhenAFKForSeconds() != 0,
(btn, modifiers) -> {
notification.setFireWhenAFKForSeconds(btn.isSelected() ? previousAFKSeconds.get() : 0);
if (notification.getFireWhenAFKForSeconds() != 0) {
afkTimerSpinner.setValue(notification.getFireWhenAFKForSeconds());
afkTimerConfigRow.add(afkTimerLabel);
afkTimerConfigRow.add(afkTimerSpinner);
} else {
afkTimerConfigRow.removeAll();
}
afkTimerConfigRow.revalidate();
afkTimerConfigRow.repaint();
onChangeListener.run();
});
rightActions.add(afkButton, BorderLayout.EAST);

JButton focusBtn = PanelUtils.createToggleActionButton(
Icons.FOREGROUND,
Icons.FOREGROUND_HOVER,
Expand Down Expand Up @@ -105,6 +152,8 @@ public NotificationPanel(Notification notification, NotificationsPanel parentPan
(btn, modifiers) -> onRemove.elementRemoved(this));
rightActions.add(deleteBtn);

container.add(afkTimerConfigRow);

this.settings.setBorder(new EmptyBorder(5, 10, 5, 10));
this.settings.setBackground(ColorScheme.DARKER_GRAY_COLOR);
container.add(this.settings);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dc38379

Please sign in to comment.