148 lines
3.3 KiB
C#
148 lines
3.3 KiB
C#
using System;
|
|
using SRDebugger.Internal;
|
|
using SRDebugger.Services;
|
|
using SRDebugger.UI.Controls;
|
|
using SRF;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace SRDebugger.UI.Tabs
|
|
{
|
|
public class ConsoleTabController : SRMonoBehaviourEx
|
|
{
|
|
private const int MaxLength = 2600;
|
|
|
|
private bool _isDirty;
|
|
|
|
[RequiredField]
|
|
public ConsoleLogControl ConsoleLogControl;
|
|
|
|
[RequiredField]
|
|
public Toggle PinToggle;
|
|
|
|
[RequiredField]
|
|
public ScrollRect StackTraceScrollRect;
|
|
|
|
[RequiredField]
|
|
public Text StackTraceText;
|
|
|
|
[RequiredField]
|
|
public Toggle ToggleErrors;
|
|
|
|
[RequiredField]
|
|
public Text ToggleErrorsText;
|
|
|
|
[RequiredField]
|
|
public Toggle ToggleInfo;
|
|
|
|
[RequiredField]
|
|
public Text ToggleInfoText;
|
|
|
|
[RequiredField]
|
|
public Toggle ToggleWarnings;
|
|
|
|
[RequiredField]
|
|
public Text ToggleWarningsText;
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
ToggleErrors.onValueChanged.AddListener(delegate
|
|
{
|
|
_isDirty = true;
|
|
});
|
|
ToggleWarnings.onValueChanged.AddListener(delegate
|
|
{
|
|
_isDirty = true;
|
|
});
|
|
ToggleInfo.onValueChanged.AddListener(delegate
|
|
{
|
|
_isDirty = true;
|
|
});
|
|
PinToggle.onValueChanged.AddListener(PinToggleValueChanged);
|
|
ConsoleLogControl.SelectedItemChanged = ConsoleLogSelectedItemChanged;
|
|
Service.Console.Updated += ConsoleOnUpdated;
|
|
StackTraceText.supportRichText = Settings.Instance.RichTextInConsole;
|
|
PopulateStackTraceArea(null);
|
|
Refresh();
|
|
}
|
|
|
|
private void PinToggleValueChanged(bool isOn)
|
|
{
|
|
Service.DockConsole.IsVisible = isOn;
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
if (Service.Console != null)
|
|
{
|
|
Service.Console.Updated -= ConsoleOnUpdated;
|
|
}
|
|
base.OnDestroy();
|
|
}
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
_isDirty = true;
|
|
}
|
|
|
|
private void ConsoleLogSelectedItemChanged(object item)
|
|
{
|
|
ConsoleEntry entry = item as ConsoleEntry;
|
|
PopulateStackTraceArea(entry);
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
if (_isDirty)
|
|
{
|
|
Refresh();
|
|
}
|
|
}
|
|
|
|
private void PopulateStackTraceArea(ConsoleEntry entry)
|
|
{
|
|
if (entry == null)
|
|
{
|
|
StackTraceText.text = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
string text = entry.Message + Environment.NewLine + (string.IsNullOrEmpty(entry.StackTrace) ? SRDebugStrings.Current.Console_NoStackTrace : entry.StackTrace);
|
|
if (text.Length > 2600)
|
|
{
|
|
text = text.Substring(0, 2600);
|
|
text = text + "\n" + SRDebugStrings.Current.Console_MessageTruncated;
|
|
}
|
|
StackTraceText.text = text;
|
|
}
|
|
StackTraceScrollRect.normalizedPosition = new Vector2(0f, 1f);
|
|
}
|
|
|
|
private void Refresh()
|
|
{
|
|
ToggleInfoText.text = SRDebuggerUtil.GetNumberString(Service.Console.InfoCount, 999, "999+");
|
|
ToggleWarningsText.text = SRDebuggerUtil.GetNumberString(Service.Console.WarningCount, 999, "999+");
|
|
ToggleErrorsText.text = SRDebuggerUtil.GetNumberString(Service.Console.ErrorCount, 999, "999+");
|
|
ConsoleLogControl.ShowErrors = ToggleErrors.isOn;
|
|
ConsoleLogControl.ShowWarnings = ToggleWarnings.isOn;
|
|
ConsoleLogControl.ShowInfo = ToggleInfo.isOn;
|
|
PinToggle.isOn = Service.DockConsole.IsVisible;
|
|
_isDirty = false;
|
|
}
|
|
|
|
private void ConsoleOnUpdated(IConsoleService console)
|
|
{
|
|
_isDirty = true;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
Service.Console.Clear();
|
|
_isDirty = true;
|
|
}
|
|
}
|
|
}
|