From b76ffd5ce3e181d23988fc3bd41c30edd84457a9 Mon Sep 17 00:00:00 2001 From: inglettronald Date: Sun, 23 Jul 2023 10:24:53 -0500 Subject: wip --- .../kotlin/com/dulkirfabric/config/DulkirConfig.kt | 17 ++++++- .../kotlin/com/dulkirfabric/features/RenderTest.kt | 13 +++++ .../dulkirfabric/util/JarvisIntegrationPlugin.kt | 15 ++++++ .../com/dulkirfabric/util/render/HudElement.kt | 57 ++++++++++++++++++++++ .../util/render/HudElementDefaultPositionings.kt | 8 +++ 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt create mode 100644 src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt create mode 100644 src/main/kotlin/com/dulkirfabric/util/render/HudElementDefaultPositionings.kt (limited to 'src/main/kotlin/com/dulkirfabric') diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt index 06b19ad..ac7e209 100644 --- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt +++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt @@ -18,6 +18,8 @@ import com.dulkirfabric.config.ConfigHelper.mkKeyField import com.dulkirfabric.config.ConfigHelper.mkStringField import com.dulkirfabric.config.ConfigHelper.mkToggle import com.dulkirfabric.util.render.AnimationPreset +import com.dulkirfabric.util.render.HudElement +import com.dulkirfabric.util.render.HudElementDefaultPositionings import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlinx.serialization.decodeFromString @@ -264,7 +266,8 @@ class DulkirConfig { var arachneSpawnTimer: Boolean = false, var bridgeFormatter: Boolean = false, var bridgeBotName: String = "Dilkur", - var bridgeNameColor: Int = Formatting.GOLD.colorValue!! + var bridgeNameColor: Int = Formatting.GOLD.colorValue!!, + var hudPosData: HudElementDefaultPositionings = HudElementDefaultPositionings() ) @Serializable @@ -285,6 +288,15 @@ class DulkirConfig { companion object ConfigVars { var configOptions = ConfigOptions() + var Huds: MutableMap<(HudElementDefaultPositionings) -> HudElement.Positioning, HudElement> = mutableMapOf() + fun hudElement(pos: (HudElementDefaultPositionings) -> HudElement.Positioning, label: Text, width: Int, height: Int): HudElement { + val hud = HudElement(pos(configOptions.hudPosData), label, width, height) + Huds[pos] = hud + return hud + } + + val fooHudElement: HudElement = hudElement(HudElementDefaultPositionings::fooPos, Text.literal("§6Hello World!"), 200, 11) + private fun saveConfig() { val json = Json { prettyPrint = true @@ -312,6 +324,9 @@ class DulkirConfig { } configOptions = json.decodeFromString(configFile.readText()) } + Huds.forEach { (a, b) -> + b.positioning = a(configOptions.hudPosData) + } } } } \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt index 3cc489d..e139ad0 100644 --- a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt +++ b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt @@ -1,6 +1,9 @@ package com.dulkirfabric.features +import com.dulkirfabric.DulkirModFabric.mc +import com.dulkirfabric.config.DulkirConfig import com.dulkirfabric.events.EntityLoadEvent +import com.dulkirfabric.events.HudRenderEvent import com.dulkirfabric.events.WorldRenderLastEvent import com.dulkirfabric.util.render.WorldRenderUtils import meteordevelopment.orbit.EventHandler @@ -30,4 +33,14 @@ object RenderTest { //if (event.entity !is GlowingEntityInterface) return //event.entity.setDulkirEntityGlow(true, Color(0, 0, 255, 255),false) } + + @EventHandler + fun onRenderHud(event: HudRenderEvent) { + val context = event.context + val matrices = context.matrices + matrices.push() + DulkirConfig.fooHudElement.applyTransformations(matrices) + context.drawText(mc.textRenderer, Text.literal("§6This is the actual element."),0, 0, -1, true) + matrices.pop() + } } \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt b/src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt new file mode 100644 index 0000000..e1f986b --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt @@ -0,0 +1,15 @@ +package com.dulkirfabric.util + +import com.dulkirfabric.config.DulkirConfig +import moe.nea.jarvis.api.JarvisHud +import moe.nea.jarvis.api.JarvisPlugin + +class JarvisIntegrationPlugin: JarvisPlugin { + override fun getModId(): String { + return "dulkirmod-fabric" + } + + override fun getAllHuds(): List { + return DulkirConfig.Huds.values.toList() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt b/src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt new file mode 100644 index 0000000..824c745 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt @@ -0,0 +1,57 @@ +package com.dulkirfabric.util.render + +import kotlinx.serialization.Serializable +import moe.nea.jarvis.api.JarvisHud +import moe.nea.jarvis.api.JarvisScalable +import net.minecraft.text.Text + +class HudElement (var positioning: Positioning, + private val label: Text, + private val width: Int, + private val height: Int + ): JarvisHud, JarvisScalable { + + @Serializable + data class Positioning( + var x: Double, + var y: Double, + var scale: Float + ) + + override fun getX(): Double { + return positioning.x + } + + override fun setX(newX: Double) { + positioning.x = newX + } + + override fun getY(): Double { + return positioning.y + } + + override fun setY(newY: Double) { + positioning.y = newY + } + + override fun getLabel(): Text { + return label + } + + override fun getWidth(): Int { + return width + } + + override fun getHeight(): Int { + return height + } + + override fun getScale(): Float { + return positioning.scale + } + + override fun setScale(newScale: Float) { + positioning.scale = newScale + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/render/HudElementDefaultPositionings.kt b/src/main/kotlin/com/dulkirfabric/util/render/HudElementDefaultPositionings.kt new file mode 100644 index 0000000..9d27158 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/util/render/HudElementDefaultPositionings.kt @@ -0,0 +1,8 @@ +package com.dulkirfabric.util.render + +import kotlinx.serialization.Serializable + +@Serializable +data class HudElementDefaultPositionings( + var fooPos: HudElement.Positioning = HudElement.Positioning(.1, .1, 1f) +) -- cgit