Skip to content

Commit

Permalink
Re-add settings to display each data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mspielberg committed Dec 21, 2020
1 parent 3855ee5 commit 0edf825
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 35 deletions.
36 changes: 1 addition & 35 deletions HeadsUpDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static bool Load(UnityModManager.ModEntry modEntry)

private static void OnGui(UnityModManager.ModEntry modEntry)
{
settings.Draw(modEntry);
settings.Draw();
if (GUILayout.Button("Reset position", GUILayout.ExpandWidth(false)))
{
settings.hudPosition = Settings.defaultPosition;
Expand Down Expand Up @@ -92,39 +92,5 @@ public static void DebugLog(string message)
if (settings.enableLogging && mod != null)
mod.Logger.Log(message);
}

public class Settings : UnityModManager.ModSettings, IDrawable
{
public static Vector2 defaultPosition = new Vector2(10, 10);

[Draw("Show driving info")] public bool showDrivingInfo = true;

[Draw("Show track info")] public bool showTrackInfo = true;
[Draw("Max events", VisibleOn = "showTrackInfo|true")] public int maxEventCount = 10;
[Draw("Max distance", VisibleOn = "showTrackInfo|true")] public double maxEventSpan = 5000;

[Draw("Show car list")] public bool showCarList = true;
[Draw("Group by job", VisibleOn = "showCarList|true")] public bool groupCarsByJob = true;
[Draw("Cornering stress", VisibleOn = "showCarList|true")] public bool showCarStress = true;
[Draw("Job ID", VisibleOn = "showCarList|true")] public bool showCarJobs = true;
[Draw("Destination", VisibleOn = "showCarList|true")] public bool showCarDestinations = true;
[Draw("Brake status", VisibleOn = "showCarList|true")] public bool showCarBrakeStatus = true;

[Draw("Enable logging")] public bool enableLogging = false;
public readonly string? version = mod?.Info.Version;

public Vector2 hudPosition;

public bool IsEnabled(DataProvider _)
{
return true;
}

override public void Save(UnityModManager.ModEntry entry) => Save<Settings>(this, entry);

public void OnChange()
{
}
}
}
}
79 changes: 79 additions & 0 deletions Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityModManagerNet;

namespace DvMod.HeadsUpDisplay
{
public class Settings : UnityModManager.ModSettings, IDrawable
{
public struct DrivingInfoSettings
{
public HashSet<string> disabledProviders;

static public DrivingInfoSettings Create()
{
return new DrivingInfoSettings() { disabledProviders = Registry.providers.Keys.ToHashSet() };
}

public void Draw()
{
GUILayout.BeginVertical("box");
foreach (string key in from dp in Registry.providers.Values orderby dp.Order select dp.Label)
{
GUILayout.BeginHorizontal();
GUILayout.Label(key, GUILayout.ExpandWidth(false));
var result = GUILayout.Toggle(!disabledProviders.Contains(key), "");
if (result)
disabledProviders.Remove(key);
else
disabledProviders.Add(key);
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}

public bool IsEnabled(DataProvider dp) => !disabledProviders.Contains(dp.Label);
}

public static Vector2 defaultPosition = new Vector2(10, 10);

public bool showDrivingInfo = true;
public DrivingInfoSettings drivingInfoSettings = DrivingInfoSettings.Create();

[Draw("Show track info")] public bool showTrackInfo = true;
[Draw("Max events", VisibleOn = "showTrackInfo|true")] public int maxEventCount = 10;
[Draw("Max distance", VisibleOn = "showTrackInfo|true")] public double maxEventSpan = 5000;

[Draw("Show car list")] public bool showCarList = true;
[Draw("Group by job", VisibleOn = "showCarList|true")] public bool groupCarsByJob = true;
[Draw("Cornering stress", VisibleOn = "showCarList|true")] public bool showCarStress = true;
[Draw("Job ID", VisibleOn = "showCarList|true")] public bool showCarJobs = true;
[Draw("Destination", VisibleOn = "showCarList|true")] public bool showCarDestinations = true;
[Draw("Brake status", VisibleOn = "showCarList|true")] public bool showCarBrakeStatus = true;

[Draw("Enable logging")] public bool enableLogging;
public readonly string? version = Main.mod?.Info.Version;

public Vector2 hudPosition;

public bool IsEnabled(DataProvider dp) => drivingInfoSettings.IsEnabled(dp);

override public void Save(UnityModManager.ModEntry entry) => Save<Settings>(this, entry);

public void Draw()
{
GUILayout.BeginHorizontal();
GUILayout.Label("Show driving info", GUILayout.ExpandWidth(false));
showDrivingInfo = GUILayout.Toggle(showDrivingInfo, "");
GUILayout.EndHorizontal();
if (showDrivingInfo)
drivingInfoSettings.Draw();
this.Draw(Main.mod);
}

public void OnChange()
{
}
}
}

0 comments on commit 0edf825

Please sign in to comment.