aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/io/github
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-07-21 22:55:33 +1000
committerGitHub <noreply@github.com>2024-07-21 14:55:33 +0200
commit394df0bc44b535be522839b2ce719f411eee6be4 (patch)
treebd7d9ed7776282a4b9a8a5ea4f1ca0e4c7178b78 /src/main/kotlin/io/github
parentc619022fe1910f0976397a9bcbecfed9b48c6a19 (diff)
downloadnotenoughupdates-394df0bc44b535be522839b2ce719f411eee6be4.tar.gz
notenoughupdates-394df0bc44b535be522839b2ce719f411eee6be4.tar.bz2
notenoughupdates-394df0bc44b535be522839b2ce719f411eee6be4.zip
Add support for only showing custom todos when they are soon (#1257)
Diffstat (limited to 'src/main/kotlin/io/github')
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodo.kt2
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt69
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt4
3 files changed, 67 insertions, 8 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodo.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodo.kt
index 7f8c6d1a..181f3335 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodo.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodo.kt
@@ -31,6 +31,8 @@ data class CustomTodo(
@Expose var trigger: String,
@Expose var icon: String,
@Expose var isResetOffset: Boolean,
+ @Expose var showWhen: Int = 0,
+ @Expose var showOnlyWhenReady: Boolean = false,
@Expose var triggerTarget: TriggerTarget = TriggerTarget.CHAT,
@Expose var triggerMatcher: TriggerMatcher = TriggerMatcher.CONTAINS,
@Expose var readyAt: MutableMap<String, Long> = mutableMapOf(),
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt
index 922240ed..2b69af48 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt
@@ -46,6 +46,9 @@ class CustomTodoEditor(
var timer: String = from.timer.toString()
@field:Bind
+ var showWhen: String = from.showWhen.toString()
+
+ @field:Bind
var trigger: String = from.trigger
@field:Bind
@@ -54,6 +57,9 @@ class CustomTodoEditor(
@field:Bind
var isResetOffset: Boolean = from.isResetOffset
+ @field:Bind
+ var showOnlyWhenReady: Boolean = from.showOnlyWhenReady
+
var target = from.triggerTarget
var matchMode = from.triggerMatcher
@@ -64,6 +70,8 @@ class CustomTodoEditor(
trigger,
icon,
isResetOffset,
+ showWhen.toIntOrNull() ?: 0,
+ showOnlyWhenReady,
target, matchMode,
from.readyAt,
from.enabled.toMutableMap().also { it[SBInfo.getInstance().currentProfile ?: return@also] = enabled }
@@ -176,7 +184,7 @@ class CustomTodoEditor(
}
@Bind
- fun getFancyTime(): String {
+ fun getFancyTimeTimer(): String {
val tint = timer.toIntOrNull() ?: return "§3Invalid Time"
val timeFormat = Utils.prettyTime(tint * 1000L)
if (isResetOffset) {
@@ -185,41 +193,88 @@ class CustomTodoEditor(
return "Reset $timeFormat after completion"
}
+ @Bind
+ fun getFancyTimeShowWhen(): String {
+ if (showOnlyWhenReady) {
+ return "Shown only when task is ready"
+ }
+ val tint = showWhen.toIntOrNull() ?: return "§3Invalid Time"
+ val timeFormat = Utils.prettyTime(tint * 1000L)
+ if (tint == 0) {
+ return "Always shown"
+ }
+ return "Show if less than $timeFormat until ready"
+ }
+
fun changeTimer(value: Int) {
timer = ((timer.toIntOrNull() ?: 0) + value).coerceAtLeast(0).toString()
}
+ fun changeShowWhen(value: Int) {
+ showWhen = ((showWhen.toIntOrNull() ?: 0) + value).coerceAtLeast(0).toString()
+ }
+
@Bind
- fun plusDay() {
+ fun plusDayTimer() {
changeTimer(60 * 60 * 24)
}
@Bind
- fun minusDay() {
+ fun minusDayTimer() {
changeTimer(-60 * 60 * 24)
}
@Bind
- fun minusHour() {
+ fun minusHourTimer() {
changeTimer(-60 * 60)
}
@Bind
- fun plusHour() {
+ fun plusHourTimer() {
changeTimer(60 * 60)
}
@Bind
- fun plusMinute() {
+ fun plusMinuteTimer() {
changeTimer(60)
}
@Bind
- fun minusMinute() {
+ fun minusMinuteTimer() {
changeTimer(-60)
}
@Bind
+ fun plusDayShowWhen() {
+ changeShowWhen(60 * 60 * 24)
+ }
+
+ @Bind
+ fun minusDayShowWhen() {
+ changeShowWhen(-60 * 60 * 24)
+ }
+
+ @Bind
+ fun minusHourShowWhen() {
+ changeShowWhen(-60 * 60)
+ }
+
+ @Bind
+ fun plusHourShowWhen() {
+ changeShowWhen(60 * 60)
+ }
+
+ @Bind
+ fun plusMinuteShowWhen() {
+ changeShowWhen(60)
+ }
+
+ @Bind
+ fun minusMinuteShowWhen() {
+ changeShowWhen(-60)
+ }
+
+ @Bind
fun delete() {
todos.remove(this)
CustomTodoList(todos, xmlUniverse).save()
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt
index 83d162f6..ad0e1c65 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt
@@ -104,10 +104,12 @@ object CustomTodoHud {
.forEach {
val readyAt = it.readyAtOnCurrentProfile ?: (System.currentTimeMillis() - 1000L)
val until = readyAt - System.currentTimeMillis()
+ if ((!it.showOnlyWhenReady && it.showWhen > 0) && until - (it.showWhen * 1000) > 0) return@forEach
+ if (it.showOnlyWhenReady && until >= 0) return@forEach
strings.add(
encodeCustomItem(it.icon) + ":§3" + it.label + ": " +
if (until <= 0)
- EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.readyColour].toString() + "Ready"
+ EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.readyColour].toString() + "Ready!"
else if (until < 60 * 30 * 1000L)
EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.verySoonColour].toString()
+ Utils.prettyTime(until)