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

Added separate menu option for collector waypoint speed zone.

This commit is contained in:
Rich Dunne 2020-08-30 10:05:58 -06:00
parent 646498bbc5
commit 54c2bd8c12
3 changed files with 53 additions and 24 deletions

View file

@ -18,8 +18,9 @@ namespace SceneManager
public static UIMenuNumericScrollerItem<int> editWaypoint; public static UIMenuNumericScrollerItem<int> editWaypoint;
private static UIMenuListScrollerItem<string> changeWaypointType = new UIMenuListScrollerItem<string>("New Waypoint Type", "", waypointTypes); private static UIMenuListScrollerItem<string> changeWaypointType = new UIMenuListScrollerItem<string>("New Waypoint Type", "", waypointTypes);
private static UIMenuNumericScrollerItem<int> changeWaypointSpeed; private static UIMenuNumericScrollerItem<int> changeWaypointSpeed;
private static UIMenuNumericScrollerItem<int> changeCollectorRadius = new UIMenuNumericScrollerItem<int>("New Collection Radius", "The distance from this waypoint in meters vehicles will be collected", 1, 50, 1);
private static UIMenuCheckboxItem collectorWaypoint = new UIMenuCheckboxItem("Collector", true, "If this waypoint will collect vehicles to follow the path"); private static UIMenuCheckboxItem collectorWaypoint = new UIMenuCheckboxItem("Collector", true, "If this waypoint will collect vehicles to follow the path");
private static UIMenuNumericScrollerItem<int> changeCollectorRadius = new UIMenuNumericScrollerItem<int>("New Collection Radius", "The distance from this waypoint (in meters) vehicles will be collected", 1, 50, 1);
private static UIMenuNumericScrollerItem<int> changeSpeedZoneRadius = new UIMenuNumericScrollerItem<int>("New Speed Zone Radius", "The distance from this collector waypoint (in meters) non-collected vehicles will drive at this waypoint's speed", 1, 50, 1);
private static UIMenuCheckboxItem updateWaypointPosition; private static UIMenuCheckboxItem updateWaypointPosition;
internal static void InstantiateMenu() internal static void InstantiateMenu()
@ -47,7 +48,6 @@ namespace SceneManager
editWaypointMenu.AddItem(changeWaypointType); editWaypointMenu.AddItem(changeWaypointType);
changeWaypointType.Index = Array.IndexOf(drivingFlags, PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].DrivingFlag); changeWaypointType.Index = Array.IndexOf(drivingFlags, PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].DrivingFlag);
//Game.LogTrivial($"Waypoint speed: {PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed}");
editWaypointMenu.AddItem(changeWaypointSpeed = new UIMenuNumericScrollerItem<int>("New Waypoint Speed", $"How fast the AI will drive to the waypoint in ~b~{SettingsMenu.speedUnits.SelectedItem}", 5, 80, 5)); editWaypointMenu.AddItem(changeWaypointSpeed = new UIMenuNumericScrollerItem<int>("New Waypoint Speed", $"How fast the AI will drive to the waypoint in ~b~{SettingsMenu.speedUnits.SelectedItem}", 5, 80, 5));
changeWaypointSpeed.Value = (int)MathHelper.ConvertMetersPerSecondToMilesPerHour(PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed); changeWaypointSpeed.Value = (int)MathHelper.ConvertMetersPerSecondToMilesPerHour(PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed);
@ -58,6 +58,14 @@ namespace SceneManager
? (int)PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].CollectorRadius ? (int)PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].CollectorRadius
: changeCollectorRadius.Minimum; : changeCollectorRadius.Minimum;
editWaypointMenu.AddItem(changeSpeedZoneRadius);
changeSpeedZoneRadius.Value = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].CollectorRadius != 0
? (int)PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].SpeedZoneRadius
: changeSpeedZoneRadius.Minimum;
changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false;
changeSpeedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false;
editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false)); editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false));
editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint")); editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint"));
editUpdateWaypoint.ForeColor = Color.Gold; editUpdateWaypoint.ForeColor = Color.Gold;
@ -78,10 +86,10 @@ namespace SceneManager
if(scrollerItem == editWaypoint) if(scrollerItem == editWaypoint)
{ {
changeWaypointType.Index = Array.IndexOf(drivingFlags, PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].DrivingFlag); changeWaypointType.Index = Array.IndexOf(drivingFlags, PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].DrivingFlag);
//changeWaypointSpeed.Index = Array.IndexOf(waypointSpeeds, MathHelper.ConvertMetersPerSecondToMilesPerHour(PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed));
changeWaypointSpeed.Value = (int)MathHelper.ConvertMetersPerSecondToMilesPerHour(PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed); changeWaypointSpeed.Value = (int)MathHelper.ConvertMetersPerSecondToMilesPerHour(PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed);
collectorWaypoint.Checked = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].IsCollector; collectorWaypoint.Checked = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].IsCollector;
changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false; changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false;
changeSpeedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false;
} }
} }
@ -90,6 +98,7 @@ namespace SceneManager
if (checkboxItem == collectorWaypoint) if (checkboxItem == collectorWaypoint)
{ {
changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false; changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false;
changeSpeedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false;
} }
} }
@ -100,7 +109,7 @@ namespace SceneManager
if (selectedItem == editUpdateWaypoint) if (selectedItem == editUpdateWaypoint)
{ {
currentWaypoint.UpdateWaypoint(currentWaypoint, drivingFlags[changeWaypointType.Index], SetDriveSpeedForWaypoint(), collectorWaypoint.Checked, changeCollectorRadius.Value, updateWaypointPosition.Checked); currentWaypoint.UpdateWaypoint(currentWaypoint, drivingFlags[changeWaypointType.Index], SetDriveSpeedForWaypoint(), collectorWaypoint.Checked, changeCollectorRadius.Value, changeSpeedZoneRadius.Value, updateWaypointPosition.Checked);
Game.LogTrivial($"Updated path {currentPath.PathNum} waypoint {currentWaypoint.Number}: Driving flag is {drivingFlags[changeWaypointType.Index].ToString()}, speed is {changeWaypointSpeed.Value}, collector is {currentWaypoint.IsCollector}"); Game.LogTrivial($"Updated path {currentPath.PathNum} waypoint {currentWaypoint.Number}: Driving flag is {drivingFlags[changeWaypointType.Index].ToString()}, speed is {changeWaypointSpeed.Value}, collector is {currentWaypoint.IsCollector}");
if (currentPath.Waypoints.Count < 2 && currentPath.Waypoints[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination) if (currentPath.Waypoints.Count < 2 && currentPath.Waypoints[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination)

View file

@ -16,8 +16,9 @@ namespace SceneManager
private static UIMenuItem trafficAddWaypoint, trafficRemoveWaypoint, trafficEndPath; private static UIMenuItem trafficAddWaypoint, trafficRemoveWaypoint, trafficEndPath;
public static UIMenuListScrollerItem<string> waypointType = new UIMenuListScrollerItem<string>("Waypoint Type", "", waypointTypes); public static UIMenuListScrollerItem<string> waypointType = new UIMenuListScrollerItem<string>("Waypoint Type", "", waypointTypes);
private static UIMenuNumericScrollerItem<int> waypointSpeed; private static UIMenuNumericScrollerItem<int> waypointSpeed;
public static UIMenuNumericScrollerItem<int> collectorRadius = new UIMenuNumericScrollerItem<int>("Collection Radius", "The distance from this waypoint in meters vehicles will be collected", 1, 50, 1);
public static UIMenuCheckboxItem collectorWaypoint = new UIMenuCheckboxItem("Collector", true, "If this waypoint will collect vehicles to follow the path"); public static UIMenuCheckboxItem collectorWaypoint = new UIMenuCheckboxItem("Collector", true, "If this waypoint will collect vehicles to follow the path");
public static UIMenuNumericScrollerItem<int> collectorRadius = new UIMenuNumericScrollerItem<int>("Collection Radius", "The distance from this waypoint (in meters) vehicles will be collected", 1, 50, 1);
public static UIMenuNumericScrollerItem<int> speedZoneRadius = new UIMenuNumericScrollerItem<int>("Speed Zone Radius", "The distance from this collector waypoint (in meters) non-collected vehicles will drive at this waypoint's speed", 1, 50, 1);
internal static void InstantiateMenu() internal static void InstantiateMenu()
{ {
@ -34,6 +35,8 @@ namespace SceneManager
pathCreationMenu.AddItem(collectorWaypoint); pathCreationMenu.AddItem(collectorWaypoint);
pathCreationMenu.AddItem(collectorRadius); pathCreationMenu.AddItem(collectorRadius);
collectorRadius.Index = 0; collectorRadius.Index = 0;
pathCreationMenu.AddItem(speedZoneRadius);
speedZoneRadius.Index = 0;
pathCreationMenu.AddItem(trafficAddWaypoint = new UIMenuItem("Add waypoint")); pathCreationMenu.AddItem(trafficAddWaypoint = new UIMenuItem("Add waypoint"));
trafficAddWaypoint.ForeColor = Color.Gold; trafficAddWaypoint.ForeColor = Color.Gold;
pathCreationMenu.AddItem(trafficRemoveWaypoint = new UIMenuItem("Remove last waypoint")); pathCreationMenu.AddItem(trafficRemoveWaypoint = new UIMenuItem("Remove last waypoint"));
@ -53,6 +56,7 @@ namespace SceneManager
if(checkboxItem == collectorWaypoint) if(checkboxItem == collectorWaypoint)
{ {
collectorRadius.Enabled = collectorWaypoint.Checked ? true : false; collectorRadius.Enabled = collectorWaypoint.Checked ? true : false;
speedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false;
} }
} }
@ -70,10 +74,7 @@ namespace SceneManager
if (SettingsMenu.debugGraphics.Checked) if (SettingsMenu.debugGraphics.Checked)
{ {
GameFiber.StartNew(() => DebugGraphics.LoopToDrawDebugGraphics(SettingsMenu.debugGraphics, PathMainMenu.GetPaths()[0]);
{
DebugGraphics.LoopToDrawDebugGraphics(SettingsMenu.debugGraphics, PathMainMenu.GetPaths()[0]);
});
} }
} }
else if(anyPathsExist && !PathMainMenu.GetPaths().Any(p => p != null && p.State == State.Creating)) else if(anyPathsExist && !PathMainMenu.GetPaths().Any(p => p != null && p.State == State.Creating))
@ -82,10 +83,7 @@ namespace SceneManager
if (SettingsMenu.debugGraphics.Checked) if (SettingsMenu.debugGraphics.Checked)
{ {
GameFiber.StartNew(() => DebugGraphics.LoopToDrawDebugGraphics(SettingsMenu.debugGraphics, PathMainMenu.GetPaths().Where(p => p != null && p.State == State.Creating).First());
{
DebugGraphics.LoopToDrawDebugGraphics(SettingsMenu.debugGraphics, PathMainMenu.GetPaths().Where(p => p != null && p.State == State.Creating).First());
});
} }
} }
@ -99,10 +97,9 @@ namespace SceneManager
if (collectorWaypoint.Checked) if (collectorWaypoint.Checked)
{ {
var yieldZone = SettingsMenu.speedUnits.SelectedItem == SettingsMenu.SpeedUnitsOfMeasure.MPH var yieldZone = SettingsMenu.speedUnits.SelectedItem == SettingsMenu.SpeedUnitsOfMeasure.MPH
? World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeed.Value)) ? World.AddSpeedZone(Game.LocalPlayer.Character.Position, speedZoneRadius.Value, MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeed.Value))
: World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeed.Value)); : World.AddSpeedZone(Game.LocalPlayer.Character.Position, speedZoneRadius.Value, MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeed.Value));
PathMainMenu.GetPaths()[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip, true, collectorRadius.Value, speedZoneRadius.Value, yieldZone));
PathMainMenu.GetPaths()[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip, true, collectorRadius.Value, yieldZone));
} }
else else
{ {
@ -166,9 +163,9 @@ namespace SceneManager
PathMainMenu.AddPathToPathCountList(i, currentPath.PathNum); PathMainMenu.AddPathToPathCountList(i, currentPath.PathNum);
// 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 PathMainMenu.GetPaths()[i].Waypoints) foreach (Waypoint waypoint in PathMainMenu.GetPaths()[i].Waypoints)
{ {
GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => VehicleCollector.StartCollectingAtWaypoint(PathMainMenu.GetPaths(), PathMainMenu.GetPaths()[i], wd)); GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => VehicleCollector.StartCollectingAtWaypoint(PathMainMenu.GetPaths(), PathMainMenu.GetPaths()[i], waypoint));
WaypointVehicleCollectorFiber.Start(); WaypointVehicleCollectorFiber.Start();
} }

