diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-06-20 23:24:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-20 23:24:51 +0200 |
commit | 9b1894c738a16ec6ce2d59a29f7b85a9b9df9381 (patch) | |
tree | ff928cca75ecd18c9929acf042b8bd15d96d9349 /src | |
parent | 9810bf56d8852806a812ba77702b670bcfe91e61 (diff) | |
download | skyhanni-9b1894c738a16ec6ce2d59a29f7b85a9b9df9381.tar.gz skyhanni-9b1894c738a16ec6ce2d59a29f7b85a9b9df9381.tar.bz2 skyhanni-9b1894c738a16ec6ce2d59a29f7b85a9b9df9381.zip |
Backend: Addition to Graph Editor (#2059)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/dev/GraphConfig.java | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt | 60 |
2 files changed, 62 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dev/GraphConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dev/GraphConfig.java index 66bc6f798..8dd606cd3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/dev/GraphConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dev/GraphConfig.java @@ -81,6 +81,10 @@ public class GraphConfig { public Position infoDisplay = new Position(20, 20); @Expose + @ConfigLink(owner = GraphConfig.class, field = "enabled") + public Position namedNodesList = new Position(20, 20); + + @Expose @ConfigOption(name = "Shows Stats", desc = "Show funny extra statistics on save. May lag the game a bit.") @ConfigEditorBoolean public boolean showsStats = true; diff --git a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt index 0e4f36d32..00fa25459 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.CollectionUtils.addString import at.hannibal2.skyhanni.utils.ColorUtils import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked @@ -26,11 +27,17 @@ import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine_nea import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.renderables.ScrollValue import kotlinx.coroutines.runBlocking import net.minecraft.client.settings.KeyBinding import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable +import kotlin.math.sqrt +import kotlin.time.Duration.Companion.milliseconds @SkyHanniModule object GraphEditor { @@ -76,6 +83,10 @@ object GraphEditor { private val edgeColor = LorenzColor.GOLD.addOpacity(150) private val edgeDijkstraColor = LorenzColor.DARK_BLUE.addOpacity(150) + val scrollValue = ScrollValue() + var namedNodeList: List<Renderable> = emptyList() + var lastUpdate = SimpleTimeMark.farPast() + @SubscribeEvent fun onRender(event: LorenzRenderWorldEvent) { if (!isEnabled()) return @@ -121,6 +132,51 @@ object GraphEditor { } } + @SubscribeEvent + fun onGuiRender(event: GuiRenderEvent) { + if (!isEnabled()) return + config.namedNodesList.renderRenderables( + buildList { + val list = getNamedNodes() + val size = list.size + addString("§eGraph Nodes: $size") + val height = (size * 10).coerceAtMost(150) + if (list.isNotEmpty()) { + add(Renderable.scrollList(list, height, scrollValue = scrollValue, velocity = 10.0)) + } + }, + posLabel = "Graph Nodes List", + ) + } + + private fun getNamedNodes(): List<Renderable> { + if (lastUpdate.passedSince() > 250.milliseconds) { + lastUpdate = SimpleTimeMark.now() + namedNodeList = calculateNamedNodes() + } + return namedNodeList + } + + + private fun calculateNamedNodes(): List<Renderable> = buildList { + for ((node, distance: Double) in nodes.map { it to it.position.distanceSqToPlayer() }.sortedBy { it.second }) { + val name = node.name?.takeIf { !it.isBlank() } ?: continue + val color = if (node == activeNode) "§a" else "§7" + val distanceFormat = sqrt(distance).toInt().addSeparators() + val text = "${color}Node §r$name §f($distanceFormat)" + add( + Renderable.clickAndHover( + text, + emptyList(), + onClick = { + activeNode = node + lastUpdate = SimpleTimeMark.farPast() + }, + ), + ) + } + } + private fun feedBackInTutorial(text: String) { if (inTutorialMode) { ChatUtils.chat(text) @@ -303,8 +359,8 @@ object GraphEditor { val length = edges.sumOf { it.node1.position.distance(it.node2.position) }.toInt().addSeparators() ChatUtils.chat( "§lStats\n" + - "§eNodes: ${nodes.size}\n" + - "§eEdges: ${edges.size}\n" + + "§eNodes: ${nodes.size.addSeparators()}\n" + + "§eEdges: ${edges.size.addSeparators()}\n" + "§eLength: $length", ) } |