Skip to content

Commit

Permalink
Add overlay timer configuration options (#136)
Browse files Browse the repository at this point in the history
* Add test logic for hydrate overlay

* Add remaining timer images with id under 10000

* Add remaining timer images with id over 10000

* Fix test names to adhere to code style guidelines

* Refactor enum getValue logic

* Add unit tests for timer images enum

* Use timer config options to update overlay

* Add unit tests for timer class

* Fix image naming error

* Improve unit test regex checks

* Refactor regex expressions in unit tests

* Fix position numbers of configuration options

* Refactor section configuration code
  • Loading branch information
jmakhack authored Jul 2, 2022
1 parent 21f1a20 commit 309dfdb
Show file tree
Hide file tree
Showing 37 changed files with 677 additions and 26 deletions.
Empty file modified .all-contributorsrc
100644 → 100755
Empty file.
Empty file modified .github/FUNDING.yml
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/bug-report.md
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/feature-request.md
100644 → 100755
Empty file.
Empty file modified .github/PULL_REQUEST_TEMPLATE.md
100644 → 100755
Empty file.
Empty file modified .github/config.yml
100644 → 100755
Empty file.
Empty file modified .github/dependabot.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/codeql-analysis.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/gradle.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified CODE_OF_CONDUCT.md
100644 → 100755
Empty file.
Empty file modified CONTRIBUTING.md
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified SECURITY.md
100644 → 100755
Empty file.
14 changes: 6 additions & 8 deletions build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@ repositories {
mavenCentral()
}

def runeLiteVersion = '1.7.27'
def runeLiteVersion = '1.8.24.3'

dependencies {
compileOnly group: 'net.runelite', name:'client', version: runeLiteVersion

compileOnly 'org.projectlombok:lombok:1.18.4'
annotationProcessor 'org.projectlombok:lombok:1.18.4'
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'

testImplementation 'junit:junit:4.12'
testImplementation 'org.slf4j:slf4j-simple:1.7.12'
testImplementation group: 'net.runelite', name:'client', version: runeLiteVersion, {
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
testImplementation group: 'net.runelite', name:'client', version: runeLiteVersion
testImplementation group: 'net.runelite', name:'jshell', version: runeLiteVersion
}

group = 'com.hydratereminder'
version = '1.1.1'
version = '1.2.0'
sourceCompatibility = '1.8'

tasks.withType(JavaCompile) {
Expand Down
Empty file modified gradle/wrapper/gradle-wrapper.jar
100644 → 100755
Empty file.
Empty file modified gradle/wrapper/gradle-wrapper.properties
100644 → 100755
Empty file.
Empty file modified gradlew
100644 → 100755
Empty file.
Empty file modified gradlew.bat
100644 → 100755
Empty file.
Empty file modified icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified runelite-plugin.properties
100644 → 100755
Empty file.
Empty file modified settings.gradle
100644 → 100755
Empty file.
Empty file.
10 changes: 9 additions & 1 deletion src/main/java/com/hydratereminder/HydrateReminderCommandArgs.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
* <p>All command arguments that the Hydrate Reminder plugin supports
* </p>
Expand Down Expand Up @@ -61,11 +63,17 @@ public String toString()
return getCommandArg();
}

/**
* <p>Get the enum value from a given command string
* </p>
* @param command chat command to get value for
* @since 1.1.0
*/
public static HydrateReminderCommandArgs getValue(String command)
{
for (HydrateReminderCommandArgs enumValue : HydrateReminderCommandArgs.values())
{
if (enumValue.getCommandArg() == command || enumValue.getCommandArgAbbr() == command)
if (Objects.equals(enumValue.getCommandArg(), command) || Objects.equals(enumValue.getCommandArgAbbr(), command))
return enumValue;
}
throw new IllegalArgumentException();
Expand Down
75 changes: 70 additions & 5 deletions src/main/java/com/hydratereminder/HydrateReminderConfig.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@

package com.hydratereminder;

import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Range;
import net.runelite.client.config.Units;
import net.runelite.client.config.*;

import java.awt.*;

/**
* <p>Configuration options interface for the Hydrate Reminder plugin
Expand All @@ -51,6 +49,18 @@ public interface HydrateReminderConfig extends Config
*/
int INTERVAL_LIMIT_MAX = 90;

/**
* <p>Separates the overlay timer settings into its own config section
* </p>
* @since 1.2.0
*/
@ConfigSection(
name = "Overlay Timer Display",
description = "Settings for Hydrate Reminder Overlay Timer",
position = 6
)
String hydrateReminderTimerSection = "Hydrate Reminder Overlay Timer Settings";

/**
* <p>Allows the player to enable/disable the hydrate login welcome message
* </p>
Expand Down Expand Up @@ -141,4 +151,59 @@ default boolean hydrateReminderComputerNotificationEnabled()
{
return false;
}

/**
* <p>Allows the player to enable/disable the overlay timer
* </p>
* @return true if the overlay timer is enabled
* @since 1.2.0
*/
@ConfigItem(
keyName = "hydrateReminderOverlayTimerEnabled",
name = "Timer Display",
description = "Sets the hydrate reminder to be sent as a computer notification",
position = 7,
section = hydrateReminderTimerSection
)
default boolean hydrateReminderOverlayTimerEnabled()
{
return true;
}

/**
* <p>Allows the player to select the text color of the overlay timer
* </p>
* @return the color to use for the overlay timer text
* @since 1.2.0
*/
@Alpha
@ConfigItem(
keyName = "hydrateReminderOverlayTimerTextColor",
name = "Text Color",
description = "Sets the text color of the timer display",
position = 8,
section = hydrateReminderTimerSection
)
default Color hydrateReminderOverlayTimerTextColor()
{
return Color.WHITE;
}

/**
* <p>Allows the player to set the image displayed on the overlay timer
* </p>
* @return the image to display on the overlay timer
* @since 1.2.0
*/
@ConfigItem(
keyName = "hydrateReminderOverlayTimerImage",
name = "Timer Image",
description = "Sets the background image of the timer display",
position = 9,
section = hydrateReminderTimerSection
)
default HydrateReminderTimerImages hydrateReminderOverlayTimerImage()
{
return HydrateReminderTimerImages.CUP_OF_WATER_IMAGE;
}
}
24 changes: 16 additions & 8 deletions src/main/java/com/hydratereminder/HydrateReminderPlugin.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@
import org.apache.commons.lang3.ArrayUtils;

import javax.inject.Inject;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.List;

import static net.runelite.api.ItemID.*;

/**
Expand Down Expand Up @@ -542,10 +545,14 @@ public void onGameTick(GameTick event)
{
sendHydrateWelcomeChatMessage();
}
removeHydrateReminderTimer();
createHydrateReminderTimer(CUP_OF_WATER);
setFirstGameTick(false);
}
// TODO: Improve resource management & performance by not having to remove and create the overlay timer on every game tick to apply updates
removeHydrateReminderOverlayTimer();
if (config.hydrateReminderOverlayTimerEnabled())
{
createHydrateReminderOverlayTimer();
}
final Instant nextHydrateReminderInstant = getNextHydrateReminderInstant();
if (nextHydrateReminderInstant.compareTo(Instant.now()) < 0)
{
Expand All @@ -560,15 +567,16 @@ public void onGameTick(GameTick event)
* <p>Initializes a new hydrate reminder timer and renders it as an infobox on the
* overlay given that one has not been initialized already
* </p>
* @param itemID id of the item to use as the infobox background
* @since 1.2.0
*/
private void createHydrateReminderTimer(int itemID)
private void createHydrateReminderOverlayTimer()
{
if (!getHydrateReminderTimer().isPresent())
{
final BufferedImage infoboxImage = itemManager.getImage(itemID);
final HydrateReminderTimer newTimer = new HydrateReminderTimer(this, infoboxImage);
final int imageID = config.hydrateReminderOverlayTimerImage().getID();
final BufferedImage timerImage = itemManager.getImage(imageID);
final Color timerColor = config.hydrateReminderOverlayTimerTextColor();
final HydrateReminderTimer newTimer = new HydrateReminderTimer(this, timerImage, timerColor);
setHydrateReminderTimer(Optional.of(newTimer));
infoBoxManager.addInfoBox(getHydrateReminderTimer().get());
}
Expand All @@ -579,9 +587,9 @@ private void createHydrateReminderTimer(int itemID)
* </p>
* @since 1.2.0
*/
private void removeHydrateReminderTimer()
private void removeHydrateReminderOverlayTimer()
{
if (hydrateReminderTimer.isPresent())
if (getHydrateReminderTimer().isPresent())
{
infoBoxManager.removeInfoBox(getHydrateReminderTimer().get());
hydrateReminderTimer = Optional.empty();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/hydratereminder/HydrateReminderTimer.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ public class HydrateReminderTimer extends InfoBox
* </p>
* @param plugin the plugin creating the timer
* @param image the background image for the infobox
* @param timerColor the color to use for the timer text
* @since 1.2.0
*/
HydrateReminderTimer(HydrateReminderPlugin plugin, BufferedImage image)
HydrateReminderTimer(HydrateReminderPlugin plugin, BufferedImage image, Color timerColor)
{
super(image, plugin);
setPriority(InfoBoxPriority.MED);
hydrateReminderPlugin = plugin;
textColor = Color.WHITE;
textColor = timerColor;
}

/**
Expand Down
Loading

0 comments on commit 309dfdb

Please sign in to comment.