UILevelSelectController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using Colorful;
  7. using Core;
  8. using DG.Tweening;
  9. using DG.Tweening.Core;
  10. using DG.Tweening.Plugins.Options;
  11. using I2.Loc;
  12. using UnityEngine;
  13. public class UILevelSelectController : MonoBehaviour
  14. {
  15. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  16. public event EventHandler StartButtonClickEvent;
  17. private bool TrueEndEnable
  18. {
  19. get
  20. {
  21. string[] source = new string[]
  22. {
  23. "E3",
  24. "E7",
  25. "E10",
  26. "E13",
  27. "E14",
  28. "E15",
  29. "E16"
  30. };
  31. bool result;
  32. if (!SaveStorage.Get("E21_Finish", false))
  33. {
  34. result = source.All((string eventId) => SaveStorage.Get(eventId + "_Finish", false));
  35. }
  36. else
  37. {
  38. result = false;
  39. }
  40. return result;
  41. }
  42. }
  43. private void Awake()
  44. {
  45. EventDelegate.Add(this._levelButtons.Last<Transform>().GetComponent<UIButton>().onClick, delegate()
  46. {
  47. UIKeyInput.SaveHoveredObject();
  48. this._layers[0].SetActive(false);
  49. this._layers.Last<GameObject>().SetActive(true);
  50. });
  51. for (int i = 0; i < this._menuButtons.Count; i++)
  52. {
  53. EventDelegate.Add(this._menuButtons[i].GetComponent<UIToggle>().onChange, new EventDelegate.Callback(this.OnMenuClick));
  54. }
  55. for (int j = 0; j < this.LevelBeginningSceneNames.Length; j++)
  56. {
  57. EventDelegate.Add(this._levelButtons[j].GetComponent<UIToggle>().onChange, new EventDelegate.Callback(this.OnLevelButtonClick));
  58. }
  59. }
  60. private void OnMenuClick()
  61. {
  62. if (UIToggle.current.value)
  63. {
  64. int num = this._menuButtons.IndexOf(UIToggle.current.gameObject);
  65. if (num != -1)
  66. {
  67. for (int i = 0; i < this._layers.Count; i++)
  68. {
  69. this._layers[i].SetActive(i == num);
  70. }
  71. }
  72. }
  73. }
  74. private void OnLevelButtonClick()
  75. {
  76. if (UIToggle.current.value)
  77. {
  78. this._currentSelectedLevel = this.LevelBeginningSceneNames[this._levelButtons.IndexOf(UIToggle.current.transform)];
  79. }
  80. }
  81. public void OnConfirmClick()
  82. {
  83. if (!Core.Input.JoystickIsOpen)
  84. {
  85. return;
  86. }
  87. if (this.StartButtonClickEvent != null)
  88. {
  89. this.StartButtonClickEvent(this._menuButtons[0], EventArgs.Empty);
  90. }
  91. if (!string.IsNullOrEmpty(this._currentSelectedLevel))
  92. {
  93. this.LoadLevel(this._currentSelectedLevel);
  94. }
  95. }
  96. public Coroutine LoadLevel(string sceneName)
  97. {
  98. return base.StartCoroutine(this.LoadLevelCoroutine(sceneName));
  99. }
  100. private IEnumerator LoadLevelCoroutine(string sceneName)
  101. {
  102. InputSetting.Stop(false);
  103. R.Ui.ShowUI(false);
  104. R.Ui.BlackScene.FadeBlack(0.3f, false);
  105. yield return R.Ui.LevelSelect.CloseWithAnim();
  106. R.RoundReset();
  107. LevelManager.LoadLevelByGateId(sceneName, SceneGate.OpenType.None);
  108. InputSetting.Resume(false);
  109. yield break;
  110. }
  111. private void Open()
  112. {
  113. base.enabled = true;
  114. this._menuButtons[this._menuButtons.Count - 1].transform.parent.gameObject.SetActive(this.TrueEndEnable);
  115. this._levelButtons[this._levelButtons.Count - 1].parent.gameObject.SetActive(this.TrueEndEnable);
  116. for (int i = 0; i < this.LevelBeginningSceneNames.Length; i++)
  117. {
  118. this._levelButtons[i].transform.parent.gameObject.SetActive(SaveStorage.Get(this.LevelBeginningSceneNames[i] + "HasConquer", false));
  119. }
  120. R.Mode.EnterMode(Mode.AllMode.UI);
  121. R.Ui.Pause.Enabled = false;
  122. this._layers[0].SetActive(true);
  123. for (int j = 1; j < this._layers.Count; j++)
  124. {
  125. this._layers[j].SetActive(false);
  126. }
  127. this._panel.gameObject.SetActive(true);
  128. CameraFilterUtils.Create<CameraFilterPack_TV_80>(R.Ui.CameraGO);
  129. AnalogTV analogTV = R.Ui.CameraGO.AddComponent<AnalogTV>();
  130. analogTV.Shader = Shader.Find("Hidden/Colorful/Analog TV");
  131. analogTV.NoiseIntensity = 1f;
  132. analogTV.ScanlinesIntensity = 0f;
  133. analogTV.ScanlinesCount = 696;
  134. analogTV.Distortion = 0.18f;
  135. analogTV.CubicDistortion = 0f;
  136. analogTV.Scale = 1.02f;
  137. this._levelGrid.Reposition();
  138. }
  139. public YieldInstruction OpenWithAnim(bool enterEmptyScene = true, bool withProgressBar = true)
  140. {
  141. return base.StartCoroutine(this.OpenWithAnimCoroutine(enterEmptyScene, withProgressBar));
  142. }
  143. private IEnumerator OpenWithAnimCoroutine(bool enterEmptyScene, bool withProgressBar)
  144. {
  145. if (withProgressBar)
  146. {
  147. R.SceneData.CanAIRun = false;
  148. yield return R.Ui.Terminal.OpenWithAnim(null);
  149. yield return R.Ui.Terminal.ShowProgressBar(0f);
  150. yield return R.Ui.Terminal.SetProgressBarValueWithAnim(1f, 2f);
  151. yield return R.Ui.Terminal.HideProgressBar();
  152. yield return R.Ui.Terminal.CloseWithAnim();
  153. }
  154. R.Audio.PlayBGM(433, true);
  155. if (enterEmptyScene)
  156. {
  157. yield return LevelManager.LoadLevelByGateId("empty", SceneGate.OpenType.None);
  158. }
  159. this.Open();
  160. AnalogTV analogTV = R.Ui.CameraGO.GetComponent<AnalogTV>();
  161. analogTV.Scale = 0f;
  162. yield return DOTween.To(() => analogTV.Scale, delegate(float scale)
  163. {
  164. analogTV.Scale = scale;
  165. }, 1.02f, 0.5f).SetUpdate(true).WaitForCompletion();
  166. yield break;
  167. }
  168. private void Close()
  169. {
  170. CameraFilterUtils.Remove<CameraFilterPack_TV_80>(R.Ui.CameraGO);
  171. UnityEngine.Object.Destroy(R.Ui.CameraGO.GetComponent<AnalogTV>());
  172. this._panel.gameObject.SetActive(false);
  173. R.Ui.Pause.Enabled = true;
  174. R.Mode.ExitMode(Mode.AllMode.UI);
  175. base.enabled = false;
  176. }
  177. public YieldInstruction CloseWithAnim()
  178. {
  179. AnalogTV analogTV = R.Ui.CameraGO.GetComponent<AnalogTV>();
  180. return DOTween.To(() => analogTV.Scale, delegate(float scale)
  181. {
  182. analogTV.Scale = scale;
  183. }, 0f, 0.5f).SetUpdate(true).OnComplete(delegate
  184. {
  185. this.Close();
  186. R.Audio.StopBGM(true);
  187. }).WaitForCompletion();
  188. }
  189. [ContextMenu("CreateToggles")]
  190. private void CreateToggles()
  191. {
  192. for (int i = 0; i < this.LevelBeginningSceneNames.Length; i++)
  193. {
  194. Transform transform;
  195. if (i != 0)
  196. {
  197. transform = UnityEngine.Object.Instantiate<Transform>(this._levelGrid.GetChild(0));
  198. transform.parent = this._levelGrid.transform;
  199. transform.localScale = Vector3.one;
  200. }
  201. else
  202. {
  203. transform = this._levelGrid.GetChild(0);
  204. }
  205. transform.name = this.LevelBeginningSceneNames[i];
  206. transform.GetComponent<Localize>().Term = "ui/levelName/" + this.LevelBeginningSceneNames[i];
  207. this._levelButtons[i] = this._levelGrid.GetChild(i).GetChild(0);
  208. }
  209. this._levelGrid.Reposition();
  210. }
  211. [SerializeField]
  212. private UIPanel _panel;
  213. [SerializeField]
  214. private List<GameObject> _menuButtons;
  215. [SerializeField]
  216. private List<GameObject> _layers;
  217. [SerializeField]
  218. private List<Transform> _levelButtons;
  219. [SerializeField]
  220. private UIGrid _levelGrid;
  221. private string _currentSelectedLevel;
  222. public readonly string[] LevelBeginningSceneNames = new string[]
  223. {
  224. "C1L1S1",
  225. "C1L2S1",
  226. "C1L3S1",
  227. "C2L1S2",
  228. "C2L2S1",
  229. "C3L1S1",
  230. "C3L1S4",
  231. "C4L1S4",
  232. "C4L2S1",
  233. "C5L1S1"
  234. };
  235. }