Skip to content

Commit

Permalink
feat: dismiss sticky overlays with notification
Browse files Browse the repository at this point in the history
Fixes #117
  • Loading branch information
adamk33n3r committed Feb 9, 2024
1 parent b65dcdf commit 461a637
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ private void init() {
.registerSubtype(Overhead.class)
.registerSubtype(Overlay.class)
.registerSubtype(RequestFocus.class)
.registerSubtype(NotificationEvent.class);
.registerSubtype(NotificationEvent.class)
.registerSubtype(DismissOverlay.class);
this.gson = this.clientGson.newBuilder()
// .serializeNulls()
.registerTypeAdapterFactory(alertTypeFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.runelite.client.ui.overlay.OverlayMenuEntry;
import net.runelite.client.ui.overlay.OverlayPanel;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
import net.runelite.client.util.ImageUtil;
Expand All @@ -21,7 +20,10 @@
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;

import static net.runelite.api.MenuAction.RUNELITE_OVERLAY;
import static net.runelite.api.MenuAction.RUNELITE_OVERLAY_CONFIG;
Expand Down Expand Up @@ -93,7 +95,7 @@ public NotificationOverlay(WatchdogPlugin plugin) {
super(plugin);
this.setPosition(OverlayPosition.TOP_LEFT);
this.setResizable(true);
this.setPriority(OverlayPriority.LOW);
this.setPriority(0);
this.setClearChildren(true);
this.setPreferredSize(DEFAULT_SIZE);

Expand All @@ -114,6 +116,13 @@ public void clear() {
this.overlayNotificationQueue.clear();
}

public void clearById(String id) {
List<OverlayNotificationData> stickiesToDismiss = this.overlayNotificationQueue.stream()
.filter(notif -> notif.overlayNotification.isSticky() && notif.overlayNotification.getId().equals(id))
.collect(Collectors.toList());
this.overlayNotificationQueue.removeAll(stickiesToDismiss);
}

@Override
public Dimension render(Graphics2D graphics) {
this.setLayer(this.config.overlayLayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum NotificationType {
TRAY_NOTIFICATION("Tray Notification", "Create a tray notification", TrayNotification.class),
OVERHEAD("Overhead", "Display overhead text", Overhead.class),
OVERLAY("Overlay", "Create an overlay notification", Overlay.class),
DISMISS_OVERLAY("Dismiss Overlay", "Dismiss a sticky overlay by ID", DismissOverlay.class),
REQUEST_FOCUS("Request Focus", "Requests focus on the window", RequestFocus.class),
NOTIFICATION_EVENT("Notification Event", "Fire a NotificationFired event so that other plugins may hook into it e.g. RL Tray Notifications", NotificationEvent.class),
;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.adamk33n3r.runelite.watchdog.notifications;

import com.adamk33n3r.runelite.watchdog.WatchdogPlugin;

import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class DismissOverlay extends Notification {
private String dismissId;

@Override
protected void fireImpl(String[] triggerValues) {
WatchdogPlugin.getInstance().getNotificationOverlay().clearById(this.dismissId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Overlay extends MessageNotification {
private boolean sticky = false;
private int timeToLive = 5;
private String imagePath;
private String id;

@Inject
public Overlay(WatchdogConfig config) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.adamk33n3r.runelite.watchdog.ui.notifications.panels;

import com.adamk33n3r.runelite.watchdog.LengthLimitFilter;
import com.adamk33n3r.runelite.watchdog.SimpleDocumentListener;
import com.adamk33n3r.runelite.watchdog.notifications.DismissOverlay;
import com.adamk33n3r.runelite.watchdog.notifications.Notification;
import com.adamk33n3r.runelite.watchdog.ui.FlatTextArea;
import com.adamk33n3r.runelite.watchdog.ui.panels.NotificationsPanel;
import com.adamk33n3r.runelite.watchdog.ui.panels.PanelUtils;

import javax.swing.text.AbstractDocument;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class DismissOverlayNotificationPanel extends NotificationPanel {
public DismissOverlayNotificationPanel(DismissOverlay notification, NotificationsPanel parentPanel, Runnable onChangeListener, PanelUtils.OnRemove onRemove) {
super(notification, parentPanel, onChangeListener, onRemove);

FlatTextArea flatTextArea = new FlatTextArea("Enter the ID of the overlay...", true);
flatTextArea.setText(notification.getDismissId());
((AbstractDocument) flatTextArea.getDocument()).setDocumentFilter(new LengthLimitFilter(200));
flatTextArea.getDocument().addDocumentListener((SimpleDocumentListener) ev -> {
notification.setDismissId(flatTextArea.getText());
});
flatTextArea.getTextArea().addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
flatTextArea.getTextArea().selectAll();
}

@Override
public void focusLost(FocusEvent e) {
onChangeListener.run();
}
});
this.settings.add(flatTextArea);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.adamk33n3r.runelite.watchdog.ui.notifications.panels;

import com.adamk33n3r.runelite.watchdog.LengthLimitFilter;
import com.adamk33n3r.runelite.watchdog.SimpleDocumentListener;
import com.adamk33n3r.runelite.watchdog.notifications.Overlay;
import com.adamk33n3r.runelite.watchdog.ui.FlatTextArea;
import com.adamk33n3r.runelite.watchdog.ui.Icons;
import com.adamk33n3r.runelite.watchdog.ui.panels.NotificationsPanel;
import com.adamk33n3r.runelite.watchdog.ui.panels.PanelUtils;
Expand All @@ -12,9 +15,13 @@
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.text.AbstractDocument;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class OverlayNotificationPanel extends MessageNotificationPanel {
private JPanel displayTime;
private JPanel stickyId;

public OverlayNotificationPanel(Overlay notification, NotificationsPanel parentPanel, ColorPickerManager colorPickerManager, Runnable onChangeListener, PanelUtils.OnRemove onRemove) {
super(notification, parentPanel, onChangeListener, onRemove);
Expand Down Expand Up @@ -59,7 +66,9 @@ public OverlayNotificationPanel(Overlay notification, NotificationsPanel parentP
notification.setSticky(val);
if (val) {
this.settings.remove(this.displayTime);
this.settings.add(this.stickyId);
} else {
this.settings.remove(this.stickyId);
this.settings.add(this.displayTime);
}
this.revalidate();
Expand All @@ -73,7 +82,28 @@ public OverlayNotificationPanel(Overlay notification, NotificationsPanel parentP
});
this.displayTime = PanelUtils.createIconComponent(Icons.CLOCK, "Time to display in seconds", displayTime);

if (!notification.isSticky()) {
FlatTextArea flatTextArea = new FlatTextArea("ID to use with Dismiss Overlay...", true);
flatTextArea.setText(notification.getId());
((AbstractDocument) flatTextArea.getDocument()).setDocumentFilter(new LengthLimitFilter(200));
flatTextArea.getDocument().addDocumentListener((SimpleDocumentListener) ev -> {
notification.setId(flatTextArea.getText());
});
flatTextArea.getTextArea().addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
flatTextArea.getTextArea().selectAll();
}

@Override
public void focusLost(FocusEvent e) {
onChangeListener.run();
}
});
this.stickyId = flatTextArea;

if (notification.isSticky()) {
this.settings.add(this.stickyId);
} else {
this.settings.add(this.displayTime);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ else if (notification instanceof RequestFocus)
notificationPanel = new RequestFocusNotificationPanel((RequestFocus) notification, this, this.alertManager::saveAlerts, removeNotification);
else if (notification instanceof NotificationEvent)
notificationPanel = new MessageNotificationPanel((NotificationEvent) notification, this, this.alertManager::saveAlerts, removeNotification);
else if (notification instanceof DismissOverlay){
notificationPanel = new DismissOverlayNotificationPanel((DismissOverlay) notification, this, this.alertManager::saveAlerts, removeNotification);
}

if (notificationPanel != null)
this.notificationContainer.add(notificationPanel);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Fri Feb 09 14:40:25 EST 2024
VERSION_BUILD=4243
#Fri Feb 09 15:50:37 EST 2024
VERSION_BUILD=4249
VERSION_PHASE=release
VERSION_MAJOR=3
VERSION_MINOR=2
Expand Down

0 comments on commit 461a637

Please sign in to comment.