InfoTabController.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using SRDebugger.Services;
  5. using SRDebugger.UI.Controls;
  6. using SRF;
  7. using SRF.Service;
  8. using UnityEngine;
  9. namespace SRDebugger.UI.Tabs
  10. {
  11. public class InfoTabController : SRMonoBehaviourEx
  12. {
  13. protected override void OnEnable()
  14. {
  15. base.OnEnable();
  16. this.Refresh();
  17. }
  18. public void Refresh()
  19. {
  20. ISystemInformationService service = SRServiceManager.GetService<ISystemInformationService>();
  21. foreach (string text in service.GetCategories())
  22. {
  23. if (!this._infoBlocks.ContainsKey(text))
  24. {
  25. InfoBlock value = this.CreateBlock(text);
  26. this._infoBlocks.Add(text, value);
  27. }
  28. }
  29. foreach (KeyValuePair<string, InfoBlock> keyValuePair in this._infoBlocks)
  30. {
  31. this.FillInfoBlock(keyValuePair.Value, service.GetInfo(keyValuePair.Key));
  32. }
  33. }
  34. private void FillInfoBlock(InfoBlock block, IList<InfoEntry> info)
  35. {
  36. StringBuilder stringBuilder = new StringBuilder();
  37. int num = 0;
  38. foreach (InfoEntry infoEntry in info)
  39. {
  40. if (infoEntry.Title.Length > num)
  41. {
  42. num = infoEntry.Title.Length;
  43. }
  44. }
  45. num += 2;
  46. bool flag = true;
  47. foreach (InfoEntry infoEntry2 in info)
  48. {
  49. if (flag)
  50. {
  51. flag = false;
  52. }
  53. else
  54. {
  55. stringBuilder.AppendLine();
  56. }
  57. stringBuilder.Append("<color=");
  58. stringBuilder.Append("#BCBCBC");
  59. stringBuilder.Append(">");
  60. stringBuilder.Append(infoEntry2.Title);
  61. stringBuilder.Append(": ");
  62. stringBuilder.Append("</color>");
  63. for (int i = infoEntry2.Title.Length; i <= num; i++)
  64. {
  65. stringBuilder.Append(' ');
  66. }
  67. if (infoEntry2.Value is bool)
  68. {
  69. stringBuilder.Append((!(bool)infoEntry2.Value) ? '×' : '✓');
  70. }
  71. else
  72. {
  73. stringBuilder.Append(infoEntry2.Value);
  74. }
  75. }
  76. block.Content.text = stringBuilder.ToString();
  77. }
  78. private InfoBlock CreateBlock(string title)
  79. {
  80. InfoBlock infoBlock = SRInstantiate.Instantiate<InfoBlock>(this.InfoBlockPrefab);
  81. infoBlock.Title.text = title;
  82. infoBlock.CachedTransform.SetParent(this.LayoutContainer, false);
  83. return infoBlock;
  84. }
  85. public const char Tick = '✓';
  86. public const char Cross = '×';
  87. public const string NameColor = "#BCBCBC";
  88. private Dictionary<string, InfoBlock> _infoBlocks = new Dictionary<string, InfoBlock>();
  89. [RequiredField]
  90. public InfoBlock InfoBlockPrefab;
  91. [RequiredField]
  92. public RectTransform LayoutContainer;
  93. }
  94. }