Skip to content

Commit

Permalink
[Update] - Improve the Console's multi-line support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gameefan committed Mar 28, 2024
1 parent 2bc6c26 commit c799b4b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Assembly-CSharp/ModLoader/Console/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class Console : MonoBehaviour
{
private bool visible = false;

uint qsize = 15; // number of messages to keep
Queue myLogQueue = new Queue();
uint consoleLines = 15; // number of messages to keep
Queue logQueue = new Queue();

string command = string.Empty;

Expand All @@ -24,15 +24,13 @@ void OnDisable()

void HandleLog(string logString, string stackTrace, LogType type)
{
myLogQueue.Enqueue("[" + type + "] : " + logString);
string message = $"[{type}] {logString}";
if (type == LogType.Exception)
{
myLogQueue.Enqueue(stackTrace);
}
while (myLogQueue.Count > qsize)
{
myLogQueue.Dequeue();
}
message += "\n" + stackTrace;
foreach (string line in message.Split('\n'))
logQueue.Enqueue(line);
while (logQueue.Count > consoleLines)
logQueue.Dequeue();
}

void Update() { }
Expand All @@ -54,9 +52,9 @@ void OnGUI()

if (visible)
{
GUILayout.BeginArea(new Rect(Screen.width * 0.05f, (Screen.height - 15 * (myLogQueue.ToArray().Length + 5)), Screen.width * 0.9f, Screen.height * 0.9f));
GUILayout.BeginArea(new Rect(Screen.width * 0.05f, (Screen.height - 15 * (logQueue.ToArray().Length + 5)), Screen.width * 0.9f, Screen.height * 0.9f));

GUILayout.Label("\n" + string.Join("\n", myLogQueue.ToArray()));
GUILayout.Label("\n" + string.Join("\n", logQueue.ToArray()));

GUI.SetNextControlName("command");
command = GUILayout.TextField(command);
Expand Down

0 comments on commit c799b4b

Please sign in to comment.