From 1a38f3d79d6cdbe90455191712fa71f0ac1aa7e6 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:17:58 +1000 Subject: Merge pull request #284 * custom text box * grammar * renamed thing * may as well fix this here as well --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 1 + .../hannibal2/skyhanni/config/features/Misc.java | 23 +++++++++++++++ .../skyhanni/features/misc/CustomTextBox.kt | 33 ++++++++++++++++++++++ .../features/misc/FrozenTreasureTracker.kt | 2 +- .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 4 +++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/CustomTextBox.kt (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index dfaa3c34f..d863f5ee8 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -315,6 +315,7 @@ class SkyHanniMod { loadModule(DungeonLividFinder) loadModule(CruxTalismanDisplay) loadModule(LaserParkour()) + loadModule(CustomTextBox()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index 497190529..4e69a2c92 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -552,6 +552,29 @@ public class Misc { public Position position = new Position(10, 80, false, true); } + @Expose + @ConfigOption(name = "Custom Text box", desc = "") + @Accordion + public TextBox textBox = new TextBox(); + + public static class TextBox { + + @Expose + @ConfigOption(name = "Enabled", desc = "Enables showing the textbox while in SkyBlock.") + @ConfigEditorBoolean + public boolean enabled = false; + + @Expose + @ConfigOption(name = "Text", desc = "Enter text you want to display here.\n" + + "§eUse '&' as the colour code character.\n" + + "§eUse '\\n' as the line break character.") + @ConfigEditorText + public Property text = Property.of("&aYour Text Here\n&bYour new line here"); + + @Expose + public Position position = new Position(10, 80, false, true); + } + @Expose @ConfigOption(name = "Exp Bottles", desc = "Hides all the experience orbs lying on the ground.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CustomTextBox.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CustomTextBox.kt new file mode 100644 index 000000000..7c05c6af1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CustomTextBox.kt @@ -0,0 +1,33 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.afterChange +import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class CustomTextBox { + private val config get() = SkyHanniMod.feature.misc.textBox + private var display = listOf() + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + display = config.text.get().format() + + config.text.afterChange { + display = format() + } + } + + private fun String.format() = replace("&", "§").split("\\n").toList() + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!config.enabled) return + if (!LorenzUtils.inSkyBlock) return + + config.position.renderStrings(display, posLabel = "Custom Text Box") + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt index c31135431..dfb4b6973 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt @@ -162,7 +162,7 @@ class FrozenTreasureTracker { if (!config.enabled) return if (!onJerryWorkshop()) return if (config.onlyInCave && !inGlacialCave()) return - config.position.renderStringsAndItems(display, posLabel = "Visitor Stats") + config.position.renderStringsAndItems(display, posLabel = "Frozen Treasure Tracker") } private fun onJerryWorkshop() = LorenzUtils.inIsland(IslandType.WINTER) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index c1309d573..77a47b895 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -275,6 +275,10 @@ object LorenzUtils { whenChanged { _, _ -> observer.run() } } + fun Property.afterChange(observer: T.() -> Unit) { + whenChanged { _, new -> observer(new) } + } + fun Map.editCopy(function: MutableMap.() -> Unit) = toMutableMap().also { function(it) }.toMap() -- cgit