LifeModeChangeWindow.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.UI;
  7. public class LifeModeChangeWindow : MonoBehaviour
  8. {
  9. private void UpdateNowSelectType()
  10. {
  11. this.m_NowSelectType = GameModeManager.nowGameMode;
  12. }
  13. private void SetNowSelectType(GameModeManager.Type type)
  14. {
  15. this.m_NowSelectType = type;
  16. }
  17. private void SetNowGameMode()
  18. {
  19. GameModeManager.nowGameMode = this.m_NowSelectType;
  20. }
  21. private uGUICanvasFade uGUICanvasFade
  22. {
  23. get
  24. {
  25. if (this.m_uGUICanvasFade == null)
  26. {
  27. this.m_uGUICanvasFade = base.GetComponent<uGUICanvasFade>();
  28. }
  29. return this.m_uGUICanvasFade;
  30. }
  31. }
  32. private void Init()
  33. {
  34. if (this.m_IsInit)
  35. {
  36. return;
  37. }
  38. this.m_IsInit = true;
  39. this.m_UIListBanner.tempItem.AddComponent<LifeModeChangeWindow.BannerEnterHandler>();
  40. this.m_ButtonClose.onClick.AddListener(new UnityAction(this.CloseWindow));
  41. }
  42. private void Start()
  43. {
  44. if (this.m_IsInit)
  45. {
  46. return;
  47. }
  48. this.Init();
  49. this.uGUICanvasFade.FadeOut(0f, null);
  50. base.gameObject.SetActive(false);
  51. }
  52. public void Open(Action callback)
  53. {
  54. this.Init();
  55. this.m_CallbackCloseWindow = callback;
  56. this.OpenWindow();
  57. }
  58. private void OpenWindow()
  59. {
  60. LifeModeChangeWindow.<OpenWindow>c__AnonStorey0 <OpenWindow>c__AnonStorey = new LifeModeChangeWindow.<OpenWindow>c__AnonStorey0();
  61. <OpenWindow>c__AnonStorey.$this = this;
  62. this.uGUICanvasFade.interactable = false;
  63. this.uGUICanvasFade.blocksRaycasts = true;
  64. this.uGUICanvasFade.alpha = 0f;
  65. this.uGUICanvasFade.FadeIn(0.3f, delegate
  66. {
  67. <OpenWindow>c__AnonStorey.$this.uGUICanvasFade.interactable = true;
  68. });
  69. this.UpdateNowSelectType();
  70. Dictionary<GameModeManager.Type, GameModeManager.Data> dataDic = GameModeManager.DataDic;
  71. <OpenWindow>c__AnonStorey.keyList = new List<GameModeManager.Type>(dataDic.Keys);
  72. <OpenWindow>c__AnonStorey.valueList = new List<GameModeManager.Data>(dataDic.Values);
  73. this.m_UIListBanner.Show<Toggle>(dataDic.Count, delegate(int index, Toggle toggle)
  74. {
  75. GameModeManager.Type dataType = <OpenWindow>c__AnonStorey.keyList[index];
  76. GameModeManager.Data data = <OpenWindow>c__AnonStorey.valueList[index];
  77. if (toggle.image != null)
  78. {
  79. Sprite spriteInAtlas = <OpenWindow>c__AnonStorey.$this.GetSpriteInAtlas(<OpenWindow>c__AnonStorey.$this.m_UIAtlasBusinessBannger, data.strBannerImageName);
  80. if (spriteInAtlas != null)
  81. {
  82. toggle.image.sprite = spriteInAtlas;
  83. }
  84. }
  85. if (dataType == <OpenWindow>c__AnonStorey.$this.m_NowSelectType)
  86. {
  87. toggle.isOn = true;
  88. }
  89. toggle.onValueChanged.AddListener(delegate(bool value)
  90. {
  91. if (!value)
  92. {
  93. return;
  94. }
  95. <OpenWindow>c__AnonStorey.SetNowSelectType(dataType);
  96. <OpenWindow>c__AnonStorey.UpdateBannerList();
  97. });
  98. LifeModeChangeWindow.BannerEnterHandler component = toggle.GetComponent<LifeModeChangeWindow.BannerEnterHandler>();
  99. component.onPointerEnter = delegate()
  100. {
  101. <OpenWindow>c__AnonStorey.UpdateDescription(data.strDescription);
  102. };
  103. component.onPointerExit = delegate()
  104. {
  105. <OpenWindow>c__AnonStorey.UpdateDescription(GameModeManager.GetData(<OpenWindow>c__AnonStorey.m_NowSelectType).strDescription);
  106. };
  107. });
  108. this.UpdateDescription(GameModeManager.GetData().strDescription);
  109. this.UpdateBannerList();
  110. }
  111. private void UpdateBannerList()
  112. {
  113. foreach (GameObject gameObject in this.m_UIListBanner.ItemArray)
  114. {
  115. LifeModeChangeWindow.BannerEnterHandler component = gameObject.GetComponent<LifeModeChangeWindow.BannerEnterHandler>();
  116. component.UpdateColorBlock();
  117. component.toggle.interactable = !component.toggle.isOn;
  118. }
  119. }
  120. private void UpdateDescription(string msg)
  121. {
  122. this.m_UITextDescription.text = msg;
  123. }
  124. public void CloseWindow()
  125. {
  126. this.SetNowGameMode();
  127. if (this.m_CallbackCloseWindow != null)
  128. {
  129. this.m_CallbackCloseWindow();
  130. this.m_CallbackCloseWindow = null;
  131. }
  132. this.uGUICanvasFade.interactable = false;
  133. this.uGUICanvasFade.FadeOut(0.3f, delegate
  134. {
  135. base.gameObject.SetActive(false);
  136. this.uGUICanvasFade.blocksRaycasts = false;
  137. this.uGUICanvasFade.alpha = 0f;
  138. });
  139. }
  140. private Sprite GetSpriteInAtlas(UIAtlas atlas, string resourceName)
  141. {
  142. Sprite sprite = null;
  143. if (this.m_SpriteDic.TryGetValue(resourceName, out sprite))
  144. {
  145. return sprite;
  146. }
  147. sprite = uGUIUtility.GetSpriteInAtlas(atlas, resourceName);
  148. this.m_SpriteDic.Add(resourceName, sprite);
  149. return sprite;
  150. }
  151. private void OnDestroy()
  152. {
  153. if (this == null)
  154. {
  155. return;
  156. }
  157. if (base.gameObject == null)
  158. {
  159. return;
  160. }
  161. if (this.m_SpriteDic != null)
  162. {
  163. int count = this.m_SpriteDic.Count;
  164. List<Sprite> list = new List<Sprite>(this.m_SpriteDic.Values);
  165. for (int i = count - 1; i >= 0; i--)
  166. {
  167. UnityEngine.Object.Destroy(list[i]);
  168. }
  169. this.m_SpriteDic.Clear();
  170. list.Clear();
  171. }
  172. }
  173. private GameModeManager.Type m_NowSelectType;
  174. [SerializeField]
  175. private uGUIListViewer m_UIListBanner;
  176. [SerializeField]
  177. private Text m_UITextDescription;
  178. [SerializeField]
  179. private Button m_ButtonClose;
  180. private uGUICanvasFade m_uGUICanvasFade;
  181. private Action m_CallbackCloseWindow;
  182. private bool m_IsInit;
  183. [SerializeField]
  184. private UIAtlas m_UIAtlasBusinessBannger;
  185. private Dictionary<string, Sprite> m_SpriteDic = new Dictionary<string, Sprite>();
  186. private class BannerEnterHandler : UIBehaviour, IPointerEnterHandler, IPointerExitHandler, IEventSystemHandler
  187. {
  188. public Toggle toggle
  189. {
  190. get
  191. {
  192. if (this.m_Toggle == null)
  193. {
  194. this.m_Toggle = base.gameObject.GetComponentInChildren<Toggle>();
  195. }
  196. return this.m_Toggle;
  197. }
  198. }
  199. protected override void Start()
  200. {
  201. this.InitColorBlock();
  202. }
  203. private void InitColorBlock()
  204. {
  205. if (this.m_IsInitColorBlock)
  206. {
  207. return;
  208. }
  209. this.m_IsInitColorBlock = true;
  210. this.m_ColorBlockDefault = this.toggle.colors;
  211. this.m_ColorBlockSelected = this.toggle.colors;
  212. this.m_ColorBlockSelected.normalColor = this.m_ColorBlockSelected.highlightedColor;
  213. this.m_ColorBlockSelected.disabledColor = this.m_ColorBlockSelected.highlightedColor;
  214. this.m_ColorBlockSelected.pressedColor = this.m_ColorBlockSelected.highlightedColor;
  215. }
  216. public void OnPointerEnter(PointerEventData eventData)
  217. {
  218. if (this.IsSelecting())
  219. {
  220. return;
  221. }
  222. if (this.onPointerEnter != null)
  223. {
  224. this.onPointerEnter();
  225. }
  226. }
  227. public void OnPointerExit(PointerEventData eventData)
  228. {
  229. if (this.IsSelecting())
  230. {
  231. return;
  232. }
  233. if (this.onPointerExit != null)
  234. {
  235. this.onPointerExit();
  236. }
  237. }
  238. private bool IsSelecting()
  239. {
  240. return this.toggle.isOn;
  241. }
  242. public void UpdateColorBlock()
  243. {
  244. this.InitColorBlock();
  245. bool flag = this.IsSelecting();
  246. this.toggle.colors = ((!flag) ? this.m_ColorBlockDefault : this.m_ColorBlockSelected);
  247. }
  248. public Action onPointerEnter;
  249. public Action onPointerExit;
  250. private ColorBlock m_ColorBlockDefault;
  251. private ColorBlock m_ColorBlockSelected;
  252. private Toggle m_Toggle;
  253. private bool m_IsInitColorBlock;
  254. }
  255. }