Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: overhead text color picker #142

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@
import net.runelite.api.Client;
import net.runelite.api.Constants;
import net.runelite.api.Player;
import net.runelite.client.util.ColorUtil;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import javax.inject.Inject;
import java.awt.Color;
import java.util.concurrent.ScheduledExecutorService;

@Slf4j
@NoArgsConstructor
public class Overhead extends MessageNotification {
@Getter @Setter
private int displayTime = 3;
@Getter @Setter
private Color textColor = null;

@Inject
private transient Client client;
Expand All @@ -39,7 +43,17 @@ protected void fireImpl(String[] triggerValues) {
if (localPlayer == null) {
return;
}
localPlayer.setOverheadText(message);
StringBuilder sb = new StringBuilder();
if (this.textColor != null) {
sb.append("<col=")
.append(ColorUtil.colorToHexCode(this.textColor))
.append(">")
.append(message)
.append("</col>");
} else {
sb.append(message);
}
localPlayer.setOverheadText(sb.toString());
localPlayer.setOverheadCycle(this.displayTime * 1000 / Constants.CLIENT_TICK_LENGTH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,29 @@
import com.adamk33n3r.runelite.watchdog.ui.panels.NotificationsPanel;
import com.adamk33n3r.runelite.watchdog.ui.panels.PanelUtils;

import net.runelite.client.ui.components.ColorJButton;
import net.runelite.client.ui.components.colorpicker.ColorPickerManager;

import javax.swing.JSpinner;

public class OverheadNotificationPanel extends MessageNotificationPanel {
public OverheadNotificationPanel(Overhead notification, NotificationsPanel parentPanel, Runnable onChangeListener, PanelUtils.OnRemove onRemove) {
public OverheadNotificationPanel(Overhead notification, NotificationsPanel parentPanel, ColorPickerManager colorPickerManager, Runnable onChangeListener, PanelUtils.OnRemove onRemove) {
super(notification, parentPanel, onChangeListener, onRemove);

ColorJButton colorPickerBtn = PanelUtils.createColorPicker(
"Pick a color",
"The color of the overhead text. Right click to reset.",
"Text Color",
this,
notification.getTextColor(),
colorPickerManager,
false,
val -> {
notification.setTextColor(val);
onChangeListener.run();
});
this.settings.add(colorPickerBtn);

JSpinner displayTime = PanelUtils.createSpinner(notification.getDisplayTime(), 1, 99, 1, val -> {
notification.setDisplayTime(val);
onChangeListener.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ else if (notification instanceof TrayNotification)
else if (notification instanceof ScreenFlash)
notificationPanel = new ScreenFlashNotificationPanel((ScreenFlash) notification, this, this.colorPickerManager, this.alertManager::saveAlerts, removeNotification);
else if (notification instanceof Overhead)
notificationPanel = new OverheadNotificationPanel((Overhead) notification, this, this.alertManager::saveAlerts, removeNotification);
notificationPanel = new OverheadNotificationPanel((Overhead) notification, this, this.colorPickerManager, this.alertManager::saveAlerts, removeNotification);
else if (notification instanceof Overlay)
notificationPanel = new OverlayNotificationPanel((Overlay) notification, this, this.colorPickerManager, this.alertManager::saveAlerts, removeNotification);
else if (notification instanceof RequestFocus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static JSpinner createSpinner(int initialValue, int min, int max, int ste
public static ColorJButton createColorPicker(String placeholder, String tooltip, String windowTitle, Component parentComponent, Color initialValue, ColorPickerManager colorPickerManager, boolean showAlpha, Consumer<Color> onChange) {
ColorJButton colorPickerBtn = new ColorJButton(placeholder, Color.BLACK);
if (initialValue != null) {
String colorHex = "#" + ColorUtil.colorToAlphaHexCode(initialValue).toUpperCase();
String colorHex = "#" + (showAlpha ? ColorUtil.colorToAlphaHexCode(initialValue) : ColorUtil.colorToHexCode(initialValue)).toUpperCase();
colorPickerBtn.setText(colorHex);
colorPickerBtn.setColor(initialValue);
}
Expand All @@ -228,6 +228,12 @@ public static ColorJButton createColorPicker(String placeholder, String tooltip,
colorPickerBtn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
colorPickerBtn.setColor(Color.BLACK);
colorPickerBtn.setText(placeholder);
onChange.accept(null);
return;
}
RuneliteColorPicker colorPicker = colorPickerManager.create(
SwingUtilities.getWindowAncestor(colorPickerBtn),
colorPickerBtn.getColor(),
Expand All @@ -236,7 +242,7 @@ public void mouseClicked(MouseEvent e) {
colorPicker.setLocation(parentComponent.getLocationOnScreen());
colorPicker.setOnColorChange(c -> {
colorPickerBtn.setColor(c);
colorPickerBtn.setText("#" + ColorUtil.colorToAlphaHexCode(c).toUpperCase());
colorPickerBtn.setText("#" + (showAlpha ? ColorUtil.colorToAlphaHexCode(c) : ColorUtil.colorToHexCode(c)).toUpperCase());
});
colorPicker.setOnClose(onChange);
colorPicker.setVisible(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Fri Apr 19 19:38:50 EDT 2024
VERSION_BUILD=4633
#Tue Apr 23 14:39:44 EDT 2024
VERSION_BUILD=4639
VERSION_PHASE=release
VERSION_MAJOR=3
VERSION_MINOR=3
Expand Down