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 8dd606cd3f0c..bbc6caf7d7b1 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 @@ -21,6 +21,11 @@ public class GraphConfig { @ConfigEditorKeybind(defaultKey = Keyboard.KEY_F) 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 @@ -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 ababb9b6569f..aeb18f82be33 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt @@ -18,7 +18,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 @@ -36,6 +36,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 @@ -53,6 +54,7 @@ object GraphEditor { private var activeNode: GraphingNode? = null private var closedNode: GraphingNode? = null + private var ghostPosition: LorenzVec? = null private var seeThroughBlocks = true @@ -92,6 +94,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 @@ -112,12 +123,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)}") @@ -274,7 +292,7 @@ object GraphEditor { editModeClicks() inEditMode = false } - if (activeNode != null && config.editKey.isKeyHeld()) { + if ((activeNode != null || ghostPosition != null) && config.editKey.isKeyHeld()) { inEditMode = true return } @@ -312,9 +330,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.") @@ -379,7 +400,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 + } + } } } @@ -402,7 +429,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 @@ -414,6 +442,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, @@ -482,6 +520,7 @@ object GraphEditor { edges.clear() activeNode = null closedNode = null + ghostPosition = null } private fun prune() { //TODO fix @@ -492,6 +531,8 @@ object GraphEditor { } nodes.removeIf { hasNeighbours[it] == false } } + + fun LorenzVec.distanceSqToPlayer(): Double = ghostPosition?.let { distanceSq(it) } ?: distanceSq(playerLocation()) } private class GraphingNode(val id: Int, var position: LorenzVec, var name: String? = null) { @@ -540,6 +581,4 @@ private class GraphingEdge(val node1: GraphingNode, val node2: GraphingNode) { } return result } - } -