1
Fork 0
mirror of https://github.com/thegeneralist01/Scene-Manager-DevRepo synced 2026-01-10 15:20:29 +01:00
* Add API

* Added API

* Updated version

* Updated RNUI

* Added checks for null paths

* BelongsToPath menu item now toggles on/off depending if any paths exist
This commit is contained in:
Rich 2021-08-03 11:07:14 -06:00 committed by GitHub
parent d118513185
commit 56a770b718
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 63 additions and 22 deletions

View file

@ -0,0 +1,34 @@
using Rage;
using SceneManager.Managers;
namespace SceneManager.API
{
public static class Functions
{
/// <summary>
/// Import paths from the Saved Paths folder and load them into the game world.
/// </summary>
/// <param name="fileName">The name of the file containing the path (extension excluded).</param>
/// <param name="filePath">Specify the path from where the file will be loaded from.</param>
public static void LoadPathsFromFile(string fileName, string filePath = "")
{
if(PathManager.ImportedPaths.ContainsKey(fileName))
{
Game.LogTrivial($"A file with that name is already loaded.");
return;
}
var importedPaths = PathManager.ImportPathsFromFile(fileName, filePath);
PathManager.LoadImportedPaths(importedPaths, fileName);
}
/// <summary>
/// Delete paths loaded from <see cref="LoadPathsFromFile"/>.
/// </summary>
public static void DeleteLoadedPaths()
{
PathManager.DeleteAllPaths();
PathManager.ImportedPaths.Clear();
}
}
}

View file

