-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.cs
More file actions
99 lines (87 loc) · 3.27 KB
/
Options.cs
File metadata and controls
99 lines (87 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Collections.Generic;
using BepInEx.Logging;
using Menu.Remix.MixedUI;
using Menu.Remix.MixedUI.ValueTypes;
using UnityEngine;
namespace TimeStop;
internal class PluginOptions : OptionInterface
{
private readonly ManualLogSource Logger;
public PluginOptions(TimeStop modInstance, ManualLogSource loggerSource)
{
Logger = loggerSource;
LogLevel = this.config.Bind<string>("LogLevel", "None");
this.TimeSwitchKeyCode = this.config.Bind<KeyCode>("TimeSwitchKeyCode", UnityEngine.KeyCode.V);
}
private static readonly Dictionary<LoggerExtensions.LogLevel, int> LevelPriorities = new()
{
{LoggerExtensions.LogLevel.None, 0},
{LoggerExtensions.LogLevel.Low, 1},
{LoggerExtensions.LogLevel.Normal, 2},
{LoggerExtensions.LogLevel.High, 3}
};
private static readonly Dictionary<string, LoggerExtensions.LogLevel> optionsToEnums = new()
{
{"None", LoggerExtensions.LogLevel.None},
{"Low", LoggerExtensions.LogLevel.Low},
{"Normal", LoggerExtensions.LogLevel.Normal },
{"High", LoggerExtensions.LogLevel.High}
};
public readonly Configurable<string> LogLevel;
public readonly Configurable<KeyCode> TimeSwitchKeyCode;
private UIelement[] UIArrGeneral;
private static readonly string[] LogLevels = { "None", "Low", "Normal", "High" };
OpComboBox logLevelComboBox;
OpLabel logLevelWarningText;
OpTab opTab;
public override void Initialize()
{
base.Initialize();
opTab = new OpTab(this, "Options");
this.Tabs = new[]
{
opTab
};
logLevelComboBox = new OpComboBox(LogLevel, new Vector2(80f, 490f), 100f, LogLevels);
logLevelWarningText = new OpLabel(190f, 490f, "WARNING: High log level will log every update tick." + System.Environment.NewLine + "It's recommended to not use it unless needed.") { color = new Color(1f, 0f, 0f) };
try
{
UIArrGeneral = new UIelement[]
{
new OpLabel(10f, 550f, "Options", true),
new OpLabel(10f, 520f, "Time State Switch Key"),
new OpKeyBinder(this.TimeSwitchKeyCode, new Vector2(150f, 520f), new Vector2(35f, 10f), true, OpKeyBinder.BindController.AnyController),
new OpLabel(10f, 490f, "Log level"),
logLevelComboBox,
logLevelWarningText
};
}
catch (System.Exception ex)
{
Logger.LogError(ex);
throw;
}
opTab.AddItems(UIArrGeneral);
}
public override void Update()
{
if (logLevelComboBox.value == "High")
{
logLevelWarningText.Show();
}
else
{
logLevelWarningText.Hide();
}
}
internal static bool ShouldLog(LoggerExtensions.LogLevel arg_lLogLevel, string arg_sLogLevel = null)
{
arg_sLogLevel ??= TimeStop.Instance.options.LogLevel.Value ?? "None";
optionsToEnums.TryGetValue(arg_sLogLevel, out var convSLogLevel);
LevelPriorities.TryGetValue(convSLogLevel, out var sLogLevel);
if (sLogLevel == 0) return false;
LevelPriorities.TryGetValue(arg_lLogLevel, out var lLogLevel);
if (lLogLevel >= sLogLevel) return true;
return false;
}
}