1
Fork 0
mirror of https://github.com/thegeneralist01/Scene-Manager-DevRepo synced 2026-01-11 15:40:29 +01:00

Updated menu references based on MenuManager refactor

This commit is contained in:
Rich Dunne 2020-08-20 18:57:20 -06:00
parent 2e65da4746
commit fe72d5daf8
10 changed files with 281 additions and 175 deletions

View file

@ -79,9 +79,9 @@ namespace SceneManager
private static void MyTerminationHandler(object sender, EventArgs e) private static void MyTerminationHandler(object sender, EventArgs e)
{ {
// Clean up paths // Clean up paths
for (int i = 0; i < TrafficMenu.paths.Count; i++) for (int i = 0; i < PathMainMenu.GetPaths().Count; i++)
{ {
TrafficMenu.DeletePath(TrafficMenu.paths[i], i, "All"); PathMainMenu.DeletePath(PathMainMenu.GetPaths()[i], i, PathMainMenu.Delete.All);
} }
// Clean up cones // Clean up cones

View file

@ -20,7 +20,7 @@ namespace SceneManager
GetControllerInput(); GetControllerInput();
// Display this message for test versions only // Display this message for test versions only
if (MenuManager.mainMenu.Visible) if (MainMenu.mainMenu.Visible)
{ {
Game.DisplaySubtitle($"You are using a test build of Scene Manager. Please report any bugs/crashes in the Discord server."); Game.DisplaySubtitle($"You are using a test build of Scene Manager. Please report any bugs/crashes in the Discord server.");
} }
@ -36,12 +36,12 @@ namespace SceneManager
{ {
if (Game.IsControllerButtonDown(EntryPoint.Settings.ToggleButton) && AreMenusClosed()) if (Game.IsControllerButtonDown(EntryPoint.Settings.ToggleButton) && AreMenusClosed())
{ {
MenuManager.mainMenu.Visible = !MenuManager.mainMenu.Visible; MainMenu.mainMenu.Visible = !MainMenu.mainMenu.Visible;
} }
} }
else if (Game.IsControllerButtonDownRightNow(EntryPoint.Settings.ModifierButton) && Game.IsControllerButtonDown(EntryPoint.Settings.ToggleButton) && AreMenusClosed()) else if (Game.IsControllerButtonDownRightNow(EntryPoint.Settings.ModifierButton) && Game.IsControllerButtonDown(EntryPoint.Settings.ToggleButton) && AreMenusClosed())
{ {
MenuManager.mainMenu.Visible = !MenuManager.mainMenu.Visible; MainMenu.mainMenu.Visible = !MainMenu.mainMenu.Visible;
} }
} }
@ -51,18 +51,18 @@ namespace SceneManager
{ {
if (Game.IsKeyDown(EntryPoint.Settings.ToggleKey) && AreMenusClosed()) if (Game.IsKeyDown(EntryPoint.Settings.ToggleKey) && AreMenusClosed())
{ {
MenuManager.mainMenu.Visible = !MenuManager.mainMenu.Visible; MainMenu.mainMenu.Visible = !MainMenu.mainMenu.Visible;
} }
} }
else if (Game.IsKeyDownRightNow(EntryPoint.Settings.ModifierKey) && Game.IsKeyDown(EntryPoint.Settings.ToggleKey) && AreMenusClosed()) else if (Game.IsKeyDownRightNow(EntryPoint.Settings.ModifierKey) && Game.IsKeyDown(EntryPoint.Settings.ToggleKey) && AreMenusClosed())
{ {
MenuManager.mainMenu.Visible = !MenuManager.mainMenu.Visible; MainMenu.mainMenu.Visible = !MainMenu.mainMenu.Visible;
} }
} }
private static bool AreMenusClosed() private static bool AreMenusClosed()
{ {
if(!MenuManager.barrierMenu.Visible && !MenuManager.pathMenu.Visible && !MenuManager.pathCreationMenu.Visible && !MenuManager.editPathMenu.Visible && !MenuManager.editWaypointMenu.Visible && !MenuManager.settingsMenu.Visible) if(!BarrierMenu.barrierMenu.Visible && !PathMainMenu.pathMainMenu.Visible && !PathCreationMenu.pathCreationMenu.Visible && !EditPathMenu.editPathMenu.Visible && !EditWaypointMenu.editWaypointMenu.Visible && !SettingsMenu.settingsMenu.Visible)
{ {
return true; return true;
} }

View file

@ -11,6 +11,7 @@ namespace SceneManager
{ {
class BarrierMenu class BarrierMenu
{ {
public static UIMenu barrierMenu { get; private set; }
public static List<Rage.Object> barriers = new List<Rage.Object>() { }; public static List<Rage.Object> barriers = new List<Rage.Object>() { };
// TODO: Refactor as dictionary // TODO: Refactor as dictionary
@ -20,16 +21,23 @@ namespace SceneManager
private static UIMenuListScrollerItem<string> removeBarrierOptions = new UIMenuListScrollerItem<string>("Remove Barrier", "", new[] { "Last Barrier", "Nearest Barrier", "All Barriers" }); private static UIMenuListScrollerItem<string> removeBarrierOptions = new UIMenuListScrollerItem<string>("Remove Barrier", "", new[] { "Last Barrier", "Nearest Barrier", "All Barriers" });
public static Rage.Object shadowBarrier; public static Rage.Object shadowBarrier;
internal static void InstantiateMenu()
{
barrierMenu = new UIMenu("Scene Manager", "~o~Barrier Management");
barrierMenu.ParentMenu = MainMenu.mainMenu;
MenuManager.menuPool.Add(barrierMenu);
}
public static void BuildBarrierMenu() public static void BuildBarrierMenu()
{ {
MenuManager.barrierMenu.AddItem(removeBarrierOptions, 0); barrierMenu.AddItem(removeBarrierOptions, 0);
removeBarrierOptions.Enabled = false; removeBarrierOptions.Enabled = false;
MenuManager.barrierMenu.AddItem(rotateBarrier, 0); barrierMenu.AddItem(rotateBarrier, 0);
MenuManager.barrierMenu.AddItem(barrierList, 0); barrierMenu.AddItem(barrierList, 0);
MenuManager.barrierMenu.RefreshIndex(); barrierMenu.RefreshIndex();
MenuManager.barrierMenu.OnItemSelect += BarrierMenu_OnItemSelected; barrierMenu.OnItemSelect += BarrierMenu_OnItemSelected;
MenuManager.barrierMenu.OnScrollerChange += BarrierMenu_OnScrollerChange; barrierMenu.OnScrollerChange += BarrierMenu_OnScrollerChange;
} }
public static void CreateShadowBarrier(UIMenu barrierMenu) public static void CreateShadowBarrier(UIMenu barrierMenu)
@ -91,7 +99,7 @@ namespace SceneManager
{ {
if (scrollerItem == barrierList) if (scrollerItem == barrierList)
{ {
CreateShadowBarrier(MenuManager.barrierMenu); CreateShadowBarrier(barrierMenu);
if (barrierObjectNames[barrierList.Index] == "prop_flare_01b") if (barrierObjectNames[barrierList.Index] == "prop_flare_01b")
{ {

View file

@ -7,23 +7,31 @@ namespace SceneManager
{ {
class EditPathMenu class EditPathMenu
{ {
public static UIMenu editPathMenu { get; private set; }
private static UIMenuItem editPathWaypoints, deletePath; private static UIMenuItem editPathWaypoints, deletePath;
public static UIMenuCheckboxItem togglePath; public static UIMenuCheckboxItem togglePath;
internal static void InstantiateMenu()
{
editPathMenu = new UIMenu("Scene Manager", "~o~Edit Path");
editPathMenu.ParentMenu = PathMainMenu.pathMainMenu;
MenuManager.menuPool.Add(editPathMenu);
}
public static void BuildEditPathMenu() public static void BuildEditPathMenu()
{ {
MenuManager.editPathMenu.AddItem(togglePath = new UIMenuCheckboxItem("Disable Path", false)); editPathMenu.AddItem(togglePath = new UIMenuCheckboxItem("Disable Path", false));
MenuManager.editPathMenu.AddItem(editPathWaypoints = new UIMenuItem("Edit Waypoints")); editPathMenu.AddItem(editPathWaypoints = new UIMenuItem("Edit Waypoints"));
MenuManager.editPathMenu.AddItem(deletePath = new UIMenuItem("Delete Path")); editPathMenu.AddItem(deletePath = new UIMenuItem("Delete Path"));
MenuManager.editPathMenu.RefreshIndex(); editPathMenu.RefreshIndex();
MenuManager.editPathMenu.OnItemSelect += EditPath_OnItemSelected; editPathMenu.OnItemSelect += EditPath_OnItemSelected;
MenuManager.editPathMenu.OnCheckboxChange += EditPath_OnCheckboxChange; editPathMenu.OnCheckboxChange += EditPath_OnCheckboxChange;
} }
private static void EditPath_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index) private static void EditPath_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
{ {
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index]; var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index];
if (selectedItem == editPathWaypoints) if (selectedItem == editPathWaypoints)
{ {
@ -32,7 +40,7 @@ namespace SceneManager
if (selectedItem == deletePath) if (selectedItem == deletePath)
{ {
TrafficMenu.DeletePath(currentPath, currentPath.PathNum - 1, "Single"); PathMainMenu.DeletePath(currentPath, currentPath.PathNum - 1, PathMainMenu.Delete.Single);
} }
} }
@ -40,7 +48,7 @@ namespace SceneManager
{ {
if (checkboxItem == togglePath) if (checkboxItem == togglePath)
{ {
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index]; var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index];
if (togglePath.Checked) if (togglePath.Checked)
{ {
currentPath.DisablePath(); currentPath.DisablePath();

View file

@ -12,6 +12,7 @@ namespace SceneManager
class EditWaypointMenu class EditWaypointMenu
{ {
#pragma warning disable CS0618 // Type or member is obsolete, clear NUI squiggles #pragma warning disable CS0618 // Type or member is obsolete, clear NUI squiggles
public static UIMenu editWaypointMenu { get; private set; }
private static UIMenuItem editUpdateWaypoint, editRemoveWaypoint; private static UIMenuItem editUpdateWaypoint, editRemoveWaypoint;
private static UIMenuListItem editWaypoint, changeWaypointType, changeWaypointSpeed, changeCollectorRadius; private static UIMenuListItem editWaypoint, changeWaypointType, changeWaypointSpeed, changeCollectorRadius;
private static UIMenuCheckboxItem collectorWaypoint, updateWaypointPosition; private static UIMenuCheckboxItem collectorWaypoint, updateWaypointPosition;
@ -22,13 +23,21 @@ namespace SceneManager
private static List<dynamic> collectorRadii = new List<dynamic>() { 3f, 5f, 10f, 15f, 20f, 30f, 40f, 50f }; private static List<dynamic> collectorRadii = new List<dynamic>() { 3f, 5f, 10f, 15f, 20f, 30f, 40f, 50f };
private static VehicleDrivingFlags[] drivingFlags = new VehicleDrivingFlags[] { VehicleDrivingFlags.Normal, VehicleDrivingFlags.StopAtDestination }; private static VehicleDrivingFlags[] drivingFlags = new VehicleDrivingFlags[] { VehicleDrivingFlags.Normal, VehicleDrivingFlags.StopAtDestination };
internal static void InstantiateMenu()
{
editWaypointMenu = new UIMenu("Scene Manager", "~o~Edit Waypoint");
editWaypointMenu.ParentMenu = EditPathMenu.editPathMenu;
MenuManager.menuPool.Add(editWaypointMenu);
}
public static void BuildEditWaypointMenu() public static void BuildEditWaypointMenu()
{ {
// Need to unsubscribe from these or else there will be duplicate firings if the user left the menu, then re-entered // Need to unsubscribe from these or else there will be duplicate firings if the user left the menu, then re-entered
MenuManager.editWaypointMenu.OnItemSelect -= EditWaypoint_OnItemSelected; editWaypointMenu.OnItemSelect -= EditWaypoint_OnItemSelected;
MenuManager.editWaypointMenu.OnListChange -= EditWaypoint_OnListChanged; editWaypointMenu.OnListChange -= EditWaypoint_OnListChanged;
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index]; //var currentPath = PathMainMenu.paths[PathMainMenu.editPath.Index];
var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index];
// Populating menu list so user can select which waypoint to edit by index // Populating menu list so user can select which waypoint to edit by index
pathWaypoints.Clear(); pathWaypoints.Clear();
@ -37,51 +46,51 @@ namespace SceneManager
pathWaypoints.Add(i + 1); pathWaypoints.Add(i + 1);
} }
MenuManager.editWaypointMenu.Clear(); editWaypointMenu.Clear();
MenuManager.editWaypointMenu.AddItem(editWaypoint = new UIMenuListItem("Edit Waypoint", pathWaypoints, 0)); editWaypointMenu.AddItem(editWaypoint = new UIMenuListItem("Edit Waypoint", pathWaypoints, 0));
MenuManager.editWaypointMenu.AddItem(changeWaypointType = new UIMenuListItem("Change Waypoint Type", waypointTypes, Array.IndexOf(drivingFlags, currentPath.Waypoints[editWaypoint.Index].DrivingFlag))); editWaypointMenu.AddItem(changeWaypointType = new UIMenuListItem("Change Waypoint Type", waypointTypes, Array.IndexOf(drivingFlags, currentPath.Waypoints[editWaypoint.Index].DrivingFlag)));
MenuManager.editWaypointMenu.AddItem(changeWaypointSpeed = new UIMenuListItem("Change Waypoint Speed", waypointSpeeds, waypointSpeeds.IndexOf(currentPath.Waypoints[editWaypoint.Index].Speed))); editWaypointMenu.AddItem(changeWaypointSpeed = new UIMenuListItem("Change Waypoint Speed", waypointSpeeds, waypointSpeeds.IndexOf(currentPath.Waypoints[editWaypoint.Index].Speed)));
MenuManager.editWaypointMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Collector Waypoint", TrafficMenu.paths[TrafficMenu.editPath.Index].Waypoints[editWaypoint.Index].Collector)); editWaypointMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Collector Waypoint", PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Collector));
MenuManager.editWaypointMenu.AddItem(changeCollectorRadius = new UIMenuListItem("Change Collection Radius", collectorRadii, collectorRadii.IndexOf(currentPath.Waypoints[editWaypoint.Index].CollectorRadius))); editWaypointMenu.AddItem(changeCollectorRadius = new UIMenuListItem("Change Collection Radius", collectorRadii, collectorRadii.IndexOf(currentPath.Waypoints[editWaypoint.Index].CollectorRadius)));
MenuManager.editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false)); editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false));
MenuManager.editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint")); editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint"));
MenuManager.editWaypointMenu.AddItem(editRemoveWaypoint = new UIMenuItem("Remove Waypoint")); editWaypointMenu.AddItem(editRemoveWaypoint = new UIMenuItem("Remove Waypoint"));
MenuManager.editPathMenu.Visible = false; EditPathMenu.editPathMenu.Visible = false;
MenuManager.editWaypointMenu.RefreshIndex(); editWaypointMenu.RefreshIndex();
MenuManager.editWaypointMenu.Visible = true; editWaypointMenu.Visible = true;
MenuManager.editWaypointMenu.OnItemSelect += EditWaypoint_OnItemSelected; editWaypointMenu.OnItemSelect += EditWaypoint_OnItemSelected;
MenuManager.editWaypointMenu.OnListChange += EditWaypoint_OnListChanged; editWaypointMenu.OnListChange += EditWaypoint_OnListChanged;
} }
private static void EditWaypoint_OnListChanged(UIMenu sender, UIMenuListItem listItem, int index) private static void EditWaypoint_OnListChanged(UIMenu sender, UIMenuListItem listItem, int index)
{ {
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index]; var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index];
var currentWaypoint = currentPath.Waypoints[editWaypoint.Index]; var currentWaypoint = currentPath.Waypoints[editWaypoint.Index];
if (listItem == editWaypoint) if (listItem == editWaypoint)
{ {
while (MenuManager.editWaypointMenu.MenuItems.Count > 1) while (editWaypointMenu.MenuItems.Count > 1)
{ {
MenuManager.editWaypointMenu.RemoveItemAt(1); editWaypointMenu.RemoveItemAt(1);
GameFiber.Yield(); GameFiber.Yield();
} }
MenuManager.editWaypointMenu.AddItem(changeWaypointType = new UIMenuListItem("Change Waypoint Type", waypointTypes, Array.IndexOf(drivingFlags, currentWaypoint.DrivingFlag))); editWaypointMenu.AddItem(changeWaypointType = new UIMenuListItem("Change Waypoint Type", waypointTypes, Array.IndexOf(drivingFlags, currentWaypoint.DrivingFlag)));
MenuManager.editWaypointMenu.AddItem(changeWaypointSpeed = new UIMenuListItem("Change Waypoint Speed", waypointSpeeds, waypointSpeeds.IndexOf(currentWaypoint.Speed))); editWaypointMenu.AddItem(changeWaypointSpeed = new UIMenuListItem("Change Waypoint Speed", waypointSpeeds, waypointSpeeds.IndexOf(currentWaypoint.Speed)));
MenuManager.editWaypointMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Attractor Waypoint", currentWaypoint.Collector)); editWaypointMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Attractor Waypoint", currentWaypoint.Collector));
MenuManager.editWaypointMenu.AddItem(changeCollectorRadius = new UIMenuListItem("Change Collection Radius", collectorRadii, collectorRadii.IndexOf(currentPath.Waypoints[editWaypoint.Index].CollectorRadius))); editWaypointMenu.AddItem(changeCollectorRadius = new UIMenuListItem("Change Collection Radius", collectorRadii, collectorRadii.IndexOf(currentPath.Waypoints[editWaypoint.Index].CollectorRadius)));
MenuManager.editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false)); editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false));
MenuManager.editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint")); editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint"));
MenuManager.editWaypointMenu.AddItem(editRemoveWaypoint = new UIMenuItem("Remove Waypoint")); editWaypointMenu.AddItem(editRemoveWaypoint = new UIMenuItem("Remove Waypoint"));
MenuManager.editWaypointMenu.RefreshIndex(); editWaypointMenu.RefreshIndex();
} }
} }
private static void EditWaypoint_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index) private static void EditWaypoint_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
{ {
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index]; var currentPath = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index];
var currentWaypoint = currentPath.Waypoints[editWaypoint.Index]; var currentWaypoint = currentPath.Waypoints[editWaypoint.Index];
if (selectedItem == editUpdateWaypoint) if (selectedItem == editUpdateWaypoint)
@ -104,10 +113,10 @@ namespace SceneManager
if (currentPath.Waypoints.Count == 1) if (currentPath.Waypoints.Count == 1)
{ {
Game.LogTrivial($"Deleting the last waypoint from the path."); Game.LogTrivial($"Deleting the last waypoint from the path.");
TrafficMenu.DeletePath(currentPath, currentPath.PathNum - 1, "Single"); PathMainMenu.DeletePath(currentPath, currentPath.PathNum - 1, PathMainMenu.Delete.Single);
MenuManager.editWaypointMenu.Visible = false; editWaypointMenu.Visible = false;
MenuManager.pathMenu.Visible = true; PathMainMenu.pathMainMenu.Visible = true;
} }
else else
{ {

View file

@ -11,26 +11,33 @@ namespace SceneManager
{ {
class MainMenu class MainMenu
{ {
public static UIMenu mainMenu { get; private set; }
private static UIMenuItem navigateToPathMenu, navigateToBarrierMenu, navigateToSettingsMenu; private static UIMenuItem navigateToPathMenu, navigateToBarrierMenu, navigateToSettingsMenu;
internal static void InstantiateMenu()
{
mainMenu = new UIMenu("Scene Manager", "");
MenuManager.menuPool.Add(mainMenu);
}
public static void BuildMainMenu() public static void BuildMainMenu()
{ {
MenuManager.mainMenu.AddItem(navigateToPathMenu = new UIMenuItem("~o~Path Menu")); mainMenu.AddItem(navigateToPathMenu = new UIMenuItem("~o~Path Menu"));
MenuManager.mainMenu.BindMenuToItem(MenuManager.pathMenu, navigateToPathMenu); mainMenu.BindMenuToItem(PathMainMenu.pathMainMenu, navigateToPathMenu);
MenuManager.mainMenu.AddItem(navigateToBarrierMenu = new UIMenuItem("~o~Barrier Menu")); mainMenu.AddItem(navigateToBarrierMenu = new UIMenuItem("~o~Barrier Menu"));
MenuManager.mainMenu.BindMenuToItem(MenuManager.barrierMenu, navigateToBarrierMenu); mainMenu.BindMenuToItem(BarrierMenu.barrierMenu, navigateToBarrierMenu);
MenuManager.mainMenu.AddItem(navigateToSettingsMenu = new UIMenuItem("~o~Settings")); mainMenu.AddItem(navigateToSettingsMenu = new UIMenuItem("~o~Settings"));
MenuManager.mainMenu.BindMenuToItem(MenuManager.settingsMenu, navigateToSettingsMenu); mainMenu.BindMenuToItem(SettingsMenu.settingsMenu, navigateToSettingsMenu);
MenuManager.mainMenu.RefreshIndex(); mainMenu.RefreshIndex();
MenuManager.mainMenu.OnItemSelect += MainMenu_OnItemSelected; mainMenu.OnItemSelect += MainMenu_OnItemSelected;
} }
private static void MainMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index) private static void MainMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
{ {
if (selectedItem == navigateToBarrierMenu) if (selectedItem == navigateToBarrierMenu)
{ {
BarrierMenu.CreateShadowBarrier(MenuManager.barrierMenu); BarrierMenu.CreateShadowBarrier(BarrierMenu.barrierMenu);
} }
} }
} }

View file

@ -12,31 +12,38 @@ namespace SceneManager
{ {
class PathCreationMenu class PathCreationMenu
{ {
#pragma warning disable CS0618 // Type or member is obsolete, clear NUI squiggles public static UIMenu pathCreationMenu { get; private set; }
public static UIMenuItem trafficAddWaypoint, trafficRemoveWaypoint, trafficEndPath; private static UIMenuItem trafficAddWaypoint, trafficRemoveWaypoint, trafficEndPath;
public static UIMenuListItem waypointType, waypointSpeed, collectorRadius; private static UIMenuListScrollerItem<string> waypointType;
private static UIMenuListScrollerItem<float> waypointSpeed;
private static UIMenuListScrollerItem<float> collectorRadius;
private static UIMenuCheckboxItem collectorWaypoint; private static UIMenuCheckboxItem collectorWaypoint;
private static List<dynamic> waypointSpeeds = new List<dynamic>() { 5f, 10f, 15f, 20f, 30f, 40f, 50f, 60f, 70f }; private static List<string> waypointTypes = new List<string>() { "Drive To", "Stop" };
//private enum waypointTypes {DriveTo, Stop }; private static List<float> waypointSpeeds = new List<float>() { 5f, 10f, 15f, 20f, 30f, 40f, 50f, 60f, 70f };
private static List<dynamic> waypointTypes = new List<dynamic>() { "Drive To", "Stop" }; private static List<float> collectorRadii = new List<float>() { 3f, 5f, 10f, 15f, 20f, 30f, 40f, 50f };
private static List<dynamic> collectorRadii = new List<dynamic>() { 3f, 5f, 10f, 15f, 20f, 30f, 40f, 50f };
private static VehicleDrivingFlags[] drivingFlags = new VehicleDrivingFlags[] { VehicleDrivingFlags.Normal, VehicleDrivingFlags.StopAtDestination }; // Implement custom driving flag for normal private static VehicleDrivingFlags[] drivingFlags = new VehicleDrivingFlags[] { VehicleDrivingFlags.Normal, VehicleDrivingFlags.StopAtDestination }; // Implement custom driving flag for normal
// Called from EditPathMenu internal static void InstantiateMenu()
{
pathCreationMenu = new UIMenu("Scene Menu", "~o~Path Creation");
pathCreationMenu.ParentMenu = PathMainMenu.pathMainMenu;
MenuManager.menuPool.Add(pathCreationMenu);
}
public static void BuildPathCreationMenu() public static void BuildPathCreationMenu()
{ {
MenuManager.pathCreationMenu.AddItem(waypointType = new UIMenuListItem("Waypoint Type", waypointTypes, 0)); pathCreationMenu.AddItem(waypointType = new UIMenuListScrollerItem<string>("Waypoint Type", "", waypointTypes));
MenuManager.pathCreationMenu.AddItem(waypointSpeed = new UIMenuListItem($"Waypoint Speed (in {SettingsMenu.speedUnits.SelectedItem})", waypointSpeeds, 0)); pathCreationMenu.AddItem(waypointSpeed = new UIMenuListScrollerItem<float>($"Waypoint Speed (in {SettingsMenu.speedUnits.SelectedItem}", "", waypointSpeeds));
MenuManager.pathCreationMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Collector", true)); // true if path's first waypoint pathCreationMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Collector", true)); // true if path's first waypoint
MenuManager.pathCreationMenu.AddItem(collectorRadius = new UIMenuListItem("Collection Radius", collectorRadii, 0)); pathCreationMenu.AddItem(collectorRadius = new UIMenuListScrollerItem<float>("Collection Radius", "", collectorRadii));
MenuManager.pathCreationMenu.AddItem(trafficAddWaypoint = new UIMenuItem("Add waypoint")); pathCreationMenu.AddItem(trafficAddWaypoint = new UIMenuItem("Add waypoint"));
MenuManager.pathCreationMenu.AddItem(trafficRemoveWaypoint = new UIMenuItem("Remove last waypoint")); pathCreationMenu.AddItem(trafficRemoveWaypoint = new UIMenuItem("Remove last waypoint"));
trafficRemoveWaypoint.Enabled = false; trafficRemoveWaypoint.Enabled = false;
MenuManager.pathCreationMenu.AddItem(trafficEndPath = new UIMenuItem("End path creation")); pathCreationMenu.AddItem(trafficEndPath = new UIMenuItem("End path creation"));
MenuManager.pathCreationMenu.RefreshIndex(); pathCreationMenu.RefreshIndex();
MenuManager.pathCreationMenu.OnItemSelect += PathCreation_OnItemSelected; pathCreationMenu.OnItemSelect += PathCreation_OnItemSelected;
} }
private static void PathCreation_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index) private static void PathCreation_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
@ -44,10 +51,10 @@ namespace SceneManager
// Do I need to implement a distance restriction? Idiots place waypoints unnecessarily close, possibly causing AI to drive in circles // Do I need to implement a distance restriction? Idiots place waypoints unnecessarily close, possibly causing AI to drive in circles
if (selectedItem == trafficAddWaypoint) if (selectedItem == trafficAddWaypoint)
{ {
var firstNonNullPath = TrafficMenu.paths.Where(p => p != null && !p.PathFinished).First(); var firstNonNullPath = PathMainMenu.GetPaths().Where(p => p != null && !p.PathFinished).First();
var pathIndex = TrafficMenu.paths.IndexOf(firstNonNullPath); var pathIndex = PathMainMenu.GetPaths().IndexOf(firstNonNullPath);
var currentPath = pathIndex + 1; var currentPath = pathIndex + 1;
var currentWaypoint = TrafficMenu.paths[pathIndex].Waypoints.Count + 1; var currentWaypoint = PathMainMenu.GetPaths()[pathIndex].Waypoints.Count + 1;
var drivingFlag = drivingFlags[waypointType.Index]; var drivingFlag = drivingFlags[waypointType.Index];
var blip = CreateWaypointBlip(pathIndex); var blip = CreateWaypointBlip(pathIndex);
@ -57,35 +64,35 @@ namespace SceneManager
? (uint)World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index])) ? (uint)World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index]))
: (uint)World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index])); : (uint)World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index]));
TrafficMenu.paths[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip, true, collectorRadii[collectorRadius.Index], yieldZone)); PathMainMenu.GetPaths()[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip, true, collectorRadii[collectorRadius.Index], yieldZone));
} }
else else
{ {
TrafficMenu.paths[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip)); PathMainMenu.GetPaths()[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip));
} }
Game.LogTrivial($"[Path {currentPath}] Waypoint {currentWaypoint} ({drivingFlag.ToString()}) added"); Game.LogTrivial($"[Path {currentPath}] Waypoint {currentWaypoint} ({drivingFlag.ToString()}) added");
// Refresh the trafficMenu after a waypoint is added in order to show Continue Creating Current Path instead of Create New Path // Refresh the trafficMenu after a waypoint is added in order to show Continue Creating Current Path instead of Create New Path
RefreshTrafficMenu(); PathMainMenu.RefreshMenu(trafficRemoveWaypoint);
} }
if (selectedItem == trafficRemoveWaypoint) 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 // 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 < TrafficMenu.paths.Count; i++) for (int i = 0; i < PathMainMenu.GetPaths().Count; i++)
{ {
if (TrafficMenu.paths.ElementAtOrDefault(i) != null && !TrafficMenu.paths[i].PathFinished) if (PathMainMenu.GetPaths().ElementAtOrDefault(i) != null && !PathMainMenu.GetPaths()[i].PathFinished)
{ {
Game.LogTrivial($"[Path {i + 1}] {TrafficMenu.paths[i].Waypoints.Last().DrivingFlag.ToString()} waypoint removed"); Game.LogTrivial($"[Path {i + 1}] {PathMainMenu.GetPaths()[i].Waypoints.Last().DrivingFlag.ToString()} waypoint removed");
TrafficMenu.paths[i].Waypoints.Last().Blip.Delete(); PathMainMenu.GetPaths()[i].Waypoints.Last().Blip.Delete();
if (TrafficMenu.paths[i].Waypoints.Last().CollectorRadiusBlip) if (PathMainMenu.GetPaths()[i].Waypoints.Last().CollectorRadiusBlip)
{ {
TrafficMenu.paths[i].Waypoints.Last().CollectorRadiusBlip.Delete(); PathMainMenu.GetPaths()[i].Waypoints.Last().CollectorRadiusBlip.Delete();
} }
TrafficMenu.paths[i].Waypoints.RemoveAt(TrafficMenu.paths[i].Waypoints.IndexOf(TrafficMenu.paths[i].Waypoints.Last())); PathMainMenu.GetPaths()[i].Waypoints.RemoveAt(PathMainMenu.GetPaths()[i].Waypoints.IndexOf(PathMainMenu.GetPaths()[i].Waypoints.Last()));
// If the path has no waypoints, disable the menu option to remove a waypoint // If the path has no waypoints, disable the menu option to remove a waypoint
if (TrafficMenu.paths[i].Waypoints.Count == 0) if (PathMainMenu.GetPaths()[i].Waypoints.Count == 0)
{ {
trafficRemoveWaypoint.Enabled = false; trafficRemoveWaypoint.Enabled = false;
} }
@ -96,10 +103,10 @@ namespace SceneManager
if (selectedItem == trafficEndPath) if (selectedItem == trafficEndPath)
{ {
// Loop through each path and find the first one which isn't finished // Loop through each path and find the first one which isn't finished
for (int i = 0; i < TrafficMenu.paths.Count; i++) for (int i = 0; i < PathMainMenu.GetPaths().Count; i++)
{ {
var currentPath = TrafficMenu.paths[i]; var currentPath = PathMainMenu.GetPaths()[i];
if (TrafficMenu.paths.ElementAtOrDefault(i) != null && !currentPath.PathFinished) if (PathMainMenu.GetPaths().ElementAtOrDefault(i) != null && !currentPath.PathFinished)
{ {
// If the path has one stop waypoint or at least two waypoints, finish the path and start the vehicle collector loop, else show user the error and delete any waypoints they made and clear the invalid path // If the path has one stop waypoint or at least two waypoints, finish the path and start the vehicle collector loop, else show user the error and delete any waypoints they made and clear the invalid path
if (currentPath.Waypoints.Count >= 2 || (currentPath.Waypoints.Count == 1 && currentPath.Waypoints[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination)) if (currentPath.Waypoints.Count >= 2 || (currentPath.Waypoints.Count == 1 && currentPath.Waypoints[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination))
@ -114,32 +121,32 @@ namespace SceneManager
currentPath.FinishPath(); currentPath.FinishPath();
currentPath.EnablePath(); currentPath.EnablePath();
currentPath.SetPathNumber(i + 1); currentPath.SetPathNumber(i + 1);
TrafficMenu.pathsNum.Insert(i, currentPath.PathNum); PathMainMenu.AddPathToPathCountList(i, currentPath.PathNum);
//GameFiber InitialWaypointVehicleCollectorFiber = new GameFiber(() => TrafficPathing.InitialWaypointVehicleCollector(paths[i])); //GameFiber InitialWaypointVehicleCollectorFiber = new GameFiber(() => TrafficPathing.InitialWaypointVehicleCollector(paths[i]));
//InitialWaypointVehicleCollectorFiber.Start(); //InitialWaypointVehicleCollectorFiber.Start();
// For each waypoint in the path's WaypointData, start a collector game fiber and loop while the path and waypoint exist, and while the path is enabled // For each waypoint in the path's WaypointData, start a collector game fiber and loop while the path and waypoint exist, and while the path is enabled
foreach (Waypoint wd in TrafficMenu.paths[i].Waypoints) foreach (Waypoint wd in PathMainMenu.GetPaths()[i].Waypoints)
{ {
GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => TrafficPathing.WaypointVehicleCollector(TrafficMenu.paths, TrafficMenu.paths[i], wd)); GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => TrafficPathing.WaypointVehicleCollector(PathMainMenu.GetPaths(), PathMainMenu.GetPaths()[i], wd));
WaypointVehicleCollectorFiber.Start(); WaypointVehicleCollectorFiber.Start();
GameFiber AssignStopForVehiclesFlagFiber = new GameFiber(() => TrafficPathing.AssignStopForVehiclesFlag(TrafficMenu.paths, TrafficMenu.paths[i], wd)); GameFiber AssignStopForVehiclesFlagFiber = new GameFiber(() => TrafficPathing.AssignStopForVehiclesFlag(PathMainMenu.GetPaths(), PathMainMenu.GetPaths()[i], wd));
AssignStopForVehiclesFlagFiber.Start(); AssignStopForVehiclesFlagFiber.Start();
} }
MenuManager.menuPool.CloseAllMenus(); MenuManager.menuPool.CloseAllMenus();
MenuManager.pathMenu.Clear(); PathMainMenu.pathMainMenu.Clear();
TrafficMenu.BuildPathMenu(); PathMainMenu.BuildPathMenu();
MenuManager.pathMenu.Visible = true; PathMainMenu.pathMainMenu.Visible = true;
break; break;
} }
else else
{ {
Game.LogTrivial($"[Path Error] A minimum of 2 waypoints is required."); Game.LogTrivial($"[Path Error] A minimum of 2 waypoints is required.");
Game.DisplayNotification($"~o~Scene Manager\n~r~[Error]~w~ A minimum of 2 waypoints or one stop waypoint is required to create a path."); Game.DisplayNotification($"~o~Scene Manager\n~r~[Error]~w~ A minimum of 2 waypoints or one stop waypoint is required to create a path.");
foreach (Waypoint wp in TrafficMenu.paths[i].Waypoints) foreach (Waypoint wp in PathMainMenu.GetPaths()[i].Waypoints)
{ {
wp.Blip.Delete(); wp.Blip.Delete();
if (wp.CollectorRadiusBlip) if (wp.CollectorRadiusBlip)
@ -147,8 +154,8 @@ namespace SceneManager
wp.CollectorRadiusBlip.Delete(); wp.CollectorRadiusBlip.Delete();
} }
} }
TrafficMenu.paths[i].Waypoints.Clear(); PathMainMenu.GetPaths()[i].Waypoints.Clear();
TrafficMenu.paths.RemoveAt(i); PathMainMenu.GetPaths().RemoveAt(i);
break; break;
} }
} }
@ -187,7 +194,7 @@ namespace SceneManager
Sprite = (BlipSprite)spriteNumericalEnum Sprite = (BlipSprite)spriteNumericalEnum
}; };
if (TrafficMenu.paths[pathIndex].Waypoints.Count == 0) if (PathMainMenu.GetPaths()[pathIndex].Waypoints.Count == 0)
{ {
blip.Color = Color.Orange; blip.Color = Color.Orange;
} }
@ -199,26 +206,36 @@ namespace SceneManager
return blip; return blip;
} }
private static void RefreshTrafficMenu() public static void AddNewPathToPathsCollection(List<Path> paths, int pathIndex)
{ {
trafficRemoveWaypoint.Enabled = true; var pathNum = pathIndex + 1;
MenuManager.pathMenu.Clear(); Game.LogTrivial($"Creating path {pathNum}");
MenuManager.pathMenu.AddItem(TrafficMenu.createNewPath = new UIMenuItem("Continue Creating Current Path")); Game.DisplayNotification($"~o~Scene Manager\n~y~[Creating]~w~ Path {pathNum} started.");
MenuManager.pathMenu.AddItem(TrafficMenu.deleteAllPaths = new UIMenuItem("Delete All Paths")); paths.Insert(pathIndex, new Path(pathNum, false));
MenuManager.pathMenu.AddItem(TrafficMenu.directDriver = new UIMenuListItem("Direct nearest driver to path", TrafficMenu.pathsNum, 0)); trafficRemoveWaypoint.Enabled = false;
MenuManager.pathMenu.AddItem(TrafficMenu.dismissDriver = new UIMenuListItem("Dismiss nearest driver", TrafficMenu.dismissOptions, 0));
if (TrafficMenu.paths.Count == 8)
{
TrafficMenu.createNewPath.Enabled = false;
}
if (TrafficMenu.paths.Count == 0)
{
TrafficMenu.editPath.Enabled = false;
TrafficMenu.deleteAllPaths.Enabled = false;
TrafficMenu.disableAllPaths.Enabled = false;
TrafficMenu.directDriver.Enabled = false;
}
} }
//private static void RefreshPathMainMenu()
//{
// trafficRemoveWaypoint.Enabled = true;
// MenuManager.pathMenu.Clear();
// //MenuManager.pathMenu.AddItem(PathMainMenu.AddNewMenuItem())
// MenuManager.pathMenu.AddItem(PathMainMenu.createNewPath = new UIMenuItem("Continue Creating Current Path"));
// MenuManager.pathMenu.AddItem(PathMainMenu.deleteAllPaths = new UIMenuItem("Delete All Paths"));
// MenuManager.pathMenu.AddItem(PathMainMenu.directDriver = new UIMenuListScrollerItem<int>("Direct nearest driver to path", ""));
// MenuManager.pathMenu.AddItem(PathMainMenu.dismissDriver = new UIMenuListScrollerItem<string>("Dismiss nearest driver", ""));
// if (PathMainMenu.GetPaths().Count == 8)
// {
// PathMainMenu.createNewPath.Enabled = false;
// }
// if (PathMainMenu.GetPaths().Count == 0)
// {
// PathMainMenu.editPath.Enabled = false;
// PathMainMenu.deleteAllPaths.Enabled = false;
// PathMainMenu.disableAllPaths.Enabled = false;
// PathMainMenu.directDriver.Enabled = false;
// }
//}
} }
} }

