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
|
|
@ -1,228 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Rage;
|
||||
using SceneManager.Menus;
|
||||
using SceneManager.Objects;
|
||||
|
||||
namespace SceneManager.Utils
|
||||
{
|
||||
internal static class BarrierManager
|
||||
{
|
||||
internal static Object PlaceholderBarrier { get; private set; }
|
||||
internal static List<Barrier> Barriers { get; } = new List<Barrier>();
|
||||
|
||||
internal static void CreatePlaceholderBarrier()
|
||||
{
|
||||
Hints.Display($"~o~Scene Manager ~y~[Hint]\n~w~The shadow barrier will disappear if you aim too far away.");
|
||||
if (PlaceholderBarrier)
|
||||
{
|
||||
PlaceholderBarrier.Delete();
|
||||
}
|
||||
|
||||
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);
|
||||
if (!PlaceholderBarrier)
|
||||
{
|
||||
BarrierMenu.Menu.Close();
|
||||
Game.LogTrivial($"Something went wrong creating the placeholder barrier. Mouse position: {UserInput.GetMousePositionForBarrier}");
|
||||
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;
|
||||
}
|
||||
|
||||
//Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(shadowBarrier, setBarrierTrafficLight.Index);
|
||||
Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(PlaceholderBarrier);
|
||||
PlaceholderBarrier.IsGravityDisabled = true;
|
||||
PlaceholderBarrier.IsCollisionEnabled = false;
|
||||
PlaceholderBarrier.Opacity = 0.7f;
|
||||
|
||||
// Start with lights off for Parks's objects
|
||||
if (Settings.EnableAdvancedBarricadeOptions)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.x971DA0055324D033(PlaceholderBarrier, BarrierMenu.BarrierTexture.Value); // _SET_OBJECT_TEXTURE_VARIATION
|
||||
SetBarrierLights();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetBarrierLights()
|
||||
{
|
||||
if (BarrierMenu.SetBarrierLights.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(PlaceholderBarrier, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_LIGHTS(PlaceholderBarrier, true);
|
||||
}
|
||||
|
||||
//Rage.Native.NativeFunction.Natives.SET_ENTITY_TRAFFICLIGHT_OVERRIDE(shadowBarrier, setBarrierTrafficLight.Index);
|
||||
}
|
||||
|
||||
internal static void UpdatePlaceholderBarrierPosition()
|
||||
{
|
||||
DisableBarrierMenuOptionsIfShadowConeTooFar();
|
||||
if (PlaceholderBarrier)
|
||||
{
|
||||
PlaceholderBarrier.Heading = BarrierMenu.RotateBarrier.Value;
|
||||
PlaceholderBarrier.Position = UserInput.GetMousePositionForBarrier;
|
||||
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)
|
||||
{
|
||||
CreatePlaceholderBarrier();
|
||||
|
||||
}
|
||||
else if (PlaceholderBarrier && PlaceholderBarrier.Position.DistanceTo2D(Game.LocalPlayer.Character.Position) > Settings.BarrierPlacementDistance)
|
||||
{
|
||||
BarrierMenu.BarrierList.Enabled = false;
|
||||
BarrierMenu.RotateBarrier.Enabled = false;
|
||||
PlaceholderBarrier.Delete();
|
||||
}
|
||||
else if (PlaceholderBarrier && PlaceholderBarrier.Position.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance && BarrierMenu.BarrierList.SelectedItem == "Flare")
|
||||
{
|
||||
BarrierMenu.BarrierList.Enabled = true;
|
||||
BarrierMenu.RotateBarrier.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
BarrierMenu.BarrierList.Enabled = true;
|
||||
BarrierMenu.RotateBarrier.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void LoopToRenderPlaceholderBarrier()
|
||||
{
|
||||
while (BarrierMenu.Menu.Visible)
|
||||
{
|
||||
if (BarrierMenu.BarrierList.Selected || BarrierMenu.RotateBarrier.Selected || BarrierMenu.Invincible.Selected || BarrierMenu.Immobile.Selected || BarrierMenu.BarrierTexture.Selected || BarrierMenu.SetBarrierLights.Selected || BarrierMenu.SetBarrierTrafficLight.Selected)
|
||||
{
|
||||
if (PlaceholderBarrier)
|
||||
{
|
||||
//UpdatePlaceholderBarrierPosition();
|
||||
UpdatePlaceholderBarrierPosition();
|
||||
}
|
||||
else if (UserInput.GetMousePositionForBarrier.DistanceTo2D(Game.LocalPlayer.Character.Position) <= Settings.BarrierPlacementDistance)
|
||||
{
|
||||
//CreatePlaceholderBarrier();
|
||||
CreatePlaceholderBarrier();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PlaceholderBarrier)
|
||||
{
|
||||
PlaceholderBarrier.Delete();
|
||||
}
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
|
||||
if (PlaceholderBarrier)
|
||||
{
|
||||
PlaceholderBarrier.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SpawnBarrier()
|
||||
{
|
||||
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);
|
||||
Barriers.Add(barrier);
|
||||
|
||||
BarrierMenu.RemoveBarrierOptions.Enabled = true;
|
||||
BarrierMenu.ResetBarriers.Enabled = true;
|
||||
}
|
||||
|
||||
void SpawnFlare()
|
||||
{
|
||||
var flare = new Weapon("weapon_flare", PlaceholderBarrier.Position, 1);
|
||||
Rage.Native.NativeFunction.Natives.SET_ENTITY_DYNAMIC(flare, true);
|
||||
GameFiber.Sleep(1);
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
while (flare && flare.HeightAboveGround > 0.05f)
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
GameFiber.Sleep(1000);
|
||||
if (flare)
|
||||
{
|
||||
flare.IsPositionFrozen = true;
|
||||
}
|
||||
}, "Spawn Flare Fiber");
|
||||
|
||||
Barriers.Add(new Barrier(flare, flare.Position, flare.Heading, BarrierMenu.Invincible.Checked, BarrierMenu.Immobile.Checked));
|
||||
BarrierMenu.RemoveBarrierOptions.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RemoveBarrier(int removeBarrierOptionsIndex)
|
||||
{
|
||||
switch (removeBarrierOptionsIndex)
|
||||
{
|
||||
case 0:
|
||||
Barriers[Barriers.Count - 1].Delete();
|
||||
Barriers.RemoveAt(Barriers.Count - 1);
|
||||
break;
|
||||
case 1:
|
||||
var nearestBarrier = Barriers.OrderBy(b => b.DistanceTo2D(Game.LocalPlayer.Character)).FirstOrDefault();
|
||||
if (nearestBarrier != null)
|
||||
{
|
||||
nearestBarrier.Delete();
|
||||
Barriers.Remove(nearestBarrier);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
foreach (Barrier b in Barriers)
|
||||
{
|
||||
b.Delete();
|
||||
}
|
||||
if (Barriers.Count > 0)
|
||||
{
|
||||
Barriers.Clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
BarrierMenu.RemoveBarrierOptions.Enabled = Barriers.Count == 0 ? false : true;
|
||||
BarrierMenu.ResetBarriers.Enabled = Barriers.Count == 0 ? false : true;
|
||||
}
|
||||
|
||||
internal static void ResetBarriers()
|
||||
{
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
var currentBarriers = Barriers.Where(b => b.Model.Name != "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));
|
||||
|
||||
if (barrier)
|
||||
{
|
||||
barrier.Delete();
|
||||
}
|
||||
Barriers.Remove(barrier);
|
||||
}
|
||||
currentBarriers.Clear();
|
||||
}, "Barrier Reset Fiber");
|
||||
|
||||
}
|
||||
|
||||
internal static void RotateBarrier()
|
||||
{
|
||||
PlaceholderBarrier.Heading = BarrierMenu.RotateBarrier.Value;
|
||||
PlaceholderBarrier.Position = UserInput.GetMousePositionForBarrier;
|
||||
Rage.Native.NativeFunction.Natives.PLACE_OBJECT_ON_GROUND_PROPERLY(PlaceholderBarrier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,258 +0,0 @@
|
|||
using Rage;
|
||||
using RAGENativeUI.Elements;
|
||||
using SceneManager.Menus;
|
||||
using SceneManager.Objects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SceneManager.Utils
|
||||
{
|
||||
internal class PathManager
|
||||
{
|
||||
internal static List<Path> Paths { get; } = new List<Path>(10);
|
||||
|
||||
internal static Path ImportPath(Path importedPath)
|
||||
{
|
||||
importedPath.State = State.Creating;
|
||||
|
||||
var firstVacantIndex = Paths.IndexOf(Paths.FirstOrDefault(x => x.State != State.Creating)) + 1;
|
||||
if (firstVacantIndex < 0)
|
||||
{
|
||||
firstVacantIndex = 0;
|
||||
}
|
||||
var pathNumber = firstVacantIndex + 1;
|
||||
|
||||
importedPath.Number = pathNumber;
|
||||
Paths.Insert(firstVacantIndex, importedPath);
|
||||
|
||||
Game.LogTrivial($"Importing path {importedPath.Number} at Paths index {firstVacantIndex}");
|
||||
Game.DisplayNotification($"~o~Scene Manager ~y~[Importing]\n~w~Path {importedPath.Number} import started.");
|
||||
|
||||
return importedPath;
|
||||
}
|
||||
|
||||
internal static void ExportPath()
|
||||
{
|
||||
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";
|
||||
|
||||
// If filename != null or empty, check if export directory exists (GTA V/Plugins/SceneManager/Saved Paths)
|
||||
if (string.IsNullOrWhiteSpace(filename))
|
||||
{
|
||||
Game.DisplayHelp($"Invalid filename given. Filename cannot be null, empty, or consist of just white spaces.");
|
||||
Game.LogTrivial($"Invalid filename given. Filename cannot be null, empty, or consist of just white spaces.");
|
||||
return;
|
||||
}
|
||||
Game.LogTrivial($"Filename: {filename}");
|
||||
currentPath.Save(filename);
|
||||
currentPath.Name = filename.Remove(filename.Length - 4);
|
||||
Game.LogTrivial($"Path name: {currentPath.Name}");
|
||||
Game.LogTrivial($"Exporting path {currentPath.Number}");
|
||||
Game.DisplayNotification($"~o~Scene Manager ~y~[Exporting]\n~w~Path {currentPath.Number} exported.");
|
||||
Settings.ImportPaths();
|
||||
PathMainMenu.ImportPath.Enabled = true;
|
||||
ImportPathMenu.BuildImportMenu();
|
||||
}
|
||||
|
||||
internal static Path InitializeNewPath()
|
||||
{
|
||||
PathCreationMenu.PathCreationState = State.Creating;
|
||||
|
||||
var firstVacantIndex = Paths.IndexOf(Paths.FirstOrDefault(x => x.State != State.Creating)) + 1;
|
||||
if(firstVacantIndex < 0)
|
||||
{
|
||||
firstVacantIndex = 0;
|
||||
}
|
||||
var pathNumber = firstVacantIndex + 1;
|
||||
|
||||
Path newPath = new Path(pathNumber, State.Creating);
|
||||
Paths.Insert(firstVacantIndex, newPath);
|
||||
|
||||
Game.LogTrivial($"Creating path {newPath.Number} at Paths index {firstVacantIndex}");
|
||||
Game.DisplayNotification($"~o~Scene Manager ~y~[Creating]\n~w~Path {newPath.Number} started.");
|
||||
|
||||
PathCreationMenu.RemoveLastWaypoint.Enabled = false;
|
||||
PathCreationMenu.EndPathCreation.Enabled = false;
|
||||
|
||||
return newPath;
|
||||
}
|
||||
|
||||
internal static void AddWaypoint(Path currentPath)
|
||||
{
|
||||
var waypointNumber = currentPath.Waypoints.Count + 1;
|
||||
DrivingFlagType drivingFlag = PathCreationMenu.DirectWaypoint.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
newWaypoint = new Waypoint(currentPath, waypointNumber, UserInput.GetMousePosition, SetDriveSpeedForWaypoint(), 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}]");
|
||||
|
||||
if(currentPath.Waypoints.Count == 1)
|
||||
{
|
||||
PathMainMenu.CreateNewPath.Text = $"Continue Creating Path {currentPath.Number}";
|
||||
}
|
||||
}
|
||||
|
||||
internal static void AddNewEditWaypoint(Path currentPath)
|
||||
{
|
||||
DrivingFlagType drivingFlag = EditWaypointMenu.DirectWaypointBehavior.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
|
||||
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPath.Waypoints.Add(new Waypoint(currentPath, currentPath.Waypoints.Last().Number + 1, UserInput.GetMousePosition, SetDriveSpeedForWaypoint(), drivingFlag, EditWaypointMenu.StopWaypointType.Checked));
|
||||
}
|
||||
Game.LogTrivial($"New waypoint (#{currentPath.Waypoints.Last().Number}) added.");
|
||||
}
|
||||
|
||||
internal static void UpdateWaypoint()
|
||||
{
|
||||
var currentPath = Paths[PathMainMenu.EditPath.Index];
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentWaypoint.UpdateWaypoint(currentWaypoint, UserInput.GetMousePosition, drivingFlag, EditWaypointMenu.StopWaypointType.Checked, SetDriveSpeedForWaypoint(), 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}]");
|
||||
|
||||
EditWaypointMenu.UpdateWaypointPosition.Checked = false;
|
||||
Game.DisplayNotification($"~o~Scene Manager ~g~[Success]~w~\nWaypoint {currentWaypoint.Number} updated.");
|
||||
}
|
||||
|
||||
private static float SetDriveSpeedForWaypoint()
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
return convertedSpeed;
|
||||
}
|
||||
|
||||
internal static void RemoveWaypoint(Path currentPath)
|
||||
{
|
||||
Waypoint lastWaypoint = currentPath.Waypoints.Last();
|
||||
lastWaypoint.Delete();
|
||||
currentPath.Waypoints.Remove(lastWaypoint);
|
||||
}
|
||||
|
||||
internal static void RemoveEditWaypoint(Path currentPath)
|
||||
{
|
||||
var currentWaypoint = currentPath.Waypoints[EditWaypointMenu.EditWaypoint.Index];
|
||||
if (currentPath.Waypoints.Count == 1)
|
||||
{
|
||||
Game.LogTrivial($"Deleting the last waypoint from the path.");
|
||||
currentPath.Delete();
|
||||
Paths.Remove(currentPath);
|
||||
PathMainMenu.BuildPathMenu();
|
||||
|
||||
EditWaypointMenu.Menu.Visible = false;
|
||||
PathMainMenu.Menu.Visible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
currentWaypoint.Delete();
|
||||
currentPath.Waypoints.Remove(currentWaypoint);
|
||||
Game.LogTrivial($"[Path {currentPath.Number}] Waypoint {currentWaypoint.Number} ({currentWaypoint.DrivingFlagType}) removed");
|
||||
currentPath.Waypoints.ForEach(x => x.Number = currentPath.Waypoints.IndexOf(x) + 1);
|
||||
|
||||
DefaultWaypointToCollector(currentPath);
|
||||
}
|
||||
|
||||
private static void DefaultWaypointToCollector(Path currentPath)
|
||||
{
|
||||
if (currentPath.Waypoints.Count == 1)
|
||||
{
|
||||
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);
|
||||
EditWaypointMenu.CollectorWaypoint.Checked = true;
|
||||
EditWaypointMenu.ChangeCollectorRadius.Enabled = true;
|
||||
EditWaypointMenu.ChangeSpeedZoneRadius.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void EndPath(Path currentPath)
|
||||
{
|
||||
Game.LogTrivial($"[Path Creation] Path {currentPath.Number} finished with {currentPath.Waypoints.Count} waypoints.");
|
||||
Game.DisplayNotification($"~o~Scene Manager ~g~[Success]\n~w~Path {currentPath.Number} complete.");
|
||||
currentPath.State = State.Finished;
|
||||
currentPath.IsEnabled = true;
|
||||
currentPath.Waypoints.ForEach(x => x.EnableBlip());
|
||||
GameFiber.StartNew(() => currentPath.LoopForVehiclesToBeDismissed(), "Vehicle Cleanup Loop Fiber");
|
||||
GameFiber.StartNew(() => currentPath.LoopWaypointCollection(), "Waypoint Collection Loop Fiber");
|
||||
|
||||
PathMainMenu.CreateNewPath.Text = "Create New Path";
|
||||
PathMainMenu.BuildPathMenu();
|
||||
PathMainMenu.Menu.Visible = true;
|
||||
}
|
||||
|
||||
internal static void TogglePathCreationMenuItems(Path currentPath)
|
||||
{
|
||||
if(currentPath.Waypoints.Count == 1)
|
||||
{
|
||||
PathCreationMenu.CollectorWaypoint.Enabled = true;
|
||||
PathCreationMenu.CollectorWaypoint.Checked = false;
|
||||
PathCreationMenu.RemoveLastWaypoint.Enabled = true;
|
||||
PathCreationMenu.EndPathCreation.Enabled = true;
|
||||
}
|
||||
|
||||
if (currentPath.Waypoints.Count < 1)
|
||||
{
|
||||
PathCreationMenu.CollectorWaypoint.Enabled = false;
|
||||
PathCreationMenu.CollectorWaypoint.Checked = true;
|
||||
PathCreationMenu.RemoveLastWaypoint.Enabled = false;
|
||||
PathCreationMenu.EndPathCreation.Enabled = false;
|
||||
}
|
||||
|
||||
if (PathCreationMenu.CollectorWaypoint.Checked)
|
||||
{
|
||||
PathCreationMenu.CollectorRadius.Enabled = true;
|
||||
PathCreationMenu.SpeedZoneRadius.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
PathCreationMenu.CollectorRadius.Enabled = false;
|
||||
PathCreationMenu.SpeedZoneRadius.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ToggleBlips(bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
Paths.SelectMany(x => x.Waypoints).ToList().ForEach(x => x.EnableBlip());
|
||||
}
|
||||
else
|
||||
{
|
||||
Paths.SelectMany(x => x.Waypoints).ToList().ForEach(x => x.DisableBlip());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue