From af2476bb2fc50c6ee97ad5754b0ffcec8dfedb80 Mon Sep 17 00:00:00 2001 From: Rich Dunne Date: Mon, 14 Sep 2020 11:30:14 -0600 Subject: [PATCH] Extracted Draw3DWaypointOnPlayer method to PathMainMenu for when a new path is created. Removed referencs to DebugGraphics class --- SceneManager/DebugGraphics.cs | 73 ------------------------------ SceneManager/Menus/PathMainMenu.cs | 50 +++++++++++++++++--- SceneManager/Menus/SettingsMenu.cs | 9 ---- 3 files changed, 43 insertions(+), 89 deletions(-) delete mode 100644 SceneManager/DebugGraphics.cs diff --git a/SceneManager/DebugGraphics.cs b/SceneManager/DebugGraphics.cs deleted file mode 100644 index 606f921..0000000 --- a/SceneManager/DebugGraphics.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Rage; -using System.Drawing; - -namespace SceneManager -{ - class DebugGraphics - { - public static void LoopToDrawDebugGraphics(Path path) - { - GameFiber.StartNew(() => - { - while (SettingsMenu.threeDWaypoints.Checked) - { - if (MenuManager.menuPool.IsAnyMenuOpen() && path != null) - { - for (int i = 0; i < path.Waypoints.Count; i++) - { - if (i != path.Waypoints.Count - 1) - { - DrawLinesBetweenWaypoints(path, i); - } - } - } - GameFiber.Yield(); - } - }); - } - - // Can this be extracted to the Waypoint or Path object - private static void DrawLinesBetweenWaypoints(Path path, int i) - { - if (path.Waypoints[i + 1].DrivingFlag == VehicleDrivingFlags.StopAtDestination) - { - Debug.DrawLine(path.Waypoints[i].Position, path.Waypoints[i + 1].Position, Color.Orange); - } - else - { - Debug.DrawLine(path.Waypoints[i].Position, path.Waypoints[i + 1].Position, Color.Green); - } - } - - public static void Draw3DWaypointOnPlayer() - { - GameFiber.StartNew(() => - { - while (SettingsMenu.threeDWaypoints.Checked) - { - if (PathCreationMenu.pathCreationMenu.Visible) - { - if (PathCreationMenu.collectorWaypoint.Checked) - { - Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.collectorRadius.Value * 2, (float)PathCreationMenu.collectorRadius.Value * 2, 1f, 80, 130, 255, 80, false, false, 2, false, 0, 0, false); - Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.speedZoneRadius.Value * 2, (float)PathCreationMenu.speedZoneRadius.Value * 2, 1f, 255, 185, 80, 80, false, false, 2, false, 0, 0, false); - } - else if (PathCreationMenu.waypointType.SelectedItem.Contains("Drive To")) - { - Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false); - } - else - { - Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 80, false, false, 2, false, 0, 0, false); - } - } - else - { - break; - } - GameFiber.Yield(); - } - }); - } - } -} diff --git a/SceneManager/Menus/PathMainMenu.cs b/SceneManager/Menus/PathMainMenu.cs index 18d13b4..f14fcc1 100644 --- a/SceneManager/Menus/PathMainMenu.cs +++ b/SceneManager/Menus/PathMainMenu.cs @@ -37,9 +37,9 @@ namespace SceneManager public static void BuildPathMenu() { - // New stuff to mitigate Rebuild method - pathMainMenu.OnItemSelect -= PathMenu_OnItemSelected; - pathMainMenu.OnCheckboxChange -= PathMenu_OnCheckboxChange; + // Need to unsubscribe from events, else there will be duplicate firings if the user left the menu and re-entered + ResetEventHandlerSubscriptions(); + MenuManager.menuPool.CloseAllMenus(); pathMainMenu.Clear(); @@ -69,11 +69,16 @@ namespace SceneManager } pathMainMenu.RefreshIndex(); + + MenuManager.menuPool.RefreshIndex(); + } + + private static void ResetEventHandlerSubscriptions() + { + pathMainMenu.OnItemSelect -= PathMenu_OnItemSelected; + pathMainMenu.OnCheckboxChange -= PathMenu_OnCheckboxChange; pathMainMenu.OnItemSelect += PathMenu_OnItemSelected; pathMainMenu.OnCheckboxChange += PathMenu_OnCheckboxChange; - - // New stuff to mitigate Rebuild method - MenuManager.menuPool.RefreshIndex(); } public static ref List GetPaths() @@ -158,7 +163,7 @@ namespace SceneManager { pathMainMenu.Visible = false; PathCreationMenu.pathCreationMenu.Visible = true; - DebugGraphics.Draw3DWaypointOnPlayer(); + Draw3DWaypointOnPlayer(); // For each element in paths, determine if the element exists but is not finished yet, or if it doesn't exist, create it. for (int i = 0; i <= paths.Count; i++) @@ -324,6 +329,37 @@ namespace SceneManager } } + private static void Draw3DWaypointOnPlayer() + { + GameFiber.StartNew(() => + { + while (SettingsMenu.threeDWaypoints.Checked) + { + if (PathCreationMenu.pathCreationMenu.Visible) + { + if (PathCreationMenu.collectorWaypoint.Checked) + { + Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.collectorRadius.Value * 2, (float)PathCreationMenu.collectorRadius.Value * 2, 1f, 80, 130, 255, 80, false, false, 2, false, 0, 0, false); + Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.speedZoneRadius.Value * 2, (float)PathCreationMenu.speedZoneRadius.Value * 2, 1f, 255, 185, 80, 80, false, false, 2, false, 0, 0, false); + } + else if (PathCreationMenu.waypointType.SelectedItem.Contains("Drive To")) + { + Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false); + } + else + { + Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 80, false, false, 2, false, 0, 0, false); + } + } + else + { + break; + } + GameFiber.Yield(); + } + }); + } + private static void PathMenu_OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked) { if (checkboxItem == disableAllPaths) diff --git a/SceneManager/Menus/SettingsMenu.cs b/SceneManager/Menus/SettingsMenu.cs index 27f9e61..de40767 100644 --- a/SceneManager/Menus/SettingsMenu.cs +++ b/SceneManager/Menus/SettingsMenu.cs @@ -44,7 +44,6 @@ namespace SceneManager { if(selectedItem == saveSettings) { - // Write to .ini Settings.UpdateSettings(threeDWaypoints.Checked, mapBlips.Checked, hints.Checked, speedUnits.SelectedItem, barrierPlacementDistance.Value); Game.DisplayHelp($"Settings saved"); } @@ -52,14 +51,6 @@ namespace SceneManager private static void SettingsMenu_OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked) { - if (checkboxItem == threeDWaypoints) - { - if (threeDWaypoints.Checked) - { - DebugGraphics.Draw3DWaypointOnPlayer(); - } - } - if (checkboxItem == mapBlips) { if (mapBlips.Checked)