diff options
author | Erymanthus[#5074] | (u/)RayDeeUx <51521765+RayDeeUx@users.noreply.github.com> | 2023-10-14 08:00:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-14 14:00:41 +0200 |
commit | d1a9b5b3ea2a4a140fc1aa34db3ad8a79822391c (patch) | |
tree | 01be443e27c247e858c921318a354e5f00dbc601 /src/main/java/at/hannibal2/skyhanni/features/misc | |
parent | 7a634386ec4dd842e946bd3ba331c0d565faf173 (diff) | |
download | skyhanni-d1a9b5b3ea2a4a140fc1aa34db3ad8a79822391c.tar.gz skyhanni-d1a9b5b3ea2a4a140fc1aa34db3ad8a79822391c.tar.bz2 skyhanni-d1a9b5b3ea2a4a140fc1aa34db3ad8a79822391c.zip |
Addition: Ingame time GUI element (#503)
Added In-Game Date Display. #503
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt | 42 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt | 19 |
2 files changed, 44 insertions, 17 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt new file mode 100644 index 000000000..8c33566d8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt @@ -0,0 +1,42 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.getFormattedSkyblockTime +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordStatus +import io.github.moulberry.notenoughupdates.util.SkyBlockTime +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.concurrent.fixedRateTimer + +class InGameDateDisplay { + private val config get() = SkyHanniMod.feature.gui + private var display = "" + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled()) return + if (!event.repeatSeconds(config.inGameDateDisplayRefreshSeconds)) return + + checkDate() + } + + private fun checkDate() { + if (!isEnabled()) return + + display = SkyBlockTime.now().getFormattedSkyblockTime() + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + + config.inGameDateDisplayPosition.renderString(display, posLabel = "In-game Date Display") + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.inGameDateDisplay +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt index 433f468cb..fed77fd39 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.colorCodeToRarity +import at.hannibal2.skyhanni.utils.LorenzUtils.getFormattedSkyblockTime import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -179,23 +180,7 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) }), TIME({ - fun formatNum(num: Int): Int { - val rem = num % 10 - var returnNum = num - rem // floor() - if (returnNum == 0) { - returnNum = "0$num".toInt() - /** - * and this is so that if the minute value is ever - * a single digit (0 after being floored), it displays as 00 because 12:0pm looks bad - */ - } - return returnNum - } - - val date: SkyBlockTime = SkyBlockTime.now() - val hour = if (date.hour > 12) date.hour - 12 else date.hour - val timeOfDay = if (date.hour > 11) "pm" else "am" // hooray for 12-hour clocks - "${SkyBlockTime.monthName(date.month)} ${date.day}${SkyBlockTime.daySuffix(date.day)}, $hour:${formatNum(date.minute)}$timeOfDay" // Early Winter 1st, 12:00pm + SkyBlockTime.now().getFormattedSkyblockTime() }), PROFILE({ |