-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMessageCenter.cs
101 lines (81 loc) · 3.18 KB
/
MessageCenter.cs
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
100
101
using BepInEx.Configuration;
using BepInEx.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using BepInEx.Bootstrap;
using UnityEngine;
namespace BepInEx
{
[BepInPlugin(GUID, PluginName, Version)]
public partial class MessageCenter : BaseUnityPlugin
{
public const string GUID = "com.bepis.messagecenter";
public const string PluginName = "Message Center";
public const string Version = "1.1.1.1";
private static readonly List<LogEntry> _shownLogLines = new List<LogEntry>();
private static float _showCounter;
private static string _shownLogText = string.Empty;
public static ConfigEntry<bool> Enabled { get; private set; }
public MessageCenter()
{
Enabled = Config.Bind("General", "Show messages in UI", true, "Allow plugins to show on screen messages");
Logging.Logger.Listeners.Add(new MessageLogListener());
}
private void Start()
{
foreach (var dependencyError in Chainloader.DependencyErrors)
ShowText(dependencyError);
}
private static void OnEntryLogged(LogEventArgs logEventArgs)
{
if (!Enabled.Value) return;
if ("BepInEx".Equals(logEventArgs.Source.SourceName, StringComparison.Ordinal)) return;
if ((logEventArgs.Level & LogLevel.Message) == LogLevel.None) return;
if (logEventArgs.Data != null)
ShowText(logEventArgs.Data.ToString());
}
private static void ShowText(string logText)
{
if (_showCounter <= 0)
_shownLogLines.Clear();
_showCounter = Mathf.Clamp(_showCounter, 7, 12);
var logEntry = _shownLogLines.FirstOrDefault(x => x.Text.Equals(logText, StringComparison.Ordinal));
if (logEntry == null)
{
logEntry = new LogEntry(logText);
_shownLogLines.Add(logEntry);
_showCounter += 0.8f;
}
logEntry.Count++;
var logLines = _shownLogLines.Select(x => x.Count > 1 ? $"{x.Count}x {x.Text}" : x.Text).ToArray();
_shownLogText = string.Join("\r\n", logLines);
}
private void Update()
{
if (_showCounter > 0)
_showCounter -= Time.deltaTime;
}
private GUIStyle _textStyle;
private void OnGUI()
{
if (_showCounter <= 0) return;
if (_textStyle == null)
{
_textStyle = new GUIStyle
{
alignment = TextAnchor.UpperLeft,
fontSize = 20
};
}
var textColor = Color.black;
var outlineColor = Color.white;
if (_showCounter <= 1)
{
textColor.a = _showCounter;
outlineColor.a = _showCounter;
}
ShadowAndOutline.DrawOutline(new Rect(40, 20, Screen.width - 80, 160), _shownLogText, _textStyle, textColor, outlineColor, 3);
}
}
}