View file

@ -7,31 +7,45 @@ using RAGENativeUI.Elements;
namespace SceneManager namespace SceneManager
{ {
static class TrafficMenu static class PathMainMenu
{ {
#pragma warning disable CS0618 // Type or member is obsolete, clear NUI squiggles public static UIMenu pathMainMenu { get; private set; }
public static UIMenuItem createNewPath, deleteAllPaths; private static UIMenuItem createNewPath, deleteAllPaths;
public static UIMenuListItem editPath, directDriver, dismissDriver; public static UIMenuListScrollerItem<int> editPath { get; private set; }
public static UIMenuCheckboxItem disableAllPaths; public static UIMenuListScrollerItem<int> directDriver { get; private set; }
public static UIMenuListScrollerItem<string> dismissDriver { get; private set; }
public static List<dynamic> pathsNum = new List<dynamic>() { }; public static UIMenuCheckboxItem disableAllPaths { get; private set; }
public static List<Path> paths = new List<Path>() { };
public static List<dynamic> dismissOptions = new List<dynamic>() { "From path", "From waypoint", "From position" }; private static List<int> pathsNum = new List<int>();
private static List<Path> paths = new List<Path>() { };
private static List<string> dismissOptions = new List<string>() { "From path", "From waypoint", "From position" };
public enum Delete
{
Single,
All
}
internal static void InstantiateMenu()
{
pathMainMenu = new UIMenu("Scene Menu", "~o~Path Manager Main Menu");
pathMainMenu.ParentMenu = MainMenu.mainMenu;
MenuManager.menuPool.Add(pathMainMenu);
}
public static void BuildPathMenu() public static void BuildPathMenu()
{ {
// New stuff to mitigate Rebuild method // New stuff to mitigate Rebuild method
MenuManager.pathMenu.OnItemSelect -= PathMenu_OnItemSelected; pathMainMenu.OnItemSelect -= PathMenu_OnItemSelected;
MenuManager.pathMenu.OnCheckboxChange -= PathMenu_OnCheckboxChange; pathMainMenu.OnCheckboxChange -= PathMenu_OnCheckboxChange;
MenuManager.menuPool.CloseAllMenus(); MenuManager.menuPool.CloseAllMenus();
MenuManager.pathMenu.Clear(); pathMainMenu.Clear();
MenuManager.pathMenu.AddItem(createNewPath = new UIMenuItem("Create New Path")); pathMainMenu.AddItem(createNewPath = new UIMenuItem("Create New Path"));
MenuManager.pathMenu.AddItem(editPath = new UIMenuListItem("Edit Path", pathsNum, 0)); pathMainMenu.AddItem(editPath = new UIMenuListScrollerItem<int>("Edit Path", "", pathsNum));
MenuManager.pathMenu.AddItem(disableAllPaths = new UIMenuCheckboxItem("Disable All Paths", false)); pathMainMenu.AddItem(disableAllPaths = new UIMenuCheckboxItem("Disable All Paths", false));
MenuManager.pathMenu.AddItem(deleteAllPaths = new UIMenuItem("Delete All Paths")); pathMainMenu.AddItem(deleteAllPaths = new UIMenuItem("Delete All Paths"));
MenuManager.pathMenu.AddItem(directDriver = new UIMenuListItem("Direct nearest driver to path", pathsNum, 0)); pathMainMenu.AddItem(directDriver = new UIMenuListScrollerItem<int>("Direct nearest driver to path", "", pathsNum));
MenuManager.pathMenu.AddItem(dismissDriver = new UIMenuListItem("Dismiss nearest driver", dismissOptions, 0)); pathMainMenu.AddItem(dismissDriver = new UIMenuListScrollerItem<string>("Dismiss nearest driver", "", dismissOptions));
if (paths.Count == 8) if (paths.Count == 8)
{ {
@ -45,14 +59,46 @@ namespace SceneManager
directDriver.Enabled = false; directDriver.Enabled = false;
} }
MenuManager.pathMenu.RefreshIndex(); pathMainMenu.RefreshIndex();
MenuManager.pathMenu.OnItemSelect += PathMenu_OnItemSelected; pathMainMenu.OnItemSelect += PathMenu_OnItemSelected;
MenuManager.pathMenu.OnCheckboxChange += PathMenu_OnCheckboxChange; pathMainMenu.OnCheckboxChange += PathMenu_OnCheckboxChange;
// New stuff to mitigate Rebuild method // New stuff to mitigate Rebuild method
MenuManager.menuPool.RefreshIndex(); MenuManager.menuPool.RefreshIndex();
} }
public static ref List<Path> GetPaths()
{
return ref paths;
}
public static void AddPathToPathCountList(int indexToInsertAt, int pathNum)
{
pathsNum.Insert(indexToInsertAt, pathNum);
}
public static void RefreshMenu(UIMenuItem trafficRemoveWaypoint)
{
trafficRemoveWaypoint.Enabled = true;
pathMainMenu.Clear();
pathMainMenu.AddItem(createNewPath = new UIMenuItem("Continue Creating Current Path"));
pathMainMenu.AddItem(deleteAllPaths = new UIMenuItem("Delete All Paths"));
pathMainMenu.AddItem(directDriver = new UIMenuListScrollerItem<int>("Direct nearest driver to path", ""));
pathMainMenu.AddItem(dismissDriver = new UIMenuListScrollerItem<string>("Dismiss nearest driver", ""));
if (GetPaths().Count == 8)
{
createNewPath.Enabled = false;
}
if (GetPaths().Count == 0)
{
editPath.Enabled = false;
deleteAllPaths.Enabled = false;
disableAllPaths.Enabled = false;
directDriver.Enabled = false;
}
}
private static bool VehicleAndDriverValid(this Vehicle v) private static bool VehicleAndDriverValid(this Vehicle v)
{ {
if (v && v.HasDriver && v.Driver && v.Driver.IsAlive) if (v && v.HasDriver && v.Driver && v.Driver.IsAlive)
@ -79,8 +125,7 @@ namespace SceneManager
} }
} }
// Refactor string param to enum public static void DeletePath(Path path, int index, Delete pathsToDelete)
public static void DeletePath(Path path, int index, string pathsToDelete)
{ {
// Before deleting a path, we need to dismiss any vehicles controlled by that path and remove the vehicles from ControlledVehicles // Before deleting a path, we need to dismiss any vehicles controlled by that path and remove the vehicles from ControlledVehicles
//Game.LogTrivial($"Deleting path {index+1}"); //Game.LogTrivial($"Deleting path {index+1}");
@ -96,7 +141,7 @@ namespace SceneManager
cv.Value.Vehicle.Driver.IsPersistent = false; cv.Value.Vehicle.Driver.IsPersistent = false;
cv.Value.Vehicle.Dismiss(); cv.Value.Vehicle.Dismiss();
cv.Value.Vehicle.IsPersistent = false; cv.Value.Vehicle.IsPersistent = false;
//TrafficPathing.ControlledVehicles.Remove(cv.Value.LicensePlate);
//Game.LogTrivial($"{cv.vehicle.Model.Name} cleared from path {cv.path}"); //Game.LogTrivial($"{cv.vehicle.Model.Name} cleared from path {cv.path}");
TrafficPathing.collectedVehicles.Remove(cv.Value.LicensePlate); TrafficPathing.collectedVehicles.Remove(cv.Value.LicensePlate);
} }
@ -122,20 +167,19 @@ namespace SceneManager
Game.LogTrivial($"Clearing path.WaypointData"); Game.LogTrivial($"Clearing path.WaypointData");
path.Waypoints.Clear(); path.Waypoints.Clear();
// Manipulating the menu to reflect specific paths being deleted // Manipulating the menu to reflect specific paths being deleted
if (pathsToDelete == "Single") if (pathsToDelete == Delete.Single)
{ {
paths.RemoveAt(index); paths.RemoveAt(index);
//Game.LogTrivial("pathsNum count: " + pathsNum.Count); //Game.LogTrivial("pathsNum count: " + pathsNum.Count);
//Game.LogTrivial("index: " + index); //Game.LogTrivial("index: " + index);
pathsNum.RemoveAt(index); pathsNum.RemoveAt(index);
//RebuildTrafficMenu();
BuildPathMenu(); BuildPathMenu();
MenuManager.pathMenu.Visible = true; pathMainMenu.Visible = true;
Game.LogTrivial($"Path {path.PathNum} deleted."); Game.LogTrivial($"Path {path.PathNum} deleted.");
Game.DisplayNotification($"~o~Scene Manager\n~w~Path {path.PathNum} deleted."); Game.DisplayNotification($"~o~Scene Manager\n~w~Path {path.PathNum} deleted.");
} }
MenuManager.editPathMenu.Reset(true, true); EditPathMenu.editPathMenu.Reset(true, true);
EditPathMenu.togglePath.Enabled = true; EditPathMenu.togglePath.Enabled = true;
} }
@ -143,8 +187,8 @@ namespace SceneManager
{ {
if (selectedItem == createNewPath) if (selectedItem == createNewPath)
{ {
MenuManager.pathMenu.Visible = false; pathMainMenu.Visible = false;
MenuManager.pathCreationMenu.Visible = true; PathCreationMenu.pathCreationMenu.Visible = true;
// For each element in paths, determine if the element exists but is not finished yet, or if it doesn't exist, create it. // For each element in paths, determine if the element exists but is not finished yet, or if it doesn't exist, create it.
for (int i = 0; i <= paths.Count; i++) for (int i = 0; i <= paths.Count; i++)
@ -158,10 +202,11 @@ namespace SceneManager
} }
else if (paths.ElementAtOrDefault(i) == null) else if (paths.ElementAtOrDefault(i) == null)
{ {
Game.LogTrivial($"Creating path {i + 1}"); PathCreationMenu.AddNewPathToPathsCollection(paths, i);
Game.DisplayNotification($"~o~Scene Manager\n~y~[Creating]~w~ Path {i + 1} started."); //Game.LogTrivial($"Creating path {i + 1}");
paths.Insert(i, new Path(i + 1, false)); //Game.DisplayNotification($"~o~Scene Manager\n~y~[Creating]~w~ Path {i + 1} started.");
PathCreationMenu.trafficRemoveWaypoint.Enabled = false; //paths.Insert(i, new Path(i + 1, false));
//PathCreationMenu.trafficRemoveWaypoint.Enabled = false;
if (SettingsMenu.debugGraphics.Checked) if (SettingsMenu.debugGraphics.Checked)
{ {
@ -177,8 +222,8 @@ namespace SceneManager
if (selectedItem == editPath) if (selectedItem == editPath)
{ {
MenuManager.pathMenu.Visible = false; pathMainMenu.Visible = false;
MenuManager.editPathMenu.Visible = true; EditPathMenu.editPathMenu.Visible = true;
} }
if (selectedItem == deleteAllPaths) if (selectedItem == deleteAllPaths)
@ -186,17 +231,20 @@ namespace SceneManager
// Iterate through each item in paths and delete it // Iterate through each item in paths and delete it
for (int i = 0; i < paths.Count; i++) for (int i = 0; i < paths.Count; i++)
{ {
DeletePath(paths[i], i, "All"); DeletePath(paths[i], i, Delete.All);
} }
foreach (Path path in paths) foreach (Path path in paths)
{ {
foreach(Waypoint wp in path.Waypoints.Where(wp => wp.YieldZone != 0))
{
World.RemoveSpeedZone(wp.YieldZone);
}
path.Waypoints.Clear(); path.Waypoints.Clear();
} }
paths.Clear(); paths.Clear();
pathsNum.Clear(); pathsNum.Clear();
//RebuildTrafficMenu();
BuildPathMenu(); BuildPathMenu();
MenuManager.pathMenu.Visible = true; pathMainMenu.Visible = true;
Game.LogTrivial($"All paths deleted"); Game.LogTrivial($"All paths deleted");
Game.DisplayNotification($"~o~Scene Manager\n~w~All paths deleted."); Game.DisplayNotification($"~o~Scene Manager\n~w~All paths deleted.");
} }

View file

@ -7,6 +7,7 @@ namespace SceneManager
{ {
class SettingsMenu class SettingsMenu
{ {
public static UIMenu settingsMenu { get; private set; }
public static UIMenuCheckboxItem debugGraphics; public static UIMenuCheckboxItem debugGraphics;
public static UIMenuListScrollerItem<SpeedUnitsOfMeasure> speedUnits; public static UIMenuListScrollerItem<SpeedUnitsOfMeasure> speedUnits;
public enum SpeedUnitsOfMeasure public enum SpeedUnitsOfMeasure
@ -15,13 +16,20 @@ namespace SceneManager
KPH KPH
} }
internal static void InstantiateMenu()
{
settingsMenu = new UIMenu("Scene Menu", "~o~Plugin Settings");
settingsMenu.ParentMenu = MainMenu.mainMenu;
MenuManager.menuPool.Add(settingsMenu);
}
public static void BuildSettingsMenu() public static void BuildSettingsMenu()
{ {
MenuManager.settingsMenu.AddItem(debugGraphics = new UIMenuCheckboxItem("Enable Debug Graphics", false)); settingsMenu.AddItem(debugGraphics = new UIMenuCheckboxItem("Enable Debug Graphics", false));
MenuManager.settingsMenu.AddItem(speedUnits = new UIMenuListScrollerItem<SpeedUnitsOfMeasure>("Speed Unit of Measure", "", new[] { SpeedUnitsOfMeasure.MPH, SpeedUnitsOfMeasure.KPH })); settingsMenu.AddItem(speedUnits = new UIMenuListScrollerItem<SpeedUnitsOfMeasure>("Speed Unit of Measure", "", new[] { SpeedUnitsOfMeasure.MPH, SpeedUnitsOfMeasure.KPH }));
MenuManager.settingsMenu.OnCheckboxChange += SettingsMenu_OnCheckboxChange; settingsMenu.OnCheckboxChange += SettingsMenu_OnCheckboxChange;
MenuManager.settingsMenu.OnScrollerChange += SettingsMenu_OnScrollerChange; settingsMenu.OnScrollerChange += SettingsMenu_OnScrollerChange;
} }
private static void SettingsMenu_OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked) private static void SettingsMenu_OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked)
@ -32,7 +40,7 @@ namespace SceneManager
// TODO: Add branch for this during path creation ... create temp Waypoint list during path creation, then assign to path[i] after creation? // TODO: Add branch for this during path creation ... create temp Waypoint list during path creation, then assign to path[i] after creation?
if (debugGraphics.Checked) if (debugGraphics.Checked)
{ {
foreach (Path path in TrafficMenu.paths) foreach (Path path in PathMainMenu.GetPaths())
{ {
GameFiber.StartNew(() => GameFiber.StartNew(() =>
{ {
@ -47,7 +55,8 @@ namespace SceneManager
{ {
if (scrollerItem == speedUnits) if (scrollerItem == speedUnits)
{ {
MenuManager.pathCreationMenu.Clear(); // Clear the menu and rebuild it to reflect the menu item text change
PathCreationMenu.pathCreationMenu.Clear();
PathCreationMenu.BuildPathCreationMenu(); PathCreationMenu.BuildPathCreationMenu();
} }
} }

View file

@ -63,7 +63,7 @@
<Compile Include="Object Classes\Path.cs" /> <Compile Include="Object Classes\Path.cs" />
<Compile Include="Menus\PathCreationMenu.cs" /> <Compile Include="Menus\PathCreationMenu.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Menus\TrafficMenu.cs" /> <Compile Include="Menus\PathMainMenu.cs" />
<Compile Include="Menus\SettingsMenu.cs" /> <Compile Include="Menus\SettingsMenu.cs" />
<Compile Include="TrafficPathing.cs" /> <Compile Include="TrafficPathing.cs" />
<Compile Include="Verification.cs" /> <Compile Include="Verification.cs" />