View file

@ -13,6 +13,7 @@ namespace SceneManager
public uint YieldZone { get; private set; } public uint YieldZone { get; private set; }
public bool IsCollector { get; private set; } public bool IsCollector { get; private set; }
public float CollectorRadius { get; private set; } public float CollectorRadius { get; private set; }
public float SpeedZoneRadius { get; private set; }
public Blip CollectorRadiusBlip { get; private set; } public Blip CollectorRadiusBlip { get; private set; }
public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip) public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip)
@ -26,7 +27,7 @@ namespace SceneManager
} }
public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip, bool collector, float collectorRadius, uint yieldZone) public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip, bool collector, float collectorRadius, float speedZoneRadius, uint yieldZone)
{ {
Path = path; Path = path;
Number = waypointNum; Number = waypointNum;
@ -36,6 +37,7 @@ namespace SceneManager
Blip = waypointBlip; Blip = waypointBlip;
IsCollector = collector; IsCollector = collector;
CollectorRadius = collectorRadius; CollectorRadius = collectorRadius;
SpeedZoneRadius = speedZoneRadius;
YieldZone = yieldZone; YieldZone = yieldZone;
CollectorRadiusBlip = new Blip(waypointBlip.Position, collectorRadius) CollectorRadiusBlip = new Blip(waypointBlip.Position, collectorRadius)
{ {
@ -44,24 +46,24 @@ namespace SceneManager
}; };
} }
public void UpdateWaypoint(Waypoint currentWaypoint, VehicleDrivingFlags drivingFlag, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius, bool updateWaypointPositionChecked) public void UpdateWaypoint(Waypoint currentWaypoint, VehicleDrivingFlags drivingFlag, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius, float speedZoneRadius, bool updateWaypointPositionChecked)
{ {
UpdateDrivingFlag(drivingFlag); UpdateDrivingFlag(drivingFlag);
UpdateWaypointSpeed(drivingSpeed); UpdateWaypointSpeed(drivingSpeed);
UpdateCollectorOptions(currentWaypoint, drivingSpeed, collectorWaypointChecked, collectorRadius); UpdateCollectorOptions(currentWaypoint, drivingSpeed, collectorWaypointChecked, collectorRadius, speedZoneRadius);
if (updateWaypointPositionChecked) if (updateWaypointPositionChecked)
{ {
UpdateWaypointPosition(Game.LocalPlayer.Character.Position); UpdateWaypointPosition(Game.LocalPlayer.Character.Position);
} }
} }
private void UpdateCollectorOptions(Waypoint currentWaypoint, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius) private void UpdateCollectorOptions(Waypoint currentWaypoint, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius, float speedZoneRadius)
{ {
if (collectorWaypointChecked) if (collectorWaypointChecked)
{ {
IsCollector = true; IsCollector = true;
World.RemoveSpeedZone(YieldZone); World.RemoveSpeedZone(YieldZone);
YieldZone = World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, drivingSpeed); YieldZone = World.AddSpeedZone(Game.LocalPlayer.Character.Position, SpeedZoneRadius, drivingSpeed);
if (CollectorRadiusBlip) if (CollectorRadiusBlip)
{ {
currentWaypoint.CollectorRadiusBlip.Alpha = 0.5f; currentWaypoint.CollectorRadiusBlip.Alpha = 0.5f;
@ -76,6 +78,7 @@ namespace SceneManager
}; };
} }
CollectorRadius = collectorRadius; CollectorRadius = collectorRadius;
SpeedZoneRadius = speedZoneRadius;
} }
else else
{ {
@ -118,5 +121,25 @@ namespace SceneManager
{ {
Number = newWaypointNumber; Number = newWaypointNumber;
} }
public void DrawWaypointMarker()
{
if(IsCollector && CollectorRadius > 0)
{
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, CollectorRadius, CollectorRadius, 1f, 80, 130, 255, 80, false, false, 2, false, 0, 0, false);
if(SpeedZoneRadius > 0)
{
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, SpeedZoneRadius, SpeedZoneRadius, 1f, 255, 185, 80, 80, false, false, 2, false, 0, 0, false);
}
}
else if(DrivingFlag == VehicleDrivingFlags.StopAtDestination)
{
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 80, false, false, 2, false, 0, 0, false);
}
else
{
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false);
}
}
} }
} }