@ -149,7 +149,7 @@ namespace SceneManager.Managers
if (barrier != null && BarrierMenu.BelongsToPath.Checked)
{
var matchingPath = PathManager.Paths.FirstOrDefault(x => x.Name == BarrierMenu.AddToPath.OptionText);
var matchingPath = PathManager.Paths.FirstOrDefault(x => x != null && x.Name == BarrierMenu.AddToPath.OptionText);
if(matchingPath != null)
{
matchingPath.Barriers.Add(barrier);
@ -257,7 +257,7 @@ namespace SceneManager.Managers
return;
}
var pathToAssignTo = PathManager.Paths.First(x => x.Name == BarrierMenu.AddUnassignedToPath.OptionText);
var pathToAssignTo = PathManager.Paths.First(x => x != null && x.Name == BarrierMenu.AddUnassignedToPath.OptionText);
foreach (Barrier barrier in unassignedBarriers)
{
pathToAssignTo.Barriers.Add(barrier);

View file

@ -54,7 +54,7 @@ namespace SceneManager.Managers
internal static void UpdateWaypoint()
{
var currentPath = Paths.FirstOrDefault(x => x.Name == PathMainMenu.EditPath.OptionText);
var currentPath = Paths.FirstOrDefault(x => x != null && x.Name == PathMainMenu.EditPath.OptionText);
var currentWaypoint = currentPath.Waypoints[EditWaypointMenu.EditWaypoint.Index];
DrivingFlagType drivingFlag = EditWaypointMenu.DirectWaypointBehavior.Checked ? DrivingFlagType.Direct : DrivingFlagType.Normal;
@ -198,27 +198,33 @@ namespace SceneManager.Managers
Menus.MainMenu.Build();
}
internal static List<Paths.Path> ImportPathsFromFile(string file)
internal static List<Paths.Path> ImportPathsFromFile(string fileName, string filePath = "")
{
List<Paths.Path> importedPaths;
var GAME_DIRECTORY = Directory.GetCurrentDirectory();
var SAVED_PATHS_DIRECTORY = GAME_DIRECTORY + "\\plugins\\SceneManager\\Saved Paths\\";
if (!Directory.Exists(SAVED_PATHS_DIRECTORY))
var PATH_FILE_DIRECTORY = GAME_DIRECTORY + "\\plugins\\SceneManager\\Saved Paths\\";
if(filePath != "")
{
Game.LogTrivial($"Directory '\\plugins\\SceneManager\\Saved Paths' does not exist. No paths available to import.");
PATH_FILE_DIRECTORY = filePath;
}
if (!Directory.Exists(PATH_FILE_DIRECTORY))
{
Game.LogTrivial($"Directory {PATH_FILE_DIRECTORY} does not exist. No paths available to import.");
return null;
}
List<Paths.Path> importedPaths;
var overrides = Serializer.DefineOverrides();
try
{
importedPaths = Serializer.LoadItemFromXML<List<Paths.Path>>(SAVED_PATHS_DIRECTORY + Path.GetFileName(file) + ".xml", overrides);
ImportedPaths.Add(file, importedPaths);
importedPaths = Serializer.LoadItemFromXML<List<Paths.Path>>(PATH_FILE_DIRECTORY + Path.GetFileName(fileName) + ".xml", overrides);
ImportedPaths.Add(fileName, importedPaths);
}
catch (Exception ex)
{
Game.DisplayNotification($"~y~Scene Manager ~w~[~r~ERROR~w~]: There was a problem importing file ~b~{file}~w~. This is likely due to an XML error. Double check any changes you've made to this file.");
Game.DisplayNotification($"~y~Scene Manager ~w~[~r~ERROR~w~]: There was a problem importing file ~b~{fileName}~w~. This is likely due to an XML error. Double check any changes you've made to this file.");
Game.LogTrivial($"Error: {ex.Message}");
return null;
}
@ -238,7 +244,7 @@ namespace SceneManager.Managers
if (Game.IsKeyDown(Keys.Y))
{
var pathToReplace = Paths.First(x => x.Name == path.Name);
var pathToReplace = Paths.First(x => x != null && x.Name == path.Name);
var pathToReplaceIndex = Array.IndexOf(Paths, pathToReplace);
pathToReplace.Delete();
Paths[pathToReplaceIndex] = path;

View file

@ -61,7 +61,7 @@ namespace SceneManager.Menus
//setBarrierTrafficLight.Index = 3;
}
Menu.AddItem(BelongsToPath);
BelongsToPath.Enabled = PathManager.Paths.Count() > 0 ? true : false;
BelongsToPath.Enabled = PathManager.Paths.Any(x => x != null);
BelongsToPath.Checked = false;
AddToPath = new UIMenuListScrollerItem<string>("Path", "The path the barrier will be saved with when the path is exported.", PathManager.Paths.Where(x => x != null).Select(x => x.Name));

View file

@ -80,7 +80,7 @@ namespace SceneManager
if (checkboxItem == DisablePath)
{
//var currentPath = PathManager.Paths[PathMainMenu.EditPath.Index];
var currentPath = PathManager.Paths.FirstOrDefault(x => x.Name == PathMainMenu.EditPath.OptionText);
var currentPath = PathManager.Paths.FirstOrDefault(x => x != null && x.Name == PathMainMenu.EditPath.OptionText);
if(currentPath == null)
{
return;

View file

@ -89,7 +89,7 @@ namespace SceneManager.Menus
var checkedItems = checkboxItems.Where(x => x.Checked);
foreach(UIMenuCheckboxItem checkedItem in checkedItems)
{
var pathToExport = PathManager.Paths.First(x => x.Name == checkedItem.Text);
var pathToExport = PathManager.Paths.First(x => x != null && x.Name == checkedItem.Text);
ExportPaths.Add(pathToExport);
}
@ -97,7 +97,7 @@ namespace SceneManager.Menus
{
foreach (UIMenuCheckboxItem menuItem in checkedItems)
{
var pathToExport = PathManager.Paths.First(x => x.Name == menuItem.Text);
var pathToExport = PathManager.Paths.First(x => x != null && x.Name == menuItem.Text);
ExportAsIndividualFile(pathToExport);
}
}

View file

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.2.0")]
[assembly: AssemblyFileVersion("2.3.2.0")]
[assembly: AssemblyVersion("2.3.3.0")]
[assembly: AssemblyFileVersion("2.3.3.0")]

View file

@ -36,8 +36,8 @@
<Reference Include="InputManager, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\InputManager.1.0.0\lib\InputManager.dll</HintPath>
</Reference>
<Reference Include="RAGENativeUI, Version=1.8.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\RAGENativeUI.1.8.0\lib\net472\RAGENativeUI.dll</HintPath>
<Reference Include="RAGENativeUI, Version=1.8.1.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\RAGENativeUI.1.8.1\lib\net472\RAGENativeUI.dll</HintPath>
</Reference>
<Reference Include="RagePluginHook, Version=0.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\RagePluginHook.1.86.1\lib\net472\RagePluginHook.dll</HintPath>
@ -62,6 +62,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="API\Functions.cs" />
<Compile Include="Menus\DriverMenu.cs" />
<Compile Include="Menus\ExportPathMenu.cs" />
<Compile Include="Menus\ImportPathMenu.cs" />

View file

@ -13,8 +13,8 @@
</rule>
</module>
<probePath>..\..\..\packages\InputManager.1.0.0\lib</probePath>
<probePath>..\..\..\packages\RAGENativeUI.1.8.0\lib\net472</probePath>
<probePath>..\..\..\packages\RagePluginHook.1.86.1\lib\net472</probePath>
<probePath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8</probePath>
<probePath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades</probePath>
<probePath>..\..\..\packages\RAGENativeUI.1.8.1\lib\net472</probePath>
</project>

View file

@ -2,6 +2,6 @@
<packages>
<package id="InputManager" version="1.0.0" targetFramework="net48" />
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net48" />
<package id="RAGENativeUI" version="1.8.0" targetFramework="net48" />
<package id="RAGENativeUI" version="1.8.1" targetFramework="net48" />
<package id="RagePluginHook" version="1.86.1" targetFramework="net48" />
</packages>