LifeModeChangeWindow.cs 7.1 KB

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