DockConsoleServiceImpl.cs 4.0 KB

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