MainBusinessWindow.cs 9.7 KB

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