117 lines
2.6 KiB
C#
117 lines
2.6 KiB
C#
using System.Collections.Generic;
|
||
using System.Text;
|
||
using SRDebugger.Services;
|
||
using SRDebugger.UI.Controls;
|
||
using SRF;
|
||
using SRF.Service;
|
||
using UnityEngine;
|
||
|
||
namespace SRDebugger.UI.Tabs
|
||
{
|
||
public class InfoTabController : SRMonoBehaviourEx
|
||
{
|
||
public const char Tick = '✓';
|
||
|
||
public const char Cross = '×';
|
||
|
||
public const string NameColor = "#BCBCBC";
|
||
|
||
private Dictionary<string, InfoBlock> _infoBlocks = new Dictionary<string, InfoBlock>();
|
||
|
||
[RequiredField]
|
||
public InfoBlock InfoBlockPrefab;
|
||
|
||
[RequiredField]
|
||
public RectTransform LayoutContainer;
|
||
|
||
protected override void Start()
|
||
{
|
||
base.Start();
|
||
Construct();
|
||
}
|
||
|
||
protected override void OnEnable()
|
||
{
|
||
base.OnEnable();
|
||
Refresh();
|
||
}
|
||
|
||
public void Refresh()
|
||
{
|
||
ISystemInformationService service = SRServiceManager.GetService<ISystemInformationService>();
|
||
foreach (KeyValuePair<string, InfoBlock> infoBlock in _infoBlocks)
|
||
{
|
||
FillInfoBlock(infoBlock.Value, service.GetInfo(infoBlock.Key));
|
||
}
|
||
}
|
||
|
||
private void Construct()
|
||
{
|
||
ISystemInformationService service = SRServiceManager.GetService<ISystemInformationService>();
|
||
foreach (string category in service.GetCategories())
|
||
{
|
||
IList<ISystemInfo> info = service.GetInfo(category);
|
||
if (info.Count != 0)
|
||
{
|
||
InfoBlock infoBlock = CreateBlock(category);
|
||
FillInfoBlock(infoBlock, info);
|
||
_infoBlocks.Add(category, infoBlock);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void FillInfoBlock(InfoBlock block, IList<ISystemInfo> info)
|
||
{
|
||
StringBuilder stringBuilder = new StringBuilder();
|
||
int num = 0;
|
||
foreach (ISystemInfo item in info)
|
||
{
|
||
if (item.Title.Length > num)
|
||
{
|
||
num = item.Title.Length;
|
||
}
|
||
}
|
||
num += 2;
|
||
bool flag = true;
|
||
foreach (ISystemInfo item2 in info)
|
||
{
|
||
if (flag)
|
||
{
|
||
flag = false;
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine();
|
||
}
|
||
stringBuilder.Append("<color=");
|
||
stringBuilder.Append("#BCBCBC");
|
||
stringBuilder.Append(">");
|
||
stringBuilder.Append(item2.Title);
|
||
stringBuilder.Append(": ");
|
||
stringBuilder.Append("</color>");
|
||
for (int i = item2.Title.Length; i <= num; i++)
|
||
{
|
||
stringBuilder.Append(' ');
|
||
}
|
||
if (item2.Value is bool)
|
||
{
|
||
stringBuilder.Append((!(bool)item2.Value) ? '×' : '✓');
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.Append(item2.Value);
|
||
}
|
||
}
|
||
block.Content.text = stringBuilder.ToString();
|
||
}
|
||
|
||
private InfoBlock CreateBlock(string title)
|
||
{
|
||
InfoBlock infoBlock = SRInstantiate.Instantiate(InfoBlockPrefab);
|
||
infoBlock.Title.text = title;
|
||
infoBlock.CachedTransform.SetParent(LayoutContainer, false);
|
||
return infoBlock;
|
||
}
|
||
}
|
||
}
|