mirror of
https://github.com/thegeneralist01/Scene-Manager-DevRepo
synced 2026-01-11 07:30:40 +01:00
Moved to new namespace
This commit is contained in:
parent
bcaecb8788
commit
1e50d1f537
12 changed files with 366 additions and 439 deletions
135
SceneManager/Barriers/Barrier.cs
Normal file
135
SceneManager/Barriers/Barrier.cs
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
using Rage;
|
||||
using SceneManager.Managers;
|
||||
using SceneManager.Utils;
|
||||
|
||||
namespace SceneManager.Barriers
|
||||
{
|
||||
public class Barrier : IDeletable, IHandleable, ISpatial
|
||||
{
|
||||
private Object _object { get; }
|
||||
public string ModelName { get; set; }
|
||||
public Vector3 Position { get; set; }
|
||||
public float Heading { get; set; }
|
||||
public bool Invincible { get; set; }
|
||||
public bool Immobile { get; set; }
|
||||
public bool LightsEnabled { get; set; }
|
||||
public int TextureVariation { get; set; }
|
||||
|
||||
public PoolHandle Handle => ((IHandleable)_object).Handle;
|
||||
|
||||
private Barrier() { }
|
||||
|
||||
internal Barrier(string modelName, Vector3 position, float heading, bool invincible, bool immobile, int textureVariation = 0, bool lightsEnabled = false)
|
||||
{
|
||||
ModelName = modelName;
|
||||
Position = position;
|
||||
Heading = heading;
|
||||
Invincible = invincible;
|
||||
Immobile = immobile;
|
||||
TextureVariation = textureVariation;
|
||||
LightsEnabled = lightsEnabled;
|
||||
_object = new Object(ModelName, Position, Heading);
|
||||
|
||||
if (BarrierManager.PlaceholderBarrier)
|
||||
{
|
||||
_object.SetPositionWithSnap(BarrierManager.PlaceholderBarrier.Position);
|
||||
}
|
||||
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_DYNAMIC(_object, true);
|
||||
if (Invincible)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_FRAG_DAMAGE(_object, true);
|
||||
if (ModelName != "prop_barrier_wat_03a")
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_BREAKING(_object, true);
|
||||
}
|
||||
}
|
||||
_object.IsPositionFrozen = Immobile;
|
||||
|
||||
if (Settings.EnableAdvancedBarricadeOptions)
|
||||
{
|
||||
SetAdvancedOptions();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAdvancedOptions()
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.x971DA0055324D033(_object, TextureVariation);
|
||||
if (LightsEnabled)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(_object, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(_object, true);
|
||||
}
|
||||
|
||||
//Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(barrier, setBarrierTrafficLight.Index);
|
||||
_object.IsPositionFrozen = true;
|
||||
GameFiber.Sleep(50);
|
||||
if (_object && !Immobile)
|
||||
{
|
||||
_object.IsPositionFrozen = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal void LoadFromImport()
|
||||
{
|
||||
Game.LogTrivial($"===== BARRIER DATA =====");
|
||||
Game.LogTrivial($"Model: {ModelName}");
|
||||
Game.LogTrivial($"Position: {Position}");
|
||||
Game.LogTrivial($"Heading: {Heading}");
|
||||
Game.LogTrivial($"Invincible: {Invincible}");
|
||||
Game.LogTrivial($"Immobile: {Immobile}");
|
||||
Game.LogTrivial($"LightsEnabled: {LightsEnabled}");
|
||||
Game.LogTrivial($"Texture Variation: {TextureVariation}");
|
||||
var barrier = new Barrier(ModelName, Position, Heading, Invincible, Immobile, TextureVariation, LightsEnabled);
|
||||
BarrierManager.Barriers.Add(barrier);
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
((IDeletable)_object).Delete();
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
return ((IHandleable)_object).IsValid();
|
||||
}
|
||||
|
||||
public bool Equals(IHandleable other)
|
||||
{
|
||||
return ((System.IEquatable<IHandleable>)_object).Equals(other);
|
||||
}
|
||||
|
||||
public float DistanceTo(Vector3 position)
|
||||
{
|
||||
return ((ISpatial)_object).DistanceTo(position);
|
||||
}
|
||||
|
||||
public float DistanceTo(ISpatial spatialObject)
|
||||
{
|
||||
return ((ISpatial)_object).DistanceTo(spatialObject);
|
||||
}
|
||||
|
||||
public float DistanceTo2D(Vector3 position)
|
||||
{
|
||||
return ((ISpatial)_object).DistanceTo2D(position);
|
||||
}
|
||||
|
||||
public float DistanceTo2D(ISpatial spatialObject)
|
||||
{
|
||||
return ((ISpatial)_object).DistanceTo2D(spatialObject);
|
||||
}
|
||||
|
||||
public float TravelDistanceTo(Vector3 position)
|
||||
{
|
||||
return ((ISpatial)_object).TravelDistanceTo(position);
|
||||
}
|
||||
|
||||
public float TravelDistanceTo(ISpatial spatialObject)
|
||||
{
|
||||
return ((ISpatial)_object).TravelDistanceTo(spatialObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SceneManager.Utils;
|
||||
using SceneManager.Waypoints;
|
||||
using SceneManager.Paths;
|
||||
|
||||
namespace SceneManager.Objects
|
||||
namespace SceneManager.CollectedPeds
|
||||
{
|
||||
internal class CollectedPed : Ped
|
||||
{
|
||||
|
|
@ -54,7 +56,7 @@ namespace SceneManager.Objects
|
|||
DriveToNextWaypoint();
|
||||
}
|
||||
|
||||
if (!Dismissed && !VehicleAndDriverAreValid() || Directed)
|
||||
if (Path.State == State.Deleting || (!Dismissed && !VehicleAndDriverAreValid()) || Directed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -62,7 +64,7 @@ namespace SceneManager.Objects
|
|||
Game.LogTrivial($"{CurrentVehicle.Model.Name} [{CurrentVehicle.Handle}] all Path {Path.Number} tasks complete.");
|
||||
if (!Dismissed)
|
||||
{
|
||||
base.Dismiss();
|
||||
Dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +87,7 @@ namespace SceneManager.Objects
|
|||
}
|
||||
}
|
||||
|
||||
void DriveToDirectedWaypoint()
|
||||
private void DriveToDirectedWaypoint()
|
||||
{
|
||||
Dismissed = false;
|
||||
|
||||
|
|
@ -115,6 +117,12 @@ namespace SceneManager.Objects
|
|||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
|
||||
if(!VehicleAndDriverAreValid() || Path.State == State.Deleting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (CurrentVehicle)
|
||||
{
|
||||
Tasks.PerformDrivingManeuver(CurrentVehicle, VehicleManeuver.GoForwardWithCustomSteeringAngle, 3).WaitForCompletion();
|
||||
|
|
@ -231,19 +239,26 @@ namespace SceneManager.Objects
|
|||
{
|
||||
var stoppingDistance = GetAcceptedStoppingDistance(CurrentWaypoint.Path.Waypoints, CurrentWaypoint.Path.Waypoints.IndexOf(CurrentWaypoint));
|
||||
Game.LogTrivial($"{CurrentVehicle.Model.Name} stopping at path {CurrentWaypoint.Path.Number} waypoint.");
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(CurrentVehicle, stoppingDistance, -1, true);
|
||||
var vehicleToStop = CurrentVehicle;
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(vehicleToStop, stoppingDistance, -1, true);
|
||||
StoppedAtWaypoint = true;
|
||||
|
||||
while (CurrentWaypoint != null && VehicleAndDriverAreValid() && StoppedAtWaypoint && !Directed)
|
||||
while (CurrentWaypoint != null && VehicleAndDriverAreValid() && StoppedAtWaypoint && !Directed && IsInVehicle(CurrentVehicle, false))
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
if (this && CurrentVehicle)
|
||||
if(vehicleToStop)
|
||||
{
|
||||
Game.LogTrivial($"{CurrentVehicle.Model.Name} releasing from stop waypoint.");
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(CurrentVehicle, 0f, 1, true);
|
||||
Tasks.CruiseWithVehicle(5f);
|
||||
Game.LogTrivial($"{vehicleToStop.Model.Name} releasing from stop waypoint.");
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(vehicleToStop, 0f, 1, true);
|
||||
}
|
||||
|
||||
//if (this && OriginalVehicle)
|
||||
//{
|
||||
// Game.LogTrivial($"{OriginalVehicle.Model.Name} releasing from stop waypoint.");
|
||||
// Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(OriginalVehicle, 0f, 1, true);
|
||||
// Tasks.CruiseWithVehicle(5f);
|
||||
//}
|
||||
}
|
||||
|
||||
private bool VehicleAndDriverAreValid()
|
||||
|
|
@ -274,7 +289,7 @@ namespace SceneManager.Objects
|
|||
{
|
||||
if (StoppedAtWaypoint)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(LastVehicle, 0f, 1, true);
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(CurrentVehicle, 0f, 1, true);
|
||||
}
|
||||
CurrentVehicle.Dismiss();
|
||||
}
|
||||
|
|
@ -379,20 +394,20 @@ namespace SceneManager.Objects
|
|||
// Check if the vehicle is near any of the path's collector waypoints
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
var nearestCollectorWaypoint = Path.Waypoints.Where(wp => wp.IsCollector).OrderBy(wp => CurrentVehicle.DistanceTo2D(wp.Position)).FirstOrDefault();
|
||||
if(nearestCollectorWaypoint == null)
|
||||
{
|
||||
Game.LogTrivial($"Nearest collector is null");
|
||||
}
|
||||
else
|
||||
{
|
||||
while (nearestCollectorWaypoint != null && CurrentVehicle && CurrentVehicle.HasDriver && this && IsAlive && CurrentVehicle.FrontPosition.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius)
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
}
|
||||
//var nearestCollectorWaypoint = Path.Waypoints.Where(wp => wp.IsCollector).OrderBy(wp => CurrentVehicle.DistanceTo2D(wp.Position)).FirstOrDefault();
|
||||
//if(nearestCollectorWaypoint == null)
|
||||
//{
|
||||
// Game.LogTrivial($"Nearest collector is null");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// while (nearestCollectorWaypoint != null && CurrentVehicle && CurrentVehicle.HasDriver && this && IsAlive && CurrentVehicle.FrontPosition.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius)
|
||||
// {
|
||||
// GameFiber.Yield();
|
||||
// }
|
||||
//}
|
||||
|
||||
if (!CurrentVehicle || !this)
|
||||
if (!this || !CurrentVehicle)
|
||||
{
|
||||
Game.LogTrivial($"Vehicle or driver is null");
|
||||
return;
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Rage;
|
||||
using SceneManager.Barriers;
|
||||
using SceneManager.Menus;
|
||||
using SceneManager.Objects;
|
||||
using SceneManager.Paths;
|
||||
using SceneManager.Utils;
|
||||
|
||||
namespace SceneManager.Utils
|
||||
namespace SceneManager.Managers
|
||||
{
|
||||
internal static class BarrierManager
|
||||
{
|
||||
|
|
@ -21,11 +23,11 @@ namespace SceneManager.Utils
|
|||
|
||||
var barrierKey = Settings.Barriers.Where(x => x.Key == BarrierMenu.BarrierList.SelectedItem).FirstOrDefault().Key;
|
||||
var barrierValue = Settings.Barriers[barrierKey].Name;
|
||||
PlaceholderBarrier = new Object(barrierValue, UserInput.GetMousePositionForBarrier, BarrierMenu.RotateBarrier.Value);
|
||||
PlaceholderBarrier = new Object(barrierValue, UserInput.PlayerMousePositionForBarrier, BarrierMenu.RotateBarrier.Value);
|
||||
if (!PlaceholderBarrier)
|
||||
{
|
||||
BarrierMenu.Menu.Close();
|
||||
Game.LogTrivial($"Something went wrong creating the placeholder barrier. Mouse position: {UserInput.GetMousePositionForBarrier}");
|
||||
Game.LogTrivial($"Something went wrong creating the placeholder barrier. Mouse position: {UserInput.PlayerMousePositionForBarrier}");
|
||||
Game.DisplayNotification($"~o~Scene Manager ~r~[Error]\n~w~Something went wrong creating the placeholder barrier. This is a rare problem that only happens in certain areas of the world. Please try again somewhere else.");
|
||||
return;
|
||||
}
|
||||
|
|
@ -64,14 +66,14 @@ namespace SceneManager.Utils
|
|||
if (PlaceholderBarrier)
|
||||
{
|
||||
PlaceholderBarrier.Heading = BarrierMenu.RotateBarrier.Value;
|
||||
PlaceholderBarrier.Position = UserInput.GetMousePositionForBarrier;
|
||||
PlaceholderBarrier.Position = UserInput.PlayerMousePositionForBarrier;
|
||||
Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(PlaceholderBarrier);
|
||||
//Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(shadowBarrier, setBarrierTrafficLight.Index);
|
||||
}
|
||||
|
||||
void DisableBarrierMenuOptionsIfShadowConeTooFar()
|
||||
{
|
||||
if (!PlaceholderBarrier && UserInput.GetMousePositionForBarrier.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance)
|
||||
if (!PlaceholderBarrier && UserInput.PlayerMousePositionForBarrier.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance)
|
||||
{
|
||||
CreatePlaceholderBarrier();
|
||||
|
||||
|
|
@ -106,7 +108,7 @@ namespace SceneManager.Utils
|
|||
//UpdatePlaceholderBarrierPosition();
|
||||
UpdatePlaceholderBarrierPosition();
|
||||
}
|
||||
else if (UserInput.GetMousePositionForBarrier.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance)
|
||||
else if (UserInput.PlayerMousePositionForBarrier.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance)
|
||||
{
|
||||
//CreatePlaceholderBarrier();
|
||||
CreatePlaceholderBarrier();
|
||||
|
|
@ -130,19 +132,31 @@ namespace SceneManager.Utils
|
|||
|
||||
internal static void SpawnBarrier()
|
||||
{
|
||||
Barrier barrier;
|
||||
|
||||
if (BarrierMenu.BarrierList.SelectedItem == "Flare")
|
||||
{
|
||||
SpawnFlare();
|
||||
}
|
||||
else
|
||||
{
|
||||
var barrier = new Barrier(PlaceholderBarrier, PlaceholderBarrier.Position, BarrierMenu.RotateBarrier.Value, BarrierMenu.Invincible.Checked, BarrierMenu.Immobile.Checked, BarrierMenu.BarrierTexture.Value, BarrierMenu.SetBarrierLights.Checked);
|
||||
//var obj = new Object(PlaceholderBarrier.Model, PlaceholderBarrier.Position, BarrierMenu.RotateBarrier.Value);
|
||||
barrier = new Barrier(PlaceholderBarrier.Model.Name, PlaceholderBarrier.Position, PlaceholderBarrier.Heading, BarrierMenu.Invincible.Checked, BarrierMenu.Immobile.Checked, BarrierMenu.BarrierTexture.Value, BarrierMenu.SetBarrierLights.Checked);
|
||||
Barriers.Add(barrier);
|
||||
|
||||
BarrierMenu.RemoveBarrierOptions.Enabled = true;
|
||||
BarrierMenu.ResetBarriers.Enabled = true;
|
||||
}
|
||||
|
||||
if (barrier != null && BarrierMenu.BelongsToPath.Checked)
|
||||
{
|
||||
var matchingPath = PathManager.Paths.FirstOrDefault(x => x.Name == BarrierMenu.AddToPath.OptionText);
|
||||
if(matchingPath != null)
|
||||
{
|
||||
matchingPath.Barriers.Add(barrier);
|
||||
}
|
||||
}
|
||||
|
||||
void SpawnFlare()
|
||||
{
|
||||
var flare = new Weapon("weapon_flare", PlaceholderBarrier.Position, 1);
|
||||
|
|
@ -161,31 +175,53 @@ namespace SceneManager.Utils
|
|||
}
|
||||
}, "Spawn Flare Fiber");
|
||||
|
||||
Barriers.Add(new Barrier(flare, flare.Position, flare.Heading, BarrierMenu.Invincible.Checked, BarrierMenu.Immobile.Checked));
|
||||
//var obj = new Object(flare.Model, flare.Position, flare.Heading);
|
||||
barrier = new Barrier(flare.Model.Name, flare.Position, flare.Heading, BarrierMenu.Invincible.Checked, BarrierMenu.Immobile.Checked);
|
||||
Barriers.Add(barrier);
|
||||
BarrierMenu.RemoveBarrierOptions.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RemoveBarrier(int removeBarrierOptionsIndex)
|
||||
{
|
||||
Path path;
|
||||
switch (removeBarrierOptionsIndex)
|
||||
{
|
||||
case 0:
|
||||
Barriers[Barriers.Count - 1].Delete();
|
||||
var barrierToRemove = Barriers[Barriers.Count - 1];
|
||||
path = PathManager.Paths.FirstOrDefault(x => x.Barriers.Contains(barrierToRemove));
|
||||
if(path != null)
|
||||
{
|
||||
path.Barriers.Remove(barrierToRemove);
|
||||
}
|
||||
|
||||
barrierToRemove.Delete();
|
||||
Barriers.RemoveAt(Barriers.Count - 1);
|
||||
break;
|
||||
case 1:
|
||||
var nearestBarrier = Barriers.OrderBy(b => b.DistanceTo2D(Game.LocalPlayer.Character)).FirstOrDefault();
|
||||
if (nearestBarrier != null)
|
||||
{
|
||||
path = PathManager.Paths.FirstOrDefault(x => x.Barriers.Contains(nearestBarrier));
|
||||
if (path != null)
|
||||
{
|
||||
path.Barriers.Remove(nearestBarrier);
|
||||
}
|
||||
|
||||
nearestBarrier.Delete();
|
||||
Barriers.Remove(nearestBarrier);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
foreach (Barrier b in Barriers)
|
||||
foreach (Barrier barrier in Barriers)
|
||||
{
|
||||
b.Delete();
|
||||
path = PathManager.Paths.FirstOrDefault(x => x.Barriers.Contains(barrier));
|
||||
if (path != null)
|
||||
{
|
||||
path.Barriers.Remove(barrier);
|
||||
}
|
||||
|
||||
barrier.Delete();
|
||||
}
|
||||
if (Barriers.Count > 0)
|
||||
{
|
||||
|
|
@ -194,20 +230,22 @@ namespace SceneManager.Utils
|
|||
break;
|
||||
}
|
||||
|
||||
BarrierMenu.RemoveBarrierOptions.Enabled = Barriers.Count == 0 ? false : true;
|
||||
BarrierMenu.ResetBarriers.Enabled = Barriers.Count == 0 ? false : true;
|
||||
BarrierMenu.RemoveBarrierOptions.Enabled = Barriers.Count != 0;
|
||||
BarrierMenu.ResetBarriers.Enabled = Barriers.Count != 0;
|
||||
}
|
||||
|
||||
internal static void ResetBarriers()
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
var currentBarriers = Barriers.Where(b => b.Model.Name != "0xa2c44e80").ToList(); // 0xa2c44e80 is the flare weapon hash
|
||||
var currentBarriers = Barriers.Where(b => b.ModelName != "0xa2c44e80").ToList(); // 0xa2c44e80 is the flare weapon hash
|
||||
foreach (Barrier barrier in currentBarriers)
|
||||
{
|
||||
Barriers.Add(new Barrier(barrier, barrier.SpawnPosition, barrier.SpawnHeading, barrier.Invincible, barrier.Immobile, barrier.TextureVariation, barrier.LightsEnabled));
|
||||
//var obj = new Object(barrier.ModelName, barrier.Position, barrier.Heading);
|
||||
var newBarrier = new Barrier(barrier.ModelName, barrier.Position, barrier.Heading, barrier.Invincible, barrier.Immobile, barrier.TextureVariation, barrier.LightsEnabled);
|
||||
Barriers.Add(newBarrier);
|
||||
|
||||
if (barrier)
|
||||
if (barrier.IsValid())
|
||||
{
|
||||
barrier.Delete();
|
||||
}
|
||||
|
|
@ -221,7 +259,7 @@ namespace SceneManager.Utils
|
|||
internal static void RotateBarrier()
|
||||
{
|
||||
PlaceholderBarrier.Heading = BarrierMenu.RotateBarrier.Value;
|
||||
PlaceholderBarrier.Position = UserInput.GetMousePositionForBarrier;
|
||||
PlaceholderBarrier.Position = UserInput.PlayerMousePositionForBarrier;
|
||||
Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(PlaceholderBarrier);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ using System.Linq;
|
|||
using RAGENativeUI.Elements;
|
||||
using System.Drawing;
|
||||
|
||||
namespace SceneManager
|
||||
namespace SceneManager.Managers
|
||||
{
|
||||
// The only reason this class should change is to modify how menus are are being handled
|
||||
internal static class MenuManager
|
||||
|
|
@ -19,6 +19,7 @@ namespace SceneManager
|
|||
PathMainMenu.Initialize();
|
||||
PathCreationMenu.Initialize();
|
||||
ImportPathMenu.Initialize();
|
||||
DriverMenu.Initialize();
|
||||
BarrierMenu.Initialize();
|
||||
EditPathMenu.Initialize();
|
||||
EditWaypointMenu.Initialize();
|
||||
|
|
@ -37,61 +38,42 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
private static void BuildMenus()
|
||||
internal static void BuildMenus()
|
||||
{
|
||||
MainMenu.BuildMainMenu();
|
||||
SettingsMenu.BuildSettingsMenu();
|
||||
PathMainMenu.BuildPathMenu();
|
||||
DriverMenu.Build();
|
||||
PathMainMenu.Build();
|
||||
PathCreationMenu.BuildPathCreationMenu();
|
||||
ImportPathMenu.BuildImportMenu();
|
||||
EditPathMenu.BuildEditPathMenu();
|
||||
BarrierMenu.BuildBarrierMenu();
|
||||
BarrierMenu.BuildMenu();
|
||||
}
|
||||
|
||||
private static void ColorMenuItems()
|
||||
internal static void ColorMenuItems()
|
||||
{
|
||||
foreach(UIMenuItem menuItem in MenuPool.SelectMany(x => x.MenuItems))
|
||||
{
|
||||
if (menuItem.Enabled && menuItem.ForeColor == Color.Gold)
|
||||
if (menuItem.Enabled)
|
||||
{
|
||||
menuItem.HighlightedBackColor = menuItem.ForeColor;
|
||||
}
|
||||
if(!menuItem.Enabled)
|
||||
{
|
||||
menuItem.HighlightedBackColor = Color.DarkGray;
|
||||
menuItem.DisabledForeColor = Color.Gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool AreMenusClosed()
|
||||
internal static void ProcessMenus()
|
||||
{
|
||||
if (!BarrierMenu.Menu.Visible && !PathMainMenu.Menu.Visible && !PathCreationMenu.Menu.Visible && !EditPathMenu.Menu.Visible && !EditWaypointMenu.Menu.Visible && !SettingsMenu.Menu.Visible)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Update()
|
||||
{
|
||||
while (AnyMenuVisible())
|
||||
while (MenuPool.Any(x => x.Visible))
|
||||
{
|
||||
MenuPool.ProcessMenus();
|
||||
ColorMenuItems();
|
||||
GameFiber.Yield();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool AnyMenuVisible()
|
||||
{
|
||||
if(MenuPool.Any(x => x.Visible))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static void AddToMenuPool(UIMenu menu)
|
||||
{
|
||||
MenuPool.Add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
using Rage;
|
||||
using RAGENativeUI.Elements;
|
||||
using SceneManager.Menus;
|
||||
using SceneManager.Objects;
|
||||
using SceneManager.Paths;
|
||||
using SceneManager.Utils;
|
||||
using SceneManager.Waypoints;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SceneManager.Utils
|
||||
namespace SceneManager.Managers
|
||||
{
|
||||
internal class PathManager
|
||||
{
|
||||
|
|
@ -15,7 +16,7 @@ namespace SceneManager.Utils
|
|||
{
|
||||
importedPath.State = State.Creating;
|
||||
|
||||
var firstVacantIndex = Paths.IndexOf(Paths.FirstOrDefault(x => x.State != State.Creating)) + 1;
|
||||
var firstVacantIndex = Paths.IndexOf(Paths.FirstOrDefault(x => x.State == State.Uninitialized)) + 1; // != State.Creating
|
||||
if (firstVacantIndex < 0)
|
||||
{
|
||||
firstVacantIndex = 0;
|
||||
|
|
@ -35,7 +36,7 @@ namespace SceneManager.Utils
|
|||
{
|
||||
var currentPath = Paths[PathMainMenu.EditPath.Index];
|
||||
// Reference PNWParks's UserInput class from LiveLights
|
||||
var filename = UserInput.GetFileName("Type the name you would like to save your file as", "Enter a filename", 100) + ".xml";
|
||||
var filename = UserInput.PromptPlayerForFileName("Type the name you would like to save your file as", "Enter a filename", 100) + ".xml";
|
||||
|
||||
// If filename != null or empty, check if export directory exists (GTA V/Plugins/SceneManager/Saved Paths)
|
||||
if (string.IsNullOrWhiteSpace(filename))
|
||||
|
|
@ -53,6 +54,9 @@ namespace SceneManager.Utils
|
|||
Settings.ImportPaths();
|
||||
PathMainMenu.ImportPath.Enabled = true;
|
||||
ImportPathMenu.BuildImportMenu();
|
||||
PathMainMenu.Build();
|
||||
|
||||
PathMainMenu.Menu.Visible = true;
|
||||
}
|
||||
|
||||
internal static Path InitializeNewPath()
|
||||
|
|
@ -85,11 +89,11 @@ namespace SceneManager.Utils
|
|||
Waypoint newWaypoint;
|
||||
if (PathCreationMenu.CollectorWaypoint.Checked)
|
||||
{
|
||||
newWaypoint = new Waypoint(currentPath, waypointNumber, UserInput.GetMousePosition, SetDriveSpeedForWaypoint(), drivingFlag, PathCreationMenu.StopWaypoint.Checked, true, PathCreationMenu.CollectorRadius.Value, PathCreationMenu.SpeedZoneRadius.Value);
|
||||
newWaypoint = new Waypoint(currentPath, waypointNumber, UserInput.PlayerMousePosition, ConvertDriveSpeedForWaypoint(PathCreationMenu.WaypointSpeed.Value), drivingFlag, PathCreationMenu.StopWaypoint.Checked, true, PathCreationMenu.CollectorRadius.Value, PathCreationMenu.SpeedZoneRadius.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
newWaypoint = new Waypoint(currentPath, waypointNumber, UserInput.GetMousePosition, SetDriveSpeedForWaypoint(), drivingFlag, PathCreationMenu.StopWaypoint.Checked);
|
||||
newWaypoint = new Waypoint(currentPath, waypointNumber, UserInput.PlayerMousePosition, ConvertDriveSpeedForWaypoint(PathCreationMenu.WaypointSpeed.Value), drivingFlag, PathCreationMenu.StopWaypoint.Checked);
|
||||
}
|
||||
currentPath.Waypoints.Add(newWaypoint);
|
||||
Game.LogTrivial($"Path {currentPath.Number} Waypoint {waypointNumber} added [Driving style: {drivingFlag} | Stop waypoint: {newWaypoint.IsStopWaypoint} | Speed: {newWaypoint.Speed} | Collector: {newWaypoint.IsCollector}]");
|
||||
|
|
@ -106,28 +110,29 @@ namespace SceneManager.Utils
|
|||
|
||||
if (EditWaypointMenu.CollectorWaypoint.Checked)
|
||||
{
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, UserInput.GetMousePosition, SetDriveSpeedForWaypoint(), drivingFlag, EditWaypointMenu.StopWaypointType.Checked, true, EditWaypointMenu.ChangeCollectorRadius.Value, EditWaypointMenu.ChangeSpeedZoneRadius.Value));
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, UserInput.PlayerMousePosition, ConvertDriveSpeedForWaypoint(EditWaypointMenu.ChangeWaypointSpeed.Value), drivingFlag, EditWaypointMenu.StopWaypointType.Checked, true, EditWaypointMenu.ChangeCollectorRadius.Value, EditWaypointMenu.ChangeSpeedZoneRadius.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, UserInput.GetMousePosition, SetDriveSpeedForWaypoint(), drivingFlag, EditWaypointMenu.StopWaypointType.Checked));
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, UserInput.PlayerMousePosition, ConvertDriveSpeedForWaypoint(EditWaypointMenu.ChangeWaypointSpeed.Value), drivingFlag, EditWaypointMenu.StopWaypointType.Checked));
|
||||
}
|
||||
Game.LogTrivial($"New waypoint (#{currentPath.Waypoints.Last().Number}) added.");
|
||||
}
|
||||
|
||||
internal static void UpdateWaypoint()
|
||||
{
|
||||
var currentPath = Paths[PathMainMenu.EditPath.Index];
|
||||
//var currentPath = Paths[PathMainMenu.EditPath.Index];
|
||||
var currentPath = Paths.FirstOrDefault(x => x.Name == PathMainMenu.EditPath.OptionText);
|
||||
var currentWaypoint = currentPath.Waypoints[EditWaypointMenu.EditWaypoint.Index];
|
||||
DrivingFlagType drivingFlag = EditWaypointMenu.DirectWaypointBehavior.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
|
||||
|
||||
if (currentPath.Waypoints.Count == 1)
|
||||
{
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, UserInput.GetMousePosition, drivingFlag, EditWaypointMenu.StopWaypointType.Checked, SetDriveSpeedForWaypoint(), true, EditWaypointMenu.ChangeCollectorRadius.Value, EditWaypointMenu.ChangeSpeedZoneRadius.Value, EditWaypointMenu.UpdateWaypointPosition.Checked);
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, UserInput.PlayerMousePosition, drivingFlag, EditWaypointMenu.StopWaypointType.Checked, ConvertDriveSpeedForWaypoint(EditWaypointMenu.ChangeWaypointSpeed.Value), true, EditWaypointMenu.ChangeCollectorRadius.Value, EditWaypointMenu.ChangeSpeedZoneRadius.Value, EditWaypointMenu.UpdateWaypointPosition.Checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, UserInput.GetMousePosition, drivingFlag, EditWaypointMenu.StopWaypointType.Checked, SetDriveSpeedForWaypoint(), EditWaypointMenu.CollectorWaypoint.Checked, EditWaypointMenu.ChangeCollectorRadius.Value, EditWaypointMenu.ChangeSpeedZoneRadius.Value, EditWaypointMenu.UpdateWaypointPosition.Checked);
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, UserInput.PlayerMousePosition, drivingFlag, EditWaypointMenu.StopWaypointType.Checked, ConvertDriveSpeedForWaypoint(EditWaypointMenu.ChangeWaypointSpeed.Value), EditWaypointMenu.CollectorWaypoint.Checked, EditWaypointMenu.ChangeCollectorRadius.Value, EditWaypointMenu.ChangeSpeedZoneRadius.Value, EditWaypointMenu.UpdateWaypointPosition.Checked);
|
||||
}
|
||||
Game.LogTrivial($"Path {currentPath.Number} Waypoint {currentWaypoint.Number} updated [Driving style: {drivingFlag} | Stop waypoint: {EditWaypointMenu.StopWaypointType.Checked} | Speed: {EditWaypointMenu.ChangeWaypointSpeed.Value} | Collector: {currentWaypoint.IsCollector}]");
|
||||
|
||||
|
|
@ -135,22 +140,11 @@ namespace SceneManager.Utils
|
|||
Game.DisplayNotification($"~o~Scene Manager ~g~[Success]~w~\nWaypoint {currentWaypoint.Number} updated.");
|
||||
}
|
||||
|
||||
private static float SetDriveSpeedForWaypoint()
|
||||
private static float ConvertDriveSpeedForWaypoint(float speed)
|
||||
{
|
||||
float convertedSpeed;
|
||||
if (SettingsMenu.SpeedUnits.SelectedItem == SpeedUnits.MPH)
|
||||
{
|
||||
//Logger.Log($"Original speed: {waypointSpeeds[waypointSpeed.Index]}{SettingsMenu.speedUnits.SelectedItem}");
|
||||
convertedSpeed = MathHelper.ConvertMilesPerHourToMetersPerSecond(PathCreationMenu.WaypointSpeed.Value);
|
||||
//Logger.Log($"Converted speed: {convertedSpeed}m/s");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Logger.Log($"Original speed: {waypointSpeeds[waypointSpeed.Index]}{SettingsMenu.speedUnits.SelectedItem}");
|
||||
convertedSpeed = MathHelper.ConvertKilometersPerHourToMetersPerSecond(PathCreationMenu.WaypointSpeed.Value);
|
||||
//Logger.Log($"Converted speed: {convertedSpeed}m/s");
|
||||
}
|
||||
|
||||
float convertedSpeed = SettingsMenu.SpeedUnits.SelectedItem == SpeedUnits.MPH
|
||||
? MathHelper.ConvertMilesPerHourToMetersPerSecond(speed)
|
||||
: MathHelper.ConvertKilometersPerHourToMetersPerSecond(speed);
|
||||
return convertedSpeed;
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +163,7 @@ namespace SceneManager.Utils
|
|||
Game.LogTrivial($"Deleting the last waypoint from the path.");
|
||||
currentPath.Delete();
|
||||
Paths.Remove(currentPath);
|
||||
PathMainMenu.BuildPathMenu();
|
||||
PathMainMenu.Build();
|
||||
|
||||
EditWaypointMenu.Menu.Visible = false;
|
||||
PathMainMenu.Menu.Visible = true;
|
||||
|
|
@ -191,7 +185,7 @@ namespace SceneManager.Utils
|
|||
DrivingFlagType drivingFlag = EditWaypointMenu.DirectWaypointBehavior.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
|
||||
Hints.Display($"~o~Scene Manager ~y~[Hint]~w~\nYour path's first waypoint ~b~must~w~ be a collector. If it's not, it will automatically be made into one.");
|
||||
Game.LogTrivial($"The path only has 1 waypoint left, this waypoint must be a collector.");
|
||||
currentPath.Waypoints[0].UpdateWaypoint(currentPath.Waypoints.First(), UserInput.GetMousePosition, drivingFlag, EditWaypointMenu.StopWaypointType.Checked, SetDriveSpeedForWaypoint(), true, EditWaypointMenu.ChangeCollectorRadius.Value, EditWaypointMenu.ChangeSpeedZoneRadius.Value, EditWaypointMenu.UpdateWaypointPosition.Checked);
|
||||
currentPath.Waypoints[0].UpdateWaypoint(currentPath.Waypoints.First(), UserInput.PlayerMousePosition, drivingFlag, EditWaypointMenu.StopWaypointType.Checked, ConvertDriveSpeedForWaypoint(EditWaypointMenu.ChangeWaypointSpeed.Value), true, EditWaypointMenu.ChangeCollectorRadius.Value, EditWaypointMenu.ChangeSpeedZoneRadius.Value, EditWaypointMenu.UpdateWaypointPosition.Checked);
|
||||
EditWaypointMenu.CollectorWaypoint.Checked = true;
|
||||
EditWaypointMenu.ChangeCollectorRadius.Enabled = true;
|
||||
EditWaypointMenu.ChangeSpeedZoneRadius.Enabled = true;
|
||||
|
|
@ -209,8 +203,13 @@ namespace SceneManager.Utils
|
|||
GameFiber.StartNew(() => currentPath.LoopWaypointCollection(), "Waypoint Collection Loop Fiber");
|
||||
|
||||
PathMainMenu.CreateNewPath.Text = "Create New Path";
|
||||
PathMainMenu.BuildPathMenu();
|
||||
PathMainMenu.Build();
|
||||
PathMainMenu.Menu.Visible = true;
|
||||
|
||||
MainMenu.BuildMainMenu();
|
||||
DriverMenu.Build();
|
||||
PathCreationMenu.BuildPathCreationMenu();
|
||||
BarrierMenu.BuildMenu();
|
||||
}
|
||||
|
||||
internal static void TogglePathCreationMenuItems(Path currentPath)
|
||||
|
|
@ -254,5 +253,28 @@ namespace SceneManager.Utils
|
|||
Paths.SelectMany(x => x.Waypoints).ToList().ForEach(x => x.DisableBlip());
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ToggleAllPaths(bool disable)
|
||||
{
|
||||
if (disable)
|
||||
{
|
||||
Paths.ForEach(x => x.DisablePath());
|
||||
Game.LogTrivial($"All paths disabled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Paths.ForEach(x => x.EnablePath());
|
||||
Game.LogTrivial($"All paths enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void DeleteAllPaths()
|
||||
{
|
||||
Paths.ForEach(x => x.Delete());
|
||||
Paths.Clear();
|
||||
Game.LogTrivial($"All paths deleted");
|
||||
Game.DisplayNotification($"~o~Scene Manager\n~w~All paths deleted.");
|
||||
MainMenu.BuildMainMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,8 @@ using Rage;
|
|||
using RAGENativeUI;
|
||||
using RAGENativeUI.Elements;
|
||||
using SceneManager.Utils;
|
||||
using SceneManager.Objects;
|
||||
using SceneManager.Managers;
|
||||
using SceneManager.Paths;
|
||||
|
||||
namespace SceneManager.Menus
|
||||
{
|
||||
|
|
@ -36,7 +37,7 @@ namespace SceneManager.Menus
|
|||
|
||||
internal static void BuildPathCreationMenu()
|
||||
{
|
||||
Menu.MenuItems.Clear();
|
||||
Menu.Clear();
|
||||
|
||||
Menu.AddItem(CollectorWaypoint);
|
||||
CollectorWaypoint.Enabled = false;
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
using Rage;
|
||||
using SceneManager.Menus;
|
||||
using SceneManager.Utils;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SceneManager.Objects
|
||||
{
|
||||
[XmlRoot(ElementName = "Barrier", Namespace = "")]
|
||||
public class Barrier : Object // Change this and properties to Public for import/export
|
||||
{
|
||||
public Vector3 SpawnPosition { get; }
|
||||
public float SpawnHeading { get; }
|
||||
new public bool Invincible { get; }
|
||||
public bool Immobile { get; }
|
||||
public bool LightsEnabled { get; }
|
||||
public int TextureVariation { get; }
|
||||
|
||||
internal Barrier(Object barrier, Vector3 barrierPosition, float barrierRotation, bool invincible, bool immobile, int textureVariation = 0, bool lightsEnabled = false) : base(barrier.Model, barrierPosition, barrierRotation)
|
||||
{
|
||||
SpawnPosition = barrierPosition;
|
||||
SpawnHeading = barrierRotation;
|
||||
Invincible = invincible;
|
||||
IsInvincible = invincible;
|
||||
Immobile = immobile;
|
||||
TextureVariation = textureVariation;
|
||||
LightsEnabled = lightsEnabled;
|
||||
|
||||
if(BarrierManager.PlaceholderBarrier)
|
||||
{
|
||||
SetPositionWithSnap(BarrierManager.PlaceholderBarrier.Position);
|
||||
}
|
||||
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_DYNAMIC(this, true);
|
||||
if (Invincible)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_FRAG_DAMAGE(this, true);
|
||||
if (Model.Name != "prop_barrier_wat_03a")
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_DISABLE_BREAKING(this, true);
|
||||
}
|
||||
}
|
||||
IsPositionFrozen = Immobile;
|
||||
|
||||
if (Settings.EnableAdvancedBarricadeOptions)
|
||||
{
|
||||
SetAdvancedOptions();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAdvancedOptions()
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.x971DA0055324D033(this, TextureVariation);
|
||||
if (LightsEnabled)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(this, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(this, true);
|
||||
}
|
||||
|
||||
//Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(barrier, setBarrierTrafficLight.Index);
|
||||
IsPositionFrozen = true;
|
||||
GameFiber.Sleep(50);
|
||||
if (this && !Immobile)
|
||||
{
|
||||
IsPositionFrozen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,12 @@ using System.Xml.Serialization;
|
|||
using SceneManager.Utils;
|
||||
using SceneManager.Menus;
|
||||
using System.IO;
|
||||
using SceneManager.Managers;
|
||||
using SceneManager.Barriers;
|
||||
using SceneManager.Waypoints;
|
||||
using SceneManager.CollectedPeds;
|
||||
|
||||
namespace SceneManager.Objects
|
||||
namespace SceneManager.Paths
|
||||
{
|
||||
[XmlRoot(ElementName = "Path", Namespace = "")]
|
||||
public class Path // Change this to Public for import/export
|
||||
|
|
@ -21,8 +25,11 @@ namespace SceneManager.Objects
|
|||
[XmlArray("Waypoints")]
|
||||
[XmlArrayItem("Waypoint")]
|
||||
public List<Waypoint> Waypoints { get; set; } = new List<Waypoint>();
|
||||
[XmlArray("Barriers")]
|
||||
[XmlArrayItem("Barrier")]
|
||||
public List<Barrier> Barriers { get; set; } = new List<Barrier>();
|
||||
internal List<CollectedPed> CollectedPeds { get; } = new List<CollectedPed>();
|
||||
private List<Vehicle> BlacklistedVehicles { get; } = new List<Vehicle>();
|
||||
internal List<Vehicle> BlacklistedVehicles { get; } = new List<Vehicle>();
|
||||
|
||||
private Path() { }
|
||||
|
||||
|
|
@ -30,6 +37,7 @@ namespace SceneManager.Objects
|
|||
{
|
||||
Number = pathNum;
|
||||
State = pathState;
|
||||
Name = Number.ToString();
|
||||
DrawLinesBetweenWaypoints();
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +50,7 @@ namespace SceneManager.Objects
|
|||
Directory.CreateDirectory(SAVED_PATHS_DIRECTORY);
|
||||
Game.LogTrivial($"New directory created at '/plugins/SceneManager/Saved Paths'");
|
||||
}
|
||||
PathXMLManager.SaveItemToXML(this, SAVED_PATHS_DIRECTORY + filename);
|
||||
Serializer.SaveItemToXML(this, SAVED_PATHS_DIRECTORY + filename);
|
||||
}
|
||||
|
||||
internal void Load()
|
||||
|
|
@ -53,6 +61,12 @@ namespace SceneManager.Objects
|
|||
{
|
||||
waypoint.LoadFromImport(this);
|
||||
}
|
||||
|
||||
Game.LogTrivial($"This path has {Barriers.Count} barriers");
|
||||
foreach(Barrier barrier in Barriers)
|
||||
{
|
||||
barrier.LoadFromImport();
|
||||
}
|
||||
DrawLinesBetweenWaypoints();
|
||||
PathManager.EndPath(this);
|
||||
}
|
||||
|
|
@ -166,98 +180,48 @@ namespace SceneManager.Objects
|
|||
int yieldAfterChecks = 50; // How many calculations to do before yielding
|
||||
while (PathManager.Paths.Contains(this))
|
||||
{
|
||||
if (IsEnabled)
|
||||
GameFiber.SleepUntil(() => IsEnabled, 0);
|
||||
|
||||
if(State == State.Deleting)
|
||||
{
|
||||
int checksDone = 0;
|
||||
try
|
||||
{
|
||||
foreach (Waypoint waypoint in Waypoints.Where(x => x != null && x.IsCollector))
|
||||
{
|
||||
foreach (Vehicle vehicle in World.GetAllVehicles())
|
||||
{
|
||||
if (VehicleIsValidForCollection(vehicle) && VehicleIsNearWaypoint(vehicle, waypoint))
|
||||
{
|
||||
CollectedPeds.Add(new CollectedPed(vehicle.Driver, this, waypoint));
|
||||
}
|
||||
Game.LogTrivial($"Path deleted, ending waypoint collection.");
|
||||
return;
|
||||
}
|
||||
|
||||
checksDone++; // Increment the counter inside the vehicle loop
|
||||
if (checksDone % yieldAfterChecks == 0)
|
||||
{
|
||||
GameFiber.Yield(); // Yield the game fiber after the specified number of vehicles have been checked
|
||||
}
|
||||
int checksDone = 0;
|
||||
var collectorWaypoints = Waypoints.Where(x => x.IsCollector);
|
||||
var vehiclesInWorld = World.GetAllVehicles().Where(x => x);
|
||||
|
||||
foreach (Waypoint waypoint in collectorWaypoints)
|
||||
{
|
||||
foreach (Vehicle vehicle in vehiclesInWorld)
|
||||
{
|
||||
if (vehicle.IsNearCollectorWaypoint(waypoint) && vehicle.IsValidForPathCollection(this))
|
||||
{
|
||||
CollectedPeds.Add(new CollectedPed(vehicle.Driver, this, waypoint));
|
||||
}
|
||||
|
||||
checksDone++; // Increment the counter inside the vehicle loop
|
||||
if (checksDone % yieldAfterChecks == 0)
|
||||
{
|
||||
GameFiber.Yield(); // Yield the game fiber after the specified number of vehicles have been checked
|
||||
if(State == State.Deleting)
|
||||
{
|
||||
Game.LogTrivial($"Path deleted, ending waypoint collection.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Game.LogTrivial($"Vehicle collection error: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
GameFiber.Sleep((int)Math.Max(1, Game.GameTime - lastProcessTime)); // If the prior lines took more than a second to run, then you'll run again almost immediately, but if they ran fairly quickly, you can sleep the loop until the remainder of the time between checks has passed
|
||||
lastProcessTime = Game.GameTime;
|
||||
}
|
||||
|
||||
bool VehicleIsNearWaypoint(Vehicle v, Waypoint wp)
|
||||
{
|
||||
return v.FrontPosition.DistanceTo2D(wp.Position) <= wp.CollectorRadius && Math.Abs(wp.Position.Z - v.Position.Z) < 3;
|
||||
}
|
||||
|
||||
bool VehicleIsValidForCollection(Vehicle v)
|
||||
{
|
||||
if(!v)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (v != Game.LocalPlayer.Character.LastVehicle && (v.IsCar || v.IsBike || v.IsBicycle || v.IsQuadBike) && !v.IsSirenOn && v.IsEngineOn && v.IsOnAllWheels && v.Speed > 1 && !CollectedPeds.Any(cp => cp && cp.CurrentVehicle == v) && !BlacklistedVehicles.Contains(v))
|
||||
{
|
||||
var vehicleCollectedOnAnotherPath = PathManager.Paths.Any(p => p.Number != Number && p.CollectedPeds.Any(cp => cp && cp.CurrentVehicle == v));
|
||||
if (vehicleCollectedOnAnotherPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (v.HasDriver && v.Driver)
|
||||
{
|
||||
if(!v.Driver.IsAlive)
|
||||
{
|
||||
Game.LogTrivial($"Vehicle's driver is dead.");
|
||||
BlacklistedVehicles.Add(v);
|
||||
return false;
|
||||
}
|
||||
if (v.IsPoliceVehicle && !v.Driver.IsAmbient())
|
||||
{
|
||||
Game.LogTrivial($"Vehicle's driver not ambient.");
|
||||
BlacklistedVehicles.Add(v);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!v.HasDriver)
|
||||
{
|
||||
v.CreateRandomDriver();
|
||||
while (!v.HasDriver)
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
if (v && v.Driver)
|
||||
{
|
||||
v.Driver.IsPersistent = true;
|
||||
v.Driver.BlockPermanentEvents = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void Delete()
|
||||
{
|
||||
State = State.Deleting;
|
||||
DismissCollectedDrivers();
|
||||
RemoveWaypoints();
|
||||
Game.LogTrivial($"Path {Number} deleted.");
|
||||
|
|
@ -63,41 +63,41 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Menus\DriverMenu.cs" />
|
||||
<Compile Include="Menus\ImportPathMenu.cs" />
|
||||
<Compile Include="SettingsValidator.cs" />
|
||||
<Compile Include="Utils\BarrierManager.cs" />
|
||||
<Compile Include="Managers\BarrierManager.cs" />
|
||||
<Compile Include="Utils\ConsoleCommands.cs" />
|
||||
<Compile Include="Utils\DeleteAllPaths.cs" />
|
||||
<Compile Include="Utils\DependencyChecker.cs" />
|
||||
<Compile Include="Utils\TogglePaths.cs" />
|
||||
<Compile Include="Utils\DismissDriver.cs" />
|
||||
<Compile Include="Utils\Enums.cs" />
|
||||
<Compile Include="Utils\Extensions.cs" />
|
||||
<Compile Include="Objects\CollectedPed.cs" />
|
||||
<Compile Include="Objects\Barrier.cs" />
|
||||
<Compile Include="CollectedPeds\CollectedPed.cs" />
|
||||
<Compile Include="Barriers\Barrier.cs" />
|
||||
<Compile Include="Utils\Hints.cs" />
|
||||
<Compile Include="Menus\BarrierMenu.cs" />
|
||||
<Compile Include="Menus\EditPathMenu.cs" />
|
||||
<Compile Include="Menus\EditWaypointMenu.cs" />
|
||||
<Compile Include="EntryPoint.cs" />
|
||||
<Compile Include="Utils\PathManager.cs" />
|
||||
<Compile Include="Managers\PathManager.cs" />
|
||||
<Compile Include="Utils\DirectDriver.cs" />
|
||||
<Compile Include="Utils\UserInput.cs" />
|
||||
<Compile Include="Menus\MainMenu.cs" />
|
||||
<Compile Include="Menus\MenuManager.cs" />
|
||||
<Compile Include="Objects\Path.cs" />
|
||||
<Compile Include="Managers\MenuManager.cs" />
|
||||
<Compile Include="Paths\Path.cs" />
|
||||
<Compile Include="Menus\PathCreationMenu.cs" />
|
||||
<Compile Include="Utils\PathXMLManager.cs" />
|
||||
<Compile Include="Utils\Serializer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Menus\PathMainMenu.cs" />
|
||||
<Compile Include="Menus\SettingsMenu.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="Objects\Waypoint.cs" />
|
||||
<Compile Include="Waypoints\Waypoint.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="AfterCompile">
|
||||
<Exec Command="if "$(ConfigurationName)" == "Release" ("$(ProjectDir)_ConfuserEx\Confuser.CLI.exe" "$(ProjectDir)_ConfuserEx\c.crproj")
" />
|
||||
|
|
|
|||
|
|
@ -1,134 +0,0 @@
|
|||
using Rage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SceneManager.Utils
|
||||
{
|
||||
internal static class PathXMLManager
|
||||
{
|
||||
private static Dictionary<Type, XmlSerializer> _serializerCache = new Dictionary<Type, XmlSerializer>();
|
||||
private static XmlSerializer _getOrCreateSerializer<T>(XmlAttributeOverrides overrides = null)
|
||||
{
|
||||
if (_serializerCache.ContainsKey(typeof(T)))
|
||||
{
|
||||
Game.LogTrivialDebug("Serializer cache already contains " + typeof(T).Name);
|
||||
return _serializerCache[typeof(T)];
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.LogTrivialDebug("Adding " + typeof(T).Name + " to serializer cache");
|
||||
Game.LogTrivialDebug("Overrides specified: " + (overrides != null));
|
||||
var s = new XmlSerializer(typeof(T), new XmlRootAttribute("Path"));
|
||||
//var s = new XmlSerializer(typeof(T), overrides);
|
||||
_serializerCache.Add(typeof(T), s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveToNode(string file, string node, string value)
|
||||
{
|
||||
XmlNode n = SelectNodeFromXml(file, node);
|
||||
|
||||
if (n == null) throw new KeyNotFoundException($"{nameof(SaveToNode)}: specified node does not exists!");
|
||||
|
||||
n.InnerText = value;
|
||||
var doc = new XmlDocument();
|
||||
doc.Save(file);
|
||||
}
|
||||
|
||||
public static string ReadFromNode(string file, string node)
|
||||
{
|
||||
return SelectNodeFromXml(file, node).InnerText;
|
||||
}
|
||||
|
||||
private static XmlNode SelectNodeFromXml(string filePath, string node)
|
||||
{
|
||||
if (!File.Exists(filePath)) throw new FileNotFoundException($"{nameof(SelectNodeFromXml)}(): specified file does not exist: {filePath}");
|
||||
|
||||
using (TextReader reader = new StreamReader(filePath))
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
doc.Load(reader);
|
||||
return doc.SelectSingleNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<T> LoadAllXML<T>(string dirPath, SearchOption searchOption = SearchOption.AllDirectories)
|
||||
{
|
||||
if (!Directory.Exists(dirPath)) throw new DirectoryNotFoundException($"{nameof(LoadAllXML)}(): specified directory could not be found: {dirPath}");
|
||||
|
||||
string[] files = Directory.GetFiles(dirPath, "*.xml", searchOption);
|
||||
|
||||
List<T> result = new List<T>();
|
||||
|
||||
Array.ForEach(files, f => result.AddRange(LoadFromXML<T>(f)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void SaveToXML<T>(List<T> list, string filePath)
|
||||
{
|
||||
SaveItemToXML(list, filePath);
|
||||
}
|
||||
|
||||
public static void SaveItemToXML<T>(T item, string path, XmlAttributeOverrides overrides)
|
||||
{
|
||||
Encoding utf8NoBom = new UTF8Encoding(false);
|
||||
using (TextWriter writer = new StreamWriter(path, false, utf8NoBom))
|
||||
{
|
||||
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
|
||||
ns.Add("", "");
|
||||
|
||||
// new XmlSerializer(typeof(T)).Serialize(writer, item);
|
||||
_getOrCreateSerializer<T>(overrides).Serialize(writer, item, ns);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveItemToXML<T>(T item, string path)
|
||||
{
|
||||
SaveItemToXML<T>(item, path, null);
|
||||
}
|
||||
|
||||
public static T LoadItemFromXML<T>(string filePath, XmlAttributeOverrides overrides)
|
||||
{
|
||||
if (!File.Exists(filePath)) throw new FileNotFoundException($"{nameof(LoadItemFromXML)}(): specified file does not exist: {filePath}");
|
||||
|
||||
using (TextReader reader = new StreamReader(filePath))
|
||||
{
|
||||
return (T)_getOrCreateSerializer<T>(overrides).Deserialize(reader);
|
||||
}
|
||||
}
|
||||
|
||||
public static T LoadItemFromXML<T>(string filePath)
|
||||
{
|
||||
return (T)LoadItemFromXML<T>(filePath, null);
|
||||
}
|
||||
|
||||
public static void ModifyItemInXML<T>(string filePath, Action<T> modification)
|
||||
{
|
||||
T item = LoadItemFromXML<T>(filePath);
|
||||
modification(item);
|
||||
SaveItemToXML<T>(item, filePath);
|
||||
}
|
||||
|
||||
public static T GetSelectedListElementFromXml<T>(string file, Func<List<T>, T> selector)
|
||||
{
|
||||
List<T> deserialized = LoadItemFromXML<List<T>>(file);
|
||||
return selector(deserialized);
|
||||
}
|
||||
|
||||
public static List<T> LoadFromXML<T>(string filePath)
|
||||
{
|
||||
return LoadItemFromXML<List<T>>(filePath);
|
||||
}
|
||||
|
||||
public static void AppendToXML<T>(T objectToAdd, string path)
|
||||
{
|
||||
ModifyItemInXML<List<T>>(path, t => t.Add(objectToAdd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
using Rage;
|
||||
|
||||
namespace SceneManager.Utils
|
||||
{
|
||||
internal static class TogglePaths
|
||||
{
|
||||
internal static void Toggle(bool disable)
|
||||
{
|
||||
if (disable)
|
||||
{
|
||||
PathManager.Paths.ForEach(x => x.DisablePath());
|
||||
Game.LogTrivial($"All paths disabled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
PathManager.Paths.ForEach(x => x.EnablePath());
|
||||
Game.LogTrivial($"All paths enabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,11 @@ using System.Drawing;
|
|||
using System.Linq;
|
||||
using SceneManager.Utils;
|
||||
using SceneManager.Menus;
|
||||
using SceneManager.Managers;
|
||||
using SceneManager.Paths;
|
||||
using SceneManager.CollectedPeds;
|
||||
|
||||
namespace SceneManager.Objects
|
||||
namespace SceneManager.Waypoints
|
||||
{
|
||||
public class Waypoint // Change this and select properties to Public for import/export
|
||||
{
|
||||
|
|
@ -77,7 +80,6 @@ namespace SceneManager.Objects
|
|||
Blip.Color = Color.Green;
|
||||
foreach(CollectedPed cp in Path.CollectedPeds.Where(cp => cp.CurrentVehicle && cp.Path == Path && cp.CurrentWaypoint == this && cp.StoppedAtWaypoint))
|
||||
{
|
||||
// Logger.Log($"Setting StoppedAtWaypoint to false for {cv.Vehicle.Model.Name}");
|
||||
cp.Dismiss(Dismiss.FromWaypoint);
|
||||
}
|
||||
}
|
||||
|
|
@ -157,15 +159,9 @@ namespace SceneManager.Objects
|
|||
}
|
||||
}
|
||||
|
||||
internal void AddSpeedZone()
|
||||
{
|
||||
SpeedZone = World.AddSpeedZone(Position, SpeedZoneRadius, Speed);
|
||||
}
|
||||
internal void AddSpeedZone() => SpeedZone = World.AddSpeedZone(Position, SpeedZoneRadius, Speed);
|
||||
|
||||
internal void RemoveSpeedZone()
|
||||
{
|
||||
World.RemoveSpeedZone(SpeedZone);
|
||||
}
|
||||
internal void RemoveSpeedZone() => World.RemoveSpeedZone(SpeedZone);
|
||||
|
||||
internal void DrawWaypointMarker()
|
||||
{
|
||||
|
|
@ -176,7 +172,7 @@ namespace SceneManager.Objects
|
|||
{
|
||||
if(SettingsMenu.ThreeDWaypoints.Checked && EnableWaypointMarker && Path.Waypoints.Contains(this))
|
||||
{
|
||||
if (EditWaypointMenu.Menu.Visible && PathMainMenu.EditPath.Value == Path.Number && EditWaypointMenu.EditWaypoint.Value == Number)
|
||||
if (EditWaypointMenu.Menu.Visible && PathMainMenu.EditPath.OptionText == Path.Name && EditWaypointMenu.EditWaypoint.Value == Number)
|
||||
{
|
||||
if (EditWaypointMenu.CollectorWaypoint.Checked)
|
||||
{
|
||||
|
|
@ -208,7 +204,7 @@ namespace SceneManager.Objects
|
|||
else if ((Path.State == State.Finished && MenuManager.MenuPool.IsAnyMenuOpen()) || (Path.State == State.Creating && PathCreationMenu.Menu.Visible))
|
||||
{
|
||||
float markerHeight = 1f;
|
||||
if ((PathMainMenu.DirectDriver.Selected && PathMainMenu.DirectDriver.Value == Path.Number) || PathMainMenu.EditPath.Selected && PathMainMenu.EditPath.Value == Path.Number && (PathMainMenu.Menu.Visible || EditPathMenu.Menu.Visible))
|
||||
if ((DriverMenu.DirectDriver.Selected && DriverMenu.DirectDriver.OptionText == Path.Name) || PathMainMenu.EditPath.Selected && PathMainMenu.EditPath.OptionText == Path.Name && (PathMainMenu.Menu.Visible || EditPathMenu.Menu.Visible))
|
||||
{
|
||||
markerHeight = 2f;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue