diff --git a/SceneManager/EntryPoint.cs b/SceneManager/EntryPoint.cs index b8d32fa..efde765 100644 --- a/SceneManager/EntryPoint.cs +++ b/SceneManager/EntryPoint.cs @@ -54,9 +54,9 @@ namespace SceneManager private static void MyTerminationHandler(object sender, EventArgs e) { // Clean up paths - for (int i = 0; i < PathMainMenu.GetPaths().Count; i++) + for (int i = 0; i < PathMainMenu.paths.Count; i++) { - PathMainMenu.DeletePath(PathMainMenu.GetPaths()[i], PathMainMenu.Delete.All); + PathMainMenu.DeletePath(PathMainMenu.paths[i], PathMainMenu.Delete.All); } // Clean up cones @@ -72,7 +72,7 @@ namespace SceneManager // Clear everything BarrierMenu.barriers.Clear(); VehicleCollector.collectedVehicles.Clear(); - PathMainMenu.GetPaths().Clear(); + PathMainMenu.paths.Clear(); Logger.Log($"Plugin has shut down."); Game.DisplayNotification($"~o~Scene Manager\n~r~[Notice]~w~ The plugin has shut down."); diff --git a/SceneManager/Menus/EditPathMenu.cs b/SceneManager/Menus/EditPathMenu.cs index 8193e21..59db1a7 100644 --- a/SceneManager/Menus/EditPathMenu.cs +++ b/SceneManager/Menus/EditPathMenu.cs @@ -32,7 +32,7 @@ namespace SceneManager private static void EditPath_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index) { - var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index]; + var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index]; if (selectedItem == editPathWaypoints) { @@ -49,7 +49,7 @@ namespace SceneManager { if (checkboxItem == disablePath) { - var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index]; + var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index]; if (disablePath.Checked) { currentPath.DisablePath(); diff --git a/SceneManager/Menus/EditWaypointMenu.cs b/SceneManager/Menus/EditWaypointMenu.cs index b50943a..073915f 100644 --- a/SceneManager/Menus/EditWaypointMenu.cs +++ b/SceneManager/Menus/EditWaypointMenu.cs @@ -34,7 +34,7 @@ namespace SceneManager // Need to unsubscribe from these or else there will be duplicate firings if the user left the menu, then re-entered ResetEventHandlerSubscriptions(); - var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Value - 1]; + var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Value-1]; //Logger.Log($"Current path: {currentPath.Number}"); editWaypoint = new UIMenuNumericScrollerItem("Edit Waypoint", "", currentPath.Waypoints.First().Number, currentPath.Waypoints.Last().Number, 1); @@ -95,7 +95,7 @@ namespace SceneManager private static void EditWaypoint_OnScrollerChanged(UIMenu sender, UIMenuScrollerItem scrollerItem, int first, int last) { - var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Value - 1]; + var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index]; var currentWaypoint = currentPath.Waypoints[editWaypoint.Value - 1]; if (scrollerItem == editWaypoint) @@ -136,7 +136,7 @@ namespace SceneManager private static void EditWaypoint_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index) { - var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index]; + var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index]; var currentWaypoint = currentPath.Waypoints[editWaypoint.Index]; if (selectedItem == updateWaypoint) @@ -160,7 +160,7 @@ namespace SceneManager if (selectedItem == addAsNewWaypoint) { - var pathIndex = PathMainMenu.GetPaths().IndexOf(currentPath); + var pathIndex = PathMainMenu.paths.IndexOf(currentPath); var drivingFlag = drivingFlags[changeWaypointType.Index]; var blip = PathCreationMenu.CreateWaypointBlip(pathIndex, drivingFlag); if (!currentPath.IsEnabled) diff --git a/SceneManager/Menus/PathCreationMenu.cs b/SceneManager/Menus/PathCreationMenu.cs index d726e3e..170e8c8 100644 --- a/SceneManager/Menus/PathCreationMenu.cs +++ b/SceneManager/Menus/PathCreationMenu.cs @@ -76,29 +76,29 @@ namespace SceneManager { if (selectedItem == trafficAddWaypoint) { - var anyPathsExist = PathMainMenu.GetPaths().Count > 0; + var anyPathsExist = PathMainMenu.paths.Count > 0; if (!anyPathsExist) { - AddNewPathToPathsCollection(PathMainMenu.GetPaths(), 0); + AddNewPathToPathsCollection(PathMainMenu.paths, 0); } - else if(anyPathsExist && !PathMainMenu.GetPaths().Any(p => p != null && p.State == State.Creating)) + else if(anyPathsExist && !PathMainMenu.paths.Any(p => p != null && p.State == State.Creating)) { - AddNewPathToPathsCollection(PathMainMenu.GetPaths(), PathMainMenu.GetPaths().IndexOf(PathMainMenu.GetPaths().Where(p => p.State == State.Finished).First()) + 1); + AddNewPathToPathsCollection(PathMainMenu.paths, PathMainMenu.paths.IndexOf(PathMainMenu.paths.Where(p => p.State == State.Finished).First()) + 1); } - var firstNonNullPath = PathMainMenu.GetPaths().Where(p => p != null && p.State == State.Creating).First(); - var pathIndex = PathMainMenu.GetPaths().IndexOf(firstNonNullPath); + var firstNonNullPath = PathMainMenu.paths.Where(p => p != null && p.State == State.Creating).First(); + var pathIndex = PathMainMenu.paths.IndexOf(firstNonNullPath); var pathNumber = firstNonNullPath.Number; - var waypointNumber = PathMainMenu.GetPaths()[pathIndex].Waypoints.Count + 1; + var waypointNumber = PathMainMenu.paths[pathIndex].Waypoints.Count + 1; if (collectorWaypoint.Checked) { - PathMainMenu.GetPaths()[pathIndex].Waypoints.Add(new Waypoint(firstNonNullPath, waypointNumber, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlags[waypointType.Index], CreateWaypointBlip(pathIndex, drivingFlags[waypointType.Index]), true, collectorRadius.Value, speedZoneRadius.Value)); + PathMainMenu.paths[pathIndex].Waypoints.Add(new Waypoint(firstNonNullPath, waypointNumber, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlags[waypointType.Index], CreateWaypointBlip(pathIndex, drivingFlags[waypointType.Index]), true, collectorRadius.Value, speedZoneRadius.Value)); } else { - PathMainMenu.GetPaths()[pathIndex].Waypoints.Add(new Waypoint(firstNonNullPath, waypointNumber, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlags[waypointType.Index], CreateWaypointBlip(pathIndex, drivingFlags[waypointType.Index]))); + PathMainMenu.paths[pathIndex].Waypoints.Add(new Waypoint(firstNonNullPath, waypointNumber, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlags[waypointType.Index], CreateWaypointBlip(pathIndex, drivingFlags[waypointType.Index]))); } Logger.Log($"[Path {pathNumber}] Waypoint {waypointNumber} ({drivingFlags[waypointType.Index].ToString()}) added"); @@ -130,24 +130,24 @@ namespace SceneManager if (selectedItem == trafficRemoveWaypoint) { // Loop through each path and find the first one which isn't finished, then delete the path's last waypoint and corresponding blip - for (int i = 0; i < PathMainMenu.GetPaths().Count; i++) + for (int i = 0; i < PathMainMenu.paths.Count; i++) { - if (PathMainMenu.GetPaths().ElementAtOrDefault(i) != null && PathMainMenu.GetPaths()[i].State == State.Creating) + if (PathMainMenu.paths.ElementAtOrDefault(i) != null && PathMainMenu.paths[i].State == State.Creating) { - Logger.Log($"[Path {i + 1}] {PathMainMenu.GetPaths()[i].Waypoints.Last().DrivingFlag.ToString()} waypoint removed"); - PathMainMenu.GetPaths()[i].Waypoints.Last().Blip.Delete(); - PathMainMenu.GetPaths()[i].Waypoints.Last().RemoveSpeedZone(); + Logger.Log($"[Path {i + 1}] {PathMainMenu.paths[i].Waypoints.Last().DrivingFlag.ToString()} waypoint removed"); + PathMainMenu.paths[i].Waypoints.Last().Blip.Delete(); + PathMainMenu.paths[i].Waypoints.Last().RemoveSpeedZone(); - if (PathMainMenu.GetPaths()[i].Waypoints.Last().CollectorRadiusBlip) + if (PathMainMenu.paths[i].Waypoints.Last().CollectorRadiusBlip) { - PathMainMenu.GetPaths()[i].Waypoints.Last().CollectorRadiusBlip.Delete(); + PathMainMenu.paths[i].Waypoints.Last().CollectorRadiusBlip.Delete(); } - PathMainMenu.GetPaths()[i].Waypoints.RemoveAt(PathMainMenu.GetPaths()[i].Waypoints.IndexOf(PathMainMenu.GetPaths()[i].Waypoints.Last())); + PathMainMenu.paths[i].Waypoints.RemoveAt(PathMainMenu.paths[i].Waypoints.IndexOf(PathMainMenu.paths[i].Waypoints.Last())); ToggleTrafficEndPathMenuItem(i); // If the path has no waypoints, disable the menu option to remove a waypoint - if (PathMainMenu.GetPaths()[i].Waypoints.Count == 0) + if (PathMainMenu.paths[i].Waypoints.Count == 0) { collectorWaypoint.Checked = true; collectorWaypoint.Enabled = false; @@ -163,10 +163,10 @@ namespace SceneManager if (selectedItem == trafficEndPath) { // Loop through each path and find the first one which isn't finished - for (int i = 0; i < PathMainMenu.GetPaths().Count; i++) + for (int i = 0; i < PathMainMenu.paths.Count; i++) { - var currentPath = PathMainMenu.GetPaths()[i]; - if (PathMainMenu.GetPaths().ElementAtOrDefault(i) != null && currentPath.State == State.Creating) + var currentPath = PathMainMenu.paths[i]; + if (PathMainMenu.paths.ElementAtOrDefault(i) != null && currentPath.State == State.Creating) { Logger.Log($"[Path Creation] Path {currentPath.Number} finished with {currentPath.Waypoints.Count} waypoints."); Game.DisplayNotification($"~o~Scene Manager\n~g~[Success]~w~ Path {i + 1} complete."); @@ -174,14 +174,16 @@ namespace SceneManager currentPath.IsEnabled = true; currentPath.Number = i + 1; - foreach (Waypoint waypoint in PathMainMenu.GetPaths()[i].Waypoints) + foreach (Waypoint waypoint in PathMainMenu.paths[i].Waypoints) { - GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => VehicleCollector.StartCollectingAtWaypoint(PathMainMenu.GetPaths(), PathMainMenu.GetPaths()[i], waypoint)); + GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => VehicleCollector.StartCollectingAtWaypoint(PathMainMenu.paths, PathMainMenu.paths[i], waypoint)); WaypointVehicleCollectorFiber.Start(); } PathMainMenu.createNewPath.Text = "Create New Path"; PathMainMenu.BuildPathMenu(); + PathMainMenu.pathMainMenu.RefreshIndex(); + pathCreationMenu.RefreshIndex(); collectorWaypoint.Enabled = false; collectorWaypoint.Checked = true; speedZoneRadius.Enabled = true; @@ -216,7 +218,7 @@ namespace SceneManager private static void ToggleTrafficEndPathMenuItem(int pathIndex) { - if (PathMainMenu.GetPaths()[pathIndex].Waypoints.Count > 0) + if (PathMainMenu.paths[pathIndex].Waypoints.Count > 0) { trafficEndPath.Enabled = true; } diff --git a/SceneManager/Menus/PathMainMenu.cs b/SceneManager/Menus/PathMainMenu.cs index 864b87d..3769c1b 100644 --- a/SceneManager/Menus/PathMainMenu.cs +++ b/SceneManager/Menus/PathMainMenu.cs @@ -10,7 +10,7 @@ namespace SceneManager { static class PathMainMenu { - private static List paths = new List() { }; + internal static List paths = new List() { }; private static List dismissOptions = new List() { "From path", "From waypoint", "From position" }; internal static UIMenu pathMainMenu = new UIMenu("Scene Manager", "~o~Path Manager Main Menu"); @@ -81,11 +81,6 @@ namespace SceneManager } } - internal static ref List GetPaths() - { - return ref paths; - } - private static bool VehicleAndDriverValid(this Vehicle v) { if (v && v.HasDriver && v.Driver && v.Driver.IsAlive) @@ -233,6 +228,10 @@ namespace SceneManager } collectedVehicle.Driver.Tasks.Clear(); + if (collectedVehicle.StoppedAtWaypoint) + { + collectedVehicle.StoppedAtWaypoint = false; + } if (directOptions.SelectedItem == "First waypoint") { diff --git a/SceneManager/Menus/SettingsMenu.cs b/SceneManager/Menus/SettingsMenu.cs index d1f0191..4bd6db2 100644 --- a/SceneManager/Menus/SettingsMenu.cs +++ b/SceneManager/Menus/SettingsMenu.cs @@ -51,7 +51,7 @@ namespace SceneManager { if (mapBlips.Checked) { - foreach(Path path in PathMainMenu.GetPaths()) + foreach(Path path in PathMainMenu.paths) { foreach(Waypoint wp in path.Waypoints) { @@ -61,7 +61,7 @@ namespace SceneManager } else { - foreach (Path path in PathMainMenu.GetPaths()) + foreach (Path path in PathMainMenu.paths) { foreach (Waypoint wp in path.Waypoints) {