mirror of
https://github.com/thegeneralist01/Scene-Manager-DevRepo
synced 2026-01-11 15:40:29 +01:00
Mid-refactor
This commit is contained in:
parent
b52f160ff7
commit
f4c1c0c693
18 changed files with 1721 additions and 916 deletions
223
SceneManager/Menus/BarrierMenu.cs
Normal file
223
SceneManager/Menus/BarrierMenu.cs
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
|
||||
namespace SceneManager
|
||||
{
|
||||
class BarrierMenu
|
||||
{
|
||||
public static List<Rage.Object> barriers = new List<Rage.Object>() { };
|
||||
|
||||
// TODO: Refactor as dictionary
|
||||
private static UIMenuListScrollerItem<string> barrierList = new UIMenuListScrollerItem<string>("Select Barrier", "", new[] { "Large Striped Cone", "Large Cone", "Medium Striped Cone", "Medium Cone", "Roadpole A", "Roadpole B", "Police Barrier", "Road Barrier", "Flare" });
|
||||
private static string[] barrierObjectNames = new string[] { "prop_mp_cone_01", "prop_roadcone01c", "prop_mp_cone_02", "prop_mp_cone_03", "prop_roadpole_01a", "prop_roadpole_01b", "prop_barrier_work05", "prop_barrier_work06a", "prop_flare_01b" };
|
||||
private static UIMenuNumericScrollerItem<int> rotateBarrier = new UIMenuNumericScrollerItem<int>("Rotate Barrier", "Rotate the barrier.", 0, 359, 10);
|
||||
private static UIMenuListScrollerItem<string> removeBarrierOptions = new UIMenuListScrollerItem<string>("Remove Barrier", "", new[] { "Last Barrier", "Nearest Barrier", "All Barriers" });
|
||||
public static Rage.Object shadowBarrier;
|
||||
|
||||
public static void BuildBarrierMenu()
|
||||
{
|
||||
MenuManager.barrierMenu.AddItem(removeBarrierOptions, 0);
|
||||
removeBarrierOptions.Enabled = false;
|
||||
MenuManager.barrierMenu.AddItem(rotateBarrier, 0);
|
||||
MenuManager.barrierMenu.AddItem(barrierList, 0);
|
||||
MenuManager.barrierMenu.RefreshIndex();
|
||||
|
||||
MenuManager.barrierMenu.OnItemSelect += BarrierMenu_OnItemSelected;
|
||||
MenuManager.barrierMenu.OnScrollerChange += BarrierMenu_OnScrollerChange;
|
||||
}
|
||||
|
||||
public static void CreateShadowBarrier(UIMenu barrierMenu)
|
||||
{
|
||||
if (EntryPoint.Settings.EnableHints)
|
||||
{
|
||||
Game.DisplayNotification($"~o~Scene Manager\n~y~[Hint]~y~ ~w~The shadow cone will disappear if you aim too far away.");
|
||||
}
|
||||
|
||||
//Game.LogTrivial("Creating shadow cone");
|
||||
if (shadowBarrier)
|
||||
shadowBarrier.Delete();
|
||||
|
||||
shadowBarrier = new Rage.Object(barrierObjectNames[barrierList.Index], TracePlayerView(15, TraceFlags.IntersectEverything).HitPosition, rotateBarrier.Index);
|
||||
Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(shadowBarrier);
|
||||
shadowBarrier.IsGravityDisabled = true;
|
||||
shadowBarrier.IsCollisionEnabled = false;
|
||||
shadowBarrier.Opacity = 0.7f;
|
||||
|
||||
GameFiber ShadowConeLoopFiber = new GameFiber(() => LoopToDisplayShadowBarrier(barrierMenu));
|
||||
ShadowConeLoopFiber.Start();
|
||||
}
|
||||
|
||||
private static void LoopToDisplayShadowBarrier(UIMenu coneMenu)
|
||||
{
|
||||
while (coneMenu.Visible && shadowBarrier)
|
||||
{
|
||||
UpdateShadowBarrierPosition();
|
||||
GameFiber.Yield();
|
||||
}
|
||||
|
||||
if (shadowBarrier)
|
||||
shadowBarrier.Delete();
|
||||
}
|
||||
|
||||
private static void UpdateShadowBarrierPosition()
|
||||
{
|
||||
DisableBarrierMenuOptionsIfShadowConeTooFar();
|
||||
shadowBarrier.Position = TracePlayerView(15, TraceFlags.IntersectEverything).HitPosition;
|
||||
Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(shadowBarrier);
|
||||
shadowBarrier.Heading = rotateBarrier.Index;
|
||||
|
||||
void DisableBarrierMenuOptionsIfShadowConeTooFar()
|
||||
{
|
||||
if (shadowBarrier.Position.DistanceTo2D(Game.LocalPlayer.Character.Position) > 15f)
|
||||
{
|
||||
barrierList.Enabled = false;
|
||||
rotateBarrier.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
barrierList.Enabled = true;
|
||||
rotateBarrier.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void BarrierMenu_OnScrollerChange(UIMenu sender, UIMenuScrollerItem scrollerItem, int oldIndex, int newIndex)
|
||||
{
|
||||
if (scrollerItem == barrierList)
|
||||
{
|
||||
CreateShadowBarrier(MenuManager.barrierMenu);
|
||||
|
||||
if (barrierObjectNames[barrierList.Index] == "prop_flare_01b")
|
||||
{
|
||||
rotateBarrier.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
rotateBarrier.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollerItem == rotateBarrier)
|
||||
{
|
||||
shadowBarrier.Heading = rotateBarrier.Index;
|
||||
}
|
||||
}
|
||||
|
||||
private static void BarrierMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
if (selectedItem == barrierList as UIMenuItem)
|
||||
{
|
||||
// Attach some invisible object to the cone which the AI try to drive around
|
||||
// Barrier rotates with cone and becomes invisible similar to ASC when created
|
||||
|
||||
if (shadowBarrier.Model.Name == "prop_flare_01b".ToUpper())
|
||||
{
|
||||
SpawnFlare();
|
||||
}
|
||||
else
|
||||
{
|
||||
SpawnBarrier();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (selectedItem == removeBarrierOptions as UIMenuItem)
|
||||
{
|
||||
RemoveBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SpawnBarrier()
|
||||
{
|
||||
var cone = new Rage.Object(shadowBarrier.Model, shadowBarrier.Position, rotateBarrier.Index);
|
||||
cone.SetPositionWithSnap(shadowBarrier.Position);
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_FRAG_DAMAGE(cone, true);
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_BREAKING(cone, true);
|
||||
|
||||
barriers.Add(cone);
|
||||
removeBarrierOptions.Enabled = true;
|
||||
}
|
||||
|
||||
private static void RemoveBarrier()
|
||||
{
|
||||
switch (removeBarrierOptions.Index)
|
||||
{
|
||||
case 0:
|
||||
barriers[barriers.Count - 1].Delete();
|
||||
barriers.RemoveAt(barriers.Count - 1);
|
||||
break;
|
||||
case 1:
|
||||
barriers = barriers.OrderBy(c => c.DistanceTo(Game.LocalPlayer.Character)).ToList();
|
||||
barriers[0].Delete();
|
||||
barriers.RemoveAt(0);
|
||||
break;
|
||||
case 2:
|
||||
foreach (Rage.Object c in barriers.Where(c => c))
|
||||
{
|
||||
c.Delete();
|
||||
}
|
||||
if (barriers.Count > 0)
|
||||
{
|
||||
barriers.Clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
removeBarrierOptions.Enabled = barriers.Count == 0 ? false : true;
|
||||
}
|
||||
|
||||
private static void SpawnFlare()
|
||||
{
|
||||
var flare = new Weapon("weapon_flare", shadowBarrier.Position, 1);
|
||||
flare.SetPositionWithSnap(shadowBarrier.Position);
|
||||
|
||||
// The purpose of this fiber is to allow the flare to spawn and fall to the ground naturally before freezing its position because you can't spawn it on the ground gracefully (it stands upright)
|
||||
GameFiber.StartNew(delegate
|
||||
{
|
||||
GameFiber.Sleep(1000);
|
||||
flare.IsPositionFrozen = true;
|
||||
flare.IsCollisionEnabled = false;
|
||||
});
|
||||
|
||||
barriers.Add(flare);
|
||||
removeBarrierOptions.Enabled = true;
|
||||
}
|
||||
|
||||
//------------ CREDIT PNWPARKS FOR THESE FUNCTIONS ------------\\
|
||||
// Implement Parks's 'Get Point Player is Looking At' script for better placement in 3rd person https://bitbucket.org/snippets/gtaparks/MeBKxX
|
||||
internal static Vector3 GetPlayerLookingDirection(out Vector3 camPosition)
|
||||
{
|
||||
if (Camera.RenderingCamera)
|
||||
{
|
||||
camPosition = Camera.RenderingCamera.Position;
|
||||
return Camera.RenderingCamera.Direction;
|
||||
}
|
||||
else
|
||||
{
|
||||
float pitch = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_PITCH<float>();
|
||||
float heading = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_HEADING<float>();
|
||||
|
||||
camPosition = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_COORD<Vector3>();
|
||||
return (Game.LocalPlayer.Character.Rotation + new Rotator(pitch, 0, heading)).ToVector().ToNormalized();
|
||||
}
|
||||
}
|
||||
|
||||
internal static Vector3 GetPlayerLookingDirection() => GetPlayerLookingDirection(out Vector3 v1);
|
||||
|
||||
internal static HitResult TracePlayerView(out Vector3 start, out Vector3 end, float maxTraceDistance, TraceFlags flags)
|
||||
{
|
||||
Vector3 direction = GetPlayerLookingDirection(out start);
|
||||
end = start + (maxTraceDistance * direction);
|
||||
return World.TraceLine(start, end, flags);
|
||||
}
|
||||
|
||||
internal static HitResult TracePlayerView(float maxTraceDistance = 15f, TraceFlags flags = TraceFlags.IntersectEverything) => TracePlayerView(out Vector3 v1, out Vector3 v2, maxTraceDistance, flags);
|
||||
//------------ CREDIT PNWPARKS FOR THESE FUNCTIONS ------------\\
|
||||
}
|
||||
}
|
||||
75
SceneManager/Menus/EditPathMenu.cs
Normal file
75
SceneManager/Menus/EditPathMenu.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using System.Drawing;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
|
||||
namespace SceneManager
|
||||
{
|
||||
class EditPathMenu
|
||||
{
|
||||
private static UIMenuItem editPathWaypoints, deletePath;
|
||||
public static UIMenuCheckboxItem togglePath, debugGraphics;
|
||||
|
||||
public static void BuildEditPathMenu()
|
||||
{
|
||||
MenuManager.editPathMenu.AddItem(togglePath = new UIMenuCheckboxItem("Disable Path", false));
|
||||
MenuManager.editPathMenu.AddItem(editPathWaypoints = new UIMenuItem("Edit Waypoints"));
|
||||
MenuManager.editPathMenu.AddItem(deletePath = new UIMenuItem("Delete Path"));
|
||||
//MenuManager.editPathMenu.AddItem(debugGraphics = new UIMenuCheckboxItem("Enable Debug Graphics", false));
|
||||
|
||||
MenuManager.editPathMenu.RefreshIndex();
|
||||
MenuManager.editPathMenu.OnItemSelect += EditPath_OnItemSelected;
|
||||
MenuManager.editPathMenu.OnCheckboxChange += EditPath_OnCheckboxChange;
|
||||
}
|
||||
|
||||
private static void EditPath_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index];
|
||||
|
||||
if (selectedItem == editPathWaypoints)
|
||||
{
|
||||
EditWaypointMenu.BuildEditWaypointMenu();
|
||||
}
|
||||
|
||||
if (selectedItem == deletePath)
|
||||
{
|
||||
TrafficMenu.DeletePath(currentPath, currentPath.PathNum - 1, "Single");
|
||||
}
|
||||
}
|
||||
|
||||
private static void EditPath_OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked)
|
||||
{
|
||||
if (checkboxItem == togglePath)
|
||||
{
|
||||
if (togglePath.Checked)
|
||||
{
|
||||
TrafficMenu.paths[TrafficMenu.editPath.Index].PathDisabled = true;
|
||||
Game.LogTrivial($"Path {TrafficMenu.paths[TrafficMenu.editPath.Index].PathNum} disabled.");
|
||||
|
||||
foreach (Waypoint wd in TrafficMenu.paths[TrafficMenu.editPath.Index].Waypoint)
|
||||
{
|
||||
wd.WaypointBlip.Alpha = 0.5f;
|
||||
if (wd.CollectorRadiusBlip)
|
||||
{
|
||||
wd.CollectorRadiusBlip.Alpha = 0.25f;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TrafficMenu.paths[TrafficMenu.editPath.Index].PathDisabled = false;
|
||||
Game.LogTrivial($"Path {TrafficMenu.paths[TrafficMenu.editPath.Index].PathNum} enabled.");
|
||||
|
||||
foreach (Waypoint wd in TrafficMenu.paths[TrafficMenu.editPath.Index].Waypoint)
|
||||
{
|
||||
wd.WaypointBlip.Alpha = 1.0f;
|
||||
if (wd.CollectorRadiusBlip)
|
||||
{
|
||||
wd.CollectorRadiusBlip.Alpha = 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
189
SceneManager/Menus/EditWaypointMenu.cs
Normal file
189
SceneManager/Menus/EditWaypointMenu.cs
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
|
||||
namespace SceneManager
|
||||
{
|
||||
class EditWaypointMenu
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete, clear NUI squiggles
|
||||
private static UIMenuItem editUpdateWaypoint, editRemoveWaypoint;
|
||||
private static UIMenuListItem editWaypoint, changeWaypointType, changeWaypointSpeed, changeCollectorRadius;
|
||||
private static UIMenuCheckboxItem collectorWaypoint, updateWaypointPosition;
|
||||
|
||||
private static List<dynamic> pathWaypoints = new List<dynamic>() { };
|
||||
private static List<dynamic> waypointSpeeds = new List<dynamic>() { 5f, 10f, 15f, 20f, 30f, 40f, 50f, 60f, 70f };
|
||||
private static List<dynamic> waypointTypes = new List<dynamic>() { "Drive To", "Stop" };
|
||||
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 };
|
||||
|
||||
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
|
||||
MenuManager.editWaypointMenu.OnItemSelect -= EditWaypoint_OnItemSelected;
|
||||
MenuManager.editWaypointMenu.OnListChange -= EditWaypoint_OnListChanged;
|
||||
|
||||
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index];
|
||||
//var currentWaypoint = currentPath.WaypointData[editWaypoint.Index]; // Can't use this before the menu is created, will this be a problem elsewhere?
|
||||
|
||||
// Populating menu list so user can select which waypoint to edit by index
|
||||
pathWaypoints.Clear();
|
||||
for (int i = 0; i < currentPath.Waypoint.Count; i++)
|
||||
{
|
||||
pathWaypoints.Add(i + 1);
|
||||
}
|
||||
|
||||
MenuManager.editWaypointMenu.Clear();
|
||||
MenuManager.editWaypointMenu.AddItem(editWaypoint = new UIMenuListItem("Edit Waypoint", pathWaypoints, 0));
|
||||
MenuManager.editWaypointMenu.AddItem(changeWaypointType = new UIMenuListItem("Change Waypoint Type", waypointTypes, Array.IndexOf(drivingFlags, currentPath.Waypoint[editWaypoint.Index].DrivingFlag)));
|
||||
MenuManager.editWaypointMenu.AddItem(changeWaypointSpeed = new UIMenuListItem("Change Waypoint Speed", waypointSpeeds, waypointSpeeds.IndexOf(currentPath.Waypoint[editWaypoint.Index].Speed)));
|
||||
MenuManager.editWaypointMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Collector Waypoint", TrafficMenu.paths[TrafficMenu.editPath.Index].Waypoint[editWaypoint.Index].Collector));
|
||||
MenuManager.editWaypointMenu.AddItem(changeCollectorRadius = new UIMenuListItem("Change Collection Radius", collectorRadii, collectorRadii.IndexOf(currentPath.Waypoint[editWaypoint.Index].CollectorRadius)));
|
||||
MenuManager.editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false));
|
||||
MenuManager.editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint"));
|
||||
MenuManager.editWaypointMenu.AddItem(editRemoveWaypoint = new UIMenuItem("Remove Waypoint"));
|
||||
|
||||
MenuManager.editPathMenu.Visible = false;
|
||||
MenuManager.editWaypointMenu.RefreshIndex();
|
||||
MenuManager.editWaypointMenu.Visible = true;
|
||||
|
||||
MenuManager.editWaypointMenu.OnItemSelect += EditWaypoint_OnItemSelected;
|
||||
MenuManager.editWaypointMenu.OnListChange += EditWaypoint_OnListChanged;
|
||||
}
|
||||
|
||||
private static void EditWaypoint_OnListChanged(UIMenu sender, UIMenuListItem listItem, int index)
|
||||
{
|
||||
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index];
|
||||
var currentWaypoint = currentPath.Waypoint[editWaypoint.Index];
|
||||
|
||||
if (listItem == editWaypoint)
|
||||
{
|
||||
while (MenuManager.editWaypointMenu.MenuItems.Count > 1)
|
||||
{
|
||||
MenuManager.editWaypointMenu.RemoveItemAt(1);
|
||||
GameFiber.Yield();
|
||||
}
|
||||
|
||||
MenuManager.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)));
|
||||
MenuManager.editWaypointMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Attractor Waypoint", currentWaypoint.Collector));
|
||||
MenuManager.editWaypointMenu.AddItem(changeCollectorRadius = new UIMenuListItem("Change Collection Radius", collectorRadii, collectorRadii.IndexOf(currentPath.Waypoint[editWaypoint.Index].CollectorRadius)));
|
||||
MenuManager.editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false));
|
||||
MenuManager.editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint"));
|
||||
MenuManager.editWaypointMenu.AddItem(editRemoveWaypoint = new UIMenuItem("Remove Waypoint"));
|
||||
MenuManager.editWaypointMenu.RefreshIndex();
|
||||
}
|
||||
}
|
||||
|
||||
// Crashed here updating waypoint position for waypoint 2/2
|
||||
private static void EditWaypoint_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
var currentPath = TrafficMenu.paths[TrafficMenu.editPath.Index];
|
||||
var currentWaypoint = currentPath.Waypoint[editWaypoint.Index];
|
||||
|
||||
if (selectedItem == editUpdateWaypoint)
|
||||
{
|
||||
currentWaypoint.DrivingFlag = drivingFlags[changeWaypointType.Index];
|
||||
currentWaypoint.Speed = waypointSpeeds[changeWaypointSpeed.Index];
|
||||
if (updateWaypointPosition.Checked)
|
||||
{
|
||||
currentWaypoint.WaypointPos = Game.LocalPlayer.Character.Position;
|
||||
currentWaypoint.WaypointBlip.Position = Game.LocalPlayer.Character.Position;
|
||||
if (currentWaypoint.CollectorRadiusBlip)
|
||||
{
|
||||
currentWaypoint.CollectorRadiusBlip.Position = Game.LocalPlayer.Character.Position;
|
||||
}
|
||||
}
|
||||
|
||||
if (collectorWaypoint.Checked)
|
||||
{
|
||||
currentWaypoint.Collector = true;
|
||||
var yieldZone = World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, currentWaypoint.Speed);
|
||||
currentWaypoint.YieldZone = yieldZone;
|
||||
if (currentWaypoint.CollectorRadiusBlip)
|
||||
{
|
||||
//currentWaypoint.CollectorRadiusBlip.Color = currentWaypoint.WaypointBlip.Color;
|
||||
currentWaypoint.CollectorRadiusBlip.Alpha = 0.5f;
|
||||
currentWaypoint.CollectorRadiusBlip.Scale = collectorRadii[changeCollectorRadius.Index];
|
||||
}
|
||||
else
|
||||
{
|
||||
currentWaypoint.CollectorRadiusBlip = new Blip(currentWaypoint.WaypointBlip.Position, collectorRadii[changeCollectorRadius.Index])
|
||||
{
|
||||
Color = currentWaypoint.WaypointBlip.Color,
|
||||
Alpha = 0.5f
|
||||
};
|
||||
}
|
||||
currentWaypoint.CollectorRadius = collectorRadii[changeCollectorRadius.Index];
|
||||
}
|
||||
else
|
||||
{
|
||||
currentWaypoint.Collector = false;
|
||||
World.RemoveSpeedZone(currentWaypoint.YieldZone);
|
||||
currentWaypoint.YieldZone = 0;
|
||||
if (currentWaypoint.CollectorRadiusBlip)
|
||||
{
|
||||
//currentWaypoint.CollectorRadiusBlip.Color = currentWaypoint.WaypointBlip.Color;
|
||||
currentWaypoint.CollectorRadiusBlip.Alpha = 0.25f;
|
||||
}
|
||||
}
|
||||
Game.LogTrivial($"Updated path {currentPath.PathNum} waypoint {currentWaypoint.WaypointNum}: Driving flag is {drivingFlags[changeWaypointType.Index].ToString()}, speed is {waypointSpeeds[changeWaypointSpeed.Index].ToString()}, collector is {currentWaypoint.Collector}");
|
||||
|
||||
if (currentPath.Waypoint.Count < 2 && currentPath.Waypoint[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination)
|
||||
{
|
||||
Game.LogTrivial($"The remaining waypoint was updated to be a stop waypoint. Enabling/disabling the path is no longer locked.");
|
||||
EditPathMenu.togglePath.Enabled = true;
|
||||
}
|
||||
|
||||
Game.DisplayNotification($"~o~Scene Manager\n~g~[Success]~w~ Waypoint {currentWaypoint.WaypointNum} updated.");
|
||||
}
|
||||
|
||||
if (selectedItem == editRemoveWaypoint)
|
||||
{
|
||||
Game.LogTrivial($"[Path {currentPath.PathNum}] Waypoint {currentWaypoint.WaypointNum} ({currentWaypoint.DrivingFlag}) removed");
|
||||
if (currentPath.Waypoint.Count == 1)
|
||||
{
|
||||
Game.LogTrivial($"Deleting the last waypoint from the path.");
|
||||
TrafficMenu.DeletePath(currentPath, currentPath.PathNum - 1, "Single");
|
||||
//pathWaypoints.Clear();
|
||||
//editPathMenu.Clear();
|
||||
MenuManager.editWaypointMenu.Visible = false;
|
||||
MenuManager.pathMenu.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentWaypoint.WaypointBlip.Delete(); // Delete the waypoint's blip
|
||||
if (currentWaypoint.CollectorRadiusBlip)
|
||||
{
|
||||
currentWaypoint.CollectorRadiusBlip.Delete();
|
||||
}
|
||||
currentPath.Waypoint.Remove(currentWaypoint); // Delete the waypoint's data object
|
||||
pathWaypoints.RemoveAt(editWaypoint.Index); // Remove the waypoint from the menu list
|
||||
|
||||
// Will this have adverse affects on vehicles currently following the path?
|
||||
// Update waypoint number for each waypoint in the path's waypoint data
|
||||
foreach (Waypoint wp in currentPath.Waypoint)
|
||||
{
|
||||
wp.WaypointNum = currentPath.Waypoint.IndexOf(wp) + 1;
|
||||
Game.LogTrivial($"Waypoint at index {currentPath.Waypoint.IndexOf(wp)} is now waypoint #{wp.WaypointNum}");
|
||||
}
|
||||
|
||||
BuildEditWaypointMenu();
|
||||
|
||||
if (currentPath.Waypoint.Count == 1 && currentPath.Waypoint[0].DrivingFlag != VehicleDrivingFlags.StopAtDestination)
|
||||
{
|
||||
Game.LogTrivial($"The path only has 1 waypoint left, and the waypoint is not a stop waypoint. Disabling the path.");
|
||||
currentPath.PathDisabled = true;
|
||||
EditPathMenu.togglePath.Checked = true;
|
||||
EditPathMenu.togglePath.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
SceneManager/Menus/MainMenu.cs
Normal file
37
SceneManager/Menus/MainMenu.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
|
||||
namespace SceneManager
|
||||
{
|
||||
class MainMenu
|
||||
{
|
||||
private static UIMenuItem navigateToPathMenu, navigateToBarrierMenu, navigateToSettingsMenu;
|
||||
|
||||
public static void BuildMainMenu()
|
||||
{
|
||||
MenuManager.mainMenu.AddItem(navigateToPathMenu = new UIMenuItem("~o~Path Menu"));
|
||||
MenuManager.mainMenu.BindMenuToItem(MenuManager.pathMenu, navigateToPathMenu);
|
||||
MenuManager.mainMenu.AddItem(navigateToBarrierMenu = new UIMenuItem("~o~Barrier Menu"));
|
||||
MenuManager.mainMenu.BindMenuToItem(MenuManager.barrierMenu, navigateToBarrierMenu);
|
||||
MenuManager.mainMenu.AddItem(navigateToSettingsMenu = new UIMenuItem("~o~Settings"));
|
||||
MenuManager.mainMenu.BindMenuToItem(MenuManager.settingsMenu, navigateToSettingsMenu);
|
||||
|
||||
MenuManager.mainMenu.RefreshIndex();
|
||||
MenuManager.mainMenu.OnItemSelect += MainMenu_OnItemSelected;
|
||||
}
|
||||
|
||||
private static void MainMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
if (selectedItem == navigateToBarrierMenu)
|
||||
{
|
||||
BarrierMenu.CreateShadowBarrier(MenuManager.barrierMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
241
SceneManager/Menus/PathCreationMenu.cs
Normal file
241
SceneManager/Menus/PathCreationMenu.cs
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
|
||||
namespace SceneManager
|
||||
{
|
||||
class PathCreationMenu
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete, clear NUI squiggles
|
||||
public static UIMenuItem trafficAddWaypoint, trafficRemoveWaypoint, trafficEndPath;
|
||||
public static UIMenuListItem waypointType, waypointSpeed, collectorRadius;
|
||||
private static UIMenuCheckboxItem collectorWaypoint;
|
||||
|
||||
private static List<dynamic> waypointSpeeds = new List<dynamic>() { 5f, 10f, 15f, 20f, 30f, 40f, 50f, 60f, 70f };
|
||||
//private enum waypointTypes {DriveTo, Stop };
|
||||
private static List<dynamic> waypointTypes = new List<dynamic>() { "Drive To", "Stop" };
|
||||
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
|
||||
|
||||
// Called from EditPathMenu
|
||||
public static void BuildPathCreationMenu()
|
||||
{
|
||||
MenuManager.pathCreationMenu.AddItem(waypointType = new UIMenuListItem("Waypoint Type", waypointTypes, 0));
|
||||
MenuManager.pathCreationMenu.AddItem(waypointSpeed = new UIMenuListItem($"Waypoint Speed (in {SettingsMenu.speedUnits.SelectedItem})", waypointSpeeds, 0));
|
||||
MenuManager.pathCreationMenu.AddItem(collectorWaypoint = new UIMenuCheckboxItem("Collector", false));
|
||||
MenuManager.pathCreationMenu.AddItem(collectorRadius = new UIMenuListItem("Collection Radius", collectorRadii, 0));
|
||||
MenuManager.pathCreationMenu.AddItem(trafficAddWaypoint = new UIMenuItem("Add waypoint"));
|
||||
MenuManager.pathCreationMenu.AddItem(trafficRemoveWaypoint = new UIMenuItem("Remove last waypoint"));
|
||||
trafficRemoveWaypoint.Enabled = false;
|
||||
MenuManager.pathCreationMenu.AddItem(trafficEndPath = new UIMenuItem("End path creation"));
|
||||
|
||||
MenuManager.pathCreationMenu.RefreshIndex();
|
||||
MenuManager.pathCreationMenu.OnItemSelect += PathCreation_OnItemSelected;
|
||||
}
|
||||
|
||||
private static void PathCreation_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
// Do I need to implement a distance restriction? Idiots place waypoints unnecessarily close, possibly causing AI to drive in circles
|
||||
if (selectedItem == trafficAddWaypoint)
|
||||
{
|
||||
uint yieldZone = 0;
|
||||
float speed;
|
||||
|
||||
// Loop through each path and find the first one which isn't finished
|
||||
var getFirstNonNullPath = TrafficMenu.paths.Where(p => p != null && !p.PathFinished).First();
|
||||
var pathIndex = TrafficMenu.paths.IndexOf(getFirstNonNullPath);
|
||||
|
||||
// Create a waypoint blip and set the sprite based on the current path number
|
||||
var blip = new Blip(Game.LocalPlayer.Character.Position)
|
||||
{
|
||||
Scale = 0.5f
|
||||
};
|
||||
switch (pathIndex)
|
||||
{
|
||||
case 0:
|
||||
blip.Sprite = BlipSprite.Numbered1;
|
||||
break;
|
||||
case 1:
|
||||
blip.Sprite = BlipSprite.Numbered2;
|
||||
break;
|
||||
case 2:
|
||||
blip.Sprite = BlipSprite.Numbered3;
|
||||
break;
|
||||
case 3:
|
||||
blip.Sprite = BlipSprite.Numbered4;
|
||||
break;
|
||||
case 4:
|
||||
blip.Sprite = BlipSprite.Numbered5;
|
||||
break;
|
||||
case 5:
|
||||
blip.Sprite = BlipSprite.Numbered6;
|
||||
break;
|
||||
case 6:
|
||||
blip.Sprite = BlipSprite.Numbered7;
|
||||
break;
|
||||
case 7:
|
||||
blip.Sprite = BlipSprite.Numbered8;
|
||||
break;
|
||||
}
|
||||
|
||||
// If it's the first waypoint, make the blip orange, else make it yellow
|
||||
if (TrafficMenu.paths[pathIndex].Waypoint.Count == 0)
|
||||
{
|
||||
blip.Color = Color.Orange;
|
||||
}
|
||||
else
|
||||
{
|
||||
blip.Color = Color.Yellow;
|
||||
}
|
||||
|
||||
if (collectorWaypoint.Checked)
|
||||
{
|
||||
if(SettingsMenu.speedUnits.SelectedItem == SettingsMenu.SpeedUnitsOfMeasure.MPH)
|
||||
{
|
||||
yieldZone = World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index]));
|
||||
}
|
||||
else
|
||||
{
|
||||
yieldZone = World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index]));
|
||||
}
|
||||
}
|
||||
|
||||
if(SettingsMenu.speedUnits.SelectedItem == SettingsMenu.SpeedUnitsOfMeasure.MPH)
|
||||
{
|
||||
Game.LogTrivial($"Original speed: {waypointSpeeds[waypointSpeed.Index]}{SettingsMenu.speedUnits.SelectedItem}");
|
||||
speed = MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index]);
|
||||
Game.LogTrivial($"Converted speed: {speed}m/s");
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.LogTrivial($"Original speed: {waypointSpeeds[waypointSpeed.Index]}{SettingsMenu.speedUnits.SelectedItem}");
|
||||
speed = MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index]);
|
||||
Game.LogTrivial($"Converted speed: {speed}m/s");
|
||||
}
|
||||
|
||||
// Add the waypoint data to the path
|
||||
TrafficMenu.paths[pathIndex].Waypoint.Add(new Waypoint(pathIndex + 1, TrafficMenu.paths[pathIndex].Waypoint.Count + 1, Game.LocalPlayer.Character.Position, speed, drivingFlags[waypointType.Index], blip, collectorWaypoint.Checked, collectorRadii[collectorRadius.Index], yieldZone));
|
||||
Game.LogTrivial($"[Path {pathIndex + 1}] Waypoint {TrafficMenu.paths[pathIndex].Waypoint[TrafficMenu.paths[pathIndex].Waypoint.Count - 1].WaypointNum} ({drivingFlags[waypointType.Index].ToString()}) added");
|
||||
|
||||
// Refresh the trafficMenu after a waypoint is added in order to show Continue Creating Current Path instead of Create New Path
|
||||
RefreshTrafficMenu();
|
||||
}
|
||||
|
||||
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 < TrafficMenu.paths.Count; i++)
|
||||
{
|
||||
if (TrafficMenu.paths.ElementAtOrDefault(i) != null && !TrafficMenu.paths[i].PathFinished)
|
||||
{
|
||||
Game.LogTrivial($"[Path {i + 1}] {TrafficMenu.paths[i].Waypoint.Last().DrivingFlag.ToString()} waypoint removed");
|
||||
TrafficMenu.paths[i].Waypoint.Last().WaypointBlip.Delete();
|
||||
if (TrafficMenu.paths[i].Waypoint.Last().CollectorRadiusBlip)
|
||||
{
|
||||
TrafficMenu.paths[i].Waypoint.Last().CollectorRadiusBlip.Delete();
|
||||
}
|
||||
TrafficMenu.paths[i].Waypoint.RemoveAt(TrafficMenu.paths[i].Waypoint.IndexOf(TrafficMenu.paths[i].Waypoint.Last()));
|
||||
|
||||
// If the path has no waypoints, disable the menu option to remove a waypoint
|
||||
if (TrafficMenu.paths[i].Waypoint.Count == 0)
|
||||
{
|
||||
trafficRemoveWaypoint.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedItem == trafficEndPath)
|
||||
{
|
||||
// Loop through each path and find the first one which isn't finished
|
||||
for (int i = 0; i < TrafficMenu.paths.Count; i++)
|
||||
{
|
||||
if (TrafficMenu.paths.ElementAtOrDefault(i) != null && !TrafficMenu.paths[i].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 (TrafficMenu.paths[i].Waypoint.Count >= 2 || (TrafficMenu.paths[i].Waypoint.Count == 1 && TrafficMenu.paths[i].Waypoint[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination))
|
||||
{
|
||||
Game.LogTrivial($"[Path Creation] Path {i + 1} finished with {TrafficMenu.paths[i].Waypoint.Count} waypoints.");
|
||||
Game.DisplayNotification($"~o~Scene Manager\n~g~[Success]~w~ Path {i + 1} complete.");
|
||||
TrafficMenu.paths[i].Waypoint.Last().WaypointBlip.Color = Color.OrangeRed;
|
||||
if (TrafficMenu.paths[i].Waypoint.Last().CollectorRadiusBlip)
|
||||
{
|
||||
TrafficMenu.paths[i].Waypoint.Last().CollectorRadiusBlip.Color = Color.OrangeRed;
|
||||
}
|
||||
TrafficMenu.paths[i].PathFinished = true;
|
||||
TrafficMenu.paths[i].PathDisabled = false;
|
||||
TrafficMenu.paths[i].PathNum = i + 1;
|
||||
TrafficMenu.pathsNum.Insert(i, TrafficMenu.paths[i].PathNum);
|
||||
|
||||
//GameFiber InitialWaypointVehicleCollectorFiber = new GameFiber(() => TrafficPathing.InitialWaypointVehicleCollector(paths[i]));
|
||||
//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
|
||||
foreach (Waypoint wd in TrafficMenu.paths[i].Waypoint)
|
||||
{
|
||||
GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => TrafficPathing.WaypointVehicleCollector(TrafficMenu.paths, TrafficMenu.paths[i], wd));
|
||||
WaypointVehicleCollectorFiber.Start();
|
||||
|
||||
GameFiber AssignStopForVehiclesFlagFiber = new GameFiber(() => TrafficPathing.AssignStopForVehiclesFlag(TrafficMenu.paths, TrafficMenu.paths[i], wd));
|
||||
AssignStopForVehiclesFlagFiber.Start();
|
||||
}
|
||||
|
||||
MenuManager.menuPool.CloseAllMenus();
|
||||
MenuManager.pathMenu.Clear();
|
||||
TrafficMenu.BuildPathMenu();
|
||||
MenuManager.pathMenu.Visible = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
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.");
|
||||
foreach (Waypoint wd in TrafficMenu.paths[i].Waypoint)
|
||||
{
|
||||
wd.WaypointBlip.Delete();
|
||||
if (wd.CollectorRadiusBlip)
|
||||
{
|
||||
wd.CollectorRadiusBlip.Delete();
|
||||
}
|
||||
}
|
||||
TrafficMenu.paths[i].Waypoint.Clear();
|
||||
TrafficMenu.paths.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// "Refresh" the menu to reflect the new path
|
||||
//TrafficMenu.RebuildTrafficMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private static void RefreshTrafficMenu()
|
||||
{
|
||||
trafficRemoveWaypoint.Enabled = true;
|
||||
MenuManager.pathMenu.Clear();
|
||||
MenuManager.pathMenu.AddItem(TrafficMenu.createNewPath = new UIMenuItem("Continue Creating Current Path"));
|
||||
MenuManager.pathMenu.AddItem(TrafficMenu.deleteAllPaths = new UIMenuItem("Delete All Paths"));
|
||||
MenuManager.pathMenu.AddItem(TrafficMenu.directDriver = new UIMenuListItem("Direct nearest driver to path", TrafficMenu.pathsNum, 0));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
374
SceneManager/Menus/TrafficMenu.cs
Normal file
374
SceneManager/Menus/TrafficMenu.cs
Normal file
|
|
@ -0,0 +1,374 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Rage;
|
||||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
|
||||
namespace SceneManager
|
||||
{
|
||||
static class TrafficMenu
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete, clear NUI squiggles
|
||||
public static UIMenuItem createNewPath, deleteAllPaths;
|
||||
public static UIMenuListItem editPath, directDriver, dismissDriver;
|
||||
public static UIMenuCheckboxItem disableAllPaths;
|
||||
|
||||
public static List<dynamic> pathsNum = new List<dynamic>() { };
|
||||
public static List<Path> paths = new List<Path>() { };
|
||||
public static List<dynamic> dismissOptions = new List<dynamic>() { "From path", "From waypoint", "From position" };
|
||||
|
||||
public static void BuildPathMenu()
|
||||
{
|
||||
// New stuff to mitigate Rebuild method
|
||||
MenuManager.pathMenu.OnItemSelect -= PathMenu_OnItemSelected;
|
||||
MenuManager.pathMenu.OnCheckboxChange -= PathMenu_OnCheckboxChange;
|
||||
MenuManager.menuPool.CloseAllMenus();
|
||||
MenuManager.pathMenu.Clear();
|
||||
|
||||
MenuManager.pathMenu.AddItem(createNewPath = new UIMenuItem("Create New Path"));
|
||||
MenuManager.pathMenu.AddItem(editPath = new UIMenuListItem("Edit Path", pathsNum, 0));
|
||||
MenuManager.pathMenu.AddItem(disableAllPaths = new UIMenuCheckboxItem("Disable All Paths", false));
|
||||
MenuManager.pathMenu.AddItem(deleteAllPaths = new UIMenuItem("Delete All Paths"));
|
||||
MenuManager.pathMenu.AddItem(directDriver = new UIMenuListItem("Direct nearest driver to path", pathsNum, 0));
|
||||
MenuManager.pathMenu.AddItem(dismissDriver = new UIMenuListItem("Dismiss nearest driver", dismissOptions, 0));
|
||||
|
||||
if (paths.Count == 8)
|
||||
{
|
||||
createNewPath.Enabled = false;
|
||||
}
|
||||
if (paths.Count == 0)
|
||||
{
|
||||
editPath.Enabled = false;
|
||||
deleteAllPaths.Enabled = false;
|
||||
disableAllPaths.Enabled = false;
|
||||
directDriver.Enabled = false;
|
||||
}
|
||||
|
||||
MenuManager.pathMenu.RefreshIndex();
|
||||
MenuManager.pathMenu.OnItemSelect += PathMenu_OnItemSelected;
|
||||
MenuManager.pathMenu.OnCheckboxChange += PathMenu_OnCheckboxChange;
|
||||
|
||||
// New stuff to mitigate Rebuild method
|
||||
MenuManager.menuPool.RefreshIndex();
|
||||
}
|
||||
|
||||
private static bool VehicleAndDriverValid(this Vehicle v)
|
||||
{
|
||||
if (v && v.HasDriver && v.Driver && v.Driver.IsAlive)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsInCollectedVehicles(this Vehicle v)
|
||||
{
|
||||
if (v && TrafficPathing.collectedVehicles.ContainsKey(v.LicensePlate))
|
||||
{
|
||||
Game.LogTrivial($"{v.Model.Name} was found in the collection.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.LogTrivial($"{v.Model.Name} was not found in the collection.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Refactor string param to enum
|
||||
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
|
||||
//Game.LogTrivial($"Deleting path {index+1}");
|
||||
Game.LogTrivial($"Deleting path {path.PathNum}");
|
||||
var pathVehicles = TrafficPathing.collectedVehicles.Where(cv => cv.Value.Path == path.PathNum).ToList();
|
||||
|
||||
Game.LogTrivial($"Removing all vehicles on the path");
|
||||
foreach (KeyValuePair<string, ControlledVehicle> cv in pathVehicles.Where(cv => cv.Value.Vehicle && cv.Value.Vehicle.Driver))
|
||||
{
|
||||
cv.Value.DismissNow = true;
|
||||
cv.Value.Vehicle.Driver.Tasks.Clear();
|
||||
cv.Value.Vehicle.Driver.Dismiss();
|
||||
cv.Value.Vehicle.Driver.IsPersistent = false;
|
||||
cv.Value.Vehicle.Dismiss();
|
||||
cv.Value.Vehicle.IsPersistent = false;
|
||||
//TrafficPathing.ControlledVehicles.Remove(cv.Value.LicensePlate);
|
||||
//Game.LogTrivial($"{cv.vehicle.Model.Name} cleared from path {cv.path}");
|
||||
TrafficPathing.collectedVehicles.Remove(cv.Value.LicensePlate);
|
||||
}
|
||||
|
||||
// Remove the speed zone so cars don't continue to be affected after the path is deleted
|
||||
Game.LogTrivial($"Removing yield zone and waypoint blips");
|
||||
foreach (Waypoint wd in path.Waypoint)
|
||||
{
|
||||
if (wd.YieldZone != 0)
|
||||
{
|
||||
World.RemoveSpeedZone(wd.YieldZone);
|
||||
}
|
||||
if (wd.WaypointBlip)
|
||||
{
|
||||
wd.WaypointBlip.Delete();
|
||||
}
|
||||
if (wd.CollectorRadiusBlip)
|
||||
{
|
||||
wd.CollectorRadiusBlip.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
Game.LogTrivial($"Clearing path.WaypointData");
|
||||
path.Waypoint.Clear();
|
||||
// Manipulating the menu to reflect specific paths being deleted
|
||||
if (pathsToDelete == "Single")
|
||||
{
|
||||
paths.RemoveAt(index);
|
||||
//Game.LogTrivial("pathsNum count: " + pathsNum.Count);
|
||||
//Game.LogTrivial("index: " + index);
|
||||
pathsNum.RemoveAt(index);
|
||||
//RebuildTrafficMenu();
|
||||
BuildPathMenu();
|
||||
MenuManager.pathMenu.Visible = true;
|
||||
Game.LogTrivial($"Path {path.PathNum} deleted.");
|
||||
Game.DisplayNotification($"~o~Scene Manager\n~w~Path {path.PathNum} deleted.");
|
||||
}
|
||||
|
||||
MenuManager.editPathMenu.Reset(true, true);
|
||||
EditPathMenu.togglePath.Enabled = true;
|
||||
}
|
||||
|
||||
private static void PathMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index)
|
||||
{
|
||||
if (selectedItem == createNewPath)
|
||||
{
|
||||
MenuManager.pathMenu.Visible = false;
|
||||
MenuManager.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 (int i = 0; i <= paths.Count; i++)
|
||||
{
|
||||
if (paths.ElementAtOrDefault(i) != null && paths[i].PathFinished == false)
|
||||
{
|
||||
//Game.LogTrivial($"pathFinished: {paths[i].PathFinished}");
|
||||
Game.LogTrivial($"Resuming path {i + 1}");
|
||||
Game.DisplayNotification($"~o~Scene Manager\n~y~[Creating]~w~ Resuming path {i + 1}");
|
||||
break;
|
||||
}
|
||||
else if (paths.ElementAtOrDefault(i) == null)
|
||||
{
|
||||
Game.LogTrivial($"Creating path {i + 1}");
|
||||
Game.DisplayNotification($"~o~Scene Manager\n~y~[Creating]~w~ Path {i + 1} started.");
|
||||
paths.Insert(i, new Path(i + 1, false));
|
||||
PathCreationMenu.trafficRemoveWaypoint.Enabled = false;
|
||||
|
||||
if (SettingsMenu.debugGraphics.Checked)
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
while (SettingsMenu.debugGraphics.Checked && paths[i] != null)
|
||||
{
|
||||
for (int j = 0; j < paths[i].Waypoint.Count; j++)
|
||||
{
|
||||
if (paths[i].Waypoint[j].Collector)
|
||||
{
|
||||
Debug.DrawSphere(paths[i].Waypoint[j].WaypointPos, paths[i].Waypoint[j].CollectorRadius, Color.FromArgb(80, Color.Blue));
|
||||
}
|
||||
else if (paths[i].Waypoint[j].DrivingFlag == VehicleDrivingFlags.StopAtDestination)
|
||||
{
|
||||
Debug.DrawSphere(paths[i].Waypoint[j].WaypointPos, 1f, Color.FromArgb(80, Color.Red));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.DrawSphere(paths[i].Waypoint[j].WaypointPos, 1f, Color.FromArgb(80, Color.Green));
|
||||
}
|
||||
|
||||
if (j != paths[i].Waypoint.Count - 1)
|
||||
{
|
||||
Debug.DrawLine(paths[i].Waypoint[j].WaypointPos, paths[i].Waypoint[j + 1].WaypointPos, Color.White);
|
||||
}
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedItem == editPath)
|
||||
{
|
||||
MenuManager.pathMenu.Visible = false;
|
||||
MenuManager.editPathMenu.Visible = true;
|
||||
}
|
||||
|
||||
if (selectedItem == deleteAllPaths)
|
||||
{
|
||||
// Iterate through each item in paths and delete it
|
||||
for (int i = 0; i < paths.Count; i++)
|
||||
{
|
||||
DeletePath(paths[i], i, "All");
|
||||
}
|
||||
foreach (Path path in paths)
|
||||
{
|
||||
path.Waypoint.Clear();
|
||||
}
|
||||
paths.Clear();
|
||||
pathsNum.Clear();
|
||||
//RebuildTrafficMenu();
|
||||
BuildPathMenu();
|
||||
MenuManager.pathMenu.Visible = true;
|
||||
Game.LogTrivial($"All paths deleted");
|
||||
Game.DisplayNotification($"~o~Scene Manager\n~w~All paths deleted.");
|
||||
}
|
||||
|
||||
if (selectedItem == directDriver)
|
||||
{
|
||||
var nearbyVehicle = Game.LocalPlayer.Character.GetNearbyVehicles(1).Where(v => v.VehicleAndDriverValid()).SingleOrDefault();
|
||||
if (nearbyVehicle)
|
||||
{
|
||||
if (nearbyVehicle.IsInCollectedVehicles())
|
||||
{
|
||||
var vehicle = TrafficPathing.collectedVehicles[nearbyVehicle.LicensePlate];
|
||||
|
||||
Game.LogTrivial($"[Direct Driver] {nearbyVehicle.Model.Name} already in collection. Clearing tasks.");
|
||||
nearbyVehicle.Driver.Tasks.Clear();
|
||||
vehicle.Path = paths[directDriver.Index].Waypoint[0].Path;
|
||||
vehicle.TotalWaypoints = paths[directDriver.Index].Waypoint.Count;
|
||||
vehicle.CurrentWaypoint = 1;
|
||||
vehicle.DismissNow = true;
|
||||
vehicle.StoppedAtWaypoint = false;
|
||||
vehicle.Redirected = true;
|
||||
GameFiber DirectTaskFiber = new GameFiber(() => TrafficPathing.DirectTask(vehicle, paths[directDriver.Index].Waypoint));
|
||||
DirectTaskFiber.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
TrafficPathing.collectedVehicles.Add(nearbyVehicle.LicensePlate, new ControlledVehicle(nearbyVehicle, nearbyVehicle.LicensePlate, paths[directDriver.Index].Waypoint[0].Path, paths[directDriver.Index].Waypoint.Count, 1, false, false, true));
|
||||
Game.LogTrivial($"[Direct Driver] {nearbyVehicle.Model.Name} not in collection, adding to collection for path {paths[directDriver.Index].Waypoint[0].Path} with {paths[directDriver.Index].Waypoint.Count} waypoints");
|
||||
|
||||
GameFiber DirectTaskFiber = new GameFiber(() => TrafficPathing.DirectTask(TrafficPathing.collectedVehicles[nearbyVehicle.LicensePlate], paths[directDriver.Index].Waypoint));
|
||||
DirectTaskFiber.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedItem == dismissDriver)
|
||||
{
|
||||
var nearbyVehicle = Game.LocalPlayer.Character.GetNearbyVehicles(1).Where(v => v.VehicleAndDriverValid()).SingleOrDefault();
|
||||
if (nearbyVehicle)
|
||||
{
|
||||
switch (dismissDriver.Index)
|
||||
{
|
||||
case 0:
|
||||
Game.LogTrivial($"Dismiss from path");
|
||||
if (nearbyVehicle.IsInCollectedVehicles())
|
||||
{
|
||||
var controlledVehicle = TrafficPathing.collectedVehicles[nearbyVehicle.LicensePlate];
|
||||
controlledVehicle.DismissNow = true;
|
||||
controlledVehicle.Vehicle.Driver.Tasks.Clear();
|
||||
controlledVehicle.Vehicle.Driver.Dismiss();
|
||||
Game.LogTrivial($"Dismissed driver of {controlledVehicle.Vehicle.Model.Name} from path {controlledVehicle.Path}");
|
||||
}
|
||||
else
|
||||
{
|
||||
goto case 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
Game.LogTrivial($"Dismiss from waypoint");
|
||||
if (nearbyVehicle.IsInCollectedVehicles())
|
||||
{
|
||||
var controlledVehicle = TrafficPathing.collectedVehicles[nearbyVehicle.LicensePlate];
|
||||
controlledVehicle.StoppedAtWaypoint = false;
|
||||
controlledVehicle.Vehicle.Driver.Tasks.Clear();
|
||||
controlledVehicle.Vehicle.Driver.Dismiss();
|
||||
|
||||
if (controlledVehicle.CurrentWaypoint == controlledVehicle.TotalWaypoints && !controlledVehicle.StoppedAtWaypoint)
|
||||
{
|
||||
controlledVehicle.DismissNow = true;
|
||||
Game.LogTrivial($"Dismissed driver of {controlledVehicle.Vehicle.Model.Name} from final waypoint and ultimately the path");
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.LogTrivial($"Dismissed driver of {controlledVehicle.Vehicle.Model.Name} from waypoint {controlledVehicle.CurrentWaypoint}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
goto case 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
Game.LogTrivial($"Dismiss from position");
|
||||
if (nearbyVehicle.IsInCollectedVehicles())
|
||||
{
|
||||
nearbyVehicle.Driver.Tasks.Clear();
|
||||
nearbyVehicle.Driver.Dismiss();
|
||||
Game.LogTrivial($"Dismissed driver of {nearbyVehicle.Model.Name} (in collection)");
|
||||
}
|
||||
else
|
||||
{
|
||||
nearbyVehicle.Driver.Tasks.Clear();
|
||||
nearbyVehicle.Driver.Dismiss();
|
||||
Game.LogTrivial($"Dismissed driver of {nearbyVehicle.Model.Name} (was not in collection)");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Game.LogTrivial($"dismissDriver index was unexpected");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.LogTrivial($"There are no vehicles nearby matching the requirements.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void PathMenu_OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked)
|
||||
{
|
||||
if (checkboxItem == disableAllPaths)
|
||||
{
|
||||
if (disableAllPaths.Checked)
|
||||
{
|
||||
foreach (Path path in paths)
|
||||
{
|
||||
path.PathDisabled = true;
|
||||
foreach (Waypoint waypoint in path.Waypoint)
|
||||
{
|
||||
waypoint.WaypointBlip.Alpha = 0.5f;
|
||||
if (waypoint.CollectorRadiusBlip)
|
||||
{
|
||||
waypoint.CollectorRadiusBlip.Alpha = 0.25f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Game.LogTrivial($"All paths disabled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Path path in paths)
|
||||
{
|
||||
path.PathDisabled = false;
|
||||
foreach (Waypoint waypoint in path.Waypoint)
|
||||
{
|
||||
waypoint.WaypointBlip.Alpha = 1f;
|
||||
if (waypoint.CollectorRadiusBlip)
|
||||
{
|
||||
waypoint.CollectorRadiusBlip.Alpha = 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Game.LogTrivial($"All paths enabled.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue