DockConsoleController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System;
  2. using SRDebugger.Internal;
  3. using SRDebugger.Services;
  4. using SRDebugger.UI.Controls;
  5. using SRF;
  6. using UnityEngine;
  7. using UnityEngine.EventSystems;
  8. using UnityEngine.UI;
  9. namespace SRDebugger.UI.Other
  10. {
  11. public class DockConsoleController : SRMonoBehaviourEx, IPointerEnterHandler, IPointerExitHandler, IEventSystemHandler
  12. {
  13. public bool IsVisible
  14. {
  15. get
  16. {
  17. return base.CachedGameObject.activeSelf;
  18. }
  19. set
  20. {
  21. base.CachedGameObject.SetActive(value);
  22. }
  23. }
  24. protected override void Start()
  25. {
  26. base.Start();
  27. Service.Console.Updated += this.ConsoleOnUpdated;
  28. this.Refresh();
  29. this.RefreshAlpha();
  30. }
  31. protected override void OnDestroy()
  32. {
  33. base.OnDestroy();
  34. if (Service.Console != null)
  35. {
  36. Service.Console.Updated -= this.ConsoleOnUpdated;
  37. }
  38. }
  39. protected override void OnEnable()
  40. {
  41. base.OnEnable();
  42. this._pointersOver = 0;
  43. this._isDragging = false;
  44. this.RefreshAlpha();
  45. }
  46. protected override void OnDisable()
  47. {
  48. base.OnDisable();
  49. this._pointersOver = 0;
  50. }
  51. protected override void Update()
  52. {
  53. base.Update();
  54. if (this._isDirty)
  55. {
  56. this.Refresh();
  57. }
  58. }
  59. private void ConsoleOnUpdated(IConsoleService console)
  60. {
  61. this._isDirty = true;
  62. }
  63. public void SetDropdownVisibility(bool visible)
  64. {
  65. this.Dropdown.SetActive(visible);
  66. this.DropdownToggleSprite.rectTransform.localRotation = Quaternion.Euler(0f, 0f, (!visible) ? 180f : 0f);
  67. }
  68. public void SetAlignmentMode(ConsoleAlignment alignment)
  69. {
  70. if (alignment != ConsoleAlignment.Top)
  71. {
  72. if (alignment == ConsoleAlignment.Bottom)
  73. {
  74. this.Dropdown.transform.SetSiblingIndex(0);
  75. this.TopBar.transform.SetSiblingIndex(2);
  76. this.TopHandle.SetActive(true);
  77. this.BottomHandle.SetActive(false);
  78. base.transform.SetSiblingIndex(1);
  79. this.DropdownToggleSprite.rectTransform.parent.localRotation = Quaternion.Euler(0f, 0f, 180f);
  80. }
  81. }
  82. else
  83. {
  84. this.TopBar.transform.SetSiblingIndex(0);
  85. this.Dropdown.transform.SetSiblingIndex(2);
  86. this.TopHandle.SetActive(false);
  87. this.BottomHandle.SetActive(true);
  88. base.transform.SetSiblingIndex(0);
  89. this.DropdownToggleSprite.rectTransform.parent.localRotation = Quaternion.Euler(0f, 0f, 0f);
  90. }
  91. }
  92. private void Refresh()
  93. {
  94. this.TextInfo.text = SRDebuggerUtil.GetNumberString(Service.Console.InfoCount, 999, "999+");
  95. this.TextWarnings.text = SRDebuggerUtil.GetNumberString(Service.Console.WarningCount, 999, "999+");
  96. this.TextErrors.text = SRDebuggerUtil.GetNumberString(Service.Console.ErrorCount, 999, "999+");
  97. this._isDirty = false;
  98. }
  99. private void RefreshAlpha()
  100. {
  101. if (this._isDragging || this._pointersOver > 0)
  102. {
  103. this.CanvasGroup.alpha = 1f;
  104. }
  105. else
  106. {
  107. this.CanvasGroup.alpha = 0.65f;
  108. }
  109. }
  110. public void ToggleDropdownVisible()
  111. {
  112. this.SetDropdownVisibility(!this.Dropdown.activeSelf);
  113. }
  114. public void MenuButtonPressed()
  115. {
  116. SRDebug.Instance.ShowDebugPanel(DefaultTabs.Console, true);
  117. }
  118. public void ClearButtonPressed()
  119. {
  120. Service.Console.Clear();
  121. }
  122. public void TogglesUpdated()
  123. {
  124. this.Console.ShowErrors = this.ToggleErrors.isOn;
  125. this.Console.ShowWarnings = this.ToggleWarnings.isOn;
  126. this.Console.ShowInfo = this.ToggleInfo.isOn;
  127. this.SetDropdownVisibility(true);
  128. }
  129. public void OnPointerEnter(PointerEventData e)
  130. {
  131. this._pointersOver = 1;
  132. this.RefreshAlpha();
  133. }
  134. public void OnPointerExit(PointerEventData e)
  135. {
  136. this._pointersOver = 0;
  137. this.RefreshAlpha();
  138. }
  139. public void OnBeginDrag()
  140. {
  141. this._isDragging = true;
  142. this.RefreshAlpha();
  143. }
  144. public void OnEndDrag()
  145. {
  146. this._isDragging = false;
  147. this._pointersOver = 0;
  148. this.RefreshAlpha();
  149. }
  150. public const float NonFocusOpacity = 0.65f;
  151. private bool _isDirty;
  152. private bool _isDragging;
  153. private int _pointersOver;
  154. [RequiredField]
  155. public GameObject BottomHandle;
  156. [RequiredField]
  157. public CanvasGroup CanvasGroup;
  158. [RequiredField]
  159. public ConsoleLogControl Console;
  160. [RequiredField]
  161. public GameObject Dropdown;
  162. [RequiredField]
  163. public Image DropdownToggleSprite;
  164. [RequiredField]
  165. public Text TextErrors;
  166. [RequiredField]
  167. public Text TextInfo;
  168. [RequiredField]
  169. public Text TextWarnings;
  170. [RequiredField]
  171. public Toggle ToggleErrors;
  172. [RequiredField]
  173. public Toggle ToggleInfo;
  174. [RequiredField]
  175. public Toggle ToggleWarnings;
  176. [RequiredField]
  177. public GameObject TopBar;
  178. [RequiredField]
  179. public GameObject TopHandle;
  180. }
  181. }