diff --git a/SceneManager/Menus/SettingsMenu.cs b/SceneManager/Menus/SettingsMenu.cs index f14b552..46bbe6e 100644 --- a/SceneManager/Menus/SettingsMenu.cs +++ b/SceneManager/Menus/SettingsMenu.cs @@ -1,22 +1,20 @@ using Rage; using RAGENativeUI; using RAGENativeUI.Elements; +using System; namespace SceneManager { class SettingsMenu { - public static UIMenu settingsMenu { get; private set; } - public static UIMenuCheckboxItem debugGraphics = new UIMenuCheckboxItem("Enable 3D Waypoints", false), - hints = new UIMenuCheckboxItem("Enable Hints", true); // Refactor this to be true/false based off the ini - public static UIMenuListScrollerItem speedUnits = new UIMenuListScrollerItem("Speed Unit of Measure", "", new[] { SpeedUnitsOfMeasure.MPH, SpeedUnitsOfMeasure.KPH }); - public static UIMenuNumericScrollerItem barrierPlacementDistance = new UIMenuNumericScrollerItem("Barrier Placement Distance", "How far away you can place a barrier (in meters)", 1, 30, 1); - - public enum SpeedUnitsOfMeasure - { - MPH, - KPH - } + public static UIMenu settingsMenu { get; set; } + public static UIMenuCheckboxItem threeDWaypoints = new UIMenuCheckboxItem("Enable 3D Waypoints", Settings.Enable3DWaypoints), + mapBlips = new UIMenuCheckboxItem("Enable Map Blips", Settings.EnableMapBlips), + hints = new UIMenuCheckboxItem("Enable Hints", Settings.EnableHints); + private static SpeedUnits[] speedArray = {SpeedUnits.MPH, SpeedUnits.KPH }; + public static UIMenuListScrollerItem speedUnits = new UIMenuListScrollerItem("Speed Unit of Measure", "", new[] { SpeedUnits.MPH, SpeedUnits.KPH }); + public static UIMenuNumericScrollerItem barrierPlacementDistance = new UIMenuNumericScrollerItem("Barrier Placement Distance", "How far away you can place a barrier (in meters)", 1, (int)Settings.BarrierPlacementDistance, 1); + public static UIMenuItem saveSettings = new UIMenuItem("Save settings to .ini", "Updates the plugin's .ini file with the current settings so the next time the plugin is loaded, it will use these settings."); internal static void InstantiateMenu() { @@ -27,38 +25,77 @@ namespace SceneManager public static void BuildSettingsMenu() { - settingsMenu.AddItem(debugGraphics); + settingsMenu.AddItem(threeDWaypoints); + settingsMenu.AddItem(mapBlips); settingsMenu.AddItem(hints); settingsMenu.AddItem(speedUnits); + speedUnits.Index = Array.IndexOf(speedArray, Settings.SpeedUnit); settingsMenu.AddItem(barrierPlacementDistance); - barrierPlacementDistance.Index = 14; + barrierPlacementDistance.Index = barrierPlacementDistance.OptionCount - 1; + settingsMenu.AddItem(saveSettings); + saveSettings.ForeColor = System.Drawing.Color.Gold; settingsMenu.OnCheckboxChange += SettingsMenu_OnCheckboxChange; settingsMenu.OnScrollerChange += SettingsMenu_OnScrollerChange; + settingsMenu.OnItemSelect += SettingsMenu_OnItemSelected; + } + + private static void SettingsMenu_OnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index) + { + if(selectedItem == saveSettings) + { + // Write to .ini + Settings.UpdateSettings(threeDWaypoints.Checked, mapBlips.Checked, hints.Checked, speedUnits.SelectedItem, barrierPlacementDistance.Value); + Game.DisplayHelp($"Settings saved"); + } } private static void SettingsMenu_OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool @checked) { - if (checkboxItem == debugGraphics) + if (checkboxItem == threeDWaypoints) { - if (debugGraphics.Checked) + if (threeDWaypoints.Checked) { foreach (Path path in PathMainMenu.GetPaths()) { - GameFiber.StartNew(() => - { + //GameFiber.StartNew(() => + //{ DebugGraphics.LoopToDrawDebugGraphics(path); - }); + //}); } DebugGraphics.Draw3DWaypointOnPlayer(); } } - if(checkboxItem == hints) + + if (checkboxItem == mapBlips) + { + if (mapBlips.Checked) + { + foreach(Path path in PathMainMenu.GetPaths()) + { + foreach(Waypoint wp in path.Waypoints) + { + wp.EnableBlip(); + } + } + } + else + { + foreach (Path path in PathMainMenu.GetPaths()) + { + foreach (Waypoint wp in path.Waypoints) + { + wp.DisableBlip(); + } + } + } + } + + if (checkboxItem == hints) { Hints.Enabled = hints.Checked ? true : false; - // Update the setting in the .ini when check state is changed } }