using System; using System.Collections.Generic; using System.Text; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class MainBusinessWindow : MonoBehaviour { private uGUICanvasFade UGUICanvas { get { if (this.m_uGUICanvasFade == null) { this.m_uGUICanvasFade = base.GetComponent(); } return this.m_uGUICanvasFade; } } private void Start() { if (base.gameObject.activeSelf) { base.gameObject.SetActive(false); } if (0f < this.UGUICanvas.alpha) { this.UGUICanvas.alpha = 0f; } this.m_UIListBanner.tempItem.AddComponent(); } public void OpenBusinessWindow(Action callback) { this.m_CallbackCloseWindow = callback; this.m_CallbackCloseWindowAtArg = null; this.OpenBusinessWindow(); } public void OpenBusinessWindow(Action callback) { this.m_CallbackCloseWindow = null; this.m_CallbackCloseWindowAtArg = callback; this.OpenBusinessWindow(); } public void OpenBusinessWindow() { this.UGUICanvas.interactable = false; this.UGUICanvas.blocksRaycasts = true; this.UGUICanvas.FadeIn(0.5f, delegate { this.UGUICanvas.interactable = true; }); this.m_LastSelectToggle = null; int nowBusinessTypeID = GameMain.Instance.FacilityMgr.NextDayBusinessTypeID; if (!FacilityDataTable.IsExistFacilityBusinessTypeData(nowBusinessTypeID)) { nowBusinessTypeID = GameMain.Instance.FacilityMgr.NowBusinessTypeID; } this.m_NowSelectingBusinessTypeID = nowBusinessTypeID; this.m_BeforeSelectingBusinessTypeID = nowBusinessTypeID; FacilityDataTable.BusinessTypeData[] businessTypeDataArray = FacilityDataTable.GetFacilityBusinessTypeDataArray(true); this.m_UIListBanner.Show(businessTypeDataArray.Length, delegate(int index, Toggle toggle) { FacilityDataTable.BusinessTypeData data = businessTypeDataArray[index]; if (data.ID == nowBusinessTypeID) { toggle.isOn = true; } if (toggle.image) { Sprite spriteInAtlas = this.GetSpriteInAtlas(this.m_UIAtlasBusinessBannger, "main_banner_dammy"); if (spriteInAtlas != null) { toggle.image.sprite = spriteInAtlas; } } toggle.onValueChanged.AddListener(delegate(bool value) { if (!value) { return; } this.OnClickBusinessBanner(toggle, data.ID); }); MainBusinessWindow.BannerEnterHandler component = toggle.GetComponent(); component.onPointerEnter = delegate { this.UpdateBusinessTypeDescription(data.ID); this.UpdateBusinessTypeConditions(data.ID); }; component.onPointerExit = delegate { this.UpdateBusinessTypeDescription(this.m_NowSelectingBusinessTypeID); this.UpdateBusinessTypeConditions(this.m_NowSelectingBusinessTypeID); }; }); this.UpdateBusinessTypeDescription(this.m_NowSelectingBusinessTypeID); this.UpdateBusinessTypeConditions(this.m_NowSelectingBusinessTypeID); } private void OnClickBusinessBanner(Toggle toggle, int businessTypeID) { bool flag = this.m_LastSelectToggle == toggle; bool flag2 = this.m_NowSelectingBusinessTypeID != businessTypeID; bool flag3 = this.IsSatisfyTheConditions(businessTypeID); if (!flag || !flag3) { this.UpdateBusinessTypeDescription(businessTypeID); this.UpdateBusinessTypeConditions(businessTypeID); } if (flag3) { this.m_NowSelectingBusinessTypeID = businessTypeID; } this.m_LastSelectToggle = toggle; } private void UpdateBusinessTypeDescription(int businessTypeID) { FacilityDataTable.BusinessTypeData facilityBusinessTypeData = FacilityDataTable.GetFacilityBusinessTypeData(businessTypeID); this.m_UITextDescription.text = facilityBusinessTypeData.description; } private void UpdateBusinessTypeConditions(int businessTypeID) { FacilityDataTable.BusinessTypeData facilityBusinessTypeData = FacilityDataTable.GetFacilityBusinessTypeData(businessTypeID); StringBuilder stringBuilder = new StringBuilder(); string[] conditions = facilityBusinessTypeData.conditions; for (int i = 0; i < conditions.Length; i++) { string text = conditions[i]; if (!string.IsNullOrEmpty(text)) { stringBuilder.AppendFormat("{0}. {1}\n", i + 1, text); } } this.m_UITextConditions.text = stringBuilder.ToString(); } private bool IsSatisfyTheConditions(int businessTypeID) { FacilityDataTable.BusinessTypeData facilityBusinessTypeData = FacilityDataTable.GetFacilityBusinessTypeData(businessTypeID); bool flag = true; flag &= GameMain.Instance.FacilityMgr.IsExistBusinessTypeFacility(businessTypeID); return true; } public void UpdateBusinessType() { GameMain.Instance.FacilityMgr.NextDayBusinessTypeID = this.m_NowSelectingBusinessTypeID; } public void CloseBusinessWindow() { if (this.m_CallbackCloseWindow != null) { this.m_CallbackCloseWindow(); this.m_CallbackCloseWindow = null; } if (this.m_CallbackCloseWindowAtArg != null) { FacilityManager facilityMgr = GameMain.Instance.FacilityMgr; FacilityDataTable.BusinessTypeData facilityBusinessTypeData = FacilityDataTable.GetFacilityBusinessTypeData(facilityMgr.NowBusinessTypeID); bool arg = this.m_BeforeSelectingBusinessTypeID != this.m_NowSelectingBusinessTypeID; string fileName = facilityBusinessTypeData.fileName; this.m_CallbackCloseWindowAtArg(arg, fileName); this.m_CallbackCloseWindowAtArg = null; } this.UGUICanvas.interactable = false; this.UGUICanvas.FadeOut(0.5f, delegate { this.UGUICanvas.blocksRaycasts = false; }); } private Sprite GetSpriteInAtlas(UIAtlas atlas, string resourceName) { Sprite sprite = null; if (this.m_SpriteDic.TryGetValue(resourceName, out sprite)) { return sprite; } sprite = uGUIUtility.GetSpriteInAtlas(atlas, resourceName); this.m_SpriteDic.Add(resourceName, sprite); return sprite; } private void OnDestroy() { if (this == null) { return; } if (base.gameObject == null) { return; } if (this.m_SpriteDic != null) { int count = this.m_SpriteDic.Count; List list = new List(this.m_SpriteDic.Values); for (int i = count - 1; i >= 0; i--) { UnityEngine.Object.Destroy(list[i]); } this.m_SpriteDic.Clear(); list.Clear(); } } [SerializeField] private uGUIListViewer m_UIListBanner; [SerializeField] private Text m_UITextDescription; [SerializeField] private Text m_UITextConditions; private int m_NowSelectingBusinessTypeID; private int m_BeforeSelectingBusinessTypeID; private Toggle m_LastSelectToggle; private uGUICanvasFade m_uGUICanvasFade; private Action m_CallbackCloseWindow; private Action m_CallbackCloseWindowAtArg; [SerializeField] private UIAtlas m_UIAtlasBusinessBannger; private Dictionary m_SpriteDic = new Dictionary(); private class BannerEnterHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IEventSystemHandler { private uGUISelectableAnimation selectableAnimation { get { if (this.m_SelectableAnimation == null) { this.m_SelectableAnimation = base.gameObject.GetComponentInChildren(); } return this.m_SelectableAnimation; } } private Toggle toggle { get { if (this.m_Toggle == null) { this.m_Toggle = base.gameObject.GetComponentInChildren(); } return this.m_Toggle; } } private void Start() { if (this.IsSelecting() && this.selectableAnimation.enabled) { this.selectableAnimation.enabled = false; } } public void OnPointerEnter(PointerEventData eventData) { if (this.IsSelecting()) { if (this.selectableAnimation.enabled) { this.selectableAnimation.enabled = false; } return; } if (!this.selectableAnimation.enabled) { this.selectableAnimation.enabled = true; this.selectableAnimation.OnPointerEnter(eventData); } if (this.onPointerEnter != null) { this.onPointerEnter(); } } public void OnPointerExit(PointerEventData eventData) { if (this.IsSelecting()) { if (this.selectableAnimation.enabled) { this.selectableAnimation.enabled = false; } return; } if (!this.selectableAnimation.enabled) { this.selectableAnimation.enabled = true; this.selectableAnimation.OnPointerExit(eventData); } if (this.onPointerExit != null) { this.onPointerExit(); } } public void OnPointerClick(PointerEventData eventData) { if (this.IsSelecting()) { if (this.selectableAnimation.enabled) { this.selectableAnimation.enabled = false; } return; } if (!this.selectableAnimation.enabled) { this.selectableAnimation.enabled = true; this.selectableAnimation.OnPointerClick(eventData); } } private bool IsSelecting() { bool flag = false; flag |= (EventSystem.current.currentSelectedGameObject == base.gameObject); return flag | this.toggle.isOn; } public Action onPointerEnter; public Action onPointerExit; private uGUISelectableAnimation m_SelectableAnimation; private Toggle m_Toggle; } }