diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/dev/GraphConfig.java | 7 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt | 57 |
2 files changed, 54 insertions, 10 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 8dd606cd3..bbc6caf7d 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 @@ -22,6 +22,11 @@ public class GraphConfig { public int placeKey = Keyboard.KEY_F; @Expose + @ConfigOption(name = "Toggle Ghost Position", desc = "Creates or removes the Ghost Position. This helps editing nodes tht are in the air.") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_F) + public int toggleGhostPosition = Keyboard.KEY_NONE; + + @Expose @ConfigOption(name = "Select Key", desc = "Select the nearest node to be active. Double press to unselect.") @ConfigEditorKeybind(defaultKey = -98) // Middle Mouse public int selectKey = -98; @@ -37,7 +42,7 @@ public class GraphConfig { public int exitKey = Keyboard.KEY_HOME; @Expose - @ConfigOption(name = "Edit Key", desc = "While holding the Key, edit the position of the active node with the minecraft movement controls.") + @ConfigOption(name = "Edit Key", desc = "While holding the Key, edit the position of the active node or the selection block with the minecraft movement controls.") @ConfigEditorKeybind(defaultKey = Keyboard.KEY_TAB) public int editKey = Keyboard.KEY_TAB; diff --git a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt index ece6d16cb..f5acf90fb 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt @@ -19,7 +19,7 @@ import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer +import at.hannibal2.skyhanni.utils.LocationUtils.playerLocation import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec @@ -37,6 +37,7 @@ 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 java.awt.Color import kotlin.math.sqrt import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @@ -55,6 +56,7 @@ object GraphEditor { private var activeNode: GraphingNode? = null private var closedNode: GraphingNode? = null + private var ghostPosition: LorenzVec? = null private var seeThroughBlocks = true @@ -94,6 +96,15 @@ object GraphEditor { if (!isEnabled()) return nodes.forEach { event.drawNode(it) } edges.forEach { event.drawEdge(it) } + ghostPosition?.let { + event.drawWaypointFilled( + it, + if (activeNode == null) Color.RED else Color.GRAY, + seeThroughBlocks = seeThroughBlocks, + minimumAlpha = 0.2f, + inverseAlphaScale = true, + ) + } } @SubscribeEvent @@ -114,12 +125,19 @@ object GraphEditor { add("§eLoad: §6${KeyboardManager.getKeyName(config.loadKey)}") add("§eClear: §6${KeyboardManager.getKeyName(config.clearKey)}") add("§eTutorial: §6${KeyboardManager.getKeyName(config.tutorialKey)}") + add("§eToggle Ghost Position: §6${KeyboardManager.getKeyName(config.toggleGhostPosition)}") add(" ") if (activeNode != null) add("§eText: §6${KeyboardManager.getKeyName(config.textKey)}") } - if (!inTextMode && activeNode != null) { - add("§eEdit: §6${KeyboardManager.getKeyName(config.editKey)}") + + if (!inTextMode) { + if (activeNode != null) { + add("§eEdit active node: §6${KeyboardManager.getKeyName(config.editKey)}") + } else if (ghostPosition != null) { + add("Edit Ghost Position: §6${KeyboardManager.getKeyName(config.editKey)}") + } } + if (inEditMode) { add("§ex+ §6${KeyboardManager.getKeyName(KeyboardManager.WasdInputMatrix.w.keyCode)}") add("§ex- §6${KeyboardManager.getKeyName(KeyboardManager.WasdInputMatrix.s.keyCode)}") @@ -374,7 +392,7 @@ object GraphEditor { editModeClicks() inEditMode = false } - if (activeNode != null && config.editKey.isKeyHeld()) { + if ((activeNode != null || ghostPosition != null) && config.editKey.isKeyHeld()) { inEditMode = true return } @@ -412,9 +430,12 @@ object GraphEditor { if (config.placeKey.isKeyClicked()) { addNode() } + if (config.toggleGhostPosition.isKeyClicked()) { + toggleGhostPosition() + } if (config.selectKey.isKeyClicked()) { activeNode = if (activeNode == closedNode) { - feedBackInTutorial("De selected active node.") + feedBackInTutorial("De-selected active node.") null } else { feedBackInTutorial("Selected new active node.") @@ -480,7 +501,13 @@ object GraphEditor { private fun KeyBinding.handleEditClicks(vector: LorenzVec) { if (this.keyCode.isKeyClicked()) { - activeNode?.position = activeNode?.position?.plus(vector) ?: return + activeNode?.let { + it.position = it.position + vector + } ?: run { + ghostPosition?.let { + ghostPosition = it + vector + } + } } } @@ -503,7 +530,8 @@ object GraphEditor { return } } - val position = LocationUtils.playerEyeLocation().roundLocationToBlock() + + val position = ghostPosition ?: LocationUtils.playerEyeLocation().roundLocationToBlock() if (nodes.any { it.position == position }) { feedBackInTutorial("Can't create node, here is already another one.") return @@ -515,6 +543,16 @@ object GraphEditor { addEdge(activeNode, node) } + fun toggleGhostPosition() { + if (ghostPosition != null) { + ghostPosition = null + feedBackInTutorial("Disabled Ghost Position.") + } else { + ghostPosition = LocationUtils.playerEyeLocation().roundLocationToBlock() + feedBackInTutorial("Enabled Ghost Position.") + } + } + private fun getEdgeIndex(node1: GraphingNode?, node2: GraphingNode?) = if (node1 != null && node2 != null && node1 != node2) GraphingEdge( node1, @@ -592,6 +630,7 @@ object GraphEditor { edges.clear() activeNode = null closedNode = null + ghostPosition = null } private fun prune() { //TODO fix @@ -602,6 +641,8 @@ object GraphEditor { } nodes.removeIf { hasNeighbours[it] == false } } + + fun LorenzVec.distanceSqToPlayer(): Double = ghostPosition?.let { distanceSq(it) } ?: distanceSq(playerLocation()) } // The node object the graph editor is working with @@ -656,6 +697,4 @@ private class GraphingEdge(val node1: GraphingNode, val node2: GraphingNode) { } return result } - } - |