DockConsoleServiceImpl.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using SRDebugger.Internal;
  3. using SRDebugger.UI.Other;
  4. using SRF.Service;
  5. using UnityEngine;
  6. namespace SRDebugger.Services.Implementation
  7. {
  8. [Service(typeof(IDockConsoleService))]
  9. public class DockConsoleServiceImpl : IDockConsoleService
  10. {
  11. public DockConsoleServiceImpl()
  12. {
  13. this._alignment = Settings.Instance.ConsoleAlignment;
  14. }
  15. public bool IsVisible
  16. {
  17. get
  18. {
  19. return this._isVisible;
  20. }
  21. set
  22. {
  23. if (value == this._isVisible)
  24. {
  25. return;
  26. }
  27. this._isVisible = value;
  28. if (this._consoleRoot == null && value)
  29. {
  30. this.Load();
  31. }
  32. else
  33. {
  34. this._consoleRoot.CachedGameObject.SetActive(value);
  35. }
  36. this.CheckTrigger();
  37. }
  38. }
  39. public bool IsExpanded
  40. {
  41. get
  42. {
  43. return this._isExpanded;
  44. }
  45. set
  46. {
  47. if (value == this._isExpanded)
  48. {
  49. return;
  50. }
  51. this._isExpanded = value;
  52. if (this._consoleRoot == null && value)
  53. {
  54. this.Load();
  55. }
  56. else
  57. {
  58. this._consoleRoot.SetDropdownVisibility(value);
  59. }
  60. this.CheckTrigger();
  61. }
  62. }
  63. public ConsoleAlignment Alignment
  64. {
  65. get
  66. {
  67. return this._alignment;
  68. }
  69. set
  70. {
  71. this._alignment = value;
  72. if (this._consoleRoot != null)
  73. {
  74. this._consoleRoot.SetAlignmentMode(value);
  75. }
  76. this.CheckTrigger();
  77. }
  78. }
  79. private void Load()
  80. {
  81. IPinnedUIService service = SRServiceManager.GetService<IPinnedUIService>();
  82. if (service == null)
  83. {
  84. UnityEngine.Debug.LogError("[DockConsoleService] PinnedUIService not found");
  85. return;
  86. }
  87. PinnedUIServiceImpl pinnedUIServiceImpl = service as PinnedUIServiceImpl;
  88. if (pinnedUIServiceImpl == null)
  89. {
  90. UnityEngine.Debug.LogError("[DockConsoleService] Expected IPinnedUIService to be PinnedUIServiceImpl");
  91. return;
  92. }
  93. this._consoleRoot = pinnedUIServiceImpl.DockConsoleController;
  94. this._consoleRoot.SetDropdownVisibility(this._isExpanded);
  95. this._consoleRoot.IsVisible = this._isVisible;
  96. this._consoleRoot.SetAlignmentMode(this._alignment);
  97. this.CheckTrigger();
  98. }
  99. private void CheckTrigger()
  100. {
  101. ConsoleAlignment? consoleAlignment = null;
  102. PinAlignment position = Service.Trigger.Position;
  103. if (position == PinAlignment.TopLeft || position == PinAlignment.TopRight || position == PinAlignment.TopCenter)
  104. {
  105. consoleAlignment = new ConsoleAlignment?(ConsoleAlignment.Top);
  106. }
  107. else if (position == PinAlignment.BottomLeft || position == PinAlignment.BottomRight || position == PinAlignment.BottomCenter)
  108. {
  109. consoleAlignment = new ConsoleAlignment?(ConsoleAlignment.Bottom);
  110. }
  111. bool flag = consoleAlignment != null && this.IsVisible && this.Alignment == consoleAlignment.Value;
  112. if (this._didSuspendTrigger && !flag)
  113. {
  114. Service.Trigger.IsEnabled = true;
  115. this._didSuspendTrigger = false;
  116. }
  117. else if (Service.Trigger.IsEnabled && flag)
  118. {
  119. Service.Trigger.IsEnabled = false;
  120. this._didSuspendTrigger = true;
  121. }
  122. }
  123. private ConsoleAlignment _alignment;
  124. private DockConsoleController _consoleRoot;
  125. private bool _didSuspendTrigger;
  126. private bool _isExpanded = true;
  127. private bool _isVisible;
  128. }
  129. }