diff --git a/MapEditor/Definition.json b/MapEditor/Definition.json index 3fdc874..5ea6d45 100644 --- a/MapEditor/Definition.json +++ b/MapEditor/Definition.json @@ -4,6 +4,7 @@ "name": "Map Editor", "version": "$(AssemblyVersion)", "assemblies": [ "MapEditor" ], + "updateUrl": "https://railroader.alinanova.dev/update.json", "requires": [ "Zamu.StrangeCustoms" ], diff --git a/MapEditor/Dialogs/TrackNodeDialog.cs b/MapEditor/Dialogs/TrackNodeDialog.cs index 7bef1ed..eaa3039 100644 --- a/MapEditor/Dialogs/TrackNodeDialog.cs +++ b/MapEditor/Dialogs/TrackNodeDialog.cs @@ -76,7 +76,7 @@ private static void BuildNodeEditor(UIPanelBuilder builder) builder.AddField("Flip Switch Stand", builder.AddToggle(() => NodeManager.GetFlipSwitchStand(), val => NodeManager.FlipSwitchStand(val))!); builder.HStack(stack => { - stack.AddButtonCompact("Add", NodeManager.AddNode); + stack.AddButtonCompact("Add", () => NodeManager.AddNode()); stack.AddButtonCompact("Split", () => NodeManager.SplitNode()); stack.AddButtonCompact("Remove", () => NodeManager.RemoveNode(Input.GetKey(KeyCode.LeftShift))); stack.AddButtonCompact("Show", EditorContext.MoveCameraToSelectedNode); diff --git a/MapEditor/EditorContext.cs b/MapEditor/EditorContext.cs index 4bbb1f2..8b85bab 100644 --- a/MapEditor/EditorContext.cs +++ b/MapEditor/EditorContext.cs @@ -250,22 +250,23 @@ public static void MoveCameraToSelectedNode() } } + public static void UpdateUiHelpers() + { + CreateUiHelpers(); + } + #region UI helpers private static void CreateUiHelpers() { foreach (var trackNode in Graph.Shared.Nodes!) { - var gameObject = new GameObject("TrackNodeHelper"); - gameObject.transform.SetParent(trackNode.transform); - gameObject.AddComponent(); + AttachUiHelper(trackNode); } foreach (var trackSegment in Graph.Shared.Segments!) { - var gameObject = new GameObject("TrackSegmentHelper"); - gameObject.transform.SetParent(trackSegment.transform); - gameObject.AddComponent(); + AttachUiHelper(trackSegment); } } @@ -290,6 +291,28 @@ private static void DestroyUiHelpers() } } + + internal static void AttachUiHelper(TrackNode node) + { + if (node.transform.Find("TrackNodeHelper") != null) + { + return; + } + var gameObject = new GameObject("TrackNodeHelper"); + gameObject.transform.SetParent(node.transform); + gameObject.AddComponent(); + } + + internal static void AttachUiHelper(TrackSegment segment) + { + if (segment.transform.Find("TrackSegmentHelper") != null) + { + return; + } + var gameObject = new GameObject("TrackSegmentHelper"); + gameObject.transform.SetParent(segment.transform); + gameObject.AddComponent(); + } #endregion } diff --git a/MapEditor/HarmonyPatches/TrackSegmentAwake.cs b/MapEditor/HarmonyPatches/TrackSegmentAwake.cs deleted file mode 100644 index cd6ef6e..0000000 --- a/MapEditor/HarmonyPatches/TrackSegmentAwake.cs +++ /dev/null @@ -1,26 +0,0 @@ -using HarmonyLib; -using JetBrains.Annotations; -using MapEditor.Helpers; -using Track; -using UnityEngine; - -namespace MapEditor.HarmonyPatches -{ - [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] - [HarmonyPatch(typeof(TrackSegment), "Awake")] - internal static class TrackSegmentAwake - { - - private static void Postfix(TrackSegment __instance) - { - if (__instance.GetComponentInChildren() == null) - { - var gameObject = new GameObject("TrackSegmentHelper"); - gameObject.transform.SetParent(__instance.transform); - var sh = gameObject.AddComponent(); - sh.Rebuild(); - } - } - - } -} diff --git a/MapEditor/Managers/NodeManager.cs b/MapEditor/Managers/NodeManager.cs index 816fc89..933584c 100644 --- a/MapEditor/Managers/NodeManager.cs +++ b/MapEditor/Managers/NodeManager.cs @@ -84,9 +84,9 @@ public static void DivideScaling() #endregion - public static void AddNode() + public static void AddNode(TrackNode? node = null) { - var node = EditorContext.SelectedNode!; + node ??= EditorContext.SelectedNode!; var nid = EditorContext.TrackNodeIdGenerator.Next()!; var sid = EditorContext.TrackSegmentIdGenerator.Next()!; EditorContext.ChangeManager.AddChange(new CompoundChange( diff --git a/MapEditor/StateTracker/Node/TrackNodeGhost.cs b/MapEditor/StateTracker/Node/TrackNodeGhost.cs index 16dab30..5fb7ea2 100644 --- a/MapEditor/StateTracker/Node/TrackNodeGhost.cs +++ b/MapEditor/StateTracker/Node/TrackNodeGhost.cs @@ -44,6 +44,7 @@ public void CreateNode() gameObject.SetActive(true); Graph.Shared.AddNode(node); EditorContext.PatchEditor!.AddOrUpdateNode(node); + EditorContext.AttachUiHelper(node); } public void DestroyNode() diff --git a/MapEditor/StateTracker/Segment/TrackSegmentGhost.cs b/MapEditor/StateTracker/Segment/TrackSegmentGhost.cs index 2256b1f..f6c907c 100644 --- a/MapEditor/StateTracker/Segment/TrackSegmentGhost.cs +++ b/MapEditor/StateTracker/Segment/TrackSegmentGhost.cs @@ -53,19 +53,15 @@ public void UpdateSegment(TrackSegment segment) public void CreateSegment() { var gameObject = new GameObject($"Segment {id}"); - gameObject.SetActive(true); + gameObject.SetActive(false); var segment = gameObject.AddComponent(); segment.id = id; segment.transform.SetParent(Graph.Shared.transform); UpdateSegment(segment); - gameObject.SetActive(false); + gameObject.SetActive(true); Graph.Shared.AddSegment(segment); - // var helper = new GameObject("TrackSegmentHelper"); - // helper.transform.SetParent(segment.transform); - // var sh = helper.AddComponent(); - // sh.Rebuild(); - EditorContext.PatchEditor!.AddOrUpdateSegment(segment); + EditorContext.AttachUiHelper(segment); } public void DestroySegment() diff --git a/MapEditor/mod.yaml b/MapEditor/mod.yaml index 857ecf7..0e82a38 100644 --- a/MapEditor/mod.yaml +++ b/MapEditor/mod.yaml @@ -4,6 +4,7 @@ name: Map Editor desc: |- A Map Editor for manipulating track mods. WARNING: Extremely WIP. I will not be providing support. Use at your own risk. +downloadUrl: https://github.com/AlinaNova21/Railroader-Mods/releases/download/v1.4.24204.650/MapEditor_1.1.24204.650.zip version: '1.1.24204.650' changelog: - version: '1.1.24204.650'