SelectButtonCtrl.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using wf;
  6. public class SelectButtonCtrl : MonoBehaviour
  7. {
  8. public void Awake()
  9. {
  10. if (this.Panel == null)
  11. {
  12. this.Panel = base.transform.parent.gameObject.GetComponent<UIPanel>();
  13. }
  14. this.grid = base.GetComponent<UIGrid>();
  15. this.scrollView = base.transform.parent.GetComponent<UIScrollView>();
  16. }
  17. public void CreateSelectButtons(List<KeyValuePair<string, KeyValuePair<string, bool>>> listSelectBtn, Action<string, string> onClickCallBack, UnityEngine.Object selectBtnPrefab)
  18. {
  19. this.grid.cellHeight = 0f;
  20. this.m_OnClickCallBack = null;
  21. this.m_OnClickCallEvent = null;
  22. this.ClearExistSelectButton();
  23. this.m_OnClickCallBack = onClickCallBack;
  24. this.m_listSelectBtn = new List<KeyValuePair<string, SelectButtonCtrl.SelectButton>>();
  25. int num = 0;
  26. foreach (KeyValuePair<string, KeyValuePair<string, bool>> keyValuePair in listSelectBtn)
  27. {
  28. GameObject gameObject = UnityEngine.Object.Instantiate(selectBtnPrefab) as GameObject;
  29. for (int i = 0; i < gameObject.transform.childCount; i++)
  30. {
  31. UIButton component = gameObject.transform.GetChild(i).GetComponent<UIButton>();
  32. EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.ClickSelectButton));
  33. component.isEnabled = keyValuePair.Value.Value;
  34. }
  35. gameObject.name = "selectButton_" + num;
  36. gameObject.transform.parent = base.transform;
  37. gameObject.transform.localScale = Vector3.one;
  38. gameObject.transform.localPosition = Vector3.zero;
  39. gameObject.transform.rotation = Quaternion.identity;
  40. SubtitleDisplayManager component2 = gameObject.GetComponent<SubtitleDisplayManager>();
  41. if (component2 != null)
  42. {
  43. component2.SetTextFromScriptStyle(keyValuePair.Key);
  44. }
  45. else
  46. {
  47. UILabel component3 = UTY.GetChildObject(gameObject, "Single/Option", false).GetComponent<UILabel>();
  48. component3.text = keyValuePair.Key;
  49. }
  50. SelectButtonCtrl.SelectButton selectButton = new SelectButtonCtrl.SelectButton();
  51. selectButton.m_btnName = gameObject.name;
  52. selectButton.m_goSelectBtn = gameObject;
  53. selectButton.m_msg = keyValuePair.Key;
  54. selectButton.m_tag = keyValuePair.Value.Key;
  55. if (GameMain.Instance.VRMode)
  56. {
  57. UIButton[] componentsInChildren = gameObject.GetComponentsInChildren<UIButton>(true);
  58. foreach (UIButton uibutton in componentsInChildren)
  59. {
  60. uibutton.defaultColor = new Color(0.8f, 0.8f, 0.8f, 1f);
  61. }
  62. }
  63. this.m_listSelectBtn.Add(new KeyValuePair<string, SelectButtonCtrl.SelectButton>(selectButton.m_btnName, selectButton));
  64. num++;
  65. }
  66. Utility.ResetNGUI(this.grid);
  67. this.scrollView.verticalScrollBar.gameObject.SetActive(true);
  68. Utility.ResetNGUI(this.scrollView);
  69. this.scrollView.verticalScrollBar.value = 0f;
  70. this.scrollView.verticalScrollBar.alpha = 0f;
  71. this.m_EffectStat = SelectButtonCtrl.EffectStat.Null;
  72. base.StartCoroutine("FadeIn");
  73. }
  74. private IEnumerator FadeIn()
  75. {
  76. this.scrollView.GetComponent<UIPanel>().alpha = 0f;
  77. yield return null;
  78. yield return null;
  79. this.scrollView.GetComponent<UIPanel>().alpha = 1f;
  80. yield break;
  81. }
  82. public void SetPanelAlpha(float value)
  83. {
  84. this.Awake();
  85. this.Panel.alpha = value;
  86. }
  87. public bool IsPlayingEffect()
  88. {
  89. return this.m_EffectStat != SelectButtonCtrl.EffectStat.Null;
  90. }
  91. public void ClearExistSelectButton()
  92. {
  93. IEnumerator enumerator = base.transform.GetEnumerator();
  94. try
  95. {
  96. while (enumerator.MoveNext())
  97. {
  98. object obj = enumerator.Current;
  99. Transform transform = (Transform)obj;
  100. UnityEngine.Object.Destroy(transform.gameObject);
  101. }
  102. }
  103. finally
  104. {
  105. IDisposable disposable;
  106. if ((disposable = (enumerator as IDisposable)) != null)
  107. {
  108. disposable.Dispose();
  109. }
  110. }
  111. }
  112. public void ClickSelectButton()
  113. {
  114. string b = string.Empty;
  115. b = UIButton.current.transform.parent.name;
  116. foreach (KeyValuePair<string, SelectButtonCtrl.SelectButton> keyValuePair in this.m_listSelectBtn)
  117. {
  118. GameObject goSelectBtn = keyValuePair.Value.m_goSelectBtn;
  119. if (keyValuePair.Key == b)
  120. {
  121. TweenAlpha tweenAlpha;
  122. if (GameMain.Instance.ScriptMgr.adv_kag.skip_mode)
  123. {
  124. tweenAlpha = TweenAlpha.Begin(goSelectBtn, 0.01f, 0f);
  125. }
  126. else
  127. {
  128. tweenAlpha = TweenAlpha.Begin(keyValuePair.Value.m_goSelectBtn, 1f * GameMain.Instance.CMSystem.FadeSpeedRate, 0f);
  129. }
  130. EventDelegate.Set(tweenAlpha.onFinished, new EventDelegate.Callback(this.OnFinished));
  131. if (this.m_OnClickCallBack != null)
  132. {
  133. string text = keyValuePair.Value.m_msg;
  134. string tag = keyValuePair.Value.m_tag;
  135. Action<string, string> tmp = this.m_OnClickCallBack;
  136. this.m_OnClickCallEvent = delegate()
  137. {
  138. tmp(text, tag);
  139. };
  140. this.m_OnClickCallBack = null;
  141. }
  142. }
  143. else
  144. {
  145. for (int i = 0; i < goSelectBtn.transform.childCount; i++)
  146. {
  147. TweenAlpha component = goSelectBtn.transform.GetChild(i).GetComponent<TweenAlpha>();
  148. component.onFinished = null;
  149. }
  150. if (GameMain.Instance.ScriptMgr.adv_kag.skip_mode)
  151. {
  152. TweenAlpha.Begin(goSelectBtn, 0.01f, 0f);
  153. }
  154. else
  155. {
  156. TweenAlpha.Begin(goSelectBtn, 0.3f * GameMain.Instance.CMSystem.FadeSpeedRate, 0f);
  157. }
  158. }
  159. BoxCollider[] componentsInChildren = goSelectBtn.GetComponentsInChildren<BoxCollider>();
  160. foreach (BoxCollider boxCollider in componentsInChildren)
  161. {
  162. boxCollider.enabled = false;
  163. }
  164. }
  165. this.scrollView.verticalScrollBar.alpha = 0f;
  166. this.scrollView.verticalScrollBar.gameObject.SetActive(false);
  167. this.m_EffectStat = SelectButtonCtrl.EffectStat.EndOut;
  168. }
  169. private void OnFinished()
  170. {
  171. if (this.dragMat == null)
  172. {
  173. this.dragMat = base.transform.parent.parent.Find("DragMat").gameObject;
  174. }
  175. this.dragMat.SetActive(false);
  176. this.ClearExistSelectButton();
  177. this.grid.cellHeight = 93f;
  178. Utility.ResetNGUI(this.scrollView);
  179. this.scrollView.verticalScrollBar.alpha = 0f;
  180. this.scrollView.verticalScrollBar.value = 0f;
  181. this.scrollView.verticalScrollBar.gameObject.SetActive(false);
  182. this.m_EffectStat = SelectButtonCtrl.EffectStat.Null;
  183. if (this.m_OnClickCallEvent != null)
  184. {
  185. this.m_OnClickCallEvent();
  186. }
  187. this.m_OnClickCallEvent = null;
  188. }
  189. private void Update()
  190. {
  191. if (this.scrollRest)
  192. {
  193. Utility.ResetNGUI(this.scrollView);
  194. this.scrollView.verticalScrollBar.value = 0f;
  195. this.scrollView.verticalScrollBar.alpha = 0f;
  196. this.scrollView.verticalScrollBar.ForceUpdate();
  197. this.scrollRest = false;
  198. }
  199. if (GameMain.Instance.CMSystem.SubtitleType == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle && this.grid.cellHeight != 110f)
  200. {
  201. this.grid.cellHeight = 110f;
  202. Utility.ResetNGUI(this.grid);
  203. this.scrollRest = true;
  204. }
  205. else if (GameMain.Instance.CMSystem.SubtitleType != SubtitleDisplayManager.DisplayType.OriginalAndSubtitle && this.grid.cellHeight != 93f)
  206. {
  207. this.grid.cellHeight = 93f;
  208. Utility.ResetNGUI(this.grid);
  209. this.scrollRest = true;
  210. }
  211. }
  212. [SerializeField]
  213. private GameObject dragMat;
  214. private UIPanel Panel;
  215. private List<KeyValuePair<string, SelectButtonCtrl.SelectButton>> m_listSelectBtn;
  216. private Action<string, string> m_OnClickCallBack;
  217. private Action m_OnClickCallEvent;
  218. private SelectButtonCtrl.EffectStat m_EffectStat;
  219. private UIGrid grid;
  220. private UIScrollView scrollView;
  221. private bool scrollRest;
  222. private enum EffectStat
  223. {
  224. Null,
  225. StartIn,
  226. EndOut
  227. }
  228. private class SelectButton
  229. {
  230. public string m_btnName { get; set; }
  231. public string m_msg { get; set; }
  232. public string m_tag { get; set; }
  233. public GameObject m_goSelectBtn { get; set; }
  234. public override string ToString()
  235. {
  236. return string.Format("SelectButton=[m_btnName={0}, m_msg={1}, m_tag={2}, m_goSelectBtn={3}]", new object[]
  237. {
  238. this.m_btnName,
  239. this.m_msg,
  240. this.m_tag,
  241. this.m_goSelectBtn
  242. });
  243. }
  244. }
  245. }