1
Fork 0
mirror of https://github.com/thegeneralist01/Scene-Manager-DevRepo synced 2026-01-11 23:50:29 +01:00

Added menu options to enable/disable map blips, as well as save settings to the plugin's .ini file

This commit is contained in:
Rich Dunne 2020-09-06 14:26:09 -06:00
parent a4e85eab51
commit 1bb4f2d750

View file

@ -1,22 +1,20 @@
using Rage; using Rage;
using RAGENativeUI; using RAGENativeUI;
using RAGENativeUI.Elements; using RAGENativeUI.Elements;
using System;
namespace SceneManager namespace SceneManager
{ {
class SettingsMenu class SettingsMenu
{ {
public static UIMenu settingsMenu { get; private set; } public static UIMenu settingsMenu { get; set; }
public static UIMenuCheckboxItem debugGraphics = new UIMenuCheckboxItem("Enable 3D Waypoints", false), public static UIMenuCheckboxItem threeDWaypoints = new UIMenuCheckboxItem("Enable 3D Waypoints", Settings.Enable3DWaypoints),
hints = new UIMenuCheckboxItem("Enable Hints", true); // Refactor this to be true/false based off the ini mapBlips = new UIMenuCheckboxItem("Enable Map Blips", Settings.EnableMapBlips),
public static UIMenuListScrollerItem<SpeedUnitsOfMeasure> speedUnits = new UIMenuListScrollerItem<SpeedUnitsOfMeasure>("Speed Unit of Measure", "", new[] { SpeedUnitsOfMeasure.MPH, SpeedUnitsOfMeasure.KPH }); hints = new UIMenuCheckboxItem("Enable Hints", Settings.EnableHints);
public static UIMenuNumericScrollerItem<int> barrierPlacementDistance = new UIMenuNumericScrollerItem<int>("Barrier Placement Distance", "How far away you can place a barrier (in meters)", 1, 30, 1); private static SpeedUnits[] speedArray = {SpeedUnits.MPH, SpeedUnits.KPH };
public static UIMenuListScrollerItem<SpeedUnits> speedUnits = new UIMenuListScrollerItem<SpeedUnits>("Speed Unit of Measure", "", new[] { SpeedUnits.MPH, SpeedUnits.KPH });
public enum SpeedUnitsOfMeasure public static UIMenuNumericScrollerItem<int> barrierPlacementDistance = new UIMenuNumericScrollerItem<int>("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.");
MPH,
KPH
}
internal static void InstantiateMenu() internal static void InstantiateMenu()
{ {
@ -27,38 +25,77 @@ namespace SceneManager
public static void BuildSettingsMenu() public static void BuildSettingsMenu()
{ {
settingsMenu.AddItem(debugGraphics); settingsMenu.AddItem(threeDWaypoints);
settingsMenu.AddItem(mapBlips);
settingsMenu.AddItem(hints); settingsMenu.AddItem(hints);
settingsMenu.AddItem(speedUnits); settingsMenu.AddItem(speedUnits);
speedUnits.Index = Array.IndexOf(speedArray, Settings.SpeedUnit);
settingsMenu.AddItem(barrierPlacementDistance); 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.OnCheckboxChange += SettingsMenu_OnCheckboxChange;
settingsMenu.OnScrollerChange += SettingsMenu_OnScrollerChange; 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) 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()) foreach (Path path in PathMainMenu.GetPaths())
{ {
GameFiber.StartNew(() => //GameFiber.StartNew(() =>
{ //{
DebugGraphics.LoopToDrawDebugGraphics(path); DebugGraphics.LoopToDrawDebugGraphics(path);
}); //});
} }
DebugGraphics.Draw3DWaypointOnPlayer(); 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; Hints.Enabled = hints.Checked ? true : false;
// Update the setting in the .ini when check state is changed
} }
} }