MainBusinessWindow.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.UI;
  7. public class MainBusinessWindow : MonoBehaviour
  8. {
  9. private uGUICanvasFade UGUICanvas
  10. {
  11. get
  12. {
  13. if (this.m_uGUICanvasFade == null)
  14. {
  15. this.m_uGUICanvasFade = base.GetComponent<uGUICanvasFade>();
  16. }
  17. return this.m_uGUICanvasFade;
  18. }
  19. }
  20. private void Start()
  21. {
  22. if (base.gameObject.activeSelf)
  23. {
  24. base.gameObject.SetActive(false);
  25. }
  26. if (0f < this.UGUICanvas.alpha)
  27. {
  28. this.UGUICanvas.alpha = 0f;
  29. }
  30. this.m_UIListBanner.tempItem.AddComponent<MainBusinessWindow.BannerEnterHandler>();
  31. }
  32. public void OpenBusinessWindow(Action callback)
  33. {
  34. this.m_CallbackCloseWindow = callback;
  35. this.m_CallbackCloseWindowAtArg = null;
  36. this.OpenBusinessWindow();
  37. }
  38. public void OpenBusinessWindow(Action<bool, string> callback)
  39. {
  40. this.m_CallbackCloseWindow = null;
  41. this.m_CallbackCloseWindowAtArg = callback;
  42. this.OpenBusinessWindow();
  43. }
  44. public void OpenBusinessWindow()
  45. {
  46. this.UGUICanvas.interactable = false;
  47. this.UGUICanvas.blocksRaycasts = true;
  48. this.UGUICanvas.FadeIn(0.5f, delegate
  49. {
  50. this.UGUICanvas.interactable = true;
  51. });
  52. this.m_LastSelectToggle = null;
  53. int nowBusinessTypeID = GameMain.Instance.FacilityMgr.NextDayBusinessTypeID;
  54. if (!FacilityDataTable.IsExistFacilityBusinessTypeData(nowBusinessTypeID))
  55. {
  56. nowBusinessTypeID = GameMain.Instance.FacilityMgr.NowBusinessTypeID;
  57. }
  58. this.m_NowSelectingBusinessTypeID = nowBusinessTypeID;
  59. this.m_BeforeSelectingBusinessTypeID = nowBusinessTypeID;
  60. FacilityDataTable.BusinessTypeData[] businessTypeDataArray = FacilityDataTable.GetFacilityBusinessTypeDataArray(true);
  61. this.m_UIListBanner.Show<Toggle>(businessTypeDataArray.Length, delegate(int index, Toggle toggle)
  62. {
  63. FacilityDataTable.BusinessTypeData data = businessTypeDataArray[index];
  64. if (data.ID == nowBusinessTypeID)
  65. {
  66. toggle.isOn = true;
  67. }
  68. if (toggle.image)
  69. {
  70. Sprite spriteInAtlas = this.GetSpriteInAtlas(this.m_UIAtlasBusinessBannger, "main_banner_dammy");
  71. if (spriteInAtlas != null)
  72. {
  73. toggle.image.sprite = spriteInAtlas;
  74. }
  75. }
  76. toggle.onValueChanged.AddListener(delegate(bool value)
  77. {
  78. if (!value)
  79. {
  80. return;
  81. }
  82. this.OnClickBusinessBanner(toggle, data.ID);
  83. });
  84. MainBusinessWindow.BannerEnterHandler component = toggle.GetComponent<MainBusinessWindow.BannerEnterHandler>();
  85. component.onPointerEnter = delegate
  86. {
  87. this.UpdateBusinessTypeDescription(data.ID);
  88. this.UpdateBusinessTypeConditions(data.ID);
  89. };
  90. component.onPointerExit = delegate
  91. {
  92. this.UpdateBusinessTypeDescription(this.m_NowSelectingBusinessTypeID);
  93. this.UpdateBusinessTypeConditions(this.m_NowSelectingBusinessTypeID);
  94. };
  95. });
  96. this.UpdateBusinessTypeDescription(this.m_NowSelectingBusinessTypeID);
  97. this.UpdateBusinessTypeConditions(this.m_NowSelectingBusinessTypeID);
  98. }
  99. private void OnClickBusinessBanner(Toggle toggle, int businessTypeID)
  100. {
  101. bool flag = this.m_LastSelectToggle == toggle;
  102. bool flag2 = this.m_NowSelectingBusinessTypeID != businessTypeID;
  103. bool flag3 = this.IsSatisfyTheConditions(businessTypeID);
  104. if (!flag || !flag3)
  105. {
  106. this.UpdateBusinessTypeDescription(businessTypeID);
  107. this.UpdateBusinessTypeConditions(businessTypeID);
  108. }
  109. if (flag3)
  110. {
  111. this.m_NowSelectingBusinessTypeID = businessTypeID;
  112. }
  113. this.m_LastSelectToggle = toggle;
  114. }
  115. private void UpdateBusinessTypeDescription(int businessTypeID)
  116. {
  117. FacilityDataTable.BusinessTypeData facilityBusinessTypeData = FacilityDataTable.GetFacilityBusinessTypeData(businessTypeID);
  118. this.m_UITextDescription.text = facilityBusinessTypeData.description;
  119. }
  120. private void UpdateBusinessTypeConditions(int businessTypeID)
  121. {
  122. FacilityDataTable.BusinessTypeData facilityBusinessTypeData = FacilityDataTable.GetFacilityBusinessTypeData(businessTypeID);
  123. StringBuilder stringBuilder = new StringBuilder();
  124. string[] conditions = facilityBusinessTypeData.conditions;
  125. for (int i = 0; i < conditions.Length; i++)
  126. {
  127. string text = conditions[i];
  128. if (!string.IsNullOrEmpty(text))
  129. {
  130. stringBuilder.AppendFormat("{0}. {1}\n", i + 1, text);
  131. }
  132. }
  133. this.m_UITextConditions.text = stringBuilder.ToString();
  134. }
  135. private bool IsSatisfyTheConditions(int businessTypeID)
  136. {
  137. FacilityDataTable.BusinessTypeData facilityBusinessTypeData = FacilityDataTable.GetFacilityBusinessTypeData(businessTypeID);
  138. bool flag = true;
  139. flag &= GameMain.Instance.FacilityMgr.IsExistBusinessTypeFacility(businessTypeID);
  140. return true;
  141. }
  142. public void UpdateBusinessType()
  143. {
  144. GameMain.Instance.FacilityMgr.NextDayBusinessTypeID = this.m_NowSelectingBusinessTypeID;
  145. }
  146. public void CloseBusinessWindow()
  147. {
  148. if (this.m_CallbackCloseWindow != null)
  149. {
  150. this.m_CallbackCloseWindow();
  151. this.m_CallbackCloseWindow = null;
  152. }
  153. if (this.m_CallbackCloseWindowAtArg != null)
  154. {
  155. FacilityManager facilityMgr = GameMain.Instance.FacilityMgr;
  156. FacilityDataTable.BusinessTypeData facilityBusinessTypeData = FacilityDataTable.GetFacilityBusinessTypeData(facilityMgr.NowBusinessTypeID);
  157. bool arg = this.m_BeforeSelectingBusinessTypeID != this.m_NowSelectingBusinessTypeID;
  158. string fileName = facilityBusinessTypeData.fileName;
  159. this.m_CallbackCloseWindowAtArg(arg, fileName);
  160. this.m_CallbackCloseWindowAtArg = null;
  161. }
  162. this.UGUICanvas.interactable = false;
  163. this.UGUICanvas.FadeOut(0.5f, delegate
  164. {
  165. this.UGUICanvas.blocksRaycasts = false;
  166. });
  167. }
  168. private Sprite GetSpriteInAtlas(UIAtlas atlas, string resourceName)
  169. {
  170. Sprite sprite = null;
  171. if (this.m_SpriteDic.TryGetValue(resourceName, out sprite))
  172. {
  173. return sprite;
  174. }
  175. sprite = uGUIUtility.GetSpriteInAtlas(atlas, resourceName);
  176. this.m_SpriteDic.Add(resourceName, sprite);
  177. return sprite;
  178. }
  179. private void OnDestroy()
  180. {
  181. if (this == null)
  182. {
  183. return;
  184. }
  185. if (base.gameObject == null)
  186. {
  187. return;
  188. }
  189. if (this.m_SpriteDic != null)
  190. {
  191. int count = this.m_SpriteDic.Count;
  192. List<Sprite> list = new List<Sprite>(this.m_SpriteDic.Values);
  193. for (int i = count - 1; i >= 0; i--)
  194. {
  195. UnityEngine.Object.Destroy(list[i]);
  196. }
  197. this.m_SpriteDic.Clear();
  198. list.Clear();
  199. }
  200. }
  201. [SerializeField]
  202. private uGUIListViewer m_UIListBanner;
  203. [SerializeField]
  204. private Text m_UITextDescription;
  205. [SerializeField]
  206. private Text m_UITextConditions;
  207. private int m_NowSelectingBusinessTypeID;
  208. private int m_BeforeSelectingBusinessTypeID;
  209. private Toggle m_LastSelectToggle;
  210. private uGUICanvasFade m_uGUICanvasFade;
  211. private Action m_CallbackCloseWindow;
  212. private Action<bool, string> m_CallbackCloseWindowAtArg;
  213. [SerializeField]
  214. private UIAtlas m_UIAtlasBusinessBannger;
  215. private Dictionary<string, Sprite> m_SpriteDic = new Dictionary<string, Sprite>();
  216. private class BannerEnterHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IEventSystemHandler
  217. {
  218. private uGUISelectableAnimation selectableAnimation
  219. {
  220. get
  221. {
  222. if (this.m_SelectableAnimation == null)
  223. {
  224. this.m_SelectableAnimation = base.gameObject.GetComponentInChildren<uGUISelectableAnimation>();
  225. }
  226. return this.m_SelectableAnimation;
  227. }
  228. }
  229. private Toggle toggle
  230. {
  231. get
  232. {
  233. if (this.m_Toggle == null)
  234. {
  235. this.m_Toggle = base.gameObject.GetComponentInChildren<Toggle>();
  236. }
  237. return this.m_Toggle;
  238. }
  239. }
  240. private void Start()
  241. {
  242. if (this.IsSelecting() && this.selectableAnimation.enabled)
  243. {
  244. this.selectableAnimation.enabled = false;
  245. }
  246. }
  247. public void OnPointerEnter(PointerEventData eventData)
  248. {
  249. if (this.IsSelecting())
  250. {
  251. if (this.selectableAnimation.enabled)
  252. {
  253. this.selectableAnimation.enabled = false;
  254. }
  255. return;
  256. }
  257. if (!this.selectableAnimation.enabled)
  258. {
  259. this.selectableAnimation.enabled = true;
  260. this.selectableAnimation.OnPointerEnter(eventData);
  261. }
  262. if (this.onPointerEnter != null)
  263. {
  264. this.onPointerEnter();
  265. }
  266. }
  267. public void OnPointerExit(PointerEventData eventData)
  268. {
  269. if (this.IsSelecting())
  270. {
  271. if (this.selectableAnimation.enabled)
  272. {
  273. this.selectableAnimation.enabled = false;
  274. }
  275. return;
  276. }
  277. if (!this.selectableAnimation.enabled)
  278. {
  279. this.selectableAnimation.enabled = true;
  280. this.selectableAnimation.OnPointerExit(eventData);
  281. }
  282. if (this.onPointerExit != null)
  283. {
  284. this.onPointerExit();
  285. }
  286. }
  287. public void OnPointerClick(PointerEventData eventData)
  288. {
  289. if (this.IsSelecting())
  290. {
  291. if (this.selectableAnimation.enabled)
  292. {
  293. this.selectableAnimation.enabled = false;
  294. }
  295. return;
  296. }
  297. if (!this.selectableAnimation.enabled)
  298. {
  299. this.selectableAnimation.enabled = true;
  300. this.selectableAnimation.OnPointerClick(eventData);
  301. }
  302. }
  303. private bool IsSelecting()
  304. {
  305. bool flag = false;
  306. flag |= (EventSystem.current.currentSelectedGameObject == base.gameObject);
  307. return flag | this.toggle.isOn;
  308. }
  309. public Action onPointerEnter;
  310. public Action onPointerExit;
  311. private uGUISelectableAnimation m_SelectableAnimation;
  312. private Toggle m_Toggle;
  313. }
  314. }