UITerminalController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using System;
  2. using System.Collections;
  3. using System.Text.RegularExpressions;
  4. using Colorful;
  5. using DG.Tweening;
  6. using DG.Tweening.Core;
  7. using DG.Tweening.Plugins.Options;
  8. using ExtensionMethods;
  9. using UnityEngine;
  10. public class UITerminalController : MonoBehaviour
  11. {
  12. private YieldInstruction Open(Color? color)
  13. {
  14. R.Mode.EnterMode(Mode.AllMode.UI);
  15. R.Ui.Pause.Enabled = false;
  16. this.Clear();
  17. if (color != null)
  18. {
  19. UILabel console = this._console;
  20. console.text += color.Value.ToBBCode();
  21. }
  22. this._panel.gameObject.SetActive(true);
  23. CameraFilterUtils.Create<CameraFilterPack_TV_80>(R.Ui.CameraGO);
  24. AnalogTV analogTV = R.Ui.CameraGO.AddComponent<AnalogTV>();
  25. analogTV.Shader = Shader.Find("Hidden/Colorful/Analog TV");
  26. analogTV.NoiseIntensity = 1f;
  27. analogTV.ScanlinesIntensity = 0f;
  28. analogTV.ScanlinesCount = 696;
  29. analogTV.Distortion = 0.18f;
  30. analogTV.CubicDistortion = 0f;
  31. analogTV.Scale = 1.02f;
  32. return null;
  33. }
  34. public YieldInstruction OpenWithoutAnim(Color? color = null)
  35. {
  36. this.Open(color);
  37. R.Camera.Camera.enabled = false;
  38. return null;
  39. }
  40. public YieldInstruction OpenWithAnim(Color? color = null)
  41. {
  42. this.Open(color);
  43. AnalogTV analogTV = R.Ui.CameraGO.GetComponent<AnalogTV>();
  44. analogTV.Scale = 0f;
  45. R.Audio.PlayEffect(358, null);
  46. return DOTween.To(() => analogTV.Scale, delegate(float scale)
  47. {
  48. analogTV.Scale = scale;
  49. }, 1.02f, 0.5f).OnComplete(delegate
  50. {
  51. R.Camera.Camera.enabled = false;
  52. }).SetUpdate(true).WaitForCompletion();
  53. }
  54. private YieldInstruction Close()
  55. {
  56. CameraFilterUtils.Remove<CameraFilterPack_TV_80>(R.Ui.CameraGO);
  57. UnityEngine.Object.Destroy(R.Ui.CameraGO.GetComponent<AnalogTV>());
  58. this._panel.gameObject.SetActive(false);
  59. R.Ui.Pause.Enabled = true;
  60. R.Mode.ExitMode(Mode.AllMode.UI);
  61. return null;
  62. }
  63. public YieldInstruction CloseWithoutAnim()
  64. {
  65. R.Camera.Camera.enabled = true;
  66. this.Close();
  67. return null;
  68. }
  69. public YieldInstruction CloseWithAnim()
  70. {
  71. AnalogTV analogTV = R.Ui.CameraGO.GetComponent<AnalogTV>();
  72. R.Audio.PlayEffect(359, null);
  73. R.Camera.Camera.enabled = true;
  74. return DOTween.To(() => analogTV.Scale, delegate(float scale)
  75. {
  76. analogTV.Scale = scale;
  77. }, 0f, 0.5f).SetUpdate(true).OnComplete(delegate
  78. {
  79. this.CloseWithoutAnim();
  80. }).WaitForCompletion();
  81. }
  82. public Coroutine Print(string text, float interval = 0.1f)
  83. {
  84. base.StopCoroutine(this.PrintCoroutine(text, interval, null, true));
  85. return base.StartCoroutine(this.PrintCoroutine(text, interval, null, true));
  86. }
  87. public Coroutine Println(string text = "", float interval = 0.1f)
  88. {
  89. base.StopCoroutine(this.PrintCoroutine(text, interval, "\n", true));
  90. return base.StartCoroutine(this.PrintCoroutine(text, interval, "\n", true));
  91. }
  92. public YieldInstruction PrintShellPrompt()
  93. {
  94. this.PrintInstantly("$ ~ ");
  95. return null;
  96. }
  97. public YieldInstruction PrintInstantly(string text)
  98. {
  99. UILabel console = this._console;
  100. console.text += text;
  101. return null;
  102. }
  103. public YieldInstruction PrintlnInstantly(string text = "")
  104. {
  105. UILabel console = this._console;
  106. console.text = console.text + text + "\n";
  107. return null;
  108. }
  109. public YieldInstruction Clear()
  110. {
  111. this._console.text = string.Empty;
  112. return null;
  113. }
  114. private IEnumerator PrintCoroutine(string text, float interval, string end = null, bool withAudio = true)
  115. {
  116. Regex colorBBCode = new Regex("\\[([0-9a-fA-F]{6}|-)\\]");
  117. for (int i = 0; i < text.Length; i++)
  118. {
  119. Match match = colorBBCode.Match(text, i);
  120. if (match.Index == i)
  121. {
  122. UILabel console = this._console;
  123. console.text += match.Value;
  124. i += match.Length;
  125. }
  126. if (i < text.Length)
  127. {
  128. UILabel console2 = this._console;
  129. console2.text += text[i];
  130. if (withAudio)
  131. {
  132. R.Audio.PlayEffect(347, null);
  133. }
  134. }
  135. yield return WorldTime.WaitForSecondsIgnoreTimeScale(interval / UILanguage.CurrentLanguage.TypeSpeed);
  136. }
  137. if (!string.IsNullOrEmpty(end))
  138. {
  139. UILabel console3 = this._console;
  140. console3.text += end;
  141. if (withAudio)
  142. {
  143. R.Audio.PlayEffect(348, null);
  144. }
  145. }
  146. yield break;
  147. }
  148. public YieldInstruction ShowProgressBar(float defaultValue = 0f)
  149. {
  150. this._progressBar.value = defaultValue;
  151. return DOTween.To(() => this._progressBar.alpha, delegate(float alpha)
  152. {
  153. this._progressBar.alpha = alpha;
  154. }, 1f, 1f).SetUpdate(true).WaitForCompletion();
  155. }
  156. public YieldInstruction HideProgressBar()
  157. {
  158. return DOTween.To(() => this._progressBar.alpha, delegate(float alpha)
  159. {
  160. this._progressBar.alpha = alpha;
  161. }, 0f, 1f).SetUpdate(true).OnComplete(delegate
  162. {
  163. this._progressBar.value = 0f;
  164. }).WaitForCompletion();
  165. }
  166. public YieldInstruction SetProgressBarValue(float value)
  167. {
  168. this._progressBar.value = value;
  169. return null;
  170. }
  171. public YieldInstruction SetProgressBarValueWithAnim(float endValue, float duration)
  172. {
  173. return DOTween.To(() => this._progressBar.value, delegate(float value)
  174. {
  175. this._progressBar.value = value;
  176. }, endValue, duration).SetUpdate(true).WaitForCompletion();
  177. }
  178. public YieldInstruction ShowTexture(Texture texture, float scale = 1f, float alpha = 1f)
  179. {
  180. this._texture.mainTexture = texture;
  181. this.SetTextureSize(scale);
  182. this._texture.alpha = 0f;
  183. return DOTween.To(() => this._texture.alpha, delegate(float a)
  184. {
  185. this._texture.alpha = a;
  186. }, alpha, 1f).SetUpdate(true).WaitForCompletion();
  187. }
  188. public YieldInstruction ShowTextureFullScreen(Texture texture)
  189. {
  190. this._texture.mainTexture = texture;
  191. this.SetTextureFullScreen();
  192. this._texture.alpha = 0f;
  193. return DOTween.To(() => this._texture.alpha, delegate(float alpha)
  194. {
  195. this._texture.alpha = alpha;
  196. }, 1f, 1f).SetUpdate(true).WaitForCompletion();
  197. }
  198. public void SetTextureSize(float scale = 1f)
  199. {
  200. Texture mainTexture = this._texture.mainTexture;
  201. Vector2 a = new Vector2((float)mainTexture.width, (float)mainTexture.height) * R.Ui.CameraGO.GetComponent<Camera>().orthographicSize;
  202. a *= scale;
  203. this._texture.SetDimensions(Mathf.RoundToInt(a.x), Mathf.RoundToInt(a.y));
  204. }
  205. public void SetTextureFullScreen()
  206. {
  207. Vector2 vector = this._panel.GetViewSize() * R.Ui.CameraGO.GetComponent<Camera>().orthographicSize;
  208. this._texture.SetDimensions(Mathf.RoundToInt(vector.x), Mathf.RoundToInt(vector.y));
  209. }
  210. public YieldInstruction HideTexture()
  211. {
  212. return DOTween.To(() => this._texture.alpha, delegate(float alpha)
  213. {
  214. this._texture.alpha = alpha;
  215. }, 0f, 1f).SetUpdate(true).WaitForCompletion();
  216. }
  217. public const string ShellPrompt = "$ ~ ";
  218. [SerializeField]
  219. private UILabel _console;
  220. [SerializeField]
  221. private UIProgressBar _progressBar;
  222. [SerializeField]
  223. private UITexture _texture;
  224. [SerializeField]
  225. private UIPanel _panel;
  226. }