You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/StompyRobot/SRDebugger/Scripts/UI/Controls/ConsoleEntryView.cs

113 lines
3.2 KiB
C#

2 months ago
namespace SRDebugger.UI.Controls
{
using System;
using Services;
using SRF;
using SRF.UI;
using SRF.UI.Layout;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof (RectTransform))]
public class ConsoleEntryView : SRMonoBehaviourEx, IVirtualView
{
public const string ConsoleBlobInfo = "Console_Info_Blob";
public const string ConsoleBlobWarning = "Console_Warning_Blob";
public const string ConsoleBlobError = "Console_Error_Blob";
private int _count;
private bool _hasCount;
private ConsoleEntry _prevData;
private RectTransform _rectTransform;
[RequiredField] public Text Count;
[RequiredField] public CanvasGroup CountContainer;
[RequiredField] public StyleComponent ImageStyle;
[RequiredField] public Text Message;
[RequiredField] public Text StackTrace;
public void SetDataContext(object data)
{
var msg = data as ConsoleEntry;
if (msg == null)
{
throw new Exception("Data should be a ConsoleEntry");
}
// Always check for updates on "Count", as it can change
if (msg.Count > 1)
{
if (!_hasCount)
{
CountContainer.alpha = 1f;
_hasCount = true;
}
if (msg.Count != _count)
{
Count.text = Internal.SRDebuggerUtil.GetNumberString(msg.Count, 999, "999+");
_count = msg.Count;
}
}
else if (_hasCount)
{
CountContainer.alpha = 0f;
_hasCount = false;
}
// Only update everything else if data context has changed, not just for an update
if (msg == _prevData)
{
return;
}
_prevData = msg;
Message.text = msg.MessagePreview;
StackTrace.text = msg.StackTracePreview;
if (string.IsNullOrEmpty(StackTrace.text))
{
Message.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 2,
_rectTransform.rect.height - 4);
}
else
{
Message.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 12,
_rectTransform.rect.height - 14);
}
switch (msg.LogType)
{
case LogType.Log:
ImageStyle.StyleKey = ConsoleBlobInfo;
break;
case LogType.Warning:
ImageStyle.StyleKey = ConsoleBlobWarning;
break;
case LogType.Exception:
case LogType.Assert:
case LogType.Error:
ImageStyle.StyleKey = ConsoleBlobError;
break;
}
}
protected override void Awake()
{
base.Awake();
_rectTransform = CachedTransform as RectTransform;
CountContainer.alpha = 0f;
Message.supportRichText = Settings.Instance.RichTextInConsole;
}
}
}