From 394df0bc44b535be522839b2ce719f411eee6be4 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sun, 21 Jul 2024 22:55:33 +1000 Subject: Add support for only showing custom todos when they are soon (#1257) --- .../miscgui/customtodos/CustomTodo.kt | 2 + .../miscgui/customtodos/CustomTodoEditor.kt | 69 +++++++++++++++++++--- .../miscgui/customtodos/CustomTodoHud.kt | 4 +- .../notenoughupdates/gui/customtodos/edit.xml | 45 +++++++++++--- 4 files changed, 105 insertions(+), 15 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 = 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 @@ -45,6 +45,9 @@ class CustomTodoEditor( @field:Bind var timer: String = from.timer.toString() + @field:Bind + var showWhen: String = from.showWhen.toString() + @field:Bind var trigger: String = from.trigger @@ -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,40 +193,87 @@ 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) 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) diff --git a/src/main/resources/assets/notenoughupdates/gui/customtodos/edit.xml b/src/main/resources/assets/notenoughupdates/gui/customtodos/edit.xml index 551d0611..dd2d4e28 100644 --- a/src/main/resources/assets/notenoughupdates/gui/customtodos/edit.xml +++ b/src/main/resources/assets/notenoughupdates/gui/customtodos/edit.xml @@ -52,25 +52,56 @@ - + - - - - - - + + + + + + + + + + + + + + + + + + + -- cgit