timetracking: add timer warning colors
Lets the user choose a time for showing when the timer should turn orange. Co-authored-by: jakewilson <jakewilsonfl@gmail.com>
This commit is contained in:
@@ -94,6 +94,18 @@ public interface TimeTrackingConfig extends Config
|
|||||||
return SortOrder.NONE;
|
return SortOrder.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "timerWarningThreshold",
|
||||||
|
name = "Timer Warning Threshold",
|
||||||
|
description = "The time at which to change the timer color to the warning color",
|
||||||
|
position = 6
|
||||||
|
)
|
||||||
|
@Units(Units.SECONDS)
|
||||||
|
default int timerWarningThreshold()
|
||||||
|
{
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "activeTab",
|
keyName = "activeTab",
|
||||||
name = "Active Tab",
|
name = "Active Tab",
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ public class TimeTrackingPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
clockDataChanged = clockManager.checkCompletion();
|
clockDataChanged = clockManager.checkCompletion();
|
||||||
timerOrderChanged = clockManager.checkTimerOrder();
|
timerOrderChanged = clockManager.checkTimerOrder();
|
||||||
|
clockManager.checkForWarnings();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unitTime % panel.getUpdateInterval() == 0 || clockDataChanged || timerOrderChanged)
|
if (unitTime % panel.getUpdateInterval() == 0 || clockDataChanged || timerOrderChanged)
|
||||||
|
|||||||
@@ -161,6 +161,17 @@ public class ClockManager
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the warning flag on each timer that should be in the warning state
|
||||||
|
*/
|
||||||
|
public void checkForWarnings()
|
||||||
|
{
|
||||||
|
for (Timer timer : timers)
|
||||||
|
{
|
||||||
|
timer.setWarning(timer.getDisplayTime() <= config.timerWarningThreshold());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void loadTimers()
|
public void loadTimers()
|
||||||
{
|
{
|
||||||
final String timersJson = configManager.getConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.TIMERS);
|
final String timersJson = configManager.getConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.TIMERS);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ abstract class ClockPanel extends JPanel
|
|||||||
|
|
||||||
private final FlatTextField nameInput;
|
private final FlatTextField nameInput;
|
||||||
private final JToggleButton startPauseButton;
|
private final JToggleButton startPauseButton;
|
||||||
private final FlatTextField displayInput;
|
protected final FlatTextField displayInput;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
@@ -150,6 +150,7 @@ abstract class ClockPanel extends JPanel
|
|||||||
|
|
||||||
clock.setDuration(Math.max(0, duration));
|
clock.setDuration(Math.max(0, duration));
|
||||||
clock.reset();
|
clock.reset();
|
||||||
|
clockManager.checkForWarnings();
|
||||||
updateDisplayInput();
|
updateDisplayInput();
|
||||||
updateActivityStatus();
|
updateActivityStatus();
|
||||||
clockManager.saveTimers();
|
clockManager.saveTimers();
|
||||||
@@ -199,6 +200,7 @@ abstract class ClockPanel extends JPanel
|
|||||||
resetButton.addActionListener(e ->
|
resetButton.addActionListener(e ->
|
||||||
{
|
{
|
||||||
clock.reset();
|
clock.reset();
|
||||||
|
clockManager.checkForWarnings();
|
||||||
reset();
|
reset();
|
||||||
clockManager.saveToConfig();
|
clockManager.saveToConfig();
|
||||||
});
|
});
|
||||||
@@ -238,7 +240,7 @@ abstract class ClockPanel extends JPanel
|
|||||||
boolean isActive = clock.isActive();
|
boolean isActive = clock.isActive();
|
||||||
|
|
||||||
displayInput.setEditable(editable && !isActive);
|
displayInput.setEditable(editable && !isActive);
|
||||||
displayInput.getTextField().setForeground(isActive ? ACTIVE_CLOCK_COLOR : INACTIVE_CLOCK_COLOR);
|
displayInput.getTextField().setForeground(getColor());
|
||||||
startPauseButton.setToolTipText(isActive ? "Pause " + clockType : "Start " + clockType);
|
startPauseButton.setToolTipText(isActive ? "Pause " + clockType : "Start " + clockType);
|
||||||
startPauseButton.setSelected(isActive);
|
startPauseButton.setSelected(isActive);
|
||||||
|
|
||||||
@@ -248,6 +250,11 @@ abstract class ClockPanel extends JPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Color getColor()
|
||||||
|
{
|
||||||
|
return clock.isActive() ? ACTIVE_CLOCK_COLOR : INACTIVE_CLOCK_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
static String getFormattedDuration(long duration)
|
static String getFormattedDuration(long duration)
|
||||||
{
|
{
|
||||||
long hours = duration / (60 * 60);
|
long hours = duration / (60 * 60);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
package net.runelite.client.plugins.timetracking.clocks;
|
package net.runelite.client.plugins.timetracking.clocks;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -40,11 +41,16 @@ class Timer extends Clock
|
|||||||
// the number of seconds remaining on the timer, as of last updated time
|
// the number of seconds remaining on the timer, as of last updated time
|
||||||
private long remaining;
|
private long remaining;
|
||||||
|
|
||||||
|
// whether this timer is in the 'warning' state or not
|
||||||
|
@Getter(AccessLevel.NONE)
|
||||||
|
private transient boolean warning;
|
||||||
|
|
||||||
Timer(String name, long duration)
|
Timer(String name, long duration)
|
||||||
{
|
{
|
||||||
super(name);
|
super(name);
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.remaining = duration;
|
this.remaining = duration;
|
||||||
|
this.warning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,6 +72,7 @@ class Timer extends Clock
|
|||||||
if (remaining <= 0)
|
if (remaining <= 0)
|
||||||
{
|
{
|
||||||
remaining = duration;
|
remaining = duration;
|
||||||
|
warning = false;
|
||||||
}
|
}
|
||||||
lastUpdate = Instant.now().getEpochSecond();
|
lastUpdate = Instant.now().getEpochSecond();
|
||||||
active = true;
|
active = true;
|
||||||
@@ -96,4 +103,9 @@ class Timer extends Clock
|
|||||||
remaining = duration;
|
remaining = duration;
|
||||||
lastUpdate = Instant.now().getEpochSecond();
|
lastUpdate = Instant.now().getEpochSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isWarning()
|
||||||
|
{
|
||||||
|
return warning && (remaining > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,16 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.timetracking.clocks;
|
package net.runelite.client.plugins.timetracking.clocks;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import net.runelite.client.ui.ColorScheme;
|
||||||
import net.runelite.client.util.SwingUtil;
|
import net.runelite.client.util.SwingUtil;
|
||||||
|
|
||||||
class TimerPanel extends ClockPanel
|
class TimerPanel extends ClockPanel
|
||||||
{
|
{
|
||||||
|
private static final Color WARNING_COLOR = ColorScheme.BRAND_ORANGE;
|
||||||
|
|
||||||
TimerPanel(ClockManager clockManager, Timer timer)
|
TimerPanel(ClockManager clockManager, Timer timer)
|
||||||
{
|
{
|
||||||
super(clockManager, timer, "timer", true);
|
super(clockManager, timer, "timer", true);
|
||||||
@@ -42,4 +46,25 @@ class TimerPanel extends ClockPanel
|
|||||||
deleteButton.addActionListener(e -> clockManager.removeTimer(timer));
|
deleteButton.addActionListener(e -> clockManager.removeTimer(timer));
|
||||||
rightActions.add(deleteButton);
|
rightActions.add(deleteButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void updateDisplayInput()
|
||||||
|
{
|
||||||
|
super.updateDisplayInput();
|
||||||
|
|
||||||
|
Timer timer = (Timer) getClock();
|
||||||
|
if (timer.isWarning())
|
||||||
|
{
|
||||||
|
displayInput.getTextField().setForeground(getColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color getColor()
|
||||||
|
{
|
||||||
|
Timer timer = (Timer) getClock();
|
||||||
|
Color warningColor = timer.isActive() ? WARNING_COLOR : WARNING_COLOR.darker();
|
||||||
|
|
||||||
|
return timer.isWarning() ? warningColor : super.getColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user